Clean up program name handling in oenv
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 22 Jun 2014 11:18:13 +0000 (14:18 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 8 Jul 2014 18:44:51 +0000 (20:44 +0200)
- 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

src/contrib/do_multiprot.c
src/gromacs/fileio/xvgr.cpp
src/gromacs/gmxana/gmx_densorder.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_tune_pme.c
src/gromacs/gmxlib/oenv.cpp
src/gromacs/gmxpreprocess/x2top.c
src/gromacs/legacyheaders/oenv.h
src/programs/mdrun/runner.cpp

index d7943a265957f0b58f6fe593240bb6f6055545ee..16e7a44d46c85e0a137a42d22b61bd5394310e80 100644 (file)
@@ -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) {
index 49081481faba437a3aa46fb7483e8211c691412c..4adfcf4144d9e299616cf0583592136d5cea7c88 100644 (file)
@@ -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));
index 020c7469472cb18d58b9d6403421580c5f86f17e..0a563590ee681509244f6a7d7dc347913ad801db 100644 (file)
@@ -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);
     }
 
 
index ba31730f9113ed966b18003a2d268b421186f876..5558a48ad71ee670ec3eff7d7f39621e25086ac3 100644 (file)
@@ -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;
index f83b4de72a0f4205fc09860e0901ba851a579602..5251166e571c65180f589eef950c24cc74a0f048 100644 (file)
 #include <sys/time.h>
 #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"
 #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);
index 73603fb55cbc1061d55c438117472ccf9bd283fc..439e12b692a6788e1e2985b7f7b8d4d9571ac348 100644 (file)
@@ -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;
 }
index 06962af891003bd66996c59532080a4e3ec0bba5..bbbe2aa6cbf07cfd95cd401804b4648d23579e24 100644 (file)
@@ -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");
 
index ed154b0db04afd87ec75413eabeafa190673e21b..8088c4f9bfce44d7b55d6852226a9efa701025bb 100644 (file)
@@ -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
index 85a2d17991d301bafce2149a26b8617fdd3f1ddb..d833b6fb23a3516bd4583583bfeda81fbbd370d9 100644 (file)
@@ -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)
                   );
     }