Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_gyrate.cpp
similarity index 95%
rename from src/gromacs/gmxana/gmx_gyrate.c
rename to src/gromacs/gmxana/gmx_gyrate.cpp
index 6b2b93762622f64c75b2aae47ae60f17472a45cf..4d6dc09f3f25c7311ed9bc77df273cc3eefd2eae 100644 (file)
@@ -36,8 +36,8 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
@@ -76,7 +76,7 @@ real calc_gyro(rvec x[], int gnx, atom_id index[], t_atom atom[], real tm,
         }
         for (m = 0; (m < DIM); m++)
         {
-            d[m] = sqrt(d[m]/tm);
+            d[m] = std::sqrt(d[m]/tm);
         }
 #ifdef DEBUG
         pr_rvecs(stderr, 0, "trans", trans, DIM);
@@ -89,7 +89,7 @@ real calc_gyro(rvec x[], int gnx, atom_id index[], t_atom atom[], real tm,
         ii = index[i];
         if (bQ)
         {
-            m0 = fabs(atom[ii].q);
+            m0 = std::abs(atom[ii].q);
         }
         else
         {
@@ -105,10 +105,10 @@ real calc_gyro(rvec x[], int gnx, atom_id index[], t_atom atom[], real tm,
 
     for (m = 0; (m < DIM); m++)
     {
-        gvec[m] = sqrt((gyro-comp[m])/tm);
+        gvec[m] = std::sqrt((gyro-comp[m])/tm);
     }
 
-    return sqrt(gyro/tm);
+    return std::sqrt(gyro/tm);
 }
 
 void calc_gyro_z(rvec x[], matrix box,
@@ -146,12 +146,12 @@ void calc_gyro_z(rvec x[], matrix box,
         }
         for (j = 0; j < 2; j++)
         {
-            zi = zf + j;
+            zi = static_cast<int>(zf + j);
             if (zi == nz)
             {
                 zi = 0;
             }
-            w               = atom[ii].m*(1 + cos(M_PI*(zf - zi)));
+            w               = atom[ii].m*(1 + std::cos(M_PI*(zf - zi)));
             inertia[zi][0] += w*sqr(x[ii][YY]);
             inertia[zi][1] += w*sqr(x[ii][XX]);
             inertia[zi][2] -= w*x[ii][XX]*x[ii][YY];
@@ -165,9 +165,9 @@ void calc_gyro_z(rvec x[], matrix box,
         {
             inertia[j][i] /= tm[j];
         }
-        sdet = sqrt(sqr(inertia[j][0] - inertia[j][1]) + 4*sqr(inertia[j][2]));
-        e1   = sqrt(0.5*(inertia[j][0] + inertia[j][1] + sdet));
-        e2   = sqrt(0.5*(inertia[j][0] + inertia[j][1] - sdet));
+        sdet = std::sqrt(sqr(inertia[j][0] - inertia[j][1]) + 4*sqr(inertia[j][2]));
+        e1   = std::sqrt(0.5*(inertia[j][0] + inertia[j][1] + sdet));
+        e2   = std::sqrt(0.5*(inertia[j][0] + inertia[j][1] - sdet));
         fprintf(out, " %5.3f %5.3f", e1, e2);
     }
     fprintf(out, "\n");
@@ -217,7 +217,7 @@ int gmx_gyrate(int argc, char *argv[])
     real            t, t0, tm, gyro;
     int             natoms;
     char           *grpname, title[256];
-    int             i, j, m, gnx, nam, mol;
+    int             j, m, gnx, nam, mol;
     atom_id        *index;
     output_env_t    oenv;
     gmx_rmpbc_t     gpbc   = NULL;
@@ -324,7 +324,9 @@ int gmx_gyrate(int argc, char *argv[])
         }
         gyro = 0;
         clear_rvec(gvec);
+        clear_rvec(gvec1);
         clear_rvec(d);
+        clear_rvec(d1);
         for (mol = 0; mol < nmol; mol++)
         {
             tm    = sub_xcm(nz == 0 ? x_s : x, nam, index+mol*nam, top.atoms.atom, xcm, bQ);