Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_rmsdist.cpp
similarity index 93%
rename from src/gromacs/gmxana/gmx_rmsdist.c
rename to src/gromacs/gmxana/gmx_rmsdist.cpp
index ad79bb2945c448fc1ca38076119adaaa44d01afb..80245997d036042ec613dca7e1ca7d40e824d60a 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -74,7 +77,7 @@ static void calc_dist(int nind, atom_id index[], rvec x[], int ePBC, matrix box,
         {
             pbc_dx(&pbc, xi, x[index[j]], dx);
             temp2   = norm2(dx);
-            d[i][j] = sqrt(temp2);
+            d[i][j] = std::sqrt(temp2);
         }
     }
 }
@@ -98,7 +101,7 @@ static void calc_dist_tot(int nind, atom_id index[], rvec x[],
         {
             pbc_dx(&pbc, xi, x[index[j]], dx);
             temp2        = norm2(dx);
-            temp         = sqrt(temp2);
+            temp         = std::sqrt(temp2);
             d[i][j]      = temp;
             dtot[i][j]  += temp;
             dtot2[i][j] += temp2;
@@ -122,8 +125,8 @@ static void calc_nmr(int nind, int nframes, real **dtot1_3, real **dtot1_6,
     {
         for (j = i+1; (j < nind); j++)
         {
-            temp1_3 = pow(dtot1_3[i][j]/nframes, -1.0/3.0);
-            temp1_6 = pow(dtot1_6[i][j]/nframes, -1.0/6.0);
+            temp1_3 = std::pow(dtot1_3[i][j]/nframes, static_cast<real>(-1.0/3.0));
+            temp1_6 = std::pow(dtot1_6[i][j]/nframes, static_cast<real>(-1.0/6.0));
             if (temp1_3 > *max1_3)
             {
                 *max1_3 = temp1_3;
@@ -250,8 +253,8 @@ static gmx_bool is_equiv(int neq, t_equiv **equiv, char **nname,
         for (j = 0; equiv[i][j].rnr != NOTSET && !bFound; j++)
         {
             bFound = ( equiv[i][j].rnr == rnr1 &&
-                       strcmp(equiv[i][j].rname, rname1) == 0 &&
-                       strcmp(equiv[i][j].aname, aname1) == 0 );
+                       std::strcmp(equiv[i][j].rname, rname1) == 0 &&
+                       std::strcmp(equiv[i][j].aname, aname1) == 0 );
         }
         if (bFound)
         {
@@ -260,8 +263,8 @@ static gmx_bool is_equiv(int neq, t_equiv **equiv, char **nname,
             for (j = 0; equiv[i][j].rnr != NOTSET && !bFound; j++)
             {
                 bFound = ( equiv[i][j].rnr == rnr2 &&
-                           strcmp(equiv[i][j].rname, rname2) == 0 &&
-                           strcmp(equiv[i][j].aname, aname2) == 0 );
+                           std::strcmp(equiv[i][j].rname, rname2) == 0 &&
+                           std::strcmp(equiv[i][j].aname, aname2) == 0 );
             }
         }
     }
@@ -278,7 +281,6 @@ static int analyze_noe_equivalent(const char *eq_fn,
                                   gmx_bool bSumH,
                                   atom_id *noe_index, t_noe_gr *noe_gr)
 {
-    FILE     *fp;
     int       i, j, anmil, anmjl, rnri, rnrj, gi, groupnr, neq;
     char     *anmi, *anmj, **nnm;
     gmx_bool  bMatch, bEquiv;
@@ -340,16 +342,16 @@ static int analyze_noe_equivalent(const char *eq_fn,
                    X are any number of letters or digits and ? goes from 1 to 3
                    This is supposed to cover all CH3 groups and the like */
                 anmi   = *atoms->atomname[index[i]];
-                anmil  = strlen(anmi);
+                anmil  = std::strlen(anmi);
                 bMatch = i <= isize-3 && anmi[anmil-1] == '1';
                 if (bMatch)
                 {
                     for (j = 1; j < 3; j++)
                     {
                         anmj   = *atoms->atomname[index[i+j]];
-                        anmjl  = strlen(anmj);
+                        anmjl  = std::strlen(anmj);
                         bMatch = bMatch && ( anmil == anmjl && anmj[anmjl-1] == Hnum[j] &&
-                                             strncmp(anmi, anmj, anmil-1) == 0 );
+                                             std::strncmp(anmi, anmj, anmil-1) == 0 );
                     }
                 }
                 /* set index for this atom */
@@ -406,7 +408,7 @@ static int analyze_noe_equivalent(const char *eq_fn,
                 noe_gr[gi].aname = gmx_strdup(*atoms->atomname[index[i]]);
                 if (noe_index[i] == noe_index[i+1])
                 {
-                    noe_gr[gi].aname[strlen(noe_gr[gi].aname)-1] = '*';
+                    noe_gr[gi].aname[std::strlen(noe_gr[gi].aname)-1] = '*';
                 }
             }
             noe_gr[gi].rnr   = atoms->atom[index[i]].resind;
@@ -443,8 +445,8 @@ static char *noe2scale(real r3, real r6, real rmax)
     /* r goes from 0 to rmax
        NSCALE*r/rmax goes from 0 to NSCALE
        NSCALE - NSCALE*r/rmax goes from NSCALE to 0 */
-    s3 = NSCALE - min(NSCALE, (int)(NSCALE*r3/rmax));
-    s6 = NSCALE - min(NSCALE, (int)(NSCALE*r6/rmax));
+    s3 = NSCALE - std::min(NSCALE, static_cast<int>(NSCALE*r3/rmax));
+    s6 = NSCALE - std::min(NSCALE, static_cast<int>(NSCALE*r6/rmax));
 
     for (i = 0; i < s3; i++)
     {
@@ -472,8 +474,8 @@ static void calc_noe(int isize, atom_id *noe_index,
         {
             gj = noe_index[j];
             noe[gi][gj].nr++;
-            noe[gi][gj].i_3 += pow(dtot1_3[i][j], -3);
-            noe[gi][gj].i_6 += pow(dtot1_6[i][j], -6);
+            noe[gi][gj].i_3 += std::pow(dtot1_3[i][j], static_cast<real>(-3.0));
+            noe[gi][gj].i_6 += std::pow(dtot1_6[i][j], static_cast<real>(-6.0));
         }
     }
 
@@ -482,8 +484,8 @@ static void calc_noe(int isize, atom_id *noe_index,
     {
         for (j = i+1; j < gnr; j++)
         {
-            noe[i][j].r_3 = pow(noe[i][j].i_3/noe[i][j].nr, -1.0/3.0);
-            noe[i][j].r_6 = pow(noe[i][j].i_6/noe[i][j].nr, -1.0/6.0);
+            noe[i][j].r_3 = std::pow(noe[i][j].i_3/noe[i][j].nr, static_cast<real>(-1.0/3.0));
+            noe[i][j].r_6 = std::pow(noe[i][j].i_6/noe[i][j].nr, static_cast<real>(-1.0/6.0));
             noe[j][i]     = noe[i][j];
         }
     }
@@ -509,8 +511,8 @@ static void write_noe(FILE *fp, int gnr, t_noe **noe, t_noe_gr *noe_gr, real rma
             grj  = noe_gr[j];
             r3   = noe[i][j].r_3;
             r6   = noe[i][j].r_6;
-            min3 = min(r3, min3);
-            min6 = min(r6, min6);
+            min3 = std::min(r3, min3);
+            min6 = std::min(r6, min6);
             if (r3 < rmax || r6 < rmax)
             {
                 if (grj.rnr == gri.rnr)
@@ -527,7 +529,7 @@ static void write_noe(FILE *fp, int gnr, t_noe **noe, t_noe_gr *noe_gr, real rma
                 }
                 else
                 {
-                    strcpy(b3, "-");
+                    std::strcpy(b3, "-");
                 }
                 if (r6 < rmax)
                 {
@@ -535,13 +537,13 @@ static void write_noe(FILE *fp, int gnr, t_noe **noe, t_noe_gr *noe_gr, real rma
                 }
                 else
                 {
-                    strcpy(b6, "-");
+                    std::strcpy(b6, "-");
                 }
                 fprintf(fp,
                         "%4d %4d %4s %4s%3d %4d %4d %4s %4s%3d %5s %5s %8d %2d %2s %s\n",
                         gri.ianr+1, gri.anr+1, gri.aname, gri.rname, gri.rnr+1,
                         grj.ianr+1, grj.anr+1, grj.aname, grj.rname, grj.rnr+1,
-                        b3, b6, (int)(noe[i][j].i_6+0.5), grj.rnr-gri.rnr, buf,
+                        b3, b6, static_cast<int>(noe[i][j].i_6+0.5), grj.rnr-gri.rnr, buf,
                         noe2scale(r3, r6, rmax));
             }
         }
@@ -584,7 +586,7 @@ static void calc_rms(int nind, int nframes,
         {
             mean  = dtot[i][j]/nframes;
             mean2 = dtot2[i][j]/nframes;
-            rms   = sqrt(max(0, mean2-mean*mean));
+            rms   = std::sqrt(std::max(static_cast<real>(0.0), mean2-mean*mean));
             rmsc  = rms/mean;
             if (mean > *meanmax)
             {
@@ -621,7 +623,7 @@ real rms_diff(int natom, real **d, real **d_r)
     }
     r2 /= (natom*(natom-1))/2;
 
-    return sqrt(r2);
+    return std::sqrt(r2);
 }
 
 int gmx_rmsdist(int argc, char *argv[])
@@ -650,7 +652,7 @@ int gmx_rmsdist(int argc, char *argv[])
 
     };
 
-    int             natom, i, j, teller, gi, gj;
+    int             i, teller;
     real            t;
 
     t_topology      top;
@@ -785,7 +787,7 @@ int gmx_rmsdist(int argc, char *argv[])
     }
 
     /*do a first step*/
-    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);
     teller = 0;
 
     do