Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_eneconv.cpp
similarity index 97%
rename from src/gromacs/gmxana/gmx_eneconv.c
rename to src/gromacs/gmxana/gmx_eneconv.cpp
index f04541ca90d32da08676ddacd812a2173d2f2456..e5cc4ab9124003797df6a1fd1a16809856ba565d 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/enxio.h"
@@ -148,7 +150,7 @@ static int scan_ene_files(char **fnms, int nfiles,
                           real *readtime, real *timestep, int *nremax)
 {
     /* Check number of energy terms and start time of all files */
-    int          f, i, nre, nremin = 0, nresav = 0;
+    int          f, nre, nremin = 0, nresav = 0;
     ener_file_t  in;
     real         t1, t2;
     char         inputstring[STRLEN];
@@ -178,8 +180,8 @@ static int scan_ene_files(char **fnms, int nfiles,
         }
         else
         {
-            nremin  = min(nremin, fr->nre);
-            *nremax = max(*nremax, fr->nre);
+            nremin  = std::min(nremin, fr->nre);
+            *nremax = std::max(*nremax, fr->nre);
             if (nre != nresav)
             {
                 fprintf(stderr,
@@ -253,7 +255,7 @@ static void edit_files(char **fnms, int nfiles, real *readtime,
                 {
                     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')
                 {
@@ -468,7 +470,7 @@ static void update_ee_sum(int nre,
                     fr->ener[i].eav +
                     dsqr(ee_sum[i].esum/nsum
                          - (ee_sum[i].esum + fr->ener[i].esum)/(nsum + fr->nsum))*
-                    nsum*(nsum + fr->nsum)/(double)fr->nsum;
+                    nsum*(nsum + fr->nsum)/static_cast<double>(fr->nsum);
                 ee_sum[i].esum += fr->ener[i].esum;
             }
         }
@@ -521,14 +523,13 @@ int gmx_eneconv(int argc, char *argv[])
     t_enxframe     *fr, *fro;
     gmx_int64_t     ee_sum_step = 0, ee_sum_nsteps, ee_sum_nsum;
     t_energy       *ee_sum;
-    gmx_int64_t     lastfilestep, laststep, startstep, startstep_file = 0;
+    gmx_int64_t     lastfilestep, laststep, startstep_file = 0;
     int             noutfr;
-    int             nre, nremax, this_nre, nfile, f, i, j, kkk, nset, *set = NULL;
+    int             nre, nremax, this_nre, nfile, f, i, kkk, nset, *set = NULL;
     double          last_t;
     char          **fnms;
-    real           *readtime, *settime, timestep, t1, tadjust;
-    char            inputstring[STRLEN], *chptr, buf[22], buf2[22], buf3[22];
-    gmx_bool        ok;
+    real           *readtime, *settime, timestep, tadjust;
+    char            buf[22], buf2[22];
     int            *cont_type;
     gmx_bool        bNewFile, bFirst, bNewOutput;
     output_env_t    oenv;
@@ -583,7 +584,7 @@ int gmx_eneconv(int argc, char *argv[])
     timestep = 0.0;
     snew(fnms, argc);
     lastfilestep = 0;
-    laststep     = startstep = 0;
+    laststep     = 0;
 
     nfile = opt2fns(&fnms, "-f", NFILE, fnm);
 
@@ -690,7 +691,6 @@ int gmx_eneconv(int argc, char *argv[])
                 if (bFirst)
                 {
                     bFirst    = FALSE;
-                    startstep = fr->step;
                 }
                 if (bWrite)
                 {