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,2018,2019,2020, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
41 #include "gromacs/utility/exceptions.h"
42 #include "gromacs/utility/programcontext.h"
43 #include "gromacs/utility/smalloc.h"
44 #include "gromacs/utility/stringutil.h"
46 struct gmx_output_env_t
48 explicit gmx_output_env_t(const gmx::IProgramContext
& context
) :
49 programContext(context
),
54 trajectory_io_verbosity(0)
59 const gmx::IProgramContext
& programContext
;
61 /* the time unit, enum defined in oenv.h */
62 time_unit_t time_unit
;
63 /* view of file requested */
65 /* xvg output format, enum defined in oenv.h */
66 xvg_format_t xvg_format
;
67 /* The level of verbosity for this program */
69 /* The level of verbosity during trajectory I/O. Default=1, quiet=0. */
70 int trajectory_io_verbosity
;
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
[] = { real(0), real(1e3
), real(1), real(1e-3),
85 real(1e-6), real(1e-9), real(1e-12), real(0) };
86 static const real timeinvfactors
[] = { real(0), real(1e-3), real(1), real(1e3
),
87 real(1e6
), real(1e9
), real(1e12
), real(0) };
88 static const char* time_units_str
[] = { nullptr, "fs", "ps", "ns", "us", "ms", "s" };
89 static const char* time_units_xvgr
[] = { nullptr, "fs", "ps", "ns", "\\mus", "ms", "s", nullptr };
92 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
94 void output_env_init(gmx_output_env_t
** oenvp
,
95 const gmx::IProgramContext
& context
,
98 xvg_format_t xvg_format
,
103 gmx_output_env_t
* oenv
= new gmx_output_env_t(context
);
105 oenv
->time_unit
= tmu
;
107 oenv
->xvg_format
= xvg_format
;
108 oenv
->verbosity
= verbosity
;
109 const char* env
= getenv("GMX_TRAJECTORY_IO_VERBOSITY");
110 oenv
->trajectory_io_verbosity
= (env
!= nullptr ? strtol(env
, nullptr, 10) : 1);
112 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
115 void output_env_init_default(gmx_output_env_t
** oenvp
)
119 gmx_output_env_t
* oenv
= new gmx_output_env_t(gmx::getProgramContext());
122 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
125 void output_env_done(gmx_output_env_t
* oenv
)
131 int output_env_get_verbosity(const gmx_output_env_t
* oenv
)
133 return oenv
->verbosity
;
136 int output_env_get_trajectory_io_verbosity(const gmx_output_env_t
* oenv
)
138 return oenv
->trajectory_io_verbosity
;
141 std::string
output_env_get_time_unit(const gmx_output_env_t
* oenv
)
143 return time_units_str
[oenv
->time_unit
];
146 std::string
output_env_get_time_label(const gmx_output_env_t
* oenv
)
148 return gmx::formatString(
149 "Time (%s)", time_units_str
[oenv
->time_unit
] ? time_units_str
[oenv
->time_unit
] : "ps");
152 std::string
output_env_get_xvgr_tlabel(const gmx_output_env_t
* oenv
)
154 return gmx::formatString(
155 "Time (%s)", time_units_xvgr
[oenv
->time_unit
] ? time_units_xvgr
[oenv
->time_unit
] : "ps");
158 real
output_env_get_time_factor(const gmx_output_env_t
* oenv
)
160 return timefactors
[oenv
->time_unit
];
163 real
output_env_get_time_invfactor(const gmx_output_env_t
* oenv
)
165 return timeinvfactors
[oenv
->time_unit
];
168 real
output_env_conv_time(const gmx_output_env_t
* oenv
, real time
)
170 return time
* timefactors
[oenv
->time_unit
];
173 void output_env_conv_times(const gmx_output_env_t
* oenv
, int n
, real
* time
)
176 double fact
= timefactors
[oenv
->time_unit
];
180 for (i
= 0; i
< n
; i
++)
187 gmx_bool
output_env_get_view(const gmx_output_env_t
* oenv
)
192 xvg_format_t
output_env_get_xvg_format(const gmx_output_env_t
* oenv
)
194 return oenv
->xvg_format
;
197 const char* output_env_get_program_display_name(const gmx_output_env_t
* oenv
)
199 const char* displayName
= nullptr;
203 displayName
= oenv
->programContext
.displayName();
205 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
210 const gmx::IProgramContext
& output_env_get_program_context(const gmx_output_env_t
* oenv
)
212 return oenv
->programContext
;