Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_vanhove.cpp
similarity index 93%
rename from src/gromacs/gmxana/gmx_vanhove.c
rename to src/gromacs/gmxana/gmx_vanhove.cpp
index 8d046f4b6afa12190776315795c3abc443b5018a..340491acaeda9ae17f2d40c8593be426f3370010 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -56,6 +55,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 
@@ -135,7 +135,7 @@ int gmx_vanhove(int argc, char *argv[])
     int          ePBC;
     matrix       boxtop, box, *sbox, avbox, corr;
     rvec        *xtop, *x, **sx;
-    int          isize, nalloc, nallocn, natom;
+    int          isize, nalloc, nallocn;
     t_trxstatus *status;
     atom_id     *index;
     char        *grpname;
@@ -189,7 +189,7 @@ int gmx_vanhove(int argc, char *argv[])
     sx     = NULL;
     clear_mat(avbox);
 
-    natom = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+    read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
     nfr   = 0;
     do
     {
@@ -200,7 +200,8 @@ int gmx_vanhove(int argc, char *argv[])
             srenew(sbox, nalloc);
             srenew(sx, nalloc);
         }
-        assert(time != NULL); assert(sbox != NULL);
+        GMX_RELEASE_ASSERT(time != NULL, "Memory allocation failure; time array is NULL");
+        GMX_RELEASE_ASSERT(sbox != NULL, "Memory allocation failure; sbox array is NULL");
 
         time[nfr] = t;
         copy_mat(box, sbox[nfr]);
@@ -226,7 +227,7 @@ int gmx_vanhove(int argc, char *argv[])
 
     dt = (time[nfr-1] - time[0])/(nfr - 1);
     /* Some ugly rounding to get nice nice times in the output */
-    dt = (int)(10000.0*dt + 0.5)/10000.0;
+    dt = static_cast<int>((10000.0*dt + 0.5)/10000.0);
 
     invbin = 1.0/rbin;
 
@@ -237,7 +238,7 @@ int gmx_vanhove(int argc, char *argv[])
             fmmax = nfr - 1;
         }
         snew(mcount, fmmax);
-        nbin = (int)(rmax*invbin + 0.5);
+        nbin = static_cast<int>(rmax*invbin + 0.5);
         if (sbin == 0)
         {
             mat_nx = fmmax + 1;
@@ -245,7 +246,7 @@ int gmx_vanhove(int argc, char *argv[])
         else
         {
             invsbin = 1.0/sbin;
-            mat_nx  = sqrt(fmmax*dt)*invsbin + 1;
+            mat_nx  = static_cast<int>(std::sqrt(fmmax*dt)*invsbin + 1);
         }
         snew(mat, mat_nx);
         for (f = 0; f < mat_nx; f++)
@@ -327,14 +328,14 @@ int gmx_vanhove(int argc, char *argv[])
                 }
                 else
                 {
-                    mbin = (int)(sqrt(fbin*dt)*invsbin + 0.5);
+                    mbin = static_cast<int>(std::sqrt(fbin*dt)*invsbin + 0.5);
                 }
                 for (i = 0; i < isize; i++)
                 {
                     d2 = distance2(sx[f][i], sx[ff][i]);
                     if (mbin < mat_nx && d2 < rmax2)
                     {
-                        bin = (int)(sqrt(d2)*invbin + 0.5);
+                        bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
                         if (bin < nbin)
                         {
                             mat[mbin][bin] += 1;
@@ -365,7 +366,7 @@ int gmx_vanhove(int argc, char *argv[])
                     for (i = 0; i < isize; i++)
                     {
                         d2  = distance2(sx[f][i], sx[ff][i]);
-                        bin = (int)(sqrt(d2)*invbin + 0.5);
+                        bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
                         if (bin >= nalloc)
                         {
                             nallocn = 10*(bin/10) + 11;
@@ -452,8 +453,7 @@ int gmx_vanhove(int argc, char *argv[])
             fprintf(fp, "%g", i*rbin);
             for (fbin = 0; fbin < nr; fbin++)
             {
-                fprintf(fp, " %g",
-                        (real)pr[fbin][i]/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1)));
+                fprintf(fp, " %g", static_cast<real>(pr[fbin][i])/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0)));
             }
             fprintf(fp, "\n");
         }
@@ -470,7 +470,7 @@ int gmx_vanhove(int argc, char *argv[])
         }
         for (f = 0; f <= ftmax; f++)
         {
-            fprintf(fp, "%g %g\n", f*dt, (real)pt[f]/(tcount[f]*isize));
+            fprintf(fp, "%g %g\n", f*dt, static_cast<real>(pt[f])/(tcount[f]*isize));
         }
         xvgrclose(fp);
     }