*
* 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.
#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_t* oenv)
{
int xvg_format;
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;
/* 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] == '\\')
{
}
else
{
- if (gmx[g+1] != ' ')
+ if (gmx[g + 1] != ' ')
{
buf[b++] = ' ';
}
/* 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);
/* 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);
{
/* 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++;
}
}
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++] = ' ';
}
break;
}
g += std::strlen(sym[i]);
- b = std::strlen(buf);
+ b = std::strlen(buf);
}
else
{
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];
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:
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;
+ FILE* fp;
fp = gmx_fio_fopen(fn, "w");
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];
}
}
-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))
{
}
}
-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::string& s)
{
return s.empty();
}
-static bool stringIsEmpty(const char *s)
+static bool stringIsEmpty(const char* s)
{
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];
{
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];
{
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));
}
}
}
}
}
-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))
{
}
}
-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))
{
}
/* 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
{
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);
}
/* 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)
{
{
/* 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(char* ptr)
{
int i, n = 0, is[2];
int cur = 0;
-#define prev (1-cur)
+#define prev (1 - cur)
if (nullptr != ptr)
{
{
n++;
}
- else if ((i > 0) && (!is[cur] && is[prev]))
+ else if ((i > 0) && (!is[cur] && is[prev]))
{
n++;
}
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)
ptr1 = std::strchr(ptr0, '"');
if (ptr1 != nullptr)
{
- str = gmx_strdup(ptr0);
- str[ptr1-ptr0] = '\0';
+ str = gmx_strdup(ptr0);
+ str[ptr1 - ptr0] = '\0';
}
else
{
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)
*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);
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)
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;
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;
}
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;
+ FILE* fp;
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++)
{
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;
+ FILE* fp;
#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;
}
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)
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)
}
else
{
- set = a-1;
+ set = a - 1;
}
}
if (set == -1 && ((bTB && dbl < tb) || (bTE && dbl > te)))
}
if (set >= 0)
{
- *nset = set+1;
+ *nset = set + 1;
srenew(val, *nset);
srenew(val_nalloc, *nset);
val_nalloc[set] = 0;
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);
}
{
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++;
}
}
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
{
{
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);
}
}
}