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, 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.
44 #include "gromacs/legacyheaders/macros.h"
45 #include "gromacs/legacyheaders/types/commrec.h"
46 #include "gromacs/utility/basedefinitions.h"
47 #include "gromacs/utility/cstringutil.h"
48 #include "gromacs/utility/fatalerror.h"
49 #include "gromacs/utility/smalloc.h"
52 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
53 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
57 eftASC, eftXDR, eftTNG, eftGEN, eftNR
60 /* To support multiple file types with one general (eg TRX) we have
63 static const int trxs[] =
66 efGRO, efG96, efPDB, efTNG
68 #define NTRXS asize(trxs)
70 static const int trcompressed[] =
75 #define NTRCOMPRESSED asize(trcompressed)
77 static const int tros[] =
80 efGRO, efG96, efPDB, efTNG
82 #define NTROS asize(tros)
84 static const int trns[] =
89 #define NTRNS asize(trns)
91 static const int stos[] =
92 { efGRO, efG96, efPDB, efBRK, efENT, efESP };
93 #define NSTOS asize(stos)
95 static const int stxs[] =
97 efGRO, efG96, efPDB, efBRK, efENT, efESP,
100 #define NSTXS asize(stxs)
102 static const int tpss[] =
105 efGRO, efG96, efPDB, efBRK, efENT
107 #define NTPSS asize(tpss)
120 /* this array should correspond to the enum in filenm.h */
121 static const t_deffile
124 { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
125 { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
126 { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
127 { eftGEN, ".???", "traj", NULL,
128 "Full precision trajectory", NTRNS, trns },
129 { eftXDR, ".trr", "traj", NULL, "Trajectory in portable xdr format" },
130 { eftGEN, ".???", "traj_comp", NULL,
131 "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED, trcompressed},
132 { eftXDR, ".xtc", "traj", NULL,
133 "Compressed trajectory (portable xdr format): xtc" },
134 { eftTNG, ".tng", "traj", NULL,
135 "Trajectory file (tng format)" },
136 { eftXDR, ".edr", "ener", NULL, "Energy file"},
137 { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
138 { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
139 { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
140 { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
141 { eftASC, ".pdb", "eiwit", "-f", "Protein data bank file"},
142 { eftASC, ".brk", "eiwit", "-f", "Brookhaven data bank file"},
143 { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
144 { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
145 { eftASC, ".pqr", "state", "-o", "Coordinate file for MEAD"},
146 { eftXDR, ".cpt", "state", "-cp", "Checkpoint file"},
147 { eftASC, ".log", "run", "-l", "Log file"},
148 { eftASC, ".xvg", "graph", "-o", "xvgr/xmgr file"},
149 { eftASC, ".out", "hello", "-o", "Generic output file"},
150 { eftASC, ".ndx", "index", "-n", "Index file", },
151 { eftASC, ".top", "topol", "-p", "Topology file"},
152 { eftASC, ".itp", "topinc", NULL, "Include file for topology"},
153 { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
154 { eftXDR, ".tpr", "topol", "-s", "Portable xdr run input file"},
155 { eftASC, ".tex", "doc", "-o", "LaTeX file"},
156 { eftASC, ".rtp", "residue", NULL, "Residue Type file used by pdb2gmx" },
157 { eftASC, ".atp", "atomtp", NULL, "Atomtype file used by pdb2gmx" },
158 { eftASC, ".hdb", "polar", NULL, "Hydrogen data base"},
159 { eftASC, ".dat", "nnnice", NULL, "Generic data file"},
160 { eftASC, ".dlg", "user", NULL, "Dialog Box data for ngmx"},
161 { eftASC, ".map", "ss", NULL, "File that maps matrix data to colors" },
162 { eftASC, ".eps", "plot", NULL, "Encapsulated PostScript (tm) file" },
163 { eftASC, ".mat", "ss", NULL, "Matrix Data file"},
164 { eftASC, ".m2p", "ps", NULL, "Input file for mat2ps"},
165 { eftXDR, ".mtx", "hessian", "-m", "Hessian matrix"},
166 { eftASC, ".edi", "sam", NULL, "ED sampling input"},
167 { eftASC, ".cub", "pot", NULL, "Gaussian cube file" },
168 { eftASC, ".xpm", "root", NULL, "X PixMap compatible matrix file" },
169 { eftASC, "", "rundir", NULL, "Run directory" }
173 static const char *z_ext[NZEXT] =
176 const char *ftp2ext(int ftp)
178 if ((0 <= ftp) && (ftp < efNR))
180 return deffile[ftp].ext[0] != '\0' ? deffile[ftp].ext + 1 : "";
188 const char *ftp2ext_generic(int ftp)
190 if ((0 <= ftp) && (ftp < efNR))
214 const char *ftp2ext_with_dot(int ftp)
216 if ((0 <= ftp) && (ftp < efNR))
218 return deffile[ftp].ext;
226 int ftp2generic_count(int ftp)
228 if ((0 <= ftp) && (ftp < efNR))
230 return deffile[ftp].ntps;
238 const int *ftp2generic_list(int ftp)
240 if ((0 <= ftp) && (ftp < efNR))
242 return deffile[ftp].tps;
250 const char *ftp2desc(int ftp)
252 if ((0 <= ftp) && (ftp < efNR))
254 return deffile[ftp].descr;
258 return "unknown filetype";
262 gmx_bool ftp_is_text(int ftp)
264 if ((ftp >= 0) && (ftp < efNR))
266 return deffile[ftp].ftype == eftASC;
271 gmx_bool ftp_is_xdr(int ftp)
273 if ((ftp >= 0) && (ftp < efNR))
275 return deffile[ftp].ftype == eftXDR;
280 const char *ftp2defnm(int ftp)
282 if ((0 <= ftp) && (ftp < efNR))
284 return deffile[ftp].defnm;
292 const char *ftp2defopt(int ftp)
294 if ((0 <= ftp) && (ftp < efNR))
296 return deffile[ftp].defopt;
304 int fn2ftp(const char *fn)
316 if ((len >= 4) && (fn[len - 4] == '.'))
318 feptr = &(fn[len - 4]);
325 for (i = 0; (i < efNR); i++)
327 if ((eptr = deffile[i].ext) != NULL)
329 if (gmx_strcasecmp(feptr, eptr) == 0)
339 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
343 for (i = 0; (i < nfile); i++)
345 if (strcmp(opt, fnm[i].opt) == 0)
347 return fnm[i].fns[0];
351 fprintf(stderr, "No option %s\n", opt);
356 const char *opt2fn_master(const char *opt, int nfile, const t_filenm fnm[],
359 return SIMMASTER(cr) ? opt2fn(opt, nfile, fnm) : NULL;
362 int opt2fns(char **fns[], const char *opt, int nfile, const t_filenm fnm[])
366 for (i = 0; (i < nfile); i++)
368 if (strcmp(opt, fnm[i].opt) == 0)
371 return fnm[i].nfiles;
375 fprintf(stderr, "No option %s\n", opt);
379 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[])
383 for (i = 0; (i < nfile); i++)
385 if (ftp == fnm[i].ftp)
387 return fnm[i].fns[0];
391 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
395 int ftp2fns(char **fns[], int ftp, int nfile, const t_filenm fnm[])
399 for (i = 0; (i < nfile); i++)
401 if (ftp == fnm[i].ftp)
404 return fnm[i].nfiles;
408 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
412 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[])
416 for (i = 0; (i < nfile); i++)
418 if (ftp == fnm[i].ftp)
420 return (gmx_bool) IS_SET(fnm[i]);
424 fprintf(stderr, "ftp2bSet: No filetype %s\n", deffile[ftp].ext);
429 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[])
433 for (i = 0; (i < nfile); i++)
435 if (strcmp(opt, fnm[i].opt) == 0)
437 return (gmx_bool) IS_SET(fnm[i]);
441 fprintf(stderr, "No option %s\n", opt);
446 const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[])
450 for (i = 0; (i < nfile); i++)
452 if (strcmp(opt, fnm[i].opt) == 0)
454 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
460 return fnm[i].fns[0];
464 fprintf(stderr, "No option %s\n", opt);
468 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[])
472 for (i = 0; (i < nfile); i++)
474 if (ftp == fnm[i].ftp)
476 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
482 return fnm[i].fns[0];
486 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
490 gmx_bool is_optional(const t_filenm *fnm)
492 return ((fnm->flag & ffOPT) == ffOPT);
495 gmx_bool is_output(const t_filenm *fnm)
497 return ((fnm->flag & ffWRITE) == ffWRITE);
500 gmx_bool is_set(const t_filenm *fnm)
502 return ((fnm->flag & ffSET) == ffSET);
505 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
508 char buf[STRLEN], newname[STRLEN];
511 for (i = 0; i < nfile; i++)
513 if (is_output(&fnm[i]) && fnm[i].ftp != efCPT)
515 /* We never use multiple _outputs_, but we might as well check
516 for it, just in case... */
517 for (j = 0; j < fnm[i].nfiles; j++)
519 strncpy(buf, fnm[i].fns[j], STRLEN - 1);
520 extpos = strrchr(buf, '.');
522 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
523 sfree(fnm[i].fns[j]);
524 fnm[i].fns[j] = gmx_strdup(newname);
531 t_filenm *dup_tfn(int nf, const t_filenm tfn[])
537 for (i = 0; i < nf; i++)
539 ret[i] = tfn[i]; /* just directly copy all non-string fields */
542 ret[i].opt = gmx_strdup(tfn[i].opt);
551 ret[i].fn = gmx_strdup(tfn[i].fn);
558 if (tfn[i].nfiles > 0)
560 snew(ret[i].fns, tfn[i].nfiles);
561 for (j = 0; j < tfn[i].nfiles; j++)
563 ret[i].fns[j] = gmx_strdup(tfn[i].fns[j]);
570 void done_filenms(int nf, t_filenm fnm[])
574 for (i = 0; i < nf; ++i)
576 for (j = 0; j < fnm[i].nfiles; ++j)
578 sfree(fnm[i].fns[j]);