diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb4eeb75..ddd8b33d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -138,6 +138,7 @@ ADD_SUBDIRECTORY(detector_control)
ADD_SUBDIRECTORY(image_puller)
ADD_SUBDIRECTORY(preview)
ADD_SUBDIRECTORY(symmetry)
+ADD_SUBDIRECTORY(ccp4c)
IF (JFJOCH_WRITER_ONLY)
MESSAGE(STATUS "Compiling HDF5 writer only")
diff --git a/ccp4c/CMakeLists.txt b/ccp4c/CMakeLists.txt
new file mode 100644
index 00000000..917ae9df
--- /dev/null
+++ b/ccp4c/CMakeLists.txt
@@ -0,0 +1,57 @@
+set(ccp4c_SOURCES
+ ccp4/ccp4_array.c
+ ccp4/cmap_data.c
+ ccp4/cmtzlib.c
+ ccp4/ccp4_general.c
+ ccp4/cmap_header.c
+ ccp4/csymlib.c
+ ccp4/ccp4_parser.c
+ ccp4/cmap_labels.c
+ ccp4/cvecmat.c
+ ccp4/ccp4_program.c
+ ccp4/cmap_open.c
+ ccp4/library_err.c
+ ccp4/ccp4_unitcell.c
+ ccp4/cmap_skew.c
+ ccp4/library_file.c
+ ccp4/cmap_accessor.c
+ ccp4/cmap_stats.c
+ ccp4/library_utils.c
+ ccp4/cmap_close.c
+ ccp4/cmap_symop.c
+ ccp4/pack_c.c
+)
+
+set(ccp4c_HEADERS
+ ccp4/ccp4_file_err.h
+ ccp4/ccp4_program.h
+ ccp4/ccp4_unitcell.h
+ ccp4/cmap_errno.h
+ ccp4/cmap_stats.h
+ ccp4/csymlib.h
+ ccp4/library_file.h
+ ccp4/w32mvs.h
+ ccp4/ccp4_fortran.h
+ ccp4/ccp4_spg.h
+ ccp4/ccp4_utils.h
+ ccp4/cmap_header.h
+ ccp4/cmaplib.h
+ ccp4/cvecmat.h
+ ccp4/mtzdata.h
+ ccp4/ccp4_array.h
+ ccp4/ccp4_general.h
+ ccp4/ccp4_vars.h
+ ccp4/cmap_labels.h
+ ccp4/cmaplib_f.h
+ ccp4/overview.h
+ ccp4/ccp4_errno.h
+ ccp4/ccp4_parser.h
+ ccp4/ccp4_types.h
+ ccp4/cmap_data.h
+ ccp4/cmap_skew.h
+ ccp4/cmtzlib.h
+ ccp4/pack_c.h
+ ccp4/ccp4_sysdep.h
+)
+
+ADD_LIBRARY(ccp4c STATIC ${ccp4c_SOURCES} ${ccp4c_HEADERS})
\ No newline at end of file
diff --git a/ccp4c/COPYING b/ccp4c/COPYING
new file mode 100644
index 00000000..14c5b73a
--- /dev/null
+++ b/ccp4c/COPYING
@@ -0,0 +1,685 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+Section 15 has been amended in accordance with Section 7a) above to
+address the requirements of UK law.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+Section 16 has been replaced in accordance with Section 7a) above to
+address the requirements of UK law.
+
+ THE LICENSOR OR ANY THIRD PARTIES FROM WHOM IT HAS LICENSED ANY CODE
+WILL NOT BE LIABLE FOR: ANY LOSS OF PROFITS, LOSS OF REVENUE, LOSS OR
+CORRUPTION OF DATA, LOSS OF CONTRACTS OR OPPORTUNITY, LOSS OF SAVINGS
+OR THIRD PARTY CLAIMS (IN EACH CASE WHETHER DIRECT OR INDIRECT), ANY
+DIRECT OR INDIRECT LOSS OR DAMAGE ARISING OUT OF OR IN CONNECTION WITH
+THE PROGRAM, IN EACH CASE, WHETHER THAT LOSS ARISES AS A RESULT OF
+LICENSOR"S NEGLIGENCE, OR IN ANY OTHER WAY, EVEN IF LICENSOR HAS BEEN
+ADVISED OF THE POSSIBILITY OF THAT LOSS ARISING, OR IF IT WAS WITHIN
+LICENSOR'S CONTEMPLATION.
+
+NONE OF THESE PROVISION LIMITS OR EXCLUDES THE LICENSOR"S LIABILITY
+FOR DEATH OR PERSONAL INJURY CAUSED BY ITS NEGLIGENCE OR FOR ANY
+FRAUD, OR FOR ANY SORT OF LIABILITY THAT, BY LAW, CANNOT BE LIMITED OR
+EXCLUDED
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/ccp4c/COPYING.LESSER b/ccp4c/COPYING.LESSER
new file mode 100644
index 00000000..fc8a5de7
--- /dev/null
+++ b/ccp4c/COPYING.LESSER
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/ccp4c/ccp4/ccp4_array.c b/ccp4c/ccp4/ccp4_array.c
new file mode 100644
index 00000000..d088c0ce
--- /dev/null
+++ b/ccp4c/ccp4/ccp4_array.c
@@ -0,0 +1,155 @@
+/*
+ ccp4_array.c: implementation file for resizable array implementation.
+ Copyright (C) 2002 Kevin Cowtan
+
+ This library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ version 3, modified in accordance with the provisions of the
+ license to address the requirements of UK law.
+
+ You should have received a copy of the modified GNU Lesser General
+ Public License along with this library. If not, copies may be
+ downloaded from http://www.ccp4.ac.uk/ccp4license.php
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+*/
+
+/** @file ccp4_array.c
+ * implementation file for resizable array implementation.
+ * Kevin Cowtan
+ */
+
+#include "ccp4_array.h"
+/* rcsid[] = "$Id$" */
+
+ccp4_ptr ccp4array_new_(ccp4_ptr *p)
+{
+ ccp4array_base *v;
+ v = (ccp4array_base *)malloc(sizeof(ccp4array_base));
+ v->size = v->capacity = 0;
+ *p = (ccp4_ptr *)((ccp4_byteptr)(v)+sizeof(ccp4array_base));
+ return *p;
+}
+
+ccp4_ptr ccp4array_new_size_(ccp4_ptr *p, const int size, const size_t reclen)
+{
+ ccp4array_base *v;
+ int capacity = (size * 12) / 10 + 2;
+ v = (ccp4array_base *)malloc(sizeof(ccp4array_base) + capacity * reclen);
+ v->size = size;
+ v->capacity = capacity;
+ *p = (ccp4_ptr *)((ccp4_byteptr)(v)+sizeof(ccp4array_base));
+ return *p;
+}
+
+void ccp4array_resize_(ccp4_ptr *p, const int size, const size_t reclen)
+{
+ ccp4array_base *v;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ if (size > v->capacity) {
+ v->capacity = (size * 12) / 10 + 2;
+ v = (ccp4array_base *)realloc(v, sizeof(ccp4array_base) + v->capacity * reclen);
+ *p = (ccp4_ptr *)((ccp4_byteptr)(v)+sizeof(ccp4array_base));
+ }
+ v->size = size;
+}
+
+void ccp4array_reserve_(ccp4_ptr *p, const int size, const size_t reclen)
+{
+ ccp4array_base *v;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ v->capacity = size;
+ if ( v->size > size ) v->size = size;
+ v = (ccp4array_base *)realloc(v, sizeof(ccp4array_base) + v->capacity * reclen);
+ *p = (ccp4_ptr *)((ccp4_byteptr)(v)+sizeof(ccp4array_base));
+}
+
+void ccp4array_append_(ccp4_ptr *p, ccp4_constptr data, const size_t reclen)
+{
+ ccp4array_base *v;
+ int osize;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ osize = v->size;
+ ccp4array_resize_(p, osize+1, reclen);
+ memcpy((ccp4_byteptr)(*p)+osize*reclen, data, reclen);
+}
+
+void ccp4array_append_n_(ccp4_ptr *p, ccp4_constptr data, const int n, const size_t reclen)
+{
+ ccp4array_base *v;
+ ccp4_byteptr newdata;
+ int osize, i;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ osize = v->size;
+ ccp4array_resize_(p, osize+n, reclen);
+ newdata = (ccp4_byteptr)(*p)+osize*reclen;
+ for ( i = 0; i < n; i++ ) {
+ memcpy(newdata, data, reclen);
+ newdata += reclen;
+ }
+}
+
+void ccp4array_append_list_(ccp4_ptr *p, ccp4_constptr data, const int n, const size_t reclen)
+{
+ ccp4array_base *v;
+ int osize;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ osize = v->size;
+ ccp4array_resize_(p, osize+n, reclen);
+ memcpy((ccp4_byteptr)(*p)+osize*reclen, data, n * reclen);
+}
+
+void ccp4array_insert_(ccp4_ptr *p, const int i, ccp4_constptr data, const size_t reclen)
+{
+ ccp4array_base *v;
+ int osize;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ osize = v->size;
+ ccp4array_resize_(p, osize+1, reclen);
+ memmove((ccp4_byteptr)(*p)+(i+1)*reclen, (ccp4_byteptr)(*p)+i*reclen, (osize-i)*reclen);
+ memcpy((ccp4_byteptr)(*p)+i*reclen, data, reclen);
+}
+
+void ccp4array_delete_ordered_(ccp4_ptr *p, const int i, const size_t reclen)
+{
+ ccp4array_base *v;
+ int nsize;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ nsize = v->size - 1;
+ memmove((ccp4_byteptr)(*p)+i*reclen, (ccp4_byteptr)(*p)+(i+1)*reclen, (nsize-i)*reclen);
+ v->size--; /* ccp4array_resize_(p, nsize, reclen); */
+}
+
+void ccp4array_delete_(ccp4_ptr *p, const int i, const size_t reclen)
+{
+ ccp4array_base *v;
+ int nsize;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ nsize = v->size - 1;
+ memcpy((ccp4_byteptr)(*p)+i*reclen, (ccp4_byteptr)(*p)+nsize*reclen, reclen);
+ v->size--; /* ccp4array_resize_(p, size, reclen); */
+}
+
+void ccp4array_delete_last_(ccp4_ptr *p, const size_t reclen)
+{
+ ccp4array_base *v;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ v->size--; /* ccp4array_resize_(p, v->size-1, reclen); */
+}
+
+int ccp4array_size_(ccp4_constptr *p)
+{
+ ccp4array_base *v;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ return v->size;
+}
+
+void ccp4array_free_(ccp4_ptr *p)
+{
+ ccp4array_base *v;
+ v = (ccp4array_base *)((ccp4_byteptr)(*p)-sizeof(ccp4array_base));
+ free(v);
+}
diff --git a/ccp4c/ccp4/ccp4_array.h b/ccp4c/ccp4/ccp4_array.h
new file mode 100644
index 00000000..64147b63
--- /dev/null
+++ b/ccp4c/ccp4/ccp4_array.h
@@ -0,0 +1,251 @@
+/*
+ ccp4_array.h: header file for resizable array implementation.
+ Copyright (C) 2002 Kevin Cowtan
+
+ This library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ version 3, modified in accordance with the provisions of the
+ license to address the requirements of UK law.
+
+ You should have received a copy of the modified GNU Lesser General
+ Public License along with this library. If not, copies may be
+ downloaded from http://www.ccp4.ac.uk/ccp4license.php
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+*/
+
+/** @file ccp4_array.h
+ * header file for resizable array implementation.
+ * Kevin Cowtan
+ */
+
+/*
+CCP4 resizable array implementation.
+
+This defines an object and methods which looks just like a simple C
+array, but can be resized at will without incurring excessive
+overheads.
+
+A pointer to the desired type is created. Array elements are accessed
+from this pointer as normal. Other operations depend on macros which
+extract the stored type from the type of the pointer.
+
+The array is managed with a header, which is positioned before the
+beginning of the array. The malloc'ed memory area starts at the
+beginning of this header. However the pointer to the header is not
+stored, but rather derived from the array pointer whenever it is
+required.
+
+Arrays have a size and a capacity. The size is the number of elements
+in use, and the capacity is the number of elements available before a
+new memory allocation is required. When new memory is required, an
+excess is reqested to allow the array to grow further before
+performing another malloc.
+
+If the precise amount of memory is known, the capacity can be
+controlled directly using the 'reserve' macro.
+
+Example: to handle an array of type mytype:
+
+\code
+ int i;
+ mytype x,y;
+ mytype *array;
+
+ ccp4array_new(array);
+
+ ccp4array_append_n(array, x, 3);
+
+ for ( i = 0; i < 3; i++ ) y = array[i];
+
+ ccp4array_free(array);
+\endcode
+*/
+
+#ifndef __CCP4_ARRAY_INC
+#define __CCP4_ARRAY_INC
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+#include
+/* rcsidha[] = "$Id$" */
+
+/*! constant pointer type */
+typedef const void *ccp4_constptr;
+/*! byte pointer type */
+typedef char *ccp4_byteptr;
+/*! pointer type */
+typedef void *ccp4_ptr;
+
+/*! struct definition for the array pre-header */
+typedef struct ccp4array_base_ {
+ int size, capacity;
+} ccp4array_base;
+
+/*! Macro to allocate a new array.
+ The array is allocated with a size and capacity of 0
+ \param v The array pointer
+ \return The new array pointer (redundent)
+*/
+#define ccp4array_new(v) ccp4array_new_((ccp4_ptr*)(&v))
+
+/*! Macro to allocate a new array with non-zero size.
+ The array is allocated with a size of s and capacity of at least s
+ \param v The array pointer
+ \param s The new size
+ \return The new array pointer (redundent)
+*/
+#define ccp4array_new_size(v,s) ccp4array_new_size_((ccp4_ptr*)(&v),s,sizeof(*v))
+
+/*! Macro to resize an array.
+ This changes the size. Memory allocation only takes place if the new
+ size is greater than the capacity. If that occurs, the new capacity
+ will be slightly greater than the requested size, to allow room for
+ expansion.
+ \param v The array pointer
+ \param s The new size
+*/
+#define ccp4array_resize(v,s) ccp4array_resize_((ccp4_ptr*)(&v),s,sizeof(*v))
+
+/*! Macro to reserve space for an array.
+ This forces a memory reallocation. The size of the array is
+ unchanged, unless the new capacity is less than the current size, in
+ which case the size is set to the new capacity. Unlike resize, the
+ new allocation will be exactly the size of the array.
+ \param v The array pointer
+ \param s The new capacity
+*/
+#define ccp4array_reserve(v,s) ccp4array_reserve_((ccp4_ptr*)(&v),s,sizeof(*v))
+
+/*! Macro to append an element to an array.
+ This increments the size. Memory allocation only takes place if the new
+ size is greater than the capacity.
+ \param v The array pointer
+ \param d The new element (may not be a literal)
+*/
+#define ccp4array_append(v,d) ccp4array_append_((ccp4_ptr*)(&v),(ccp4_constptr)(&d),sizeof(*v))
+
+/*! Macro to append n copies of an element to an array.
+ This increments the size by n. Memory allocation only takes place if the new
+ size is greater than the capacity.
+ \param v The array pointer
+ \param d The new element (may not be a literal)
+ \param n The number of copies to append
+*/
+#define ccp4array_append_n(v,d,n) ccp4array_append_n_((ccp4_ptr*)(&v),(ccp4_constptr)(&d),n,sizeof(*v))
+
+/*! Macro to append n elements from another list to an array.
+ This increment the size by n. Memory allocation only takes place if the new
+ size is greater than the capacity.
+ \param v The array pointer
+ \param l Pointer to the list
+ \param n The number of copies to append
+*/
+#define ccp4array_append_list(v,l,n) ccp4array_append_list_((ccp4_ptr*)(&v),(ccp4_constptr)l,n,sizeof(*v))
+
+/*! Macro to insert an element before the element[i] of an array.
+ This increments the size. All subsequent elements are moved up. As a
+ result this method is slow.
+ \param v The array pointer
+ \param d The new element (may not be a literal)
+ \param i The element before which the insertion is to be made.
+*/
+#define ccp4array_insert(v,i,d) ccp4array_insert_((ccp4_ptr*)(&v),i,(ccp4_constptr)(&d),sizeof(*v))
+
+/*! Macro to delete element[i] of an array, preserving order.
+ This decrements the size. All subsequent elements are moved down. As a
+ result this method is slow.
+ \param v The array pointer
+ \param i The element to be deleted
+*/
+#define ccp4array_delete_ordered(v,i) ccp4array_delete_ordered_((ccp4_ptr*)(&v),i,sizeof(*v))
+
+/*! Macro to delete element[i] of an array without preserving order. The
+ last element is moved into the gap, and the size is decremented.
+ \param v The array pointer
+ \param i The element to be deleted
+*/
+#define ccp4array_delete(v,i) ccp4array_delete_((ccp4_ptr*)(&v),i,sizeof(*v))
+
+/*! Macro to delete the last element of an array.
+ This decrements the size.
+ \param v The array pointer
+*/
+#define ccp4array_delete_last(v) ccp4array_delete_last_((ccp4_ptr*)(&v),sizeof(*v))
+
+/*! Macro to return the size of the array.
+ \param v The array pointer
+ \return The size (int)
+*/
+#define ccp4array_size(v) ccp4array_size_((ccp4_constptr*)(&v))
+
+/*! Macro free the array.
+ All memory, including the header, is freed.
+ \param v The array pointer
+*/
+#define ccp4array_free(v) ccp4array_free_((ccp4_ptr*)(&v))
+
+/**
+ * See macro ccp4array_new
+*/
+ccp4_ptr ccp4array_new_(ccp4_ptr *p);
+/**
+ * See macro ccp4array_new_size
+*/
+ccp4_ptr ccp4array_new_size_(ccp4_ptr *p, const int size, const size_t reclen);
+/**
+ * See macro ccp4array_resize
+*/
+void ccp4array_resize_(ccp4_ptr *p, const int size, const size_t reclen);
+/**
+ * See macro ccp4array_reserve
+*/
+void ccp4array_reserve_(ccp4_ptr *p, const int size, const size_t reclen);
+/**
+ * See macro ccp4array_append
+*/
+void ccp4array_append_(ccp4_ptr *p, ccp4_constptr data, const size_t reclen);
+/**
+ * See macro ccp4array_append_n
+*/
+void ccp4array_append_n_(ccp4_ptr *p, ccp4_constptr data, const int n, const size_t reclen);
+/**
+ * See macro ccp4array_append_list
+*/
+void ccp4array_append_list_(ccp4_ptr *p, ccp4_constptr data, const int n, const size_t reclen);
+/**
+ * See macro ccp4array_insert
+*/
+void ccp4array_insert_(ccp4_ptr *p, const int i, ccp4_constptr data, const size_t reclen);
+/**
+ * See macro ccp4array_delete_ordered
+*/
+void ccp4array_delete_ordered_(ccp4_ptr *p, const int i, const size_t reclen);
+/**
+ * See macro ccp4array_delete
+*/
+void ccp4array_delete_(ccp4_ptr *p, const int i, const size_t reclen);
+/**
+ * See macro ccp4array_delete_last
+*/
+void ccp4array_delete_last_(ccp4_ptr *p, const size_t reclen);
+/**
+ * See macro ccp4array_size
+*/
+int ccp4array_size_(ccp4_constptr *p);
+/**
+ * See macro ccp4array_free
+*/
+void ccp4array_free_(ccp4_ptr *p);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CCP4_ARRAY_INC */
diff --git a/ccp4c/ccp4/ccp4_errno.h b/ccp4c/ccp4/ccp4_errno.h
new file mode 100644
index 00000000..3e9bc659
--- /dev/null
+++ b/ccp4c/ccp4/ccp4_errno.h
@@ -0,0 +1,166 @@
+/*
+ ccp4_errno.h: Header file for error handling routines
+ Copyright (C) 2001 CCLRC, Charles Ballard and Martyn Winn
+
+ This library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ version 3, modified in accordance with the provisions of the
+ license to address the requirements of UK law.
+
+ You should have received a copy of the modified GNU Lesser General
+ Public License along with this library. If not, copies may be
+ downloaded from http://www.ccp4.ac.uk/ccp4license.php
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+*/
+/** @file ccp4_errno.h
+ * Header file for error handling routines
+ * base error codes on system errors.
+ */
+
+#ifndef __CCP4_ERROR_GUARD
+#define __CCP4_ERROR_GUARD
+
+#include
+#include "ccp4_sysdep.h"
+
+/* rcsidhe[] = "$Id$" */
+
+#ifndef CCP4_ERRSYSTEM
+#define CCP4_ERRSYSTEM(x) (((x)&0xfff)<<24)
+#endif
+#ifndef CCP4_ERRLEVEL
+#define CCP4_ERRLEVEL(x) (((x)&0xf)<<16)
+#endif
+#ifndef CCP4_ERRSETLEVEL
+#define CCP4_ERRSETLEVEL(y,x) ((y) & (~CCP4_ERRLEVEL(0xf)) | CCP4_ERRLEVEL(x)))
+#endif
+#ifndef CCP4_ERRGETSYS
+#define CCP4_ERRGETSYS(x) (((x)>>24)&0xfff)
+#endif
+#ifndef CCP4_ERRGETLEVEL
+#define CCP4_ERRGETLEVEL(x) (((x)>>16)&0xf)
+#endif
+#ifndef CCP4_ERRGETCODE
+#define CCP4_ERRGETCODE(x) ((x)&0xffff)
+#endif
+
+#define CCP4_ERR_SYS CCP4_ERRSYSTEM(0x0)
+#define CCP4_ERR_FILE CCP4_ERRSYSTEM(0x1)
+#define CCP4_ERR_COORD CCP4_ERRSYSTEM(0x2)
+#define CCP4_ERR_MTZ CCP4_ERRSYSTEM(0x3)
+#define CCP4_ERR_MAP CCP4_ERRSYSTEM(0x4)
+#define CCP4_ERR_UTILS CCP4_ERRSYSTEM(0x5)
+#define CCP4_ERR_PARS CCP4_ERRSYSTEM(0x6)
+#define CCP4_ERR_SYM CCP4_ERRSYSTEM(0x7)
+#define CCP4_ERR_GEN CCP4_ERRSYSTEM(0x8)
+
+#define CCP4_COUNT(x) sizeof(x)/sizeof(x[0])
+
+/** @global ccp4_errno: global variable that stores the error last error
+ * code from the ccp4 libraries
+ * | 12 bits - library | 4 bits - level | 16 bits - code |
+ *
+ * associated macros
+ * CCP4_ERR_SYS 0 OS error
+ * CCP4_ERR_FILE 1 io library
+ * CCP4_ERR_COORD 2 mmdb
+ * CCP4_ERR_MTZ 3 cmtz
+ * CCP4_ERR_MAP 4 map io
+ * CCP4_ERR_UTILS 5 utility routines
+ * CCP4_ERR_PARS 6 parser routines
+ * CCP4_ERR_SYM 7 csymlib
+ *
+ * and bit manipulation
+ * CCP4_ERRSYSTEM system mask for setting
+ * CCP4_ERRLEVEL error level mask
+ * CCP4_ERRSETLEVEL error level mask for setting error level
+ * CCP4_ERRGETSYS mask for returning system
+ * CCP4_ERRGETLEVEL mask for returning level
+ * CCP4_ERRGETCODE mask for returning the code
+ *
+ * error levels
+ * 0 Success
+ * 1 Informational
+ * 2 Warning
+ * 3 Error
+ * 4 Fatal
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern CCP4_DL_IMPORT(int) ccp4_errno;
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef __cplusplus
+namespace CCP4 {
+extern "C" {
+#endif
+
+/** Print out passed message and internal message based upon
+ * ccp4_errno
+ * "message : error message "
+ * @param message (const char *)
+ * @return void
+ */
+void ccp4_error( const char *);
+
+/** Obtain character string based upon error code.
+ * Typical use ccp4_strerror(ccp4_errno)
+ * The returned string is statically allocated in the
+ * library_err.c file and should not be freed.
+ * @param error code (int)
+ * @return const pointer to error message (const char *)
+ */
+const char *ccp4_strerror( int);
+
+/** Wrapper for ccp4_error which also calls exit(1)
+ * @param message (const char *)
+ * @return void
+ */
+void ccp4_fatal(const char *);
+
+/** Function to set verbosity level for messages from
+ * ccp4_signal. Currently just off (0) and on (1).
+ * It should be generalised to be able to switch
+ * individual components on and off, i.e. replace 1 by
+ * a mask.
+ * cf. ccp4VerbosityLevel which sets the verbosity level
+ * for ccp4printf These are separate as they may be used
+ * differently.
+ * @param iverb If >= 0 then set the verbosity level to the
+ * value of iverb. If < 0 (by convention -1) then report
+ * current level.
+ * @return current verbosity level
+ */
+int ccp4_liberr_verbosity(int iverb);
+
+/** Routine to set ccp4_errno and print out message for
+ * error tracing. This should be the only way in
+ * which ccp4_errno is set.
+ * See error codes above for levels and systems.
+ * A callback with prototype void function(void)
+ * may also be passed to the routine.
+ * Note: FATAL calls exit(1).
+ * If ccp4_liberr_verbosity returns 0, then ccp4_signal sets
+ * ccp4_errno and returns without doing anything else.
+ * @param error code (int)
+ * @param message (const char * const)
+ * @param callback (point to routine void (*)(void) )
+ * @return void
+ */
+void ccp4_signal(const int, const char *const, void (*)());
+
+int cfile_perror(const char *);
+
+#ifdef __cplusplus
+}
+}
+#endif
+
+#endif /*!CCP4_ERROR_GUARD */
diff --git a/ccp4c/ccp4/ccp4_file_err.h b/ccp4c/ccp4/ccp4_file_err.h
new file mode 100644
index 00000000..6f6ae483
--- /dev/null
+++ b/ccp4c/ccp4/ccp4_file_err.h
@@ -0,0 +1,38 @@
+/*
+ ccp4_file_err.h: header file with file handling error codes
+ Copyright (C) 2001 CCLRC, Charles Ballard
+
+ This library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ version 3, modified in accordance with the provisions of the
+ license to address the requirements of UK law.
+
+ You should have received a copy of the modified GNU Lesser General
+ Public License along with this library. If not, copies may be
+ downloaded from http://www.ccp4.ac.uk/ccp4license.php
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+*/
+#ifndef _GUARD_FILE_ERR
+#define _GUARD_FILE_ERR
+
+#define CCP4_ERRNO(y) (CCP4_ERR_FILE | (y))
+#define CIO_Ok 0
+#define CIO_BadMode 1
+#define CIO_CantOpenFile 2
+#define CIO_MaxFile 3
+#define CIO_ReadFail 4
+#define CIO_WriteFail 5
+#define CIO_CloseFail 6
+#define CIO_SeekFail 7
+#define CIO_NullPtr 8
+#define CIO_EOF 9
+#define CIO_NoFile 10
+#define CIO_NotOpen 11
+#define CIO_UnlinkFail 12
+
+#endif
+
diff --git a/ccp4c/ccp4/ccp4_fortran.h b/ccp4c/ccp4/ccp4_fortran.h
new file mode 100644
index 00000000..ea79b65c
--- /dev/null
+++ b/ccp4c/ccp4/ccp4_fortran.h
@@ -0,0 +1,393 @@
+/*
+ ccp4_fortran.h: header file for Fortran APIs
+ Copyright (C) 2001 Eugene Krissinel
+
+ This library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ version 3, modified in accordance with the provisions of the
+ license to address the requirements of UK law.
+
+ You should have received a copy of the modified GNU Lesser General
+ Public License along with this library. If not, copies may be
+ downloaded from http://www.ccp4.ac.uk/ccp4license.php
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+*/
+
+/** @file ccp4_fortran.h
+ * header file for Fortran APIs
+ * Eugene Krissinel
+ */
+
+#ifndef __CCP4_FORTRAN
+#define __CCP4_FORTRAN
+
+#include "ccp4_types.h"
+/* rcsidhh[] = "$Id$" */
+
+/* stardent is now obsolete, but we retain this category in case it is useful later */
+#ifdef CALL_LIKE_STARDENT
+ /* SStrParam is used in Ardent-like machines' fortran calls */
+ /* for passing a string parameter */
+ DefineStructure(SStrPar)
+ struct SStrPar {
+ pstr S;
+ int len;
+ int id;
+ };
+#endif
+
+#define _LVTOB(l) ((long) ((l) == 0 ? 0 : 1))
+#define _BTOLV(l) ((int) ((l) == 0 ? 0 : 1))
+#if defined (__OSF1__) || defined (__osf__)
+#undef _BTOLV
+#define _BTOLV(l) ((int) ((l) == 0 ? 0 : -1))
+#endif
+
+/*
+ Macro FORTRAN_SUBR(NAME,name,p_send,p_sstruct,p_sflw)
+ makes function header statements that allow for linking with
+ programs written in FORTRAN.
+
+ Parameters:
+
+ NAME name of the FORTRAN subroutine in capital letters
+ name name of the FORTRAN subroutine in small letters
+ p_send parameter list (in brackets) with string lengths
+ attached to the end of it (see below)
+ p_sstruct parameter list (in brackets) with strings passed
+ as complex parameters, or structures
+ p_sflw parameter list (in brackets) with string lengths
+ following immediately the string parameters
+ (see below)
+
+ All non-string parameters must be passed as pointers, in
+ the same order as they enter the FORTRAN call. Rules for
+ the string parameters are as follows.
+
+ 1. All strings should be specified as of 'fpstr' type.
+ The 'fpstr' type is defined below and depends on the
+ platform:
+
+ a) whenever length of string is passed as a separate
+ parameter ( CALL_LIKE_SUN, CALL_LIKE_HPUX,
+ CALL_LIKE_MVS ) 'fpstr' is identical to 'pstr'.
+ You may choose arbitrary name for the string,
+ but you MUST use the same name, appended with
+ suffix '_len', for its length (see example below).
+
+ b) whenever string and its length are passed as
+ complex parameter, 'fpstr' is identical to the
+ pointer on the corresponding structure:
+ CALL_LIKE_STARDENT :
+ 'fpstr' is identical to 'PSStrPar'
+ CALL_LIKE_VMS :
+ 'fpstr' is identical to 'dsc$descriptor_s *'
+
+ With 'fpstr' type, two important macro definition come:
+
+ i) FTN_STR(s) - returns pointer to fortran-passed
+ string s. This pointer is always
+ of 'pstr' type
+ ii) FTN_LEN(s) - returns integer length of fortran-
+ passed string s. For this macro to
+ work properly with SUN- and MVS-like
+ machines, always use suffix '_len'
+ for the string length parameters as
+ described in a) above.
+
+ 2. Three parameter lists, each enclosed in brackets, should
+ be given. These lists retain the general order of
+ parameters in the corresponding fortran call. Non-string
+ parameters are passed as pointers. String parameters
+ and their lengths are passed differently in different
+ lists:
+
+ p_send strings enter their place in the list as in
+ the corresponding FORTRAN call, having 'fpstr'
+ parameter type. Their lengths are appended as
+ 'int' to the end of the list. They should
+ retain the order in which the strings appear
+ in the list.
+
+ p_sstruct strings enter their place in the list as in
+ the corresponding FORTRAN call, having 'fpstr'
+ parameter type.
+
+ p_sflw strings enter their place in the list as in
+ the corresponding FORTRAN call, having 'fpstr'
+ type and being immediately followed by their
+ lengths as 'int' parameters.
+
+
+
+ Example:
+
+ FORTRAN statement
+
+ subroutine SomeSub ( k,s1,a,s2,m )
+ integer k,m
+ real a
+ character*(*) s1,s2
+
+ is translated to
+
+ FORTRAN_SUBR ( SOMESUB, somesub,
+ ( int * k, fpstr s1, float * a, fpstr s2, int * m,
+ int s1_len, int s2_len ),
+ ( int * k, fpstr s1, float * a, fpstr s2, int * m ),
+ ( int * k, fpstr s1, int s1_len, float * a,
+ fpstr s2, int s2_len, int * m ) )
+
+
+ The macro should replace ordinary function header
+ statements to assure compatibility with FORTRAN links.
+ In header files, do not forget to add semicolumn:
+
+ FORTRAN_SUBR ( .... );
+
+ while in source files use simply
+
+ FORTRAN_SUBR ( .... ) {
+
+ }
+
+
+
+ Macro FORTRAN_CALL(NAME,name,p_send,p_sstruct,p_sflw)
+ calls function defined with macro FORTRAN_SUBR(...), from
+ a C/C++ application. Its parameters and their meaning are
+ exactly identical to those of FORTRAN_SUBR(...).
+ FORTRAN_CALL(...) should be followed by semicolon. */
+
+
+#if defined(CALL_LIKE_SUN)
+
+ typedef pstr fpstr;
+#if __GNUC__ > 7 || __clang_major__ > 10
+ typedef size_t fpstr_size_t;
+#else
+ typedef int fpstr_size_t;
+#endif
+
+#define FTN_STR(s) s
+#define FTN_LEN(s) s##_len
+
+#define char_struct(s) \
+ pstr s; \
+ int s##_len;
+#define fill_char_struct(s,str) \
+ s = str; \
+ s##_len = strlen(str);
+#define init_char_struct(s,str,size) \
+ s = str; \
+ s##_len = size;
+
+#define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
+ void name##_ p_sun
+#define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
+ name##_ p_sun
+#define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
+ val name##_ p_sun
+#elif defined(CALL_LIKE_HPUX)
+
+ typedef pstr fpstr;
+ typedef int fpstr_size_t;
+
+# define FTN_STR(s) s
+# define FTN_LEN(s) s##_len
+
+# define char_struct(s) \
+ pstr s; \
+ int s##_len;
+# define fill_char_struct(s,str) \
+ s = str; \
+ s##_len = strlen(str);
+# define init_char_struct(s,str,size) \
+ s = str; \
+ s##_len = size;
+
+# define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
+ void name p_sun
+# define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
+ name p_sun
+# define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
+ val name p_sun
+#elif defined(CALL_LIKE_STARDENT)
+
+ typedef PStrPar fpstr;
+ typedef int fpstr_size_t;
+
+# define FTN_STR(s) s->Str_pointer
+# define FTN_LEN(s) s->Str_length
+
+# define char_struct(s) \
+ SStrPar s;
+# define fill_char_struct(s,str) \
+ s.S = str; \
+ s.len = strlen(FName); \
+ s.id = 0;
+# define init_char_struct(s,str,size) \
+ s.S = str; \
+ s.len = size; \
+ s.id = 0;
+
+# define FORTRAN_SUBR(NAME,name,p_send,p_sstruct,p_sflw) \
+ void NAME p_stardent
+# define FORTRAN_CALL(NAME,name,p_send,p_sstruct,p_sflw) \
+ NAME p_stardent
+# define FORTRAN_FUN(val,NAME,name,p_send,p_sstruct,p_sflw) \
+ val NAME p_stardent
+
+#elif defined(CALL_LIKE_VMS)
+
+ typedef dsc$descriptor_s * fpstr;
+
+# define FTN_STR(s) s->dsc$a_pointer;
+# define FTN_LEN(s) s->dsc$w_length;
+
+# define char_struct(s) \
+ dsc$descriptor_s s;
+# define fill_char_struct(s,str) \
+ s.dsc$a_pointer = str; \
+ s.dsc$w_length = strlen(str); \
+ s.dsc$b_dtype = DSC$K_DTYPE_T; \
+ s.dsc$b_class = DSC$K_CLASS_S;
+# define init_char_struct(s,str,size) \
+ s.dsc$a_pointer = str; \
+ s.dsc$w_length = size; \
+ s.dsc$b_dtype = DSC$K_DTYPE_T; \
+ s.dsc$b_class = DSC$K_CLASS_S;
+
+# define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
+ void NAME p_stardent
+# define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
+ NAME p_stardent
+# define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
+ val NAME p_stardent
+
+#elif defined(CALL_LIKE_MVS)
+
+#if (CALL_LIKE_MVS == 2)
+
+ typedef pstr fpstr;
+ typedef int fpstr_size_t;
+
+#define FTN_STR(s) s
+#define FTN_LEN(s) s##_len
+
+#define char_struct(s) \
+ pstr s; \
+ int s##_len;
+#define fill_char_struct(s,str) \
+ s = str; \
+ s##_len = strlen(str);
+#define init_char_struct(s,str,size) \
+ s = str; \
+ s##_len = size;
+
+#define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
+ void NAME p_sun
+#define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
+ NAME p_sun
+#define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
+ val NAME p_sun
+
+#else
+
+ typedef pstr fpstr;
+ typedef int fpstr_size_t;
+
+# define FTN_STR(s) s
+# define FTN_LEN(s) s##_len
+
+# define char_struct(s) \
+ pstr s; \
+ int s##_len;
+# define fill_char_struct(s,str) \
+ s = str; \
+ s##_len = strlen(str);
+# define init_char_struct(s,str,size) \
+ s = str; \
+ s##_len = size;
+
+# define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
+ void __stdcall NAME p_mvs
+# define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
+ NAME p_mvs
+# define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
+ val __stdcall NAME p_mvs
+
+# endif
+
+#else
+
+# error Unknown machine!!!
+
+ typedef pstr fpstr;
+ typedef int fpstr_size_t;
+
+# define FTN_STR(s) s
+# define FTN_LEN(s) s##_len
+
+# define char_struct(s) \
+ pstr s; \
+ int s##_len;
+# define fill_char_struct(s,str) \
+ s = str; \
+ s##_len = strlen(str);
+# define init_char_struct(s,str,size) \
+ s = str; \
+ s##_len = size;
+
+/** Macro to define a function such that it is callable as
+ * a Fortran subroutine.
+ * @param NAME Subroutine name in upper case
+ * @param name Subroutine name in lower case
+ * @param p_sun Argument list in Sun style
+ * @param p_stardent Argument list in Stardent style
+ * @param p_mvs Argument list in MVS style
+*/
+# define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
+ void name##_ p_sun
+
+/** Macro to call a Fortran subroutine from a C function.
+ * @param NAME Subroutine name in upper case
+ * @param name Subroutine name in lower case
+ * @param p_sun Argument list in Sun style
+ * @param p_stardent Argument list in Stardent style
+ * @param p_mvs Argument list in MVS style
+*/
+# define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
+ name##_ p_sun
+
+/** Macro to define a function such that it is callable as
+ * a Fortran function.
+ * @param val Data type of return value.
+ * @param NAME Function name in upper case
+ * @param name Function name in lower case
+ * @param p_sun Argument list in Sun style
+ * @param p_stardent Argument list in Stardent style
+ * @param p_mvs Argument list in MVS style
+*/
+# define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
+ val name##_ p_sun
+
+#endif
+
+/* Define Fortran logical */
+typedef unsigned int ftn_logical;
+#define FORTRAN_LOGICAL_TRUE 1
+#define FORTRAN_LOGICAL_FALSE 0
+#if defined (__OSF1__) || defined (__osf__)
+# undef FORTRAN_LOGICAL_TRUE
+# define FORTRAN_LOGICAL_TRUE -1
+#endif
+
+char *ccp4_FtoCString(fpstr str1, int str1_len);
+void ccp4_CtoFString(fpstr str1, int str1_len, const char *cstring);
+
+#endif /* __CCP4_FORTRAN */
diff --git a/ccp4c/ccp4/ccp4_general.c b/ccp4c/ccp4/ccp4_general.c
new file mode 100644
index 00000000..4c0d38fa
--- /dev/null
+++ b/ccp4c/ccp4/ccp4_general.c
@@ -0,0 +1,1436 @@
+/*
+ ccp4_general.c: General library functions and utilities.
+ Copyright (C) 2001 CCLRC, Peter Briggs et al
+
+ This library is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ version 3, modified in accordance with the provisions of the
+ license to address the requirements of UK law.
+
+ You should have received a copy of the modified GNU Lesser General
+ Public License along with this library. If not, copies may be
+ downloaded from http://www.ccp4.ac.uk/ccp4license.php
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+*/
+
+/** @file ccp4_general.c
+ * General library functions and utilities.
+ * Peter Briggs et al
+ */
+
+/* ccp4_general.c
+ Peter Briggs CCP4 May 2001/Feb 2003
+
+ General library functions and utilities
+
+ ccperror(level,message)
+ Error reporting and program termination
+
+ ccp4printf(level,format,printargs)
+ A wrapper for vprintf - acts like printf with an additional
+ argument which is checked against the reference verbosity
+ level.
+
+ ccp4fyp(argc,argv)
+ Initialise environment for CCP4 programs and parse the
+ command line arguments
+
+ ccp4setenv(logical_name,value,envname,envtype,envext,ienv,
+ no_overwrt)
+ Set up file names and associate with logical_name in
+ environment
+
+ ccpexists(filename)
+ Check if file exists and can be opened for reading
+
+ ccpputenv(logical_name,file_name)
+ Set environment variable logical_name to have value file_name
+*/
+
+/*------------------------------------------------------------------*/
+
+/* CCP4 library clones */
+
+#include
+#include
+#include
+#include
+
+#ifdef HAVE_CONFIG_H
+#include /* PACKAGE_ROOT */
+#endif
+/* Library header files */
+#include "ccp4_fortran.h"
+#include "ccp4_utils.h"
+#include "ccp4_parser.h"
+#include "ccp4_general.h"
+#include "ccp4_program.h"
+#include "cmtzlib.h"
+#include "csymlib.h"
+#include "ccp4_errno.h"
+/* rcsid[] = "$Id$" */
+
+/*------------------------------------------------------------------*/
+
+/* ccperror
+
+ Error reporting and program termination
+
+ ccperror is called with a message level ierr and a message string
+ The exact behaviour is determined by the value of ierr:
+
+ 0 : normal termination and stop
+ 1 : fatal error and stop
+ 2 : report severe warning
+ 3 : report information
+ 4 : report from library
+
+ ierr=-1 also reports last system error and terminates.
+
+ The text in message is sent to standard output, and to standard
+ error for ierr=1 (or -1).
+
+*/
+int ccperror(int ierr, const char *message)
+{
+ /* Execute user-defined function callback */
+ ccp4InvokeCallback(ierr,message);
+ /* Do messaging */
+ ccperror_noexit(ierr, message);
+ /* Exit if necessary */
+ if (ierr==0) {
+ exit(0);
+ } else if (ierr==1 || ierr==-1) {
+ exit(1);
+ }
+ return 0;
+}
+
+/* ccperror_noexit
+
+ As above, but doesn't call exit()
+
+*/
+
+int ccperror_noexit(int ierr, const char *message)
+{
+ char *prog_name=NULL;
+
+ /* Get the program name */
+ prog_name = ccp4ProgramName(NULL);
+ if (!prog_name) prog_name = strdup("CCP4");
+
+ if (ierr==0) {
+ /* Level 0 : normal termination */
+ ccp4printf(0," %s: %s\n",prog_name,message);
+ /* Get the amount of time elapsed since start of
+ program. Initialised by ccp4fyp */
+ ccp4ProgramTime(0);
+
+ /* closing tags - these are simplified w.r.t. Fortranic
+ versions for this special case */
+ if (html_log_output(-1)) {
+ printf("\n");
+ printf("