Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_make_edi.cpp
similarity index 97%
rename from src/gromacs/gmxana/gmx_make_edi.c
rename to src/gromacs/gmxana/gmx_make_edi.cpp
index e33ddc7eead7e42dd8bd4a22a1b5e97462e1ddc5..da86456f4be663c06d69091c1246a7acb65c88bf 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <ctype.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/eigio.h"
+#include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/readinp.h"
 #include "gromacs/legacyheaders/txtdump.h"
@@ -137,7 +138,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
     int   i, istep;
     char  c;
     char *pos, *startpos, *step;
-    int   n = strlen(str);
+    int   n = std::strlen(str);
 
     /*enums to define the different lexical stati */
     enum {
@@ -156,7 +157,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
     step = NULL;
     snew(pos, n+4);
     startpos = pos;
-    strcpy(pos, str);
+    std::strcpy(pos, str);
     pos[n]   = ',';
     pos[n+1] = '1';
     pos[n+2] = '\0';
@@ -168,7 +169,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
         switch (status)
         {
             /* expect a number */
-            case sBefore: if (isdigit(c))
+            case sBefore: if (std::isdigit(c))
                 {
                     start  = pos;
                     status = sNumber;
@@ -184,7 +185,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
                 {
                     /*store number*/
                     srenew(*list, nvecs+1);
-                    (*list)[nvecs++] = number = strtol(start, NULL, 10);
+                    (*list)[nvecs++] = number = std::strtol(start, NULL, 10);
                     status           = sBefore;
                     if (number == 0)
                     {
@@ -196,7 +197,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
                 {
                     status = sMinus; break;
                 }
-                else if (isdigit(c))
+                else if (std::isdigit(c))
                 {
                     break;
                 }
@@ -207,7 +208,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
 
             /* have read a '-' -> expect a number */
             case sMinus:
-                if (isdigit(c))
+                if (std::isdigit(c))
                 {
                     end    = pos;
                     status = sRange; break;
@@ -218,7 +219,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
                 } break;
 
             case sSteppedRange:
-                if (isdigit(c))
+                if (std::isdigit(c))
                 {
                     if (step)
                     {
@@ -241,8 +242,8 @@ int sscan_list(int *list[], const char *str, const char *listname)
                 if (c == ',')
                 {
                     /*store numbers*/
-                    end_number = strtol(end, NULL, 10);
-                    number     = strtol(start, NULL, 10);
+                    end_number = std::strtol(end, NULL, 10);
+                    number     = std::strtol(start, NULL, 10);
                     status     = sBefore;
                     if (number == 0)
                     {
@@ -273,7 +274,7 @@ int sscan_list(int *list[], const char *str, const char *listname)
                     status = sSteppedRange;
                     break;
                 }
-                else if (isdigit(c))
+                else if (std::isdigit(c))
                 {
                     break;
                 }
@@ -313,7 +314,6 @@ void write_eigvec(FILE* fp, int natoms, int eig_list[], rvec** eigvecs, int nvec
  */
 
     int  n = 0, i; rvec x;
-    real sum;
     while (eig_list[n++])
     {
         ;                 /*count selected eigenvecs*/
@@ -338,7 +338,6 @@ void write_eigvec(FILE* fp, int natoms, int eig_list[], rvec** eigvecs, int nvec
     /* dump coordinates of the selected eigenvectors */
     while (eig_list[n])
     {
-        sum = 0;
         for (i = 0; i < natoms; i++)
         {
             if (eig_list[n] > nvec)
@@ -346,7 +345,6 @@ void write_eigvec(FILE* fp, int natoms, int eig_list[], rvec** eigvecs, int nvec
                 gmx_fatal(FARGS, "Selected eigenvector %d is higher than maximum number %d of available eigenvectors", eig_list[n], nvec);
             }
             copy_rvec(eigvecs[eig_list[n]-1][i], x);
-            sum += norm2(x);
             fprintf(fp, "%8.5f %8.5f %8.5f\n", x[XX], x[YY], x[ZZ]);
         }
         n++;
@@ -474,7 +472,7 @@ void read_eigenvalues(int vecs[], const char *eigfile, real values[],
 static real *scan_vecparams(const char *str, const char * par, int nvecs)
 {
     char    f0[256], f1[256];         /*format strings adapted every pass of the loop*/
-    double  d, tcap = 0;
+    double  d;
     int     i;
     real   *vec_params;
 
@@ -484,15 +482,14 @@ static real *scan_vecparams(const char *str, const char * par, int nvecs)
         f0[0] = '\0';
         for (i = 0; (i < nvecs); i++)
         {
-            strcpy(f1, f0);    /*f0 is the format string for the "to-be-ignored" numbers*/
-            strcat(f1, "%lf"); /*and f1 to read the actual number in this pass of the loop*/
+            std::strcpy(f1, f0);    /*f0 is the format string for the "to-be-ignored" numbers*/
+            std::strcat(f1, "%lf"); /*and f1 to read the actual number in this pass of the loop*/
             if (sscanf(str, f1, &d) != 1)
             {
                 gmx_fatal(FARGS, "Not enough elements for %s parameter (I need %d)", par, nvecs);
             }
             vec_params[i] = d;
-            tcap         += d;
-            strcat(f0, "%*s");
+            std::strcat(f0, "%*s");
         }
     }
     return vec_params;
@@ -765,7 +762,7 @@ int gmx_make_edi(int argc, char *argv[])
     char        title[STRLEN];
     matrix      topbox;
     rvec       *xtop;
-    gmx_bool    bTop, bFit1;
+    gmx_bool    bFit1;
 
     t_filenm    fnm[] = {
         { efTRN, "-f",    "eigenvec",    ffREAD  },
@@ -862,8 +859,8 @@ int gmx_make_edi(int argc, char *argv[])
     read_eigenvectors(EigvecFile, &nav, &bFit1,
                       &xref1, &edi_params.fitmas, &xav1, &edi_params.pcamas, &nvec1, &eignr1, &eigvec1, &eigval1);
 
-    bTop = read_tps_conf(ftp2fn(efTPS, NFILE, fnm),
-                         title, &top, &ePBC, &xtop, NULL, topbox, 0);
+    read_tps_conf(ftp2fn(efTPS, NFILE, fnm),
+                  title, &top, &ePBC, &xtop, NULL, topbox, 0);
     atoms = &top.atoms;