From: Teemu Murtola Date: Sun, 22 Jun 2014 11:18:13 +0000 (+0300) Subject: Clean up program name handling in oenv X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=679d45de7fc08bf03c6bea606af576e10917bfdc;p=alexxy%2Fgromacs.git Clean up program name handling in oenv - Remove unused functions to access the program name and command line from oenv. - Replace these with direct access to a ProgramContextInterface, and use that instead of the global program context instance in places where output_env_t is easily accessible. - Replace some calls to ShortProgram() with an equivalent call in oenv for places where oenv is readily accessible. Change-Id: I2e8bc8701b8217f51ed9936338e1e9c3c21bd8ba --- diff --git a/src/contrib/do_multiprot.c b/src/contrib/do_multiprot.c index d7943a2659..16e7a44d46 100644 --- a/src/contrib/do_multiprot.c +++ b/src/contrib/do_multiprot.c @@ -347,9 +347,6 @@ int main(int argc,char *argv[]) out=gmx_ffopen(TrjoutFile,filemode); break; } - if (outftp == efG87) - fprintf(gmx_fio_getfp(trx_get_fileio(trxout)),"Generated by %s. #atoms=%d, a BOX is" - " stored in this file.\n",ShortProgram(),nout); } if (natoms > atoms->nr) { diff --git a/src/gromacs/fileio/xvgr.cpp b/src/gromacs/fileio/xvgr.cpp index 49081481fa..4adfcf4144 100644 --- a/src/gromacs/fileio/xvgr.cpp +++ b/src/gromacs/fileio/xvgr.cpp @@ -57,7 +57,6 @@ #include "gromacs/utility/exceptions.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/futil.h" -#include "gromacs/utility/programcontext.h" #include "gromacs/utility/smalloc.h" gmx_bool output_env_get_print_xvgr_codes(const output_env_t oenv) @@ -252,10 +251,12 @@ void xvgr_header(FILE *fp, const char *title, const char *xaxis, gmx::BinaryInformationSettings settings; settings.generatedByHeader(true); settings.linePrefix("# "); - gmx::printBinaryInformation(fp, gmx::getProgramContext(), 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", ShortProgram()); + fprintf(fp, "# %s is part of G R O M A C S:\n#\n", + output_env_get_program_display_name(oenv)); bromacs(pukestr, 99); fprintf(fp, "# %s\n#\n", pukestr); fprintf(fp, "@ title \"%s\"\n", xvgrstr(title, oenv, buf, STRLEN)); diff --git a/src/gromacs/gmxana/gmx_densorder.cpp b/src/gromacs/gmxana/gmx_densorder.cpp index 020c746947..0a563590ee 100644 --- a/src/gromacs/gmxana/gmx_densorder.cpp +++ b/src/gromacs/gmxana/gmx_densorder.cpp @@ -63,7 +63,6 @@ #include "gromacs/pbcutil/rmpbc.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/fatalerror.h" -#include "gromacs/utility/programcontext.h" #include "gromacs/utility/smalloc.h" #ifdef GMX_DOUBLE @@ -615,7 +614,9 @@ static void writesurftoxpms(t_interf ***surf1, t_interf ***surf2, int tblocks, i sfree(yticks); } -static void writeraw(t_interf ***int1, t_interf ***int2, int tblocks, int xbins, int ybins, char **fnms) +static void writeraw(t_interf ***int1, t_interf ***int2, int tblocks, + int xbins, int ybins, char **fnms, + const output_env_t oenv) { FILE *raw1, *raw2; int i, j, n; @@ -627,8 +628,10 @@ static void writeraw(t_interf ***int1, t_interf ***int2, int tblocks, int xbins, gmx::BinaryInformationSettings settings; settings.generatedByHeader(true); settings.linePrefix("# "); - gmx::printBinaryInformation(raw1, gmx::getProgramContext(), settings); - gmx::printBinaryInformation(raw2, gmx::getProgramContext(), settings); + gmx::printBinaryInformation(raw1, output_env_get_program_context(oenv), + settings); + gmx::printBinaryInformation(raw2, output_env_get_program_context(oenv), + settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; fprintf(raw1, "# Legend: nt nx ny\n# Xbin Ybin Z t\n"); @@ -798,7 +801,7 @@ int gmx_densorder(int argc, char *argv[]) { gmx_fatal(FARGS, "No or not correct number (2) of output-files: %d", nfxpm); } - writeraw(surf1, surf2, tblock, xslices, yslices, rawfiles); + writeraw(surf1, surf2, tblock, xslices, yslices, rawfiles, oenv); } diff --git a/src/gromacs/gmxana/gmx_dipoles.cpp b/src/gromacs/gmxana/gmx_dipoles.cpp index ba31730f91..5558a48ad7 100644 --- a/src/gromacs/gmxana/gmx_dipoles.cpp +++ b/src/gromacs/gmxana/gmx_dipoles.cpp @@ -68,7 +68,6 @@ #include "gromacs/pbcutil/rmpbc.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/fatalerror.h" -#include "gromacs/utility/programcontext.h" #include "gromacs/utility/smalloc.h" #define e2d(x) ENM2DEBYE*(x) @@ -955,7 +954,7 @@ static void do_dip(t_topology *top, int ePBC, real volume, gmx::BinaryInformationSettings settings; settings.generatedByHeader(true); settings.linePrefix("# "); - gmx::printBinaryInformation(dip3d, gmx::getProgramContext(), + gmx::printBinaryInformation(dip3d, output_env_get_program_context(oenv), settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; diff --git a/src/gromacs/gmxana/gmx_tune_pme.c b/src/gromacs/gmxana/gmx_tune_pme.c index f83b4de72a..5251166e57 100644 --- a/src/gromacs/gmxana/gmx_tune_pme.c +++ b/src/gromacs/gmxana/gmx_tune_pme.c @@ -42,12 +42,9 @@ #include #endif -#include "gromacs/commandline/pargs.h" #include "typedefs.h" #include "types/commrec.h" -#include "gromacs/utility/smalloc.h" #include "gromacs/math/vec.h" -#include "copyrite.h" #include "gromacs/fileio/tpxio.h" #include "gromacs/utility/cstringutil.h" #include "readinp.h" @@ -61,7 +58,10 @@ #include "gromacs/timing/walltime_accounting.h" #include "gromacs/math/utilities.h" +#include "gromacs/commandline/pargs.h" +#include "gromacs/utility/baseversion.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/smalloc.h" /* Enum for situations that can occur during log file parsing, the * corresponding string entries can be found in do_the_tests() in @@ -2356,7 +2356,8 @@ int gmx_tune_pme(int argc, char *argv[]) sep_line(fp); fprintf(fp, "\n P E R F O R M A N C E R E S U L T S\n"); sep_line(fp); - fprintf(fp, "%s for Gromacs %s\n", ShortProgram(), GromacsVersion()); + fprintf(fp, "%s for Gromacs %s\n", output_env_get_program_display_name(oenv), + gmx_version()); if (!bThreads) { fprintf(fp, "Number of ranks : %d\n", nnodes); diff --git a/src/gromacs/gmxlib/oenv.cpp b/src/gromacs/gmxlib/oenv.cpp index 73603fb55c..439e12b692 100644 --- a/src/gromacs/gmxlib/oenv.cpp +++ b/src/gromacs/gmxlib/oenv.cpp @@ -193,30 +193,17 @@ xvg_format_t output_env_get_xvg_format(const output_env_t oenv) return oenv->xvg_format; } -const char *output_env_get_program_name(const output_env_t oenv) +const char *output_env_get_program_display_name(const output_env_t oenv) { try { - return oenv->programContext.fullBinaryPath(); + return oenv->programContext.displayName(); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; } -const char *output_env_get_short_program_name(const output_env_t oenv) +const gmx::ProgramContextInterface & +output_env_get_program_context(const output_env_t oenv) { - try - { - // TODO: Use the display name once it doesn't break anything. - return oenv->programContext.programName(); - } - GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; -} - -const char *output_env_get_cmd_line(const output_env_t oenv) -{ - try - { - return oenv->programContext.commandLine(); - } - GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; + return oenv->programContext; } diff --git a/src/gromacs/gmxpreprocess/x2top.c b/src/gromacs/gmxpreprocess/x2top.c index 06962af891..bbbe2aa6cb 100644 --- a/src/gromacs/gmxpreprocess/x2top.c +++ b/src/gromacs/gmxpreprocess/x2top.c @@ -636,7 +636,7 @@ int gmx_x2top(int argc, char *argv[]) sfree(mymol.name); printf("\nWARNING: topologies generated by %s can not be trusted at face value.\n", - ShortProgram()); + output_env_get_program_display_name(oenv)); printf(" Please verify atomtypes and charges by comparison to other\n"); printf(" topologies.\n"); diff --git a/src/gromacs/legacyheaders/oenv.h b/src/gromacs/legacyheaders/oenv.h index ed154b0db0..8088c4f9bf 100644 --- a/src/gromacs/legacyheaders/oenv.h +++ b/src/gromacs/legacyheaders/oenv.h @@ -107,14 +107,10 @@ gmx_bool output_env_get_view(const output_env_t oenv); xvg_format_t output_env_get_xvg_format(const output_env_t oenv); /* Returns enum (see above) for xvg output formatting */ -const char *output_env_get_program_name(const output_env_t oenv); -/* return the program name */ - -const char *output_env_get_cmd_line(const output_env_t oenv); -/* return the command line */ - -const char *output_env_get_short_program_name(const output_env_t oenv); -/* get the short version (without path component) of the program name */ +/*! \brief + * Returns display name for the currently running program. + */ +const char *output_env_get_program_display_name(const output_env_t oenv); #ifdef __cplusplus } @@ -132,6 +128,13 @@ void output_env_init(output_env_t *oenvp, the default time value a gmx_boolean view that is set to TRUE when the user requests direct viewing of graphs, the graph formatting type, the verbosity, and debug level */ + +/*! \brief + * Returns gmx::ProgramContextInterface from an output_env structure. + */ +const gmx::ProgramContextInterface & +output_env_get_program_context(const output_env_t oenv); + #endif #endif diff --git a/src/programs/mdrun/runner.cpp b/src/programs/mdrun/runner.cpp index 85a2d17991..d833b6fb23 100644 --- a/src/programs/mdrun/runner.cpp +++ b/src/programs/mdrun/runner.cpp @@ -50,7 +50,7 @@ #endif #include "typedefs.h" -#include "copyrite.h" +#include "oenv.h" #include "force.h" #include "mdrun.h" #include "md_logging.h" @@ -1323,7 +1323,7 @@ int mdrunner(gmx_hw_opt_t *hw_opt, "but %s was not started through mpirun/mpiexec or only one rank was requested through mpirun/mpiexec" #endif #endif - , ShortProgram() + , output_env_get_program_display_name(oenv) ); }