Commits

Matthew Turk committed d59972e

Importing version 0.99 of Rockstar

Comments (0)

Files changed (104)

Binary file added.

Binary file added.

+The initial version of Rockstar would not have been possible without the contributions of a very large number of people.  Along with Risa Wechsler and Hao-Yi Wu, the co-authors of the original paper (http://arxiv.org/abs/1110.4372), we would like to thank Anatoly Klypin, Joel Primack, Michael Busha, Houjun Mo, Alexie Leauthaud, Andrey Kravtsov, James Bullock, Alex Knebe, Rachel Reddick, Yu Lu, Oliver Hahn, Matt Becker, Louie Strigari, Jeremy Tinker, Tom Abel, Steven Rieder, Markus Haider, Shea Garrison-Kimmel, Gus Evrard, Marcelo Alvarez, Joanne Cohn, Martin White, Simon White, Manodeep Sinha, and Annika Peters for interesting discussions, helpful suggestions, and testing. We gratefully acknowledge the support of Stuart Marshall and the SLAC computational team, as well as the computational resources at SLAC, NASA, and Teragrid/XSEDE.  I (PSB) and Risa (RHW) received support from NASA HST Theory grant HST-AR-12159.01-A; RHW was also supported by the National Science Foundation under grant NSF AST-0807312.  This work was additionally supported by the U.S. Department of Energy under contract number DE-AC02-76SF00515.
+
+Since the release of the initial public version (v0.96.2), I would also like to acknowledge the following contributors:
+
+*) Matt Turk: YT support
+*) Greg Stinson: TIPSY support
+v0.99 (3/19/2012):
+*) Updated the unbinding calculation to use physical velocities instead of peculiar velocities.
+*) Improved network layer now supports transparent auto-healing in case of connection failures and better rejection of non-Rockstar connections.
+*) No lower boxsize limit for non-periodic boundary conditions.
+*) A utility for calculating host-subhalo relationships is now included (see README).
+*) Included example source code for reading the particle output formats (see examples/).
+
+v0.98.5 (1/10/2012):
+*) Fixed an important issue with calculating Vrms: previously, it was calculated using all particles associated to the halo, instead of just those within the halo radius R_delta (thanks to Michael Busha for catching this).
+*) Added support for easy restarting of Rockstar if it terminates in the middle of a run for any reason.  (See restart.cfg in README).
+*) Added support for specifying the GADGET halo particle type (if it is not the default, 1).
+*) Support for the undocumented "GADGET_INTERNAL" format was removed.
+*) Added missing support for auto server port when server address is specified.
+
+v0.98 (12/27/2011):
+*) Increased the speed of boundary checks; the particle distribution stage is now more efficient.
+*) Fixed an issue whereby duplicate halos could be output in merger trees; this only appears on certain versions of Linux when there are very few halos per processor (thanks to Markus Haider for finding this!).
+*) Fixed two issues where calculating the position and velocity variance of particle groups would in hang in rare instances (Thanks to Michael Busha for finding the first of these!).
+*) Fixed a mistake in the IO code which prevented TIPSY support from working (Thanks to Michael Busha for catching this!).
+*) Updated the readme to be clearer about how to run Rockstar in master/client mode.
+
+v0.97.1:
+*) Added support for user-configurable load-balancing.
+
+v0.97 (11/1/2011):
+*) Fixed a race condition which was halting execution for snapshots without any halos.
+*) Included config files to run on the Ranger machine at TACC.
+*) Added YT support (from Matt Turk).
+*) Added initial/alpha support for reading TIPSY files (from Greg Stinson).
+
+v0.96.2 (10/20/2011):
+Initial public release
+		    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ 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.
+
+  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 MERCHANTABILITY AND 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.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  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.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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 <http://www.gnu.org/licenses/>.
+
+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:
+
+    <program>  Copyright (C) <year>  <name of author>
+    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
+<http://www.gnu.org/licenses/>.
+
+  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
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+CFLAGS=-m64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_BSD_SOURCE -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200809L -D_SVID_SOURCE -D_DARWIN_C_SOURCE -Wall -fno-math-errno -fPIC
+LDFLAGS=-shared
+OFLAGS = -lm -O3 -std=c99
+DEBUGFLAGS = -lm -g -O3 -std=c99 -Dinline=
+PROFFLAGS = -lm -g -pg -O2 -std=c99
+CC = gcc
+CFILES = rockstar.c check_syscalls.c fof.c groupies.c subhalo_metric.c potential.c nfw.c jacobi.c fun_times.c universe_time.c distance.c config_vars.c config.c bounds.c litehash.c io/read_config.c client.c server.c merger.c inet/socket.c inet/rsocket.c inet/address.c io/meta_io.c io/io_internal.c io/io_ascii.c io/stringparse.c io/io_gadget.c io/io_generic.c io/io_art.c io/io_tipsy.c io/io_bgc2.c io/io_util.c
+DIST_FLAGS =
+
+all:
+	@make reg EXTRA_FLAGS="$(OFLAGS)"
+
+debug:
+	@make reg EXTRA_FLAGS="$(DEBUGFLAGS)"
+
+prof:
+	@make reg EXTRA_FLAGS="$(PROFFLAGS)"
+
+.REMAKE:
+
+dist: .REMAKE
+	cd ../ ; perl -ne 'print "$$1\n" if (/VERSION\s*\"([^\"]+)/)' Rockstar/version.h > Rockstar/VERSION; tar -czvf rockstar.tar.gz Rockstar/Makefile Rockstar/*.[ch] Rockstar/examples/Makefile Rockstar/[^st]*/*.[ch] Rockstar/quickstart.cfg Rockstar/parallel.cfg Rockstar/scripts/*.pbs Rockstar/scripts/*.cfg Rockstar/scripts/*.pl Rockstar/SOURCE_LAYOUT Rockstar/README Rockstar/LICENSE Rockstar/VERSION Rockstar/ACKNOWLEDGMENTS Rockstar/CHANGELOG; mv rockstar.tar.gz Rockstar
+
+versiondist:
+	$(MAKE) dist DIST_FLAGS="$(DIST_FLAGS)"
+	rm -rf dist
+	mkdir dist
+	cd dist; tar xzf ../rockstar.tar.gz ; perl -ne '/\#define.*VERSION\D*([\d\.]+)/ && print $$1' Rockstar/version.h > NUMBER ; mv Rockstar Rockstar-`cat NUMBER`; tar czf rockstar-`cat NUMBER`.tar.gz Rockstar-`cat NUMBER`
+
+reg:
+	$(CC) $(CFLAGS) main.c $(CFILES) -o rockstar  $(EXTRA_FLAGS)
+
+lib:
+	$(CC) $(CFLAGS) $(LDFLAGS) $(CFILES) -o librockstar.so $(OFLAGS)
+
+bgc2:
+	$(CC) $(CFLAGS) io/extra_bgc2.c util/redo_bgc2.c $(CFILES) -o util/finish_bgc2  $(OFLAGS)
+	$(CC) $(CFLAGS) io/extra_bgc2.c util/bgc2_to_ascii.c $(CFILES) -o util/bgc2_to_ascii  $(OFLAGS)
+
+parents:
+	$(CC) util/find_parents.c io/stringparse.c check_syscalls.c  -o util/find_parents $(CFLAGS) $(EXTRA_FLAGS)
+
+substats:
+	$(CC) $(CFLAGS) util/subhalo_stats.c $(CFILES) -o util/subhalo_stats  $(OFLAGS)
+
+
+clean:
+	rm -f *~ io/*~ inet/*~ util/*~ rockstar util/redo_bgc2 util/subhalo_stats
+
+The Rockstar Halo Finder
+Most code: Copyright (C) 2011,2012 Peter Behroozi
+License: GNU GPLv3
+Documentation Paper: http://arxiv.org/abs/1110.4372
+
+Contents:
+1) Compiling
+2) Running
+   i) Quick start (single snapshot)
+   ii) More complete setup (multiple snapshots/input files)
+   iii) Merger Trees
+   iv) Host / Subhalo relationships
+   v) Lightcone setup
+   vi) Controlling Output Formats
+   vii) Infiniband/Network Connectivity Notes
+   viii) Full configuration options
+   ix) Full example scripts
+   x) Example source code for loading particle outputs
+
+
+1) Compiling:
+   If you use the GNU C compiler version 4.0 or above on a 64-bit machine,
+   compiling should be as simple as typing "make" at the command prompt.
+
+   Rockstar does not support compiling on 32-bit machines and has not been
+   tested with other compilers.  Additionally, Rockstar does not support
+   non-Unix environments.  (Mac OS X is fine; Windows is not).
+
+2) Running
+   i) Quick start (single snapshot):
+      Several example configuration files have been provided.  If you have a
+      small simulation file and you'd like to run Rockstar on a single processor
+      to test its output, edit the file "quickstart.cfg" and change the file
+      format to one of "ASCII", "GADGET", "ART", or "TIPSY" to match your
+      simulation file.  If you use the ART option, only PMss files are
+      currently supported.  (PMcrs files, which do not include particle IDs
+      explicitly, are not supported).
+
+      If you use "ASCII", "ART", or "TIPSY", you will additionally have to set
+      the particle mass; if you use "ASCII" or "TIPSY", you will also have to
+      set parameters for the cosmology and box size.
+
+      If you use GADGET, you should check to make sure that the length
+      and mass conversion multipliers are correct (GADGET_LENGTH_CONVERSION and
+      GADGET_MASS_CONVERSION) to convert Gadget internal units to comoving Mpc/h
+      and Msun/h.
+
+      Similarly, if you use TIPSY, you should set the length and velocity
+      conversion multipliers (TIPSY_LENGTH_CONVERSION and TIPSY_MASS_CONVERSION)
+      to convert Tipsy internal units to comoving Mpc/h and physical km/s.
+      *Note that TIPSY format is in an alpha stage of support---please contact
+       me if you have issues!*
+
+      Then, you can run Rockstar: "./rockstar -c quickstart.cfg <particle file>"
+      
+      Note that periodic boundary conditions are *not* assumed for a single-cpu
+      run.  (For that, see the section on parallel IO).
+
+   ii) More complete setup (multiple snapshots/input files):
+      Note: Rockstar does *not* use MPI for its parallelization.  As such,
+      there should be no headaches with finding a working MPI installation
+      to use. :)
+
+      For running on multiple snapshots or simulations with multiple input
+      files per snapshot, Rockstar uses a master process to direct the
+      order of processing steps and several client processes to do the
+      actual work.
+
+      For historical reasons, enabling Rockstar to run on multiple input files
+      or multiple snapshots is controlled by setting the following "Parallel
+      IO" option in the config file:
+
+      	 PARALLEL_IO = 1
+
+      Several more options are necessary in the configuration file to specify
+      filenames, paths, and information about the number of processes you want
+      to use.
+
+      By default, the number of reading tasks is set to the number
+      of files being read for each simulation snapshot:
+
+         NUM_BLOCKS = <number of files per snapshot>
+
+      However, if you want to have a different (smaller) number of reading
+      tasks, you have to use:
+
+      	 NUM_READERS = <number of reading tasks>
+
+      (This is helpful if the number of files per snapshot exceeds the maximum
+      number of connections allowed by the system on a single socket.)
+
+      You will also have to provide information on where the data files are
+      located.  To do so, you will have to set:
+
+      	 INBASE = "/directory/where/files/are/located"
+         FILENAME = "my_sim.<snap>.<block>"
+
+      In this example, "my_sim" should be the base of your simulation filename.
+      For multiple snapshots, the text "<snap>" will be automatically replaced
+      by the snapshot number, and the text "<block>" will be automatically
+      replaced by the block number (0 to NUM_BLOCKS-1).  To specify the range
+      of snapshot numbers, you may set
+
+         NUM_SNAPS = <total number of snapshots>
+	 STARTING_SNAP = <first snap> #defaults to 0
+  
+      If you have nonstandard names for your snapshots (e.g., "001" instead of
+      "1"), you may create a text file with one snapshot name per line and set:
+
+         SNAPSHOT_NAMES = </path/to/snapshot names>
+
+      This will automatically override the number of snapshots and the starting
+      snapshot if specified.  You may do the same thing for the block names,
+      too:
+
+         BLOCK_NAMES = </path/to/block names>
+
+      (Note that NUM_BLOCKS should still be specified in this case, so that the
+      server knows how many reader connections to accept).
+
+      The number of analysis tasks can be set to either 1 or a multiple of
+      8.  If set to 1, periodic boundary conditions are *not* assumed; otherwise
+      periodic boundary conditions *are* assumed (see also the "PERIODIC" option
+      in the full list of config options).  To set the number of analysis
+      tasks, set:
+
+      	  NUM_WRITERS = <number of analysis tasks>
+
+      Starting Rockstar (under the default options) is then accomplished by
+      first starting the server process: /path/to/rockstar -c server.cfg
+      The server process will generate a file called "auto-rockstar.cfg" in the
+      data output directory (OUTBASE, see below) with contact information;
+      you should then start client processes on all the machine(s) necessary
+      (/path/to/rockstar -c OUTBASE/auto-rockstar.cfg).
+
+      Specifically, you will have to start NUM_READERS (usually, NUM_BLOCKS)
+      reader tasks and NUM_WRITERS writer tasks.  To simplify this process,
+      there are two additional options you can set:
+
+         FORK_READERS_FROM_WRITERS = 1
+	 FORK_PROCESSORS_PER_MACHINE = <number of processors per machine>
+
+      The first option will automatically split off the reader tasks for you
+      (which are idle most of the time) so that you only have to start the
+      analysis tasks.  The second option will automatically split each analysis
+      task into many separate tasks (according to the number of processors
+      you specify to use per machine).  Thus, if set, you would only have to
+      start Rockstar running once on each machine (instead of once per
+      processor).  The command to start Rockstar for the reading/analysis tasks
+      is (as explained above): /path/to/rockstar -c OUTBASE/auto-rockstar.cfg
+
+      In terms of memory usage, Rockstar will use about 60 bytes / particle
+      *maximum total* for a cosmological simulation.  Thus, if you have a
+      1024^3 simulation and 2G of memory available per processor, you should
+      plan on using at least 32 processors in parallel.  Note that this
+      includes the particle readers as well---readers delete particles from
+      memory as soon as they are sent to the analysis tasks so that no extra
+      memory is wasted.
+
+      If Rockstar is terminated for any reason, it is easy to restart it where
+      it left off.  Simply start the server process by running:
+      /path/to/rockstar -c OUTBASE/restart.cfg .  Then, start client processes
+      as you would normally (either from auto-rockstar.cfg or your usual
+      config file).  Rockstar will automatically start from the last snapshot
+      which was incomplete.
+
+   iii) Merger trees
+      By default, the output files for Rockstar include some basic descendant
+      information for each halo.  However, it is strongly recommended that
+      you use a more sophisticated package, such as Consistent Trees
+      ( http://code.google.com/p/consistent-trees ) to improve consistency
+      between timesteps before using the descendant information for science
+      purposes (e.g., calculating merger rates).  Rockstar includes a script
+      to autogenerate configuration files for Consistent Trees (see the
+      Consistent Trees README file for use).
+
+   iv) Host / Subhalo relationships
+      By default, the output files for Rockstar do not include information
+      about which halos are hosts (as opposed to subhalos).  This is because
+      the consistent tree code (see Merger trees, above) automatically
+      calculates such relationships.  However, if you do not intend to use the
+      merger tree code, then there is a utility included with Rockstar to
+      postprocess the output halo catalogs (i.e., the out_*.list files).  To
+      compile, run "make parents" from the Rockstar source directory.  Then,
+      run the following command
+
+      	  /path/to/rockstar/util/find_parents <box_size> out_XYZ.list
+
+      on each halo catalog for which you want to find host halos.  Information
+      about which halos are hosts and which are subs will be output as an
+      extra column, the parent ID.  Host halos will have a parent ID of -1;
+      subhaloes will have a parent ID which corresponds to their host halo ID.
+
+   v) Lightcone setup
+      Lightcones are currently only supported with parallel IO (see options
+      above).  To turn on lightcone support, set
+
+         LIGHTCONE = 1
+
+      The scale factor will be automatically computed (flat cosmologies only)
+      from the distance to the origin, which is set by
+
+         LIGHTCONE_ORIGIN = (x,y,z) # default: (0,0,0)
+
+      If you want a lightcone created by joining two different fields of view
+      from the same box, you will have to set the following options:
+
+         LIGHTCONE_ALT_SNAPS = /path/to/second_lightcone_snapnames
+	 LIGHTCONE_ALT_ORIGIN = (x,y,z) #default: (0,0,0)
+
+      (The LIGHTCONE_ALT_ORIGIN option translates all particles in the second
+      field of view from (x,y,z) to the first LIGHTCONE_ORIGIN.)  If using two
+      fields of view, it is assumed that they have equal numbers of input files;
+      NUM_BLOCKS should be set to the combined total number of input files.
+
+      If you have more than two fields of view from the same box, you will
+      have to make sure that their positions are already translated
+      appropriately so that they can be joined/unioned together without any
+      overlap issues.  In this case, you should not set any of the ALT lightcone
+      options.  Additionally, you should set IGNORE_PARTICLE_IDS = 1 so as
+      to prevent confusion with the same particle ID appearing multiple times.
+
+   vi) Controlling Output Formats:
+      Rockstar can currently output in either ascii or binary formats.
+      You can control the output directory for halo catalogs by setting:
+
+         OUTBASE = "/desired/output/path" # default is current directory
+
+      By default, both binary and ascii catalogs are printed.  You can change
+      this by setting:
+
+         OUTPUT_FORMAT = "BOTH" # or "ASCII" or "BINARY"
+
+      However, as the binary outputs are required for generating merger trees,
+      merger trees will *not* be generated if you select the "ASCII" option.
+      If you want merger trees but not the binary outputs (which take up
+      lots of space), you can set the following option:
+
+         DELETE_BINARY_OUTPUT_AFTER_FINISHED = 1
+
+      For the binary outputs, there is a 256-byte header (detailed in
+      io/meta_io.h) followed by a binary dump of the halo structures
+      (see halo.h), followed by a binary dump of the particle ids in
+      each halo (type int64_t).  See the load_binary_halos() routine in
+      io/meta_io.c for an example of how to read in the binary files.
+
+      To change the minimum particle size of output halos, set
+
+          MIN_HALO_OUTPUT_SIZE = <minimum number of particles> #default: 20
+
+      Note that this option does *not* specify the minimum number of particles
+      bound within the virial or other halo radius.  Instead, it specifies the
+      minimum number of particles which Rockstar identifies as uniquely assigned
+      to that halo.  The virial mass can (and usually will) be much less.
+
+      To avoid printing spurious halos, Rockstar excludes significantly 
+      unbound objects by default.  To change the threshold of what is considered
+      "significantly unbound"---e.g., for studying tidal remnants, you may
+      consider lowering the value of the following parameter:      
+
+      	 UNBOUND_THRESHOLD = <minimum fraction of bound mass> #default: 0.5
+
+      Generally, this affects the halo mass function at the few percent level
+      for halos of 100 bound particles or less.
+
+      Rockstar does not by default output full particle information to
+      save space.  In order to turn on this capability, set
+
+         FULL_PARTICLE_CHUNKS = <number of processes to output particles>
+
+      to the desired number of analysis processes which you want to output
+      particles (i.e., something between 1 and NUM_WRITERS) at every timestep.
+
+      Alternately, you can choose to use the BGC2 output format, which
+      records full particle information as well as some halo information for
+      an entire snapshot.  In order to turn on this capability, set
+
+         BGC2_SNAPNAMES = </path/to/snapshot_names>
+
+      Where the file contains a list of snapshots (formatted the same way as
+      in SNAPSHOT_NAMES, if you used that option) for which you want BGC2
+      output.  (Note that BGC2 output is the only way to obtain a fully SO
+      mass calculation, as all other mass calculations are performed on
+      FOF groups, which may not include all the particles out to the desired
+      mass threshold.)  Note that the BGC2 format is currently incompatible
+      with processing lightcones.
+
+      Once the BGC2 files have been generated, a short postprocessing step
+      is necessary to bring them into full compliance with the spec (calculating
+      subs/centrals, etc.).  You will need to compile the postprocessing
+      code with:
+
+         make bgc2
+
+      Then, for every BGC2 snapshot you have generated, you will need to run
+
+         /path/to/rockstar/util/finish_bgc2 -c rockstar.cfg -s <snap>
+
+   vii) Infiniband / Network Connectivity Notes:
+      As particle transfer is usually a small fraction of the total analysis
+      time, Rockstar performs well on pretty much any gigabit or faster network.
+
+      However, if you have IP over Infiniband, Rockstar can use this natively;
+      for the server address, you simply have to specify the IP address
+      assigned to the Infiniband port.  Alternately, if you have "auto"
+      specified for the server name, you may force Rockstar to use the
+      Infiniband interface (e.g., "ib0") with the following config option:
+
+         PARALLEL_IO_SERVER_INTERFACE = "ib0"
+
+      Rockstar supports IPv4 and IPv6 natively; addresses may be specified
+      in either format.
+
+   viii) Full Configuration Options:
+      For those options not mentioned directly above:
+
+      	  MASS_DEFINITION = <"vir" or "XXXc" or "XXXb" etc.> #default: vir
+
+      This lets you specify how you want masses calculated.  "vir" uses the
+      formula from Bryan & Norman 1998; a number plus "c" or "b" calculates
+      masses relative to the critical or background density, respectively.
+      (E.g. "200b" or "200c", or even "1600b").
+
+          SCALE_NOW = <current cosmological scale factor>
+	  h0 = <hubble constant today> # in units of 100 km/s/Mpc
+	  Ol = <Omega_Lambda> # in units of the critical density
+	  Om = <Omega_Matter> # in units of the critical density
+
+      These cosmology options are only relevant if one is reading from an ASCII
+      or TIPSY particle file.  (For TIPSY, the SCALE_NOW parameter may be
+      omitted).  For other data formats, these values are automatically
+      overwritten with values in the particle data files.
+
+          PARTICLE_MASS = <mass of each particle> #in Msun/h
+
+      It is not necessary to specify the particle mass for GADGET2 files.
+      However, for GADGET2 files, you will need to specify the conversion to
+      Rockstar's internal length (comoving Mpc/h) and mass (Msun/h) units:
+
+          GADGET_MASS_CONVERSION = <conversion from GADGET units to Msun/h>
+	  GADGET_LENGTH_CONVERSION = <conversion from GADGET units to Mpc/h>
+
+      In general, these will be ~1e10 (mass conversion) and either 1 or
+      1e-3 (length conversion for Mpc/h and kpc/h, respectively).
+
+      Similarly, for TIPSY files, you will need to convert lengths and
+      velocities to comoving MPC/h and physical km/s:
+
+	  TIPSY_LENGTH_CONVERSION = <conversion from TIPSY units to Mpc/h>
+          TIPSY_VELOCITY_CONVERSION = <conversion from TIPSY units to km/s>
+
+      *Note that TIPSY format is in an alpha stage of support---please contact
+       me if you have issues!*
+
+      To disable periodic boundary conditions (only applicable for PARALLEL_IO),
+      you can set:
+      
+          PERIODIC = 0
+
+      *Note that setting this to 1 does not enable periodic boundary conditions
+      for single-processor halo finding.*
+
+      	  BOX_SIZE = <side length of cosmological box in comoving Mpc/h>
+
+      The box size is only necessary to set for ASCII particle data.
+
+      	  GADGET_SKIP_NON_HALO_PARTICLES = <0 or 1> #default = 1
+
+      By default, Rockstar only considers dark matter particles; the preceeding
+      option can be set to 0 to force consideration of other particles as well
+      in GADGET2 files.  The default halo particle type in GADGET is 1; however,
+      if you need to change this, you can use the following option:
+
+          GADGET_HALO_PARTICLE_TYPE = <0 to 5> #default = 1
+
+      Note that Rockstar has no current support for multiple particle masses.
+
+      	  RESCALE_PARTICLE_MASSES = <0 or 1> #default 1
+
+      If only dark matter particles are used from GADGET2 files in a simulation
+      which also includes gas particles, it is necessary to rescale the particle
+      masses so as to preserve the correct matter density; setting this option
+      tells Rockstar to do so.
+
+      If for some reason your simulation data has inconsistent or duplicate
+      particle IDs, you can set the following option to prevent problems with
+      halo finding:
+
+          IGNORE_PARTICLE_IDS = 1
+
+      Note that in this case, merger trees are disabled.
+
+      As mentioned above, Rockstar requires one master server accessible by
+      all reading/analyis tasks.  The server does not require access to any
+      data files, but it must be of the same architecture as the reading/
+      analysis tasks.  In order to contact the master server, the reading/
+      analysis tasks need to know its address, specified by the following two
+      options in the config file:
+
+      	 PARALLEL_IO_SERVER_ADDRESS = <server address> #default: auto
+	 PARALLEL_IO_SERVER_PORT = <server port> #default: auto
+
+      The server port should be in the range 1025-65000, and it should be
+      unblocked by the server firewall.  Alternately, you may specify
+      "auto" for both the server address and the server port.  In this case,
+      once you launch the server process, it will write to a file called
+      "auto-rockstar.cfg" in the launch directory (or the directory that
+      OUTBASE is set to).  This file will contain updated settings with
+      the machine name and port for the server, which you can then use
+      to launch the reading/analysis tasks.  To force Rockstar to use a
+      specified interface (useful for machines on multiple networks),
+      you can use:
+
+      	 PARALLEL_IO_SERVER_INTERFACE = <interface name> # ib0, for example
+
+      Since analysis tasks have to acquire particle data from reading tasks,
+      the analysis tasks need to be contactable by the reading tasks.  You
+      should choose a port number for the analysis tasks which is distinct
+      from the server port above:
+
+          PARALLEL_IO_WRITER_PORT = <port from 1025-65000>
+
+      If you have a firewall, you will have to open this port for access
+      *as well as* the N ports above this port, where N is the number of
+      analysis tasks you are running per machine.
+
+      The following options determine details of the halo finding.  To tell
+      Rockstar to calculate halo radii as well as Vmax, Rvmax, and other
+      halo properties from the *unbound* particles, set the following option
+      to 0:
+
+          BOUND_PROPS = <0 or 1> #default 1
+
+      To change the default FOF refinement fraction (see the Rockstar paper),
+      change:
+
+          FOF_FRACTION = <FOF refinement fraction> #default 0.7
+
+      To change the default 3D FOF linking length, set:
+
+          FOF_LINKING_LENGTH = <FOF linking length> #default 0.28
+
+      To set the force resolution (or equivalently, the softening length),
+      set:
+
+          FORCE_RES = <force resolution> #default: 0.0012, in comoving Mpc/h
+
+      To change the minimum (internal) number of particles considered to be
+      a halo seed, change:
+
+          MIN_HALO_PARTICLES = <minimum number of halo particles> #default: 10
+
+      See also MIN_HALO_OUTPUT_SIZE, above.
+
+      To run postprocessing scripts after each snapshot finishes, you can use
+      the RUN_ON_SUCCESS config option:
+
+      	  RUN_ON_SUCCESS = "/path/to/myscript"
+
+      The script will be executed with two arguments: the snapshot number
+      followed by the snapshot name (only different if specified via the
+      SNAPSHOT_NAMES file).
+
+      To specify your own load-balancing distribution, you can use the
+      LOAD_BALANCE_SCRIPT option.  There is an example of such a script in
+      the scripts directory; to use, set the LOAD_BALANCE_SCRIPT option to
+      "perl /path/to/rockstar/scripts/sample_loadbalance.pl".  The script is
+      given the number of writer tasks, the recommended dimensional divisions,
+      the box size, the scale factor, as well as the IP addresses and ports
+      of all the writer tasks.  The script is expected to reoutput the
+      information for each writer task along with an additional set of six
+      numbers specifying the boundary region (min_x, min_y, min_z) to
+      (max_x, max_y, max_z).  The boundary region *must* be contained within
+      the box size in each dimension; the boundary regions are also assumed to
+      be overlapping (it is up to your script to check this).
+
+    ix) Full Example Script
+      For a full example configuration file, used for running on the Bolshoi
+      simulation, see scripts/pleiades.cfg or scripts/ranger.cfg.
+
+      For the example PBS submission script used to run the halo finding on
+      Pleiades, see scripts/pleiades.pbs; for Ranger, see scripts/ranger.pbs.
+
+   x) Example source code for loading particle outputs
+      For additional useful source code to load in both the BGC2 and
+      FULL_PARTICLE halo/particle formats, check the examples/ subdirectory.
+Short list of source code files and their contents:
+
+main.c: Main program execution path.
+
+rockstar.c: Master code for finding halos/subhalos.
+fof.c: Code for assembling FOF groups.
+groupies.c: Code for finding substructure within 3D FOF groups.
+subhalo_metric.c: Code for deciding particle-halo membership.
+potential.c: Code for calculating gravitational potentials.
+fun_times.c: Code for calculating likely progenitors of current halo seeds.
+merger.c: Code for calculating particle-based merger trees.
+
+halo.h: Halo structure definition
+particle.h: Particle structure definition
+universal_constants.h: Gravitational and conversion constants.
+jacobi.c: Code for calculating eigenvectors/eigenvalues of symmetric matrices.
+distance.c: Code for calculating cosmological distances.
+universe_time.c: Code for converting scale factors to times.
+nfw.c: Code for calculating the scale radius given a mass and vmax for an
+       NFW halo.
+
+io/meta_io.c: Code for reading and writing particle and halo data.
+io/io_[ascii|art|gadget|generic|tipsy|internal].c: 
+   Code for reading particle formats.
+io/io_bgc2.c: Code for writing particles in the BGC2 format
+io/io_util.c: Code for reading FORTRAN formats and swapping endianness.
+io/read_config.c: Code for parsing configuration files.
+io/stringparse.c: Efficient scanf() replacement.
+
+server.c: Code for master task. (Parallel IO)
+client.c: Code for reading / analysis parallel tasks.  (Parallel IO)
+load_balance.c: Code for dividing work fairly among analysis tasks.
+inet/socket.c: Code for interfacing with TCP sockets.
+
+config.c: Code for loading configuration.
+config.template.h: Code for config variables.
+
+fast3tree.c: Binary Space Partitioning tree code.
+litehash.c: Lightweight hash tables.
+check_syscalls.c: Error-checking for fopen(), realloc(), fread(), and fwrite().
+
+0.99 (Beta)
+#include "config_vars.h"
+
+int _check_bounds(float *pos_i, float *pos_f, float *bounds) {
+  int64_t i;
+  for (i=0; i<3; i++) {
+    if (pos_i[i]>bounds[i+3]) {
+      if (bounds[i]<0 && PERIODIC) {
+        pos_f[i]=pos_i[i]-BOX_SIZE;
+        if (pos_f[i]>bounds[i+3] || pos_f[i] < bounds[i]) return 0;
+      } else return 0;
+    }
+    else if (pos_i[i]<bounds[i]) {
+      if (bounds[i+3]>BOX_SIZE && PERIODIC) {
+        pos_f[i]=pos_i[i]+BOX_SIZE;
+        if (pos_f[i]>bounds[i+3] || pos_f[i] < bounds[i]) return 0;
+      } else return 0;
+    }
+    else pos_f[i] = pos_i[i];
+  }
+  return 1;
+}
+
+int _check_bounds_raw(float *pos_i, float *bounds) {
+  int64_t i;
+  for (i=0; i<3; i++)
+    if (pos_i[i]>bounds[i+3] || pos_i[i]<bounds[i]) return 0;
+  return 1;
+}
+
+
+int _check_bounds_old(float *pos_i, float *pos_f, float *bounds) {
+  int64_t i, wrap, max_wrap;
+  for (i=0; i<3; i++) {
+    wrap = ((bounds[i]<0) && PERIODIC) ? -1 : 0;
+    max_wrap = ((bounds[i+3]>BOX_SIZE) && PERIODIC) ? 2 : 1;
+    for (; wrap < max_wrap; wrap++) {
+      pos_f[i] = pos_i[i]+wrap*BOX_SIZE;
+      if (pos_f[i]<=bounds[i+3] && pos_f[i] >= bounds[i]) break;
+    }
+    if (wrap == max_wrap) return 0; //Not in bounds
+  }
+  return 1;
+}
+
+//Note that b2 is extended by "overlap" in all directions
+int bounds_overlap(float *b1, float *b2, float *b3, double overlap) {
+  int64_t i;
+  int wrap = 0, max_wrap;
+  float min, max;
+  for (i=0; i<3; i++) {
+    b3[i] = min = b2[i]-overlap;
+    b3[i+3] = max = b2[i+3]+overlap;
+    wrap = ((min < 0) && PERIODIC) ? -1 : 0;
+    max_wrap = ((max > BOX_SIZE) && PERIODIC) ? 2 : 1;
+    for (; wrap<max_wrap; wrap++) {
+      if (((b1[i]+wrap*BOX_SIZE) < max) &&
+          ((b1[i+3]+wrap*BOX_SIZE) > min)) break;
+    }
+    if (wrap == max_wrap) return 0;
+  }
+  return 1;
+}
+#ifndef _BOUNDS_H_
+#define _BOUNDS_H_
+
+int _check_bounds(float *pos_i, float *pos_f, float *bounds);
+int _check_bounds_raw(float *pos_i, float *bounds);
+int bounds_overlap(float *b1, float *b2, float *b3, double overlap);
+
+#endif /* _BOUNDS_H_ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <signal.h>
+
+//#define DEBUG_IO
+
+void system_error(char *errmsg) {
+  fprintf(stderr, "[Error] %s\n", errmsg);
+  perror("[Error] Reason");
+  exit(1);
+}
+
+FILE *check_fopen(char *filename, char *mode) {
+  FILE *res = fopen(filename, mode);
+  if (res == NULL) {
+    if (mode[0] == 'w')
+      fprintf(stderr, "[Error] Failed to open file %s for writing!\n", filename);
+    else if (mode[0] == 'a')
+      fprintf(stderr, "[Error] Failed to open file %s for appending!\n", filename);
+    else
+      fprintf(stderr, "[Error] Failed to open file %s for reading!\n", filename);
+    exit(1);
+  }
+#ifdef DEBUG_IO
+  fprintf(stderr, "[Note] Opened file %s with mode '%s' in fileno %d.\n", 
+	  filename, mode, fileno(res));
+#endif /* DEBUG_IO */
+  return res;
+}
+
+FILE *check_popen(char *command, char *mode) {
+  FILE *res = popen(command, mode);
+  if (res == NULL) {
+    fprintf(stderr, "[Error] Failed to start command %s!\n", command);
+    exit(1);
+  }
+#ifdef DEBUG_IO
+  fprintf(stderr, "[Note] Opened command %s with mode '%s' in fileno %d.\n", 
+	  command, mode, fileno(res));
+#endif /* DEBUG_IO */
+  return res;
+}
+
+FILE *check_rw_socket(char *command, pid_t *pid) {
+  int sockets[2], status;
+  FILE *res;
+  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)<0)
+    system_error("Failed to create socket pair!");
+  *pid = fork();
+  if (*pid < 0) system_error("Failed to fork new process!");
+  if (!*pid) {
+    if (dup2(sockets[1], 0) < 0) system_error("Failed to reopen stdin!");
+    if (dup2(sockets[1], 1) < 0) system_error("Failed to reopen stdout!");
+    close(sockets[0]);
+    if (execlp("sh", "sh", "-c", command, NULL) < 0)
+      system_error("Failed to exec command!");
+  }
+  close(sockets[1]);
+  res = fdopen(sockets[0], "r+");
+  if (!res) system_error("Failed to convert socket to stream!");
+  if (waitpid(*pid, &status, WNOHANG)) {
+    fprintf(stderr, "[Error] Failed to start child process: %s\n", command);
+    exit(1);
+  }
+#ifdef DEBUG_IO
+  fprintf(stderr, "[Note] Started command %s with mode 'r+' in fileno %d.\n", 
+	  command, fileno(res));
+#endif /* DEBUG_IO */
+  return res;
+}
+
+void rw_socket_close(FILE *res, pid_t pid) {
+  fclose(res);
+  kill(pid, 9);
+  waitpid(pid, NULL, 0);
+}
+
+void *check_realloc(void *ptr, size_t size, char *reason) {
+  void *res = realloc(ptr, size);
+  if ((res == NULL) && (size > 0)) {
+    fprintf(stderr, "[Error] Failed to allocate memory (%s)!\n", reason);
+    exit(1);
+  }
+  return res;
+}
+
+
+void _io_err(int rw, size_t size, size_t nitems, FILE *stream) {
+  char *verb = (rw) ? "write" : "read";
+  char *dir = (rw) ? "to" : "from";
+  char *items = (nitems == 1) ? "item" : "items";
+
+  fprintf(stderr, "[Error] Failed to %s %"PRIu64" %s of size "
+	  "%"PRIu64" bytes %s fileno %d!\n", 
+	  verb, (uint64_t)nitems, items, (uint64_t)size, dir, fileno(stream));
+  if (feof(stream))
+    fprintf(stderr, "[Error] Reason: end of file (offset %"PRIu64").\n",
+	    (uint64_t)ftello(stream));
+  else
+    perror("[Error] Reason");
+  exit(1);
+}
+
+void check_fseeko(FILE *stream, off_t offset, int whence) {
+  if (fseeko(stream, offset, whence) < 0) {
+    fprintf(stderr, "[Error] Seek error in fileno %d: ", fileno(stream));
+    perror(NULL);
+    exit(1);
+  }
+}
+
+size_t check_fread(void *ptr, size_t size, size_t nitems, FILE *stream) {
+  size_t res = 1, nread = 0;
+  while (nread < nitems) {
+    res = fread(ptr, size, nitems, stream);
+    if (res <= 0) _io_err(0, size, nitems, stream);
+    nread += res;
+  }
+  return nread;
+}
+
+char *check_fgets(char *ptr, size_t size, FILE *stream) {
+  char *res = fgets(ptr, size, stream);
+  if (res <= 0) _io_err(0, size, 1, stream);
+  return res;
+}
+
+
+size_t check_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream) {
+  size_t res = 1, nwritten = 0;
+  while (nwritten < nitems) {
+    res = fwrite(ptr, size, nitems, stream);
+    if (res <= 0) _io_err(1, size-1, nitems, stream);
+    nwritten += res;
+  }
+  return nwritten;
+}
+#ifndef CHECK_SYSCALLS_H
+#define CHECK_SYSCALLS_H
+
+void system_error(char *errmsg);
+FILE *check_fopen(char *filename, char *mode);
+FILE *check_popen(char *command, char *mode);
+void *check_realloc(void *ptr, size_t size, char *reason);
+size_t check_fread(void *ptr, size_t size, size_t nitems, FILE *stream);
+size_t check_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream);
+void check_fseeko(FILE *stream, off_t offset, int whence);
+char *check_fgets(char *ptr, size_t size, FILE *stream);
+FILE *check_rw_socket(char *command, pid_t *pid);
+void rw_socket_close(FILE *res, pid_t pid);
+
+#define check_fprintf(file, ...) { if (fprintf(file, __VA_ARGS__) <= 0)	{  \
+      fprintf(stderr, "[Error] Failed printf to fileno %d!\n", fileno(file)); \
+      perror("[Error] Reason"); \
+      exit(1); \
+    }}
+
+#endif /* CHECK_SYSCALLS_H */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <assert.h>
+#include <sys/select.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <time.h>
+#include "check_syscalls.h"
+#include "particle.h"
+#include "rockstar.h"
+#include "groupies.h"
+#include "inet/rsocket.h"
+#include "io/meta_io.h"
+#include "config_vars.h"
+#include "server.h"
+#include "client.h"
+#include "merger.h"
+#include "distance.h"
+#include "bounds.h"
+#include "fun_times.h"
+#include "universe_time.h"
+
+#define CLIENT_DEBUG 0
+
+struct recipient *recipients = NULL;
+int64_t num_recipients = 0;
+int64_t *part_ids = NULL;
+int64_t *part_id_buffer = NULL;
+int64_t num_buffer_part_ids = 0;
+
+struct projection *prj = NULL;
+struct projection_request *prq = NULL;
+int64_t num_proj = 0;
+int64_t in_error_state = 0;
+int64_t RECIPIENT_BUFFER=100000;
+
+void network_io_err(int64_t s) {
+  if (in_error_state) return;
+  in_error_state = 1;
+  send_to_socket(s, "err!", 4);
+}
+
+void network_error_cleanup() {
+  p = check_realloc(p, 0, "Freeing particle memory");
+  num_p = 0;
+  halos = check_realloc(halos, 0, "Freeing halos");
+  num_halos = 0;
+  rockstar_cleanup();
+  clear_merger_tree();
+  in_error_state = 0;
+}
+
+void reset_projection_count(void) {
+  prj = check_realloc(prj, sizeof(struct projection)*num_proj,
+		      "Allocating projections.");
+  prq = check_realloc(prq, sizeof(struct projection_request)*num_proj,
+		      "Allocating projection requests.");
+}
+
+struct recipient *add_recipient(int halo_recipient, int64_t c) {
+  struct recipient *r;
+  int64_t struct_size;
+  num_recipients++;
+  recipients = check_realloc(recipients, (sizeof(struct recipient)
+					  * num_recipients), 
+			     "Allocating particle data recipients.");
+  r = recipients+num_recipients-1;
+  memset(r, 0, sizeof(struct recipient));
+  struct_size = (halo_recipient) ? sizeof(struct halo):sizeof(struct particle);
+  r->buffer = check_realloc(NULL, struct_size*RECIPIENT_BUFFER,
+			    "Allocating recipient transmit buffer.");
+
+  recv_from_socket(c, r->bounds, sizeof(float)*6);
+  r->address = recv_msg_nolength(c, r->address);
+  r->port = recv_msg_nolength(c, r->port);
+  return r;
+}
+
+void clear_recipients(void) {
+  int64_t i;
+  for (i=0; i<num_recipients; i++) {
+    free(recipients[i].buffer);
+    free(recipients[i].port);
+    free(recipients[i].address);
+  }
+  free(recipients);
+  recipients = NULL;
+  num_recipients = 0;
+}
+
+void calc_particle_bounds(float *bounds) {
+  int64_t i,j;
+  for (j=0; j<6; j++) bounds[j]=0;
+  if (!num_p) return;
+  memcpy(bounds, p[0].pos, sizeof(float)*3);
+  memcpy(bounds+3, p[0].pos, sizeof(float)*3);
+  for (i=1; i<num_p; i++) {
+    for (j=0; j<3; j++) {
+      if (bounds[j] > p[i].pos[j]) 
+	bounds[j] = p[i].pos[j];
+      if (bounds[j+3] < p[i].pos[j]) 
+	bounds[j+3] = p[i].pos[j];
+    }
+  }
+}
+
+void trim_particles(float *bounds) {
+  int64_t i, j;
+  if (!TRIM_OVERLAP) return;
+  for (i=0; i<3; i++) {
+    bounds[i] += TRIM_OVERLAP;
+    bounds[i+3] -= TRIM_OVERLAP;
+  }
+
+  if (ROUND_AFTER_TRIM)
+    for (i=0; i<6; i++) 
+      bounds[i]=((int64_t)(bounds[i]/ROUND_AFTER_TRIM + 0.5))*ROUND_AFTER_TRIM;
+
+  for (i=0; i<num_p; i++)
+    for (j=0; j<3; j++)
+      if (bounds[j] > p[i].pos[j] || bounds[j+3] <= p[i].pos[j]) {
+	num_p--;
+	p[i] = p[num_p];
+	i--;
+	break;
+      }
+
+  p = check_realloc(p, sizeof(struct particle)*num_p, "Removing overlap.");
+}
+
+void clear_particle_rbuffer(struct recipient *r) {
+  if (!r->buffered) return;
+  send_to_socket(r->cs, "part", 4);
+  send_msg(r->cs, r->buffer, sizeof(struct particle)*r->buffered);
+  r->buffered = 0;
+}
+
+void clear_halo_rbuffer(struct recipient *r) {
+  int64_t i, pids=0;
+  struct halo *bh = r->buffer;
+  if (!r->buffered) return;
+  send_to_socket(r->cs, "halo", 4);
+  send_msg(r->cs, r->buffer, sizeof(struct halo)*r->buffered);
+
+  for (i=0; i<r->buffered; i++) pids+=bh[i].num_p;
+  if (pids>num_buffer_part_ids) {
+    part_id_buffer = check_realloc(part_id_buffer, sizeof(int64_t)*pids,
+				   "Allocating particle ID buffer.");
+    num_buffer_part_ids = pids;
+  }
+  pids = 0;
+  for (i=0; i<r->buffered; i++) {
+    memcpy(part_id_buffer + pids, part_ids + bh[i].p_start,
+	   sizeof(int64_t)*bh[i].num_p);
+    pids += bh[i].num_p;
+  }
+  send_to_socket(r->cs, "pids", 4);
+  send_msg(r->cs, part_id_buffer, sizeof(int64_t)*pids);
+  r->buffered = 0;
+}
+
+
+void add_particle_to_buffer(struct recipient *r, struct particle *p1) {
+  struct particle *buffer = r->buffer;
+  if (r->buffered == RECIPIENT_BUFFER) clear_particle_rbuffer(r); 
+  buffer[r->buffered] = *p1;
+  r->buffered++;
+}
+
+void add_halo_to_buffer(struct recipient *r, struct halo *h1) {
+  struct halo *buffer = r->buffer;
+  if (r->buffered == RECIPIENT_BUFFER) clear_halo_rbuffer(r); 
+  buffer[r->buffered] = *h1;
+  r->buffered++;
+}
+
+void check_particle_bounds(struct particle *p1, struct recipient *r) {
+  struct particle pt = *p1;
+  if (_check_bounds(p1->pos, pt.pos, r->bounds)) add_particle_to_buffer(r, &pt);
+}
+
+void check_halo_bounds(struct halo *h1, struct recipient *r) {
+  struct halo ht = *h1;
+  if (_check_bounds(h1->pos, ht.pos, r->bounds)) add_halo_to_buffer(r, &ht);
+}
+
+int64_t check_projection_bounds(struct particle *p1, struct projection *pr) {
+  return (_check_bounds_raw(p1->pos, pr->bounds));
+}
+
+void send_config(int64_t c) {
+  double data;
+#define snd(x) { data = x; send_to_socket_noconfirm(c, &data, sizeof(double)); }
+  snd(PARTICLE_MASS);
+  snd(AVG_PARTICLE_SPACING);
+  snd(SCALE_NOW);
+  snd(BOX_SIZE);
+  snd(Ol);
+  snd(Om);
+  snd(h0);
+#undef snd
+}
+
+void recv_config(int64_t c) {
+  int64_t i;
+#define rcv(x) { recv_from_socket(c, &x, sizeof(double)); }
+  rcv(PARTICLE_MASS);
+  rcv(AVG_PARTICLE_SPACING);
+  rcv(SCALE_NOW);
+  rcv(BOX_SIZE);
+  rcv(Ol);
+  rcv(Om);
+  rcv(h0);
+#undef rcv
+  for (i=0; i<3; i++)
+    if (LIGHTCONE_ORIGIN[i] || LIGHTCONE_ALT_ORIGIN[i]) break;
+  if (i==3) {
+    for (i=0; i<3; i++) LIGHTCONE_ORIGIN[i] = LIGHTCONE_ALT_ORIGIN[i] = BOX_SIZE/2.0;
+  }
+}
+
+void send_particles(int64_t c) {
+  int64_t i,j;
+  for (j=0; j<num_recipients; j++) 
+    recipients[j].cs = 
+      connect_to_addr(recipients[j].address, recipients[j].port);
+  for (i=num_p-1; i>=0; i--) {
+    for (j=0; j<num_recipients; j++) check_particle_bounds(p+i, recipients+j);
+    if (!(i%PARTICLE_REALLOC_NUM)) 
+      p = check_realloc(p,sizeof(struct particle)*i,"Freeing particle memory.");
+  }
+  num_p = 0;
+  p = check_realloc(p,0,"Freeing particle memory.");
+  for (j=0; j<num_recipients; j++) {
+    clear_particle_rbuffer(recipients+j);
+    send_to_socket(recipients[j].cs, "done", 4);
+    close_rsocket(recipients[j].cs);
+  }
+  clear_recipients();
+  send_to_socket(c, "done", 4);
+}
+
+void send_halos(char *c_address, char *c_port, int64_t snap, int64_t chunk) {
+  int64_t i,j, c;
+  struct binary_output_header bheader;
+
+  load_binary_halos(snap, chunk, &bheader, &halos, &part_ids);
+
+  for (j=0; j<num_recipients; j++)
+    recipients[j].cs=connect_to_addr(recipients[j].address, recipients[j].port);
+
+  for (i=0; i<bheader.num_halos; i++)
+    for (j=0; j<num_recipients; j++) check_halo_bounds(halos+i, recipients+j);
+
+  for (j=0; j<num_recipients; j++) {
+    clear_halo_rbuffer(recipients+j);
+    send_to_socket(recipients[j].cs, "cnfg", 4);
+    send_config(recipients[j].cs);
+    send_to_socket(recipients[j].cs, "done", 4);
+    close_rsocket(recipients[j].cs);
+  }
+  
+  c = connect_to_addr(c_address, c_port);
+  send_to_socket(c, "rdne", 4);
+  exit(0);
+}
+
+void close_connection(int64_t cs, int64_t *cslist, int64_t *num_cs) {
+  int64_t i;
+  for (i=0; i<*num_cs; i++) {
+    if (cslist[i] == cs) {
+      close_rsocket(cslist[i]);
+      *num_cs = (*num_cs)-1;
+      cslist[i] = cslist[*num_cs];
+      break;
+    }
+  }
+}
+
+void receive_stuff(int64_t s, int64_t c, int64_t timestep) {
+  int64_t i, j, num_senders = 0, done = 0, length, new_p_start, *senders = NULL;
+  char cmd[5] = {0};
+  struct binary_output_header *bheader;
+  struct halo **halos_recv, *th;
+  int64_t max_conn, **pids_recv;
+
+  while (!in_error_state && (num_senders || !done)) {
+    clear_rsocket_tags();
+    if (!done) {
+      tag_rsocket(s);
+      tag_rsocket(c);
+    }
+    for (i=0; i<num_senders; i++) tag_rsocket(senders[i]);
+    max_conn = select_rsocket(RSOCKET_READ, 0);
+    for (i=0; i<max_conn; i++) {
+      if (!check_rsocket_tag(i)) continue;
+      if (i==s) {
+	num_senders++;
+	senders = check_realloc(senders, sizeof(int64_t)*num_senders,
+				"Allocating particle sender FDs.");
+	senders[num_senders-1] = accept_connection(s,NULL,NULL);
+      }
+      else if (i==c) {
+	recv_from_socket(c, cmd, 4);
+	if (!strcmp(cmd, "done")) { done = 1; }
+	else if (!strcmp(cmd, "err!")) {
+	  in_error_state = 1;
+	  for (j=0; j<num_senders; j++) close_rsocket(senders[j]);
+	  num_senders = 0;
+	  break;
+	}
+	else { fprintf(stderr, "[Error] Server protocol error rs (%s)!\n", cmd); exit(1); }
+      }
+      else {
+	if (recv_from_socket(i, cmd, 4)<=0) {
+	  network_io_err(c);
+	  for (j=0; j<num_senders; j++) close_rsocket(senders[j]);
+	  num_senders = 0;
+	  break;
+	}
+	if (!strcmp(cmd, "part")) {
+	  length = num_p*sizeof(struct particle);
+	  p = recv_msg(i, p, &length, length);
+	  assert(!(length%(sizeof(struct particle))));
+	  num_p = length / sizeof(struct particle);
+	}
+
+	else if (!strcmp(cmd, "halo")) {
+	  assert(timestep > 0);
+	  bheader = (timestep > 1) ? &head2 : &head1;
+	  pids_recv = (timestep > 1) ? &part2 : &part1;
+	  halos_recv = (timestep > 1) ? &halos2 : &halos1;
+
+	  length = bheader->num_halos*sizeof(struct halo);
+	  *halos_recv = recv_msg(i, *halos_recv, &length, length);
+	  assert(!(length%sizeof(struct halo)));
+	  length /= sizeof(struct halo);
+
+	  //Redo particle pointers
+	  new_p_start = bheader->num_particles;
+	  for (j=bheader->num_halos; j<length; j++) {
+	    th = (*halos_recv) + j;
+	    th->p_start = new_p_start;
+	    new_p_start += th->num_p;
+	  }
+	  bheader->num_halos = length;
+
+	  recv_from_socket(i, cmd, 4);
+	  assert(!strcmp(cmd, "pids"));
+	  length = bheader->num_particles*sizeof(int64_t);
+	  *pids_recv = recv_msg(i, *pids_recv, &length, length);
+	  assert(!(length%sizeof(int64_t)));
+	  bheader->num_particles = length / sizeof(int64_t);
+	}
+
+	else if (!strcmp(cmd, "cnfg")) {
+	  recv_config(i);
+	}
+
+	else if (!strcmp(cmd, "done"))
+	  close_connection(i, senders, &num_senders);
+
+	else if (!strcmp(cmd, "rdne")) {
+	  close_connection(i, senders, &num_senders);
+	  send_to_socket_noconfirm(c, "done", 4);
+	}
+
+	else { fprintf(stderr, "[Error] Client protocol error rs (%s)!\n", cmd); exit(1); }
+      }
+    }
+  }
+  free(senders);
+}
+
+void do_projections(void) {
+  int64_t i, j, idx, dir;
+  assert(BOX_SIZE > 0);
+  for (i=0; i<num_proj; i++) {
+    prj[i].id = prq[i].id;
+    dir = prj[i].dir = prq[i].dir;
+    memcpy(prj[i].bounds, prq[i].bounds, sizeof(float)*6);
+    for (j=0; j<PROJECTION_SIZE; j++) prj[i].data[j] = 0;
+    for (j=0; j<num_p; j++) {
+      if (check_projection_bounds(p+j, prj+i)) {
+	idx = (double)PROJECTION_SIZE*p[j].pos[dir]/(double)BOX_SIZE;
+	if (idx >= PROJECTION_SIZE) idx = PROJECTION_SIZE-1;
+	prj[i].data[idx]++;
+      }
+    }
+  }
+}
+
+void accept_workloads(char *c_address, char *c_port, int64_t snap, int64_t chunk) {
+  char *address = NULL, *port = NULL;
+  int64_t s = connect_to_addr(c_address, c_port);
+  int64_t m = s;
+  int64_t id = -1, new_bounds = 1;
+  char cmd[5] = {0};
+  float zero_bounds[6];
+  struct fof *fofs = NULL;
+  struct workunit_info w;
+  rockstar_cleanup();
+  p = check_realloc(p, 0, "Freeing particles.\n");
+  num_p = 0;
+
+  if (s < 0) exit(1);
+  memset(zero_bounds, 0, sizeof(float)*6);
+
+  send_to_socket(m, &chunk, sizeof(int64_t));
+  while (1) {
+    if (recv_from_socket(m, cmd, 4)<=0) {
+      fprintf(stderr, "[Warning] Failed to receive instruction from server for chunk %"PRId64" (shutting down)!\n", chunk);
+      send_to_socket(s, "clos", 4);
+      exit(1);
+    }
+    if (!strcmp(cmd, "wrku")) {
+      recv_from_socket(m, &w, sizeof(struct workunit_info));
+      assert(w.num_particles >= 0 && w.num_fofs >= 0 && !w.num_halos);
+      num_p = w.num_particles;
+      fofs = recv_and_alloc(m, fofs, sizeof(struct fof)*w.num_fofs);
+      p = recv_and_alloc(m, p, sizeof(struct particle)*w.num_particles);
+      if (CLIENT_DEBUG) fprintf(stderr, "Received %"PRId64" particles and %"PRId64" fofs from id %"PRId64" (Worker %"PRId64")\n", w.num_particles, w.num_fofs, id-NUM_READERS, chunk);
+      if (new_bounds && TEMPORAL_HALO_FINDING) {
+	new_bounds = 0;
+	if (!memcmp(w.bounds, zero_bounds, sizeof(float)*6))
+	  load_previous_halos(snap, w.chunk, NULL);
+	else load_previous_halos(snap, w.chunk, w.bounds);
+      }
+      do_workunit(&w, fofs);
+      if (CLIENT_DEBUG) fprintf(stderr, "Analyzed %"PRId64" particles and %"PRId64" fofs from id %"PRId64", and found %"PRId64" halos. (Worker %"PRId64")\n", w.num_particles, w.num_fofs, id-NUM_READERS, num_halos, chunk);
+      w.num_halos = num_halos;
+      send_to_socket(m, "wrkd", 4);
+      send_to_socket(m, &w, sizeof(struct workunit_info));
+      send_to_socket(m, fofs, sizeof(struct fof)*w.num_fofs);
+      send_to_socket(m, halos, sizeof(struct halo)*w.num_halos);
+      send_to_socket(m, extra_info, sizeof(struct extra_halo_info)*w.num_halos);
+      send_to_socket(m, p, sizeof(struct particle)*w.num_particles);
+    }
+    else if (!strcmp(cmd, "nmwk")) {
+      if (m != s) close_rsocket(m);
+      p = check_realloc(p, 0, "Freeing particles.");
+      send_to_socket(s, "nmwk", 4);
+      send_to_socket(s, &id, sizeof(int64_t));
+      m = s;
+    }
+    else if (!strcmp(cmd, "work")) {
+      assert(m==s);
+      recv_from_socket(s, &id, sizeof(int64_t));
+      address = recv_msg_nolength(s, address);
+      port = recv_msg_nolength(s, port);
+      m = connect_to_addr(address, port);
+      if (m<0) {
+	send_to_socket(s, "clos", 4);
+	exit(1);
+      }
+      send_to_socket(m, &chunk, sizeof(int64_t));
+      new_bounds = 1;
+    }
+    else if (!strcmp(cmd, "fini")) {
+      exit(0);
+    }
+    else {
+      fprintf(stderr, "[Error] Error in client protocol aw (%s)!\n", cmd);
+      send_to_socket_noconfirm(s, "clos", 4);
+      exit(1);
+    }
+  }
+}
+
+int send_workunit(int64_t sock, struct workunit_info *w,
+		  struct fof **fofs, struct particle **particles,
+		  int64_t *no_more_work) {
+  if (!(*no_more_work)) find_unfinished_workunit(w, fofs, particles);
+  if ((*no_more_work) || (!w->num_fofs)) {
+    *no_more_work = 1;
+    send_to_socket(sock, "nmwk", 4);
+    return 0;
+  }
+  send_to_socket(sock, "wrku", 4);
+  send_to_socket(sock, w, sizeof(struct workunit_info));
+  send_to_socket(sock, *fofs, sizeof(struct fof)*w->num_fofs);
+  send_to_socket(sock, *particles, sizeof(struct particle)*w->num_particles);
+  if ((*particles >= p) && (*particles < p+num_p)) *particles = NULL;
+  return 1;
+}
+
+void distribute_workloads(int64_t c, int64_t s, int64_t snap, int64_t chunk, float *bounds) {
+  int64_t i, j, num_workers = 0, no_more_work = 0, workdone = 0,
+    done = 0, id_offset, worker_chunk, hcnt, id;
+  int64_t *workers = NULL, max_cs = 0, child = -1, new_w, child_has_connected=0;
+  char *address = NULL, *port = NULL;
+  char cmd[5] = {0};
+  struct workunit_info w;
+  struct particle *parts = NULL;
+  struct fof *fofs = NULL;
+  struct halo *rhalos = NULL;
+  struct extra_halo_info *ehi = NULL;
+
+  if (bounds) memcpy(w.bounds, bounds, sizeof(float)*6);
+  else memset(w.bounds, 0, sizeof(float)*6);
+  w.chunk = chunk;
+
+  while ((num_workers || !done) && !(in_error_state)) {
+
+    if (work_finished() && !workdone && no_more_work && child_has_connected) {
+      workdone = 1;
+      rockstar_cleanup();
+      hcnt = count_halos_to_print(bounds);
+      send_to_socket_noconfirm(c, "hcnt", 4);
+      send_to_socket_noconfirm(c, &hcnt, sizeof(int64_t));
+      if (CLIENT_DEBUG) fprintf(stderr, "Analysis of %"PRId64" halos complete (chunk %"PRId64")\n", hcnt, chunk);
+    }
+
+    clear_rsocket_tags();
+    if (!done || child > -1) tag_rsocket(c);
+    if (!done) tag_rsocket(s);
+    for (i=0; i<num_workers; i++) tag_rsocket(workers[i]);
+
+    max_cs = select_rsocket(RSOCKET_READ, 0);
+    for (i=0; i<max_cs; i++) {
+      if (!check_rsocket_tag(i)) continue;
+      if (i==s) {
+	new_w = accept_connection(s,NULL,NULL);
+	recv_from_socket(new_w, &worker_chunk, sizeof(int64_t));
+	if (worker_chunk == chunk) {
+	  assert(child < 0);
+	  child = new_w;
+	  child_has_connected = 1;
+	}
+	if (send_workunit(new_w, &w, &fofs, &parts, &no_more_work) ||
+	    (child == new_w)) {
+	  workers = check_realloc(workers, sizeof(int64_t)*(num_workers+1),
+				  "Allocating rockstar analysis FDs.");
+	  workers[num_workers] = new_w;
+	  num_workers++;
+	  if (CLIENT_DEBUG) fprintf(stderr, "Got new worker (chunk %"PRId64"; wchunk %"PRId64")\n", chunk, worker_chunk);
+	} else {
+	  close_rsocket(new_w);
+	}
+      }
+      else if (i==c) {
+	recv_from_socket(c, cmd, 4);
+	if (!strcmp(cmd, "fini")) {
+	  assert(child >= 0);
+	  send_to_socket(child, "fini", 4);
+	  close_connection(child, workers, &num_workers);
+	  child = -1;
+	  if (CLIENT_DEBUG) fprintf(stderr, "Told child to finish (chunk %"PRId64")\n", chunk);
+	}
+	else if (!strcmp(cmd, "work")) {
+	  assert(child >= 0);
+	  recv_from_socket(c, &id, sizeof(int64_t));
+	  address = recv_msg_nolength(c, address);
+	  port = recv_msg_nolength(c, port);
+	  send_to_socket(child, "work", 4);
+	  send_to_socket(child, &id, sizeof(int64_t));
+	  send_msg(child, address, strlen(address)+1);
+	  send_msg(child, port, strlen(port)+1);
+	  if (CLIENT_DEBUG) fprintf(stderr, "Child (%"PRId64") connecting to id %"PRId64"\n", chunk, id);
+	}
+	else if (!strcmp(cmd, "outp")) {
+	  assert(no_more_work && !done);
+	  recv_from_socket(c, &id_offset, sizeof(int64_t));
+	  output_and_free_halos(id_offset, snap, chunk, bounds);
+	  p = check_realloc(p, 0, "Freeing particle memory");
+	  num_p = 0;
+	  done = 1;
+	  if (CLIENT_DEBUG) fprintf(stderr, "Finished (chunk %"PRId64")\n", chunk);
+	}
+	else if (!strcmp(cmd, "quit")) {
+	  exit(1);
+	}
+	else if (!strcmp(cmd, "err!")) {
+	  in_error_state = 1;
+	  for (j=0; j<num_workers; j++) close_rsocket(workers[j]);
+	  num_workers = 0;
+	  break;
+	}
+	else { fprintf(stderr, "[Error] Server protocol error dw (%s)!\n", cmd); exit(1); }
+      }
+      else {
+	if (recv_from_socket(i, cmd, 4) <= 0) {
+	  network_io_err(c);
+	  for (j=0; j<num_workers; j++) close_rsocket(workers[j]);
+	  num_workers = 0;
+	  break;
+	}
+	if (!strcmp(cmd, "wrkd")) {
+	  recv_from_socket(i, &w, sizeof(struct workunit_info));
+	  assert(w.num_particles >= 0 && w.num_particles <= num_p);
+	  fofs = recv_and_alloc(i, fofs, sizeof(struct fof)*w.num_fofs);
+	  rhalos = recv_and_alloc(i, rhalos, sizeof(struct halo)*w.num_halos);
+	  ehi = recv_and_alloc(i, ehi, sizeof(struct extra_halo_info)*w.num_halos);
+	  parts = recv_and_alloc(i, parts, sizeof(struct particle)*w.num_particles);
+	  integrate_finished_workunit(&w, fofs, rhalos, ehi, parts);
+	  if (!send_workunit(i, &w, &fofs, &parts, &no_more_work) && 
+	      (child != i))
+	    close_connection(i, workers, &num_workers);
+	}
+	else if (!strcmp(cmd, "clos")) {
+	  close_connection(i, workers, &num_workers);
+	}
+	else if (!strcmp(cmd, "nmwk")) {
+	  assert(i == child);
+	  recv_from_socket(i, &id, sizeof(int64_t));
+	  send_to_socket_noconfirm(c, "nmwk", 4);
+	  send_to_socket_noconfirm(c, &id, sizeof(int64_t));
+	}
+
+	else { fprintf(stderr, "[Error] Client protocol error dw (%s)!\n", cmd); exit(1); }
+      }
+    }
+  }
+  check_realloc(address, 0, "Freeing address memory.");
+  check_realloc(port, 0, "Freeing port memory.");
+  check_realloc(workers, 0, "Freeing worker memory.");
+  check_realloc(fofs, 0, "Freeing FOF memory.");
+  check_realloc(parts, 0, "Freeing particle memory.");
+  check_realloc(rhalos, 0, "Freeing halo memory.");
+  check_realloc(ehi, 0, "Freeing extra halo info memory.");
+}
+
+
+void client(void) {
+  int64_t snap, block, chunk, type=-1, i, n, timestep, id_offset;
+  struct binary_output_header bheader;
+  uint64_t magic;
+  char buffer[1024];
+  char cmd[5] = {0};
+  char *hostname = NULL;
+  char port[10] = {0};
+  float bounds[6], box_size;
+  //struct recipient *r;
+  int64_t c, s = -1, portnum, readers;
+  int stat_loc;
+  int64_t num_nodes;
+