Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / fileio / xvgr.cpp
index 86deb5740150ce7b65ff0daac3ba238ef6d7d48f..55764b0362ee81e92ed7adbadea0386f13baab2e 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,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -56,7 +56,7 @@
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/sysinfo.h"
 
-gmx_bool output_env_get_print_xvgr_codes(const gmx_output_env_t *oenv)
+gmx_bool output_env_get_print_xvgr_codes(const gmx_output_env_toenv)
 {
     int xvg_format;
 
@@ -65,12 +65,12 @@ gmx_bool output_env_get_print_xvgr_codes(const gmx_output_env_t *oenv)
     return (xvg_format == exvgXMGRACE || xvg_format == exvgXMGR);
 }
 
-static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
-                     char *buf, int buflen)
+static char* xvgrstr(const std::string& gmx, const gmx_output_env_t* oenv, char* buf, int buflen)
 {
     /* Supported greek letter names and corresponding xmgrace/xmgr symbols */
-    const char *sym[]  = { "beta", "chi", "delta", "eta", "lambda", "mu", "omega", "phi", "psi", "rho", "theta", nullptr };
-    const char  symc[] = { 'b',    'c',   'd',     'h',   'l',      'm',  'w',     'f',   'y',   'r',   'q',     '\0' };
+    const char* sym[]  = { "beta",  "chi", "delta", "eta", "lambda", "mu",
+                          "omega", "phi", "psi",   "rho", "theta",  nullptr };
+    const char  symc[] = { 'b', 'c', 'd', 'h', 'l', 'm', 'w', 'f', 'y', 'r', 'q', '\0' };
     int         xvgf;
     gmx_bool    bXVGR;
     int         g, b, i;
@@ -86,7 +86,10 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
         /* Check with the largest string we have ("lambda"), add one for \0 */
         if (b + 6 + 1 >= buflen)
         {
-            gmx_fatal(FARGS, "Output buffer length in xvgstr (%d) too small to process xvg input string '%s'", buflen, gmx.c_str());
+            gmx_fatal(FARGS,
+                      "Output buffer length in xvgstr (%d) too small to process xvg input string "
+                      "'%s'",
+                      buflen, gmx.c_str());
         }
         if (gmx[g] == '\\')
         {
@@ -129,7 +132,7 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
                 }
                 else
                 {
-                    if (gmx[g+1] != ' ')
+                    if (gmx[g + 1] != ' ')
                     {
                         buf[b++] = ' ';
                     }
@@ -141,15 +144,9 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
                 /* Backward compatibility for xmgr normal font "\4" */
                 switch (xvgf)
                 {
-                    case exvgXMGRACE:
-                        sprintf(buf+b, "%s", "\\f{}");
-                        break;
-                    case exvgXMGR:
-                        sprintf(buf+b, "%s", "\\4");
-                        break;
-                    default:
-                        buf[b] = '\0';
-                        break;
+                    case exvgXMGRACE: sprintf(buf + b, "%s", "\\f{}"); break;
+                    case exvgXMGR: sprintf(buf + b, "%s", "\\4"); break;
+                    default: buf[b] = '\0'; break;
                 }
                 g++;
                 b = strlen(buf);
@@ -159,15 +156,9 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
                 /* Backward compatibility for xmgr symbol font "\8" */
                 switch (xvgf)
                 {
-                    case exvgXMGRACE:
-                        sprintf(buf+b, "%s", "\\x");
-                        break;
-                    case exvgXMGR:
-                        sprintf(buf+b, "%s", "\\8");
-                        break;
-                    default:
-                        buf[b] = '\0';
-                        break;
+                    case exvgXMGRACE: sprintf(buf + b, "%s", "\\x"); break;
+                    case exvgXMGR: sprintf(buf + b, "%s", "\\8"); break;
+                    default: buf[b] = '\0'; break;
                 }
                 g++;
                 b = std::strlen(buf);
@@ -176,8 +167,7 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
             {
                 /* Check for special symbol */
                 i = 0;
-                while (sym[i] != nullptr &&
-                       gmx_strncasecmp(sym[i], &gmx[g], std::strlen(sym[i])) != 0)
+                while (sym[i] != nullptr && gmx_strncasecmp(sym[i], &gmx[g], std::strlen(sym[i])) != 0)
                 {
                     i++;
                 }
@@ -190,16 +180,12 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
                     }
                     switch (xvgf)
                     {
-                        case exvgXMGRACE:
-                            sprintf(buf+b, "%s%c%s", "\\x", c, "\\f{}");
-                            break;
-                        case exvgXMGR:
-                            sprintf(buf+b, "%s%c%s", "\\8", c, "\\4");
-                            break;
+                        case exvgXMGRACE: sprintf(buf + b, "%s%c%s", "\\x", c, "\\f{}"); break;
+                        case exvgXMGR: sprintf(buf + b, "%s%c%s", "\\8", c, "\\4"); break;
                         default:
-                            std::strncat(buf+b, &gmx[g], std::strlen(sym[i]));
+                            std::strncat(buf + b, &gmx[g], std::strlen(sym[i]));
                             b += std::strlen(sym[i]);
-                            if (gmx[g+std::strlen(sym[i])] != ' ')
+                            if (gmx[g + std::strlen(sym[i])] != ' ')
                             {
                                 buf[b++] = ' ';
                             }
@@ -207,7 +193,7 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
                             break;
                     }
                     g += std::strlen(sym[i]);
-                    b  = std::strlen(buf);
+                    b = std::strlen(buf);
                 }
                 else
                 {
@@ -231,9 +217,12 @@ static char *xvgrstr(const std::string &gmx, const gmx_output_env_t *oenv,
     return buf;
 }
 
-void xvgr_header(FILE *fp, const char *title, const std::string &xaxis,
-                 const std::string &yaxis, int exvg_graph_type,
-                 const gmx_output_env_t *oenv)
+void xvgr_header(FILE*                   fp,
+                 const char*             title,
+                 const std::string&      xaxis,
+                 const std::string&      yaxis,
+                 int                     exvg_graph_type,
+                 const gmx_output_env_t* oenv)
 {
     char buf[STRLEN];
 
@@ -245,18 +234,14 @@ void xvgr_header(FILE *fp, const char *title, const std::string &xaxis,
             gmx::BinaryInformationSettings settings;
             settings.generatedByHeader(true);
             settings.linePrefix("# ");
-            gmx::printBinaryInformation(fp, output_env_get_program_context(oenv),
-                                        settings);
+            gmx::printBinaryInformation(fp, output_env_get_program_context(oenv), settings);
         }
-        GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
-        fprintf(fp, "# %s is part of G R O M A C S:\n#\n",
-                output_env_get_program_display_name(oenv));
+        GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
+        fprintf(fp, "# %s is part of G R O M A C S:\n#\n", output_env_get_program_display_name(oenv));
         fprintf(fp, "# %s\n#\n", gmx::bromacs().c_str());
         fprintf(fp, "@    title \"%s\"\n", xvgrstr(title, oenv, buf, STRLEN));
-        fprintf(fp, "@    xaxis  label \"%s\"\n",
-                xvgrstr(xaxis, oenv, buf, STRLEN));
-        fprintf(fp, "@    yaxis  label \"%s\"\n",
-                xvgrstr(yaxis, oenv, buf, STRLEN));
+        fprintf(fp, "@    xaxis  label \"%s\"\n", xvgrstr(xaxis, oenv, buf, STRLEN));
+        fprintf(fp, "@    yaxis  label \"%s\"\n", xvgrstr(yaxis, oenv, buf, STRLEN));
         switch (exvg_graph_type)
         {
             case exvggtXNY:
@@ -269,21 +254,20 @@ void xvgr_header(FILE *fp, const char *title, const std::string &xaxis,
                     fprintf(fp, "@TYPE xy\n");
                 }
                 break;
-            case exvggtXYDY:
-                fprintf(fp, "@TYPE xydy\n");
-                break;
-            case exvggtXYDYDY:
-                fprintf(fp, "@TYPE xydydy\n");
-                break;
+            case exvggtXYDY: fprintf(fp, "@TYPE xydy\n"); break;
+            case exvggtXYDYDY: fprintf(fp, "@TYPE xydydy\n"); break;
         }
     }
 }
 
-FILE *xvgropen_type(const char *fn, const char *title, const std::string &xaxis,
-                    const std::string &yaxis, int exvg_graph_type,
-                    const gmx_output_env_t *oenv)
+FILE* xvgropen_type(const char*             fn,
+                    const char*             title,
+                    const std::string&      xaxis,
+                    const std::string&      yaxis,
+                    int                     exvg_graph_type,
+                    const gmx_output_env_t* oenv)
 {
-    FILE  *fp;
+    FILEfp;
 
     fp = gmx_fio_fopen(fn, "w");
 
@@ -292,19 +276,21 @@ FILE *xvgropen_type(const char *fn, const char *title, const std::string &xaxis,
     return fp;
 }
 
-FILE *xvgropen(const char *fn, const char *title, const std::string &xaxis,
-               const std::string &yaxis, const gmx_output_env_t *oenv)
+FILE* xvgropen(const char*             fn,
+               const char*             title,
+               const std::string&      xaxis,
+               const std::string&      yaxis,
+               const gmx_output_env_t* oenv)
 {
     return xvgropen_type(fn, title, xaxis, yaxis, exvggtXNY, oenv);
 }
 
-void
-xvgrclose(FILE *fp)
+void xvgrclose(FILE* fp)
 {
     gmx_fio_fclose(fp);
 }
 
-void xvgr_subtitle(FILE *out, const char *subtitle, const gmx_output_env_t *oenv)
+void xvgr_subtitle(FILE* out, const char* subtitle, const gmx_output_env_t* oenv)
 {
     char buf[STRLEN];
 
@@ -314,8 +300,7 @@ void xvgr_subtitle(FILE *out, const char *subtitle, const gmx_output_env_t *oenv
     }
 }
 
-void xvgr_view(FILE *out, real xmin, real ymin, real xmax, real ymax,
-               const gmx_output_env_t *oenv)
+void xvgr_view(FILE* out, real xmin, real ymin, real xmax, real ymax, const gmx_output_env_t* oenv)
 {
     if (output_env_get_print_xvgr_codes(oenv))
     {
@@ -323,31 +308,31 @@ void xvgr_view(FILE *out, real xmin, real ymin, real xmax, real ymax,
     }
 }
 
-void xvgr_world(FILE *out, real xmin, real ymin, real xmax, real ymax,
-                const gmx_output_env_t *oenv)
+void xvgr_world(FILE* out, real xmin, real ymin, real xmax, real ymax, const gmx_output_env_t* oenv)
 {
     if (output_env_get_print_xvgr_codes(oenv))
     {
-        fprintf(out, "@ world xmin %g\n"
+        fprintf(out,
+                "@ world xmin %g\n"
                 "@ world ymin %g\n"
                 "@ world xmax %g\n"
-                "@ world ymax %g\n", xmin, ymin, xmax, ymax);
+                "@ world ymax %g\n",
+                xmin, ymin, xmax, ymax);
     }
 }
 
-static bool stringIsEmpty(const std::string &s)
+static bool stringIsEmpty(const std::strings)
 {
     return s.empty();
 }
 
-static bool stringIsEmpty(const char *s)
+static bool stringIsEmpty(const chars)
 {
     return (s == nullptr || s[0] == '\0');
 }
 
-template <typename T>
-static void xvgr_legend(FILE *out, int nsets, const T * setname,
-                        const gmx_output_env_t *oenv)
+template<typename T>
+static void xvgr_legend(FILE* out, int nsets, const T* setname, const gmx_output_env_t* oenv)
 {
     int  i;
     char buf[STRLEN];
@@ -366,34 +351,27 @@ static void xvgr_legend(FILE *out, int nsets, const T * setname,
             {
                 if (output_env_get_xvg_format(oenv) == exvgXMGR)
                 {
-                    fprintf(out, "@ legend string %d \"%s\"\n",
-                            i, xvgrstr(setname[i], oenv, buf, STRLEN));
+                    fprintf(out, "@ legend string %d \"%s\"\n", i, xvgrstr(setname[i], oenv, buf, STRLEN));
                 }
                 else
                 {
-                    fprintf(out, "@ s%d legend \"%s\"\n",
-                            i, xvgrstr(setname[i], oenv, buf, STRLEN));
+                    fprintf(out, "@ s%d legend \"%s\"\n", i, xvgrstr(setname[i], oenv, buf, STRLEN));
                 }
             }
         }
     }
 }
 
-void xvgrLegend(FILE                           *out,
-                const std::vector<std::string> &setNames,
-                const struct gmx_output_env_t  *oenv)
+void xvgrLegend(FILE* out, const std::vector<std::string>& setNames, const struct gmx_output_env_t* oenv)
 {
     xvgr_legend(out, setNames.size(), setNames.data(), oenv);
 }
-void xvgr_legend(FILE *out, int nsets, const char*const* setnames,
-                 const struct gmx_output_env_t *oenv)
+void xvgr_legend(FILE* out, int nsets, const char* const* setnames, const struct gmx_output_env_t* oenv)
 {
-    xvgr_legend<const char *>(out, nsets, setnames, oenv);
+    xvgr_legend<const char*>(out, nsets, setnames, oenv);
 }
 
-void xvgr_new_dataset(FILE *out, int nr_first, int nsets,
-                      const char **setname,
-                      const gmx_output_env_t *oenv)
+void xvgr_new_dataset(FILE* out, int nr_first, int nsets, const char** setname, const gmx_output_env_t* oenv)
 {
     int  i;
     char buf[STRLEN];
@@ -407,13 +385,13 @@ void xvgr_new_dataset(FILE *out, int nr_first, int nsets,
             {
                 if (output_env_get_xvg_format(oenv) == exvgXMGR)
                 {
-                    fprintf(out, "@ legend string %d \"%s\"\n",
-                            i+nr_first, xvgrstr(setname[i], oenv, buf, STRLEN));
+                    fprintf(out, "@ legend string %d \"%s\"\n", i + nr_first,
+                            xvgrstr(setname[i], oenv, buf, STRLEN));
                 }
                 else
                 {
-                    fprintf(out, "@ s%d legend \"%s\"\n",
-                            i+nr_first, xvgrstr(setname[i], oenv, buf, STRLEN));
+                    fprintf(out, "@ s%d legend \"%s\"\n", i + nr_first,
+                            xvgrstr(setname[i], oenv, buf, STRLEN));
                 }
             }
         }
@@ -424,8 +402,7 @@ void xvgr_new_dataset(FILE *out, int nr_first, int nsets,
     }
 }
 
-void xvgr_line_props(FILE *out, int NrSet, int LineStyle, int LineColor,
-                     const gmx_output_env_t *oenv)
+void xvgr_line_props(FILE* out, int NrSet, int LineStyle, int LineColor, const gmx_output_env_t* oenv)
 {
     if (output_env_get_print_xvgr_codes(oenv))
     {
@@ -435,14 +412,22 @@ void xvgr_line_props(FILE *out, int NrSet, int LineStyle, int LineColor,
     }
 }
 
-static const char *LocTypeStr[] = { "view", "world" };
-static const char *BoxFillStr[] = { "none", "color", "pattern" };
-
-void xvgr_box(FILE *out,
-              int LocType,
-              real xmin, real ymin, real xmax, real ymax,
-              int LineStyle, int LineWidth, int LineColor,
-              int BoxFill, int BoxColor, int BoxPattern, const gmx_output_env_t *oenv)
+static const char* LocTypeStr[] = { "view", "world" };
+static const char* BoxFillStr[] = { "none", "color", "pattern" };
+
+void xvgr_box(FILE*                   out,
+              int                     LocType,
+              real                    xmin,
+              real                    ymin,
+              real                    xmax,
+              real                    ymax,
+              int                     LineStyle,
+              int                     LineWidth,
+              int                     LineColor,
+              int                     BoxFill,
+              int                     BoxColor,
+              int                     BoxPattern,
+              const gmx_output_env_t* oenv)
 {
     if (output_env_get_print_xvgr_codes(oenv))
     {
@@ -461,10 +446,10 @@ void xvgr_box(FILE *out,
 }
 
 /* reads a line into ptr, adjusting len and renewing ptr if neccesary */
-static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen)
+static char* fgets3(FILE* fp, char** ptr, int* len, int maxlen)
 {
-    int   len_remaining = *len; /* remaining amount of allocated bytes in buf */
-    int   curp          = 0;    /* current position in buf to read into */
+    int len_remaining = *len; /* remaining amount of allocated bytes in buf */
+    int curp          = 0;    /* current position in buf to read into */
 
     do
     {
@@ -473,7 +458,7 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen)
             if (*len + STRLEN < maxlen)
             {
                 /* This line is longer than len characters, let's increase len! */
-                *len          += STRLEN;
+                *len += STRLEN;
                 len_remaining += STRLEN;
                 srenew(*ptr, *len);
             }
@@ -489,10 +474,9 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen)
             /* if last line, skip */
             return nullptr;
         }
-        curp         += len_remaining-1; /* overwrite the nul char in next iteration */
+        curp += len_remaining - 1; /* overwrite the nul char in next iteration */
         len_remaining = 1;
-    }
-    while ((std::strchr(*ptr, '\n') == nullptr) && (feof(fp) == 0));
+    } while ((std::strchr(*ptr, '\n') == nullptr) && (feof(fp) == 0));
 
     if (*len + STRLEN >= maxlen)
     {
@@ -507,20 +491,20 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen)
     {
         /* now remove newline */
         int slen = std::strlen(*ptr);
-        if ((*ptr)[slen-1] == '\n')
+        if ((*ptr)[slen - 1] == '\n')
         {
-            (*ptr)[slen-1] = '\0';
+            (*ptr)[slen - 1] = '\0';
         }
     }
 
     return *ptr;
 }
 
-static int wordcount(char *ptr)
+static int wordcount(charptr)
 {
     int i, n = 0, is[2];
     int cur = 0;
-#define prev (1-cur)
+#define prev (1 - cur)
 
     if (nullptr != ptr)
     {
@@ -531,7 +515,7 @@ static int wordcount(char *ptr)
             {
                 n++;
             }
-            else if ((i > 0)  && (!is[cur] && is[prev]))
+            else if ((i > 0) && (!is[cur] && is[prev]))
             {
                 n++;
             }
@@ -541,10 +525,10 @@ static int wordcount(char *ptr)
     return n;
 }
 
-static char *read_xvgr_string(const char *line)
+static char* read_xvgr_string(const char* line)
 {
     const char *ptr0, *ptr1;
-    char       *str;
+    char*       str;
 
     ptr0 = std::strchr(line, '"');
     if (ptr0 != nullptr)
@@ -553,8 +537,8 @@ static char *read_xvgr_string(const char *line)
         ptr1 = std::strchr(ptr0, '"');
         if (ptr1 != nullptr)
         {
-            str            = gmx_strdup(ptr0);
-            str[ptr1-ptr0] = '\0';
+            str              = gmx_strdup(ptr0);
+            str[ptr1 - ptr0] = '\0';
         }
         else
         {
@@ -569,23 +553,22 @@ static char *read_xvgr_string(const char *line)
     return str;
 }
 
-int read_xvg_legend(const char *fn, double ***y, int *ny,
-                    char **subtitle, char ***legend)
+int read_xvg_legend(const char* fn, double*** y, int* ny, char** subtitle, char*** legend)
 {
-    FILE    *fp;
-    char    *ptr;
-    char    *base = nullptr;
-    char    *fmt  = nullptr;
+    FILE*    fp;
+    char*    ptr;
+    char*    base = nullptr;
+    char*    fmt  = nullptr;
     int      k, line = 0, nny, nx, maxx, rval, legend_nalloc, set, nchar;
     double   lf;
-    double **yy = nullptr;
-    char    *tmpbuf;
+    double** yy = nullptr;
+    char*    tmpbuf;
     int      len = STRLEN;
-    *ny  = 0;
-    nny  = 0;
-    nx   = 0;
-    maxx = 0;
-    fp   = gmx_fio_fopen(fn, "r");
+    *ny          = 0;
+    nny          = 0;
+    nx           = 0;
+    maxx         = 0;
+    fp           = gmx_fio_fopen(fn, "r");
 
     snew(tmpbuf, len);
     if (subtitle != nullptr)
@@ -598,7 +581,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
         *legend = nullptr;
     }
 
-    while ((ptr = fgets3(fp, &tmpbuf, &len, 10*STRLEN)) != nullptr && ptr[0] != '&')
+    while ((ptr = fgets3(fp, &tmpbuf, &len, 10 * STRLEN)) != nullptr && ptr[0] != '&')
     {
         line++;
         trim(ptr);
@@ -660,8 +643,8 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
                     return 0;
                 }
                 snew(yy, nny);
-                snew(fmt, 3*nny+1);
-                snew(base, 3*nny+1);
+                snew(fmt, 3 * nny + 1);
+                snew(base, 3 * nny + 1);
             }
             /* Allocate column space */
             if (nx >= maxx)
@@ -688,14 +671,13 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
                     break;
                 }
                 yy[k][nx] = lf;
-                srenew(fmt, 3*(nny+1)+1);
-                srenew(base, 3*nny+1);
+                srenew(fmt, 3 * (nny + 1) + 1);
+                srenew(base, 3 * nny + 1);
                 std::strcat(base, "%*s");
             }
             if (k != nny)
             {
-                fprintf(stderr, "Only %d columns on line %d in file %s\n",
-                        k, line, fn);
+                fprintf(stderr, "Only %d columns on line %d in file %s\n", k, line, fn);
                 for (; (k < nny); k++)
                 {
                     yy[k][nx] = 0.0;
@@ -716,8 +698,8 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
         if (*ny - 1 > legend_nalloc)
         {
             assert(legend);
-            srenew(*legend, *ny-1);
-            for (set = legend_nalloc; set < *ny-1; set++)
+            srenew(*legend, *ny - 1);
+            for (set = legend_nalloc; set < *ny - 1; set++)
             {
                 (*legend)[set] = nullptr;
             }
@@ -727,21 +709,20 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
     return nx;
 }
 
-int read_xvg(const char *fn, double ***y, int *ny)
+int read_xvg(const char* fn, double*** y, int* ny)
 {
     return read_xvg_legend(fn, y, ny, nullptr, nullptr);
 }
 
-void write_xvg(const char *fn, const char *title, int nx, int ny, real **y,
-               const char **leg, const gmx_output_env_t *oenv)
+void write_xvg(const char* fn, const char* title, int nx, int ny, real** y, const char** leg, const gmx_output_env_t* oenv)
 {
-    FILE *fp;
+    FILEfp;
     int   i, j;
 
     fp = xvgropen(fn, title, "X", "Y", oenv);
     if (leg)
     {
-        xvgr_legend(fp, ny-1, leg, oenv);
+        xvgr_legend(fp, ny - 1, leg, oenv);
     }
     for (i = 0; (i < nx); i++)
     {
@@ -754,18 +735,26 @@ void write_xvg(const char *fn, const char *title, int nx, int ny, real **y,
     xvgrclose(fp);
 }
 
-real **read_xvg_time(const char *fn,
-                     gmx_bool bHaveT, gmx_bool bTB, real tb, gmx_bool bTE, real te,
-                     int nsets_in, int *nset, int *nval, real *dt, real **t)
+real** read_xvg_time(const char* fn,
+                     gmx_bool    bHaveT,
+                     gmx_bool    bTB,
+                     real        tb,
+                     gmx_bool    bTE,
+                     real        te,
+                     int         nsets_in,
+                     int*        nset,
+                     int*        nval,
+                     real*       dt,
+                     real**      t)
 {
-    FILE      *fp;
+    FILEfp;
 #define MAXLINELEN 16384
-    char       line0[MAXLINELEN];
-    char      *line;
-    int        t_nalloc, *val_nalloc, a, narg, n, sin, set, nchar;
-    double     dbl;
-    gmx_bool   bEndOfSet, bTimeInRange, bFirstLine = TRUE;
-    real     **val;
+    char     line0[MAXLINELEN];
+    char*    line;
+    int      t_nalloc, *val_nalloc, a, narg, n, sin, set, nchar;
+    double   dbl;
+    gmx_bool bEndOfSet, bTimeInRange, bFirstLine = TRUE;
+    real**   val;
 
     t_nalloc   = 0;
     *t         = nullptr;
@@ -807,7 +796,8 @@ real **read_xvg_time(const char *fn,
                     }
                     else if (a == 1)
                     {
-                        fprintf(stderr, "Found only 1 number on line, "
+                        fprintf(stderr,
+                                "Found only 1 number on line, "
                                 "assuming no time is present.\n");
                         bHaveT = FALSE;
                         if (nsets_in > 1)
@@ -819,8 +809,8 @@ real **read_xvg_time(const char *fn,
 
                 a            = 0;
                 bTimeInRange = TRUE;
-                while ((a < narg || (nsets_in == 1 && n == 0)) &&
-                       sscanf(line, "%lf%n", &dbl, &nchar) == 1 && bTimeInRange)
+                while ((a < narg || (nsets_in == 1 && n == 0))
+                       && sscanf(line, "%lf%n", &dbl, &nchar) == 1 && bTimeInRange)
                 {
                     /* Use set=-1 as the time "set" */
                     if (sin)
@@ -842,7 +832,7 @@ real **read_xvg_time(const char *fn,
                         }
                         else
                         {
-                            set = a-1;
+                            set = a - 1;
                         }
                     }
                     if (set == -1 && ((bTB && dbl < tb) || (bTE && dbl > te)))
@@ -860,7 +850,7 @@ real **read_xvg_time(const char *fn,
                             }
                             if (set >= 0)
                             {
-                                *nset = set+1;
+                                *nset = set + 1;
                                 srenew(val, *nset);
                                 srenew(val_nalloc, *nset);
                                 val_nalloc[set] = 0;
@@ -893,7 +883,7 @@ real **read_xvg_time(const char *fn,
                     a++;
                     line += nchar;
                 }
-                if (line0[strlen(line0)-1] != '\n')
+                if (line0[strlen(line0) - 1] != '\n')
                 {
                     fprintf(stderr, "File %s does not end with a newline, ignoring the last line\n", fn);
                 }
@@ -907,9 +897,10 @@ real **read_xvg_time(const char *fn,
                     {
                         if (a != narg)
                         {
-                            fprintf(stderr, "Invalid line in %s:\n%s"
+                            fprintf(stderr,
+                                    "Invalid line in %s:\n%s"
                                     "Using zeros for the last %d sets\n",
-                                    fn, line0, narg-a);
+                                    fn, line0, narg - a);
                         }
                         n++;
                     }
@@ -933,7 +924,7 @@ real **read_xvg_time(const char *fn,
             }
             if (n > 1)
             {
-                *dt = static_cast<real>((*t)[n-1]-(*t)[0])/(n-1.0);
+                *dt = static_cast<real>((*t)[n - 1] - (*t)[0]) / (n - 1.0);
             }
             else
             {
@@ -944,11 +935,9 @@ real **read_xvg_time(const char *fn,
         {
             if (n < *nval)
             {
-                fprintf(stderr, "Set %d is shorter (%d) than the previous set (%d)\n",
-                        sin+1, n, *nval);
+                fprintf(stderr, "Set %d is shorter (%d) than the previous set (%d)\n", sin + 1, n, *nval);
                 *nval = n;
-                fprintf(stderr, "Will use only the first %d points of every set\n",
-                        *nval);
+                fprintf(stderr, "Will use only the first %d points of every set\n", *nval);
             }
         }
     }