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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
56 #include "gmx_fatal.h"
59 #include "mtop_util.h"
64 #include "thread_mpi.h"
69 /* The source code in this file should be thread-safe.
70 Please keep it that way. */
72 /******************************************************************
74 * T R A J E C T O R Y S T U F F
76 ******************************************************************/
78 /* read only time names */
79 /* These must correspond to the time units type time_unit_t in statutil.h */
80 static const real timefactors[] = { 0, 1e3, 1, 1e-3, 1e-6, 1e-9, 1e-12, 0 };
81 static const real timeinvfactors[] ={ 0, 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 0 };
82 static const char *time_units_str[] = { NULL, "fs", "ps", "ns", "us",
84 static const char *time_units_xvgr[] = { NULL, "fs", "ps", "ns",
89 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
91 void output_env_init(output_env_t oenv, int argc, char *argv[],
92 time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
93 int verbosity, int debug_level)
97 char *argvzero=NULL, *extpos;
99 oenv->time_unit = tmu;
101 oenv->xvg_format = xvg_format;
102 oenv->verbosity=verbosity;
103 oenv->debug_level=debug_level;
104 oenv->program_name=NULL;
111 /* set program name */
114 /* if filename has file ending (e.g. .exe) then strip away */
115 extpos=strrchr(argvzero,'.');
116 if(extpos > strrchr(argvzero,DIR_SEPARATOR))
118 oenv->program_name=gmx_strndup(argvzero,extpos-argvzero);
122 oenv->program_name=gmx_strdup(argvzero);
125 if (oenv->program_name == NULL)
127 oenv->program_name = gmx_strdup("GROMACS");
130 /* copy command line */
133 cmdlength = strlen(argvzero);
134 for (i=1; i<argc; i++)
136 cmdlength += strlen(argv[i]);
140 /* Fill the cmdline string */
141 snew(oenv->cmd_line,cmdlength+argc+1);
144 for (i=0; i<argc; i++)
146 strcat(oenv->cmd_line,argv[i]);
147 strcat(oenv->cmd_line," ");
153 void output_env_init_default(output_env_t oenv)
155 output_env_init(oenv, 0, NULL, time_ps, FALSE, exvgNONE, 0, 0);
159 void output_env_done(output_env_t oenv)
161 sfree(oenv->program_name);
162 sfree(oenv->cmd_line);
168 int output_env_get_verbosity(const output_env_t oenv)
170 return oenv->verbosity;
173 int output_env_get_debug_level(const output_env_t oenv)
175 return oenv->debug_level;
179 const char *output_env_get_time_unit(const output_env_t oenv)
181 return time_units_str[oenv->time_unit];
184 const char *output_env_get_time_label(const output_env_t oenv)
189 sprintf(label,"Time (%s)",time_units_str[oenv->time_unit] ?
190 time_units_str[oenv->time_unit]: "ps");
195 const char *output_env_get_xvgr_tlabel(const output_env_t oenv)
200 sprintf(label,"Time (%s)", time_units_xvgr[oenv->time_unit] ?
201 time_units_xvgr[oenv->time_unit] : "ps");
207 real output_env_get_time_factor(const output_env_t oenv)
209 return timefactors[oenv->time_unit];
212 real output_env_get_time_invfactor(const output_env_t oenv)
214 return timeinvfactors[oenv->time_unit];
217 real output_env_conv_time(const output_env_t oenv, real time)
219 return time*timefactors[oenv->time_unit];
223 void output_env_conv_times(const output_env_t oenv, int n, real *time)
226 double fact=timefactors[oenv->time_unit];
233 gmx_bool output_env_get_view(const output_env_t oenv)
238 xvg_format_t output_env_get_xvg_format(const output_env_t oenv)
240 return oenv->xvg_format;
243 const char *output_env_get_program_name(const output_env_t oenv)
245 return oenv->program_name;
248 const char *output_env_get_short_program_name(const output_env_t oenv)
251 pr=ret=oenv->program_name;
252 if ((pr=strrchr(ret,DIR_SEPARATOR)) != NULL)
254 /* Strip away the libtool prefix if it's still there. */
255 if(strlen(ret) > 3 && !strncmp(ret, "lt-", 3))
262 const char *output_env_get_cmd_line(const output_env_t oenv)
264 return oenv->cmd_line;