Moved second half of gmxana tools to C++
authorErik Lindahl <erik@kth.se>
Sat, 11 Jul 2015 16:56:01 +0000 (18:56 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 28 Jul 2015 21:52:13 +0000 (23:52 +0200)
Code that the static analyzer found to be
unused or irrelevant have been removed.

Change-Id: I9acb45f953d6fd8fde04c9bed29272772f93ad58

40 files changed:
src/gromacs/gmxana/gmx_make_edi.cpp [moved from src/gromacs/gmxana/gmx_make_edi.c with 97% similarity]
src/gromacs/gmxana/gmx_make_ndx.cpp [moved from src/gromacs/gmxana/gmx_make_ndx.c with 95% similarity]
src/gromacs/gmxana/gmx_mdmat.cpp [moved from src/gromacs/gmxana/gmx_mdmat.c with 97% similarity]
src/gromacs/gmxana/gmx_mindist.cpp [moved from src/gromacs/gmxana/gmx_mindist.c with 95% similarity]
src/gromacs/gmxana/gmx_mk_angndx.cpp [moved from src/gromacs/gmxana/gmx_mk_angndx.c with 97% similarity]
src/gromacs/gmxana/gmx_morph.cpp [moved from src/gromacs/gmxana/gmx_morph.c with 100% similarity]
src/gromacs/gmxana/gmx_msd.cpp [moved from src/gromacs/gmxana/gmx_msd.c with 97% similarity]
src/gromacs/gmxana/gmx_nmeig.cpp [moved from src/gromacs/gmxana/gmx_nmeig.c with 96% similarity]
src/gromacs/gmxana/gmx_nmens.cpp [moved from src/gromacs/gmxana/gmx_nmens.c with 93% similarity]
src/gromacs/gmxana/gmx_nmtraj.cpp [moved from src/gromacs/gmxana/gmx_nmtraj.c with 90% similarity]
src/gromacs/gmxana/gmx_order.cpp [moved from src/gromacs/gmxana/gmx_order.c with 95% similarity]
src/gromacs/gmxana/gmx_polystat.cpp [moved from src/gromacs/gmxana/gmx_polystat.c with 95% similarity]
src/gromacs/gmxana/gmx_potential.cpp [moved from src/gromacs/gmxana/gmx_potential.c with 95% similarity]
src/gromacs/gmxana/gmx_principal.cpp [moved from src/gromacs/gmxana/gmx_principal.c with 98% similarity]
src/gromacs/gmxana/gmx_rama.cpp [moved from src/gromacs/gmxana/gmx_rama.c with 99% similarity]
src/gromacs/gmxana/gmx_rms.cpp [moved from src/gromacs/gmxana/gmx_rms.c with 97% similarity]
src/gromacs/gmxana/gmx_rmsdist.cpp [moved from src/gromacs/gmxana/gmx_rmsdist.c with 93% similarity]
src/gromacs/gmxana/gmx_rmsf.cpp [moved from src/gromacs/gmxana/gmx_rmsf.c with 94% similarity]
src/gromacs/gmxana/gmx_rotacf.cpp [moved from src/gromacs/gmxana/gmx_rotacf.c with 98% similarity]
src/gromacs/gmxana/gmx_rotmat.cpp [moved from src/gromacs/gmxana/gmx_rotmat.c with 97% similarity]
src/gromacs/gmxana/gmx_saltbr.cpp [moved from src/gromacs/gmxana/gmx_saltbr.c with 96% similarity]
src/gromacs/gmxana/gmx_sans.cpp [moved from src/gromacs/gmxana/gmx_sans.c with 97% similarity]
src/gromacs/gmxana/gmx_saxs.cpp [moved from src/gromacs/gmxana/gmx_saxs.c with 97% similarity]
src/gromacs/gmxana/gmx_sham.cpp [moved from src/gromacs/gmxana/gmx_sham.c with 94% similarity]
src/gromacs/gmxana/gmx_sigeps.cpp [moved from src/gromacs/gmxana/gmx_sigeps.c with 87% similarity]
src/gromacs/gmxana/gmx_sorient.cpp [moved from src/gromacs/gmxana/gmx_sorient.c with 95% similarity]
src/gromacs/gmxana/gmx_spatial.cpp [moved from src/gromacs/gmxana/gmx_spatial.c with 87% similarity]
src/gromacs/gmxana/gmx_spol.cpp [moved from src/gromacs/gmxana/gmx_spol.c with 96% similarity]
src/gromacs/gmxana/gmx_tcaf.cpp [moved from src/gromacs/gmxana/gmx_tcaf.c with 96% similarity]
src/gromacs/gmxana/gmx_traj.cpp [moved from src/gromacs/gmxana/gmx_traj.c with 98% similarity]
src/gromacs/gmxana/gmx_trjcat.cpp [moved from src/gromacs/gmxana/gmx_trjcat.c with 97% similarity]
src/gromacs/gmxana/gmx_trjconv.cpp [moved from src/gromacs/gmxana/gmx_trjconv.c with 95% similarity]
src/gromacs/gmxana/gmx_trjorder.cpp [moved from src/gromacs/gmxana/gmx_trjorder.c with 98% similarity]
src/gromacs/gmxana/gmx_tune_pme.cpp [moved from src/gromacs/gmxana/gmx_tune_pme.c with 95% similarity]
src/gromacs/gmxana/gmx_vanhove.cpp [moved from src/gromacs/gmxana/gmx_vanhove.c with 93% similarity]
src/gromacs/gmxana/gmx_velacc.cpp [moved from src/gromacs/gmxana/gmx_velacc.c with 99% similarity]
src/gromacs/gmxana/gmx_wheel.cpp [moved from src/gromacs/gmxana/gmx_wheel.c with 93% similarity]
src/gromacs/gmxana/gmx_xpm2ps.cpp [moved from src/gromacs/gmxana/gmx_xpm2ps.c with 94% similarity]
src/gromacs/utility/stringutil.cpp
src/gromacs/utility/stringutil.h

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;
 
 
similarity index 95%
rename from src/gromacs/gmxana/gmx_make_ndx.c
rename to src/gromacs/gmxana/gmx_make_ndx.cpp
index 55dc3ab47b4027dda9599d1634b2d3994fb9d124..4bd93584a5fe6de862d502c299639301e7c90a00 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  */
 #include "gmxpre.h"
 
-#include <ctype.h>
-#include <string.h>
+#include <cctype>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
+#include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/vec.h"
@@ -149,7 +152,7 @@ static gmx_bool is_name_char(char c)
      */
     const char *spec = " !&|";
 
-    return (c != '\0' && strchr(spec, c) == NULL);
+    return (c != '\0' && std::strchr(spec, c) == NULL);
 }
 
 static int parse_names(char **string, int *n_names, char **names)
@@ -209,22 +212,22 @@ static gmx_bool parse_int_char(char **string, int *nr, char *c)
 
     *c = ' ';
 
-    if (isdigit((*string)[0]))
+    if (std::isdigit((*string)[0]))
     {
         *nr = (*string)[0]-'0';
         (*string)++;
-        while (isdigit((*string)[0]))
+        while (std::isdigit((*string)[0]))
         {
             *nr = (*nr)*10+(*string)[0]-'0';
             (*string)++;
         }
-        if (isalpha((*string)[0]))
+        if (std::isalpha((*string)[0]))
         {
             *c = (*string)[0];
             (*string)++;
         }
         /* Check if there is at most one non-digit character */
-        if (!isalnum((*string)[0]))
+        if (!std::isalnum((*string)[0]))
         {
             bRet = TRUE;
         }
@@ -278,7 +281,7 @@ static gmx_bool parse_string(char **string, int *nr, int ngrps, char **grpname)
         c = (*string)[0];
         (*string)++;
         s  = gmx_strdup((*string));
-        sp = strchr(s, c);
+        sp = std::strchr(s, c);
         if (sp != NULL)
         {
             (*string) += sp-s + 1;
@@ -325,7 +328,7 @@ static int select_atomnumbers(char **string, t_atoms *atoms, atom_id n1,
             {
                 sprintf(buf, "a_%d-%d", n1, up);
             }
-            strcpy(gname, buf);
+            std::strcpy(gname, buf);
         }
     }
     else
@@ -339,7 +342,7 @@ static int select_atomnumbers(char **string, t_atoms *atoms, atom_id n1,
                 index[*nr] = i-1;
                 (*nr)++;
                 sprintf(buf, "_%d", i);
-                strcat(gname, buf);
+                std::strcat(gname, buf);
             }
             else
             {
@@ -399,7 +402,7 @@ static int select_residuenumbers(char **string, t_atoms *atoms,
         {
             sprintf(buf, "r_%d-%d", n1, up);
         }
-        strcpy(gname, buf);
+        std::strcpy(gname, buf);
     }
     else
     {
@@ -418,7 +421,7 @@ static int select_residuenumbers(char **string, t_atoms *atoms,
                 }
             }
             sprintf(buf, "_%d", j);
-            strcat(gname, buf);
+            std::strcat(gname, buf);
         }
         while (parse_int_char(string, &j, &c));
     }
@@ -474,7 +477,7 @@ static int select_residueindices(char **string, t_atoms *atoms,
         {
             sprintf(buf, "r_%d-%d", n1, up);
         }
-        strcpy(gname, buf);
+        std::strcpy(gname, buf);
     }
     else
     {
@@ -493,7 +496,7 @@ static int select_residueindices(char **string, t_atoms *atoms,
                 }
             }
             sprintf(buf, "_%d", j);
-            strcat(gname, buf);
+            std::strcat(gname, buf);
         }
         while (parse_int_char(string, &j, &c));
     }
@@ -559,7 +562,7 @@ static gmx_bool comp_name(char *name, char *search)
                 break;
             default:
                 /* Compare a single character */
-                if (( bCase && strncmp(name, search, 1)) ||
+                if (( bCase && std::strncmp(name, search, 1)) ||
                     (!bCase && gmx_strncasecmp(name, search, 1)))
                 {
                     return FALSE;
@@ -698,11 +701,11 @@ static void make_gname(int n, char **names, char *gname)
 {
     int i;
 
-    strcpy(gname, names[0]);
+    std::strcpy(gname, names[0]);
     for (i = 1; i < n; i++)
     {
-        strcat(gname, "_");
-        strcat(gname, names[i]);
+        std::strcat(gname, "_");
+        std::strcat(gname, names[i]);
     }
 }
 
@@ -817,7 +820,7 @@ static int split_chain(t_atoms *atoms, rvec *x,
 
     while (ca_start < natoms)
     {
-        while ((ca_start < natoms) && strcmp(*atoms->atomname[ca_start], "CA"))
+        while ((ca_start < natoms) && std::strcmp(*atoms->atomname[ca_start], "CA"))
         {
             ca_start++;
         }
@@ -841,7 +844,7 @@ static int split_chain(t_atoms *atoms, rvec *x,
                 {
                     i++;
                 }
-                while ((i < natoms) && strcmp(*atoms->atomname[i], "CA"));
+                while ((i < natoms) && std::strcmp(*atoms->atomname[i], "CA"));
                 if (i < natoms)
                 {
                     rvec_sub(x[ca_end], x[i], vec);
@@ -973,7 +976,7 @@ static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
         if ((sel_nr1 >= 0) && (sel_nr1 < block->nr))
         {
             copy_group(sel_nr1, block, nr, index);
-            strcpy(gname, (*gn)[sel_nr1]);
+            std::strcpy(gname, (*gn)[sel_nr1]);
             printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]);
             bRet = TRUE;
         }
@@ -1015,7 +1018,7 @@ static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
             }
         }
     }
-    else if (strncmp(*string, "res", 3) == 0)
+    else if (std::strncmp(*string, "res", 3) == 0)
     {
         (*string) += 3;
         if (check_have_atoms(atoms, ostring) &&
@@ -1027,7 +1030,7 @@ static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
             sprintf(gname, "atom_%s", (*gn)[sel_nr1]);
         }
     }
-    else if (strncmp(*string, "ri", 2) == 0)
+    else if (std::strncmp(*string, "ri", 2) == 0)
     {
         (*string) += 2;
         if (check_have_atoms(atoms, ostring) &&
@@ -1052,7 +1055,7 @@ static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
             }
         }
     }
-    else if (strncmp(*string, "chain", 5) == 0)
+    else if (std::strncmp(*string, "chain", 5) == 0)
     {
         (*string) += 5;
         if (check_have_atoms(atoms, ostring) &&
@@ -1062,7 +1065,7 @@ static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
             sprintf(gname, "ch%s", names[0]);
             for (i = 1; i < n_names; i++)
             {
-                strcat(gname, names[i]);
+                std::strcat(gname, names[i]);
             }
         }
     }
@@ -1095,7 +1098,7 @@ static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
         }
         sfree(index1);
 
-        for (i = strlen(gname)+1; i > 0; i--)
+        for (i = std::strlen(gname)+1; i > 0; i--)
         {
             gname[i] = gname[i-1];
         }
@@ -1119,8 +1122,8 @@ static void list_residues(t_atoms *atoms)
         resind = atoms->atom[i].resind;
         if ((resind != prev_resind) || (i == atoms->nr-1))
         {
-            if ((bDiff = strcmp(*atoms->resinfo[resind].name,
-                                *atoms->resinfo[start].name)) ||
+            if ((bDiff = std::strcmp(*atoms->resinfo[resind].name,
+                                     *atoms->resinfo[start].name)) ||
                 (i == atoms->nr-1))
             {
                 if (bDiff)
@@ -1221,7 +1224,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
         {
             gmx_fatal(FARGS, "Error reading user input");
         }
-        inp_string[strlen(inp_string)-1] = 0;
+        inp_string[std::strlen(inp_string)-1] = 0;
         printf("\n");
         string = inp_string;
         while (string[0] == ' ')
@@ -1279,7 +1282,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 getchar();
             }
         }
-        else if (strncmp(string, "del", 3) == 0)
+        else if (std::strncmp(string, "del", 3) == 0)
         {
             string += 3;
             if (parse_int(&string, &sel_nr))
@@ -1311,7 +1314,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 }
             }
         }
-        else if (strncmp(string, "keep", 4) == 0)
+        else if (std::strncmp(string, "keep", 4) == 0)
         {
             string += 4;
             if (parse_int(&string, &sel_nr))
@@ -1320,7 +1323,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 remove_group(0, sel_nr-1, block, gn);
             }
         }
-        else if (strncmp(string, "name", 4) == 0)
+        else if (std::strncmp(string, "name", 4) == 0)
         {
             string += 4;
             if (parse_int(&string, &sel_nr))
@@ -1333,7 +1336,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 }
             }
         }
-        else if (strncmp(string, "case", 4) == 0)
+        else if (std::strncmp(string, "case", 4) == 0)
         {
             bCase = !bCase;
             printf("Switched to case %s\n", bCase ? "sensitive" : "insensitive");
@@ -1350,7 +1353,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 list_residues(atoms);
             }
         }
-        else if (strncmp(string, "splitch", 7) == 0)
+        else if (std::strncmp(string, "splitch", 7) == 0)
         {
             string += 7;
             if (check_have_atoms(atoms, ostring) &&
@@ -1360,7 +1363,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 split_chain(atoms, x, sel_nr, block, gn);
             }
         }
-        else if (strncmp(string, "splitres", 8) == 0)
+        else if (std::strncmp(string, "splitres", 8) == 0)
         {
             string += 8;
             if (check_have_atoms(atoms, ostring) &&
@@ -1370,7 +1373,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 split_group(atoms, sel_nr, block, gn, FALSE);
             }
         }
-        else if (strncmp(string, "splitat", 7) == 0)
+        else if (std::strncmp(string, "splitat", 7) == 0)
         {
             string += 7;
             if (check_have_atoms(atoms, ostring) &&
@@ -1386,7 +1389,6 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
         }
         else if (string[0] != 'q')
         {
-            nr1 = -1;
             nr2 = -1;
             if (parse_entry(&string, natoms, atoms, block, gn, &nr, index, gname))
             {
@@ -1416,7 +1418,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                         {
                             index1[i] = index[i];
                         }
-                        strcpy(gname1, gname);
+                        std::strcpy(gname1, gname);
                         if (parse_entry(&string, natoms, atoms, block, gn, &nr2, index2, gname2))
                         {
                             if (bOr)
@@ -1469,7 +1471,7 @@ static int block2natoms(t_blocka *block)
     natoms = 0;
     for (i = 0; i < block->nra; i++)
     {
-        natoms = max(natoms, block->a[i]);
+        natoms = std::max(natoms, block->a[i]);
     }
     natoms++;
 
similarity index 97%
rename from src/gromacs/gmxana/gmx_mdmat.c
rename to src/gromacs/gmxana/gmx_mdmat.cpp
index 8d2ac08527ab1a3d5367d54d667db66d3cfcfd83..d832088c9051cdf4e91e6190ef092b8eaf112958 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -134,7 +136,7 @@ static void calc_mat(int nres, int natoms, int rndx[],
                 nmat[resi][j]++;
                 nmat[resj][i]++;
             }
-            mdmat[resi][resj] = min(r2, mdmat[resi][resj]);
+            mdmat[resi][resj] = std::min(r2, mdmat[resi][resj]);
         }
     }
 
@@ -143,7 +145,7 @@ static void calc_mat(int nres, int natoms, int rndx[],
         mdmat[resi][resi] = 0;
         for (resj = resi+1; (resj < nres); resj++)
         {
-            r                 = sqrt(mdmat[resi][resj]);
+            r                 = std::sqrt(mdmat[resi][resj]);
             mdmat[resi][resj] = r;
             mdmat[resj][resi] = r;
         }
@@ -183,7 +185,6 @@ int gmx_mdmat(int argc, char *argv[])
         "The output can be processed with [gmx-xpm2ps] to make a PostScript (tm) plot."
     };
     static real     truncate = 1.5;
-    static gmx_bool bAtom    = FALSE;
     static int      nlevels  = 40;
     t_pargs         pa[]     = {
         { "-t",   FALSE, etREAL, {&truncate},
@@ -210,9 +211,8 @@ int gmx_mdmat(int argc, char *argv[])
     char          *grpname;
     int           *rndx, *natm, prevres, newres;
 
-    int            i, j, nres, natoms, nframes, it, trxnat;
+    int            i, j, nres, natoms, nframes, trxnat;
     t_trxstatus   *status;
-    int            nr0;
     gmx_bool       bCalcN, bFrames;
     real           t, ratio;
     char           title[256], label[234];
similarity index 95%
rename from src/gromacs/gmxana/gmx_mindist.c
rename to src/gromacs/gmxana/gmx_mindist.cpp
index 214ba9ef4099c7dfc095bb48d21773c5dadc37f6..44f5d36af840cee470734d9551051289ca65c27f 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -55,6 +57,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 
@@ -67,10 +70,10 @@ static void periodic_dist(int ePBC,
     real sqr_box, r2min, r2max, r2;
     rvec shift[NSHIFT_MAX], d0, d;
 
-    sqr_box = min(norm2(box[XX]), norm2(box[YY]));
+    sqr_box = std::min(norm2(box[XX]), norm2(box[YY]));
     if (ePBC == epbcXYZ)
     {
-        sqr_box = min(sqr_box, norm2(box[ZZ]));
+        sqr_box = std::min(sqr_box, norm2(box[ZZ]));
         nsz     = 1;
     }
     else if (ePBC == epbcXY)
@@ -131,8 +134,8 @@ static void periodic_dist(int ePBC,
         }
     }
 
-    *rmin = sqrt(r2min);
-    *rmax = sqrt(r2max);
+    *rmin = std::sqrt(r2min);
+    *rmax = std::sqrt(r2max);
 }
 
 static void periodic_mindist_plot(const char *trxfn, const char *outfn,
@@ -147,7 +150,7 @@ static void periodic_mindist_plot(const char *trxfn, const char *outfn,
     rvec        *x;
     matrix       box;
     int          natoms, ind_min[2] = {0, 0}, ind_mini = 0, ind_minj = 0;
-    real         r, rmin, rmax, rmint, tmint;
+    real         rmin, rmax, rmint, tmint;
     gmx_bool     bFirst;
     gmx_rmpbc_t  gpbc = NULL;
 
@@ -187,7 +190,7 @@ static void periodic_mindist_plot(const char *trxfn, const char *outfn,
             ind_mini = ind_min[0];
             ind_minj = ind_min[1];
         }
-        if (bSplit && !bFirst && fabs(t/output_env_get_time_factor(oenv)) < 1e-5)
+        if (bSplit && !bFirst && std::abs(t/output_env_get_time_factor(oenv)) < 1e-5)
         {
             fprintf(out, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
         }
@@ -316,8 +319,8 @@ static void calc_dist(real rcut, gmx_bool bPBC, int ePBC, matrix box, rvec x[],
             *nmax += nmax_j;
         }
     }
-    *rmin = sqrt(rmin2);
-    *rmax = sqrt(rmax2);
+    *rmin = std::sqrt(rmin2);
+    *rmax = std::sqrt(rmax2);
 }
 
 void dist_plot(const char *fn, const char *afile, const char *dfile,
@@ -335,16 +338,17 @@ void dist_plot(const char *fn, const char *afile, const char *dfile,
     real             t, dmin, dmax, **mindres = NULL, **maxdres = NULL;
     int              nmin, nmax;
     t_trxstatus     *status;
-    int              i = -1, j, k, natoms;
-    int              min1, min2, max1, max2, min1r, min2r, max1r, max2r;
+    int              i = -1, j, k;
+    int              min2, max2, min1r, min2r, max1r, max2r;
+    int              min1 = 0;
+    int              max1 = 0;
     atom_id          oindex[2];
     rvec            *x0;
     matrix           box;
-    t_trxframe       frout;
     gmx_bool         bFirst;
     FILE            *respertime = NULL;
 
-    if ((natoms = read_first_x(oenv, &status, fn, &t, &x0, box)) == 0)
+    if (read_first_x(oenv, &status, fn, &t, &x0, box) == 0)
     {
         gmx_fatal(FARGS, "Could not read coordinates from statusfile\n");
     }
@@ -419,7 +423,6 @@ void dist_plot(const char *fn, const char *afile, const char *dfile,
 
     }
 
-    j = 0;
     if (nres)
     {
         snew(mindres, ng-1);
@@ -438,7 +441,7 @@ void dist_plot(const char *fn, const char *afile, const char *dfile,
     bFirst = TRUE;
     do
     {
-        if (bSplit && !bFirst && fabs(t/output_env_get_time_factor(oenv)) < 1e-5)
+        if (bSplit && !bFirst && std::abs(t/output_env_get_time_factor(oenv)) < 1e-5)
         {
             fprintf(dist, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
             if (num)
@@ -503,8 +506,8 @@ void dist_plot(const char *fn, const char *afile, const char *dfile,
                         calc_dist(rcut, bPBC, ePBC, box, x0, residue[j+1]-residue[j], gnx[i],
                                   &(index[0][residue[j]]), index[i], bGroup,
                                   &dmin, &dmax, &nmin, &nmax, &min1r, &min2r, &max1r, &max2r);
-                        mindres[i-1][j] = min(mindres[i-1][j], dmin);
-                        maxdres[i-1][j] = max(maxdres[i-1][j], dmax);
+                        mindres[i-1][j] = std::min(mindres[i-1][j], dmin);
+                        maxdres[i-1][j] = std::max(maxdres[i-1][j], dmax);
                     }
                 }
             }
@@ -658,9 +661,6 @@ int gmx_mindist(int argc, char *argv[])
         "of the three box vectors.[PAR]",
         "Also [gmx-distance] and [gmx-pairdist] calculate distances."
     };
-    const char     *bugs[] = {
-        "The [TT]-pi[tt] option is very slow."
-    };
 
     static gmx_bool bMat             = FALSE, bPI = FALSE, bSplit = FALSE, bMax = FALSE, bPBC = TRUE;
     static gmx_bool bGroup           = FALSE;
@@ -693,13 +693,11 @@ int gmx_mindist(int argc, char *argv[])
     t_topology     *top  = NULL;
     int             ePBC = -1;
     char            title[256];
-    real            t;
     rvec           *x;
     matrix          box;
     gmx_bool        bTop = FALSE;
 
-    FILE           *atm;
-    int             i, j, nres = 0;
+    int             i, nres = 0;
     const char     *trxfnm, *tpsfnm, *ndxfnm, *distfnm, *numfnm, *atmfnm, *oxfnm, *resfnm;
     char          **grpname;
     int            *gnx;
@@ -790,8 +788,9 @@ int gmx_mindist(int argc, char *argv[])
 
     if (resfnm)
     {
-        nres = find_residues(top ? &(top->atoms) : NULL,
-                             gnx[0], index[0], &residues);
+        GMX_RELEASE_ASSERT(top != NULL, "top pointer cannot be NULL when finding residues");
+        nres = find_residues(&(top->atoms), gnx[0], index[0], &residues);
+
         if (debug)
         {
             dump_res(debug, nres, residues, index[0]);
similarity index 97%
rename from src/gromacs/gmxana/gmx_mk_angndx.c
rename to src/gromacs/gmxana/gmx_mk_angndx.cpp
index 048d7452fa013cf7a8737b9c4a8fde44ae882c4f..b435bcb3b0ac99d22960b313f6f6767625be1c28 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/trxio.h"
+#include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #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 int calc_ntype(int nft, int *ft, t_idef *idef)
@@ -178,7 +180,7 @@ static void fill_ang(int nft, int *ft, int fac,
             {
                 for (j = 0; j < fac; j++)
                 {
-                    if (atom[ia[1+j]].m < 1.5 && fabs(atom[ia[1+j]].q) < hq)
+                    if (atom[ia[1+j]].m < 1.5 && std::abs(atom[ia[1+j]].q) < hq)
                     {
                         bUse = FALSE;
                     }
@@ -285,6 +287,7 @@ int gmx_mk_angndx(int argc, char *argv[])
         return 0;
     }
 
+    GMX_RELEASE_ASSERT(opt[0] != 0, "Options inconsistency; opt[0] is NULL");
 
     ft = select_ftype(opt[0], &nft, &mult);
 
similarity index 97%
rename from src/gromacs/gmxana/gmx_msd.c
rename to src/gromacs/gmxana/gmx_msd.cpp
index 3a6361d8969d93c6a82784dfbd9462c91f6cda5d..90fe9725e2a78659d7fc99b5274633e1234d3e40 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"
@@ -55,6 +55,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #define FACTOR  1000.0  /* Convert nm^2/ps to 10e-5 cm^2/s */
@@ -229,7 +230,7 @@ static void calc_corr(t_corr *curr, int nr, int nx, atom_id index[], rvec xc[],
     {
         if ((thistime(curr) >= (curr->nlast*curr->delta_t)) && (nr == 0))
         {
-            memcpy(curr->x0[curr->nlast], xc, curr->ncoords*sizeof(xc[0]));
+            std::memcpy(curr->x0[curr->nlast], xc, curr->ncoords*sizeof(xc[0]));
             curr->n_offs[curr->nlast] = curr->nframes;
             copy_rvec(com, curr->com[curr->nlast]);
             curr->nlast++;
@@ -490,7 +491,6 @@ static void calc_com(gmx_bool bMol, int gnx, atom_id index[],
 
     clear_dvec(sx);
     tmass = 0;
-    mass  = 1;
 
     prep_data(bMol, gnx, index, xcur, xprev, box);
     for (i = 0; (i < gnx); i++)
@@ -595,7 +595,7 @@ void printmol(t_corr *curr, const char *fn,
         fprintf(out, "%10d  %10g\n", i, D);
         if (pdbinfo)
         {
-            sqrtD = sqrt(D);
+            sqrtD = std::sqrt(D);
             if (sqrtD > sqrtD_max)
             {
                 sqrtD_max = sqrtD;
@@ -614,7 +614,7 @@ void printmol(t_corr *curr, const char *fn,
     D2av /= curr->nmol;
     VarD  = D2av - sqr(Dav);
     printf("<D> = %.4f Std. Dev. = %.4f Error = %.4f\n",
-           Dav, sqrt(VarD), sqrt(VarD/curr->nmol));
+           Dav, std::sqrt(VarD), std::sqrt(VarD/curr->nmol));
 
     if (fn_pdb && x)
     {
@@ -627,6 +627,7 @@ void printmol(t_corr *curr, const char *fn,
         {
             scale *= 10;
         }
+        GMX_RELEASE_ASSERT(pdbinfo != NULL, "Internal error - pdbinfo not set for PDB input");
         for (i = 0; i < top->atoms.nr; i++)
         {
             pdbinfo[i].bfac *= scale;
@@ -778,7 +779,7 @@ int corr_loop(t_corr *curr, const char *fn, t_topology *top, int ePBC,
         /* for the first frame, the previous frame is a copy of the first frame */
         if (bFirst)
         {
-            memcpy(xa[prev], xa[cur], curr->ncoords*sizeof(xa[prev][0]));
+            std::memcpy(xa[prev], xa[cur], curr->ncoords*sizeof(xa[prev][0]));
             bFirst = FALSE;
         }
 
@@ -953,7 +954,7 @@ void do_corr(const char *trx_file, const char *ndx_file, const char *msd_file,
 
     if (beginfit == -1)
     {
-        i0       = (int)(0.1*(msd->nframes - 1) + 0.5);
+        i0       = static_cast<int>(0.1*(msd->nframes - 1) + 0.5);
         beginfit = msd->time[i0];
     }
     else
@@ -966,7 +967,7 @@ void do_corr(const char *trx_file, const char *ndx_file, const char *msd_file,
 
     if (endfit == -1)
     {
-        i1     = (int)(0.9*(msd->nframes - 1) + 0.5) + 1;
+        i1     = static_cast<int>(0.9*(msd->nframes - 1) + 0.5) + 1;
         endfit = msd->time[i1-1];
     }
     else
@@ -995,7 +996,7 @@ void do_corr(const char *trx_file, const char *ndx_file, const char *msd_file,
             {
                 lsq_y_ax_b(N/2, &(msd->time[i0]), &(msd->data[j][i0]), &a, &b, &r, &chi2);
                 lsq_y_ax_b(N/2, &(msd->time[i0+N/2]), &(msd->data[j][i0+N/2]), &a2, &b, &r, &chi2);
-                SigmaD[j] = fabs(a-a2);
+                SigmaD[j] = std::abs(a-a2);
             }
             else
             {
@@ -1160,6 +1161,9 @@ int gmx_msd(int argc, char *argv[])
         fprintf(stderr, "Calculating diffusion coefficients for molecules.\n");
     }
 
+    GMX_RELEASE_ASSERT(normtype[0] != 0, "Options inconsistency; normtype[0] is NULL");
+    GMX_RELEASE_ASSERT(axtitle[0] != 0, "Options inconsistency; axtitle[0] is NULL");
+
     if (normtype[0][0] != 'n')
     {
         type       = normtype[0][0] - 'x' + X; /* See defines above */
similarity index 96%
rename from src/gromacs/gmxana/gmx_nmeig.c
rename to src/gromacs/gmxana/gmx_nmeig.cpp
index 4560444e68827885052559546f1ce325b3c30aa9..fbfb008c863fd7222b8538bbf9dcde3e7dd0a49d 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/mtxio.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 static double cv_corr(double nu, double T)
 {
     double x  = PLANCK*nu/(BOLTZ*T);
-    double ex = exp(x);
+    double ex = std::exp(x);
 
     if (nu <= 0)
     {
@@ -75,7 +76,7 @@ static double cv_corr(double nu, double T)
 static double u_corr(double nu, double T)
 {
     double x  = PLANCK*nu/(BOLTZ*T);
-    double ex = exp(x);
+    double ex = std::exp(x);
 
     if (nu <= 0)
     {
@@ -145,7 +146,7 @@ nma_full_hessian(real     *           hess,
                  real     *           eigenvectors)
 {
     int  i, j, k, l;
-    real mass_fac, rdum;
+    real mass_fac;
     int  natoms;
 
     natoms = top->atoms.nr;
@@ -217,6 +218,8 @@ nma_sparse_hessian(gmx_sparsematrix_t     *     sparse_hessian,
     /* Cannot check symmetry since we only store half matrix */
     /* divide elements hess[i][j] by sqrt(mas[i])*sqrt(mas[j]) when required */
 
+    GMX_RELEASE_ASSERT(sparse_hessian != NULL, "NULL matrix pointer provided to nma_sparse_hessian");
+
     if (bM)
     {
         for (iatom = 0; (iatom < natoms); iatom++)
@@ -312,20 +315,16 @@ int gmx_nmeig(int argc, char *argv[])
           "Width (sigma) of the gaussian peaks (1/cm) when generating a spectrum" }
     };
     FILE                  *out, *qc, *spec;
-    int                    status, trjout;
     t_topology             top;
     gmx_mtop_t             mtop;
-    int                    ePBC;
     rvec                  *top_x;
     matrix                 box;
     real                  *eigenvalues;
     real                  *eigenvectors;
-    real                   rdum, mass_fac, qcvtot, qutot, qcv, qu;
-    int                    natoms, ndim, nrow, ncol, count, nharm, nvsite;
-    char                  *grpname;
-    int                    i, j, k, l, d, gnx;
+    real                   qcvtot, qutot, qcv, qu;
+    int                    natoms, ndim, nrow, ncol, nharm, nvsite;
+    int                    i, j, k;
     gmx_bool               bSuck;
-    atom_id               *index;
     t_tpxheader            tpx;
     int                    version, generation;
     real                   value, omega, nu;
@@ -455,7 +454,7 @@ int gmx_nmeig(int argc, char *argv[])
     bSuck = FALSE;
     for (i = begin-1; (i < 6); i++)
     {
-        if (fabs(eigenvalues[i]) > 1.0e-3)
+        if (std::abs(eigenvalues[i]) > 1.0e-3)
         {
             bSuck = TRUE;
         }
@@ -551,16 +550,16 @@ int gmx_nmeig(int argc, char *argv[])
         {
             value = 0;
         }
-        omega = sqrt(value*factor_gmx_to_omega2);
+        omega = std::sqrt(value*factor_gmx_to_omega2);
         nu    = 1e-12*omega/(2*M_PI);
         value = omega*factor_omega_to_wavenumber;
         fprintf (out, "%6d %15g\n", i, value);
         if (NULL != spec)
         {
-            wfac = eigenvalues[i-begin]/(width*sqrt(2*M_PI));
+            wfac = eigenvalues[i-begin]/(width*std::sqrt(2*M_PI));
             for (j = 0; (j < maxspec); j++)
             {
-                spectrum[j] += wfac*exp(-sqr(j-value)/(2*sqr(width)));
+                spectrum[j] += wfac*std::exp(-sqr(j-value)/(2*sqr(width)));
             }
         }
         if (NULL != qc)
similarity index 93%
rename from src/gromacs/gmxana/gmx_nmens.c
rename to src/gromacs/gmxana/gmx_nmens.cpp
index 4028f46b455d8e4995fb8c9a56c3cca099d8eeb3..b53f3b0d602d44ecfdc9765187efc2a90f563465 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"
@@ -86,7 +86,6 @@ int gmx_nmens(int argc, char *argv[])
 #define NPA asize(pa)
 
     t_trxstatus        *out;
-    int                 status, trjout;
     t_topology          top;
     int                 ePBC;
     t_atoms            *atoms;
@@ -95,18 +94,17 @@ int gmx_nmens(int argc, char *argv[])
     int                 nvec, *eignr = NULL;
     rvec              **eigvec = NULL;
     matrix              box;
-    real               *eigval, totmass, *invsqrtm, t, disp;
-    int                 natoms, neigval;
+    real               *eigval, *invsqrtm, t, disp;
+    int                 natoms;
     char               *grpname, title[STRLEN];
     const char         *indexfile;
     int                 i, j, d, s, v;
     int                 nout, *iout, noutvec, *outvec;
     atom_id            *index;
-    real                rfac, invfr, rhalf, jr;
-    int          *      eigvalnr;
+    real                rfac, rhalf, jr;
     output_env_t        oenv;
     gmx_rng_t           rng;
-    unsigned long       jran;
+    int                 jran;
     const unsigned long im = 0xffff;
     const unsigned long ia = 1093;
     const unsigned long ic = 18257;
@@ -215,7 +213,7 @@ int gmx_nmens(int argc, char *argv[])
 
     if (seed == -1)
     {
-        seed = (int)gmx_rng_make_seed();
+        seed = static_cast<int>(gmx_rng_make_seed());
         rng  = gmx_rng_init(seed);
     }
     else
@@ -227,7 +225,7 @@ int gmx_nmens(int argc, char *argv[])
     snew(xout1, natoms);
     snew(xout2, atoms->nr);
     out  = open_trx(ftp2fn(efTRO, NFILE, fnm), "w");
-    jran = (unsigned long)((real)im*gmx_rng_uniform_real(rng));
+    jran = static_cast<int>(im*gmx_rng_uniform_real(rng));
     gmx_rng_destroy(rng);
     for (s = 0; s < nstruct; s++)
     {
@@ -241,18 +239,18 @@ int gmx_nmens(int argc, char *argv[])
             /* (r-0.5) n times:  var_n = n * var_1 = n/12
                n=4:  var_n = 1/3, so multiply with 3 */
 
-            rfac  = sqrt(3.0 * BOLTZ*temp/eigval[iout[j]]);
+            rfac  = std::sqrt(3.0 * BOLTZ*temp/eigval[iout[j]]);
             rhalf = 2.0*rfac;
-            rfac  = rfac/(real)im;
+            rfac  = rfac/im;
 
             jran = (jran*ia+ic) & im;
-            jr   = (real)jran;
+            jr   = jran;
             jran = (jran*ia+ic) & im;
-            jr  += (real)jran;
+            jr  += jran;
             jran = (jran*ia+ic) & im;
-            jr  += (real)jran;
+            jr  += jran;
             jran = (jran*ia+ic) & im;
-            jr  += (real)jran;
+            jr  += jran;
             disp = rfac * jr - rhalf;
 
             for (i = 0; i < natoms; i++)
similarity index 90%
rename from src/gromacs/gmxana/gmx_nmtraj.c
rename to src/gromacs/gmxana/gmx_nmtraj.cpp
index 7e98f3de6d82b546f2774e30873d6caaf1f2ca62..f319773d8445ae416c17cfd35659152dbf7d9188 100644 (file)
  */
 #include "gmxpre.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"
@@ -55,7 +56,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
-
+#include "gromacs/utility/stringutil.h"
 
 int gmx_nmtraj(int argc, char *argv[])
 {
@@ -100,31 +101,24 @@ int gmx_nmtraj(int argc, char *argv[])
     t_atoms          *atoms;
     rvec             *xtop, *xref, *xav, *xout;
     int               nvec, *eignr = NULL;
-    int              *eigvalnr;
     rvec            **eigvec = NULL;
     matrix            box;
     int               natoms;
-    int               i, j, k, kmode, d, s, v;
+    int               i, j, k, kmode, d;
     gmx_bool          bDMR, bDMA, bFit;
-    char        *     indexfile;
 
-    char        *     grpname;
     real        *     eigval;
-    int               neigval;
     int        *      dummy;
     real        *     invsqrtm;
     char              title[STRLEN];
     real              fraction;
     int              *out_eigidx;
-    real             *out_eigval;
     rvec        *     this_eigvec;
-    real              omega, Ekin, sum, m, vel;
-    gmx_bool          found;
+    real              omega, Ekin, m, vel;
     int               nmodes, nphases;
     int              *imodes;
     real             *amplitude;
     real             *phases;
-    real              dum;
     const char       *p;
     char             *pe;
     output_env_t      oenv;
@@ -152,33 +146,20 @@ int gmx_nmtraj(int argc, char *argv[])
     /* Find vectors and phases */
 
     /* first find number of args in string */
-    nmodes = 0;
-    p      = eignrvec;
-    while (*p != 0)
-    {
-        dum = strtod(p, &pe);
-        p   = pe;
-        nmodes++;
-    }
+    nmodes = gmx::countWords(eignrvec);
 
     snew(imodes, nmodes);
     p = eignrvec;
     for (i = 0; i < nmodes; i++)
     {
         /* C indices start on 0 */
-        imodes[i] = strtol(p, &pe, 10)-1;
+        imodes[i] = std::strtol(p, &pe, 10)-1;
         p         = pe;
     }
 
     /* Now read phases */
-    nphases = 0;
-    p       = phasevec;
-    while (*p != 0)
-    {
-        dum = strtod(p, &pe);
-        p   = pe;
-        nphases++;
-    }
+    nphases = gmx::countWords(phasevec);
+
     if (nphases > nmodes)
     {
         gmx_fatal(FARGS, "More phases than eigenvector indices specified.\n");
@@ -274,7 +255,7 @@ int gmx_nmtraj(int argc, char *argv[])
             /* Derive amplitude from temperature and eigenvalue if we can */
 
             /* Convert eigenvalue to angular frequency, in units s^(-1) */
-            omega = sqrt(eigval[kmode]*1.0E21/(AVOGADRO*AMU));
+            omega = std::sqrt(eigval[kmode]*1.0E21/(AVOGADRO*AMU));
             /* Harmonic motion will be x=x0 + A*sin(omega*t)*eigenvec.
              * The velocity is thus:
              *
@@ -307,7 +288,7 @@ int gmx_nmtraj(int argc, char *argv[])
             Ekin *= AMU*1E-18;
 
             /* Set the amplitude so the energy is kT/2 */
-            amplitude[i] = sqrt(0.5*BOLTZMANN*temp/Ekin);
+            amplitude[i] = std::sqrt(0.5*BOLTZMANN*temp/Ekin);
         }
         else
         {
@@ -323,7 +304,7 @@ int gmx_nmtraj(int argc, char *argv[])
 
     for (i = 0; i < nframes; i++)
     {
-        fraction = (real)i/(real)nframes;
+        fraction = static_cast<real>(i)/nframes;
         for (j = 0; j < natoms; j++)
         {
             copy_rvec(xav[j], xout[j]);
@@ -338,11 +319,11 @@ int gmx_nmtraj(int argc, char *argv[])
             {
                 for (d = 0; d < DIM; d++)
                 {
-                    xout[j][d] += amplitude[k]*sin(2*M_PI*(fraction+phases[k]/360.0))*this_eigvec[j][d];
+                    xout[j][d] += amplitude[k]*std::sin(2*M_PI*(fraction+phases[k]/360.0))*this_eigvec[j][d];
                 }
             }
         }
-        write_trx(out, natoms, dummy, atoms, i, (real)i/(real)nframes, box, xout, NULL, NULL);
+        write_trx(out, natoms, dummy, atoms, i, static_cast<real>(i)/nframes, box, xout, NULL, NULL);
     }
 
     fprintf(stderr, "\n");
similarity index 95%
rename from src/gromacs/gmxana/gmx_order.c
rename to src/gromacs/gmxana/gmx_order.cpp
index c0dded8283de35e32d686594ece504779146a3eb..0b28c3bbd3d644c907a7b12cc490767b0a06776b 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.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"
 
 /****************************************************************************/
@@ -77,17 +80,13 @@ static void find_nearest_neighbours(int ePBC,
                                     real sgslice[], real skslice[],
                                     gmx_rmpbc_t gpbc)
 {
-    FILE    *fpoutdist;
-    char     fnsgdist[32];
     int      ix, jx, nsgbin, *sgbin;
-    int      i1, i2, i, ibin, j, k, l, n, *nn[4];
-    rvec     dx, dx1, dx2, rj, rk, urk, urj;
+    int      i, ibin, j, k, l, n, *nn[4];
+    rvec     dx, rj, rk, urk, urj;
     real     cost, cost2, *sgmol, *skmol, rmean, rmean2, r2, box2, *r_nn[4];
     t_pbc    pbc;
-    t_mat   *dmat;
-    t_dist  *d;
-    int      m1, mm, sl_index;
-    int    **nnb, *sl_count;
+    int      sl_index;
+    int     *sl_count;
     real     onethird = 1.0/3.0;
     /*  dmat = init_mat(maxidx, FALSE); */
     box2 = box[XX][XX] * box[XX][XX];
@@ -111,7 +110,7 @@ static void find_nearest_neighbours(int ePBC,
 
     gmx_rmpbc(gpbc, natoms, box, x);
 
-    nsgbin = 1 + 1/0.0005;
+    nsgbin = 2001; // Calculated as (1 + 1/0.0005)
     snew(sgbin, nsgbin);
 
     *sgmean = 0.0;
@@ -164,7 +163,7 @@ static void find_nearest_neighbours(int ePBC,
         rmean = 0;
         for (j = 0; (j < 4); j++)
         {
-            r_nn[j][i] = sqrt(r_nn[j][i]);
+            r_nn[j][i] = std::sqrt(r_nn[j][i]);
             rmean     += r_nn[j][i];
         }
         rmean /= 4;
@@ -192,7 +191,7 @@ static void find_nearest_neighbours(int ePBC,
                 sgmol[i] += cost2;
 
                 /* determine distribution */
-                ibin = nsgbin * cost2;
+                ibin = static_cast<int>(nsgbin * cost2);
                 if (ibin < nsgbin)
                 {
                     sgbin[ibin]++;
@@ -259,7 +258,7 @@ static void calc_tetra_order_parm(const char *fnNDX, const char *fnTPS,
     FILE        *fpsg = NULL, *fpsk = NULL;
     t_topology   top;
     int          ePBC;
-    char         title[STRLEN], fn[STRLEN], subtitle[STRLEN];
+    char         title[STRLEN];
     t_trxstatus *status;
     int          natoms;
     real         t;
@@ -396,12 +395,11 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
     int natoms,                                  /* nr. atoms in trj                               */
         nr_tails,                                /* nr tails, to check if index file is correct    */
         size = 0,                                /* nr. of atoms in group. same as nr_tails        */
-        i, j, m, k, l, teller = 0,
+        i, j, m, k, teller = 0,
         slice,                                   /* current slice number                           */
         nr_frames = 0;
     int         *slCount;                        /* nr. of atoms in one slice                      */
-    real         dbangle                = 0,     /* angle between double bond and  axis            */
-                 sdbangle               = 0;     /* sum of these angles                            */
+    real         sdbangle               = 0;     /* sum of these angles                            */
     gmx_bool     use_unitvector         = FALSE; /* use a specified unit vector instead of axis to specify unit normal*/
     rvec         direction, com, dref, dvec;
     int          comsize, distsize;
@@ -413,7 +411,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
 
     /* PBC added for center-of-mass vector*/
     /* Initiate the pbc structure */
-    memset(&pbc, 0, sizeof(pbc));
+    std::memset(&pbc, 0, sizeof(pbc));
 
     if ((natoms = read_first_x(oenv, &status, fn, &t, &x0, box)) == 0)
     {
@@ -567,7 +565,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                     rvec_sub(x1[a[index[i+1]+j]], x1[a[index[i]+j]], dist);
                     length = norm(dist);
                     check_length(length, a[index[i]+j], a[index[i+1]+j]);
-                    svmul(1/length, dist, Sz);
+                    svmul(1.0/length, dist, Sz);
 
                     /* this is actually the cosine of the angle between the double bond
                        and axis, because Sz is normalized and the two other components of
@@ -578,7 +576,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                     }
                     else
                     {
-                        sdbangle += acos(Sz[axis]);
+                        sdbangle += std::acos(Sz[axis]);
                     }
                 }
                 else
@@ -588,7 +586,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                     length = norm(dist); /* determine distance between two atoms */
                     check_length(length, a[index[i-1]+j], a[index[i+1]+j]);
 
-                    svmul(1/length, dist, Sz);
+                    svmul(1.0/length, dist, Sz);
                     /* Sz is now the molecular axis Sz, normalized and all that */
                 }
 
@@ -597,11 +595,11 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                 rvec_sub(x1[a[index[i+1]+j]], x1[a[index[i]+j]], tmp1);
                 rvec_sub(x1[a[index[i-1]+j]], x1[a[index[i]+j]], tmp2);
                 cprod(tmp1, tmp2, Sx);
-                svmul(1/norm(Sx), Sx, Sx);
+                svmul(1.0/norm(Sx), Sx, Sx);
 
                 /* now we can get Sy from the outer product of Sx and Sz   */
                 cprod(Sz, Sx, Sy);
-                svmul(1/norm(Sy), Sy, Sy);
+                svmul(1.0/norm(Sy), Sy, Sy);
 
                 /* the square of cosine of the angle between dist and the axis.
                    Using the innerproduct, but two of the three elements are zero
@@ -622,7 +620,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
 
                 for (m = 0; m < DIM; m++)
                 {
-                    frameorder[m] += 0.5 * (3 * cossum[m] - 1);
+                    frameorder[m] += 0.5 * (3.0 * cossum[m] - 1.0);
                 }
 
                 if (bSliced)
@@ -646,7 +644,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                         z_ave -= box[axis][axis];
                     }
 
-                    slice  = (int)(0.5 + (z_ave / (*slWidth))) - 1;
+                    slice  = static_cast<int>((0.5 + (z_ave / (*slWidth))) - 1);
                     slCount[slice]++;     /* determine slice, increase count */
 
                     slFrameorder[slice] += 0.5 * (3 * cossum[axis] - 1);
@@ -656,7 +654,7 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                     /*  store per-molecule order parameter
                      *  To just track single-axis order: (*slOrder)[j][i] += 0.5 * (3 * iprod(cossum,direction) - 1);
                      *  following is for Scd order: */
-                    (*slOrder)[j][i] += -1* (0.3333 * (3 * cossum[XX] - 1) + 0.3333 * 0.5 * (3 * cossum[YY] - 1));
+                    (*slOrder)[j][i] += -1* (1.0/3.0 * (3 * cossum[XX] - 1) + 1.0/3.0 * 0.5 * (3.0 * cossum[YY] - 1));
                 }
                 if (distcalc)
                 {
@@ -675,10 +673,10 @@ void calc_order(const char *fn, atom_id *index, atom_id *a, rvec **order,
                             pbc_dx(&pbc, x1[distidx[k]], x1[a[index[i]+j]], dvec);
                             /* at the moment, just remove dvec[axis] */
                             dvec[axis] = 0;
-                            tmpdist    = min(tmpdist, norm2(dvec));
+                            tmpdist    = std::min(tmpdist, norm2(dvec));
                         }
                         //fprintf(stderr, "Min dist %f; trace %f\n", tmpdist, trace(box));
-                        (*distvals)[j][i] += sqrt(tmpdist);
+                        (*distvals)[j][i] += std::sqrt(tmpdist);
                     }
                 }
             } /* end loop j, over all atoms in group */
@@ -771,8 +769,8 @@ void order_plot(rvec order[], real *slOrder[], const char *afile, const char *bf
         slOrd = xvgropen(bfile, buf, "Molecule", "S", oenv);
         for (atom = 1; atom < ngrps - 1; atom++)
         {
-            fprintf(ord, "%12d   %12g\n", atom, -1 * (0.6667 * order[atom][XX] +
-                                                      0.333 * order[atom][YY]));
+            fprintf(ord, "%12d   %12g\n", atom, -1.0 * (2.0/3.0 * order[atom][XX] +
+                                                        1.0/3.0 * order[atom][YY]));
         }
 
         for (slice = 0; slice < nslices; slice++)
@@ -826,8 +824,8 @@ void order_plot(rvec order[], real *slOrder[], const char *afile, const char *bf
         {
             fprintf(ord, "%12d   %12g   %12g   %12g\n", atom, order[atom][XX],
                     order[atom][YY], order[atom][ZZ]);
-            fprintf(slOrd, "%12d   %12g\n", atom, -1 * (0.6667 * order[atom][XX] +
-                                                        0.333 * order[atom][YY]));
+            fprintf(slOrd, "%12d   %12g\n", atom, -1.0 * (2.0/3.0 * order[atom][XX] +
+                                                          1.0/3.0 * order[atom][YY]));
         }
 
     }
@@ -840,7 +838,6 @@ void write_bfactors(t_filenm  *fnm, int nfile, atom_id *index, atom_id *a, int n
     /*function to write order parameters as B factors in PDB file using
           first frame of trajectory*/
     t_trxstatus *status;
-    int          natoms;
     t_trxframe   fr, frout;
     t_atoms      useatoms;
     int          i, j, ctr, nout;
@@ -848,8 +845,8 @@ void write_bfactors(t_filenm  *fnm, int nfile, atom_id *index, atom_id *a, int n
     ngrps -= 2;  /*we don't have an order parameter for the first or
                        last atom in each chain*/
     nout   = nslices*ngrps;
-    natoms = read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr,
-                              TRX_NEED_X);
+    read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr, TRX_NEED_X);
+
     close_trj(status);
     frout        = fr;
     frout.natoms = nout;
@@ -883,7 +880,7 @@ void write_bfactors(t_filenm  *fnm, int nfile, atom_id *index, atom_id *a, int n
             copy_rvec(fr.x[a[index[i+1]+j]], frout.x[ctr]);
             useatoms.atomname[ctr] = top->atoms.atomname[a[index[i+1]+j]];
             useatoms.atom[ctr]     = top->atoms.atom[a[index[i+1]+j]];
-            useatoms.nres          = max(useatoms.nres, useatoms.atom[ctr].resind+1);
+            useatoms.nres          = std::max(useatoms.nres, useatoms.atom[ctr].resind+1);
             useatoms.resinfo[useatoms.atom[ctr].resind] = top->atoms.resinfo[useatoms.atom[ctr].resind]; /*copy resinfo*/
         }
     }
@@ -991,15 +988,16 @@ int gmx_order(int argc, char *argv[])
     trxfnm = ftp2fn(efTRX, NFILE, fnm);
 
     /* Calculate axis */
-    if (strcmp(normal_axis[0], "x") == 0)
+    GMX_RELEASE_ASSERT(normal_axis[0] != NULL, "Options inconsistency; normal_axis[0] is NULL");
+    if (std::strcmp(normal_axis[0], "x") == 0)
     {
         axis = XX;
     }
-    else if (strcmp(normal_axis[0], "y") == 0)
+    else if (std::strcmp(normal_axis[0], "y") == 0)
     {
         axis = YY;
     }
-    else if (strcmp(normal_axis[0], "z") == 0)
+    else if (std::strcmp(normal_axis[0], "z") == 0)
     {
         axis = ZZ;
     }
similarity index 95%
rename from src/gromacs/gmxana/gmx_polystat.c
rename to src/gromacs/gmxana/gmx_polystat.cpp
index d174119ac54301394b32234d7852457921f6a5ad..48f8092ecabdd533101f6214399453a198684e45 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/tpxio.h"
@@ -86,7 +88,7 @@ static void gyro_eigen(double **gyr, double *eig, double **eigv, int *ord)
 /* Calculate mean square internal distances (Auhl et al., JCP 119, 12718) */
 static void calc_int_dist(double *intd, rvec *x, int i0, int i1)
 {
-    int       ii, jj;
+    int       ii;
     const int ml = i1 - i0 + 1; /* Number of beads in molecule. */
     int       bd;               /* Distance between beads */
     double    d;
@@ -211,8 +213,8 @@ int gmx_polystat(int argc, char *argv[])
     nat_max      = 0;
     for (mol = 0; mol < nmol; mol++)
     {
-        nat_min = min(nat_min, molind[mol+1]-molind[mol]);
-        nat_max = max(nat_max, molind[mol+1]-molind[mol]);
+        nat_min = std::min(nat_min, molind[mol+1]-molind[mol]);
+        nat_max = std::max(nat_max, molind[mol+1]-molind[mol]);
     }
     fprintf(stderr, "Group %s consists of %d molecules\n", grpname, nmol);
     fprintf(stderr, "Group size per molecule, min: %d atoms, max %d atoms\n",
@@ -405,13 +407,13 @@ int gmx_polystat(int argc, char *argv[])
 
         fprintf(out, "%10.3f %8.4f %8.4f %8.4f %8.4f %8.4f",
                 t*output_env_get_time_factor(oenv),
-                sqrt(sum_eed2), sqrt(sum_gyro),
-                sqrt(eig[ord[0]]), sqrt(eig[ord[1]]), sqrt(eig[ord[2]]));
+                std::sqrt(sum_eed2), sqrt(sum_gyro),
+                std::sqrt(eig[ord[0]]), std::sqrt(eig[ord[1]]), std::sqrt(eig[ord[2]]));
         if (bPC)
         {
             for (d = 0; d < DIM; d++)
             {
-                fprintf(out, " %8.4f", sqrt(sum_eig[d]/nmol));
+                fprintf(out, " %8.4f", std::sqrt(sum_eig[d]/nmol));
             }
         }
         fprintf(out, "\n");
@@ -438,7 +440,7 @@ int gmx_polystat(int argc, char *argv[])
             for (j = 0; j < nat_min/2; j += 2)
             {
                 sum_inp[j] /= ninp[j];
-                if (i == -1 && sum_inp[j] <= exp(-1.0))
+                if (i == -1 && sum_inp[j] <= std::exp(-1.0))
                 {
                     i = j;
                 }
@@ -450,8 +452,8 @@ int gmx_polystat(int argc, char *argv[])
             else
             {
                 /* Do linear interpolation on a log scale */
-                pers = i - 2
-                    + 2*(log(sum_inp[i-2]) + 1)/(log(sum_inp[i-2]) - log(sum_inp[i]));
+                pers = i - 2.0
+                    + 2.0*(std::log(sum_inp[i-2]) + 1.0)/(std::log(sum_inp[i-2]) - std::log(sum_inp[i]));
             }
             fprintf(outp, "%10.3f %8.4f\n", t*output_env_get_time_factor(oenv), pers);
             sum_pers_tot += pers;
@@ -479,9 +481,9 @@ int gmx_polystat(int argc, char *argv[])
     sum_gyro_tot /= frame;
     sum_pers_tot /= frame;
     fprintf(stdout, "\nAverage end to end distance: %.3f (nm)\n",
-            sqrt(sum_eed2_tot));
+            std::sqrt(sum_eed2_tot));
     fprintf(stdout, "\nAverage radius of gyration:  %.3f (nm)\n",
-            sqrt(sum_gyro_tot));
+            std::sqrt(sum_gyro_tot));
     if (opt2bSet("-p", NFILE, fnm))
     {
         fprintf(stdout, "\nAverage persistence length:  %.2f bonds\n",
similarity index 95%
rename from src/gromacs/gmxana/gmx_potential.c
rename to src/gromacs/gmxana/gmx_potential.cpp
index fb56240c3adee3119754814f5d9d2da34f635758..e07a38eda3cd999e68a7b9ad64272e6f6146a765 100644 (file)
@@ -36,9 +36,9 @@
  */
 #include "gmxpre.h"
 
-#include <ctype.h>
-#include <math.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/trxio.h"
@@ -106,12 +106,11 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
                     double fudge_z, gmx_bool bSpherical, gmx_bool bCorrect,
                     const output_env_t oenv)
 {
-    rvec        *x0;      /* coordinates without pbc */
-    matrix       box;     /* box (3x3) */
-    int          natoms;  /* nr. atoms in trj */
+    rvec        *x0;     /* coordinates without pbc */
+    matrix       box;    /* box (3x3) */
+    int          natoms; /* nr. atoms in trj */
     t_trxstatus *status;
-    int        **slCount, /* nr. of atoms in one slice for a group */
-                 i, j, n, /* loop indices */
+    int          i, n,   /* loop indices */
                  teller    = 0,
                  ax1       = 0, ax2 = 0,
                  nr_frames = 0, /* number of frames */
@@ -145,7 +144,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
 
     if (!*nslices)
     {
-        *nslices = (int)(box[axis][axis] * 10); /* default value */
+        *nslices = static_cast<int>(box[axis][axis] * 10.0); /* default value */
 
     }
     fprintf(stderr, "\nDividing the box in %d slices\n", *nslices);
@@ -190,7 +189,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
                 {
                     rvec_add(x0[index[n][i]], xcm, x0[index[n][i]]);
                     /* only distance from origin counts, not sign */
-                    slice = norm(x0[index[n][i]])/(*slWidth);
+                    slice = static_cast<int>(norm(x0[index[n][i]])/(*slWidth));
 
                     /* this is a nice check for spherical groups but not for
                        all water in a cubic box since a lot will fall outside
@@ -215,7 +214,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
                         z -= box[axis][axis];
                     }
                     /* determine which slice atom is in */
-                    slice                  = (z / (*slWidth));
+                    slice                  = static_cast<int>((z / (*slWidth)));
                     (*slCharge)[n][slice] += top->atoms.atom[index[n][i]].q;
                 }
             }
@@ -282,7 +281,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
             qsum = 0;
             for (i = 0; i < *nslices; i++)
             {
-                if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+                if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
                 {
                     nn++;
                     qsum += (*slCharge)[n][i];
@@ -291,7 +290,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
             qsum /= nn;
             for (i = 0; i < *nslices; i++)
             {
-                if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+                if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
                 {
                     (*slCharge)[n][i] -= qsum;
                 }
@@ -314,7 +313,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
             qsum = 0;
             for (i = 0; i < *nslices; i++)
             {
-                if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+                if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
                 {
                     nn++;
                     qsum += (*slField)[n][i];
@@ -323,7 +322,7 @@ void calc_potential(const char *fn, atom_id **index, int gnx[],
             qsum /= nn;
             for (i = 0; i < *nslices; i++)
             {
-                if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+                if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
                 {
                     (*slField)[n][i] -= qsum;
                 }
similarity index 98%
rename from src/gromacs/gmxana/gmx_principal.c
rename to src/gromacs/gmxana/gmx_principal.cpp
index 68d10a239b6406adbe4b987f01e06689daa2d129..6ef089ebe82122d557496801ff80180d329e7d6e 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"
@@ -94,9 +94,9 @@ int gmx_principal(int argc, char *argv[])
 
     int             natoms;
     char           *grpname, title[256];
-    int             i, j, m, gnx, nam, mol;
+    int             i, gnx;
     atom_id        *index;
-    rvec            a1, a2, a3, moi;
+    rvec            moi;
     FILE      *     axis1;
     FILE      *     axis2;
     FILE      *     axis3;
similarity index 99%
rename from src/gromacs/gmxana/gmx_rama.c
rename to src/gromacs/gmxana/gmx_rama.cpp
index f48e3b6f8fa2a3ed068089a5db42e95756e8cbff..4bb3d9b69c5b5e295063d2d1fbc9da82efa9f667 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/xvgr.h"
similarity index 97%
rename from src/gromacs/gmxana/gmx_rms.c
rename to src/gromacs/gmxana/gmx_rms.cpp
index 3e32fa29e142e02a984e85440a548b00b222b100..44f98652767aee87c6d1a252ec42c1387537b680 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdlib>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -77,9 +79,9 @@ static void norm_princ(t_atoms *atoms, int isize, atom_id *index, int natoms,
         {
             vec[m] += sqr(x[index[i]][m]);
         }
-        vec[m] = sqrt(vec[m] / isize);
+        vec[m] = std::sqrt(vec[m] / isize);
         /* calculate scaling constants */
-        vec[m] = 1 / (sqrt(3) * vec[m]);
+        vec[m] = 1.0 / (std::sqrt(3.0) * vec[m]);
     }
 
     /* scale coordinates */
@@ -497,7 +499,7 @@ int gmx_rms(int argc, char *argv[])
                 "\nWARNING: topology has %d atoms, whereas trajectory has %d\n",
                 top.atoms.nr, natoms_trx);
     }
-    natoms = min(top.atoms.nr, natoms_trx);
+    natoms = std::min(top.atoms.nr, natoms_trx);
     if (bMat || bBond || bPrev)
     {
         snew(mat_x, NFRAME);
@@ -560,7 +562,6 @@ int gmx_rms(int argc, char *argv[])
         {
             if (IS_CHEMBOND(k))
             {
-                iatom  = top.idef.il[k].iatoms;
                 ncons += top.idef.il[k].nr/3;
             }
         }
@@ -835,8 +836,8 @@ int gmx_rms(int argc, char *argv[])
         {
             if (bDeltaLog)
             {
-                delta_scalex = 8.0/log(2.0);
-                delta_xsize  = (int)(log(tel_mat/2)*delta_scalex+0.5)+1;
+                delta_scalex = 8.0/std::log(2.0);
+                delta_xsize  = static_cast<int>(std::log(static_cast<real>(tel_mat/2))*delta_scalex+0.5)+1;
             }
             else
             {
@@ -919,7 +920,7 @@ int gmx_rms(int argc, char *argv[])
                         {
                             rvec_sub(mat_x[i][ind_bond1[m]], mat_x[i][ind_bond2[m]], vec1);
                             rvec_sub(mat_x2_j[ind_bond1[m]], mat_x2_j[ind_bond2[m]], vec2);
-                            ang += acos(cos_angle(vec1, vec2));
+                            ang += std::acos(cos_angle(vec1, vec2));
                         }
                         bond_mat[i][j] = ang*180.0/(M_PI*ibond);
                         if (bond_mat[i][j] > bond_max)
@@ -961,12 +962,12 @@ int gmx_rms(int argc, char *argv[])
                     {
                         if ((j+my >= 0) && (j+my < tel_mat))
                         {
-                            abs_my = abs(my);
+                            abs_my = std::abs(my);
                             for (mx = -avl; mx <= avl; mx++)
                             {
                                 if ((i+mx >= 0) && (i+mx < tel_mat))
                                 {
-                                    weight      = (real)(avl+1-max(abs(mx), abs_my));
+                                    weight      = avl+1.0-std::max(std::abs(mx), abs_my);
                                     av_tot     += weight*rmsd_mat[i+mx][j+my];
                                     weight_tot += weight;
                                 }
@@ -1025,9 +1026,9 @@ int gmx_rms(int argc, char *argv[])
                         {
                             if (bDeltaLog)
                             {
-                                mx = (int)(log(mx)*delta_scalex+0.5);
+                                mx = static_cast<int>(std::log(static_cast<real>(mx))*delta_scalex+0.5);
                             }
-                            my             = (int)(rmsd_mat[i][j]*delta_scaley*del_lev+0.5);
+                            my             = static_cast<int>(rmsd_mat[i][j]*delta_scaley*del_lev+0.5);
                             delta_tot[mx] += 1.0;
                             if ((rmsd_mat[i][j] >= 0) && (rmsd_mat[i][j] <= delta_maxy))
                             {
@@ -1076,7 +1077,7 @@ int gmx_rms(int argc, char *argv[])
                 fp = ftp2FILE(efDAT, NFILE, fnm, "wb");
                 for (i = 0; i < tel_mat; i++)
                 {
-                    if (fwrite(rmsd_mat[i], sizeof(**rmsd_mat), tel_mat2, fp) != tel_mat2)
+                    if (static_cast<int>(fwrite(rmsd_mat[i], sizeof(**rmsd_mat), tel_mat2, fp)) != tel_mat2)
                     {
                         gmx_fatal(FARGS, "Error writing to output file");
                     }
@@ -1136,7 +1137,7 @@ int gmx_rms(int argc, char *argv[])
     for (i = 0; (i < teller); i++)
     {
         if (bSplit && i > 0 &&
-            fabs(time[bPrev ? freq*i : i]/output_env_get_time_factor(oenv)) < 1e-5)
+            std::abs(time[bPrev ? freq*i : i]/output_env_get_time_factor(oenv)) < 1e-5)
         {
             fprintf(fp, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
         }
@@ -1165,20 +1166,20 @@ int gmx_rms(int argc, char *argv[])
             if (output_env_get_print_xvgr_codes(oenv))
             {
                 fprintf(fp, "@ subtitle \"of %s after lsq fit to mirror of %s\"\n",
-                        gn_rms[0], gn_fit);
+                        gn_rms[0], bFit ? gn_fit : "");
             }
         }
         else
         {
             if (output_env_get_print_xvgr_codes(oenv))
             {
-                fprintf(fp, "@ subtitle \"after lsq fit to mirror %s\"\n", gn_fit);
+                fprintf(fp, "@ subtitle \"after lsq fit to mirror %s\"\n", bFit ? gn_fit : "");
             }
             xvgr_legend(fp, nrms, (const char**)gn_rms, oenv);
         }
         for (i = 0; (i < teller); i++)
         {
-            if (bSplit && i > 0 && fabs(time[i]) < 1e-5)
+            if (bSplit && i > 0 && std::abs(time[i]) < 1e-5)
             {
                 fprintf(fp, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
             }
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
similarity index 94%
rename from src/gromacs/gmxana/gmx_rmsf.c
rename to src/gromacs/gmxana/gmx_rmsf.cpp
index 223a1d7d5995684f3ace3de3cb19a4dfedb0b48d..3d08a0f3db4b55d11d3d19582ce2779813d33b52 100644 (file)
@@ -36,7 +36,8 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
+#include <cmath>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -62,14 +63,14 @@ static real find_pdb_bfac(t_atoms *atoms, t_resinfo *ri, char *atomnm)
     char rresnm[8];
     int  i;
 
-    strcpy(rresnm, *ri->name);
+    std::strcpy(rresnm, *ri->name);
     rresnm[3] = '\0';
     for (i = 0; (i < atoms->nr); i++)
     {
         if ((ri->nr == atoms->resinfo[atoms->atom[i].resind].nr) &&
             (ri->ic == atoms->resinfo[atoms->atom[i].resind].ic) &&
-            (strcmp(*atoms->resinfo[atoms->atom[i].resind].name, rresnm) == 0) &&
-            (strstr(*atoms->atomname[i], atomnm) != NULL))
+            (std::strcmp(*atoms->resinfo[atoms->atom[i].resind].name, rresnm) == 0) &&
+            (std::strstr(*atoms->atomname[i], atomnm) != NULL))
         {
             break;
         }
@@ -211,7 +212,7 @@ int gmx_rmsf(int argc, char *argv[])
         "This shows the directions in which the atoms fluctuate the most and",
         "the least."
     };
-    static gmx_bool  bRes    = FALSE, bAniso = FALSE, bdevX = FALSE, bFit = TRUE;
+    static gmx_bool  bRes    = FALSE, bAniso = FALSE, bFit = TRUE;
     t_pargs          pargs[] = {
         { "-res", FALSE, etBOOL, {&bRes},
           "Calculate averages for each residue" },
@@ -221,20 +222,17 @@ int gmx_rmsf(int argc, char *argv[])
           "Do a least squares superposition before computing RMSF. Without this you must make sure that the reference structure and the trajectory match." }
     };
     int              natom;
-    int              step, nre, natoms, i, g, m, teller = 0;
-    real             t, lambda, *w_rls, *w_rms;
+    int              i, m, teller = 0;
+    real             t, *w_rls;
 
-    t_inputrec       ir;
     t_topology       top;
     int              ePBC;
     t_atoms         *pdbatoms, *refatoms;
-    gmx_bool         bCont;
 
     matrix           box, pdbbox;
     rvec            *x, *pdbx, *xref;
     t_trxstatus     *status;
-    int              npdbatoms, res0;
-    char             buf[256];
+    int              npdbatoms;
     const char      *label;
     char             title[STRLEN];
 
@@ -438,12 +436,12 @@ int gmx_rmsf(int argc, char *argv[])
         {
             aid = index[i];
             pdbatoms->pdbinfo[aid].bAnisotropic = TRUE;
-            pdbatoms->pdbinfo[aid].uij[U11]     = 1e6*U[i][XX*DIM + XX];
-            pdbatoms->pdbinfo[aid].uij[U22]     = 1e6*U[i][YY*DIM + YY];
-            pdbatoms->pdbinfo[aid].uij[U33]     = 1e6*U[i][ZZ*DIM + ZZ];
-            pdbatoms->pdbinfo[aid].uij[U12]     = 1e6*U[i][XX*DIM + YY];
-            pdbatoms->pdbinfo[aid].uij[U13]     = 1e6*U[i][XX*DIM + ZZ];
-            pdbatoms->pdbinfo[aid].uij[U23]     = 1e6*U[i][YY*DIM + ZZ];
+            pdbatoms->pdbinfo[aid].uij[U11]     = static_cast<int>(1e6*U[i][XX*DIM + XX]);
+            pdbatoms->pdbinfo[aid].uij[U22]     = static_cast<int>(1e6*U[i][YY*DIM + YY]);
+            pdbatoms->pdbinfo[aid].uij[U33]     = static_cast<int>(1e6*U[i][ZZ*DIM + ZZ]);
+            pdbatoms->pdbinfo[aid].uij[U12]     = static_cast<int>(1e6*U[i][XX*DIM + YY]);
+            pdbatoms->pdbinfo[aid].uij[U13]     = static_cast<int>(1e6*U[i][XX*DIM + ZZ]);
+            pdbatoms->pdbinfo[aid].uij[U23]     = static_cast<int>(1e6*U[i][YY*DIM + ZZ]);
         }
     }
     if (bRes)
@@ -507,7 +505,7 @@ int gmx_rmsf(int argc, char *argv[])
                 top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
             {
                 fprintf(fp, "%5d %8.4f\n",
-                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, sqrt(rmsf[i]));
+                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, std::sqrt(rmsf[i]));
             }
         }
         xvgrclose(fp);
@@ -536,7 +534,7 @@ int gmx_rmsf(int argc, char *argv[])
                 top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
             {
                 fprintf(fp, "%5d %8.4f\n",
-                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, sqrt(rmsf[i]));
+                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, std::sqrt(rmsf[i]));
             }
         }
         xvgrclose(fp);
similarity index 98%
rename from src/gromacs/gmxana/gmx_rotacf.c
rename to src/gromacs/gmxana/gmx_rotacf.cpp
index e48fc483f262fa549f38bf5da9608fdefa17dc33..98abcf48ad4dac2012665870de3531010d71320a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -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"
@@ -155,7 +155,7 @@ int gmx_rotacf(int argc, char *argv[])
     gpbc = gmx_rmpbc_init(&(top->idef), ePBC, natoms);
 
     /* Start the loop over frames */
-    t1      = t0 = t;
+    t0      = t;
     teller  = 0;
     do
     {
similarity index 97%
rename from src/gromacs/gmxana/gmx_rotmat.c
rename to src/gromacs/gmxana/gmx_rotmat.cpp
index 1c95da982faae63eb698031aee3a8ab67079aced..28fd1e81a6d317aadb713d362d7a8c6f97559a5f 100644 (file)
@@ -34,8 +34,8 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -50,6 +50,7 @@
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 static void get_refx(output_env_t oenv, const char *trxfn, int nfitdim, int skip,
@@ -134,8 +135,8 @@ static void get_refx(output_env_t oenv, const char *trxfn, int nfitdim, int skip
                 }
             }
             msd      /= tot_mass;
-            srmsd[i] += sqrt(msd);
-            srmsd[j] += sqrt(msd);
+            srmsd[i] += std::sqrt(msd);
+            srmsd[j] += std::sqrt(msd);
         }
         sfree(xi[i]);
     }
@@ -251,6 +252,7 @@ int gmx_rotmat(int argc, char *argv[])
 
     get_index(&top.atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpname);
 
+    GMX_RELEASE_ASSERT(reffit[0] != NULL, "Options inconsistency; reffit[0] is NULL");
     if (reffit[0][0] != 'n')
     {
         get_refx(oenv, ftp2fn(efTRX, NFILE, fnm), reffit[0][2] == 'z' ? 3 : 2, skip,
similarity index 96%
rename from src/gromacs/gmxana/gmx_saltbr.c
rename to src/gromacs/gmxana/gmx_saltbr.cpp
index cc4417213daa0cc39ce816d0227a35ca93273b60..85e05de0e8ada5a44a612635ea529a5155b1d401 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/filenm.h"
@@ -75,7 +75,7 @@ static t_charge *mk_charge(t_atoms *atoms, t_block *cgs, int *nncg)
         {
             qq += atoms->atom[j].q;
         }
-        if (fabs(qq) > 1.0e-5)
+        if (std::abs(qq) > 1.0e-5)
         {
             srenew(cg, ncg+1);
             cg[ncg].q  = qq;
@@ -124,7 +124,7 @@ static real calc_dist(t_pbc *pbc, rvec x[], t_block *cgs, int icg, int jcg)
             }
         }
     }
-    return sqrt(mindist2);
+    return std::sqrt(mindist2);
 }
 
 int gmx_saltbr(int argc, char *argv[])
@@ -170,14 +170,12 @@ int gmx_saltbr(int argc, char *argv[])
     int                ePBC;
     char              *buf;
     t_trxstatus       *status;
-    int                i, j, k, m, nnn, teller, ncg, n1, n2, n3, natoms;
+    int                i, j, k, m, nnn, teller, ncg;
     real               t, *time, qi, qj;
     t_charge          *cg;
     real            ***cgdist;
     int              **nWithin;
 
-    double             t0, dt;
-    char               label[234];
     t_pbc              pbc;
     rvec              *x;
     matrix             box;
@@ -199,7 +197,7 @@ int gmx_saltbr(int argc, char *argv[])
         snew(nWithin[i], ncg);
     }
 
-    natoms = 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;
     time   = NULL;
similarity index 97%
rename from src/gromacs/gmxana/gmx_sans.c
rename to src/gromacs/gmxana/gmx_sans.cpp
index 90d30a617a1718e45aa45c4102fc6725b21a2332..f017f4145c1c57d1de072ce7f0e7ee0191f48331 100644 (file)
@@ -53,6 +53,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/gmxomp.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -118,12 +119,10 @@ int gmx_sans(int argc, char *argv[])
 #endif
     };
     FILE                                 *fp;
-    const char                           *fnTPX, *fnNDX, *fnTRX, *fnDAT = NULL;
+    const char                           *fnTPX, *fnTRX, *fnDAT = NULL;
     t_trxstatus                          *status;
     t_topology                           *top  = NULL;
-    t_atom                               *atom = NULL;
     gmx_rmpbc_t                           gpbc = NULL;
-    gmx_bool                              bTPX;
     gmx_bool                              bFFT = FALSE, bDEBYE = FALSE;
     gmx_bool                              bMC  = FALSE;
     int                                   ePBC = -1;
@@ -135,7 +134,7 @@ int gmx_sans(int argc, char *argv[])
     char                                **grpname = NULL;
     atom_id                              *index   = NULL;
     int                                   isize;
-    int                                   i, j;
+    int                                   i;
     char                                 *hdr            = NULL;
     char                                 *suffix         = NULL;
     t_filenm                             *fnmdup         = NULL;
@@ -172,6 +171,7 @@ int gmx_sans(int argc, char *argv[])
     gmx_omp_set_num_threads(nthreads);
 
     /* Now try to parse opts for modes */
+    GMX_RELEASE_ASSERT(emethod[0] != NULL, "Options inconsistency; emethod[0] is NULL");
     switch (emethod[0][0])
     {
         case 'd':
@@ -227,7 +227,7 @@ int gmx_sans(int argc, char *argv[])
     snew(grpname, 1);
     snew(index, 1);
 
-    bTPX = read_tps_conf(fnTPX, title, top, &ePBC, &x, NULL, box, TRUE);
+    read_tps_conf(fnTPX, title, top, &ePBC, &x, NULL, box, TRUE);
 
     printf("\nPlease select group for SANS spectra calculation:\n");
     get_index(&(top->atoms), ftp2fn_null(efNDX, NFILE, fnm), 1, &isize, &index, grpname);
similarity index 97%
rename from src/gromacs/gmxana/gmx_saxs.c
rename to src/gromacs/gmxana/gmx_saxs.cpp
index 30967feab71464ac42c24f784e2984a6f2594ab8..de51400a29c6704108eda4b9b348a7d228706c68 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -37,7 +37,7 @@
 
 #include "gmxpre.h"
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/gmxana/gmx_ana.h"
similarity index 94%
rename from src/gromacs/gmxana/gmx_sham.c
rename to src/gromacs/gmxana/gmx_sham.cpp
index 87b28e124d386a724bbdab8e63e377bab0e788d7..f24788810c2121678d1a8407a5e5264d34f180f4 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/matio.h"
@@ -229,7 +231,7 @@ static gmx_inline
 void print_minimum(FILE *fp, int num, const t_minimum *min)
 {
     fprintf(fp,
-            "Minimum %d at index " "%"GMX_PRId64 " energy %10.3f\n",
+            "Minimum %d at index " "%" GMX_PRId64 " energy %10.3f\n",
             num, min->index, min->ener);
 }
 
@@ -428,9 +430,9 @@ static void do_sham(const char *fn, const char *ndx,
     real       **PP, *W, *E, **WW, **EE, *S, **SS, *M, *bE;
     rvec         xxx;
     char        *buf;
-    double      *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf, Mmin, Mmax;
+    double      *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf;
     real        *delta;
-    int          i, j, k, imin, len, index, d, *nbin, *bindex, bi;
+    int          i, j, k, imin, len, index, *nbin, *bindex, bi;
     int         *nxyz, maxbox;
     t_blocka    *b;
     gmx_bool     bOutside;
@@ -451,8 +453,8 @@ static void do_sham(const char *fn, const char *ndx,
         min_eig[i] = max_eig[i] = eig[i][0];
         for (j = 0; (j < n); j++)
         {
-            min_eig[i] = min(min_eig[i], eig[i][j]);
-            max_eig[i] = max(max_eig[i], eig[i][j]);
+            min_eig[i] = std::min(min_eig[i], eig[i][j]);
+            max_eig[i] = std::max(max_eig[i], eig[i][j]);
             delta[i]   = (max_eig[i]-min_eig[i])/(2.0*ibox[i]);
         }
         /* Add some extra space, half a bin on each side, unless the
@@ -501,7 +503,7 @@ static void do_sham(const char *fn, const char *ndx,
             {
                 bE[j] = (bref - 1/(BOLTZ*enerT[1][j]))*enerT[0][j];
             }
-            Emin  = min(Emin, bE[j]);
+            Emin  = std::min(Emin, static_cast<double>(bE[j]));
         }
     }
     else
@@ -531,7 +533,7 @@ static void do_sham(const char *fn, const char *ndx,
         bOutside = FALSE;
         for (i = 0; (i < neig); i++)
         {
-            nxyz[i] = bfac[i]*(eig[i][j]-min_eig[i]);
+            nxyz[i] = static_cast<int>(bfac[i]*(eig[i][j]-min_eig[i]));
             if (nxyz[i] < 0 || nxyz[i] >= ibox[i])
             {
                 bOutside = TRUE;
@@ -544,7 +546,7 @@ static void do_sham(const char *fn, const char *ndx,
             /* Compute the exponential factor */
             if (enerT)
             {
-                efac = exp(-bE[j]+Emin);
+                efac = std::exp(-bE[j]+Emin);
             }
             else
             {
@@ -563,7 +565,7 @@ static void do_sham(const char *fn, const char *ndx,
                 }
                 else if (idim[i] == -1)
                 {
-                    efac /= sin(DEG2RAD*eig[i][j]);
+                    efac /= std::sin(DEG2RAD*eig[i][j]);
                 }
             }
             /* Update the probability */
@@ -592,16 +594,16 @@ static void do_sham(const char *fn, const char *ndx,
     {
         if (P[i] != 0)
         {
-            Pmax = max(P[i], Pmax);
-            W[i] = -BOLTZ*Tref*log(P[i]);
+            Pmax = std::max(P[i], Pmax);
+            W[i] = -BOLTZ*Tref*std::log(P[i]);
             if (W[i] < Wmin)
             {
                 Wmin = W[i];
                 imin = i;
             }
-            Emin = min(E[i], Emin);
-            Emax = max(E[i], Emax);
-            Wmax = max(W[i], Wmax);
+            Emin = std::min(static_cast<double>(E[i]), Emin);
+            Emax = std::max(static_cast<double>(E[i]), Emax);
+            Wmax = std::max(static_cast<double>(W[i]), Wmax);
         }
     }
     if (pmax > 0)
@@ -681,12 +683,12 @@ static void do_sham(const char *fn, const char *ndx,
     snew(axis_x, ibox[0]+1);
     snew(axis_y, ibox[1]+1);
     snew(axis_z, ibox[2]+1);
-    maxbox = max(ibox[0], max(ibox[1], ibox[2]));
+    maxbox = std::max(ibox[0], std::max(ibox[1], ibox[2]));
     snew(PP, maxbox*maxbox);
     snew(WW, maxbox*maxbox);
     snew(EE, maxbox*maxbox);
     snew(SS, maxbox*maxbox);
-    for (i = 0; (i < min(neig, 3)); i++)
+    for (i = 0; (i < std::min(neig, 3)); i++)
     {
         switch (i)
         {
@@ -776,9 +778,9 @@ static void do_sham(const char *fn, const char *ndx,
                 WW[i][j] = W[index3(ibox, i, j, nxyz[ZZ])];
             }
         }
-        snew(buf, strlen(xpm)+4);
+        snew(buf, std::strlen(xpm)+4);
         sprintf(buf, "%s", xpm);
-        sprintf(&buf[strlen(xpm)-4], "12.xpm");
+        sprintf(&buf[std::strlen(xpm)-4], "12.xpm");
         fp = gmx_ffopen(buf, "w");
         write_xpm(fp, flags, "Gibbs Energy Landscape", "W (kJ/mol)", "PC1", "PC2",
                   ibox[0], ibox[1], axis_x, axis_y, WW, 0, gmax, rlo, rhi, &nlevels);
@@ -790,7 +792,7 @@ static void do_sham(const char *fn, const char *ndx,
                 WW[i][j] = W[index3(ibox, i, nxyz[YY], j)];
             }
         }
-        sprintf(&buf[strlen(xpm)-4], "13.xpm");
+        sprintf(&buf[std::strlen(xpm)-4], "13.xpm");
         fp = gmx_ffopen(buf, "w");
         write_xpm(fp, flags, "SHAM Energy Landscape", "kJ/mol", "PC1", "PC3",
                   ibox[0], ibox[2], axis_x, axis_z, WW, 0, gmax, rlo, rhi, &nlevels);
@@ -802,7 +804,7 @@ static void do_sham(const char *fn, const char *ndx,
                 WW[i][j] = W[index3(ibox, nxyz[XX], i, j)];
             }
         }
-        sprintf(&buf[strlen(xpm)-4], "23.xpm");
+        sprintf(&buf[std::strlen(xpm)-4], "23.xpm");
         fp = gmx_ffopen(buf, "w");
         write_xpm(fp, flags, "SHAM Energy Landscape", "kJ/mol", "PC2", "PC3",
                   ibox[1], ibox[2], axis_y, axis_z, WW, 0, gmax, rlo, rhi, &nlevels);
@@ -840,11 +842,11 @@ static void ehisto(const char *fh, int n, real **enerT, const output_env_t oenv)
             T[nbin]   = enerT[1][j];
             nbin++;
         }
-        bmin = min(enerT[0][j], bmin);
-        bmax = max(enerT[0][j], bmax);
+        bmin = std::min(enerT[0][j], bmin);
+        bmax = std::max(enerT[0][j], bmax);
     }
     bwidth  = 1.0;
-    blength = (bmax - bmin)/bwidth + 2;
+    blength = static_cast<int>((bmax - bmin)/bwidth + 2);
     snew(histo, nbin);
     for (i = 0; (i < nbin); i++)
     {
@@ -852,7 +854,7 @@ static void ehisto(const char *fh, int n, real **enerT, const output_env_t oenv)
     }
     for (j = 0; (j < n); j++)
     {
-        k = (enerT[0][j]-bmin)/bwidth;
+        k = static_cast<int>((enerT[0][j]-bmin)/bwidth);
         histo[bindex[j]][k]++;
     }
     fp = xvgropen(fh, "Energy distribution", "E (kJ/mol)", "", oenv);
@@ -911,15 +913,14 @@ int gmx_sham(int argc, char *argv[])
         "is the natural quantity to use, as it will produce bins of the same",
         "volume."
     };
-    static real        tb        = -1, te = -1, frac = 0.5, filtlen = 0;
-    static gmx_bool    bHaveT    = TRUE, bDer = FALSE, bSubAv = TRUE, bAverCorr = FALSE, bXYdy = FALSE;
-    static gmx_bool    bEESEF    = FALSE, bEENLC = FALSE, bEeFitAc = FALSE, bPower = FALSE;
-    static gmx_bool    bShamEner = TRUE, bSham = TRUE;
+    static real        tb        = -1, te = -1;
+    static gmx_bool    bHaveT    = TRUE, bDer = FALSE;
+    static gmx_bool    bSham     = TRUE;
     static real        Tref      = 298.15, pmin = 0, ttol = 0, pmax = 0, gmax = 0, emin = 0, emax = 0;
     static rvec        nrdim     = {1, 1, 1};
     static rvec        nrbox     = {32, 32, 32};
     static rvec        xmin      = {0, 0, 0}, xmax = {1, 1, 1};
-    static int         nsets_in  = 1, nb_min = 4, resol = 10, nlevels = 25;
+    static int         nsets_in  = 1, nlevels = 25;
     t_pargs            pa[]      = {
         { "-time",    FALSE, etBOOL, {&bHaveT},
           "Expect a time in the input" },
@@ -960,11 +961,9 @@ int gmx_sham(int argc, char *argv[])
     };
 #define NPA asize(pa)
 
-    FILE           *out;
-    int             n, e_n, nlast, s, nset, e_nset, d_nset, i, j = 0, *idim, *ibox;
-    real          **val, **et_val, *t, *e_t, e_dt, d_dt, dt, tot, error;
+    int             n, e_n, nset, e_nset = 0, i, *idim, *ibox;
+    real          **val, **et_val, *t, *e_t, e_dt, dt;
     real           *rmin, *rmax;
-    double         *av, *sig, cum1, cum2, cum3, cum4, db;
     const char     *fn_ge, *fn_ene;
     output_env_t    oenv;
     gmx_int64_t     num_grid_points;
@@ -1045,21 +1044,21 @@ int gmx_sham(int argc, char *argv[])
         ehisto(opt2fn("-histo", NFILE, fnm), e_n, et_val, oenv);
     }
 
-    snew(idim, max(3, nset));
-    snew(ibox, max(3, nset));
-    snew(rmin, max(3, nset));
-    snew(rmax, max(3, nset));
-    for (i = 0; (i < min(3, nset)); i++)
+    snew(idim, std::max(3, nset));
+    snew(ibox, std::max(3, nset));
+    snew(rmin, std::max(3, nset));
+    snew(rmax, std::max(3, nset));
+    for (i = 0; (i < std::min(3, nset)); i++)
     {
-        idim[i] = nrdim[i];
-        ibox[i] = nrbox[i];
+        idim[i] = static_cast<int>(nrdim[i]);
+        ibox[i] = static_cast<int>(nrbox[i]);
         rmin[i] = xmin[i];
         rmax[i] = xmax[i];
     }
     for (; (i < nset); i++)
     {
-        idim[i] = nrdim[2];
-        ibox[i] = nrbox[2];
+        idim[i] = static_cast<int>(nrdim[2]);
+        ibox[i] = static_cast<int>(nrbox[2]);
         rmin[i] = xmin[2];
         rmax[i] = xmax[2];
     }
similarity index 87%
rename from src/gromacs/gmxana/gmx_sigeps.c
rename to src/gromacs/gmxana/gmx_sigeps.cpp
index 3866506b280c0e65b57091e7a9bada03eb1c743d..59df10f858440561b85ec5524b0c30af1054c5b8 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
+#include <cmath>
+#include <cstdio>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/xvgr.h"
+#include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/txtdump.h"
 
 real pot(real x, real qq, real c6, real cn, int npow)
 {
-    return cn*pow(x, -npow)-c6*pow(x, -6)+qq*ONE_4PI_EPS0/x;
+    return cn*pow(x, -npow)-c6*std::pow(x, -6)+qq*ONE_4PI_EPS0/x;
 }
 
 real bhpot(real x, real A, real B, real C)
 {
-    return A*exp(-B*x) - C*pow(x, -6.0);
+    return A*std::exp(-B*x) - C*std::pow(x, -6);
 }
 
 real dpot(real x, real qq, real c6, real cn, int npow)
 {
-    return -(npow*cn*pow(x, -npow-1)-6*c6*pow(x, -7)+qq*ONE_4PI_EPS0/sqr(x));
+    return -(npow*cn*std::pow(x, -npow-1)-6*c6*std::pow(x, -7)+qq*ONE_4PI_EPS0/sqr(x));
 }
 
 int gmx_sigeps(int argc, char *argv[])
@@ -98,7 +99,7 @@ int gmx_sigeps(int argc, char *argv[])
     FILE         *fp;
     int           i;
     gmx_bool      bBham;
-    real          qq, x, oldx, minimum, mval, dp[2], pp[2];
+    real          qq, x, oldx, minimum, mval, dp[2];
     int           cur = 0;
 #define next (1-cur)
 
@@ -116,24 +117,24 @@ int gmx_sigeps(int argc, char *argv[])
     if (bBham)
     {
         c6  = Cbh;
-        sig = pow((6.0/npow)*pow(npow/Bbh, npow-6.0), 1.0/(npow-6.0));
-        eps = c6/(4*pow(sig, 6.0));
-        cn  = 4*eps*pow(sig, npow);
+        sig = std::pow((6.0/npow)*std::pow(npow/Bbh, npow-6), 1.0/(npow-6));
+        eps = c6/(4*std::pow(sig, 6));
+        cn  = 4*eps*std::pow(sig, npow);
     }
     else
     {
         if (opt2parg_bSet("-sig", asize(pa), pa) ||
             opt2parg_bSet("-eps", asize(pa), pa))
         {
-            c6  = 4*eps*pow(sig, 6);
-            cn  = 4*eps*pow(sig, npow);
+            c6  = 4*eps*std::pow(sig, 6);
+            cn  = 4*eps*std::pow(sig, npow);
         }
         else if (opt2parg_bSet("-c6", asize(pa), pa) ||
                  opt2parg_bSet("-cn", asize(pa), pa) ||
                  opt2parg_bSet("-pow", asize(pa), pa))
         {
-            sig = pow(cn/c6, 1.0/(npow-6.0));
-            eps = 0.25*c6*pow(sig, -6.0);
+            sig = std::pow(cn/c6, static_cast<real>(1.0/(npow-6)));
+            eps = 0.25*c6*std::pow(sig, -6);
         }
         else
         {
@@ -142,13 +143,13 @@ int gmx_sigeps(int argc, char *argv[])
         printf("c6    = %12.5e, c%d    = %12.5e\n", c6, npow, cn);
         printf("sigma = %12.5f, epsilon = %12.5f\n", sig, eps);
 
-        minimum = pow(npow/6.0*pow(sig, npow-6.0), 1.0/(npow-6));
+        minimum = std::pow(npow/6.0*std::pow(sig, npow-6), 1.0/(npow-6));
         printf("Van der Waals minimum at %g, V = %g\n\n",
                minimum, pot(minimum, 0, c6, cn, npow));
         printf("Fit of Lennard Jones (%d-6) to Buckingham:\n", npow);
         Bbh = npow/minimum;
         Cbh = c6;
-        Abh = 4*eps*pow(sig/minimum, npow)*exp(npow);
+        Abh = 4*eps*std::pow(sig/minimum, static_cast<real>(npow))*std::exp(static_cast<real>(npow));
         printf("A = %g, B = %g, C = %g\n", Abh, Bbh, Cbh);
     }
     qq = qi*qj;
@@ -161,8 +162,6 @@ int gmx_sigeps(int argc, char *argv[])
     {
         sig = 0.25;
     }
-    minimum = -1;
-    mval    = 0;
     oldx    = 0;
     for (i = 0; (i < 100); i++)
     {
similarity index 95%
rename from src/gromacs/gmxana/gmx_sorient.c
rename to src/gromacs/gmxana/gmx_sorient.cpp
index ac01e53622643043d4b52931743c9c9ad6994fc9..8acf9a03f92205f5f46241c3cd8ba3b648d93797 100644 (file)
@@ -36,6 +36,8 @@
  */
 #include "gmxpre.h"
 
+#include <cmath>
+
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
@@ -90,7 +92,7 @@ static void calc_com_pbc(int nrefat, t_topology *top, rvec x[], t_pbc *pbc,
                 rvec_add(xref, dx, xtest);
                 for (j = 0; (j < DIM); j++)
                 {
-                    if (fabs(xtest[j]-x[ai][j]) > tol)
+                    if (std::abs(xtest[j]-x[ai][j]) > tol)
                     {
                         /* Here we have used the wrong image for contributing to the COM */
                         xref[j] += mass*(xtest[j]-x[ai][j]);
@@ -121,13 +123,13 @@ int gmx_sorient(int argc, char *argv[])
     matrix          box;
 
     FILE           *fp;
-    int             i, j, p, sa0, sa1, sa2, n, ntot, nf, m, *hist1, *hist2, *histn, nbin1, nbin2, nrbin;
+    int             i, p, sa0, sa1, sa2, n, ntot, nf, m, *hist1, *hist2, *histn, nbin1, nbin2, nrbin;
     real           *histi1, *histi2, invbw, invrbw;
     double          sum1, sum2;
     int            *isize, nrefgrp, nrefat;
     atom_id       **index;
     char          **grpname;
-    real            inp, outp, two_pi, nav, normfac, rmin2, rmax2, rcut, rcut2, r2, r, mass, mtot;
+    real            inp, outp, nav, normfac, rmin2, rmax2, rcut, rcut2, r2, r;
     real            c1, c2;
     char            str[STRLEN];
     gmx_bool        bTPS;
@@ -201,8 +203,6 @@ int gmx_sorient(int argc, char *argv[])
         return 0;
     }
 
-    two_pi = 2/M_PI;
-
     bTPS = (opt2bSet("-s", NFILE, fnm) || !opt2bSet("-n", NFILE, fnm) || bCom);
     if (bTPS)
     {
@@ -246,7 +246,7 @@ int gmx_sorient(int argc, char *argv[])
 
     rmin2 = sqr(rmin);
     rmax2 = sqr(rmax);
-    rcut  = 0.99*sqrt(max_cutoff2(guess_ePBC(box), box));
+    rcut  = 0.99*std::sqrt(max_cutoff2(guess_ePBC(box), box));
     if (rcut == 0)
     {
         rcut = 10*rmax;
@@ -254,14 +254,14 @@ int gmx_sorient(int argc, char *argv[])
     rcut2 = sqr(rcut);
 
     invbw = 1/binwidth;
-    nbin1 = 1+(int)(2*invbw + 0.5);
-    nbin2 = 1+(int)(invbw + 0.5);
+    nbin1 = 1+static_cast<int>(2*invbw + 0.5);
+    nbin2 = 1+static_cast<int>(invbw + 0.5);
 
     invrbw = 1/rbinw;
 
     snew(hist1, nbin1);
     snew(hist2, nbin2);
-    nrbin = 1+(int)(rcut/rbinw);
+    nrbin = 1+static_cast<int>(rcut/rbinw);
     if (nrbin == 0)
     {
         nrbin = 1;
@@ -292,7 +292,6 @@ int gmx_sorient(int argc, char *argv[])
         set_pbc(&pbc, ePBC, box);
         n    = 0;
         inp  = 0;
-        outp = 0;
         for (p = 0; (p < nrefgrp); p++)
         {
             if (bCom)
@@ -316,7 +315,7 @@ int gmx_sorient(int argc, char *argv[])
                 r2  = norm2(dx);
                 if (r2 < rcut2)
                 {
-                    r = sqrt(r2);
+                    r = std::sqrt(r2);
                     if (!bVec23)
                     {
                         /* Determine the normal to the plain */
@@ -338,7 +337,7 @@ int gmx_sorient(int argc, char *argv[])
                         outp = iprod(dx, dxh2)/r;
                     }
                     {
-                        int ii = (int)(invrbw*r);
+                        int ii = static_cast<int>(invrbw*r);
                         range_check(ii, 0, nrbin);
                         histi1[ii] += inp;
                         histi2[ii] += 3*sqr(outp) - 1;
@@ -346,8 +345,8 @@ int gmx_sorient(int argc, char *argv[])
                     }
                     if ((r2 >= rmin2) && (r2 < rmax2))
                     {
-                        int ii1 = (int)(invbw*(inp + 1));
-                        int ii2 = (int)(invbw*fabs(outp));
+                        int ii1 = static_cast<int>(invbw*(inp + 1));
+                        int ii2 = static_cast<int>(invbw*std::abs(outp));
 
                         range_check(ii1, 0, nbin1);
                         range_check(ii2, 0, nbin2);
@@ -375,7 +374,7 @@ int gmx_sorient(int argc, char *argv[])
     hist1[nbin1-1] += hist1[nbin1];
     hist2[nbin2-1] += hist2[nbin2];
 
-    nav     = (real)ntot/(nrefgrp*nf);
+    nav     = static_cast<real>(ntot)/(nrefgrp*nf);
     normfac = invbw/ntot;
 
     fprintf(stderr,  "Average nr of molecules between %g and %g nm: %.1f\n",
similarity index 87%
rename from src/gromacs/gmxana/gmx_spatial.c
rename to src/gromacs/gmxana/gmx_spatial.cpp
index a7f3d12720ba4f39634ae03d2cb1dc1bda3d2a4e..44f9b2ac1631285d9c169d8779fea617bb0d76db 100644 (file)
@@ -34,8 +34,8 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdlib>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -106,7 +106,6 @@ int gmx_spatial(int argc, char *argv[])
     };
 
     static gmx_bool bPBC         = FALSE;
-    static gmx_bool bSHIFT       = FALSE;
     static int      iIGNOREOUTER = -1;   /*Positive values may help if the surface is spikey */
     static gmx_bool bCUTDOWN     = TRUE;
     static real     rBINWIDTH    = 0.05; /* nm */
@@ -134,7 +133,7 @@ int gmx_spatial(int argc, char *argv[])
     int             ePBC;
     char            title[STRLEN];
     t_trxframe      fr;
-    rvec           *xtop, *shx[26];
+    rvec           *xtop;
     matrix          box, box_pbc;
     t_trxstatus    *status;
     int             flags = TRX_READ_X;
@@ -146,12 +145,12 @@ int gmx_spatial(int argc, char *argv[])
     int             i, nidx, nidxp;
     int             v;
     int             j, k;
-    long         ***bin = (long ***)NULL;
-    long            nbin[3];
+    int          ***bin = NULL;
+    int             nbin[3];
     FILE           *flp;
-    long            x, y, z, minx, miny, minz, maxx, maxy, maxz;
-    long            numfr, numcu;
-    long            tot, max, min;
+    int             x, y, z, minx, miny, minz, maxx, maxy, maxz;
+    int             numfr, numcu;
+    int             tot, maxval, minval;
     double          norm;
     output_env_t    oenv;
     gmx_rmpbc_t     gpbc = NULL;
@@ -217,9 +216,9 @@ int gmx_spatial(int argc, char *argv[])
     }
     for (i = ZZ; i >= XX; --i)
     {
-        MAXBIN[i]  = (ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH)+(double)iNAB)*rBINWIDTH+MINBIN[i];
-        MINBIN[i] -= (double)iNAB*rBINWIDTH;
-        nbin[i]    = (long)ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH);
+        MAXBIN[i]  = (std::ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH)+iNAB)*rBINWIDTH+MINBIN[i];
+        MINBIN[i] -= iNAB*rBINWIDTH;
+        nbin[i]    = static_cast<int>(std::ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH));
     }
     snew(bin, nbin[XX]);
     for (i = 0; i < nbin[XX]; ++i)
@@ -262,9 +261,9 @@ int gmx_spatial(int argc, char *argv[])
                 printf("Memory was required for [%f,%f,%f]\n", fr.x[index[i]][XX], fr.x[index[i]][YY], fr.x[index[i]][ZZ]);
                 exit(1);
             }
-            x = (long)ceil((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH);
-            y = (long)ceil((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH);
-            z = (long)ceil((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH);
+            x = static_cast<int>(std::ceil((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH));
+            y = static_cast<int>(std::ceil((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH));
+            z = static_cast<int>(std::ceil((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH));
             ++bin[x][y][z];
             if (x < minx)
             {
@@ -315,9 +314,9 @@ int gmx_spatial(int argc, char *argv[])
     fprintf(flp, "Spatial Distribution Function\n");
     fprintf(flp, "test\n");
     fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", nidxp, (MINBIN[XX]+(minx+iIGNOREOUTER)*rBINWIDTH)*10./bohr, (MINBIN[YY]+(miny+iIGNOREOUTER)*rBINWIDTH)*10./bohr, (MINBIN[ZZ]+(minz+iIGNOREOUTER)*rBINWIDTH)*10./bohr);
-    fprintf(flp, "%5ld%12.6f%12.6f%12.6f\n", maxx-minx+1-(2*iIGNOREOUTER), rBINWIDTH*10./bohr, 0., 0.);
-    fprintf(flp, "%5ld%12.6f%12.6f%12.6f\n", maxy-miny+1-(2*iIGNOREOUTER), 0., rBINWIDTH*10./bohr, 0.);
-    fprintf(flp, "%5ld%12.6f%12.6f%12.6f\n", maxz-minz+1-(2*iIGNOREOUTER), 0., 0., rBINWIDTH*10./bohr);
+    fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", maxx-minx+1-(2*iIGNOREOUTER), rBINWIDTH*10./bohr, 0., 0.);
+    fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", maxy-miny+1-(2*iIGNOREOUTER), 0., rBINWIDTH*10./bohr, 0.);
+    fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", maxz-minz+1-(2*iIGNOREOUTER), 0., 0., rBINWIDTH*10./bohr);
     for (i = 0; i < nidxp; i++)
     {
         v = 2;
@@ -341,7 +340,7 @@ int gmx_spatial(int argc, char *argv[])
         {
             v = 16;
         }
-        fprintf(flp, "%5d%12.6f%12.6f%12.6f%12.6f\n", v, 0., (double)fr.x[indexp[i]][XX]*10./bohr, (double)fr.x[indexp[i]][YY]*10./bohr, (double)fr.x[indexp[i]][ZZ]*10./bohr);
+        fprintf(flp, "%5d%12.6f%12.6f%12.6f%12.6f\n", v, 0., fr.x[indexp[i]][XX]*10.0/bohr, fr.x[indexp[i]][YY]*10.0/bohr, fr.x[indexp[i]][ZZ]*10.0/bohr);
     }
 
     tot = 0;
@@ -366,15 +365,15 @@ int gmx_spatial(int argc, char *argv[])
                 if (bin[k][j][i] != 0)
                 {
                     printf("A bin was not empty when it should have been empty. Programming error.\n");
-                    printf("bin[%d][%d][%d] was = %ld\n", k, j, i, bin[k][j][i]);
+                    printf("bin[%d][%d][%d] was = %d\n", k, j, i, bin[k][j][i]);
                     exit(1);
                 }
             }
         }
     }
 
-    min = 999;
-    max = 0;
+    minval = 999;
+    maxval = 0;
     for (k = 0; k < nbin[XX]; k++)
     {
         if (k < minx+iIGNOREOUTER || k > maxx-iIGNOREOUTER)
@@ -394,13 +393,13 @@ int gmx_spatial(int argc, char *argv[])
                     continue;
                 }
                 tot += bin[k][j][i];
-                if (bin[k][j][i] > max)
+                if (bin[k][j][i] > maxval)
                 {
-                    max = bin[k][j][i];
+                    maxval = bin[k][j][i];
                 }
-                if (bin[k][j][i] < min)
+                if (bin[k][j][i] < minval)
                 {
-                    min = bin[k][j][i];
+                    minval = bin[k][j][i];
                 }
             }
         }
@@ -409,7 +408,7 @@ int gmx_spatial(int argc, char *argv[])
     numcu = (maxx-minx+1-(2*iIGNOREOUTER))*(maxy-miny+1-(2*iIGNOREOUTER))*(maxz-minz+1-(2*iIGNOREOUTER));
     if (bCALCDIV)
     {
-        norm = ((double)numcu*(double)numfr) / (double)tot;
+        norm = static_cast<double>(numcu*numfr)/tot;
     }
     else
     {
@@ -434,7 +433,7 @@ int gmx_spatial(int argc, char *argv[])
                 {
                     continue;
                 }
-                fprintf(flp, "%12.6f ", norm*(double)bin[k][j][i]/(double)numfr);
+                fprintf(flp, "%12.6f ", static_cast<double>(norm*bin[k][j][i])/numfr);
             }
             fprintf(flp, "\n");
         }
@@ -442,19 +441,15 @@ int gmx_spatial(int argc, char *argv[])
     }
     gmx_ffclose(flp);
 
-    /* printf("x=%d to %d\n",minx,maxx); */
-    /* printf("y=%d to %d\n",miny,maxy); */
-    /* printf("z=%d to %d\n",minz,maxz); */
-
     if (bCALCDIV)
     {
-        printf("Counts per frame in all %ld cubes divided by %le\n", numcu, 1.0/norm);
-        printf("Normalized data: average %le, min %le, max %le\n", 1.0, norm*(double)min/(double)numfr, norm*(double)max/(double)numfr);
+        printf("Counts per frame in all %d cubes divided by %le\n", numcu, 1.0/norm);
+        printf("Normalized data: average %le, min %le, max %le\n", 1.0, minval*norm/numfr, maxval*norm/numfr);
     }
     else
     {
-        printf("grid.cube contains counts per frame in all %ld cubes\n", numcu);
-        printf("Raw data: average %le, min %le, max %le\n", 1.0/norm, (double)min/(double)numfr, (double)max/(double)numfr);
+        printf("grid.cube contains counts per frame in all %d cubes\n", numcu);
+        printf("Raw data: average %le, min %le, max %le\n", 1.0/norm, static_cast<double>(minval)/numfr, static_cast<double>(maxval)/numfr);
     }
 
     return 0;
similarity index 96%
rename from src/gromacs/gmxana/gmx_spol.c
rename to src/gromacs/gmxana/gmx_spol.cpp
index 8c6c25034026515bf520b741e5d36cbf7769e676..78fe38ee9febb9c69530176dfd86c43e1a21bad9 100644 (file)
@@ -36,6 +36,8 @@
  */
 #include "gmxpre.h"
 
+#include <cmath>
+
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
@@ -91,7 +93,7 @@ static void calc_com_pbc(int nrefat, t_topology *top, rvec x[], t_pbc *pbc,
                 rvec_add(xref, dx, xtest);
                 for (j = 0; (j < DIM); j++)
                 {
-                    if (fabs(xtest[j]-x[ai][j]) > tol)
+                    if (std::abs(xtest[j]-x[ai][j]) > tol)
                     {
                         /* Here we have used the wrong image for contributing to the COM */
                         xref[j] += mass*(xtest[j]-x[ai][j]);
@@ -148,11 +150,10 @@ int gmx_spol(int argc, char *argv[])
     t_topology  *top;
     t_inputrec  *ir;
     t_atom      *atom;
-    char         title[STRLEN];
     t_trxstatus *status;
     int          nrefat, natoms, nf, ntot;
     real         t;
-    rvec        *xtop, *x, xref, trial, dx = {0}, dip, dir;
+    rvec        *x, xref, trial, dx = {0}, dip, dir;
     matrix       box;
 
     FILE        *fp;
@@ -189,7 +190,7 @@ int gmx_spol(int argc, char *argv[])
     };
 
     output_env_t    oenv;
-    static gmx_bool bCom   = FALSE, bPBC = FALSE;
+    static gmx_bool bCom   = FALSE;
     static int      srefat = 1;
     static real     rmin   = 0.0, rmax = 0.32, refdip = 0, bw = 0.01;
     t_pargs         pa[]   = {
@@ -246,14 +247,14 @@ int gmx_spol(int argc, char *argv[])
     /* initialize reading trajectory:                         */
     natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
 
-    rcut  = 0.99*sqrt(max_cutoff2(ir->ePBC, box));
+    rcut  = 0.99*std::sqrt(max_cutoff2(ir->ePBC, box));
     if (rcut == 0)
     {
         rcut = 10*rmax;
     }
     rcut2 = sqr(rcut);
     invbw = 1/bw;
-    nbin  = (int)(rcut*invbw)+2;
+    nbin  = static_cast<int>(rcut*invbw)+2;
     snew(hist, nbin);
 
     rmin2 = sqr(rmin);
@@ -300,7 +301,7 @@ int gmx_spol(int argc, char *argv[])
             }
             if (rdx2 < rcut2)
             {
-                hist[(int)(sqrt(rdx2)*invbw)+1]++;
+                hist[static_cast<int>(std::sqrt(rdx2)*invbw)+1]++;
             }
             if (rdx2 >= rmin2 && rdx2 < rmax2)
             {
@@ -335,7 +336,7 @@ int gmx_spol(int argc, char *argv[])
 
                 svmul(ENM2DEBYE, dip, dip);
                 dip2   = norm2(dip);
-                sdip  += sqrt(dip2);
+                sdip  += std::sqrt(dip2);
                 sdip2 += dip2;
                 for (d = 0; d < DIM; d++)
                 {
@@ -358,7 +359,7 @@ int gmx_spol(int argc, char *argv[])
     close_trj(status);
 
     fprintf(stderr, "Average number of molecules within %g nm is %.1f\n",
-            rmax, (real)ntot/(real)nf);
+            rmax, static_cast<real>(ntot)/nf);
     if (ntot > 0)
     {
         sdip  /= ntot;
@@ -366,7 +367,7 @@ int gmx_spol(int argc, char *argv[])
         sinp  /= ntot;
         sdinp /= ntot;
         fprintf(stderr, "Average dipole:                               %f (D), std.dev. %f\n",
-                sdip, sqrt(sdip2-sqr(sdip)));
+                sdip, std::sqrt(sdip2-sqr(sdip)));
         fprintf(stderr, "Average radial component of the dipole:       %f (D)\n",
                 sinp);
         fprintf(stderr, "Average radial component of the polarization: %f (D)\n",
similarity index 96%
rename from src/gromacs/gmxana/gmx_tcaf.c
rename to src/gromacs/gmxana/gmx_tcaf.cpp
index eef238878a838552fa2f93d21d61225212536ad0..c139df52ed8f72004f8d0ed337995a33d6847b8f 100644 (file)
@@ -36,9 +36,9 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
@@ -59,6 +59,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #define NK  24
@@ -106,9 +107,9 @@ static void process_tcaf(int nframes, real dt, int nkc, real **tc, rvec *kfac,
     }
 
     ncorr = (nframes+1)/2;
-    if (ncorr > (int)(5*wt/dt+0.5))
+    if (ncorr > static_cast<int>(5*wt/dt+0.5))
     {
-        ncorr = (int)(5*wt/dt+0.5)+1;
+        ncorr = static_cast<int>(5*wt/dt+0.5)+1;
     }
     snew(tcaf, nk);
     for (k = 0; k < nk; k++)
@@ -126,7 +127,7 @@ static void process_tcaf(int nframes, real dt, int nkc, real **tc, rvec *kfac,
     snew(sig, ncorr);
     for (i = 0; i < ncorr; i++)
     {
-        sig[i] = exp(0.5*i*dt/wt);
+        sig[i] = std::exp(0.5*i*dt/wt);
     }
 
     low_do_autocorr(fn_tca, oenv, "Transverse Current Autocorrelation Functions",
@@ -306,7 +307,7 @@ int gmx_tcaf(int argc, char *argv[])
     int             ePBC;
     t_trxframe      fr;
     matrix          box;
-    gmx_bool        bTPS, bTop; /* ,bCubic; */
+    gmx_bool        bTop;
     int             gnx;
     atom_id        *index, *atndx = NULL, at;
     char           *grpname;
@@ -316,7 +317,7 @@ int gmx_tcaf(int argc, char *argv[])
     int             nframes, n_alloc, i, j, k, d;
     rvec            mv_mol, cm_mol, kfac[NK];
     int             nkc, nk, ntc;
-    real          **c1, **tc;
+    real          **tc;
     output_env_t    oenv;
 
 #define NHISTO 360
@@ -402,14 +403,9 @@ int gmx_tcaf(int argc, char *argv[])
     n_alloc = 0;
     nframes = 0;
     rho     = 0;
-    /* bCubic = TRUE; */
+
     do
     {
-        /*
-           bCubic = bCubic && !TRICLINIC(fr.box) &&
-           fabs(fr.box[XX][XX]-fr.box[YY][YY]) < 0.001*fr.box[XX][XX] &&
-           fabs(fr.box[XX][XX]-fr.box[ZZ][ZZ]) < 0.001*fr.box[XX][XX];
-         */
 
         if (nframes >= n_alloc)
         {
@@ -466,8 +462,8 @@ int gmx_tcaf(int argc, char *argv[])
             j = 0;
             for (k = 0; k < nk; k++)
             {
-                sx              = sin(iprod(kfac[k], cm_mol));
-                cx              = cos(iprod(kfac[k], cm_mol));
+                sx              = std::sin(iprod(kfac[k], cm_mol));
+                cx              = std::cos(iprod(kfac[k], cm_mol));
                 tc[j][nframes] += sx*iprod(v1[k], mv_mol);
                 j++;
                 tc[j][nframes] += cx*iprod(v1[k], mv_mol);
similarity index 98%
rename from src/gromacs/gmxana/gmx_traj.c
rename to src/gromacs/gmxana/gmx_traj.cpp
index 7560cec153d82974784b366b5e4c442401493380..3cb4ead8184e090cf246189271f36e5a62ad9e57 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -424,7 +426,6 @@ static void write_pdb_bfac(const char *fname, const char *xname,
     real        max, len2, scale;
     atom_id     maxi;
     int         i, m, onedim;
-    gmx_bool    bOne;
 
     if ((nfr_x == 0) || (nfr_v == 0))
     {
@@ -495,12 +496,12 @@ static void write_pdb_bfac(const char *fname, const char *xname,
             }
             else
             {
-                scale = 10.0/sqrt(max);
+                scale = 10.0/std::sqrt(max);
             }
         }
 
         printf("Maximum %s is %g on atom %d %s, res. %s %d\n",
-               title, sqrt(max), maxi+1, *(atoms->atomname[maxi]),
+               title, std::sqrt(max), maxi+1, *(atoms->atomname[maxi]),
                *(atoms->resinfo[atoms->atom[maxi].resind].name),
                atoms->resinfo[atoms->atom[maxi].resind].nr);
 
@@ -520,7 +521,7 @@ static void write_pdb_bfac(const char *fname, const char *xname,
                         len2 += sqr(sum[index[i]][m]);
                     }
                 }
-                atoms->pdbinfo[index[i]].bfac = sqrt(len2)*scale;
+                atoms->pdbinfo[index[i]].bfac = std::sqrt(len2)*scale;
             }
         }
         else
@@ -546,16 +547,16 @@ static void update_histo(int gnx, atom_id index[], rvec v[],
         for (i = 0; (i < gnx); i++)
         {
             vn    = norm(v[index[i]]);
-            vnmax = max(vn, vnmax);
+            vnmax = std::max(vn, vnmax);
         }
         vnmax  *= 2;
-        *nhisto = 1+(vnmax/binwidth);
+        *nhisto = static_cast<int>(1+(vnmax/binwidth));
         snew(*histo, *nhisto);
     }
     for (i = 0; (i < gnx); i++)
     {
         vn = norm(v[index[i]]);
-        in = vn/binwidth;
+        in = static_cast<int>(vn/binwidth);
         if (in >= *nhisto)
         {
             nnn = in+100;
@@ -667,7 +668,7 @@ int gmx_traj(int argc, char *argv[])
     t_trxstatus    *status;
     t_trxstatus    *status_out = NULL;
     gmx_rmpbc_t     gpbc       = NULL;
-    int             i, j, n;
+    int             i, j;
     int             nr_xfr, nr_vfr, nr_ffr;
     char          **grpname;
     int            *isize0, *isize;
@@ -676,7 +677,7 @@ int gmx_traj(int argc, char *argv[])
     t_block        *mols;
     gmx_bool        bTop, bOX, bOXT, bOV, bOF, bOB, bOT, bEKT, bEKR, bCV, bCF;
     gmx_bool        bDim[4], bDum[4], bVD;
-    char           *sffmt, sffmt6[1024];
+    char            sffmt[STRLEN], sffmt6[STRLEN];
     const char     *box_leg[6] = { "XX", "YY", "ZZ", "YX", "ZX", "ZY" };
     output_env_t    oenv;
 
@@ -736,11 +737,11 @@ int gmx_traj(int argc, char *argv[])
 
     if (bFP)
     {
-        sffmt = "\t" gmx_real_fullprecision_pfmt;
+        sprintf(sffmt, "\t%s", gmx_real_fullprecision_pfmt);
     }
     else
     {
-        sffmt = "\t%g";
+        sprintf(sffmt, "\t%%g");
     }
     sprintf(sffmt6, "%s%s%s%s%s%s", sffmt, sffmt, sffmt, sffmt, sffmt, sffmt);
 
similarity index 97%
rename from src/gromacs/gmxana/gmx_trjcat.c
rename to src/gromacs/gmxana/gmx_trjcat.cpp
index d6c2335650c06fa4d2aeee205abe5af5fc829234..1ddc5ca074d3c8460b112e0f3788e4ea328fa6ae 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -74,7 +76,6 @@ static void scan_trj_files(char **fnms, int nfiles, real *readtime,
     /* Check start time of all files */
     int          i, natoms = 0;
     t_trxstatus *status;
-    real         t;
     t_trxframe   fr;
     gmx_bool     ok;
 
@@ -214,7 +215,7 @@ static void edit_files(char **fnms, int nfiles, real *readtime, real *timestep,
                     gmx_fatal(FARGS, "Error reading user input" );
                 }
 
-                inputstring[strlen(inputstring)-1] = 0;
+                inputstring[std::strlen(inputstring)-1] = 0;
 
                 if (inputstring[0] == 'c' || inputstring[0] == 'C')
                 {
@@ -472,24 +473,22 @@ int gmx_trjcat(int argc, char *argv[])
           { &bCat }, "Do not discard double time frames" }
     };
 #define npargs asize(pa)
-    int          ftpin, i, frame, frame_out, step = 0, trjout = 0;
+    int          ftpin, i, frame, frame_out;
     t_trxstatus *status, *trxout = NULL;
-    rvec        *x, *v;
     real         t_corr;
     t_trxframe   fr, frout;
-    char       **fnms, **fnms_out, *in_file, *out_file;
+    char       **fnms, **fnms_out, *out_file;
     int          n_append;
     gmx_bool     bNewFile, bIndex, bWrite;
-    int          earliersteps, nfile_in, nfile_out, *cont_type, last_ok_step;
+    int          nfile_in, nfile_out, *cont_type;
     real        *readtime, *timest, *settime;
     real         first_time = 0, lasttime = NOTSET, last_ok_t = -1, timestep;
     real         last_frame_time, searchtime;
-    int          isize, j;
+    int          isize = 0, j;
     atom_id     *index = NULL, imax;
     char        *grpname;
     real       **val = NULL, *t = NULL, dt_remd;
     int          n, nset, ftpout = -1, prevEndStep = 0, filetype;
-    gmx_bool     bOK;
     gmx_off_t    fpos;
     output_env_t oenv;
     t_filenm     fnm[] =
@@ -521,7 +520,7 @@ int gmx_trjcat(int argc, char *argv[])
         imax = index[0];
         for (i = 1; i < isize; i++)
         {
-            imax = max(imax, index[i]);
+            imax = std::max(imax, index[i]);
         }
     }
     if (bDeMux)
@@ -590,7 +589,7 @@ int gmx_trjcat(int argc, char *argv[])
             snew(fnms_out, nset);
             for (i = 0; (i < nset); i++)
             {
-                snew(fnms_out[i], strlen(buf)+32);
+                snew(fnms_out[i], std::strlen(buf)+32);
                 sprintf(fnms_out[i], "%d_%s", i, buf);
             }
             sfree(buf);
@@ -616,7 +615,7 @@ int gmx_trjcat(int argc, char *argv[])
         n_append = -1;
         for (i = 0; ((i < nfile_in) && (n_append == -1)); i++)
         {
-            if (strcmp(fnms[i], out_file) == 0)
+            if (std::strcmp(fnms[i], out_file) == 0)
             {
                 n_append = i;
             }
@@ -631,7 +630,6 @@ int gmx_trjcat(int argc, char *argv[])
             gmx_fatal(FARGS, "Can only append to the first file which is %s (not %s)",
                       fnms[0], out_file);
         }
-        earliersteps = 0;
 
         /* Not checking input format, could be dangerous :-) */
         /* Not checking output format, equally dangerous :-) */
@@ -666,7 +664,7 @@ int gmx_trjcat(int argc, char *argv[])
             {
                 trxout = open_trx(out_file, "w");
             }
-            memset(&frout, 0, sizeof(frout));
+            std::memset(&frout, 0, sizeof(frout));
         }
         else
         {
@@ -731,7 +729,7 @@ int gmx_trjcat(int argc, char *argv[])
                     gmx_fatal(FARGS, "Error seeking to append position.");
                 }
                 read_next_frame(oenv, status, &fr);
-                if (fabs(searchtime - fr.time) > timest[0]*0.5)
+                if (std::abs(searchtime - fr.time) > timest[0]*0.5)
                 {
                     gmx_fatal(FARGS, "Error seeking: attempted to seek to %f but got %f.",
                               searchtime, fr.time);
@@ -908,8 +906,6 @@ int gmx_trjcat(int argc, char *argv[])
             while (read_next_frame(oenv, status, &fr));
 
             close_trj(status);
-
-            earliersteps += step;
         }
         if (trxout)
         {
similarity index 95%
rename from src/gromacs/gmxana/gmx_trjconv.c
rename to src/gromacs/gmxana/gmx_trjconv.cpp
index 213eae951b78a56321bea554305c0c56c84f3303..a5e9913ee663bffb0412fd101389c9cff780e5f6 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -85,7 +87,6 @@ static void calc_pbc_cluster(int ecenter, int nrefat, t_topology *top, int ePBC,
     gmx_bool *bMol, *bTmp;
     rvec     *m_com, *m_shift;
     t_pbc     pbc;
-    real     *com_dist2;
     int      *cluster;
     int      *added;
     int       ncluster, nadded;
@@ -94,7 +95,7 @@ static void calc_pbc_cluster(int ecenter, int nrefat, t_topology *top, int ePBC,
     calc_box_center(ecenter, box, box_center);
 
     /* Initiate the pbc structure */
-    memset(&pbc, 0, sizeof(pbc));
+    std::memset(&pbc, 0, sizeof(pbc));
     set_pbc(&pbc, ePBC, box);
 
     /* Convert atom index to molecular */
@@ -269,7 +270,7 @@ static void put_molecule_com_in_box(int unitcell_enum, int ecenter,
 {
     atom_id i, j;
     int     d;
-    rvec    com, new_com, shift, dx, box_center;
+    rvec    com, new_com, shift, box_center;
     real    m;
     double  mtot;
     t_pbc   pbc;
@@ -332,7 +333,7 @@ static void put_residue_com_in_box(int unitcell_enum, int ecenter,
                                    int natoms, t_atom atom[],
                                    int ePBC, matrix box, rvec x[])
 {
-    atom_id i, j, res_start, res_end, res_nat;
+    atom_id i, j, res_start, res_end;
     int     d, presnr;
     real    m;
     double  mtot;
@@ -350,7 +351,6 @@ static void put_residue_com_in_box(int unitcell_enum, int ecenter,
         {
             /* calculate final COM */
             res_end = i;
-            res_nat = res_end - res_start;
             svmul(1.0/mtot, com, com);
 
             /* check if COM is outside box */
@@ -445,7 +445,7 @@ static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr,
     char nbuf[128];
     int  nd = 0, fnr;
 
-    strcpy(out_file, base);
+    std::strcpy(out_file, base);
     fnr = file_nr;
     do
     {
@@ -456,11 +456,11 @@ static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr,
 
     if (nd < ndigit)
     {
-        strncat(out_file, "00000000000", ndigit-nd);
+        std::strncat(out_file, "00000000000", ndigit-nd);
     }
     sprintf(nbuf, "%d.", file_nr);
-    strcat(out_file, nbuf);
-    strcat(out_file, ext);
+    std::strcat(out_file, nbuf);
+    std::strcat(out_file, ext);
 }
 
 void check_trr(const char *fn)
@@ -522,7 +522,7 @@ void do_trunc(const char *fn, real t0)
             {
                 gmx_fatal(FARGS, "Error reading user input");
             }
-            if (strcmp(yesno, "YES") == 0)
+            if (std::strcmp(yesno, "YES") == 0)
             {
                 fprintf(stderr, "Once again, I'm gonna DO this...\n");
                 gmx_trr_close(in);
@@ -858,58 +858,57 @@ int gmx_trjconv(int argc, char *argv[])
     };
 #define NPA asize(pa)
 
-    FILE            *out    = NULL;
-    t_trxstatus     *trxout = NULL;
-    t_trxstatus     *trxin;
-    int              ftp, ftpin = 0, file_nr;
-    t_trxframe       fr, frout;
-    int              flags;
-    rvec            *xmem = NULL, *vmem = NULL, *fmem = NULL;
-    rvec            *xp   = NULL, x_shift, hbox, box_center, dx;
-    real             xtcpr, lambda, *w_rls = NULL;
-    int              m, i, d, frame, outframe, natoms, nout, ncent, nre, newstep = 0, model_nr;
+    FILE             *out    = NULL;
+    t_trxstatus      *trxout = NULL;
+    t_trxstatus      *trxin;
+    int               ftp, ftpin = 0, file_nr;
+    t_trxframe        fr, frout;
+    int               flags;
+    rvec             *xmem  = NULL, *vmem = NULL, *fmem = NULL;
+    rvec             *xp    = NULL, x_shift, hbox;
+    real             *w_rls = NULL;
+    int               m, i, d, frame, outframe, natoms, nout, ncent, newstep = 0, model_nr;
 #define SKIP 10
-    t_topology       top;
-    gmx_mtop_t      *mtop  = NULL;
-    gmx_conect       gc    = NULL;
-    int              ePBC  = -1;
-    t_atoms         *atoms = NULL, useatoms;
-    matrix           top_box;
-    atom_id         *index, *cindex;
-    char            *grpnm;
-    int             *frindex, nrfri;
-    char            *frname;
-    int              ifit, irms, my_clust = -1;
-    atom_id         *ind_fit, *ind_rms;
-    char            *gn_fit, *gn_rms;
-    t_cluster_ndx   *clust           = NULL;
-    t_trxstatus    **clust_status    = NULL;
-    int             *clust_status_id = NULL;
-    int              ntrxopen        = 0;
-    int             *nfwritten       = NULL;
-    int              ndrop           = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
-    double         **dropval;
-    real             tshift = 0, t0 = -1, dt = 0.001, prec;
-    gmx_bool         bFit, bFitXY, bPFit, bReset;
-    int              nfitdim;
-    gmx_rmpbc_t      gpbc = NULL;
-    gmx_bool         bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
-    gmx_bool         bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
-    gmx_bool         bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetPrec, bNeedPrec;
-    gmx_bool         bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
-    gmx_bool         bSubTraj = FALSE, bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
-    gmx_bool         bWriteFrame, bSplitHere;
-    const char      *top_file, *in_file, *out_file = NULL;
-    char             out_file2[256], *charpt;
-    char            *outf_base = NULL;
-    const char      *outf_ext  = NULL;
-    char             top_title[256], title[256], command[256], filemode[5];
-    int              xdr          = 0;
-    gmx_bool         bWarnCompact = FALSE;
-    const char      *warn;
-    output_env_t     oenv;
-
-    t_filenm         fnm[] = {
+    t_topology        top;
+    gmx_mtop_t       *mtop  = NULL;
+    gmx_conect        gc    = NULL;
+    int               ePBC  = -1;
+    t_atoms          *atoms = NULL, useatoms;
+    matrix            top_box;
+    atom_id          *index, *cindex;
+    char             *grpnm;
+    int              *frindex, nrfri;
+    char             *frname;
+    int               ifit, my_clust = -1;
+    atom_id          *ind_fit;
+    char             *gn_fit;
+    t_cluster_ndx    *clust           = NULL;
+    t_trxstatus     **clust_status    = NULL;
+    int              *clust_status_id = NULL;
+    int               ntrxopen        = 0;
+    int              *nfwritten       = NULL;
+    int               ndrop           = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
+    double          **dropval;
+    real              tshift = 0, t0 = -1, dt = 0.001, prec;
+    gmx_bool          bFit, bPFit, bReset;
+    int               nfitdim;
+    gmx_rmpbc_t       gpbc = NULL;
+    gmx_bool          bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
+    gmx_bool          bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
+    gmx_bool          bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetPrec, bNeedPrec;
+    gmx_bool          bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
+    gmx_bool          bSubTraj = FALSE, bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
+    gmx_bool          bWriteFrame, bSplitHere;
+    const char       *top_file, *in_file, *out_file = NULL;
+    char              out_file2[256], *charpt;
+    char             *outf_base = NULL;
+    const char       *outf_ext  = NULL;
+    char              top_title[256], title[256], filemode[5];
+    gmx_bool          bWarnCompact = FALSE;
+    const char       *warn;
+    output_env_t      oenv;
+
+    t_filenm          fnm[] = {
         { efTRX, "-f",   NULL,      ffREAD  },
         { efTRO, "-o",   NULL,      ffWRITE },
         { efTPS, NULL,   NULL,      ffOPTRD },
@@ -957,7 +956,6 @@ int gmx_trjconv(int argc, char *argv[])
         /* parse enum options */
         fit_enum      = nenum(fit);
         bFit          = (fit_enum == efFit || fit_enum == efFitXY);
-        bFitXY        = fit_enum == efFitXY;
         bReset        = (fit_enum == efReset || fit_enum == efResetXY);
         bPFit         = fit_enum == efPFit;
         pbc_enum      = nenum(pbc_opt);
@@ -996,7 +994,6 @@ int gmx_trjconv(int argc, char *argv[])
                         "         only has effect in combination with -pbc %s, %s or %s.\n"
                         "         Ingoring unitcell representation.\n\n",
                         unitcell_opt[0], pbc_opt[2], pbc_opt[3], pbc_opt[4]);
-                bSetUR = FALSE;
             }
         }
         if (bFit && bPBC)
@@ -1034,7 +1031,7 @@ int gmx_trjconv(int argc, char *argv[])
         }
         if (bSeparate || bSplit)
         {
-            outf_ext = strrchr(out_file, '.');
+            outf_ext = std::strrchr(out_file, '.');
             if (outf_ext == NULL)
             {
                 gmx_fatal(FARGS, "Output file name '%s' does not contain a '.'", out_file);
@@ -1111,7 +1108,7 @@ int gmx_trjconv(int argc, char *argv[])
              * the header in such a file is top_title t= ...
              * to prevent a double t=, remove it from top_title
              */
-            if ((charpt = strstr(top_title, " t= ")))
+            if ((charpt = std::strstr(top_title, " t= ")))
             {
                 charpt[0] = '\0';
             }
@@ -1258,7 +1255,7 @@ int gmx_trjconv(int argc, char *argv[])
                 {
                     useatoms.pdbinfo[i]  = atoms->pdbinfo[index[i]];
                 }
-                useatoms.nres        = max(useatoms.nres, useatoms.atom[i].resind+1);
+                useatoms.nres        = std::max(useatoms.nres, useatoms.atom[i].resind+1);
             }
             useatoms.nr = nout;
         }
@@ -1331,7 +1328,7 @@ int gmx_trjconv(int argc, char *argv[])
             }
 
             /* open output for writing */
-            strcpy(filemode, "w");
+            std::strcpy(filemode, "w");
             switch (ftp)
             {
                 case efTNG:
@@ -1558,8 +1555,8 @@ int gmx_trjconv(int argc, char *argv[])
                         drop0 = drop1;
                         drop1++;
                     }
-                    if (fabs(dropval[0][drop0] - fr.time)
-                        < fabs(dropval[0][drop1] - fr.time))
+                    if (std::abs(dropval[0][drop0] - fr.time)
+                        < std::abs(dropval[0][drop1] - fr.time))
                     {
                         dropuse = drop0;
                     }
@@ -1612,8 +1609,8 @@ int gmx_trjconv(int argc, char *argv[])
                         else
                         {
                             /* round() is not C89 compatible, so we do this:  */
-                            bDoIt = bRmod(floor(frout_time+0.5), floor(tzero+0.5),
-                                          floor(delta_t+0.5));
+                            bDoIt = bRmod(std::floor(frout_time+0.5), std::floor(tzero+0.5),
+                                          std::floor(delta_t+0.5));
                         }
                     }
 
@@ -1744,9 +1741,9 @@ int gmx_trjconv(int argc, char *argv[])
                         else
                         {
                             /* round() is not C89 compatible, so we do this: */
-                            bSplitHere = bSplit && bRmod(floor(frout.time+0.5),
-                                                         floor(tzero+0.5),
-                                                         floor(split_t+0.5));
+                            bSplitHere = bSplit && bRmod(std::floor(frout.time+0.5),
+                                                         std::floor(tzero+0.5),
+                                                         std::floor(split_t+0.5));
                         }
                         if (bSeparate || bSplitHere)
                         {
similarity index 98%
rename from src/gromacs/gmxana/gmx_trjorder.c
rename to src/gromacs/gmxana/gmx_trjorder.cpp
index 8b9e56ad9a7c0cf6721738911ed8338576216f13..70c8d7f4b644a0c3067775a3873dcd877e96a84a 100644 (file)
@@ -36,9 +36,9 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -260,7 +260,7 @@ int gmx_trjorder(int argc, char *argv[])
                         xsol[i][d] += mass*x[sa][d];
                     }
                 }
-                svmul(1/totmass, xsol[i], xsol[i]);
+                svmul(1.0/totmass, xsol[i], xsol[i]);
             }
         }
         else
@@ -318,7 +318,6 @@ int gmx_trjorder(int argc, char *argv[])
                 sr = ind_ref[j];
                 for (i = 0; (i < nwat); i++)
                 {
-                    sa = ind_sol[na*i];
                     pbc_dx(&pbc, x[sr], xsol[i], dx);
                     n2 = norm2(dx);
                     if (n2 < order[i].d2)
@@ -359,7 +358,7 @@ int gmx_trjorder(int argc, char *argv[])
                 {
                     for (j = 0; (j < na); j++)
                     {
-                        top.atoms.pdbinfo[order[i].i+j].bfac = sqrt(order[i].d2);
+                        top.atoms.pdbinfo[order[i].i+j].bfac = std::sqrt(order[i].d2);
                     }
                 }
             }
similarity index 95%
rename from src/gromacs/gmxana/gmx_tune_pme.c
rename to src/gromacs/gmxana/gmx_tune_pme.cpp
index 838b98e72b57d0c2c09e93493d483999df411c12..bee0529b0a2858852a142a0ae2461b73258727a5 100644 (file)
 
 #include "config.h"
 
-#include <stdlib.h>
-#include <time.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <algorithm>
 
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #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"
 
+#include "gmx_ana.h"
+
 /* Enum for situations that can occur during log file parsing, the
  * corresponding string entries can be found in do_the_tests() in
  * const char* ParseLog[] */
@@ -130,7 +137,7 @@ static int gmx_system_call(char *command)
 /* Check if string starts with substring */
 static gmx_bool str_starts(const char *string, const char *substring)
 {
-    return ( strncmp(string, substring, strlen(substring)) == 0);
+    return ( std::strncmp(string, substring, std::strlen(substring)) == 0);
 }
 
 
@@ -219,7 +226,7 @@ static int parse_logfile(const char *logfile, const char *errfile,
         ltrim(line);
 
         /* Check for TERM and INT signals from user: */
-        if (strstr(line, errSIG) != NULL)
+        if (std::strstr(line, errSIG) != NULL)
         {
             fclose(fp);
             cleandata(perfdata, test_nr);
@@ -229,9 +236,9 @@ static int parse_logfile(const char *logfile, const char *errfile,
         /* Check whether cycle resetting  worked */
         if (presteps > 0 && !bFoundResetStr)
         {
-            if (strstr(line, matchstrcr) != NULL)
+            if (std::strstr(line, matchstrcr) != NULL)
             {
-                sprintf(dumstring, "step %s", "%"GMX_SCNd64);
+                sprintf(dumstring, "step %s", "%" GMX_SCNd64);
                 sscanf(line, dumstring, &resetsteps);
                 bFoundResetStr = TRUE;
                 if (resetsteps == presteps+cpt_steps)
@@ -240,8 +247,8 @@ static int parse_logfile(const char *logfile, const char *errfile,
                 }
                 else
                 {
-                    sprintf(dumstring, "%"GMX_PRId64, resetsteps);
-                    sprintf(dumstring2, "%"GMX_PRId64, presteps+cpt_steps);
+                    sprintf(dumstring, "%" GMX_PRId64, resetsteps);
+                    sprintf(dumstring2, "%" GMX_PRId64, presteps+cpt_steps);
                     fprintf(stderr, "WARNING: Time step counters were reset at step %s,\n"
                             "         though they were supposed to be reset at step %s!\n",
                             dumstring, dumstring2);
@@ -306,7 +313,7 @@ static int parse_logfile(const char *logfile, const char *errfile,
                 /* Look for PME mesh/force balance (not necessarily present, though) */
                 else if (str_starts(line, matchstrbal))
                 {
-                    sscanf(&line[strlen(matchstrbal)], "%f", &(perfdata->PME_f_load[test_nr]));
+                    sscanf(&line[std::strlen(matchstrbal)], "%f", &(perfdata->PME_f_load[test_nr]));
                 }
                 /* Look for matchstring */
                 else if (str_starts(line, matchstring))
@@ -483,10 +490,10 @@ static gmx_bool analyze_data(
                     s = 0.0;
                     for (j = 0; j < nrepeats; j++)
                     {
-                        s += pow( pd->Gcycles[j] - pd->Gcycles_Av, 2 );
+                        s += std::pow( pd->Gcycles[j] - pd->Gcycles_Av, 2 );
                     }
                     s /= (nrepeats - 1);
-                    s  = sqrt(s);
+                    s  = std::sqrt(s);
 
                     fprintf(fp, "%4d %3d %4d%s %12.3f %12.3f %12.3f %s",
                             line, k, pd->nPMEnodes, strbuf, pd->Gcycles_Av, s,
@@ -595,7 +602,6 @@ static gmx_bool analyze_data(
 static void get_program_paths(gmx_bool bThreads, char *cmd_mpirun[], char *cmd_mdrun[])
 {
     char      *cp;
-    FILE      *fp;
     const char def_mpirun[]   = "mpirun";
     const char def_mdrun[]    = "mdrun";
 
@@ -659,12 +665,12 @@ static void check_mdrun_works(gmx_bool    bThreads,
     fprintf(stdout, "Making sure that mdrun can be executed. ");
     if (bThreads)
     {
-        snew(command, strlen(cmd_mdrun) + strlen(cmd_np) + strlen(filename) + 50);
+        snew(command, std::strlen(cmd_mdrun) + std::strlen(cmd_np) + std::strlen(filename) + 50);
         sprintf(command, "%s%s-version -maxh 0.001 1> %s 2>&1", cmd_mdrun, cmd_np, filename);
     }
     else
     {
-        snew(command, strlen(cmd_mpirun) + strlen(cmd_np) + strlen(cmd_mdrun) + strlen(filename) + 50);
+        snew(command, std::strlen(cmd_mpirun) + std::strlen(cmd_np) + std::strlen(cmd_mdrun) + std::strlen(filename) + 50);
         sprintf(command, "%s%s%s -version -maxh 0.001 1> %s 2>&1", cmd_mpirun, cmd_np, cmd_mdrun, filename);
     }
     fprintf(stdout, "Trying '%s' ... ", command);
@@ -751,13 +757,14 @@ typedef struct eligible_gpu_ids
 /* Handles the no-GPU case by emitting an empty string. */
 static char *make_gpu_id_command_line(int numRanks, int numPmeRanks, const t_eligible_gpu_ids *gpu_ids)
 {
-    char *command_line, *flag = "-gpu_id ", *ptr;
-    int   flag_length;
+    char       *command_line, *ptr;
+    const char *flag = "-gpu_id ";
+    int         flag_length;
 
     /* Reserve enough room for the option name, enough single-digit
        GPU ids (since that is currently all that is possible to use
        with mdrun), and a terminating NULL. */
-    flag_length = strlen(flag);
+    flag_length = std::strlen(flag);
     snew(command_line, flag_length + numRanks + 1);
     ptr = command_line;
 
@@ -770,7 +777,7 @@ static char *make_gpu_id_command_line(int numRanks, int numPmeRanks, const t_eli
         int   gpu_id, rank;
 
         /* Write the option flag */
-        strcpy(ptr, flag);
+        std::strcpy(ptr, flag);
         ptr += flag_length;
 
         numPpRanks                 = numRanks - numPmeRanks;
@@ -821,7 +828,7 @@ static void launch_simulation(
 
     /* Make enough space for the system call command,
      * (200 extra chars for -npme ... etc. options should suffice): */
-    snew(command, strlen(cmd_mpirun)+strlen(cmd_mdrun)+strlen(cmd_np)+strlen(args_for_mdrun)+strlen(simulation_tpr)+200);
+    snew(command, std::strlen(cmd_mpirun)+std::strlen(cmd_mdrun)+std::strlen(cmd_np)+std::strlen(args_for_mdrun)+std::strlen(simulation_tpr)+200);
 
     cmd_gpu_ids = make_gpu_id_command_line(nnodes, nPMEnodes, gpu_ids);
 
@@ -872,7 +879,7 @@ static void modify_PMEsettings(
     ir->init_step = init_step;
 
     /* Write the tpr file which will be launched */
-    sprintf(buf, "Writing optimized simulation file %s with nsteps=%s.\n", fn_sim_tpr, "%"GMX_PRId64);
+    sprintf(buf, "Writing optimized simulation file %s with nsteps=%s.\n", fn_sim_tpr, "%" GMX_PRId64);
     fprintf(stdout, buf, ir->nsteps);
     fflush(stdout);
     write_tpx_state(fn_sim_tpr, ir, &state, &mtop);
@@ -917,11 +924,11 @@ static void make_benchmark_tprs(
 
 
     sprintf(buf, "Making benchmark tpr file%s with %s time step%s",
-            *ntprs > 1 ? "s" : "", "%"GMX_PRId64, benchsteps > 1 ? "s" : "");
+            *ntprs > 1 ? "s" : "", "%" GMX_PRId64, benchsteps > 1 ? "s" : "");
     fprintf(stdout, buf, benchsteps);
     if (statesteps > 0)
     {
-        sprintf(buf, " (adding %s steps from checkpoint file)", "%"GMX_PRId64);
+        sprintf(buf, " (adding %s steps from checkpoint file)", "%" GMX_PRId64);
         fprintf(stdout, buf, statesteps);
         benchsteps += statesteps;
     }
@@ -976,7 +983,7 @@ static void make_benchmark_tprs(
         {
             box_size[d] += state.box[d][i]*state.box[d][i];
         }
-        box_size[d] = sqrt(box_size[d]);
+        box_size[d] = std::sqrt(box_size[d]);
     }
 
     if (ir->fourier_spacing > 0)
@@ -1003,7 +1010,7 @@ static void make_benchmark_tprs(
     else
     {
         /* Use the maximum observed spacing */
-        fourierspacing = max(max(info->fsx[0], info->fsy[0]), info->fsz[0]);
+        fourierspacing = std::max(std::max(info->fsx[0], info->fsy[0]), info->fsz[0]);
     }
 
     fprintf(stdout, "Calculating PME grid points on the basis of a fourierspacing of %f nm\n", fourierspacing);
@@ -1104,7 +1111,7 @@ static void make_benchmark_tprs(
                 else
                 {
                     /* For vdw cutoff, rvdw >= rlist */
-                    ir->rvdw = max(info->rvdw[0], ir->rlist);
+                    ir->rvdw = std::max(info->rvdw[0], ir->rlist);
                 }
             }
 
@@ -1126,11 +1133,11 @@ static void make_benchmark_tprs(
         info->fsz[j]       = fac*fourierspacing;
 
         /* Write the benchmark tpr file */
-        strncpy(fn_bench_tprs[j], fn_sim_tpr, strlen(fn_sim_tpr)-strlen(".tpr"));
+        std::strncpy(fn_bench_tprs[j], fn_sim_tpr, std::strlen(fn_sim_tpr)-std::strlen(".tpr"));
         sprintf(buf, "_bench%.2d.tpr", j);
-        strcat(fn_bench_tprs[j], buf);
+        std::strcat(fn_bench_tprs[j], buf);
         fprintf(stdout, "Writing benchmark tpr %s with nsteps=", fn_bench_tprs[j]);
-        fprintf(stdout, "%"GMX_PRId64, ir->nsteps);
+        fprintf(stdout, "%" GMX_PRId64, ir->nsteps);
         if (j > 0)
         {
             fprintf(stdout, ", scaling factor %f\n", fac);
@@ -1196,12 +1203,12 @@ static void cleanup(const t_filenm *fnm, int nfile, int k, int nnodes,
     for (i = 0; i < nfile; i++)
     {
         opt = (char *)fnm[i].opt;
-        if (strcmp(opt, "-p") == 0)
+        if (std::strcmp(opt, "-p") == 0)
         {
             /* do nothing; keep this file */
             ;
         }
-        else if (strcmp(opt, "-bg") == 0)
+        else if (std::strcmp(opt, "-bg") == 0)
         {
             /* Give the log file a nice name so one can later see which parameters were used */
             numstring[0] = '\0';
@@ -1217,7 +1224,7 @@ static void cleanup(const t_filenm *fnm, int nfile, int k, int nnodes,
                 rename(opt2fn("-bg", nfile, fnm), newfilename);
             }
         }
-        else if (strcmp(opt, "-err") == 0)
+        else if (std::strcmp(opt, "-err") == 0)
         {
             /* This file contains the output of stderr. We want to keep it in
              * cases where there have been problems. */
@@ -1244,7 +1251,7 @@ static void cleanup(const t_filenm *fnm, int nfile, int k, int nnodes,
             }
         }
         /* Delete the files which are created for each benchmark run: (options -b*) */
-        else if ( (0 == strncmp(opt, "-b", 2)) && (opt2bSet(opt, nfile, fnm) || !is_optional(&fnm[i])) )
+        else if ( (0 == std::strncmp(opt, "-b", 2)) && (opt2bSet(opt, nfile, fnm) || !is_optional(&fnm[i])) )
         {
             remove_if_exists(opt2fn(opt, nfile, fnm));
         }
@@ -1276,11 +1283,11 @@ static void make_npme_list(
 
 
     /* Do we need to check all possible values for -npme or is a reduced list enough? */
-    if (0 == strcmp(npmevalues_opt, "all") )
+    if (!std::strcmp(npmevalues_opt, "all") )
     {
         eNPME = eNpmeAll;
     }
-    else if (0 == strcmp(npmevalues_opt, "subset") )
+    else if (!std::strcmp(npmevalues_opt, "subset") )
     {
         eNPME = eNpmeSubset;
     }
@@ -1332,7 +1339,7 @@ static void make_npme_list(
             case eNpmeSubset:
                 /* For 2d PME we want a common largest factor of at least the cube
                  * root of the number of PP nodes */
-                min_factor = (int) pow(npp, 1.0/3.0);
+                min_factor = static_cast<int>(std::pow(npp, 1.0/3.0));
                 break;
             default:
                 gmx_fatal(FARGS, "Unknown option for eNPME in make_npme_list");
@@ -1384,11 +1391,9 @@ static void init_perfdata(t_perf *perfdata[], int ntprs, int datasets, int repea
 static void make_sure_it_runs(char *mdrun_cmd_line, int length, FILE *fp,
                               const t_filenm *fnm, int nfile)
 {
-    const char *fn = NULL;
     char       *command, *msg;
     int         ret;
 
-
     snew(command, length +  15);
     snew(msg, length + 500);
 
@@ -1462,7 +1467,6 @@ static void do_the_tests(
     char     buf[STRLEN];
     gmx_bool bResetProblem = FALSE;
     gmx_bool bFirst        = TRUE;
-    gmx_bool bUsingGpus    = 0 < gpu_ids->n;
 
     /* This string array corresponds to the eParselog enum type at the start
      * of this file */
@@ -1485,11 +1489,11 @@ static void do_the_tests(
 
     /* Allocate space for the mdrun command line. 100 extra characters should
        be more than enough for the -npme etcetera arguments */
-    cmdline_length =  strlen(cmd_mpirun)
-        + strlen(cmd_np)
-        + strlen(cmd_mdrun)
-        + strlen(cmd_args_bench)
-        + strlen(tpr_names[0]) + 100;
+    cmdline_length =  std::strlen(cmd_mpirun)
+        + std::strlen(cmd_np)
+        + std::strlen(cmd_mdrun)
+        + std::strlen(cmd_args_bench)
+        + std::strlen(tpr_names[0]) + 100;
     snew(command, cmdline_length);
     snew(cmd_stub, cmdline_length);
 
@@ -1696,7 +1700,7 @@ static void check_input(
     }
 
     /* Make sure that the checkpoint file is not overwritten during benchmarking */
-    if ( (0 == strcmp(opt2fn("-cpi", nfile, fnm), opt2fn("-bcpo", nfile, fnm)) ) && (sim_part > 1) )
+    if ( (0 == std::strcmp(opt2fn("-cpi", nfile, fnm), opt2fn("-bcpo", nfile, fnm)) ) && (sim_part > 1) )
     {
         gmx_fatal(FARGS, "Checkpoint input (-cpi) and benchmark checkpoint output (-bcpo) files must not be identical.\n"
                   "The checkpoint input file must not be overwritten during the benchmarks.\n");
@@ -1774,13 +1778,13 @@ static void check_input(
     /* If one of rmin, rmax is set, we need 2 tpr files at minimum */
     if (!gmx_within_tol(*rmax, rcoulomb, GMX_REAL_EPS) || !gmx_within_tol(*rmin, rcoulomb, GMX_REAL_EPS) )
     {
-        *ntprs = max(*ntprs, 2);
+        *ntprs = std::max(*ntprs, 2);
     }
 
     /* If both rmin, rmax are set, we need 3 tpr files at minimum */
     if (!gmx_within_tol(*rmax, rcoulomb, GMX_REAL_EPS) && !gmx_within_tol(*rmin, rcoulomb, GMX_REAL_EPS) )
     {
-        *ntprs = max(*ntprs, 3);
+        *ntprs = std::max(*ntprs, 3);
     }
 
     if (old != *ntprs)
@@ -1822,7 +1826,7 @@ static void check_input(
     if (bench_nsteps > 10000 || bench_nsteps < 100)
     {
         fprintf(stderr, "WARNING: steps=");
-        fprintf(stderr, "%"GMX_PRId64, bench_nsteps);
+        fprintf(stderr, "%" GMX_PRId64, bench_nsteps);
         fprintf(stderr, ". Are you sure you want to perform so %s steps for each benchmark?\n", (bench_nsteps < 100) ? "few" : "many");
     }
 
@@ -1854,7 +1858,7 @@ static void check_input(
         if ((npme_fixed > 0) && (5*npme_fixed < nnodes))
         {
             fprintf(stderr, "WARNING: Only %g percent of the ranks are assigned as PME-only ranks.\n",
-                    100.0*((real)npme_fixed / (real)nnodes));
+                    (100.0*npme_fixed)/nnodes);
         }
         if (opt2parg_bSet("-min", npargs, pa) || opt2parg_bSet("-max", npargs, pa))
         {
@@ -1868,15 +1872,15 @@ static void check_input(
 /* Returns TRUE when "opt" is needed at launch time */
 static gmx_bool is_launch_file(char *opt, gmx_bool bSet)
 {
-    if (0 == strncmp(opt, "-swap", 5))
+    if (0 == std::strncmp(opt, "-swap", 5))
     {
         return bSet;
     }
 
     /* Apart from the input .tpr and the output log files we need all options that
      * were set on the command line and that do not start with -b */
-    if    (0 == strncmp(opt, "-b", 2) || 0 == strncmp(opt, "-s", 2)
-           || 0 == strncmp(opt, "-err", 4) || 0 == strncmp(opt, "-p", 2) )
+    if    (0 == std::strncmp(opt, "-b", 2) || 0 == std::strncmp(opt, "-s", 2)
+           || 0 == std::strncmp(opt, "-err", 4) || 0 == std::strncmp(opt, "-p", 2) )
     {
         return FALSE;
     }
@@ -1890,12 +1894,12 @@ static gmx_bool is_bench_file(char *opt, gmx_bool bSet, gmx_bool bOptional, gmx_
 {
     /* Apart from the input .tpr, all files starting with "-b" are for
      * _b_enchmark files exclusively */
-    if (0 == strncmp(opt, "-s", 2))
+    if (0 == std::strncmp(opt, "-s", 2))
     {
         return FALSE;
     }
 
-    if (0 == strncmp(opt, "-b", 2) || 0 == strncmp(opt, "-s", 2))
+    if (0 == std::strncmp(opt, "-b", 2) || 0 == std::strncmp(opt, "-s", 2))
     {
         if (!bOptional || bSet)
         {
@@ -1928,14 +1932,14 @@ static gmx_bool is_bench_file(char *opt, gmx_bool bSet, gmx_bool bOptional, gmx_
 
 
 /* Adds 'buf' to 'str' */
-static void add_to_string(char **str, char *buf)
+static void add_to_string(char **str, const char *buf)
 {
     int len;
 
 
-    len = strlen(*str) + strlen(buf) + 1;
+    len = std::strlen(*str) + std::strlen(buf) + 1;
     srenew(*str, len);
-    strcat(*str, buf);
+    std::strcat(*str, buf);
 }
 
 
@@ -2002,7 +2006,7 @@ static void create_command_line_snippets(
         {
             /* All options starting with -b* need the 'b' removed,
              * therefore overwrite strbuf */
-            if (0 == strncmp(opt, "-b", 2))
+            if (0 == std::strncmp(opt, "-b", 2))
             {
                 sprintf(strbuf, "-%s %s ", &opt[2], name);
             }
@@ -2028,7 +2032,7 @@ static void setopt(const char *opt, int nfile, t_filenm fnm[])
 
     for (i = 0; (i < nfile); i++)
     {
-        if (strcmp(opt, fnm[i].opt) == 0)
+        if (std::strcmp(opt, fnm[i].opt) == 0)
         {
             fnm[i].flag |= ffSET;
         }
@@ -2103,7 +2107,7 @@ static void couple_files_options(int nfile, t_filenm fnm[])
     {
         opt    = (char *)fnm[i].opt;
         bSet   = ((fnm[i].flag & ffSET) != 0);
-        bBench = (0 == strncmp(opt, "-b", 2));
+        bBench = (0 == std::strncmp(opt, "-b", 2));
 
         /* Check optional files */
         /* If e.g. -eo is set, then -beo also needs to be set */
@@ -2222,7 +2226,6 @@ int gmx_tune_pme(int argc, char *argv[])
     t_inputinfo        *info;
     int                 i;
     FILE               *fp;
-    t_commrec          *cr;
 
     /* Print out how long the tuning took */
     double          seconds;
@@ -2373,6 +2376,9 @@ int gmx_tune_pme(int argc, char *argv[])
         return 0;
     }
 
+    // procstring[0] is used inside two different conditionals further down
+    GMX_RELEASE_ASSERT(procstring[0] != NULL, "Options inconsistency; procstring[0] is NULL");
+
     /* Store the remaining unparsed command line entries in a string which
      * is then attached to the mdrun command line */
     snew(ExtraArgs, 1);
@@ -2414,7 +2420,7 @@ int gmx_tune_pme(int argc, char *argv[])
     {
         /* This string will be used for MPI runs and will appear after the
          * mpirun command. */
-        if (strcmp(procstring[0], "none") != 0)
+        if (std::strcmp(procstring[0], "none") != 0)
         {
             sprintf(bbuf, " %s %d ", procstring[0], nnodes);
         }
@@ -2461,7 +2467,7 @@ int gmx_tune_pme(int argc, char *argv[])
      * the actual list of settings is build in do_the_tests(). */
     if ((nnodes > 2) && (npme_fixed < -1))
     {
-        if (0 == strcmp(npmevalues_opt[0], "auto"))
+        if (0 == std::strcmp(npmevalues_opt[0], "auto"))
         {
             /* Determine the npme range automatically based on the PME:PP load guess */
             if (guessPMEratio > 1.0)
@@ -2473,17 +2479,17 @@ int gmx_tune_pme(int argc, char *argv[])
             else
             {
                 /* PME : PP load is in the range 0..1, let's test around the guess */
-                guessPMEnodes = nnodes/(1.0 + 1.0/guessPMEratio);
-                minPMEnodes   = floor(0.7*guessPMEnodes);
-                maxPMEnodes   =  ceil(1.6*guessPMEnodes);
-                maxPMEnodes   = min(maxPMEnodes, nnodes/2);
+                guessPMEnodes = static_cast<int>(nnodes/(1.0 + 1.0/guessPMEratio));
+                minPMEnodes   = static_cast<int>(std::floor(0.7*guessPMEnodes));
+                maxPMEnodes   = static_cast<int>(std::ceil(1.6*guessPMEnodes));
+                maxPMEnodes   = std::min(maxPMEnodes, nnodes/2);
             }
         }
         else
         {
             /* Determine the npme range based on user input */
-            maxPMEnodes = floor(maxPMEfraction*nnodes);
-            minPMEnodes = max(floor(minPMEfraction*nnodes), 0);
+            maxPMEnodes = static_cast<int>(std::floor(maxPMEfraction*nnodes));
+            minPMEnodes = std::max(static_cast<int>(std::floor(minPMEfraction*nnodes)), 0);
             fprintf(stdout, "Will try runs with %d ", minPMEnodes);
             if (maxPMEnodes != minPMEnodes)
             {
@@ -2515,7 +2521,7 @@ int gmx_tune_pme(int argc, char *argv[])
     {
         fprintf(fp, "Number of ranks         : %d\n", nnodes);
         fprintf(fp, "The mpirun command is   : %s\n", cmd_mpirun);
-        if (strcmp(procstring[0], "none") != 0)
+        if (std::strcmp(procstring[0], "none") != 0)
         {
             fprintf(fp, "Passing # of ranks via  : %s\n", procstring[0]);
         }
@@ -2532,13 +2538,13 @@ int gmx_tune_pme(int argc, char *argv[])
     fprintf(fp, "The mdrun  command is   : %s\n", cmd_mdrun);
     fprintf(fp, "mdrun args benchmarks   : %s\n", cmd_args_bench);
     fprintf(fp, "Benchmark steps         : ");
-    fprintf(fp, "%"GMX_PRId64, bench_nsteps);
+    fprintf(fp, "%" GMX_PRId64, bench_nsteps);
     fprintf(fp, "\n");
     fprintf(fp, "dlb equilibration steps : %d\n", presteps);
     if (sim_part > 1)
     {
         fprintf(fp, "Checkpoint time step    : ");
-        fprintf(fp, "%"GMX_PRId64, cpt_steps);
+        fprintf(fp, "%" GMX_PRId64, cpt_steps);
         fprintf(fp, "\n");
     }
     fprintf(fp, "mdrun args at launchtime: %s\n", cmd_args_launch);
@@ -2547,10 +2553,10 @@ int gmx_tune_pme(int argc, char *argv[])
     {
         bOverwrite = TRUE;
         fprintf(stderr, "Note: Simulation input file %s will have ", opt2fn("-so", NFILE, fnm));
-        fprintf(stderr, "%"GMX_PRId64, new_sim_nsteps+cpt_steps);
+        fprintf(stderr, "%" GMX_PRId64, new_sim_nsteps+cpt_steps);
         fprintf(stderr, " steps.\n");
         fprintf(fp, "Simulation steps        : ");
-        fprintf(fp, "%"GMX_PRId64, new_sim_nsteps);
+        fprintf(fp, "%" GMX_PRId64, new_sim_nsteps);
         fprintf(fp, "\n");
     }
     if (repeats > 1)
@@ -2600,6 +2606,7 @@ int gmx_tune_pme(int argc, char *argv[])
     snew(perfdata, ntprs);
     if (bBenchmark)
     {
+        GMX_RELEASE_ASSERT(npmevalues_opt[0] != NULL, "Options inconsistency; npmevalues_opt[0] is NULL");
         do_the_tests(fp, tpr_names, maxPMEnodes, minPMEnodes, npme_fixed, npmevalues_opt[0], perfdata, &pmeentries,
                      repeats, nnodes, ntprs, bThreads, cmd_mpirun, cmd_np, cmd_mdrun,
                      cmd_args_bench, fnm, NFILE, presteps, cpt_steps, bCheck, gpu_ids);
similarity index 93%
rename from src/gromacs/gmxana/gmx_vanhove.c
rename to src/gromacs/gmxana/gmx_vanhove.cpp
index 8d046f4b6afa12190776315795c3abc443b5018a..340491acaeda9ae17f2d40c8593be426f3370010 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -56,6 +55,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 
@@ -135,7 +135,7 @@ int gmx_vanhove(int argc, char *argv[])
     int          ePBC;
     matrix       boxtop, box, *sbox, avbox, corr;
     rvec        *xtop, *x, **sx;
-    int          isize, nalloc, nallocn, natom;
+    int          isize, nalloc, nallocn;
     t_trxstatus *status;
     atom_id     *index;
     char        *grpname;
@@ -189,7 +189,7 @@ int gmx_vanhove(int argc, char *argv[])
     sx     = NULL;
     clear_mat(avbox);
 
-    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);
     nfr   = 0;
     do
     {
@@ -200,7 +200,8 @@ int gmx_vanhove(int argc, char *argv[])
             srenew(sbox, nalloc);
             srenew(sx, nalloc);
         }
-        assert(time != NULL); assert(sbox != NULL);
+        GMX_RELEASE_ASSERT(time != NULL, "Memory allocation failure; time array is NULL");
+        GMX_RELEASE_ASSERT(sbox != NULL, "Memory allocation failure; sbox array is NULL");
 
         time[nfr] = t;
         copy_mat(box, sbox[nfr]);
@@ -226,7 +227,7 @@ int gmx_vanhove(int argc, char *argv[])
 
     dt = (time[nfr-1] - time[0])/(nfr - 1);
     /* Some ugly rounding to get nice nice times in the output */
-    dt = (int)(10000.0*dt + 0.5)/10000.0;
+    dt = static_cast<int>((10000.0*dt + 0.5)/10000.0);
 
     invbin = 1.0/rbin;
 
@@ -237,7 +238,7 @@ int gmx_vanhove(int argc, char *argv[])
             fmmax = nfr - 1;
         }
         snew(mcount, fmmax);
-        nbin = (int)(rmax*invbin + 0.5);
+        nbin = static_cast<int>(rmax*invbin + 0.5);
         if (sbin == 0)
         {
             mat_nx = fmmax + 1;
@@ -245,7 +246,7 @@ int gmx_vanhove(int argc, char *argv[])
         else
         {
             invsbin = 1.0/sbin;
-            mat_nx  = sqrt(fmmax*dt)*invsbin + 1;
+            mat_nx  = static_cast<int>(std::sqrt(fmmax*dt)*invsbin + 1);
         }
         snew(mat, mat_nx);
         for (f = 0; f < mat_nx; f++)
@@ -327,14 +328,14 @@ int gmx_vanhove(int argc, char *argv[])
                 }
                 else
                 {
-                    mbin = (int)(sqrt(fbin*dt)*invsbin + 0.5);
+                    mbin = static_cast<int>(std::sqrt(fbin*dt)*invsbin + 0.5);
                 }
                 for (i = 0; i < isize; i++)
                 {
                     d2 = distance2(sx[f][i], sx[ff][i]);
                     if (mbin < mat_nx && d2 < rmax2)
                     {
-                        bin = (int)(sqrt(d2)*invbin + 0.5);
+                        bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
                         if (bin < nbin)
                         {
                             mat[mbin][bin] += 1;
@@ -365,7 +366,7 @@ int gmx_vanhove(int argc, char *argv[])
                     for (i = 0; i < isize; i++)
                     {
                         d2  = distance2(sx[f][i], sx[ff][i]);
-                        bin = (int)(sqrt(d2)*invbin + 0.5);
+                        bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
                         if (bin >= nalloc)
                         {
                             nallocn = 10*(bin/10) + 11;
@@ -452,8 +453,7 @@ int gmx_vanhove(int argc, char *argv[])
             fprintf(fp, "%g", i*rbin);
             for (fbin = 0; fbin < nr; fbin++)
             {
-                fprintf(fp, " %g",
-                        (real)pr[fbin][i]/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1)));
+                fprintf(fp, " %g", static_cast<real>(pr[fbin][i])/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0)));
             }
             fprintf(fp, "\n");
         }
@@ -470,7 +470,7 @@ int gmx_vanhove(int argc, char *argv[])
         }
         for (f = 0; f <= ftmax; f++)
         {
-            fprintf(fp, "%g %g\n", f*dt, (real)pt[f]/(tcount[f]*isize));
+            fprintf(fp, "%g %g\n", f*dt, static_cast<real>(pt[f])/(tcount[f]*isize));
         }
         xvgrclose(fp);
     }
similarity index 99%
rename from src/gromacs/gmxana/gmx_velacc.c
rename to src/gromacs/gmxana/gmx_velacc.cpp
index 9af61df1e092ea88679a55416edd732ec40903c1..16c24304d769191598825d47d5e37a1ff7ea53c1 100644 (file)
@@ -36,9 +36,9 @@
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
similarity index 93%
rename from src/gromacs/gmxana/gmx_wheel.c
rename to src/gromacs/gmxana/gmx_wheel.cpp
index 552c8d62db42b2e1c3a1cf5df47092af4cf70e7e..1c0bbad601231083e30c85db862500db12f4a68e 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/strdb.h"
@@ -94,7 +96,7 @@ void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, char *tit
     for (i = 0; (i < nres); i++)
     {
         snew(rnms[i], 256);
-        sl   = strlen(resnm[i]);
+        sl   = std::strlen(resnm[i]);
         sign = resnm[i][sl-1];
         if ((sign == '+') || (sign == '-'))
         {
@@ -103,12 +105,12 @@ void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, char *tit
         sprintf(rnms[i], "%s-%d", resnm[i], i+r0);
         if ((sign == '+') || (sign == '-'))
         {
-            sl            = strlen(rnms[i]);
+            sl            = std::strlen(rnms[i]);
             rnms[i][sl]   = sign;
             rnms[i][sl+1] = '\0';
         }
 
-        slen = max(slen, (int)strlen(rnms[i]));
+        slen = std::max(slen, static_cast<int>(std::strlen(rnms[i])));
     }
     ring  = (2+slen)*fontwidth;
     outer = inner+ring;
@@ -168,10 +170,10 @@ void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *title)
     slen  = 0;
     for (i = 0; (i < nres); i++)
     {
-        slen = max(slen, (int)strlen(resnm[i]));
+        slen = std::max(slen, static_cast<int>(strlen(resnm[i])));
     }
     fprintf(stderr, "slen = %d\n", slen);
-    ring  = (slen)*fontwidth;
+    ring  = slen*fontwidth;
     outer = inner+ring;
     box   = (1+(nres / (2*angle)))*outer;
 
@@ -252,22 +254,22 @@ int gmx_wheel(int argc, char *argv[])
 
     for (i = 1; (i < argc); i++)
     {
-        if (strcmp(argv[i], "-r0") == 0)
+        if (std::strcmp(argv[i], "-r0") == 0)
         {
-            r0 = strtol(argv[++i], NULL, 10);
+            r0 = std::strtol(argv[++i], NULL, 10);
             fprintf(stderr, "First residue is %d\n", r0);
         }
-        else if (strcmp(argv[i], "-rot0") == 0)
+        else if (std::strcmp(argv[i], "-rot0") == 0)
         {
             rot0 = strtod(argv[++i], NULL);
             fprintf(stderr, "Initial rotation is %g\n", rot0);
         }
-        else if (strcmp(argv[i], "-T") == 0)
+        else if (std::strcmp(argv[i], "-T") == 0)
         {
             title = gmx_strdup(argv[++i]);
             fprintf(stderr, "Title will be '%s'\n", title);
         }
-        else if (strcmp(argv[i], "-nn") == 0)
+        else if (std::strcmp(argv[i], "-nn") == 0)
         {
             bNum = FALSE;
             fprintf(stderr, "No residue numbers\n");
similarity index 94%
rename from src/gromacs/gmxana/gmx_xpm2ps.c
rename to src/gromacs/gmxana/gmx_xpm2ps.cpp
index 83f5523ed7a4d93194ab5b028daad3cbb7944caf..06c2677a89503a4c5a3646b0ceb8fc554edca072 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/matio.h"
@@ -51,6 +54,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"
 
 #define FUDGE 1.2
@@ -200,7 +204,7 @@ gmx_bool diff_maps(int nmap1, t_mapping *map1, int nmap2, t_mapping *map2)
             {
                 bDiff = TRUE;
             }
-            if (strcmp(map1[i].desc, map2[i].desc) != 0)
+            if (std::strcmp(map1[i].desc, map2[i].desc) != 0)
             {
                 bDiff = TRUE;
             }
@@ -232,7 +236,7 @@ void leg_discrete(t_psdata ps, real x0, real y0, char *label,
     ps_rgb(ps, BLACK);
     ps_strfont(ps, font, fontsize);
     yhh = y0+fontsize+3*DDD;
-    if ((int)strlen(label) > 0)
+    if (std::strlen(label) > 0)
     {
         ps_ctext(ps, x0, yhh, label, eXLeft);
     }
@@ -264,12 +268,14 @@ void leg_continuous(t_psdata ps, real x0, real x, real y0, char *label,
     {
         x = 8*fontsize;
     }
-    boxxh = (real)x/(real)(nmap-mapoffset);
+    boxxh = x/(nmap-mapoffset);
     if (boxxh > fontsize)
     {
         boxxh = fontsize;
     }
 
+    GMX_RELEASE_ASSERT(map != NULL, "NULL map array provided to leg_continuous()");
+
     /* LANDSCAPE */
     xx0 = x0-((nmap-mapoffset)*boxxh)/2.0;
 
@@ -284,7 +290,7 @@ void leg_continuous(t_psdata ps, real x0, real x, real y0, char *label,
 
     yhh = y0+boxyh+3*DDD;
     ps_ctext(ps, xx0+boxxh/2, yhh, map[0].desc, eXCenter);
-    if ((int)strlen(label) > 0)
+    if (std::strlen(label) > 0)
     {
         ps_ctext(ps, x0, yhh, label, eXCenter);
     }
@@ -353,14 +359,15 @@ static void draw_boxes(t_psdata ps, real x0, real y0, real w,
     real     xxx;
     char   **xtick, **ytick;
     real     xx, yy, dy, xx00, yy00, offset_x, offset_y;
-    int      i, j, x, y, ntx, nty, strlength;
+    int      i, j, x, y, ntx, nty;
+    size_t   strlength;
 
     /* Only necessary when there will be no y-labels */
     strlength = 0;
 
     /* Draw the box */
     ps_rgb(ps, BLACK);
-    ps_linewidth(ps, psr->boxlinewidth);
+    ps_linewidth(ps, static_cast<int>(psr->boxlinewidth));
     yy00 = y0;
     for (i = 0; (i < nmat); i++)
     {
@@ -370,7 +377,7 @@ static void draw_boxes(t_psdata ps, real x0, real y0, real w,
     }
 
     /* Draw the ticks on the axes */
-    ps_linewidth(ps, psr->ticklinewidth);
+    ps_linewidth(ps, static_cast<int>(psr->ticklinewidth));
     xx00 = x0-1;
     yy00 = y0-1;
     for (i = 0; (i < nmat); i++)
@@ -446,7 +453,7 @@ static void draw_boxes(t_psdata ps, real x0, real y0, real w,
                 (psr->Y.first && (y == 0)))
             {
                 /* Major ticks */
-                strlength = max(strlength, (int)strlen(ytick[y]));
+                strlength = std::max(strlength, std::strlen(ytick[y]));
                 ps_line (ps, xx00, yy, xx00-psr->Y.majorticklen, yy);
                 ps_ctext(ps, xx00-psr->Y.majorticklen-DDD,
                          yy-psr->Y.tickfontsize/3.0, ytick[y], eXRight);
@@ -509,7 +516,7 @@ static void draw_zerolines(t_psdata out, real x0, real y0, real w,
 
     xx00 = x0-1.5;
     yy00 = y0-1.5;
-    ps_linewidth(out, psr->zerolinewidth);
+    ps_linewidth(out, static_cast<int>(psr->zerolinewidth));
     for (i = 0; (i < nmat); i++)
     {
         dy = box_height(&(mat[i]), psr);
@@ -522,8 +529,8 @@ static void draw_zerolines(t_psdata out, real x0, real y0, real w,
                 xx = xx00+(x+0.7)*psr->xboxsize;
                 /* draw lines whenever tick label almost zero (e.g. next trajectory) */
                 if (x != 0 && x < mat[i].nx-1 &&
-                    fabs(mat[i].axis_x[x]) <
-                    0.1*fabs(mat[i].axis_x[x+1]-mat[i].axis_x[x]) )
+                    std::abs(mat[i].axis_x[x]) <
+                    0.1*std::abs(mat[i].axis_x[x+1]-mat[i].axis_x[x]) )
                 {
                     ps_line (out, xx, yy00, xx, yy00+dy+2);
                 }
@@ -537,8 +544,8 @@ static void draw_zerolines(t_psdata out, real x0, real y0, real w,
                 yy = yy00+(y+0.7)*psr->yboxsize;
                 /* draw lines whenever tick label almost zero (e.g. next trajectory) */
                 if (y != 0 && y < mat[i].ny-1 &&
-                    fabs(mat[i].axis_y[y]) <
-                    0.1*fabs(mat[i].axis_y[y+1]-mat[i].axis_y[y]) )
+                    std::abs(mat[i].axis_y[y]) <
+                    0.1*std::abs(mat[i].axis_y[y+1]-mat[i].axis_y[y]) )
                 {
                     ps_line (out, xx00, yy, xx00+w+2, yy);
                 }
@@ -561,9 +568,9 @@ static void box_dim(int nmat, t_matrix mat[], t_matrix *mat2, t_psrec *psr,
     ww = 0;
     for (i = 0; (i < nmat); i++)
     {
-        ww       = max(ww, mat[i].nx*psr->xboxsize);
+        ww       = std::max(ww, mat[i].nx*psr->xboxsize);
         hh      += box_height(&(mat[i]), psr);
-        maxytick = max(maxytick, mat[i].nx);
+        maxytick = std::max(maxytick, mat[i].nx);
     }
     if (bFrame)
     {
@@ -574,7 +581,7 @@ static void box_dim(int nmat, t_matrix mat[], t_matrix *mat2, t_psrec *psr,
         if (psr->Y.major > 0)
         {
             dww += psr->Y.majorticklen + DDD +
-                psr->Y.tickfontsize*(log(maxytick)/log(10.0));
+                psr->Y.tickfontsize*(std::log(static_cast<real>(maxytick))/std::log(10.0));
         }
         else if (psr->Y.minor > 0)
         {
@@ -626,7 +633,7 @@ int add_maps(t_mapping **newmap,
     int         nmap, j, k;
     t_mapping  *map;
 
-    nsymbols = strlen(mapper);
+    nsymbols = std::strlen(mapper);
     nmap     = nmap1+nmap2;
     if (nmap > nsymbols*nsymbols)
     {
@@ -669,8 +676,7 @@ void xpm_mat(const char *outf, int nmat, t_matrix *mat, t_matrix *mat2,
              gmx_bool bDiag, gmx_bool bFirstDiag)
 {
     FILE      *out;
-    char       buf[100];
-    int        i, j, k, x, y, col;
+    int        i, x, y, col;
     int        nmap;
     t_mapping *map = NULL;
 
@@ -710,11 +716,11 @@ void xpm_mat(const char *outf, int nmat, t_matrix *mat, t_matrix *mat2,
             sfree(mat[i].map);
             mat[i].nmap = nmap;
             mat[i].map  = map;
-            if (strcmp(mat[i].title, mat2[i].title) != 0)
+            if (std::strcmp(mat[i].title, mat2[i].title) != 0)
             {
                 sprintf(mat[i].title+strlen(mat[i].title), " / %s", mat2[i].title);
             }
-            if (strcmp(mat[i].legend, mat2[i].legend) != 0)
+            if (std::strcmp(mat[i].legend, mat2[i].legend) != 0)
             {
                 sprintf(mat[i].legend+strlen(mat[i].legend), " / %s", mat2[i].legend);
             }
@@ -728,22 +734,22 @@ static void tick_spacing(int n, real axis[], real offset, char axisnm,
                          real *major, real *minor)
 {
     real     space;
-    gmx_bool bTryAgain, bFive;
+    gmx_bool bTryAgain;
     int      i, j, t, f = 0, ten;
 #define NFACT 4
     real     major_fact[NFACT] = {5, 4, 2, 1};
     real     minor_fact[NFACT] = {5, 4, 4, 5};
 
     /* start with interval between 10 matrix points: */
-    space = max(10*axis[1]-axis[0], axis[min(10, n-1)]-axis[0]);
+    space = std::max(10*axis[1]-axis[0], axis[std::min(10, n-1)]-axis[0]);
     /* get power of 10 */
-    ten       = (int)ceil(log(space)/log(10))-1;
+    ten       = static_cast<int>(std::ceil(std::log(space)/std::log(10.0))-1);
     bTryAgain = TRUE;
     for (t = ten+2; t > ten-3 && bTryAgain; t--)
     {
         for (f = 0; f < NFACT && bTryAgain; f++)
         {
-            space = pow(10, t) * major_fact[f];
+            space = std::pow(static_cast<real>(10.0), static_cast<real>(t)) * major_fact[f];
             /* count how many ticks we would get: */
             i = 0;
             for (j = 0; j < n; j++)
@@ -754,17 +760,17 @@ static void tick_spacing(int n, real axis[], real offset, char axisnm,
                 }
             }
             /* do we have a reasonable number of ticks ? */
-            bTryAgain = (i > min(10, n-1)) || (i < 5);
+            bTryAgain = (i > std::min(10, n-1)) || (i < 5);
         }
     }
     if (bTryAgain)
     {
-        space = max(10*axis[1]-axis[0], axis[min(10, n-1)]-axis[0]);
+        space = std::max(10*axis[1]-axis[0], axis[std::min(10, n-1)]-axis[0]);
         fprintf(stderr, "Auto tick spacing failed for %c-axis, guessing %g\n",
                 axisnm, space);
     }
     *major = space;
-    *minor = space / minor_fact[f-1];
+    *minor = space / minor_fact[(f > 0) ? f-1 : 0];
     fprintf(stderr, "Auto tick spacing for %c-axis: major %g, minor %g\n",
             axisnm, *major, *minor);
 }
@@ -780,7 +786,7 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
     t_psdata      out;
     t_psrec       psrec, *psr;
     int           W, H;
-    int           i, j, x, y, col, leg = 0;
+    int           i, x, y, col, leg = 0;
     real          x0, y0, xx;
     real          w, h, dw, dh;
     int           nmap1 = 0, nmap2 = 0, leg_nmap;
@@ -868,7 +874,7 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
     }
     if ( (mat[0].legend[0] == 0) && psr->legend)
     {
-        strcpy(mat[0].legend, psr->leglabel);
+        std::strcpy(mat[0].legend, psr->leglabel);
     }
 
     bTitle          = bTitle     && mat[nmat-1].title[0];
@@ -881,21 +887,21 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
     box_dim(nmat, mat, mat2, psr, elegend, bFrame, &w, &h, &dw, &dh);
 
     /* Set up bounding box */
-    W = w+dw;
-    H = h+dh;
+    W = static_cast<int>(w+dw);
+    H = static_cast<int>(h+dh);
 
     /* Start box at */
     x0 = dw;
     y0 = dh;
-    x  = W+psr->xoffs;
-    y  = H+psr->yoffs;
+    x  = static_cast<int>(W+psr->xoffs);
+    y  = static_cast<int>(H+psr->yoffs);
     if (bFrame)
     {
         x += 5*DDD;
         y += 4*DDD;
     }
     out = ps_open(outf, 0, 0, x, y);
-    ps_linewidth(out, psr->linewidth);
+    ps_linewidth(out, static_cast<int>(psr->linewidth));
     ps_init_rgb_box(out, psr->xboxsize, psr->yboxsize);
     ps_init_rgb_nbox(out, psr->xboxsize, psr->yboxsize);
     ps_translate(out, psr->xoffs, psr->yoffs);
@@ -913,9 +919,9 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
             /* Print title, if any */
             ps_rgb(out, BLACK);
             ps_strfont(out, psr->titfont, psr->titfontsize);
-            if (!mat2 || (strcmp(mat[i].title, mat2[i].title) == 0))
+            if (!mat2 || (std::strcmp(mat[i].title, mat2[i].title) == 0))
             {
-                strcpy(buf, mat[i].title);
+                std::strcpy(buf, mat[i].title);
             }
             else
             {
@@ -993,7 +999,7 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
     if (elegend != elNone)
     {
         ps_comment(out, "Now it's legend time!");
-        ps_linewidth(out, psr->linewidth);
+        ps_linewidth(out, static_cast<int>(psr->linewidth));
         if (mat2 == NULL || elegend != elSecond)
         {
             bDiscrete = mat[0].bDiscrete;
@@ -1134,7 +1140,7 @@ void zero_lines(int nmat, t_matrix *mat, t_matrix *mat2)
             }
             for (x = 0; x < mats[i].nx-1; x++)
             {
-                if (fabs(mats[i].axis_x[x+1]) < 1e-5)
+                if (std::abs(mats[i].axis_x[x+1]) < 1e-5)
                 {
                     for (y = 0; y < mats[i].ny; y++)
                     {
@@ -1144,7 +1150,7 @@ void zero_lines(int nmat, t_matrix *mat, t_matrix *mat2)
             }
             for (y = 0; y < mats[i].ny-1; y++)
             {
-                if (fabs(mats[i].axis_y[y+1]) < 1e-5)
+                if (std::abs(mats[i].axis_y[y+1]) < 1e-5)
                 {
                     for (x = 0; x < mats[i].nx; x++)
                     {
@@ -1161,7 +1167,6 @@ void write_combined_matrix(int ecombine, const char *fn,
                            real *cmin, real *cmax)
 {
     int        i, j, k, nlevels;
-    t_mapping *map = NULL;
     FILE      *out;
     real     **rmat1, **rmat2;
     real       rhi, rlo;
@@ -1198,8 +1203,8 @@ void write_combined_matrix(int ecombine, const char *fn,
                     default:
                         gmx_fatal(FARGS, "No such combination rule %d for matrices", ecombine);
                 }
-                rlo = min(rlo, rmat1[i][j]);
-                rhi = max(rhi, rmat1[i][j]);
+                rlo = std::min(rlo, rmat1[i][j]);
+                rhi = std::max(rhi, rmat1[i][j]);
             }
         }
         if (cmin)
@@ -1210,7 +1215,7 @@ void write_combined_matrix(int ecombine, const char *fn,
         {
             rhi = *cmax;
         }
-        nlevels = max(mat1[k].nmap, mat2[k].nmap);
+        nlevels = std::max(mat1[k].nmap, mat2[k].nmap);
         if (rhi == rlo)
         {
             fprintf(stderr,
@@ -1339,25 +1344,25 @@ void rainbow_map(gmx_bool bBlue, int nmap, t_mapping map[])
         if (c <= 0.25) /* 0-0.25 */
         {
             r = 0;
-            g = pow(4*c, 0.666);
+            g = std::pow(4.0*c, 2.0/3.0);
             b = 1;
         }
         else if (c <= 0.5) /* 0.25-0.5 */
         {
             r = 0;
             g = 1;
-            b = pow(2-4*c, 0.666);
+            b = std::pow(2.0-4.0*c, 2.0/3.0);
         }
         else if (c <= 0.75) /* 0.5-0.75 */
         {
-            r = pow(4*c-2, 0.666);
+            r = std::pow(4.0*c-2.0, 2.0/3.0);
             g = 1;
             b = 0;
         }
         else /* 0.75-1 */
         {
             r = 1;
-            g = pow(4-4*c, 0.666);
+            g = std::pow(4.0-4.0*c, 2.0/3.0);
             b = 0;
         }
         map[i].rgb.r = r;
@@ -1426,7 +1431,7 @@ int gmx_xpm2ps(int argc, char *argv[])
     int             i, nmat, nmat2, etitle, elegend, ediag, erainbow, ecombine;
     t_matrix       *mat = NULL, *mat2 = NULL;
     gmx_bool        bTitle, bTitleOnce, bDiag, bFirstDiag, bGrad;
-    static gmx_bool bFrame = TRUE, bZeroLine = FALSE, bYonce = FALSE, bAdd = FALSE;
+    static gmx_bool bFrame = TRUE, bZeroLine = FALSE, bYonce = FALSE;
     static real     size   = 400, boxx = 0, boxy = 0, cmin = 0, cmax = 0;
     static rvec     grad   = {0, 0, 0};
     enum                    {
@@ -1547,7 +1552,7 @@ int gmx_xpm2ps(int argc, char *argv[])
         if (nmat != nmat2)
         {
             fprintf(stderr, "Different number of matrices, using the smallest number.\n");
-            nmat = nmat2 = min(nmat, nmat2);
+            nmat = nmat2 = std::min(nmat, nmat2);
         }
     }
     else
@@ -1568,10 +1573,10 @@ int gmx_xpm2ps(int argc, char *argv[])
     {
         for (i = 0; (i < nmat); i++)
         {
-            strcpy(mat[i].label_y, mat[i].title);
+            std::strcpy(mat[i].label_y, mat[i].title);
             if (mat2)
             {
-                strcpy(mat2[i].label_y, mat2[i].title);
+                std::strcpy(mat2[i].label_y, mat2[i].title);
             }
         }
     }
index 54b32214926a49b5cd98658a72dbbbc0fe5f284b..f019512d1b699ee5d48a97dc3f336b3543ab37dd 100644 (file)
 namespace gmx
 {
 
+std::size_t
+countWords(const char *s)
+{
+    std::size_t nWords = 0;
+    // Use length variable to avoid N^2 complexity when executing strlen(s) every iteration
+    std::size_t length = std::strlen(s);
+
+    for (std::size_t i = 0; i < length; i++)
+    {
+        // If we found a new word, increase counter and step through the word
+        if (std::isalnum(s[i]))
+        {
+            ++nWords;
+            // If we hit string end, '\0' is not alphanumerical
+            while (std::isalnum(s[i]))
+            {
+                // This might increment i to the string end, and then the outer
+                // loop will increment i one unit beyond that, but since
+                // we compare to the string length in the outer loop this is fine.
+                i++;
+            }
+        }
+    }
+    return nWords;
+}
+
+
+std::size_t
+countWords(const std::string &str)
+{
+    // Under out beautiful C++ interface hides an ugly c-string implementation :-)
+    return countWords(str.c_str());
+}
+
 bool endsWith(const char *str, const char *suffix)
 {
     if (isNullOrEmpty(suffix))
index 004daae3e0353708bfa75d731a5fe6fd2db4b0db..034f258013a60872ddfd2701481aaeff25d4534f 100644 (file)
@@ -101,6 +101,27 @@ static inline bool endsWith(const std::string &str, const char *suffix)
     return endsWith(str.c_str(), suffix);
 }
 
+/*!\brief Returns number of space-separated words in zero-terminated char ptr
+ *
+ * \param s Character pointer to zero-terminated, which will not be changed.
+ *
+ * \returns number of words in string.
+ *
+ * \note This routine is mainly meant to support legacy code in GROMACS. For
+ *       new source you should try hard to use C++ string objects instead.
+ */
+std::size_t
+countWords(const char *s);
+
+/*!\brief Returns the number of space-separated words in a string object
+ *
+ * \param str Reference to string object, which will not be changed.
+ *
+ * \returns number of words in string.
+ */
+std::size_t
+countWords(const std::string &str);
+
 /*! \brief
  * Removes a suffix from a string.
  *