Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / fileio / 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, 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37
38 #ifndef GMX_FILEIO_FILENM_H
39 #define GMX_FILEIO_FILENM_H
40
41 #include "futil.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /* this enum should correspond to the array deffile in gmxlib/filenm.c */
48 enum {
49     efMDP,
50     efTRX, efTRO, efTRN, efTRR, efTRJ, efXTC, efG87,
51     efEDR,
52     efSTX, efSTO, efGRO, efG96, efPDB, efBRK, efENT, efESP, efPQR, efXYZ,
53     efCPT,
54     efLOG, efXVG, efOUT,
55     efNDX,
56     efTOP, efITP,
57     efTPX, efTPS, efTPR, efTPA, efTPB,
58     efTEX, efRTP, efATP, efHDB,
59     efDAT, efDLG,
60     efMAP, efEPS, efMAT, efM2P,
61     efMTX,
62     efEDI,
63     efCUB,
64     efXPM,
65     efRND,
66     efNR
67 };
68
69 typedef struct {
70     int           ftp;    /* File type (see enum above)         */
71     const char   *opt;    /* Command line option                        */
72     const char   *fn;     /* File name (as set in source code)  */
73     unsigned long flag;   /* Flag for all kinds of info (see defs)*/
74     int           nfiles; /* number of files                    */
75     char        **fns;    /* File names                         */
76 } t_filenm;
77
78 #define ffSET   1<<0
79 #define ffREAD  1<<1
80 #define ffWRITE 1<<2
81 #define ffOPT   1<<3
82 #define ffLIB   1<<4
83 #define ffMULT  1<<5
84 #define ffRW    (ffREAD | ffWRITE)
85 #define ffOPTRD (ffREAD | ffOPT)
86 #define ffOPTWR (ffWRITE| ffOPT)
87 #define ffOPTRW (ffRW   | ffOPT)
88 #define ffLIBRD (ffREAD | ffLIB)
89 #define ffLIBOPTRD (ffOPTRD | ffLIB)
90 #define ffRDMULT   (ffREAD  | ffMULT)
91 #define ffOPTRDMULT   (ffRDMULT | ffOPT)
92 #define ffWRMULT   (ffWRITE  | ffMULT)
93 #define ffOPTWRMULT   (ffWRMULT | ffOPT)
94
95 void set_default_file_name(const char *name);
96 /* Set the default file name for all file types to name */
97
98 const char *ftp2ext(int ftp);
99 /* Return extension for filetype */
100
101 const char *ftp2ext_generic(int ftp);
102 /* Return extension for filetype, and a generic name for generic types
103    (e.g. trx)*/
104
105 const char *ftp2ext_with_dot(int ftp);
106 /* Return extension for filetype with a leading dot */
107
108 int ftp2generic_count(int ftp);
109 /* Return the number of filetypes for a generic filetype */
110
111 const int *ftp2generic_list(int ftp);
112 /* Return the list of filetypes for a generic filetype */
113
114 const char *ftp2desc(int ftp);
115 /* Return description for file type */
116
117 const char *ftp2defnm(int ftp);
118 /* Return default file name for file type */
119
120 const char *ftp2ftype(int ftp);
121 /* Return Binary or ASCII depending on file type */
122
123 void pr_fns(FILE *fp, int nf, const t_filenm tfn[]);
124 /* Print nf file names and types */
125
126 void pr_fopts(FILE *fp, int nf, const t_filenm tfn[], int shell);
127 /* prints file options in tcsh 'complete' format */
128
129 void parse_file_args(int *argc, char *argv[], int nf, t_filenm fnm[],
130                      gmx_bool bKeep, gmx_bool bReadNode);
131 /* Parse command line for file names. When bKeep is set args are
132  * not removed from argv. */
133
134 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[]);
135 /* Return the filename belonging to cmd-line option opt, or NULL when
136  * no such option. */
137
138 const char *opt2fn_master(const char *opt, int nfile,
139                           const t_filenm fnm[], t_commrec *cr);
140 /* Return the filename belonging to cmd-line option opt, or NULL when
141  * no such option or not running on master */
142
143
144 int opt2fns(char **fns[], const char *opt, int nfile,
145             const t_filenm fnm[]);
146 /* Return the filenames belonging to cmd-line option opt, or NULL when
147  * no such option. */
148
149 #define opt2FILE(opt, nfile, fnm, mode) ffopen(opt2fn(opt, nfile, fnm), mode)
150 /* Return a file pointer from the filename (see above) */
151
152 int fn2ftp(const char *fn);
153 /* Return the filetype corrsponding to filename */
154
155 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[]);
156 /* Return the first file name with type ftp, or NULL when none found. */
157
158 int ftp2fns(char **fns[], int ftp, int nfile, const t_filenm fnm[]);
159 /* Return the number of files for the first option with type ftp
160    and the files in **fns[] (will be allocated), or NULL when none found. */
161
162 #define ftp2FILE(ftp, nfile, fnm, mode) ffopen(ftp2fn(ftp, nfile, fnm), mode)
163 /* Return a file pointer from the filename (see above) */
164
165 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[]);
166 /* Return TRUE when this file type has been found on the cmd-line */
167
168 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[]);
169 /* Return TRUE when this option has been found on the cmd-line */
170
171 const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[]);
172 /* Return the filenm belonging top cmd-line option opt, or NULL when
173  * no such option.
174  * Also return NULL when opt is optional and option is not set.
175  */
176
177 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[]);
178 /* Return the first file name with type ftp, or NULL when none found.
179  * Also return NULL when ftp is optional and option is not set.
180  */
181
182 gmx_bool is_optional(const t_filenm *fnm);
183 /* Return whether or not this filenm is optional */
184
185 gmx_bool is_output(const t_filenm *fnm);
186 /* Return whether or not this filenm is output */
187
188 gmx_bool is_set(const t_filenm *fnm);
189 /* Return whether or not this filenm is set */
190
191 /* When we do checkpointing, this routine is called to check for previous
192  * output files and append a '.partNNNN' suffix before the (output) file extensions.
193  */
194 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix);
195
196 /* duplicate the filename list (to make a private copy for each thread,
197    for example) */
198 t_filenm *dup_tfn(int nf, const t_filenm tfn[]);
199
200 /* Free memory allocated for file names by parse_file_args(). */
201 void done_filenms(int nf, t_filenm fnm[]);
202
203 #ifdef __cplusplus
204 }
205 #endif
206
207 #endif  /* GMX_FILEIO_FILENM_H */