Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_clustsize.cpp
similarity index 96%
rename from src/gromacs/gmxana/gmx_clustsize.c
rename to src/gromacs/gmxana/gmx_clustsize.cpp
index 6aa02a2a954c7c72a62ad51966df3d4a5ae902d6..337e630101e07eff8a274d192f48a31fa27a3c73 100644 (file)
@@ -36,7 +36,9 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
+#include <cmath>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/matio.h"
@@ -56,6 +58,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 static void clust_size(const char *ndx, const char *trx, const char *xpm,
@@ -83,12 +86,12 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
     t_block              *mols = NULL;
     gmx_mtop_atomlookup_t alook;
     t_atom               *atom;
-    int                   version, generation, ii, jj, nsame;
+    int                   version, generation, ii, jj;
     real                  temp, tfac;
     /* Cluster size distribution (matrix) */
     real                **cs_dist = NULL;
     real                  tf, dx2, cut2, *t_x = NULL, *t_y, cmid, cmax, cav, ekin;
-    int                   i, j, k, ai, aj, ak, ci, cj, nframe, nclust, n_x, n_y, max_size = 0;
+    int                   i, j, k, ai, aj, ci, cj, nframe, nclust, n_x, max_size = 0;
     int                  *clust_index, *clust_size, max_clust_size, max_clust_ind, nav, nhisto;
     t_rgb                 rlo = { 1.0, 1.0, 1.0 };
 
@@ -136,6 +139,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
             printf("Using molecules rather than atoms. Not reading index file %s\n",
                    ndx);
         }
+        GMX_RELEASE_ASSERT(mtop != NULL, "Trying to access mtop->mols from NULL mtop pointer");
         mols = &(mtop->mols);
 
         /* Make dummy index */
@@ -205,6 +209,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
                         /* Compute distance */
                         if (bMol)
                         {
+                            GMX_RELEASE_ASSERT(mols != NULL, "Cannot access index[] from NULL mols pointer");
                             bSame = FALSE;
                             for (ii = mols->index[ai]; !bSame && (ii < mols->index[ai+1]); ii++)
                             {
@@ -280,7 +285,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
                 {
                     nclust++;
                     cs_dist[n_x-1][ci-1] += 1.0;
-                    max_size              = max(max_size, ci);
+                    max_size              = std::max(max_size, ci);
                     if (ci > 1)
                     {
                         cav += ci;
@@ -348,6 +353,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
             {
                 if (bMol)
                 {
+                    GMX_RELEASE_ASSERT(mols != NULL, "Cannot access index[] from NULL mols pointer");
                     for (j = mols->index[i]; (j < mols->index[i+1]); j++)
                     {
                         fprintf(fp, "%d\n", j+1);
@@ -374,7 +380,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
             nelem += cs_dist[i][j];
         }
         fprintf(fp, "%5d  %8.3f\n", j+1, nelem/n_x);
-        nhisto += (int)((j+1)*nelem/n_x);
+        nhisto += static_cast<int>((j+1)*nelem/n_x);
     }
     fprintf(fp, "%5d  %8.3f\n", j+1, 0.0);
     xvgrclose(fp);
@@ -394,7 +400,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
             {
                 cmid = cs_dist[i][j];
             }
-            cmax = max(cs_dist[i][j], cmax);
+            cmax = std::max(cs_dist[i][j], cmax);
         }
     }
     fprintf(stderr, "cmid: %g, cmax: %g, max_size: %d\n", cmid, cmax, max_size);
@@ -415,7 +421,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm,
             {
                 cmid = cs_dist[i][j];
             }
-            cmax = max(cs_dist[i][j], cmax);
+            cmax = std::max(cs_dist[i][j], cmax);
         }
     }
     fprintf(stderr, "cmid: %g, cmax: %g, max_size: %d\n", cmid, cmax, max_size);
@@ -482,7 +488,6 @@ int gmx_clustsize(int argc, char *argv[])
     };
 #define NPA asize(pa)
     const char     *fnNDX, *fnTPR;
-    gmx_bool        bSQ, bRDF;
     t_rgb           rgblo, rgbhi;
 
     t_filenm        fnm[] = {