Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_genion.cpp
similarity index 96%
rename from src/gromacs/gmxana/gmx_genion.c
rename to src/gromacs/gmxana/gmx_genion.cpp
index c7d980eee99a68d5b8a266427d420ef520f95c5b..a77f6b11d40e6562dc85be988406c6e4aa1419cd 100644 (file)
@@ -36,9 +36,9 @@
  */
 #include "gmxpre.h"
 
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -68,14 +68,13 @@ static void insert_ion(int nsa, int *nwater,
     rvec            dx;
     gmx_int64_t     maxrand;
 
-    ei       = -1;
     nw       = *nwater;
     maxrand  = nw;
     maxrand *= 1000;
 
     do
     {
-        ei = nw*gmx_rng_uniform_real(rng);
+        ei = static_cast<int>(nw*gmx_rng_uniform_real(rng));
         maxrand--;
     }
     while (bSet[ei] && (maxrand > 0));
@@ -122,8 +121,8 @@ static char *aname(const char *mname)
     int   i;
 
     str = gmx_strdup(mname);
-    i   = strlen(str)-1;
-    while (i > 1 && (isdigit(str[i]) || (str[i] == '+') || (str[i] == '-')))
+    i   = std::strlen(str)-1;
+    while (i > 1 && (std::isdigit(str[i]) || (str[i] == '+') || (str[i] == '-')))
     {
         str[i] = '\0';
         i--;
@@ -235,13 +234,13 @@ static void update_topol(const char *topinout, int p_num, int n_num,
 {
     FILE    *fpin, *fpout;
     char     buf[STRLEN], buf2[STRLEN], *temp, **mol_line = NULL;
-    int      line, i, nsol, nmol_line, sol_line, nsol_last;
+    int      line, i, nmol_line, sol_line, nsol_last;
     gmx_bool bMolecules;
     char     temporary_filename[STRLEN];
 
     printf("\nProcessing topology\n");
     fpin  = gmx_ffopen(topinout, "r");
-    strncpy(temporary_filename, "temp.topXXXXXX", STRLEN);
+    std::strncpy(temporary_filename, "temp.topXXXXXX", STRLEN);
     gmx_tmpnam(temporary_filename);
     fpout = gmx_ffopen(temporary_filename, "w");
 
@@ -253,8 +252,8 @@ static void update_topol(const char *topinout, int p_num, int n_num,
     while (fgets(buf, STRLEN, fpin))
     {
         line++;
-        strcpy(buf2, buf);
-        if ((temp = strchr(buf2, '\n')) != NULL)
+        std::strcpy(buf2, buf);
+        if ((temp = std::strchr(buf2, '\n')) != NULL)
         {
             temp[0] = '\0';
         }
@@ -262,14 +261,14 @@ static void update_topol(const char *topinout, int p_num, int n_num,
         if (buf2[0] == '[')
         {
             buf2[0] = ' ';
-            if ((temp = strchr(buf2, '\n')) != NULL)
+            if ((temp = std::strchr(buf2, '\n')) != NULL)
             {
                 temp[0] = '\0';
             }
             rtrim(buf2);
-            if (buf2[strlen(buf2)-1] == ']')
+            if (buf2[std::strlen(buf2)-1] == ']')
             {
-                buf2[strlen(buf2)-1] = '\0';
+                buf2[std::strlen(buf2)-1] = '\0';
                 ltrim(buf2);
                 rtrim(buf2);
                 bMolecules = (gmx_strcasecmp(buf2, "molecules") == 0);