2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
41 #include "gromacs/utility/programcontext.h"
42 #include "gromacs/utility/exceptions.h"
46 explicit output_env(const gmx::ProgramContextInterface &context)
47 : programContext(context)
51 xvg_format = exvgNONE;
56 const gmx::ProgramContextInterface &programContext;
58 /* the time unit, enum defined in oenv.h */
59 time_unit_t time_unit;
60 /* view of file requested */
62 /* xvg output format, enum defined in oenv.h */
63 xvg_format_t xvg_format;
64 /* The level of verbosity for this program */
70 /* The source code in this file should be thread-safe.
71 Please keep it that way. */
73 /******************************************************************
75 * T R A J E C T O R Y S T U F F
77 ******************************************************************/
79 /* read only time names */
80 /* These must correspond to the time units type time_unit_t in oenv.h */
81 static const real timefactors[] = { 0, 1e3, 1, 1e-3, 1e-6, 1e-9, 1e-12, 0 };
82 static const real timeinvfactors[] = { 0, 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 0 };
83 static const char *time_units_str[] = {
84 NULL, "fs", "ps", "ns", "us",
87 static const char *time_units_xvgr[] = {
88 NULL, "fs", "ps", "ns",
93 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
95 void output_env_init(output_env_t *oenvp,
96 const gmx::ProgramContextInterface &context,
97 time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
98 int verbosity, int debug_level)
102 output_env_t oenv = new output_env(context);
104 oenv->time_unit = tmu;
106 oenv->xvg_format = xvg_format;
107 oenv->verbosity = verbosity;
108 oenv->debug_level = debug_level;
110 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
113 void output_env_init_default(output_env_t *oenvp)
117 output_env_t oenv = new output_env(gmx::getProgramContext());
120 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
123 void output_env_done(output_env_t oenv)
129 int output_env_get_verbosity(const output_env_t oenv)
131 return oenv->verbosity;
134 int output_env_get_debug_level(const output_env_t oenv)
136 return oenv->debug_level;
139 const char *output_env_get_time_unit(const output_env_t oenv)
141 return time_units_str[oenv->time_unit];
144 const char *output_env_get_time_label(const output_env_t oenv)
149 sprintf(label, "Time (%s)", time_units_str[oenv->time_unit] ?
150 time_units_str[oenv->time_unit] : "ps");
155 const char *output_env_get_xvgr_tlabel(const output_env_t oenv)
160 sprintf(label, "Time (%s)", time_units_xvgr[oenv->time_unit] ?
161 time_units_xvgr[oenv->time_unit] : "ps");
166 real output_env_get_time_factor(const output_env_t oenv)
168 return timefactors[oenv->time_unit];
171 real output_env_get_time_invfactor(const output_env_t oenv)
173 return timeinvfactors[oenv->time_unit];
176 real output_env_conv_time(const output_env_t oenv, real time)
178 return time*timefactors[oenv->time_unit];
181 void output_env_conv_times(const output_env_t oenv, int n, real *time)
184 double fact = timefactors[oenv->time_unit];
188 for (i = 0; i < n; i++)
195 gmx_bool output_env_get_view(const output_env_t oenv)
200 xvg_format_t output_env_get_xvg_format(const output_env_t oenv)
202 return oenv->xvg_format;
205 const char *output_env_get_program_name(const output_env_t oenv)
209 return oenv->programContext.fullBinaryPath();
211 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
214 const char *output_env_get_short_program_name(const output_env_t oenv)
218 // TODO: Use the display name once it doesn't break anything.
219 return oenv->programContext.programName();
221 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
224 const char *output_env_get_cmd_line(const output_env_t oenv)
228 return oenv->programContext.commandLine();
230 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;