Merge branch 'release-4-5-patches' into release-4-6
[alexxy/gromacs.git] / src / tools / gmx_trjconv.c
index 48132f894acadefbf61682ec7bbe2a2025da8ceb..9d7ed66f5c7fa9a8424018a9296daea8269b8ac6 100644 (file)
@@ -1,36 +1,39 @@
 /*
- * 
- *                This source code is part of
- * 
- *                 G   R   O   M   A   C   S
- * 
- *          GROningen MAchine for Chemical Simulations
- * 
- *                        VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * This file is part of the GROMACS molecular simulation package.
+ *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team,
  * check out http://www.gromacs.org for more information.
-
- * 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 2
+ * Copyright (c) 2012, by the GROMACS development team, led by
+ * David van der Spoel, Berk Hess, Erik Lindahl, and including many
+ * others, as listed in the AUTHORS file in the top-level source
+ * directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
- * 
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
- * 
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- * 
- * For more info, check our website at http://www.gromacs.org
- * 
- * And Hey:
- * Green Red Orange Magenta Azure Cyan Skyblue
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -58,7 +61,6 @@
 #include "do_fit.h"
 #include "rmpbc.h"
 #include "wgms.h"
-#include "magic.h"
 #include "pbc.h"
 #include "viewit.h"
 #include "xvgr.h"
 enum { euSel,euRect, euTric, euCompact, euNR};
 
 
-static int 
-sort_comdist2(void *thunk, const void *a, const void *b)
-{
-    /* Thunk should point to a real array with the distance to the cluster COM for each molecule,
-     * a/b point to integers that refer to the molecule number. 
-     */
-    real *pcomdist2 = thunk;
-    int  ia    = * (int *)a;
-    int  ib    = * (int *)b;
-    int  rc;
-    
-    if(pcomdist2[ia]<pcomdist2[ib])
-    {
-        rc=-1;
-    }
-    else if (pcomdist2[ia]>pcomdist2[ib])
-    {
-        rc=1;
-    }
-    else
-    {
-        rc=0;
-    }
-    return rc;
-}
-
-
 static void calc_pbc_cluster(int ecenter,int nrefat,t_topology *top,int ePBC,
                              rvec x[],atom_id index[],
                              rvec clust_com,matrix box, rvec clustercenter)
@@ -305,7 +280,7 @@ static void put_molecule_com_in_box(int unitcell_enum,int ecenter,
         copy_rvec(com,new_com);
         switch (unitcell_enum) {
         case euRect: 
-            put_atoms_in_box(box,1,&new_com);
+            put_atoms_in_box(ePBC,box,1,&new_com);
             break;
         case euTric: 
             put_atoms_in_triclinic_unitcell(ecenter,box,1,&new_com);
@@ -353,7 +328,7 @@ static void put_residue_com_in_box(int unitcell_enum,int ecenter,
             copy_rvec(com,new_com);
             switch (unitcell_enum) {
             case euRect: 
-                put_atoms_in_box(box,1,&new_com);
+                put_atoms_in_box(ePBC,box,1,&new_com);
                 break;
             case euTric: 
                 put_atoms_in_triclinic_unitcell(ecenter,box,1,&new_com);
@@ -441,7 +416,7 @@ void check_trn(const char *fn)
         gmx_fatal(FARGS,"%s is not a trajectory file, exiting\n",fn);
 }
 
-#if (!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64)
+#ifndef GMX_NATIVE_WINDOWS
 void do_trunc(const char *fn, real t0)
 {
     t_fileio     *in;
@@ -744,7 +719,7 @@ int gmx_trjconv(int argc,char *argv[])
                         { &bVels }, "Read and write velocities if possible" },
                     { "-force", FALSE, etBOOL,
                         { &bForce }, "Read and write forces if possible" },
-#if (!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64)
+#ifndef GMX_NATIVE_WINDOWS
                     { "-trunc", FALSE, etTIME,
                         { &ttrunc }, 
                         "Truncate input trajectory file after this time (%t)" },
@@ -853,7 +828,7 @@ int gmx_trjconv(int argc,char *argv[])
     in_file=opt2fn("-f",NFILE,fnm);
 
     if (ttrunc != -1) {
-#if (!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64)
+#ifndef GMX_NATIVE_WINDOWS
         do_trunc(in_file,ttrunc);
 #endif
     }
@@ -1364,7 +1339,7 @@ int gmx_trjconv(int argc,char *argv[])
                         if (bPBCcomAtom) {
                             switch (unitcell_enum) {
                             case euRect:
-                                put_atoms_in_box(fr.box,natoms,fr.x);
+                                put_atoms_in_box(ePBC,fr.box,natoms,fr.x);
                                 break;
                             case euTric:
                                 put_atoms_in_triclinic_unitcell(ecenter,fr.box,natoms,fr.x);
@@ -1555,6 +1530,8 @@ int gmx_trjconv(int argc,char *argv[])
         fprintf(stderr,"\n");
 
         close_trj(status);
+        sfree(outf_base);
+
        if (bRmPBC)
          gmx_rmpbc_done(gpbc);