From 51558bf6315dc1c375835834bc685ad65c349549 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Thu, 20 Apr 2017 11:18:29 +0200 Subject: [PATCH] Clean up memory usage with oenv and xvg writing Change-Id: I41386eaa7a045d115599b8f8a1839d12f7e4400d --- src/gromacs/fileio/matio.cpp | 19 ++++++++++--------- src/gromacs/fileio/matio.h | 16 +++++++++------- src/gromacs/fileio/oenv.cpp | 25 ++++++++----------------- src/gromacs/fileio/oenv.h | 21 +++++++-------------- src/gromacs/fileio/xvgr.cpp | 20 ++++++++++---------- src/gromacs/fileio/xvgr.h | 24 +++++++++--------------- src/gromacs/gmxana/gmx_anaeig.cpp | 5 +++-- src/gromacs/gmxana/gmx_cluster.cpp | 21 +++++++++++---------- src/gromacs/gmxana/gmx_clustsize.cpp | 15 +++++++-------- src/gromacs/gmxana/gmx_covar.cpp | 2 +- src/gromacs/gmxana/gmx_do_dssp.cpp | 2 +- src/gromacs/gmxana/gmx_hbond.cpp | 2 +- src/gromacs/gmxana/gmx_mindist.cpp | 2 +- src/gromacs/gmxana/gmx_msd.cpp | 10 +++++----- src/gromacs/gmxana/gmx_rms.cpp | 2 +- src/gromacs/gmxana/gmx_trjcat.cpp | 21 ++++++++++++--------- src/gromacs/gmxana/gmx_trjconv.cpp | 2 +- 17 files changed, 97 insertions(+), 112 deletions(-) diff --git a/src/gromacs/fileio/matio.cpp b/src/gromacs/fileio/matio.cpp index 0fb307ca73..56eb00cc52 100644 --- a/src/gromacs/fileio/matio.cpp +++ b/src/gromacs/fileio/matio.cpp @@ -44,6 +44,7 @@ #include #include +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/math/utilities.h" @@ -1094,8 +1095,8 @@ void write_xpm_m(FILE *out, t_matrix m) } void write_xpm3(FILE *out, unsigned int flags, - const char *title, const char *legend, - const char *label_x, const char *label_y, + const std::string &title, const std::string &legend, + const std::string &label_x, const std::string &label_y, int n_x, int n_y, real axis_x[], real axis_y[], real *mat[], real lo, real mid, real hi, t_rgb rlo, t_rgb rmid, t_rgb rhi, int *nlevels) @@ -1109,7 +1110,7 @@ void write_xpm3(FILE *out, unsigned int flags, gmx_fatal(FARGS, "hi (%g) <= lo (%g)", hi, lo); } - write_xpm_header(out, title, legend, label_x, label_y, FALSE); + write_xpm_header(out, title.c_str(), legend.c_str(), label_x.c_str(), label_y.c_str(), FALSE); write_xpm_map3(out, n_x, n_y, nlevels, lo, mid, hi, rlo, rmid, rhi); write_xpm_axis(out, "x", flags & MAT_SPATIAL_X, n_x, axis_x); write_xpm_axis(out, "y", flags & MAT_SPATIAL_Y, n_y, axis_y); @@ -1117,8 +1118,8 @@ void write_xpm3(FILE *out, unsigned int flags, } void write_xpm_split(FILE *out, unsigned int flags, - const char *title, const char *legend, - const char *label_x, const char *label_y, + const std::string &title, const std::string &legend, + const std::string &label_x, const std::string &label_y, int n_x, int n_y, real axis_x[], real axis_y[], real *mat[], real lo_top, real hi_top, int *nlevel_top, @@ -1144,7 +1145,7 @@ void write_xpm_split(FILE *out, unsigned int flags, gmx_impl("Can not plot more than 16 discrete colors"); } - write_xpm_header(out, title, legend, label_x, label_y, FALSE); + write_xpm_header(out, title.c_str(), legend.c_str(), label_x.c_str(), label_y.c_str(), FALSE); write_xpm_map_split(out, n_x, n_y, nlevel_top, lo_top, hi_top, rlo_top, rhi_top, bDiscreteColor, nlevel_bot, lo_bot, hi_bot, rlo_bot, rhi_bot); write_xpm_axis(out, "x", flags & MAT_SPATIAL_X, n_x, axis_x); @@ -1154,8 +1155,8 @@ void write_xpm_split(FILE *out, unsigned int flags, } void write_xpm(FILE *out, unsigned int flags, - const char *title, const char *legend, - const char *label_x, const char *label_y, + const std::string &title, const std::string &legend, + const std::string &label_x, const std::string &label_y, int n_x, int n_y, real axis_x[], real axis_y[], real *mat[], real lo, real hi, t_rgb rlo, t_rgb rhi, int *nlevels) @@ -1181,7 +1182,7 @@ void write_xpm(FILE *out, unsigned int flags, gmx_fatal(FARGS, "hi (%f) <= lo (%f)", hi, lo); } - write_xpm_header(out, title, legend, label_x, label_y, FALSE); + write_xpm_header(out, title.c_str(), legend.c_str(), label_x.c_str(), label_y.c_str(), FALSE); write_xpm_map(out, n_x, n_y, nlevels, lo, hi, rlo, rhi); write_xpm_axis(out, "x", flags & MAT_SPATIAL_X, n_x, axis_x); write_xpm_axis(out, "y", flags & MAT_SPATIAL_Y, n_y, axis_y); diff --git a/src/gromacs/fileio/matio.h b/src/gromacs/fileio/matio.h index 4bb767ae2c..a060583703 100644 --- a/src/gromacs/fileio/matio.h +++ b/src/gromacs/fileio/matio.h @@ -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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2017, 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. @@ -40,6 +40,8 @@ #include +#include + #include "gromacs/fileio/rgb.h" #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" @@ -125,8 +127,8 @@ void write_xpm_m(FILE *out, t_matrix m); /* Writes a t_matrix struct to .xpm file */ void write_xpm3(FILE *out, unsigned int flags, - const char *title, const char *legend, - const char *label_x, const char *label_y, + const std::string &title, const std::string &legend, + const std::string &label_x, const std::string &label_y, int n_x, int n_y, real axis_x[], real axis_y[], real *mat[], real lo, real mid, real hi, t_rgb rlo, t_rgb rmid, t_rgb rhi, int *nlevels); @@ -134,8 +136,8 @@ void write_xpm3(FILE *out, unsigned int flags, * Writes a colormap varying as rlo -> rmid -> rhi. */ void write_xpm_split(FILE *out, unsigned int flags, - const char *title, const char *legend, - const char *label_x, const char *label_y, + const std::string &title, const std::string &legend, + const std::string &label_x, const std::string &label_y, int n_x, int n_y, real axis_x[], real axis_y[], real *mat[], real lo_top, real hi_top, int *nlevel_top, @@ -150,8 +152,8 @@ void write_xpm_split(FILE *out, unsigned int flags, */ void write_xpm(FILE *out, unsigned int flags, - const char *title, const char *legend, - const char *label_x, const char *label_y, + const std::string &title, const std::string &legend, + const std::string &label_x, const std::string &label_y, int n_x, int n_y, real t_x[], real t_y[], real *mat[], real lo, real hi, t_rgb rlo, t_rgb rhi, int *nlevels); diff --git a/src/gromacs/fileio/oenv.cpp b/src/gromacs/fileio/oenv.cpp index 4c1f5fbf25..c1d19ce08e 100644 --- a/src/gromacs/fileio/oenv.cpp +++ b/src/gromacs/fileio/oenv.cpp @@ -41,6 +41,7 @@ #include "gromacs/utility/exceptions.h" #include "gromacs/utility/programcontext.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/stringutil.h" struct gmx_output_env_t { @@ -126,31 +127,21 @@ int output_env_get_verbosity(const gmx_output_env_t *oenv) return oenv->verbosity; } -const char *output_env_get_time_unit(const gmx_output_env_t *oenv) +std::string output_env_get_time_unit(const gmx_output_env_t *oenv) { return time_units_str[oenv->time_unit]; } -const char *output_env_get_time_label(const gmx_output_env_t *oenv) +std::string output_env_get_time_label(const gmx_output_env_t *oenv) { - char *label; - snew(label, 20); - - sprintf(label, "Time (%s)", time_units_str[oenv->time_unit] ? - time_units_str[oenv->time_unit] : "ps"); - - return label; + return gmx::formatString("Time (%s)", time_units_str[oenv->time_unit] ? + time_units_str[oenv->time_unit] : "ps"); } -const char *output_env_get_xvgr_tlabel(const gmx_output_env_t *oenv) +std::string output_env_get_xvgr_tlabel(const gmx_output_env_t *oenv) { - char *label; - snew(label, 20); - - sprintf(label, "Time (%s)", time_units_xvgr[oenv->time_unit] ? - time_units_xvgr[oenv->time_unit] : "ps"); - - return label; + return gmx::formatString("Time (%s)", time_units_xvgr[oenv->time_unit] ? + time_units_xvgr[oenv->time_unit] : "ps"); } real output_env_get_time_factor(const gmx_output_env_t *oenv) diff --git a/src/gromacs/fileio/oenv.h b/src/gromacs/fileio/oenv.h index e3dcecc403..51c7b23b3a 100644 --- a/src/gromacs/fileio/oenv.h +++ b/src/gromacs/fileio/oenv.h @@ -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,2015, by the GROMACS development team, led by + * Copyright (c) 2012,2014,2015,2017, 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. @@ -37,13 +37,11 @@ #ifndef GMX_FILEIO_OENV_H #define GMX_FILEIO_OENV_H +#include + #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" -#ifdef __cplusplus -extern "C" { -#endif - struct gmx_output_env_t; /* output_env member functions */ @@ -77,14 +75,14 @@ void output_env_done(gmx_output_env_t *oenv); int output_env_get_verbosity(const gmx_output_env_t *oenv); /* return the verbosity */ -const char *output_env_get_time_unit(const gmx_output_env_t *oenv); +std::string output_env_get_time_unit(const gmx_output_env_t *oenv); /* return time unit (e.g. ps or ns) */ -const char *output_env_get_time_label(const gmx_output_env_t *oenv); +std::string output_env_get_time_label(const gmx_output_env_t *oenv); /* return time unit label (e.g. "Time (ps)") */ -const char *output_env_get_xvgr_tlabel(const gmx_output_env_t *oenv); -/* retrun x-axis time label for xmgr */ +std::string output_env_get_xvgr_tlabel(const gmx_output_env_t *oenv); +/* return x-axis time label for xmgr */ real output_env_get_time_factor(const gmx_output_env_t *oenv); /* return time conversion factor from ps (i.e. 1e-3 for ps->ns) */ @@ -109,9 +107,6 @@ xvg_format_t output_env_get_xvg_format(const gmx_output_env_t *oenv); */ const char *output_env_get_program_display_name(const gmx_output_env_t *oenv); -#ifdef __cplusplus -} - namespace gmx { class IProgramContext; @@ -133,5 +128,3 @@ const gmx::IProgramContext & output_env_get_program_context(const gmx_output_env_t *oenv); #endif - -#endif diff --git a/src/gromacs/fileio/xvgr.cpp b/src/gromacs/fileio/xvgr.cpp index 226d9d242b..2dd05b986e 100644 --- a/src/gromacs/fileio/xvgr.cpp +++ b/src/gromacs/fileio/xvgr.cpp @@ -65,7 +65,7 @@ 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 char *gmx, const gmx_output_env_t *oenv, +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 */ @@ -86,7 +86,7 @@ static char *xvgrstr(const char *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); + gmx_fatal(FARGS, "Output buffer length in xvgstr (%d) too small to process xvg input string '%s'", buflen, gmx.c_str()); } if (gmx[g] == '\\') { @@ -177,7 +177,7 @@ static char *xvgrstr(const char *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) + gmx_strncasecmp(sym[i], &gmx[g], std::strlen(sym[i])) != 0) { i++; } @@ -197,7 +197,7 @@ static char *xvgrstr(const char *gmx, const gmx_output_env_t *oenv, 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])] != ' ') { @@ -231,8 +231,8 @@ static char *xvgrstr(const char *gmx, const gmx_output_env_t *oenv, return buf; } -void xvgr_header(FILE *fp, const char *title, const char *xaxis, - const char *yaxis, int exvg_graph_type, +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]; @@ -280,8 +280,8 @@ void xvgr_header(FILE *fp, const char *title, const char *xaxis, } } -FILE *xvgropen_type(const char *fn, const char *title, const char *xaxis, - const char *yaxis, int exvg_graph_type, +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; @@ -293,8 +293,8 @@ FILE *xvgropen_type(const char *fn, const char *title, const char *xaxis, return fp; } -FILE *xvgropen(const char *fn, const char *title, const char *xaxis, - const char *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); } diff --git a/src/gromacs/fileio/xvgr.h b/src/gromacs/fileio/xvgr.h index 35f81b42c1..166300ff1f 100644 --- a/src/gromacs/fileio/xvgr.h +++ b/src/gromacs/fileio/xvgr.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015,2017, 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,13 +39,11 @@ #include +#include + #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" -#ifdef __cplusplus -extern "C" { -#endif - struct gmx_output_env_t; /*************************************************** @@ -99,23 +97,23 @@ enum { exvggtNONE, exvggtXNY, exvggtXYDY, exvggtXYDYDY, exvggtNR }; -void xvgr_header(FILE *fp, const char *title, const char *xaxis, - const char *yaxis, int exvg_graph_type, +void xvgr_header(FILE *fp, const char *title, const std::string &xaxis, + const std::string &yaxis, int exvg_graph_type, const struct gmx_output_env_t *oenv); /* In most cases you want to use xvgropen_type, which does the same thing * but takes a filename and opens it. */ -FILE *xvgropen_type(const char *fn, const char *title, const char *xaxis, - const char *yaxis, int exvg_graph_type, +FILE *xvgropen_type(const char *fn, const char *title, const std::string &xaxis, + const std::string &yaxis, int exvg_graph_type, const struct gmx_output_env_t *oenv); /* Open a file, and write a title, and axis-labels in Xvgr format * or write nothing when oenv specifies so. * The xvgr graph type enum is defined above. */ -FILE *xvgropen(const char *fn, const char *title, const char *xaxis, - const char *yaxis, const struct gmx_output_env_t *oenv); +FILE *xvgropen(const char *fn, const char *title, const std::string &xaxis, + const std::string &yaxis, const struct gmx_output_env_t *oenv); /* Calls xvgropen_type with graph type xvggtXNY. */ /* Close xvgr file, and clean up internal file buffers correctly */ @@ -189,8 +187,4 @@ real **read_xvg_time(const char *fn, gmx_bool bTE, real te, int nsets_in, int *nset, int *nval, real *dt, real **t); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxana/gmx_anaeig.cpp b/src/gromacs/gmxana/gmx_anaeig.cpp index 9e4b629b5b..bd390ebab7 100644 --- a/src/gromacs/gmxana/gmx_anaeig.cpp +++ b/src/gromacs/gmxana/gmx_anaeig.cpp @@ -42,6 +42,7 @@ #include #include +#include #include "gromacs/commandline/pargs.h" #include "gromacs/commandline/viewit.h" @@ -147,7 +148,7 @@ static real tick_spacing(real range, int minticks) static void write_xvgr_graphs(const char *file, int ngraphs, int nsetspergraph, const char *title, const char *subtitle, - const char *xlabel, const char **ylabel, + const std::string &xlabel, const char **ylabel, int n, real *x, real **y, real ***sy, real scale_x, gmx_bool bZero, gmx_bool bSplit, const gmx_output_env_t *oenv) @@ -223,7 +224,7 @@ static void write_xvgr_graphs(const char *file, int ngraphs, int nsetspergraph, } if (g == ngraphs-1) { - fprintf(out, "@ xaxis label \"%s\"\n", xlabel); + fprintf(out, "@ xaxis label \"%s\"\n", xlabel.c_str()); } else { diff --git a/src/gromacs/gmxana/gmx_cluster.cpp b/src/gromacs/gmxana/gmx_cluster.cpp index 6dd4946104..2421a10a3f 100644 --- a/src/gromacs/gmxana/gmx_cluster.cpp +++ b/src/gromacs/gmxana/gmx_cluster.cpp @@ -65,6 +65,7 @@ #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/futil.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/stringutil.h" /* print to two file pointers at once (i.e. stderr and log) */ static gmx_inline @@ -1412,7 +1413,7 @@ int gmx_cluster(int argc, char *argv[]) int *index = nullptr, *fitidx = nullptr, *outidx = nullptr; char *grpname; real rmsd, **d1, **d2, *time = nullptr, time_invfac, *mass = nullptr; - char buf[STRLEN], buf1[80], title[STRLEN]; + char buf[STRLEN], buf1[80]; gmx_bool bAnalyze, bUseRmsdCut, bJP_RMSD = FALSE, bReadMat, bReadTraj, bPBC = TRUE; int method, ncluster = 0; @@ -1529,7 +1530,7 @@ int gmx_cluster(int argc, char *argv[]) { fprintf(stderr, "\nWarning: assuming the time unit in %s is %s\n", - opt2fn("-dm", NFILE, fnm), output_env_get_time_unit(oenv)); + opt2fn("-dm", NFILE, fnm), output_env_get_time_unit(oenv).c_str()); } if (trx_out_fn && !bReadTraj) { @@ -1937,19 +1938,19 @@ int gmx_cluster(int argc, char *argv[]) } else { - sprintf(buf, "Time (%s)", output_env_get_time_unit(oenv)); - sprintf(title, "RMS%sDeviation / Cluster Index", - bRMSdist ? " Distance " : " "); + auto timeLabel = output_env_get_time_label(oenv); + auto title = gmx::formatString("RMS%sDeviation / Cluster Index", + bRMSdist ? " Distance " : " "); if (minstruct > 1) { - write_xpm_split(fp, 0, title, "RMSD (nm)", buf, buf, + write_xpm_split(fp, 0, title, "RMSD (nm)", timeLabel, timeLabel, nf, nf, time, time, rms->mat, 0.0, rms->maxrms, &nlevels, rlo_top, rhi_top, 0.0, ncluster, &ncluster, TRUE, rlo_bot, rhi_bot); } else { - write_xpm(fp, 0, title, "RMSD (nm)", buf, buf, + write_xpm(fp, 0, title, "RMSD (nm)", timeLabel, timeLabel, nf, nf, time, time, rms->mat, 0.0, rms->maxrms, rlo_top, rhi_top, &nlevels); } @@ -1959,9 +1960,9 @@ int gmx_cluster(int argc, char *argv[]) if (nullptr != orig) { fp = opt2FILE("-om", NFILE, fnm, "w"); - sprintf(buf, "Time (%s)", output_env_get_time_unit(oenv)); - sprintf(title, "RMS%sDeviation", bRMSdist ? " Distance " : " "); - write_xpm(fp, 0, title, "RMSD (nm)", buf, buf, + auto timeLabel = output_env_get_time_label(oenv); + auto title = gmx::formatString("RMS%sDeviation", bRMSdist ? " Distance " : " "); + write_xpm(fp, 0, title, "RMSD (nm)", timeLabel, timeLabel, nf, nf, time, time, orig->mat, 0.0, orig->maxrms, rlo_top, rhi_top, &nlevels); gmx_ffclose(fp); diff --git a/src/gromacs/gmxana/gmx_clustsize.cpp b/src/gromacs/gmxana/gmx_clustsize.cpp index a88b365a6c..6c3cd17131 100644 --- a/src/gromacs/gmxana/gmx_clustsize.cpp +++ b/src/gromacs/gmxana/gmx_clustsize.cpp @@ -77,7 +77,6 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm, t_trxstatus *status; rvec *x = nullptr, *v = nullptr, dx; t_pbc pbc; - char timebuf[32]; gmx_bool bSame, bTPRwarn = TRUE; /* Topology stuff */ t_trxframe fr; @@ -95,12 +94,12 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm, t_rgb rlo = { 1.0, 1.0, 1.0 }; clear_trxframe(&fr, TRUE); - sprintf(timebuf, "Time (%s)", output_env_get_time_unit(oenv)); + auto timeLabel = output_env_get_time_label(oenv); tf = output_env_get_time_factor(oenv); - fp = xvgropen(ncl, "Number of clusters", timebuf, "N", oenv); - gp = xvgropen(acl, "Average cluster size", timebuf, "#molecules", oenv); - hp = xvgropen(mcl, "Max cluster size", timebuf, "#molecules", oenv); - tp = xvgropen(tempf, "Temperature of largest cluster", timebuf, "T (K)", + fp = xvgropen(ncl, "Number of clusters", timeLabel, "N", oenv); + gp = xvgropen(acl, "Average cluster size", timeLabel, "#molecules", oenv); + hp = xvgropen(mcl, "Max cluster size", timeLabel, "#molecules", oenv); + tp = xvgropen(tempf, "Temperature of largest cluster", timeLabel, "T (K)", oenv); if (!read_first_frame(oenv, &status, trx, &fr, TRX_NEED_X | TRX_READ_V)) @@ -404,7 +403,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm, fprintf(stderr, "cmid: %g, cmax: %g, max_size: %d\n", cmid, cmax, max_size); cmid = 1; fp = gmx_ffopen(xpm, "w"); - write_xpm3(fp, 0, "Cluster size distribution", "# clusters", timebuf, "Size", + write_xpm3(fp, 0, "Cluster size distribution", "# clusters", timeLabel, "Size", n_x, max_size, t_x, t_y, cs_dist, 0, cmid, cmax, rlo, rmid, rhi, &nlevels); gmx_ffclose(fp); @@ -424,7 +423,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm, } fprintf(stderr, "cmid: %g, cmax: %g, max_size: %d\n", cmid, cmax, max_size); fp = gmx_ffopen(xpmw, "w"); - write_xpm3(fp, 0, "Weighted cluster size distribution", "Fraction", timebuf, + write_xpm3(fp, 0, "Weighted cluster size distribution", "Fraction", timeLabel, "Size", n_x, max_size, t_x, t_y, cs_dist, 0, cmid, cmax, rlo, rmid, rhi, &nlevels); gmx_ffclose(fp); diff --git a/src/gromacs/gmxana/gmx_covar.cpp b/src/gromacs/gmxana/gmx_covar.cpp index 3c0a849915..ef9bacc70b 100644 --- a/src/gromacs/gmxana/gmx_covar.cpp +++ b/src/gromacs/gmxana/gmx_covar.cpp @@ -599,7 +599,7 @@ int gmx_covar(int argc, char *argv[]) fprintf(out, "Working directory: %s\n\n", str); fprintf(out, "Read %d frames from %s (time %g to %g %s)\n", nframes, trxfile, - output_env_conv_time(oenv, tstart), output_env_conv_time(oenv, tend), output_env_get_time_unit(oenv)); + output_env_conv_time(oenv, tstart), output_env_conv_time(oenv, tend), output_env_get_time_unit(oenv).c_str()); if (bFit) { fprintf(out, "Read reference structure for fit from %s\n", fitfile); diff --git a/src/gromacs/gmxana/gmx_do_dssp.cpp b/src/gromacs/gmxana/gmx_do_dssp.cpp index c7e1210b36..70c4256cfb 100644 --- a/src/gromacs/gmxana/gmx_do_dssp.cpp +++ b/src/gromacs/gmxana/gmx_do_dssp.cpp @@ -147,7 +147,7 @@ static int strip_dssp(char *dsspfile, int nres, sprintf(mat->title, "Secondary structure"); mat->legend[0] = 0; - sprintf(mat->label_x, "%s", output_env_get_time_label(oenv)); + sprintf(mat->label_x, "%s", output_env_get_time_label(oenv).c_str()); sprintf(mat->label_y, "Residue"); mat->bDiscrete = TRUE; mat->ny = nr; diff --git a/src/gromacs/gmxana/gmx_hbond.cpp b/src/gromacs/gmxana/gmx_hbond.cpp index fa43c15eb8..b9706ae5f0 100644 --- a/src/gromacs/gmxana/gmx_hbond.cpp +++ b/src/gromacs/gmxana/gmx_hbond.cpp @@ -3364,7 +3364,7 @@ int gmx_hbond(int argc, char *argv[]) sprintf(mat.title, bContact ? "Contact Existence Map" : "Hydrogen Bond Existence Map"); sprintf(mat.legend, bContact ? "Contacts" : "Hydrogen Bonds"); - sprintf(mat.label_x, "%s", output_env_get_xvgr_tlabel(oenv)); + sprintf(mat.label_x, "%s", output_env_get_xvgr_tlabel(oenv).c_str()); sprintf(mat.label_y, bContact ? "Contact Index" : "Hydrogen Bond Index"); mat.bDiscrete = TRUE; mat.nmap = 2; diff --git a/src/gromacs/gmxana/gmx_mindist.cpp b/src/gromacs/gmxana/gmx_mindist.cpp index 1229511dd7..b2a05a954c 100644 --- a/src/gromacs/gmxana/gmx_mindist.cpp +++ b/src/gromacs/gmxana/gmx_mindist.cpp @@ -212,7 +212,7 @@ static void periodic_mindist_plot(const char *trxfn, const char *outfn, fprintf(stdout, "\nThe shortest periodic distance is %g (nm) at time %g (%s),\n" "between atoms %d and %d\n", - rmint, output_env_conv_time(oenv, tmint), output_env_get_time_unit(oenv), + rmint, output_env_conv_time(oenv, tmint), output_env_get_time_unit(oenv).c_str(), index[ind_mini]+1, index[ind_minj]+1); } diff --git a/src/gromacs/gmxana/gmx_msd.cpp b/src/gromacs/gmxana/gmx_msd.cpp index c654f2a60c..faa8d1fdbd 100644 --- a/src/gromacs/gmxana/gmx_msd.cpp +++ b/src/gromacs/gmxana/gmx_msd.cpp @@ -185,9 +185,9 @@ static void corr_print(t_corr *curr, gmx_bool bTen, const char *fn, const char * if (DD) { fprintf(out, "# MSD gathered over %g %s with %d restarts\n", - msdtime, output_env_get_time_unit(oenv), curr->nrestart); + msdtime, output_env_get_time_unit(oenv).c_str(), curr->nrestart); fprintf(out, "# Diffusion constants fitted from time %g to %g %s\n", - beginfit, endfit, output_env_get_time_unit(oenv)); + beginfit, endfit, output_env_get_time_unit(oenv).c_str()); for (i = 0; i < curr->ngrp; i++) { fprintf(out, "# D[%10s] = %.4f (+/- %.4f) (1e-5 cm^2/s)\n", @@ -819,9 +819,9 @@ int corr_loop(t_corr *curr, const char *fn, const t_topology *top, int ePBC, while (read_next_x(oenv, status, &t, x[cur], box)); fprintf(stderr, "\nUsed %d restart points spaced %g %s over %g %s\n\n", curr->nrestart, - output_env_conv_time(oenv, dt), output_env_get_time_unit(oenv), + output_env_conv_time(oenv, dt), output_env_get_time_unit(oenv).c_str(), output_env_conv_time(oenv, curr->time[curr->nframes-1]), - output_env_get_time_unit(oenv) ); + output_env_get_time_unit(oenv).c_str() ); if (bMol) { @@ -977,7 +977,7 @@ void do_corr(const char *trx_file, const char *ndx_file, const char *msd_file, } } fprintf(stdout, "Fitting from %g to %g %s\n\n", beginfit, endfit, - output_env_get_time_unit(oenv)); + output_env_get_time_unit(oenv).c_str()); N = i1-i0; if (N <= 2) diff --git a/src/gromacs/gmxana/gmx_rms.cpp b/src/gromacs/gmxana/gmx_rms.cpp index 8b0eb99be0..c80debaea8 100644 --- a/src/gromacs/gmxana/gmx_rms.cpp +++ b/src/gromacs/gmxana/gmx_rms.cpp @@ -1124,7 +1124,7 @@ int gmx_rms(int argc, char *argv[]) else { sprintf(buf, "%s with frame %g %s ago", whatxvgname[ewhat], - time[prev*freq]-time[0], output_env_get_time_label(oenv)); + time[prev*freq]-time[0], output_env_get_time_label(oenv).c_str()); } fp = xvgropen(opt2fn("-o", NFILE, fnm), buf, output_env_get_xvgr_tlabel(oenv), whatxvglabel[ewhat], oenv); diff --git a/src/gromacs/gmxana/gmx_trjcat.cpp b/src/gromacs/gmxana/gmx_trjcat.cpp index 9c9bdc6fd3..9c951195db 100644 --- a/src/gromacs/gmxana/gmx_trjcat.cpp +++ b/src/gromacs/gmxana/gmx_trjcat.cpp @@ -41,6 +41,7 @@ #include #include +#include #include "gromacs/commandline/pargs.h" #include "gromacs/fileio/confio.h" @@ -183,6 +184,7 @@ static void edit_files(char **fnms, int nfiles, real *readtime, real *timestep, gmx_bool ok; char inputstring[STRLEN], *chptr; + auto timeUnit = output_env_get_time_unit(oenv); if (bSetTime) { fprintf(stderr, "\n\nEnter the new start time (%s) for each file.\n" @@ -194,18 +196,18 @@ static void edit_files(char **fnms, int nfiles, real *readtime, real *timestep, "same amount as in the previous. Use it when the time in the\n" "new run continues from the end of the previous one,\n" "since this takes possible overlap into account.\n\n", - output_env_get_time_unit(oenv)); + timeUnit.c_str()); fprintf( stderr, " File Current start (%s) New start (%s)\n" "---------------------------------------------------------\n", - output_env_get_time_unit(oenv), output_env_get_time_unit(oenv)); + timeUnit.c_str(), timeUnit.c_str()); for (i = 0; i < nfiles; i++) { fprintf(stderr, "%25s %10.3f %s ", fnms[i], - output_env_conv_time(oenv, readtime[i]), output_env_get_time_unit(oenv)); + output_env_conv_time(oenv, readtime[i]), timeUnit.c_str()); ok = FALSE; do { @@ -281,8 +283,8 @@ static void edit_files(char **fnms, int nfiles, real *readtime, real *timestep, case TIME_EXPLICIT: fprintf(stderr, "%25s %10.3f %s %10.3f %s", fnms[i], - output_env_conv_time(oenv, settime[i]), output_env_get_time_unit(oenv), - output_env_conv_time(oenv, timestep[i]), output_env_get_time_unit(oenv)); + output_env_conv_time(oenv, settime[i]), timeUnit.c_str(), + output_env_conv_time(oenv, timestep[i]), timeUnit.c_str()); if (i > 0 && cont_type[i-1] == TIME_EXPLICIT && settime[i] == settime[i-1]) { @@ -503,6 +505,7 @@ int gmx_trjcat(int argc, char *argv[]) { return 0; } + auto timeUnit = output_env_get_time_unit(oenv); bIndex = ftp2bSet(efNDX, NFILE, fnm); bDeMux = ftp2bSet(efXVG, NFILE, fnm); @@ -796,7 +799,7 @@ int gmx_trjcat(int argc, char *argv[]) "spacing than the rest,\n" "might be a gap or overlap that couldn't be corrected " "automatically.\n", output_env_conv_time(oenv, frout.time), - output_env_get_time_unit(oenv)); + timeUnit.c_str()); } } } @@ -886,7 +889,7 @@ int gmx_trjcat(int argc, char *argv[]) { fprintf(stderr, "\nContinue writing frames from %s t=%g %s, " "frame=%d \n", - fnms[i], output_env_conv_time(oenv, frout.time), output_env_get_time_unit(oenv), + fnms[i], output_env_conv_time(oenv, frout.time), timeUnit.c_str(), frame); bNewFile = FALSE; } @@ -903,7 +906,7 @@ int gmx_trjcat(int argc, char *argv[]) if ( ((frame % 10) == 0) || (frame < 10) ) { fprintf(stderr, " -> frame %6d time %8.3f %s \r", - frame_out, output_env_conv_time(oenv, frout.time), output_env_get_time_unit(oenv)); + frame_out, output_env_conv_time(oenv, frout.time), timeUnit.c_str()); fflush(stderr); } } @@ -918,7 +921,7 @@ int gmx_trjcat(int argc, char *argv[]) close_trx(trxout); } fprintf(stderr, "\nLast frame written was %d, time %f %s\n", - frame, output_env_conv_time(oenv, last_ok_t), output_env_get_time_unit(oenv)); + frame, output_env_conv_time(oenv, last_ok_t), timeUnit.c_str()); } return 0; diff --git a/src/gromacs/gmxana/gmx_trjconv.cpp b/src/gromacs/gmxana/gmx_trjconv.cpp index 92c192830d..41f5ab8915 100644 --- a/src/gromacs/gmxana/gmx_trjconv.cpp +++ b/src/gromacs/gmxana/gmx_trjconv.cpp @@ -1591,7 +1591,7 @@ int gmx_trjconv(int argc, char *argv[]) if (bTDump) { fprintf(stderr, "\nDumping frame at t= %g %s\n", - output_env_conv_time(oenv, frout_time), output_env_get_time_unit(oenv)); + output_env_conv_time(oenv, frout_time), output_env_get_time_unit(oenv).c_str()); } /* check for writing at each delta_t */ -- 2.11.4.GIT