More files to C++.
[alexxy/gromacs.git] / src / gromacs / gmxlib / matio.cpp
similarity index 98%
rename from src/gromacs/gmxlib/matio.c
rename to src/gromacs/gmxlib/matio.cpp
index f13351cc2fef5eb5b60aa3a3e59533182209f0d2..7ab142ba7bfde8974b542e98e50b80b7c51b99b2 100644 (file)
@@ -38,6 +38,9 @@
 
 #include <stdio.h>
 #include <ctype.h>
+
+#include <algorithm>
+
 #include "sysstuff.h"
 #include "futil.h"
 #include "string2.h"
@@ -283,7 +286,7 @@ void read_xpm_entry(FILE *in, t_matrix *mm)
 {
     t_mapping   *map;
     char        *line_buf = NULL, *line = NULL, *str, buf[256] = {0};
-    int          i, m, col_len, nch, n_axis_x, n_axis_y, llmax;
+    int          i, m, col_len, nch = 0, n_axis_x, n_axis_y, llmax;
     int          llalloc = 0;
     unsigned int r, g, b;
     double       u;
@@ -351,7 +354,7 @@ void read_xpm_entry(FILE *in, t_matrix *mm)
             {
                 gmx_fatal(FARGS, "Dimensions of xpm-file have to be larger than 0\n");
             }
-            llmax        = max(STRLEN, mm->nx+10);
+            llmax        = std::max(STRLEN, mm->nx+10);
             bGetOnWithIt = TRUE;
         }
     }
@@ -360,6 +363,10 @@ void read_xpm_entry(FILE *in, t_matrix *mm)
         fprintf(debug, "mm->nx %d mm->ny %d mm->nmap %d nch %d\n",
                 mm->nx, mm->ny, mm->nmap, nch);
     }
+    if (nch == 0)
+    {
+        gmx_fatal(FARGS, "Number of characters per pixel not found in xpm\n");
+    }
 
     /* Read color map */
     snew(map, mm->nmap);
@@ -441,7 +448,6 @@ void read_xpm_entry(FILE *in, t_matrix *mm)
     /* Read axes, if there are any */
     n_axis_x     = 0;
     n_axis_y     = 0;
-    bGetOnWithIt = FALSE;
     bSetLine     = FALSE;
     do
     {
@@ -659,7 +665,8 @@ static int calc_nmid(int nlevels, real lo, real mid, real hi)
 {
     /* Take care that we have at least 1 entry in the mid to hi range
      */
-    return min(max(0, ((mid-lo)/(hi-lo))*(nlevels-1)), nlevels-1);
+    return std::min(std::max(0, static_cast<int>(((mid-lo)/(hi-lo))*(nlevels-1))),
+                    nlevels-1);
 }
 
 void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
@@ -766,7 +773,7 @@ static void pr_discrete_cmap(FILE *out, int *nlevel, int i0)
 
     int    i, n;
 
-    *nlevel = min(16, *nlevel);
+    *nlevel = std::min(16, *nlevel);
     n       = *nlevel;
     for (i = 0; (i < n); i++)
     {
@@ -789,8 +796,7 @@ void write_xpm_map_split(FILE *out, int n_x, int n_y,
                          int *nlevel_bot, real lo_bot, real hi_bot,
                          t_rgb rlo_bot, t_rgb rhi_bot)
 {
-    int    i, ntot;
-    real   r, g, b, fac;
+    int    ntot;
 
     ntot = *nlevel_top + *nlevel_bot;
     if (ntot > NMAP)