Moved additional gmxlib sources to C++
authorErik Lindahl <erik@kth.se>
Fri, 17 Jul 2015 19:40:41 +0000 (21:40 +0200)
committerErik Lindahl <erik@kth.se>
Mon, 27 Jul 2015 13:06:13 +0000 (15:06 +0200)
Moved functions into std:: namespace and changed try->attempt
to avoid using reserved names. gmx_cpuid.c has been left
as C for now, both because __cpuid() and __cpuidex() does
not appear to be present in C++ source, and because it will
anyway be replaced with a proper C++ module that can also
interface to hwloc.

Change-Id: I6f10b19a499209b375ee154540a3386f882457bd

23 files changed:
src/gromacs/gmxlib/calcgrid.cpp
src/gromacs/gmxlib/chargegroup.cpp
src/gromacs/gmxlib/checkpoint.cpp
src/gromacs/gmxlib/conformation-utilities.cpp [moved from src/gromacs/gmxlib/conformation-utilities.c with 96% similarity]
src/gromacs/gmxlib/copyrite.cpp
src/gromacs/gmxlib/disre.cpp
src/gromacs/gmxlib/gmx_detect_hardware.cpp
src/gromacs/gmxlib/gmx_omp_nthreads.cpp [moved from src/gromacs/gmxlib/gmx_omp_nthreads.c with 98% similarity]
src/gromacs/gmxlib/gmx_thread_affinity.cpp [moved from src/gromacs/gmxlib/gmx_thread_affinity.c with 96% similarity]
src/gromacs/gmxlib/inputrec.cpp
src/gromacs/gmxlib/main.cpp
src/gromacs/gmxlib/md_logging.cpp
src/gromacs/gmxlib/network.cpp
src/gromacs/gmxlib/nrnb.cpp [moved from src/gromacs/gmxlib/nrnb.c with 96% similarity]
src/gromacs/gmxlib/orires.cpp
src/gromacs/gmxlib/rbin.cpp
src/gromacs/gmxlib/readinp.cpp [moved from src/gromacs/gmxlib/readinp.c with 95% similarity]
src/gromacs/gmxlib/sighandler.cpp
src/gromacs/gmxlib/splitter.cpp [moved from src/gromacs/gmxlib/splitter.c with 84% similarity]
src/gromacs/gmxlib/txtdump.cpp
src/gromacs/gmxlib/typedefs.cpp
src/gromacs/gmxlib/viewit.cpp [moved from src/gromacs/gmxlib/viewit.c with 97% similarity]
src/gromacs/gmxlib/warninp.cpp [moved from src/gromacs/gmxlib/warninp.c with 97% similarity]

index 80da0e1a396ae58606c4d38242c81ed5cadfe1d2..b1e7aa8e073d9e9d34f08db0806c5b4f9a4e062e 100644 (file)
@@ -38,7 +38,9 @@
 
 #include "gromacs/legacyheaders/calcgrid.h"
 
-#include <math.h>
+#include <cmath>
+
+#include <algorithm>
 
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/utility/fatalerror.h"
@@ -98,7 +100,7 @@ real calc_grid(FILE *fp, matrix box, real gr_sp,
         {
             box_size[d] += box[d][i]*box[d][i];
         }
-        box_size[d] = sqrt(box_size[d]);
+        box_size[d] = std::sqrt(box_size[d]);
     }
 
     n[XX] = *nx;
@@ -119,7 +121,7 @@ real calc_grid(FILE *fp, matrix box, real gr_sp,
     {
         if (n[d] <= 0)
         {
-            nmin = (int)(box_size[d]/gr_sp + 0.999);
+            nmin = static_cast<int>(box_size[d]/gr_sp + 0.999);
 
             i = g_initNR - 1;
             if (grid_init[i] >= nmin)
@@ -156,11 +158,8 @@ real calc_grid(FILE *fp, matrix box, real gr_sp,
             }
         }
 
-        spacing[d] = box_size[d]/n[d];
-        if (spacing[d] > max_spacing)
-        {
-            max_spacing = spacing[d];
-        }
+        spacing[d]  = box_size[d]/n[d];
+        max_spacing = std::max(max_spacing, spacing[d]);
     }
     *nx = n[XX];
     *ny = n[YY];
index aaf9d131671e377f77f2e60b86837b8e3fe5a533..b98383c4a88052e5e9650198923add5de0108012 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "gromacs/legacyheaders/chargegroup.h"
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/vec.h"
@@ -139,10 +139,10 @@ void calc_chargegroup_radii(const gmx_mtop_t *mtop, rvec *x,
 
     sfree(bLJ);
 
-    *rvdw1  = sqrt(r2v1);
-    *rvdw2  = sqrt(r2v2);
-    *rcoul1 = sqrt(r2c1);
-    *rcoul2 = sqrt(r2c2);
+    *rvdw1  = std::sqrt(r2v1);
+    *rvdw2  = std::sqrt(r2v2);
+    *rcoul1 = std::sqrt(r2c1);
+    *rcoul2 = std::sqrt(r2c2);
 }
 
 void calc_cgcm(FILE gmx_unused *fplog, int cg0, int cg1, t_block *cgs,
index e38563f9c95446411ec6ea473492da16111252ca..4f3634d5f7f4771116c818bec7e8e3c50b19f4bd 100644 (file)
@@ -41,9 +41,9 @@
 
 #include "config.h"
 
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
 
 #include <fcntl.h>
 #ifdef GMX_NATIVE_WINDOWS
@@ -189,14 +189,11 @@ static void cp_error()
 
 static void do_cpt_string_err(XDR *xd, gmx_bool bRead, const char *desc, char **s, FILE *list)
 {
-    bool_t res = 0;
-
     if (bRead)
     {
         snew(*s, CPTSTRLEN);
     }
-    res = xdr_string(xd, s, CPTSTRLEN);
-    if (res == 0)
+    if (xdr_string(xd, s, CPTSTRLEN) == 0)
     {
         cp_error();
     }
@@ -209,10 +206,7 @@ static void do_cpt_string_err(XDR *xd, gmx_bool bRead, const char *desc, char **
 
 static int do_cpt_int(XDR *xd, const char *desc, int *i, FILE *list)
 {
-    bool_t res = 0;
-
-    res = xdr_int(xd, i);
-    if (res == 0)
+    if (xdr_int(xd, i) == 0)
     {
         return -1;
     }
@@ -225,13 +219,12 @@ static int do_cpt_int(XDR *xd, const char *desc, int *i, FILE *list)
 
 static int do_cpt_u_chars(XDR *xd, const char *desc, int n, unsigned char *i, FILE *list)
 {
-    bool_t res = 1;
-    int    j;
     if (list)
     {
         fprintf(list, "%s = ", desc);
     }
-    for (j = 0; j < n && res; j++)
+    bool_t res = 1;
+    for (int j = 0; j < n && res; j++)
     {
         res &= xdr_u_char(xd, &i[j]);
         if (list)
@@ -261,11 +254,9 @@ static void do_cpt_int_err(XDR *xd, const char *desc, int *i, FILE *list)
 
 static void do_cpt_step_err(XDR *xd, const char *desc, gmx_int64_t *i, FILE *list)
 {
-    bool_t res = 0;
     char   buf[STEPSTRSIZE];
 
-    res = xdr_int64(xd, i);
-    if (res == 0)
+    if (xdr_int64(xd, i) == 0)
     {
         cp_error();
     }
@@ -277,10 +268,7 @@ static void do_cpt_step_err(XDR *xd, const char *desc, gmx_int64_t *i, FILE *lis
 
 static void do_cpt_double_err(XDR *xd, const char *desc, double *f, FILE *list)
 {
-    bool_t res = 0;
-
-    res = xdr_double(xd, f);
-    if (res == 0)
+    if (xdr_double(xd, f) == 0)
     {
         cp_error();
     }
@@ -292,12 +280,10 @@ static void do_cpt_double_err(XDR *xd, const char *desc, double *f, FILE *list)
 
 static void do_cpt_real_err(XDR *xd, real *f)
 {
-    bool_t res = 0;
-
 #ifdef GMX_DOUBLE
-    res = xdr_double(xd, f);
+    bool_t res = xdr_double(xd, f);
 #else
-    res = xdr_float(xd, f);
+    bool_t res = xdr_float(xd, f);
 #endif
     if (res == 0)
     {
@@ -307,11 +293,9 @@ static void do_cpt_real_err(XDR *xd, real *f)
 
 static void do_cpt_n_rvecs_err(XDR *xd, const char *desc, int n, rvec f[], FILE *list)
 {
-    int i, j;
-
-    for (i = 0; i < n; i++)
+    for (int i = 0; i < n; i++)
     {
-        for (j = 0; j < DIM; j++)
+        for (int j = 0; j < DIM; j++)
         {
             do_cpt_real_err(xd, &f[i][j]);
         }
@@ -404,14 +388,14 @@ static int do_cpte_reals_low(XDR *xd, int cptp, int ecpt, int sflags,
     {
         if (dtc == xdr_datatype_float)
         {
-            vf = (float *)vp;
+            vf = reinterpret_cast<float *>(vp);
         }
         else
         {
             snew(vf, nf);
         }
-        res = xdr_vector(xd, (char *)vf, nf,
-                         (unsigned int)sizeof(float), (xdrproc_t)xdr_float);
+        res = xdr_vector(xd, reinterpret_cast<char *>(vf), nf,
+                         static_cast<unsigned int>(sizeof(float)), (xdrproc_t)xdr_float);
         if (res == 0)
         {
             return -1;
@@ -437,8 +421,8 @@ static int do_cpte_reals_low(XDR *xd, int cptp, int ecpt, int sflags,
         {
             snew(vd, nf);
         }
-        res = xdr_vector(xd, (char *)vd, nf,
-                         (unsigned int)sizeof(double), (xdrproc_t)xdr_double);
+        res = xdr_vector(xd, reinterpret_cast<char *>(vd), nf,
+                         static_cast<unsigned int>(sizeof(double)), (xdrproc_t)xdr_double);
         if (res == 0)
         {
             return -1;
@@ -545,8 +529,8 @@ static int do_cpte_ints(XDR *xd, int cptp, int ecpt, int sflags,
         }
         vp = *v;
     }
-    res = xdr_vector(xd, (char *)vp, nf,
-                     (unsigned int)sizeof(int), (xdrproc_t)xdr_int);
+    res = xdr_vector(xd, reinterpret_cast<char *>(vp), nf,
+                     static_cast<unsigned int>(sizeof(int)), (xdrproc_t)xdr_int);
     if (res == 0)
     {
         return -1;
@@ -612,8 +596,8 @@ static int do_cpte_doubles(XDR *xd, int cptp, int ecpt, int sflags,
         }
         vp = *v;
     }
-    res = xdr_vector(xd, (char *)vp, nf,
-                     (unsigned int)sizeof(double), (xdrproc_t)xdr_double);
+    res = xdr_vector(xd, reinterpret_cast<char *>(vp), nf,
+                     static_cast<unsigned int>(sizeof(double)), (xdrproc_t)xdr_double);
     if (res == 0)
     {
         return -1;
@@ -650,7 +634,7 @@ static int do_cpte_matrix(XDR *xd, int cptp, int ecpt, int sflags,
     real *vr;
     int   ret;
 
-    vr  = (real *)&(v[0][0]);
+    vr  = &(v[0][0]);
     ret = do_cpte_reals_low(xd, cptp, ecpt, sflags,
                             DIM*DIM, NULL, &vr, NULL, ecprMATRIX);
 
@@ -1390,7 +1374,7 @@ static int do_cpt_files(XDR *xd, gmx_bool bRead,
         if (bRead)
         {
             do_cpt_string_err(xd, bRead, "output filename", &buf, list);
-            strncpy(outputfiles[i].filename, buf, CPTSTRLEN-1);
+            std::strncpy(outputfiles[i].filename, buf, CPTSTRLEN-1);
             if (list == NULL)
             {
                 sfree(buf);
@@ -1404,7 +1388,7 @@ static int do_cpt_files(XDR *xd, gmx_bool bRead,
             {
                 return -1;
             }
-            outputfiles[i].offset = ( ((gmx_off_t) offset_high) << 32 ) | ( (gmx_off_t) offset_low & mask );
+            outputfiles[i].offset = (static_cast<gmx_off_t>(offset_high) << 32 ) | ( static_cast<gmx_off_t>(offset_low) & mask );
         }
         else
         {
@@ -1419,8 +1403,8 @@ static int do_cpt_files(XDR *xd, gmx_bool bRead,
             }
             else
             {
-                offset_low  = (int) (offset & mask);
-                offset_high = (int) ((offset >> 32) & mask);
+                offset_low  = static_cast<int>(offset & mask);
+                offset_high = static_cast<int>((offset >> 32) & mask);
             }
             if (do_cpt_int(xd, "file_offset_high", &offset_high, list) != 0)
             {
@@ -1489,18 +1473,18 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
 
 #if !GMX_NO_RENAME
     /* make the new temporary filename */
-    snew(fntemp, strlen(fn)+5+STEPSTRSIZE);
-    strcpy(fntemp, fn);
-    fntemp[strlen(fn) - strlen(ftp2ext(fn2ftp(fn))) - 1] = '\0';
+    snew(fntemp, std::strlen(fn)+5+STEPSTRSIZE);
+    std::strcpy(fntemp, fn);
+    fntemp[std::strlen(fn) - std::strlen(ftp2ext(fn2ftp(fn))) - 1] = '\0';
     sprintf(suffix, "_%s%s", "step", gmx_step_str(step, sbuf));
-    strcat(fntemp, suffix);
-    strcat(fntemp, fn+strlen(fn) - strlen(ftp2ext(fn2ftp(fn))) - 1);
+    std::strcat(fntemp, suffix);
+    std::strcat(fntemp, fn+std::strlen(fn) - std::strlen(ftp2ext(fn2ftp(fn))) - 1);
 #else
     /* if we can't rename, we just overwrite the cpt file.
      * dangerous if interrupted.
      */
-    snew(fntemp, strlen(fn));
-    strcpy(fntemp, fn);
+    snew(fntemp, std::strlen(fn));
+    std::strcpy(fntemp, fn);
 #endif
     gmx_format_current_time(timebuf, STRLEN);
 
@@ -1648,10 +1632,10 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
         if (gmx_fexist(fn))
         {
             /* Rename the previous checkpoint file */
-            strcpy(buf, fn);
-            buf[strlen(fn) - strlen(ftp2ext(fn2ftp(fn))) - 1] = '\0';
-            strcat(buf, "_prev");
-            strcat(buf, fn+strlen(fn) - strlen(ftp2ext(fn2ftp(fn))) - 1);
+            std::strcpy(buf, fn);
+            buf[std::strlen(fn) - std::strlen(ftp2ext(fn2ftp(fn))) - 1] = '\0';
+            std::strcat(buf, "_prev");
+            std::strcat(buf, fn+std::strlen(fn) - std::strlen(ftp2ext(fn2ftp(fn))) - 1);
 #ifndef GMX_FAHCORE
             /* we copy here so that if something goes wrong between now and
              * the rename below, there's always a state.cpt.
@@ -1725,7 +1709,7 @@ static void check_string(FILE *fplog, const char *type, const char *p,
 {
     FILE *fp = fplog ? fplog : stderr;
 
-    if (strcmp(p, f) != 0)
+    if (std::strcmp(p, f) != 0)
     {
         fprintf(fp, "  %s mismatch,\n", type);
         fprintf(fp, "    current program: %s\n", p);
@@ -2153,7 +2137,7 @@ static void read_checkpoint(const char *fn, FILE **pfplog,
                     else
                     {
                         gmx_fatal(FARGS, "Failed to lock: %s. %s.",
-                                  outputfiles[i].filename, strerror(errno));
+                                  outputfiles[i].filename, std::strerror(errno));
                     }
                 }
             }
@@ -2173,7 +2157,7 @@ static void read_checkpoint(const char *fn, FILE **pfplog,
             {
                 if (gmx_fio_seek(chksum_file, outputfiles[i].offset))
                 {
-                    gmx_fatal(FARGS, "Seek error! Failed to truncate log-file: %s.", strerror(errno));
+                    gmx_fatal(FARGS, "Seek error! Failed to truncate log-file: %s.", std::strerror(errno));
                 }
             }
 #endif
similarity index 96%
rename from src/gromacs/gmxlib/conformation-utilities.c
rename to src/gromacs/gmxlib/conformation-utilities.cpp
index d21efa4cde0a00dae3f51dd55e597715e35e5cd4..0e1241acaefe9ba1c89a96d78160ce4e312750ac 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,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
@@ -39,7 +39,9 @@
 
 #include "conformation-utilities.h"
 
-#include <math.h>
+#include <cmath>
+
+#include <algorithm>
 
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/math/vec.h"
@@ -127,7 +129,6 @@ void make_new_box(int natoms, rvec *x, matrix box, rvec box_space,
 {
     int  i, m;
     rvec xmin, xmax;
-    real max_box;
 
     /*calculate minimum and maximum x[0..DIM-1]*/
     for (m = 0; (m < DIM); m++)
@@ -138,8 +139,8 @@ void make_new_box(int natoms, rvec *x, matrix box, rvec box_space,
     {
         for (m = 0; m < DIM; m++)
         {
-            xmin[m] = min(xmin[m], x[i][m]);
-            xmax[m] = max(xmax[m], x[i][m]);
+            xmin[m] = std::min(xmin[m], x[i][m]);
+            xmax[m] = std::max(xmax[m], x[i][m]);
         }
     }
 
index abb0d80c4c054dc32b70268aae626248bc234302..b741fedb62441bbc1337adfc2735aee105e964d5 100644 (file)
 
 #include "config.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
 
 #include <algorithm>
 
@@ -102,11 +102,11 @@ static void pukeit(const char *db, const char *defstring, char *retstring,
         rng    = gmx_rng_init(gmx_rng_make_seed());
         *cqnum = static_cast<int>(nhlp*gmx_rng_uniform_real(rng));
         gmx_rng_destroy(rng);
-        if (strlen(help[*cqnum]) >= STRLEN)
+        if (std::strlen(help[*cqnum]) >= STRLEN)
         {
             help[*cqnum][STRLEN-1] = '\0';
         }
-        strncpy(retstring, help[*cqnum], retsize);
+        std::strncpy(retstring, help[*cqnum], retsize);
         for (i = 0; (i < nhlp); i++)
         {
             sfree(help[i]);
@@ -116,7 +116,7 @@ static void pukeit(const char *db, const char *defstring, char *retstring,
     else
     {
         *cqnum = -1;
-        strncpy(retstring, defstring, retsize);
+        std::strncpy(retstring, defstring, retsize);
     }
 }
 
@@ -149,7 +149,7 @@ void cool_quote(char *retstring, int retsize, int *cqnum)
     pukeit("gurgle.dat", "Thanx for Using GROMACS - Have a Nice Day",
            tmpstr, retsize-2, p);
 
-    if ((ptr = strchr(tmpstr, '_')) != NULL)
+    if ((ptr = std::strchr(tmpstr, '_')) != NULL)
     {
         *ptr = '\0';
         ptr++;
@@ -157,7 +157,7 @@ void cool_quote(char *retstring, int retsize, int *cqnum)
     }
     else
     {
-        strcpy(retstring, tmpstr);
+        std::strcpy(retstring, tmpstr);
     }
     sfree(tmpstr);
 }
@@ -844,7 +844,7 @@ void printBinaryInformation(FILE                            *fp,
     std::string title
         = formatString(":-) GROMACS - %s, %s%s (-:", name, gmx_version(), precisionString);
     const int   indent
-        = centeringOffset(78 - strlen(prefix) - strlen(suffix), title.length()) + 1;
+        = centeringOffset(78 - std::strlen(prefix) - std::strlen(suffix), title.length()) + 1;
     fprintf(fp, "%s%*c%s%s\n", prefix, indent, ' ', title.c_str(), suffix);
     fprintf(fp, "%s%s\n", prefix, suffix);
     if (settings.bCopyright_)
index cecfb04bfac6acd65981e5b725034f47d261c33d..491504b82e6575ccb2653c2100e44f5055a5fc43 100644 (file)
@@ -41,8 +41,9 @@
 
 #include "config.h"
 
-#include <math.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include <algorithm>
 
@@ -109,7 +110,7 @@ void init_disres(FILE *fplog, const gmx_mtop_t *mtop,
     else
     {
         dd->dr_bMixed = ir->bDisreMixed;
-        dd->ETerm     = exp(-(ir->delta_t/ir->dr_tau));
+        dd->ETerm     = std::exp(-(ir->delta_t/ir->dr_tau));
     }
     dd->ETerm1        = 1.0 - dd->ETerm;
 
@@ -331,7 +332,7 @@ void calc_disres_R_6(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
             rt_1 = gmx_invsqrt(rt2);
             rt_3 = rt_1*rt_1*rt_1;
 
-            rt[pair]         = sqrt(rt2);
+            rt[pair]         = std::sqrt(rt2);
             if (bTav)
             {
                 /* Here we update rm3tav in t_fcdata using the data
@@ -429,15 +430,15 @@ real ta_disres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
         {
             bConservative = (dr_weighting == edrwConservative) && (npair > 1);
             bMixed        = dr_bMixed;
-            Rt            = pow(Rt_6[res], -sixth);
-            Rtav          = pow(Rtav_6[res], -sixth);
+            Rt            = std::pow(Rt_6[res], -sixth);
+            Rtav          = std::pow(Rtav_6[res], -sixth);
         }
         else
         {
             /* When rtype=2 use instantaneous not ensemble avereged distance */
             bConservative = (npair > 1);
             bMixed        = FALSE;
-            Rt            = pow(Rtl_6[res], -sixth);
+            Rt            = std::pow(Rtl_6[res], -sixth);
             Rtav          = Rt;
         }
 
@@ -501,7 +502,7 @@ real ta_disres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
                 }
                 if (bViolation)
                 {
-                    mixed_viol = sqrt(tav_viol*instant_viol);
+                    mixed_viol = std::sqrt(tav_viol*instant_viol);
                     f_scal     = -k0*mixed_viol;
                     violtot   += mixed_viol;
                 }
@@ -528,7 +529,7 @@ real ta_disres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
             }
             else
             {
-                f_scal /= (real)npair;
+                f_scal /= npair;
                 f_scal  = std::max(f_scal, fmax_scal);
             }
 
@@ -557,12 +558,12 @@ real ta_disres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
                 {
                     if (!dr_bMixed)
                     {
-                        weight_rt_1 *= pow(dd->rm3tav[pair], seven_three);
+                        weight_rt_1 *= std::pow(dd->rm3tav[pair], seven_three);
                     }
                     else
                     {
-                        weight_rt_1 *= tav_viol_Rtav7*pow(dd->rm3tav[pair], seven_three)+
-                            instant_viol_Rtav7*pow(dd->rt[pair], -7);
+                        weight_rt_1 *= tav_viol_Rtav7*std::pow(dd->rm3tav[pair], seven_three)+
+                            instant_viol_Rtav7*std::pow(dd->rt[pair], static_cast<real>(-7));
                     }
                 }
 
index e93fe43d10971cb0dda10d1aa38f38be56fce2d6..02a543dffdc93a903b64b86b7c7312d6c912f908 100644 (file)
 
 #include "config.h"
 
-#include <assert.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
 
+#include <algorithm>
 #include <string>
 #include <vector>
 
@@ -182,11 +182,11 @@ static void print_gpu_detection_stats(FILE                 *fplog,
 
 #if defined GMX_MPI && !defined GMX_THREAD_MPI
     /* We only print the detection on one, of possibly multiple, nodes */
-    strncpy(onhost, " on host ", 10);
+    std::strncpy(onhost, " on host ", 10);
     gmx_gethostname(onhost + 9, HOSTNAMELEN);
 #else
     /* We detect all relevant GPUs */
-    strncpy(onhost, "", 1);
+    std::strncpy(onhost, "", 1);
 #endif
 
     if (ngpu > 0)
@@ -327,8 +327,8 @@ void gmx_check_hw_runconf_consistency(FILE                *fplog,
     char     th_or_proc[STRLEN], th_or_proc_plural[STRLEN], pernode[STRLEN];
     gmx_bool btMPI, bMPI, bNthreadsAuto, bEmulateGPU;
 
-    assert(hwinfo);
-    assert(cr);
+    GMX_RELEASE_ASSERT(hwinfo, "hwinfo must be a non-NULL pointer");
+    GMX_RELEASE_ASSERT(cr, "cr must be a non-NULL pointer");
 
     /* Below we only do consistency checks for PP and GPUs,
      * this is irrelevant for PME only nodes, so in that case we return
@@ -572,8 +572,8 @@ static int gmx_count_gpu_dev_unique(const gmx_gpu_info_t *gpu_info,
     int  i, uniq_count, ngpu;
     int *uniq_ids;
 
-    assert(gpu_info);
-    assert(gpu_opt);
+    GMX_RELEASE_ASSERT(gpu_info, "gpu_info must be a non-NULL pointer");
+    GMX_RELEASE_ASSERT(gpu_opt, "gpu_opt must be a non-NULL pointer");
 
     ngpu = gpu_info->n_dev;
 
@@ -707,7 +707,7 @@ static void gmx_detect_gpus(FILE *fplog, const t_commrec *cr)
     MPI_Comm_rank(physicalnode_comm, &rank_local);
 #else
     /* Here there should be only one process, check this */
-    assert(cr->nnodes == 1 && cr->sim_nodeid == 0);
+    GMX_RELEASE_ASSERT(cr->nnodes == 1 && cr->sim_nodeid == 0, "Only a single (master) process should execute here");
 
     rank_local = 0;
 #endif
similarity index 98%
rename from src/gromacs/gmxlib/gmx_omp_nthreads.c
rename to src/gromacs/gmxlib/gmx_omp_nthreads.cpp
index 50c3b9d261943fd5cb07e5b962971fae9f23ce85..dc9d51835d6ae381adafe20a5d89c906900ebb13 100644 (file)
 
 #include "config.h"
 
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -52,6 +51,7 @@
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/gmxomp.h"
 
 /** Structure with the number of threads for each OpenMP multi-threaded
@@ -196,7 +196,7 @@ void gmx_omp_nthreads_read_env(int     *nthreads_omp,
     gmx_bool bCommandLineSetNthreadsOMP = *nthreads_omp > 0;
     char     buffer[STRLEN];
 
-    assert(nthreads_omp);
+    GMX_RELEASE_ASSERT(nthreads_omp, "nthreads_omp must be a non-NULL pointer");
 
     if ((env = getenv("OMP_NUM_THREADS")) != NULL)
     {
@@ -297,7 +297,7 @@ static void manage_number_of_openmp_threads(FILE               *fplog,
     nth = 1;
     if ((env = getenv("OMP_NUM_THREADS")) != NULL)
     {
-        if (!bOMP && (strncmp(env, "1", 1) != 0))
+        if (!bOMP && (std::strncmp(env, "1", 1) != 0))
         {
             gmx_warning("OMP_NUM_THREADS is set, but %s was compiled without OpenMP support!",
                         ShortProgram());
@@ -524,7 +524,7 @@ void gmx_omp_nthreads_init(FILE *fplog, t_commrec *cr,
                            gmx_bool bThisNodePMEOnly,
                            gmx_bool bFullOmpSupport)
 {
-    int      nth_pmeonly, gmx_maxth, nppn;
+    int      nppn;
     gmx_bool bSepPME, bOMP;
 
 #ifdef GMX_OPENMP
@@ -576,7 +576,7 @@ gmx_omp_nthreads_set(int mod, int nthreads)
 {
     /* Catch an attempt to set the number of threads on an invalid
      * OpenMP module. */
-    assert(mod >= 0 && mod < emntNR);
+    GMX_RELEASE_ASSERT(mod >= 0 && mod < emntNR, "Trying to set nthreads on invalid OpenMP module");
 
     modth.nth[mod] = nthreads;
 }
similarity index 96%
rename from src/gromacs/gmxlib/gmx_thread_affinity.c
rename to src/gromacs/gmxlib/gmx_thread_affinity.cpp
index b43444468007852d8029d6c8dbcfa883ee807977..dd763ca7941b33e469384b40a6c7d683709d1a3d 100644 (file)
 
 #include "config.h"
 
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
 
 #ifdef HAVE_SCHED_AFFINITY
 #  include <sched.h>
@@ -60,6 +59,7 @@
 #include "gromacs/utility/basenetwork.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/gmxomp.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -189,7 +189,7 @@ gmx_set_thread_affinity(FILE                *fplog,
                         const gmx_hw_info_t *hwinfo)
 {
     int        nth_affinity_set, thread0_id_node,
-               nthread_local, nthread_node, nthread_hw_max, nphyscore;
+               nthread_local, nthread_node;
     int        offset;
     const int *locality_order;
     int        rc;
@@ -287,6 +287,10 @@ gmx_set_thread_affinity(FILE                *fplog,
      * Reducing these 0/1 values over the threads will give the total number
      * of threads on which we succeeded.
      */
+
+    // To avoid warnings from the static analyzer we initialize nth_affinity_set
+    // to zero outside the OpenMP block, and then add to it inside the block.
+    // The value will still always be 0 or 1 from each thread.
     nth_affinity_set = 0;
 #pragma omp parallel num_threads(nthread_local) reduction(+:nth_affinity_set)
     {
@@ -309,7 +313,7 @@ gmx_set_thread_affinity(FILE                *fplog,
         setaffinity_ret = tMPI_Thread_setaffinity_single(tMPI_Thread_self(), core);
 
         /* store the per-thread success-values of the setaffinity */
-        nth_affinity_set = (setaffinity_ret == 0);
+        nth_affinity_set += (setaffinity_ret == 0);
 
         if (debug)
         {
@@ -374,16 +378,8 @@ gmx_check_thread_affinity_set(FILE            *fplog,
                               int  gmx_unused  nthreads_hw_avail,
                               gmx_bool         bAfterOpenmpInit)
 {
-#ifdef HAVE_SCHED_AFFINITY
-    cpu_set_t mask_current;
-    int       i, ret, cpu_count, cpu_set;
-    gmx_bool  bAllSet;
-#endif
-#ifdef GMX_LIB_MPI
-    gmx_bool  bAllSet_All;
-#endif
+    GMX_RELEASE_ASSERT(hw_opt, "hw_opt must be a non-NULL pointer");
 
-    assert(hw_opt);
     if (!bAfterOpenmpInit)
     {
         /* Check for externally set OpenMP affinity and turn off internal
@@ -418,6 +414,9 @@ gmx_check_thread_affinity_set(FILE            *fplog,
     }
 
 #ifdef HAVE_SCHED_GETAFFINITY
+    int       ret;
+    cpu_set_t mask_current;
+
     if (hw_opt->thread_affinity == threadaffOFF)
     {
         /* internal affinity setting is off, don't bother checking process affinity */
@@ -450,13 +449,15 @@ gmx_check_thread_affinity_set(FILE            *fplog,
     }
 #endif /* CPU_COUNT */
 
-    bAllSet = TRUE;
-    for (i = 0; (i < nthreads_hw_avail && i < CPU_SETSIZE); i++)
+    gmx_bool bAllSet = TRUE;
+    for (int i = 0; (i < nthreads_hw_avail && i < CPU_SETSIZE); i++)
     {
         bAllSet = bAllSet && (CPU_ISSET(i, &mask_current) != 0);
     }
 
 #ifdef GMX_LIB_MPI
+    gmx_bool  bAllSet_All;
+
     MPI_Allreduce(&bAllSet, &bAllSet_All, 1, MPI_INT, MPI_LAND, MPI_COMM_WORLD);
     bAllSet = bAllSet_All;
 #endif
index cf642041c354f4552a2556fee1dfdbc0cfd8d7e8..d30f41f08cfd335c9cc4548006d8e4c91b3e2bb5 100644 (file)
@@ -182,7 +182,7 @@ int ir_optimal_nstpcouple(const t_inputrec *ir)
     }
     else
     {
-        n = (int)(ir->tau_p/(ir->delta_t*nmin) + 0.001);
+        n = static_cast<int>(ir->tau_p/(ir->delta_t*nmin) + 0.001);
         if (n < 1)
         {
             n = 1;
index 28644ba909b177380e0626b35ef3743a09968b46..a7965804d948c3f5e554283907bd938a587f9b92 100644 (file)
 
 #include "config.h"
 
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/gmxfio.h"
@@ -70,14 +69,14 @@ static void par_fn(char *base, int ftp, const t_commrec *cr,
                    gmx_bool bAppendSimId, gmx_bool bAppendNodeId,
                    char buf[], int bufsize)
 {
-    if ((size_t)bufsize < (strlen(base)+10))
+    if (static_cast<std::size_t>(bufsize) < (std::strlen(base)+10))
     {
         gmx_mem("Character buffer too small!");
     }
 
     /* Copy to buf, and strip extension */
-    strcpy(buf, base);
-    buf[strlen(base) - strlen(ftp2ext(fn2ftp(base))) - 1] = '\0';
+    std::strcpy(buf, base);
+    buf[strlen(base) - std::strlen(ftp2ext(fn2ftp(base))) - 1] = '\0';
 
     if (bAppendSimId)
     {
@@ -85,13 +84,13 @@ static void par_fn(char *base, int ftp, const t_commrec *cr,
     }
     if (bAppendNodeId)
     {
-        strcat(buf, "_rank");
+        std::strcat(buf, "_rank");
         sprintf(buf+strlen(buf), "%d", cr->nodeid);
     }
-    strcat(buf, ".");
+    std::strcat(buf, ".");
 
     /* Add extension again */
-    strcat(buf, (ftp == efTPR) ? "tpr" : (ftp == efEDR) ? "edr" : ftp2ext(ftp));
+    std::strcat(buf, (ftp == efTPR) ? "tpr" : (ftp == efEDR) ? "edr" : ftp2ext(ftp));
     if (debug)
     {
         fprintf(debug, "rank %d par_fn '%s'\n", cr->nodeid, buf);
index 23ac56230cd2f5679ecdf2c415fd6e0aee1e4196..6636117d98adbc05c9beeb9c2839310d63d72e4c 100644 (file)
@@ -38,8 +38,8 @@
 
 #include "gromacs/legacyheaders/md_logging.h"
 
-#include <stdarg.h>
-#include <stdio.h>
+#include <cstdarg>
+#include <cstdio>
 
 #include "gromacs/legacyheaders/types/commrec.h"
 
index 5ac06a00aeb7eb5b251b9dc024422acae8cc587b..c089d78ef02e096706387bd91dea7053b39edd29 100644 (file)
 
 #include "config.h"
 
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cstdarg>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -155,12 +155,12 @@ void gmx_setup_nodecomm(FILE gmx_unused *fplog, t_commrec *cr)
     nc->bUse = FALSE;
 #ifndef GMX_THREAD_MPI
 #ifdef GMX_MPI
-    int n, rank, nodehash, ng, ni;
+    int n, rank;
 
     MPI_Comm_size(cr->mpi_comm_mygroup, &n);
     MPI_Comm_rank(cr->mpi_comm_mygroup, &rank);
 
-    nodehash = gmx_physicalnode_id_hash();
+    int nodehash = gmx_physicalnode_id_hash();
 
     if (debug)
     {
@@ -182,6 +182,8 @@ void gmx_setup_nodecomm(FILE gmx_unused *fplog, t_commrec *cr)
      */
     MPI_Comm_split(cr->mpi_comm_mygroup, nc->rank_intra, rank, &nc->comm_inter);
     /* Check if this really created two step communication */
+    int ng, ni;
+
     MPI_Comm_size(nc->comm_inter, &ng);
     MPI_Comm_size(nc->comm_intra, &ni);
     if (debug)
similarity index 96%
rename from src/gromacs/gmxlib/nrnb.c
rename to src/gromacs/gmxlib/nrnb.cpp
index 5007d2aab3e5e4e8976d69141233369977528591..33a877a347cefc67954adc7f19019b5bf36e3632 100644 (file)
 
 #include "gromacs/legacyheaders/nrnb.h"
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/names.h"
@@ -208,13 +210,13 @@ static void pr_difftime(FILE *out, double dt)
     int        ndays, nhours, nmins, nsecs;
     gmx_bool   bPrint, bPrinted;
 
-    ndays    = dt/(24*3600);
+    ndays    = static_cast<int>(dt/(24*3600));
     dt       = dt-24*3600*ndays;
-    nhours   = dt/3600;
+    nhours   = static_cast<int>(dt/3600);
     dt       = dt-3600*nhours;
-    nmins    = dt/60;
+    nmins    = static_cast<int>(dt/60);
     dt       = dt-nmins*60;
-    nsecs    = dt;
+    nsecs    = static_cast<int>(dt);
     bPrint   = (ndays > 0);
     bPrinted = bPrint;
     if (bPrint)
@@ -331,19 +333,19 @@ void print_flop(FILE *out, t_nrnb *nrnb, double *nbfs, double *mflop)
     *nbfs = 0.0;
     for (i = 0; (i < eNR_NBKERNEL_ALLVSALLGB); i++)
     {
-        if (strstr(nbdata[i].name, "W3-W3") != NULL)
+        if (std::strstr(nbdata[i].name, "W3-W3") != NULL)
         {
             *nbfs += 9e-6*nrnb->n[i];
         }
-        else if (strstr(nbdata[i].name, "W3") != NULL)
+        else if (std::strstr(nbdata[i].name, "W3") != NULL)
         {
             *nbfs += 3e-6*nrnb->n[i];
         }
-        else if (strstr(nbdata[i].name, "W4-W4") != NULL)
+        else if (std::strstr(nbdata[i].name, "W4-W4") != NULL)
         {
             *nbfs += 10e-6*nrnb->n[i];
         }
-        else if (strstr(nbdata[i].name, "W4") != NULL)
+        else if (std::strstr(nbdata[i].name, "W4") != NULL)
         {
             *nbfs += 4e-6*nrnb->n[i];
         }
@@ -536,13 +538,13 @@ static double pr_av(FILE *log, t_commrec *cr,
         for (i = 0; (i < cr->nnodes); i++)
         {
             dperc = (100.0*ftot[i])/fav;
-            unb   = max(unb, dperc);
-            perc  = dperc;
+            unb   = std::max(unb, dperc);
+            perc  = static_cast<int>(dperc);
             fprintf(log, "%3d ", perc);
         }
         if (unb > 0)
         {
-            perc = 10000.0/unb;
+            perc = static_cast<int>(10000.0/unb);
             fprintf(log, "%6d%%\n\n", perc);
         }
         else
@@ -585,7 +587,7 @@ void pr_load(FILE *log, t_commrec *cr, t_nrnb nrnb[])
     }
     for (j = 0; (j < eNRNB); j++)
     {
-        av->n[j] = av->n[j]/(double)(cr->nnodes - cr->npmenodes);
+        av->n[j] = av->n[j]/static_cast<double>(cr->nnodes - cr->npmenodes);
     }
 
     fprintf(log, "\nDetailed load balancing info in percentage of average\n");
@@ -612,13 +614,13 @@ void pr_load(FILE *log, t_commrec *cr, t_nrnb nrnb[])
             for (i = 0; (i < cr->nnodes); i++)
             {
                 dperc = (100.0*nrnb[i].n[j])/av->n[j];
-                unb   = max(unb, dperc);
-                perc  = dperc;
+                unb   = std::max(unb, dperc);
+                perc  = static_cast<int>(dperc);
                 fprintf(log, "%3d ", perc);
             }
             if (unb > 0)
             {
-                perc = 10000.0/unb;
+                perc = static_cast<int>(10000.0/unb);
                 fprintf(log, "%6d%%\n", perc);
             }
             else
index f67d2bb5426ae7a5f478fcbf20f5267e7ba62b05..656417268f7c3804315b315e472652dfa6683e56 100644 (file)
@@ -38,6 +38,8 @@
 
 #include "gromacs/legacyheaders/orires.h"
 
+#include <cmath>
+
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/main.h"
 #include "gromacs/legacyheaders/network.h"
@@ -137,7 +139,7 @@ void init_orires(FILE *fplog, const gmx_mtop_t *mtop,
     else
     {
         snew(od->Dtav, od->nr);
-        od->edt   = exp(-ir->delta_t/ir->orires_tau);
+        od->edt   = std::exp(-ir->delta_t/ir->orires_tau);
         od->edt_1 = 1.0 - od->edt;
 
         /* Extend the state with the orires history */
@@ -588,7 +590,7 @@ real calc_orires_dev(const gmx_multisim_t *ms,
 
         d++;
     }
-    od->rmsdev = sqrt(wsv2/sw);
+    od->rmsdev = std::sqrt(wsv2/sw);
 
     /* Rotate the S matrices back, so we get the correct grad(tr(S D)) */
     for (ex = 0; ex < od->nex; ex++)
@@ -669,7 +671,7 @@ real orires(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
                 }
                 else
                 {
-                    dev = sqrt(dev*devins);
+                    dev = std::sqrt(dev*devins);
                     if (devins < 0)
                     {
                         dev = -dev;
index 3301969e4fdc95958d282201e51525cc9f2519a2..c650d40e9e6d9afa4e0a2913266cb7efffa96d0d 100644 (file)
@@ -174,8 +174,8 @@ int main(int argc, char *argv[])
     int        k, i, ni, mi, n, m;
 
     cr = init_par(&argc, argv);
-    n  = strtol(argv[1], NULL, 10);
-    m  = strtol(argv[2], NULL, 10);
+    n  = std::strtol(argv[1], NULL, 10);
+    m  = std::strtol(argv[2], NULL, 10);
     fprintf(stdlog, "n=%d\n", n);
     rb = mk_bin();
     snew(r, n);
similarity index 95%
rename from src/gromacs/gmxlib/readinp.c
rename to src/gromacs/gmxlib/readinp.cpp
index ccc6ccea2b1707b361598fb73d9404f8668eaf8c..a5fd617d71fbac1cfae946af0be9286032f54735 100644 (file)
 
 #include "gromacs/legacyheaders/readinp.h"
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -80,7 +83,7 @@ t_inpfile *read_inpfile(const char *fn, int *ninp,
         if (ptr)
         {
             /* Strip comment */
-            if ((cptr = strchr(buf, COMMENTSIGN)) != NULL)
+            if ((cptr = std::strchr(buf, COMMENTSIGN)) != NULL)
             {
                 *cptr = '\0';
             }
@@ -186,6 +189,10 @@ t_inpfile *read_inpfile(const char *fn, int *ninp,
                                 else
                                 {
                                     /* override */
+                                    if (!inp)
+                                    {
+                                        gmx_fatal(FARGS, "Internal inconsistency; inp[] base pointer is NULL");
+                                    }
                                     sfree(inp[found_index].value);
                                     inp[found_index].value = gmx_strdup(rbuf);
                                     sprintf(warn_buf,
@@ -220,7 +227,7 @@ t_inpfile *read_inpfile(const char *fn, int *ninp,
 
 static int inp_comp(const void *a, const void *b)
 {
-    return ((t_inpfile *)a)->count - ((t_inpfile *)b)->count;
+    return (reinterpret_cast<const t_inpfile *>(a))->count - (reinterpret_cast<const t_inpfile *>(b))->count;
 }
 
 static void sort_inp(int ninp, t_inpfile inp[])
@@ -230,7 +237,7 @@ static void sort_inp(int ninp, t_inpfile inp[])
     mm = -1;
     for (i = 0; (i < ninp); i++)
     {
-        mm = max(mm, inp[i].count);
+        mm = std::max(mm, inp[i].count);
     }
     for (i = 0; (i < ninp); i++)
     {
@@ -239,7 +246,7 @@ static void sort_inp(int ninp, t_inpfile inp[])
             inp[i].count = mm++;
         }
     }
-    gmx_qsort(inp, ninp, (size_t)sizeof(inp[0]), inp_comp);
+    gmx_qsort(inp, ninp, static_cast<size_t>(sizeof(inp[0])), inp_comp);
 }
 
 void write_inpfile(const char *fn, int ninp, t_inpfile inp[], gmx_bool bHaltOnUnknown,
@@ -331,14 +338,7 @@ static int get_einp(int *ninp, t_inpfile **inp, const char *name)
 {
     int    i;
     int    notfound = FALSE;
-    char   warn_buf[STRLEN];
 
-/*  if (inp==NULL)
-    return -1;
-   for(i=0; (i<(*ninp)); i++)
-    if (gmx_strcasecmp_min(name,(*inp)[i].name) == 0)
-      break;
-   if (i == (*ninp)) {*/
     i = search_einp(*ninp, *inp, name);
     if (i == -1)
     {
@@ -384,7 +384,7 @@ int get_eint(int *ninp, t_inpfile **inp, const char *name, int def,
     }
     else
     {
-        ret = strtol((*inp)[ii].value, &ptr, 10);
+        ret = std::strtol((*inp)[ii].value, &ptr, 10);
         if (ptr == (*inp)[ii].value)
         {
             sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not an integer value\n", (*inp)[ii].value, (*inp)[ii].name);
@@ -407,7 +407,7 @@ gmx_int64_t get_eint64(int *ninp, t_inpfile **inp,
 
     if (ii == -1)
     {
-        sprintf(buf, "%"GMX_PRId64, def);
+        sprintf(buf, "%" GMX_PRId64, def);
         (*inp)[(*ninp)-1].value = gmx_strdup(buf);
 
         return def;
@@ -535,7 +535,5 @@ int get_eeenum(int *ninp, t_inpfile **inp, const char *name, const char **defs,
 
 int get_eenum(int *ninp, t_inpfile **inp, const char *name, const char **defs)
 {
-    int dum = 0;
-
     return get_eeenum(ninp, inp, name, defs, NULL);
 }
index d22fe2159be12204fbf0d8944ec4e391c3b8c857..58943ee1328ddee04a50e93599ee36d50a9ae24c 100644 (file)
@@ -40,7 +40,7 @@
 
 #include "config.h"
 
-#include <stdlib.h>
+#include <cstdlib>
 
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/utility/fatalerror.h"
@@ -182,7 +182,7 @@ const char *gmx_get_signal_name(void)
 gmx_bool gmx_got_usr_signal(void)
 {
 #if HAVE_SIGUSR1
-    gmx_bool ret = (gmx_bool)usr_condition;
+    gmx_bool ret = static_cast<gmx_bool>(usr_condition);
     usr_condition = 0;
     return ret;
 #else
similarity index 84%
rename from src/gromacs/gmxlib/splitter.c
rename to src/gromacs/gmxlib/splitter.cpp
index cb2eb90f6b976fb595d82462a4baaf291760d9c1..cdeff9e45cd537bde3b374dae28d5e98577af986 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.
 
 #include "gromacs/legacyheaders/splitter.h"
 
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/idef.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 typedef struct {
@@ -230,9 +232,9 @@ typedef struct {
 
 static int ms_comp(const void *a, const void *b)
 {
-    t_merge_sid *ma = (t_merge_sid *)a;
-    t_merge_sid *mb = (t_merge_sid *)b;
-    int          d;
+    const t_merge_sid *ma = reinterpret_cast<const t_merge_sid *>(a);
+    const t_merge_sid *mb = reinterpret_cast<const t_merge_sid *>(b);
+    int                d;
 
     d = ma->first-mb->first;
     if (d == 0)
@@ -250,7 +252,6 @@ static int merge_sid(int at_start, int at_end, int nsid, t_sid sid[],
 {
     int          i, j, k, n, isid, ndel;
     t_merge_sid *ms;
-    int          nChanged;
 
     /* We try to remdy the following problem:
      * Atom: 1  2  3  4  5 6 7 8 9 10
@@ -272,8 +273,8 @@ static int merge_sid(int at_start, int at_end, int nsid, t_sid sid[],
         range_check(isid, -1, nsid);
         if (isid >= 0)
         {
-            ms[isid].first = min(ms[isid].first, sid[i].atom);
-            ms[isid].last  = max(ms[isid].last, sid[i].atom);
+            ms[isid].first = std::min(ms[isid].first, sid[i].atom);
+            ms[isid].last  = std::max(ms[isid].last, sid[i].atom);
         }
     }
     qsort(ms, nsid, sizeof(ms[0]), ms_comp);
@@ -286,8 +287,8 @@ static int merge_sid(int at_start, int at_end, int nsid, t_sid sid[],
         {
             if (ms[j].first <= ms[k].last)
             {
-                ms[k].last  = max(ms[k].last, ms[j].last);
-                ms[k].first = min(ms[k].first, ms[j].first);
+                ms[k].last  = std::max(ms[k].last, ms[j].last);
+                ms[k].first = std::min(ms[k].first, ms[j].first);
                 ms[j].sid   = -1;
                 ndel++;
                 j++;
@@ -309,7 +310,7 @@ static int merge_sid(int at_start, int at_end, int nsid, t_sid sid[],
         {
             for (j = k+1; (j < nsid); j++)
             {
-                memcpy(&(ms[j-1]), &(ms[j]), sizeof(ms[0]));
+                std::memcpy(&(ms[j-1]), &(ms[j]), sizeof(ms[0]));
             }
             nsid--;
         }
@@ -345,16 +346,10 @@ static int merge_sid(int at_start, int at_end, int nsid, t_sid sid[],
             }
         }
     }
-    assert(k == nsid);
-    /* Removed 2007-09-04
-       sblock->index[k+1] = natoms;
-       for(k=0; (k<natoms); k++)
-       if (sid[k].sid == -1)
-        sblock->a[n++] = k;
-       assert(n == natoms);
-     */
+
     sblock->nra = n;
-    assert(sblock->index[k] == sblock->nra);
+    GMX_RELEASE_ASSERT(sblock->index[k] == sblock->nra, "Internal inconsistency; sid merge failed");
+
     sfree(ms);
 
     return nsid;
@@ -365,9 +360,9 @@ void gen_sblocks(FILE *fp, int at_start, int at_end,
                  gmx_bool bSettle)
 {
     t_graph *g;
-    int      i, i0, j, k, istart, n;
+    int      i, i0;
     t_sid   *sid;
-    int      isid, nsid;
+    int      nsid;
 
     g = mk_graph(NULL, idef, at_start, at_end, TRUE, bSettle);
     if (debug)
@@ -388,7 +383,7 @@ void gen_sblocks(FILE *fp, int at_start, int at_end,
     }
 
     /* Now sort the shake blocks... */
-    qsort(sid+at_start, at_end-at_start, (size_t)sizeof(sid[0]), sid_comp);
+    qsort(sid+at_start, at_end-at_start, static_cast<size_t>(sizeof(sid[0])), sid_comp);
 
     if (debug)
     {
@@ -413,36 +408,7 @@ void gen_sblocks(FILE *fp, int at_start, int at_end,
      * part of the shake block too. There may be cases where blocks overlap
      * and they will have to be merged.
      */
-    nsid = merge_sid(at_start, at_end, nsid, sid, sblock);
-    /* Now sort the shake blocks again... */
-    /*qsort(sid,natoms,(size_t)sizeof(sid[0]),sid_comp);*/
-
-    /* Fill the sblock struct */
-    /*  sblock->nr  = nsid;
-       sblock->nra = natoms;
-       srenew(sblock->a,sblock->nra);
-       srenew(sblock->index,sblock->nr+1);
-
-       i    = i0;
-       isid = sid[i].sid;
-       n    = k = 0;
-       sblock->index[n++]=k;
-       while (i < natoms) {
-       istart = sid[i].atom;
-       while ((i<natoms-1) && (sid[i+1].sid == isid))
-       i++;*/
-    /* After while: we found a new block, or are thru with the atoms */
-    /*    for(j=istart; (j<=sid[i].atom); j++,k++)
-        sblock->a[k]=j;
-       sblock->index[n] = k;
-       if (i < natoms-1)
-        n++;
-       if (n > nsid)
-        gmx_fatal(FARGS,"Death Horror: nsid = %d, n= %d",nsid,n);
-       i++;
-       isid = sid[i].sid;
-       }
-     */
+    merge_sid(at_start, at_end, nsid, sid, sblock);
     sfree(sid);
     /* Due to unknown reason this free generates a problem sometimes */
     done_graph(g);
index c39508d05dbd7df312e7abd584a83181ea727bb6..2748a97093af6f6e8dbaf68bcffc5d69735d2a7b 100644 (file)
@@ -40,8 +40,8 @@
 
 #include "gromacs/legacyheaders/txtdump.h"
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
 
 #include <algorithm>
 
@@ -60,7 +60,7 @@ int pr_indent(FILE *fp, int n)
 
     for (i = 0; i < n; i++)
     {
-        (void) fprintf(fp, " ");
+        fprintf(fp, " ");
     }
     return n;
 }
@@ -73,29 +73,29 @@ int available(FILE *fp, void *p, int indent, const char *title)
         {
             pr_indent(fp, indent);
         }
-        (void) fprintf(fp, "%s: not available\n", title);
+        fprintf(fp, "%s: not available\n", title);
     }
     return (p != NULL);
 }
 
 int pr_title(FILE *fp, int indent, const char *title)
 {
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "%s:\n", title);
+    pr_indent(fp, indent);
+    fprintf(fp, "%s:\n", title);
     return (indent+INDENT);
 }
 
 int pr_title_n(FILE *fp, int indent, const char *title, int n)
 {
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "%s (%d):\n", title, n);
+    pr_indent(fp, indent);
+    fprintf(fp, "%s (%d):\n", title, n);
     return (indent+INDENT);
 }
 
 int pr_title_nxn(FILE *fp, int indent, const char *title, int n1, int n2)
 {
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "%s (%dx%d):\n", title, n1, n2);
+    pr_indent(fp, indent);
+    fprintf(fp, "%s (%dx%d):\n", title, n1, n2);
     return (indent+INDENT);
 }
 
@@ -108,8 +108,8 @@ void pr_ivec(FILE *fp, int indent, const char *title, int vec[], int n, gmx_bool
         indent = pr_title_n(fp, indent, title, n);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%d]=%d\n", title, bShowNumbers ? i : -1, vec[i]);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%d]=%d\n", title, bShowNumbers ? i : -1, vec[i]);
         }
     }
 }
@@ -134,20 +134,20 @@ void pr_ivec_block(FILE *fp, int indent, const char *title, int vec[], int n, gm
             {
                 while (i < j)
                 {
-                    (void) pr_indent(fp, indent);
-                    (void) fprintf(fp, "%s[%d]=%d\n",
-                                   title, bShowNumbers ? i : -1, vec[i]);
+                    pr_indent(fp, indent);
+                    fprintf(fp, "%s[%d]=%d\n",
+                            title, bShowNumbers ? i : -1, vec[i]);
                     i++;
                 }
             }
             else
             {
-                (void) pr_indent(fp, indent);
-                (void) fprintf(fp, "%s[%d,...,%d] = {%d,...,%d}\n",
-                               title,
-                               bShowNumbers ? i : -1,
-                               bShowNumbers ? j-1 : -1,
-                               vec[i], vec[j-1]);
+                pr_indent(fp, indent);
+                fprintf(fp, "%s[%d,...,%d] = {%d,...,%d}\n",
+                        title,
+                        bShowNumbers ? i : -1,
+                        bShowNumbers ? j-1 : -1,
+                        vec[i], vec[j-1]);
                 i = j;
             }
         }
@@ -163,9 +163,9 @@ void pr_bvec(FILE *fp, int indent, const char *title, gmx_bool vec[], int n, gmx
         indent = pr_title_n(fp, indent, title, n);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%d]=%s\n", title, bShowNumbers ? i : -1,
-                           EBOOL(vec[i]));
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%d]=%s\n", title, bShowNumbers ? i : -1,
+                    EBOOL(vec[i]));
         }
     }
 }
@@ -179,17 +179,17 @@ void pr_ivecs(FILE *fp, int indent, const char *title, ivec vec[], int n, gmx_bo
         indent = pr_title_nxn(fp, indent, title, n, DIM);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%d]={", title, bShowNumbers ? i : -1);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%d]={", title, bShowNumbers ? i : -1);
             for (j = 0; j < DIM; j++)
             {
                 if (j != 0)
                 {
-                    (void) fprintf(fp, ", ");
+                    fprintf(fp, ", ");
                 }
                 fprintf(fp, "%d", vec[i][j]);
             }
-            (void) fprintf(fp, "}\n");
+            fprintf(fp, "}\n");
         }
     }
 }
@@ -250,17 +250,17 @@ void pr_rvecs_len(FILE *fp, int indent, const char *title, rvec vec[], int n)
         indent = pr_title_nxn(fp, indent, title, n, DIM);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%5d]={", title, i);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%5d]={", title, i);
             for (j = 0; j < DIM; j++)
             {
                 if (j != 0)
                 {
-                    (void) fprintf(fp, ", ");
+                    fprintf(fp, ", ");
                 }
-                (void) fprintf(fp, "%12.5e", vec[i][j]);
+                fprintf(fp, "%12.5e", vec[i][j]);
             }
-            (void) fprintf(fp, "} len=%12.5e\n", norm(vec[i]));
+            fprintf(fp, "} len=%12.5e\n", norm(vec[i]));
         }
     }
 }
@@ -286,17 +286,17 @@ void pr_rvecs(FILE *fp, int indent, const char *title, rvec vec[], int n)
         indent = pr_title_nxn(fp, indent, title, n, DIM);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%5d]={", title, i);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%5d]={", title, i);
             for (j = 0; j < DIM; j++)
             {
                 if (j != 0)
                 {
-                    (void) fprintf(fp, ", ");
+                    fprintf(fp, ", ");
                 }
-                (void) fprintf(fp, format, vec[i][j]);
+                fprintf(fp, format, vec[i][j]);
             }
-            (void) fprintf(fp, "}\n");
+            fprintf(fp, "}\n");
         }
     }
 }
@@ -323,17 +323,17 @@ void pr_rvecs_of_dim(FILE *fp, int indent, const char *title, rvec vec[], int n,
         indent = pr_title_nxn(fp, indent, title, n, dim);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%5d]={", title, i);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%5d]={", title, i);
             for (j = 0; j < dim; j++)
             {
                 if (j != 0)
                 {
-                    (void) fprintf(fp, ", ");
+                    fprintf(fp, ", ");
                 }
-                (void) fprintf(fp, format, vec[i][j]);
+                fprintf(fp, format, vec[i][j]);
             }
-            (void) fprintf(fp, "}\n");
+            fprintf(fp, "}\n");
         }
     }
 }
@@ -344,13 +344,13 @@ void pr_reals(FILE *fp, int indent, const char *title, real *vec, int n)
 
     if (available(fp, vec, indent, title))
     {
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "%s:\t", title);
+        pr_indent(fp, indent);
+        fprintf(fp, "%s:\t", title);
         for (i = 0; i < n; i++)
         {
             fprintf(fp, "  %10g", vec[i]);
         }
-        (void) fprintf(fp, "\n");
+        fprintf(fp, "\n");
     }
 }
 
@@ -360,13 +360,13 @@ void pr_doubles(FILE *fp, int indent, const char *title, double *vec, int n)
 
     if (available(fp, vec, indent, title))
     {
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "%s:\t", title);
+        pr_indent(fp, indent);
+        fprintf(fp, "%s:\t", title);
         for (i = 0; i < n; i++)
         {
             fprintf(fp, "  %10g", vec[i]);
         }
-        (void) fprintf(fp, "\n");
+        fprintf(fp, "\n");
     }
 }
 
@@ -391,17 +391,17 @@ void pr_reals_of_dim(FILE *fp, int indent, const char *title, real *vec, int n,
         indent = pr_title_nxn(fp, indent, title, n, dim);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%5d]={", title, i);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%5d]={", title, i);
             for (j = 0; j < dim; j++)
             {
                 if (j != 0)
                 {
-                    (void) fprintf(fp, ", ");
+                    fprintf(fp, ", ");
                 }
-                (void) fprintf(fp, format, vec[i * dim  + j]);
+                fprintf(fp, format, vec[i * dim  + j]);
             }
-            (void) fprintf(fp, "}\n");
+            fprintf(fp, "}\n");
         }
     }
 }
@@ -591,18 +591,18 @@ static void pr_cosine(FILE *fp, int indent, const char *title, t_cosines *cos,
     else
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
+        pr_indent(fp, indent);
         fprintf(fp, "n = %d\n", cos->n);
         if (cos->n > 0)
         {
-            (void) pr_indent(fp, indent+2);
+            pr_indent(fp, indent+2);
             fprintf(fp, "a =");
             for (j = 0; (j < cos->n); j++)
             {
                 fprintf(fp, " %e", cos->a[j]);
             }
             fprintf(fp, "\n");
-            (void) pr_indent(fp, indent+2);
+            pr_indent(fp, indent+2);
             fprintf(fp, "phi =");
             for (j = 0; (j < cos->n); j++)
             {
@@ -1401,28 +1401,28 @@ void pr_ilist(FILE *fp, int indent, const char *title,
     if (available(fp, ilist, indent, title) && ilist->nr > 0)
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
+        pr_indent(fp, indent);
         fprintf(fp, "nr: %d\n", ilist->nr);
         if (ilist->nr > 0)
         {
-            (void) pr_indent(fp, indent);
+            pr_indent(fp, indent);
             fprintf(fp, "iatoms:\n");
             iatoms = ilist->iatoms;
             for (i = j = 0; i < ilist->nr; )
             {
 #ifndef DEBUG
-                (void) pr_indent(fp, indent+INDENT);
+                pr_indent(fp, indent+INDENT);
                 type  = *(iatoms++);
                 ftype = functype[type];
-                (void) fprintf(fp, "%d type=%d (%s)",
-                               bShowNumbers ? j : -1, bShowNumbers ? type : -1,
-                               interaction_function[ftype].name);
+                fprintf(fp, "%d type=%d (%s)",
+                        bShowNumbers ? j : -1, bShowNumbers ? type : -1,
+                        interaction_function[ftype].name);
                 j++;
                 for (k = 0; k < interaction_function[ftype].nratoms; k++)
                 {
-                    (void) fprintf(fp, " %d", *(iatoms++));
+                    fprintf(fp, " %d", *(iatoms++));
                 }
-                (void) fprintf(fp, "\n");
+                fprintf(fp, "\n");
                 i += 1+interaction_function[ftype].nratoms;
 #else
                 fprintf(fp, "%5d%5d\n", i, iatoms[i]);
@@ -1479,20 +1479,20 @@ void pr_ffparams(FILE *fp, int indent, const char *title,
     int i;
 
     indent = pr_title(fp, indent, title);
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "atnr=%d\n", ffparams->atnr);
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "ntypes=%d\n", ffparams->ntypes);
+    pr_indent(fp, indent);
+    fprintf(fp, "atnr=%d\n", ffparams->atnr);
+    pr_indent(fp, indent);
+    fprintf(fp, "ntypes=%d\n", ffparams->ntypes);
     for (i = 0; i < ffparams->ntypes; i++)
     {
-        (void) pr_indent(fp, indent+INDENT);
-        (void) fprintf(fp, "functype[%d]=%s, ",
-                       bShowNumbers ? i : -1,
-                       interaction_function[ffparams->functype[i]].name);
+        pr_indent(fp, indent+INDENT);
+        fprintf(fp, "functype[%d]=%s, ",
+                bShowNumbers ? i : -1,
+                interaction_function[ffparams->functype[i]].name);
         pr_iparams(fp, ffparams->functype[i], &ffparams->iparams[i]);
     }
-    (void) pr_double(fp, indent, "reppow", ffparams->reppow);
-    (void) pr_real(fp, indent, "fudgeQQ", ffparams->fudgeQQ);
+    pr_double(fp, indent, "reppow", ffparams->reppow);
+    pr_real(fp, indent, "fudgeQQ", ffparams->fudgeQQ);
     pr_cmap(fp, indent, "cmap", &ffparams->cmap_grid, bShowNumbers);
 }
 
@@ -1503,19 +1503,19 @@ void pr_idef(FILE *fp, int indent, const char *title, t_idef *idef, gmx_bool bSh
     if (available(fp, idef, indent, title))
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "atnr=%d\n", idef->atnr);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "ntypes=%d\n", idef->ntypes);
+        pr_indent(fp, indent);
+        fprintf(fp, "atnr=%d\n", idef->atnr);
+        pr_indent(fp, indent);
+        fprintf(fp, "ntypes=%d\n", idef->ntypes);
         for (i = 0; i < idef->ntypes; i++)
         {
-            (void) pr_indent(fp, indent+INDENT);
-            (void) fprintf(fp, "functype[%d]=%s, ",
-                           bShowNumbers ? i : -1,
-                           interaction_function[idef->functype[i]].name);
+            pr_indent(fp, indent+INDENT);
+            fprintf(fp, "functype[%d]=%s, ",
+                    bShowNumbers ? i : -1,
+                    interaction_function[idef->functype[i]].name);
             pr_iparams(fp, idef->functype[i], &idef->iparams[i]);
         }
-        (void) pr_real(fp, indent, "fudgeQQ", idef->fudgeQQ);
+        pr_real(fp, indent, "fudgeQQ", idef->fudgeQQ);
 
         for (j = 0; (j < F_NRE); j++)
         {
@@ -1530,8 +1530,8 @@ static int pr_block_title(FILE *fp, int indent, const char *title, t_block *bloc
     if (available(fp, block, indent, title))
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "nr=%d\n", block->nr);
+        pr_indent(fp, indent);
+        fprintf(fp, "nr=%d\n", block->nr);
     }
     return indent;
 }
@@ -1541,10 +1541,10 @@ static int pr_blocka_title(FILE *fp, int indent, const char *title, t_blocka *bl
     if (available(fp, block, indent, title))
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "nr=%d\n", block->nr);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "nra=%d\n", block->nra);
+        pr_indent(fp, indent);
+        fprintf(fp, "nr=%d\n", block->nr);
+        pr_indent(fp, indent);
+        fprintf(fp, "nra=%d\n", block->nra);
     }
     return indent;
 }
@@ -1558,15 +1558,15 @@ static void low_pr_blocka(FILE *fp, int indent, const char *title, t_blocka *blo
         indent = pr_blocka_title(fp, indent, title, block);
         for (i = 0; i <= block->nr; i++)
         {
-            (void) pr_indent(fp, indent+INDENT);
-            (void) fprintf(fp, "%s->index[%d]=%d\n",
-                           title, bShowNumbers ? i : -1, block->index[i]);
+            pr_indent(fp, indent+INDENT);
+            fprintf(fp, "%s->index[%d]=%d\n",
+                    title, bShowNumbers ? i : -1, block->index[i]);
         }
         for (i = 0; i < block->nra; i++)
         {
-            (void) pr_indent(fp, indent+INDENT);
-            (void) fprintf(fp, "%s->a[%d]=%d\n",
-                           title, bShowNumbers ? i : -1, block->a[i]);
+            pr_indent(fp, indent+INDENT);
+            fprintf(fp, "%s->a[%d]=%d\n",
+                    title, bShowNumbers ? i : -1, block->a[i]);
         }
     }
 }
@@ -1581,7 +1581,7 @@ void pr_block(FILE *fp, int indent, const char *title, t_block *block, gmx_bool
         start  = 0;
         if (block->index[start] != 0)
         {
-            (void) fprintf(fp, "block->index[%d] should be 0\n", start);
+            fprintf(fp, "block->index[%d] should be 0\n", start);
         }
         else
         {
@@ -1616,7 +1616,7 @@ void pr_blocka(FILE *fp, int indent, const char *title, t_blocka *block, gmx_boo
         end    = start;
         if ((ok = (block->index[start] == 0)) == 0)
         {
-            (void) fprintf(fp, "block->index[%d] should be 0\n", start);
+            fprintf(fp, "block->index[%d] should be 0\n", start);
         }
         else
         {
@@ -1642,19 +1642,19 @@ void pr_blocka(FILE *fp, int indent, const char *title, t_blocka *block, gmx_boo
                     }
                     if ((size) > (USE_WIDTH))
                     {
-                        (void) fprintf(fp, "\n");
+                        fprintf(fp, "\n");
                         size = pr_indent(fp, indent+INDENT);
                     }
                     size += fprintf(fp, "%d", block->a[j]);
                 }
-                (void) fprintf(fp, "}\n");
+                fprintf(fp, "}\n");
                 start = end;
             }
         }
         if ((end != block->nra) || (!ok))
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "tables inconsistent, dumping complete tables:\n");
+            pr_indent(fp, indent);
+            fprintf(fp, "tables inconsistent, dumping complete tables:\n");
             low_pr_blocka(fp, indent, title, block, bShowNumbers);
         }
     }
@@ -1669,9 +1669,9 @@ static void pr_strings(FILE *fp, int indent, const char *title, char ***nm, int
         indent = pr_title_n(fp, indent, title, n);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%d]={name=\"%s\"}\n",
-                           title, bShowNumbers ? i : -1, *(nm[i]));
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%d]={name=\"%s\"}\n",
+                    title, bShowNumbers ? i : -1, *(nm[i]));
         }
     }
 }
@@ -1686,9 +1686,9 @@ static void pr_strings2(FILE *fp, int indent, const char *title,
         indent = pr_title_n(fp, indent, title, n);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%d]={name=\"%s\",nameB=\"%s\"}\n",
-                           title, bShowNumbers ? i : -1, *(nm[i]), *(nmB[i]));
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%d]={name=\"%s\",nameB=\"%s\"}\n",
+                    title, bShowNumbers ? i : -1, *(nm[i]), *(nmB[i]));
         }
     }
 }
@@ -1702,11 +1702,11 @@ static void pr_resinfo(FILE *fp, int indent, const char *title, t_resinfo *resin
         indent = pr_title_n(fp, indent, title, n);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
-            (void) fprintf(fp, "%s[%d]={name=\"%s\", nr=%d, ic='%c'}\n",
-                           title, bShowNumbers ? i : -1,
-                           *(resinfo[i].name), resinfo[i].nr,
-                           (resinfo[i].ic == '\0') ? ' ' : resinfo[i].ic);
+            pr_indent(fp, indent);
+            fprintf(fp, "%s[%d]={name=\"%s\", nr=%d, ic='%c'}\n",
+                    title, bShowNumbers ? i : -1,
+                    *(resinfo[i].name), resinfo[i].nr,
+                    (resinfo[i].ic == '\0') ? ' ' : resinfo[i].ic);
         }
     }
 }
@@ -1720,7 +1720,7 @@ static void pr_atom(FILE *fp, int indent, const char *title, t_atom *atom, int n
         indent = pr_title_n(fp, indent, title, n);
         for (i = 0; i < n; i++)
         {
-            (void) pr_indent(fp, indent);
+            pr_indent(fp, indent);
             fprintf(fp, "%s[%6d]={type=%3d, typeB=%3d, ptype=%8s, m=%12.5e, "
                     "q=%12.5e, mB=%12.5e, qB=%12.5e, resind=%5d, atomnumber=%3d}\n",
                     title, i, atom[i].type, atom[i].typeB, ptype_str[atom[i].ptype],
@@ -1754,7 +1754,7 @@ static void pr_groups(FILE *fp, int indent,
     pr_grps(fp, "grp", groups->grps, groups->grpname);
     pr_strings(fp, indent, "grpname", groups->grpname, groups->ngrpname, bShowNumbers);
 
-    (void) pr_indent(fp, indent);
+    pr_indent(fp, indent);
     fprintf(fp, "groups          ");
     for (g = 0; g < egcNR; g++)
     {
@@ -1762,7 +1762,7 @@ static void pr_groups(FILE *fp, int indent,
     }
     printf("\n");
 
-    (void) pr_indent(fp, indent);
+    pr_indent(fp, indent);
     fprintf(fp, "allocated       ");
     nat_max = 0;
     for (g = 0; g < egcNR; g++)
@@ -1774,7 +1774,7 @@ static void pr_groups(FILE *fp, int indent,
 
     if (nat_max == 0)
     {
-        (void) pr_indent(fp, indent);
+        pr_indent(fp, indent);
         fprintf(fp, "groupnr[%5s] =", "*");
         for (g = 0; g < egcNR; g++)
         {
@@ -1786,7 +1786,7 @@ static void pr_groups(FILE *fp, int indent,
     {
         for (i = 0; i < nat_max; i++)
         {
-            (void) pr_indent(fp, indent);
+            pr_indent(fp, indent);
             fprintf(fp, "groupnr[%5d] =", i);
             for (g = 0; g < egcNR; g++)
             {
@@ -1839,8 +1839,8 @@ static void pr_moltype(FILE *fp, int indent, const char *title,
     int j;
 
     indent = pr_title_n(fp, indent, title, n);
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "name=\"%s\"\n", *(molt->name));
+    pr_indent(fp, indent);
+    fprintf(fp, "name=\"%s\"\n", *(molt->name));
     pr_atoms(fp, indent, "atoms", &(molt->atoms), bShowNumbers);
     pr_block(fp, indent, "cgs", &molt->cgs, bShowNumbers);
     pr_blocka(fp, indent, "excls", &molt->excls, bShowNumbers);
@@ -1856,9 +1856,9 @@ static void pr_molblock(FILE *fp, int indent, const char *title,
                         gmx_moltype_t *molt)
 {
     indent = pr_title_n(fp, indent, title, n);
-    (void) pr_indent(fp, indent);
-    (void) fprintf(fp, "%-20s = %d \"%s\"\n",
-                   "moltype", molb->type, *(molt[molb->type].name));
+    pr_indent(fp, indent);
+    fprintf(fp, "%-20s = %d \"%s\"\n",
+            "moltype", molb->type, *(molt[molb->type].name));
     pr_int(fp, indent, "#molecules", molb->nmol);
     pr_int(fp, indent, "#atoms_mol", molb->natoms_mol);
     pr_int(fp, indent, "#posres_xA", molb->nposres_xA);
@@ -1881,8 +1881,8 @@ void pr_mtop(FILE *fp, int indent, const char *title, gmx_mtop_t *mtop,
     if (available(fp, mtop, indent, title))
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "name=\"%s\"\n", *(mtop->name));
+        pr_indent(fp, indent);
+        fprintf(fp, "name=\"%s\"\n", *(mtop->name));
         pr_int(fp, indent, "#atoms", mtop->natoms);
         pr_int(fp, indent, "#molblock", mtop->nmolblock);
         for (mb = 0; mb < mtop->nmolblock; mb++)
@@ -1915,8 +1915,8 @@ void pr_top(FILE *fp, int indent, const char *title, t_topology *top, gmx_bool b
     if (available(fp, top, indent, title))
     {
         indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "name=\"%s\"\n", *(top->name));
+        pr_indent(fp, indent);
+        fprintf(fp, "name=\"%s\"\n", *(top->name));
         pr_atoms(fp, indent, "atoms", &(top->atoms), bShowNumbers);
         pr_atomtypes(fp, indent, "atomtypes", &(top->atomtypes), bShowNumbers);
         pr_block(fp, indent, "cgs", &top->cgs, bShowNumbers);
index 000a30bd194d09d383fdc21297337bb38a6256be..6dd0e3bbe053c9e3c5d8f5cf10f751c7d2251f45 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "gromacs/legacyheaders/typedefs.h"
 
-#include <string.h>
+#include <cstring>
 
 #include <algorithm>
 
@@ -56,7 +56,7 @@ int gmx_int64_to_int(gmx_int64_t step, const char *warn)
 {
     int i;
 
-    i = (int)step;
+    i = static_cast<int>(step);
 
     if (warn != NULL && (step < INT_MIN || step > INT_MAX))
     {
@@ -71,7 +71,7 @@ int gmx_int64_to_int(gmx_int64_t step, const char *warn)
 
 void init_inputrec(t_inputrec *ir)
 {
-    memset(ir, 0, (size_t)sizeof(*ir));
+    std::memset(ir, 0, sizeof(*ir));
     snew(ir->fepvals, 1);
     snew(ir->expandedvals, 1);
     snew(ir->simtempvals, 1);
similarity index 97%
rename from src/gromacs/gmxlib/viewit.c
rename to src/gromacs/gmxlib/viewit.cpp
index 61f00ae86130c601a17e7e8f44899b0e5e080b2e..bfe96e364c7d74d946f448cfd08d236d671a18ff 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.
@@ -39,8 +39,8 @@
 
 #include "gromacs/legacyheaders/viewit.h"
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/legacyheaders/macros.h"
similarity index 97%
rename from src/gromacs/gmxlib/warninp.c
rename to src/gromacs/gmxlib/warninp.cpp
index 62ce4aa2e4790dce6b91a696ab5d27776ecc2aa5..3d1eb9cadf9bfd691a47c90b2bbe2ce67d32e934 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "gromacs/legacyheaders/warninp.h"
 
-#include <string.h>
+#include <cstring>
 
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/utility/cstringutil.h"
@@ -76,7 +76,7 @@ void set_warning_line(warninp_t wi, const char *s, int line)
 {
     if (s != NULL)
     {
-        strcpy(wi->filenm, s);
+        std::strcpy(wi->filenm, s);
     }
     wi->lineno = line;
 }
@@ -101,15 +101,15 @@ static void low_warning(warninp_t wi, const char *wtype, int n, const char *s)
     {
         s = "Empty error message.";
     }
-    snew(temp, strlen(s)+indent+1);
+    snew(temp, std::strlen(s)+indent+1);
     for (i = 0; i < indent; i++)
     {
         temp[i] = ' ';
     }
     temp[indent] = '\0';
-    strcat(temp, s);
+    std::strcat(temp, s);
     temp2 = wrap_lines(temp, 78-indent, indent, FALSE);
-    if (strlen(wi->filenm) > 0)
+    if (std::strlen(wi->filenm) > 0)
     {
         if (wi->lineno != -1)
         {