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, 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/exceptions.h"
42 #include "gromacs/utility/programinfo.h"
50 output_env(int argc, const char *const argv[])
51 : programInfo(argc, argv)
60 xvg_format = exvgNONE;
65 gmx::ProgramInfo programInfo;
67 time_unit_t time_unit; /* the time unit, enum defined in oenv.h */
68 gmx_bool view; /* view of file requested */
69 xvg_format_t xvg_format; /* xvg output format, enum defined in oenv.h */
70 int verbosity; /* The level of verbosity for this program */
71 int debug_level; /* the debug level */
74 /* The source code in this file should be thread-safe.
75 Please keep it that way. */
77 /******************************************************************
79 * T R A J E C T O R Y S T U F F
81 ******************************************************************/
83 /* read only time names */
84 /* These must correspond to the time units type time_unit_t in oenv.h */
85 static const real timefactors[] = { 0, 1e3, 1, 1e-3, 1e-6, 1e-9, 1e-12, 0 };
86 static const real timeinvfactors[] = { 0, 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 0 };
87 static const char *time_units_str[] = {
88 NULL, "fs", "ps", "ns", "us",
91 static const char *time_units_xvgr[] = {
92 NULL, "fs", "ps", "ns",
97 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
99 void output_env_init(output_env_t *oenvp, int argc, char *argv[],
100 time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
101 int verbosity, int debug_level)
105 output_env_t oenv = new output_env(argc, argv);
107 oenv->time_unit = tmu;
109 oenv->xvg_format = xvg_format;
110 oenv->verbosity = verbosity;
111 oenv->debug_level = debug_level;
113 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
116 void output_env_init_default(output_env_t *oenvp)
120 output_env_t oenv = new output_env();
123 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
126 void output_env_done(output_env_t oenv)
132 int output_env_get_verbosity(const output_env_t oenv)
134 return oenv->verbosity;
137 int output_env_get_debug_level(const output_env_t oenv)
139 return oenv->debug_level;
142 const char *output_env_get_time_unit(const output_env_t oenv)
144 return time_units_str[oenv->time_unit];
147 const char *output_env_get_time_label(const output_env_t oenv)
152 sprintf(label, "Time (%s)", time_units_str[oenv->time_unit] ?
153 time_units_str[oenv->time_unit] : "ps");
158 const char *output_env_get_xvgr_tlabel(const output_env_t oenv)
163 sprintf(label, "Time (%s)", time_units_xvgr[oenv->time_unit] ?
164 time_units_xvgr[oenv->time_unit] : "ps");
169 real output_env_get_time_factor(const output_env_t oenv)
171 return timefactors[oenv->time_unit];
174 real output_env_get_time_invfactor(const output_env_t oenv)
176 return timeinvfactors[oenv->time_unit];
179 real output_env_conv_time(const output_env_t oenv, real time)
181 return time*timefactors[oenv->time_unit];
184 void output_env_conv_times(const output_env_t oenv, int n, real *time)
187 double fact = timefactors[oenv->time_unit];
191 for (i = 0; i < n; i++)
198 gmx_bool output_env_get_view(const output_env_t oenv)
203 xvg_format_t output_env_get_xvg_format(const output_env_t oenv)
205 return oenv->xvg_format;
208 const char *output_env_get_program_name(const output_env_t oenv)
212 return oenv->programInfo.fullBinaryPath().c_str();
214 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
217 const char *output_env_get_short_program_name(const output_env_t oenv)
221 // TODO: Use the display name once it doesn't break anything.
222 return oenv->programInfo.programName().c_str();
224 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
227 const char *output_env_get_cmd_line(const output_env_t oenv)
231 return oenv->programInfo.commandLine().c_str();
233 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;