Fixing more clang warnings
[gromacs.git] / src / gmxlib / oenv.c
bloba9573bd17ccba827deedf8e51acc06dc1eed871f
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
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
33 * And Hey:
34 * GROningen Mixture of Alchemy and Childrens' Stories
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
41 #include <ctype.h>
42 #include <assert.h>
43 #include "sysstuff.h"
44 #include "macros.h"
45 #include "string2.h"
46 #include "smalloc.h"
47 #include "pbc.h"
48 #include "statutil.h"
49 #include "names.h"
50 #include "vec.h"
51 #include "futil.h"
52 #include "wman.h"
53 #include "tpxio.h"
54 #include "gmx_fatal.h"
55 #include "network.h"
56 #include "vec.h"
57 #include "mtop_util.h"
58 #include "gmxfio.h"
59 #include "oenv.h"
61 #ifdef GMX_THREAD_MPI
62 #include "thread_mpi.h"
63 #endif
67 /* The source code in this file should be thread-safe.
68 Please keep it that way. */
70 /******************************************************************
72 * T R A J E C T O R Y S T U F F
74 ******************************************************************/
76 /* read only time names */
77 /* These must correspond to the time units type time_unit_t in statutil.h */
78 static const real timefactors[] = { 0, 1e3, 1, 1e-3, 1e-6, 1e-9, 1e-12, 0 };
79 static const real timeinvfactors[] ={ 0, 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 0 };
80 static const char *time_units_str[] = { NULL, "fs", "ps", "ns", "us",
81 "\\mus", "ms", "s" };
82 static const char *time_units_xvgr[] = { NULL, "fs", "ps", "ns",
83 "ms", "s", NULL };
87 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
89 void output_env_init(output_env_t oenv, int argc, char *argv[],
90 time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
91 int verbosity, int debug_level)
93 int i;
94 int cmdlength=0;
95 char *argvzero=NULL;
97 oenv->time_unit = tmu;
98 oenv->view=view;
99 oenv->xvg_format = xvg_format;
100 oenv->verbosity=verbosity;
101 oenv->debug_level=debug_level;
102 oenv->program_name=NULL;
104 if (argv)
106 argvzero=argv[0];
107 assert(argvzero);
109 /* set program name */
110 /* When you run a dynamically linked program before installing
111 * it, libtool uses wrapper scripts and prefixes the name with "lt-".
112 * Until libtool is fixed to set argv[0] right, rip away the prefix:
114 if (argvzero)
116 if(strlen(argvzero)>3 && !strncmp(argvzero,"lt-",3))
117 oenv->program_name=strdup(argvzero+3);
118 else
119 oenv->program_name=strdup(argvzero);
121 if (oenv->program_name == NULL)
122 oenv->program_name = strdup("GROMACS");
124 /* copy command line */
125 if (argv)
127 cmdlength = strlen(argvzero);
128 for (i=1; i<argc; i++)
130 cmdlength += strlen(argv[i]);
134 /* Fill the cmdline string */
135 snew(oenv->cmd_line,cmdlength+argc+1);
136 if (argv)
138 for (i=0; i<argc; i++)
140 strcat(oenv->cmd_line,argv[i]);
141 strcat(oenv->cmd_line," ");
147 void output_env_init_default(output_env_t oenv)
149 output_env_init(oenv, 0, NULL, time_ps, FALSE, exvgNONE, 0, 0);
153 void output_env_done(output_env_t oenv)
155 sfree(oenv->program_name);
156 sfree(oenv->cmd_line);
157 sfree(oenv);
162 int output_env_get_verbosity(const output_env_t oenv)
164 return oenv->verbosity;
167 int output_env_get_debug_level(const output_env_t oenv)
169 return oenv->debug_level;
173 const char *output_env_get_time_unit(const output_env_t oenv)
175 return time_units_str[oenv->time_unit];
178 const char *output_env_get_time_label(const output_env_t oenv)
180 char *label;
181 snew(label, 20);
183 sprintf(label,"Time (%s)",time_units_str[oenv->time_unit] ?
184 time_units_str[oenv->time_unit]: "ps");
186 return label;
189 const char *output_env_get_xvgr_tlabel(const output_env_t oenv)
191 char *label;
192 snew(label, 20);
194 sprintf(label,"Time (%s)", time_units_xvgr[oenv->time_unit] ?
195 time_units_xvgr[oenv->time_unit] : "ps");
197 return label;
201 real output_env_get_time_factor(const output_env_t oenv)
203 return timefactors[oenv->time_unit];
206 real output_env_get_time_invfactor(const output_env_t oenv)
208 return timeinvfactors[oenv->time_unit];
211 real output_env_conv_time(const output_env_t oenv, real time)
213 return time*timefactors[oenv->time_unit];
217 void output_env_conv_times(const output_env_t oenv, int n, real *time)
219 int i;
220 double fact=timefactors[oenv->time_unit];
222 if (fact!=1.)
223 for(i=0; i<n; i++)
224 time[i] *= fact;
227 gmx_bool output_env_get_view(const output_env_t oenv)
229 return oenv->view;
232 xvg_format_t output_env_get_xvg_format(const output_env_t oenv)
234 return oenv->xvg_format;
237 const char *output_env_get_program_name(const output_env_t oenv)
239 return oenv->program_name;
242 const char *output_env_get_short_program_name(const output_env_t oenv)
244 const char *pr,*ret;
245 pr=ret=oenv->program_name;
246 if ((pr=strrchr(ret,DIR_SEPARATOR)) != NULL)
247 ret=pr+1;
248 /* Strip away the libtool prefix if it's still there. */
249 if(strlen(ret) > 3 && !strncmp(ret, "lt-", 3))
250 ret = ret + 3;
251 return ret;
256 const char *output_env_get_cmd_line(const output_env_t oenv)
258 return oenv->cmd_line;