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[] = { NULL, "fs", "ps", "ns", "us",
88 static const char *time_units_xvgr[] = { NULL, "fs", "ps", "ns",
92 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
94 void output_env_init(output_env_t *oenvp, int argc, char *argv[],
95 time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
96 int verbosity, int debug_level)
100 output_env_t oenv = new output_env(argc, argv);
102 oenv->time_unit = tmu;
104 oenv->xvg_format = xvg_format;
105 oenv->verbosity = verbosity;
106 oenv->debug_level = debug_level;
108 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
111 void output_env_init_default(output_env_t *oenvp)
115 output_env_t oenv = new output_env();
118 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
121 void output_env_done(output_env_t oenv)
127 int output_env_get_verbosity(const output_env_t oenv)
129 return oenv->verbosity;
132 int output_env_get_debug_level(const output_env_t oenv)
134 return oenv->debug_level;
137 const char *output_env_get_time_unit(const output_env_t oenv)
139 return time_units_str[oenv->time_unit];
142 const char *output_env_get_time_label(const output_env_t oenv)
147 sprintf(label,"Time (%s)",time_units_str[oenv->time_unit] ?
148 time_units_str[oenv->time_unit]: "ps");
153 const char *output_env_get_xvgr_tlabel(const output_env_t oenv)
158 sprintf(label,"Time (%s)", time_units_xvgr[oenv->time_unit] ?
159 time_units_xvgr[oenv->time_unit] : "ps");
164 real output_env_get_time_factor(const output_env_t oenv)
166 return timefactors[oenv->time_unit];
169 real output_env_get_time_invfactor(const output_env_t oenv)
171 return timeinvfactors[oenv->time_unit];
174 real output_env_conv_time(const output_env_t oenv, real time)
176 return time*timefactors[oenv->time_unit];
179 void output_env_conv_times(const output_env_t oenv, int n, real *time)
182 double fact=timefactors[oenv->time_unit];
189 gmx_bool output_env_get_view(const output_env_t oenv)
194 xvg_format_t output_env_get_xvg_format(const output_env_t oenv)
196 return oenv->xvg_format;
199 const char *output_env_get_program_name(const output_env_t oenv)
203 return oenv->programInfo.programNameWithPath().c_str();
205 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
208 const char *output_env_get_short_program_name(const output_env_t oenv)
212 return oenv->programInfo.programName().c_str();
214 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
217 const char *output_env_get_cmd_line(const output_env_t oenv)
221 return oenv->programInfo.commandLine().c_str();
223 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;