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.
40 #include "gromacs/fileio/oenv.h"
42 #include "gromacs/utility/enumerationhelpers.h"
43 #include "gromacs/utility/exceptions.h"
44 #include "gromacs/utility/programcontext.h"
45 #include "gromacs/utility/smalloc.h"
46 #include "gromacs/utility/stringutil.h"
48 struct gmx_output_env_t
50 explicit gmx_output_env_t(const gmx::IProgramContext
& context
) :
51 programContext(context
),
52 timeUnit(gmx::TimeUnit::Picoseconds
),
54 xvgFormat(XvgFormat::None
),
56 trajectory_io_verbosity(0)
61 const gmx::IProgramContext
& programContext
;
63 /* the time unit, enum defined in timeunitmanager.h */
64 gmx::TimeUnit timeUnit
;
65 /* view of file requested */
67 /* xvg output format, enum defined in oenv.h */
69 /* The level of verbosity for this program */
71 /* The level of verbosity during trajectory I/O. Default=1, quiet=0. */
72 int trajectory_io_verbosity
;
75 /* The source code in this file should be thread-safe.
76 Please keep it that way. */
78 /******************************************************************
80 * T R A J E C T O R Y S T U F F
82 ******************************************************************/
84 /* read only time names */
85 static const gmx::EnumerationArray
<gmx::TimeUnit
, real
> c_picosecondsInTimeUnit
= {
86 { real(1e3
), real(1), real(1e-3), real(1e-6), real(1e-9), real(1e-12) }
88 static const gmx::EnumerationArray
<gmx::TimeUnit
, real
> c_timeUnitsInPicoseconds
= {
89 { real(1e-3), real(1), real(1e3
), real(1e6
), real(1e9
), real(1e12
) }
91 static const gmx::EnumerationArray
<gmx::TimeUnit
, const char*> c_timeUnitNames
= {
92 { "fs", "ps", "ns", "us", "ms", "s" }
94 static const gmx::EnumerationArray
<gmx::TimeUnit
, const char*> c_timeUnitNamesForXvgr
= {
95 { "fs", "ps", "ns", "\\mus", "ms", "s" }
99 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
101 void output_env_init(gmx_output_env_t
** oenvp
,
102 const gmx::IProgramContext
& context
,
110 gmx_output_env_t
* oenv
= new gmx_output_env_t(context
);
112 oenv
->timeUnit
= tmu
;
114 oenv
->xvgFormat
= xvgFormat
;
115 oenv
->verbosity
= verbosity
;
116 const char* env
= getenv("GMX_TRAJECTORY_IO_VERBOSITY");
117 oenv
->trajectory_io_verbosity
= (env
!= nullptr ? strtol(env
, nullptr, 10) : 1);
119 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
122 void output_env_init_default(gmx_output_env_t
** oenvp
)
126 gmx_output_env_t
* oenv
= new gmx_output_env_t(gmx::getProgramContext());
129 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
132 void output_env_done(gmx_output_env_t
* oenv
)
138 int output_env_get_verbosity(const gmx_output_env_t
* oenv
)
140 return oenv
->verbosity
;
143 int output_env_get_trajectory_io_verbosity(const gmx_output_env_t
* oenv
)
145 return oenv
->trajectory_io_verbosity
;
148 std::string
output_env_get_time_unit(const gmx_output_env_t
* oenv
)
150 return c_timeUnitNames
[oenv
->timeUnit
];
153 std::string
output_env_get_time_label(const gmx_output_env_t
* oenv
)
155 return gmx::formatString("Time (%s)", c_timeUnitNames
[oenv
->timeUnit
]);
158 std::string
output_env_get_xvgr_tlabel(const gmx_output_env_t
* oenv
)
160 return gmx::formatString("Time (%s)", c_timeUnitNamesForXvgr
[oenv
->timeUnit
]);
163 real
output_env_get_time_factor(const gmx_output_env_t
* oenv
)
165 return c_picosecondsInTimeUnit
[oenv
->timeUnit
];
168 real
output_env_get_time_invfactor(const gmx_output_env_t
* oenv
)
170 return c_timeUnitsInPicoseconds
[oenv
->timeUnit
];
173 real
output_env_conv_time(const gmx_output_env_t
* oenv
, real time
)
175 return time
* c_picosecondsInTimeUnit
[oenv
->timeUnit
];
178 void output_env_conv_times(const gmx_output_env_t
* oenv
, int n
, real
* time
)
181 double fact
= c_picosecondsInTimeUnit
[oenv
->timeUnit
];
185 for (i
= 0; i
< n
; i
++)
192 gmx_bool
output_env_get_view(const gmx_output_env_t
* oenv
)
197 XvgFormat
output_env_get_xvg_format(const gmx_output_env_t
* oenv
)
199 return oenv
->xvgFormat
;
202 const char* output_env_get_program_display_name(const gmx_output_env_t
* oenv
)
204 const char* displayName
= nullptr;
208 displayName
= oenv
->programContext
.displayName();
210 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
215 const gmx::IProgramContext
& output_env_get_program_context(const gmx_output_env_t
* oenv
)
217 return oenv
->programContext
;