Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_trjcat.cpp
similarity index 97%
rename from src/gromacs/gmxana/gmx_trjcat.c
rename to src/gromacs/gmxana/gmx_trjcat.cpp
index d6c2335650c06fa4d2aeee205abe5af5fc829234..1ddc5ca074d3c8460b112e0f3788e4ea328fa6ae 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -74,7 +76,6 @@ static void scan_trj_files(char **fnms, int nfiles, real *readtime,
     /* Check start time of all files */
     int          i, natoms = 0;
     t_trxstatus *status;
-    real         t;
     t_trxframe   fr;
     gmx_bool     ok;
 
@@ -214,7 +215,7 @@ static void edit_files(char **fnms, int nfiles, real *readtime, real *timestep,
                     gmx_fatal(FARGS, "Error reading user input" );
                 }
 
-                inputstring[strlen(inputstring)-1] = 0;
+                inputstring[std::strlen(inputstring)-1] = 0;
 
                 if (inputstring[0] == 'c' || inputstring[0] == 'C')
                 {
@@ -472,24 +473,22 @@ int gmx_trjcat(int argc, char *argv[])
           { &bCat }, "Do not discard double time frames" }
     };
 #define npargs asize(pa)
-    int          ftpin, i, frame, frame_out, step = 0, trjout = 0;
+    int          ftpin, i, frame, frame_out;
     t_trxstatus *status, *trxout = NULL;
-    rvec        *x, *v;
     real         t_corr;
     t_trxframe   fr, frout;
-    char       **fnms, **fnms_out, *in_file, *out_file;
+    char       **fnms, **fnms_out, *out_file;
     int          n_append;
     gmx_bool     bNewFile, bIndex, bWrite;
-    int          earliersteps, nfile_in, nfile_out, *cont_type, last_ok_step;
+    int          nfile_in, nfile_out, *cont_type;
     real        *readtime, *timest, *settime;
     real         first_time = 0, lasttime = NOTSET, last_ok_t = -1, timestep;
     real         last_frame_time, searchtime;
-    int          isize, j;
+    int          isize = 0, j;
     atom_id     *index = NULL, imax;
     char        *grpname;
     real       **val = NULL, *t = NULL, dt_remd;
     int          n, nset, ftpout = -1, prevEndStep = 0, filetype;
-    gmx_bool     bOK;
     gmx_off_t    fpos;
     output_env_t oenv;
     t_filenm     fnm[] =
@@ -521,7 +520,7 @@ int gmx_trjcat(int argc, char *argv[])
         imax = index[0];
         for (i = 1; i < isize; i++)
         {
-            imax = max(imax, index[i]);
+            imax = std::max(imax, index[i]);
         }
     }
     if (bDeMux)
@@ -590,7 +589,7 @@ int gmx_trjcat(int argc, char *argv[])
             snew(fnms_out, nset);
             for (i = 0; (i < nset); i++)
             {
-                snew(fnms_out[i], strlen(buf)+32);
+                snew(fnms_out[i], std::strlen(buf)+32);
                 sprintf(fnms_out[i], "%d_%s", i, buf);
             }
             sfree(buf);
@@ -616,7 +615,7 @@ int gmx_trjcat(int argc, char *argv[])
         n_append = -1;
         for (i = 0; ((i < nfile_in) && (n_append == -1)); i++)
         {
-            if (strcmp(fnms[i], out_file) == 0)
+            if (std::strcmp(fnms[i], out_file) == 0)
             {
                 n_append = i;
             }
@@ -631,7 +630,6 @@ int gmx_trjcat(int argc, char *argv[])
             gmx_fatal(FARGS, "Can only append to the first file which is %s (not %s)",
                       fnms[0], out_file);
         }
-        earliersteps = 0;
 
         /* Not checking input format, could be dangerous :-) */
         /* Not checking output format, equally dangerous :-) */
@@ -666,7 +664,7 @@ int gmx_trjcat(int argc, char *argv[])
             {
                 trxout = open_trx(out_file, "w");
             }
-            memset(&frout, 0, sizeof(frout));
+            std::memset(&frout, 0, sizeof(frout));
         }
         else
         {
@@ -731,7 +729,7 @@ int gmx_trjcat(int argc, char *argv[])
                     gmx_fatal(FARGS, "Error seeking to append position.");
                 }
                 read_next_frame(oenv, status, &fr);
-                if (fabs(searchtime - fr.time) > timest[0]*0.5)
+                if (std::abs(searchtime - fr.time) > timest[0]*0.5)
                 {
                     gmx_fatal(FARGS, "Error seeking: attempted to seek to %f but got %f.",
                               searchtime, fr.time);
@@ -908,8 +906,6 @@ int gmx_trjcat(int argc, char *argv[])
             while (read_next_frame(oenv, status, &fr));
 
             close_trj(status);
-
-            earliersteps += step;
         }
         if (trxout)
         {