1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * GROningen Mixture of Alchemy and Childrens' Stories
40 #include "gromacs/utility/exceptions.h"
41 #include "gromacs/utility/programinfo.h"
49 output_env(int argc, const char *const argv[])
50 : programInfo(argc, argv)
59 xvg_format = exvgNONE;
64 gmx::ProgramInfo programInfo;
66 time_unit_t time_unit; /* the time unit, enum defined in oenv.h */
67 gmx_bool view; /* view of file requested */
68 xvg_format_t xvg_format; /* xvg output format, enum defined in oenv.h */
69 int verbosity; /* The level of verbosity for this program */
70 int debug_level; /* the debug level */
73 /* The source code in this file should be thread-safe.
74 Please keep it that way. */
76 /******************************************************************
78 * T R A J E C T O R Y S T U F F
80 ******************************************************************/
82 /* read only time names */
83 /* These must correspond to the time units type time_unit_t in oenv.h */
84 static const real timefactors[] = { 0, 1e3, 1, 1e-3, 1e-6, 1e-9, 1e-12, 0 };
85 static const real timeinvfactors[] = { 0, 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 0 };
86 static const char *time_units_str[] = {
87 NULL, "fs", "ps", "ns", "us",
90 static const char *time_units_xvgr[] = {
91 NULL, "fs", "ps", "ns",
96 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
98 void output_env_init(output_env_t *oenvp, int argc, char *argv[],
99 time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
100 int verbosity, int debug_level)
104 output_env_t oenv = new output_env(argc, argv);
106 oenv->time_unit = tmu;
108 oenv->xvg_format = xvg_format;
109 oenv->verbosity = verbosity;
110 oenv->debug_level = debug_level;
112 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
115 void output_env_init_default(output_env_t *oenvp)
119 output_env_t oenv = new output_env();
122 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
125 void output_env_done(output_env_t oenv)
131 int output_env_get_verbosity(const output_env_t oenv)
133 return oenv->verbosity;
136 int output_env_get_debug_level(const output_env_t oenv)
138 return oenv->debug_level;
141 const char *output_env_get_time_unit(const output_env_t oenv)
143 return time_units_str[oenv->time_unit];
146 const char *output_env_get_time_label(const output_env_t oenv)
151 sprintf(label, "Time (%s)", time_units_str[oenv->time_unit] ?
152 time_units_str[oenv->time_unit] : "ps");
157 const char *output_env_get_xvgr_tlabel(const output_env_t oenv)
162 sprintf(label, "Time (%s)", time_units_xvgr[oenv->time_unit] ?
163 time_units_xvgr[oenv->time_unit] : "ps");
168 real output_env_get_time_factor(const output_env_t oenv)
170 return timefactors[oenv->time_unit];
173 real output_env_get_time_invfactor(const output_env_t oenv)
175 return timeinvfactors[oenv->time_unit];
178 real output_env_conv_time(const output_env_t oenv, real time)
180 return time*timefactors[oenv->time_unit];
183 void output_env_conv_times(const output_env_t oenv, int n, real *time)
186 double fact = timefactors[oenv->time_unit];
190 for (i = 0; i < n; i++)
197 gmx_bool output_env_get_view(const output_env_t oenv)
202 xvg_format_t output_env_get_xvg_format(const output_env_t oenv)
204 return oenv->xvg_format;
207 const char *output_env_get_program_name(const output_env_t oenv)
211 return oenv->programInfo.fullBinaryPath().c_str();
213 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
216 const char *output_env_get_short_program_name(const output_env_t oenv)
220 // TODO: Use the display name once it doesn't break anything.
221 return oenv->programInfo.programName().c_str();
223 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
226 const char *output_env_get_cmd_line(const output_env_t oenv)
230 return oenv->programInfo.commandLine().c_str();
232 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;