Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_covar.cpp
similarity index 96%
rename from src/gromacs/gmxana/gmx_covar.c
rename to src/gromacs/gmxana/gmx_covar.cpp
index 779326f0b5a91ab8473a45f602a691da66ba2b33..6338262b25c1bb512966725848b5f1c4ca77b63d 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/fileio/confio.h"
@@ -111,7 +111,6 @@ int gmx_covar(int argc, char *argv[])
     };
     FILE           *out = NULL; /* initialization makes all compilers happy */
     t_trxstatus    *status;
-    t_trxstatus    *trjout;
     t_topology      top;
     int             ePBC;
     t_atoms        *atoms;
@@ -121,14 +120,13 @@ int gmx_covar(int argc, char *argv[])
     real            t, tstart, tend, **mat2;
     real            xj, *w_rls = NULL;
     real            min, max, *axis;
-    int             ntopatoms, step;
-    int             natoms, nat, count, nframes0, nframes, nlevels;
+    int             natoms, nat, nframes0, nframes, nlevels;
     gmx_int64_t     ndim, i, j, k, l;
     int             WriteXref;
     const char     *fitfile, *trxfile, *ndxfile;
     const char     *eigvalfile, *eigvecfile, *averfile, *logfile;
     const char     *asciifile, *xpmfile, *xpmafile;
-    char            str[STRLEN], *fitname, *ananame, *pcwd;
+    char            str[STRLEN], *fitname, *ananame;
     int             d, dj, nfit;
     atom_id        *index, *ifit;
     gmx_bool        bDiffMass1, bDiffMass2;
@@ -209,7 +207,7 @@ int gmx_covar(int argc, char *argv[])
     {
         if (bM)
         {
-            sqrtm[i] = sqrt(atoms->atom[index[i]].m);
+            sqrtm[i] = std::sqrt(atoms->atom[index[i]].m);
             if (i)
             {
                 bDiffMass2 = bDiffMass2 || (sqrtm[i] != sqrtm[i-1]);
@@ -224,7 +222,6 @@ int gmx_covar(int argc, char *argv[])
     if (bFit && bDiffMass1 && !bDiffMass2)
     {
         bDiffMass1 = natoms != nfit;
-        i          = 0;
         for (i = 0; (i < natoms) && !bDiffMass1; i++)
         {
             bDiffMass1 = index[i] != ifit[i];
@@ -256,7 +253,7 @@ int gmx_covar(int argc, char *argv[])
     snew(x, natoms);
     snew(xav, natoms);
     ndim = natoms*DIM;
-    if (sqrt(GMX_INT64_MAX) < ndim)
+    if (std::sqrt(static_cast<real>(GMX_INT64_MAX)) < static_cast<real>(ndim))
     {
         gmx_fatal(FARGS, "Number of degrees of freedoms to large for matrix.\n");
     }
@@ -303,7 +300,7 @@ int gmx_covar(int argc, char *argv[])
                            atoms, xread, NULL, epbcNONE, zerobox, natoms, index);
     sfree(xread);
 
-    fprintf(stderr, "Constructing covariance matrix (%dx%d) ...\n", (int)ndim, (int)ndim);
+    fprintf(stderr, "Constructing covariance matrix (%dx%d) ...\n", static_cast<int>(ndim), static_cast<int>(ndim));
     nframes = 0;
     nat     = read_first_x(oenv, &status, trxfile, &t, &xread, box);
     tstart  = t;
@@ -517,7 +514,7 @@ int gmx_covar(int argc, char *argv[])
     snew(eigenvalues, ndim);
     snew(eigenvectors, ndim*ndim);
 
-    memcpy(eigenvectors, mat, ndim*ndim*sizeof(real));
+    std::memcpy(eigenvectors, mat, ndim*ndim*sizeof(real));
     fprintf(stderr, "\nDiagonalizing ...\n");
     fflush(stderr);
     eigensolver(eigenvectors, ndim, 0, ndim, eigenvalues, mat);
@@ -532,7 +529,7 @@ int gmx_covar(int argc, char *argv[])
     }
     fprintf(stderr, "\nSum of the eigenvalues: %g (%snm^2)\n",
             sum, bM ? "u " : "");
-    if (fabs(trace-sum) > 0.01*trace)
+    if (std::abs(trace-sum) > 0.01*trace)
     {
         fprintf(stderr, "\nWARNING: eigenvalue sum deviates from the trace of the covariance matrix\n");
     }
@@ -545,7 +542,7 @@ int gmx_covar(int argc, char *argv[])
             end = nframes-1;
             fprintf(stderr, "\nWARNING: there are fewer frames in your trajectory than there are\n");
             fprintf(stderr, "degrees of freedom in your system. Only generating the first\n");
-            fprintf(stderr, "%d out of %d eigenvectors and eigenvalues.\n", end, (int)ndim);
+            fprintf(stderr, "%d out of %d eigenvectors and eigenvalues.\n", end, static_cast<int>(ndim));
         }
         else
         {
@@ -561,7 +558,7 @@ int gmx_covar(int argc, char *argv[])
                    "Eigenvector index", str, oenv);
     for (i = 0; (i < end); i++)
     {
-        fprintf (out, "%10d %g\n", (int)i+1, eigenvalues[ndim-1-i]);
+        fprintf (out, "%10d %g\n", static_cast<int>(i+1), eigenvalues[ndim-1-i]);
     }
     xvgrclose(out);
 
@@ -626,13 +623,13 @@ int gmx_covar(int argc, char *argv[])
     {
         fprintf(out, "Fit is %smass weighted\n", bDiffMass1 ? "" : "non-");
     }
-    fprintf(out, "Diagonalized the %dx%d covariance matrix\n", (int)ndim, (int)ndim);
+    fprintf(out, "Diagonalized the %dx%d covariance matrix\n", static_cast<int>(ndim), static_cast<int>(ndim));
     fprintf(out, "Trace of the covariance matrix before diagonalizing: %g\n",
             trace);
     fprintf(out, "Trace of the covariance matrix after diagonalizing: %g\n\n",
             sum);
 
-    fprintf(out, "Wrote %d eigenvalues to %s\n", (int)end, eigvalfile);
+    fprintf(out, "Wrote %d eigenvalues to %s\n", static_cast<int>(end), eigvalfile);
     if (WriteXref == eWXR_YES)
     {
         fprintf(out, "Wrote reference structure to %s\n", eigvecfile);