Split lines with many copyright years
[gromacs.git] / src / gromacs / fileio / oenv.cpp
blob8f19e66c225aeb8f1c9d51992c7e79d47aea2356
1 /*
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,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source 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.
38 #include "gmxpre.h"
40 #include "oenv.h"
42 #include "gromacs/utility/exceptions.h"
43 #include "gromacs/utility/programcontext.h"
44 #include "gromacs/utility/smalloc.h"
45 #include "gromacs/utility/stringutil.h"
47 struct gmx_output_env_t
49 explicit gmx_output_env_t(const gmx::IProgramContext& context) :
50 programContext(context),
51 time_unit(time_ps),
52 view(FALSE),
53 xvg_format(exvgNONE),
54 verbosity(0),
55 trajectory_io_verbosity(0)
60 const gmx::IProgramContext& programContext;
62 /* the time unit, enum defined in oenv.h */
63 time_unit_t time_unit;
64 /* view of file requested */
65 gmx_bool view;
66 /* xvg output format, enum defined in oenv.h */
67 xvg_format_t xvg_format;
68 /* The level of verbosity for this program */
69 int verbosity;
70 /* The level of verbosity during trajectory I/O. Default=1, quiet=0. */
71 int trajectory_io_verbosity;
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[] = { real(0), real(1e3), real(1), real(1e-3),
86 real(1e-6), real(1e-9), real(1e-12), real(0) };
87 static const real timeinvfactors[] = { real(0), real(1e-3), real(1), real(1e3),
88 real(1e6), real(1e9), real(1e12), real(0) };
89 static const char* time_units_str[] = { nullptr, "fs", "ps", "ns", "us", "\\mus", "ms", "s" };
90 static const char* time_units_xvgr[] = { nullptr, "fs", "ps", "ns", "ms", "s", nullptr };
93 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
95 void output_env_init(gmx_output_env_t** oenvp,
96 const gmx::IProgramContext& context,
97 time_unit_t tmu,
98 gmx_bool view,
99 xvg_format_t xvg_format,
100 int verbosity)
104 gmx_output_env_t* oenv = new gmx_output_env_t(context);
105 *oenvp = oenv;
106 oenv->time_unit = tmu;
107 oenv->view = view;
108 oenv->xvg_format = xvg_format;
109 oenv->verbosity = verbosity;
110 const char* env = getenv("GMX_TRAJECTORY_IO_VERBOSITY");
111 oenv->trajectory_io_verbosity = (env != nullptr ? strtol(env, nullptr, 10) : 1);
113 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
116 void output_env_init_default(gmx_output_env_t** oenvp)
120 gmx_output_env_t* oenv = new gmx_output_env_t(gmx::getProgramContext());
121 *oenvp = oenv;
123 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
126 void output_env_done(gmx_output_env_t* oenv)
128 delete oenv;
132 int output_env_get_verbosity(const gmx_output_env_t* oenv)
134 return oenv->verbosity;
137 int output_env_get_trajectory_io_verbosity(const gmx_output_env_t* oenv)
139 return oenv->trajectory_io_verbosity;
142 std::string output_env_get_time_unit(const gmx_output_env_t* oenv)
144 return time_units_str[oenv->time_unit];
147 std::string output_env_get_time_label(const gmx_output_env_t* oenv)
149 return gmx::formatString(
150 "Time (%s)", time_units_str[oenv->time_unit] ? time_units_str[oenv->time_unit] : "ps");
153 std::string output_env_get_xvgr_tlabel(const gmx_output_env_t* oenv)
155 return gmx::formatString(
156 "Time (%s)", time_units_xvgr[oenv->time_unit] ? time_units_xvgr[oenv->time_unit] : "ps");
159 real output_env_get_time_factor(const gmx_output_env_t* oenv)
161 return timefactors[oenv->time_unit];
164 real output_env_get_time_invfactor(const gmx_output_env_t* oenv)
166 return timeinvfactors[oenv->time_unit];
169 real output_env_conv_time(const gmx_output_env_t* oenv, real time)
171 return time * timefactors[oenv->time_unit];
174 void output_env_conv_times(const gmx_output_env_t* oenv, int n, real* time)
176 int i;
177 double fact = timefactors[oenv->time_unit];
179 if (fact != 1.)
181 for (i = 0; i < n; i++)
183 time[i] *= fact;
188 gmx_bool output_env_get_view(const gmx_output_env_t* oenv)
190 return oenv->view;
193 xvg_format_t output_env_get_xvg_format(const gmx_output_env_t* oenv)
195 return oenv->xvg_format;
198 const char* output_env_get_program_display_name(const gmx_output_env_t* oenv)
200 const char* displayName = nullptr;
204 displayName = oenv->programContext.displayName();
206 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
208 return displayName;
211 const gmx::IProgramContext& output_env_get_program_context(const gmx_output_env_t* oenv)
213 return oenv->programContext;