Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / commandline / filenm.h
blob7100f8640335d4496ba919b431a93cf812c60439
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,2018,2019, 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.
37 /*! \file
38 * \brief
39 * Declares t_filenm for old-style command-line parsing of file name options.
41 * \inpublicapi
42 * \ingroup module_commandline
44 #ifndef GMX_COMMANDLINE_FILENM_H
45 #define GMX_COMMANDLINE_FILENM_H
47 #include <string>
48 #include <vector>
50 #include "gromacs/compat/string_view.h"
51 #include "gromacs/fileio/filetypes.h"
52 #include "gromacs/utility/arrayref.h"
53 #include "gromacs/utility/basedefinitions.h"
56 //! \addtogroup module_commandline
57 //! \{
59 /*! \brief
60 * File name option definition for C code.
62 * \inpublicapi
64 struct t_filenm
66 int ftp; //!< File type, see enum in filetypes.h
67 const char * opt; //!< Command line option, can be nullptr in which case the commandline module, including all opt2??? functions below, will use the default option for the file type
68 const char * fn; //!< File name (as set in source code), can be nullptr in which case the commandline module will use the default file name for the file type
69 unsigned long flag; //!< Flag for all kinds of info (see defs)
70 std::vector<std::string> filenames; //!< File names
73 //! Whether a file name option is set.
74 #define ffSET 1<<0
75 //! Whether a file name option specifies an input file.
76 #define ffREAD 1<<1
77 //! Whether a file name option specifies an output file.
78 #define ffWRITE 1<<2
79 //! Whether a file name option specifies an optional file.
80 #define ffOPT 1<<3
81 //! Whether a file name option specifies a library file.
82 #define ffLIB 1<<4
83 //! Whether a file name option accepts multiple file names.
84 #define ffMULT 1<<5
85 //! Whether an input file name option accepts non-existent files.
86 #define ffALLOW_MISSING 1<<6
87 //! Convenience flag for an input/output file.
88 #define ffRW (ffREAD | ffWRITE)
89 //! Convenience flag for an optional input file.
90 #define ffOPTRD (ffREAD | ffOPT)
91 //! Convenience flag for an optional output file.
92 #define ffOPTWR (ffWRITE| ffOPT)
93 //! Convenience flag for an optional input/output file.
94 #define ffOPTRW (ffRW | ffOPT)
95 //! Convenience flag for a library input file.
96 #define ffLIBRD (ffREAD | ffLIB)
97 //! Convenience flag for an optional library input file.
98 #define ffLIBOPTRD (ffOPTRD | ffLIB)
99 //! Convenience flag for an input file that accepts multiple files.
100 #define ffRDMULT (ffREAD | ffMULT)
101 //! Convenience flag for an optional input file that accepts multiple files.
102 #define ffOPTRDMULT (ffRDMULT | ffOPT)
103 //! Convenience flag for an output file that accepts multiple files.
104 #define ffWRMULT (ffWRITE | ffMULT)
105 //! Convenience flag for an optional output file that accepts multiple files.
106 #define ffOPTWRMULT (ffWRMULT | ffOPT)
108 /*! \brief
109 * Returns the filename belonging to cmd-line option opt, or NULL when
110 * no such option.
112 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[]);
114 /*! \brief
115 * Returns the filenames belonging to cmd-line option opt.
117 * An assertion will fail when the option does not exist.
119 gmx::ArrayRef<const std::string>
120 opt2fns(const char *opt, int nfile, const t_filenm fnm[]);
122 /*! \brief
123 * Returns the filenames belonging to cmd-line option opt when set,
124 * returns an empty vector when the option is not set.
126 * An assertion will fail when the option does not exist.
128 gmx::ArrayRef<const std::string>
129 opt2fnsIfOptionSet(const char *opt, int nfile, const t_filenm fnm[]);
131 //! Returns a file pointer from the filename.
132 #define opt2FILE(opt, nfile, fnm, mode) gmx_ffopen(opt2fn(opt, nfile, fnm), mode)
134 //! Returns the first file name with type ftp, or NULL when none found.
135 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[]);
137 /*! \brief
138 * Returns the filenames for the first option with type ftp.
140 * An assertion will fail when when none found.
142 gmx::ArrayRef<const std::string>
143 ftp2fns(int ftp, int nfile, const t_filenm fnm[]);
145 //! Returns a file pointer from the file type.
146 #define ftp2FILE(ftp, nfile, fnm, mode) gmx_ffopen(ftp2fn(ftp, nfile, fnm), mode)
148 //! Returns TRUE when this file type has been found on the cmd-line.
149 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[]);
151 //! Returns TRUE when this option has been found on the cmd-line.
152 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[]);
154 /*! \brief
155 * Returns the file name belonging top cmd-line option opt, or NULL when
156 * no such option.
158 * Also return NULL when opt is optional and option is not set.
160 const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[]);
162 /*! \brief
163 * Returns the first file name with type ftp, or NULL when none found.
165 * Also return NULL when ftp is optional and option is not set.
167 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[]);
169 //! Returns whether or not this filenm is optional.
170 gmx_bool is_optional(const t_filenm *fnm);
172 //! Returns whether or not this filenm is output.
173 gmx_bool is_output(const t_filenm *fnm);
175 //! Returns whether or not this filenm is set.
176 gmx_bool is_set(const t_filenm *fnm);
178 /*! \brief Return whether \c filename might have been produced by mdrun -noappend.
180 * If so, it must match "prefix.partNNNN.extension", for four decimal
181 * digits N and non-empty prefix and extension. */
182 bool hasSuffixFromNoAppend(gmx::compat::string_view filename);
184 /*! \brief
185 * When we do checkpointing, this routine is called to check for previous
186 * output files and append a '.partNNNN' suffix before the (output) file extensions.
187 * If there was already a '.partNNNN' suffix before the file extension, that
188 * is removed before the new suffix is added.
190 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix);
192 //! \}
194 #endif