Split lines with many copyright years
[alexxy/gromacs.git] / src / gromacs / commandline / filenm.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
11  *
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.
16  *
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.
21  *
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.
26  *
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.
34  *
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.
37  */
38 /*! \file
39  * \brief
40  * Declares t_filenm for old-style command-line parsing of file name options.
41  *
42  * \inpublicapi
43  * \ingroup module_commandline
44  */
45 #ifndef GMX_COMMANDLINE_FILENM_H
46 #define GMX_COMMANDLINE_FILENM_H
47
48 #include <string>
49 #include <vector>
50
51 #include "gromacs/compat/string_view.h"
52 #include "gromacs/fileio/filetypes.h"
53 #include "gromacs/utility/arrayref.h"
54 #include "gromacs/utility/basedefinitions.h"
55
56
57 //! \addtogroup module_commandline
58 //! \{
59
60 /*! \brief
61  * File name option definition for C code.
62  *
63  * \inpublicapi
64  */
65 struct t_filenm
66 {
67     int                      ftp; //!< File type, see enum in filetypes.h
68     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
69     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
70     unsigned long            flag;      //!< Flag for all kinds of info (see defs)
71     std::vector<std::string> filenames; //!< File names
72 };
73
74 //! Whether a file name option is set.
75 #define ffSET 1 << 0
76 //! Whether a file name option specifies an input file.
77 #define ffREAD 1 << 1
78 //! Whether a file name option specifies an output file.
79 #define ffWRITE 1 << 2
80 //! Whether a file name option specifies an optional file.
81 #define ffOPT 1 << 3
82 //! Whether a file name option specifies a library file.
83 #define ffLIB 1 << 4
84 //! Whether a file name option accepts multiple file names.
85 #define ffMULT 1 << 5
86 //! Whether an input file name option accepts non-existent files.
87 #define ffALLOW_MISSING 1 << 6
88 //! Convenience flag for an input/output file.
89 #define ffRW (ffREAD | ffWRITE)
90 //! Convenience flag for an optional input file.
91 #define ffOPTRD (ffREAD | ffOPT)
92 //! Convenience flag for an optional output file.
93 #define ffOPTWR (ffWRITE | ffOPT)
94 //! Convenience flag for an optional input/output file.
95 #define ffOPTRW (ffRW | ffOPT)
96 //! Convenience flag for a library input file.
97 #define ffLIBRD (ffREAD | ffLIB)
98 //! Convenience flag for an optional library input file.
99 #define ffLIBOPTRD (ffOPTRD | ffLIB)
100 //! Convenience flag for an input file that accepts multiple files.
101 #define ffRDMULT (ffREAD | ffMULT)
102 //! Convenience flag for an optional input file that accepts multiple files.
103 #define ffOPTRDMULT (ffRDMULT | ffOPT)
104 //! Convenience flag for an output file that accepts multiple files.
105 #define ffWRMULT (ffWRITE | ffMULT)
106 //! Convenience flag for an optional output file that accepts multiple files.
107 #define ffOPTWRMULT (ffWRMULT | ffOPT)
108
109 /*! \brief
110  * Returns the filename belonging to cmd-line option opt, or NULL when
111  * no such option.
112  */
113 const char* opt2fn(const char* opt, int nfile, const t_filenm fnm[]);
114
115 /*! \brief
116  * Returns the filenames belonging to cmd-line option opt.
117  *
118  * An assertion will fail when the option does not exist.
119  */
120 gmx::ArrayRef<const std::string> opt2fns(const char* opt, int nfile, const t_filenm fnm[]);
121
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.
125  *
126  * An assertion will fail when the option does not exist.
127  */
128 gmx::ArrayRef<const std::string> opt2fnsIfOptionSet(const char* opt, int nfile, const t_filenm fnm[]);
129
130 //! Returns a file pointer from the filename.
131 #define opt2FILE(opt, nfile, fnm, mode) gmx_ffopen(opt2fn(opt, nfile, fnm), mode)
132
133 //! Returns the first file name with type ftp, or NULL when none found.
134 const char* ftp2fn(int ftp, int nfile, const t_filenm fnm[]);
135
136 /*! \brief
137  * Returns the filenames for the first option with type ftp.
138  *
139  * An assertion will fail when when none found.
140  */
141 gmx::ArrayRef<const std::string> ftp2fns(int ftp, int nfile, const t_filenm fnm[]);
142
143 //! Returns a file pointer from the file type.
144 #define ftp2FILE(ftp, nfile, fnm, mode) gmx_ffopen(ftp2fn(ftp, nfile, fnm), mode)
145
146 //! Returns TRUE when this file type has been found on the cmd-line.
147 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[]);
148
149 //! Returns TRUE when this option has been found on the cmd-line.
150 gmx_bool opt2bSet(const char* opt, int nfile, const t_filenm fnm[]);
151
152 /*! \brief
153  * Returns the file name belonging top cmd-line option opt, or NULL when
154  * no such option.
155  *
156  * Also return NULL when opt is optional and option is not set.
157  */
158 const char* opt2fn_null(const char* opt, int nfile, const t_filenm fnm[]);
159
160 /*! \brief
161  * Returns the first file name with type ftp, or NULL when none found.
162  *
163  * Also return NULL when ftp is optional and option is not set.
164  */
165 const char* ftp2fn_null(int ftp, int nfile, const t_filenm fnm[]);
166
167 //! Returns whether or not this filenm is optional.
168 gmx_bool is_optional(const t_filenm* fnm);
169
170 //! Returns whether or not this filenm is output.
171 gmx_bool is_output(const t_filenm* fnm);
172
173 //! Returns whether or not this filenm is set.
174 gmx_bool is_set(const t_filenm* fnm);
175
176 /*! \brief Return whether \c filename might have been produced by mdrun -noappend.
177  *
178  * If so, it must match "prefix.partNNNN.extension", for four decimal
179  * digits N and non-empty prefix and extension. */
180 bool hasSuffixFromNoAppend(gmx::compat::string_view filename);
181
182 /*! \brief
183  * When we do checkpointing, this routine is called to check for previous
184  * output files and append a '.partNNNN' suffix before the (output) file extensions.
185  * If there was already a '.partNNNN' suffix before the file extension, that
186  * is removed before the new suffix is added.
187  */
188 int add_suffix_to_output_names(t_filenm* fnm, int nfile, const char* suffix);
189
190 //! \}
191
192 #endif