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, 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"
47 #include "gromacs/utility/basedefinitions.h"
48 #include "gromacs/utility/cstringutil.h"
49 #include "gromacs/utility/fatalerror.h"
50 #include "gromacs/utility/smalloc.h"
52 /* XDR should be available on all platforms now,
53 * but we keep the possibility of turning it off...
58 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
59 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
63 eftASC, eftBIN, eftXDR, eftTNG, eftGEN, eftNR
66 /* To support multiple file types with one general (eg TRX) we have
69 static const int trxs[] =
74 efGRO, efG96, efPDB, efTNG
76 #define NTRXS asize(trxs)
78 static const int trcompressed[] =
85 #define NTRCOMPRESSED asize(trcompressed)
87 static const int tros[] =
92 efGRO, efG96, efPDB, efTNG
94 #define NTROS asize(tros)
96 static const int trns[] =
103 #define NTRNS asize(trns)
105 static const int stos[] =
106 { efGRO, efG96, efPDB, efBRK, efENT, efESP };
107 #define NSTOS asize(stos)
109 static const int stxs[] =
111 efGRO, efG96, efPDB, efBRK, efENT, efESP
116 #define NSTXS asize(stxs)
118 static const int tpss[] =
123 efGRO, efG96, efPDB, efBRK, efENT
125 #define NTPSS asize(tpss)
138 /* this array should correspond to the enum in filenm.h */
139 static const t_deffile
142 { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
143 { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
144 { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
145 { eftGEN, ".???", "traj", NULL,
146 "Full precision trajectory", NTRNS, trns },
147 { eftXDR, ".trr", "traj", NULL, "Trajectory in portable xdr format" },
148 { eftGEN, ".???", "traj_comp", NULL,
149 "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED, trcompressed},
150 { eftXDR, ".xtc", "traj", NULL,
151 "Compressed trajectory (portable xdr format): xtc" },
152 { eftTNG, ".tng", "traj", NULL,
153 "Trajectory file (tng format)" },
154 { eftXDR, ".edr", "ener", NULL, "Energy file"},
155 { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
156 { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
157 { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
158 { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
159 { eftASC, ".pdb", "eiwit", "-f", "Protein data bank file"},
160 { eftASC, ".brk", "eiwit", "-f", "Brookhaven data bank file"},
161 { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
162 { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
163 { eftASC, ".pqr", "state", "-o", "Coordinate file for MEAD"},
164 { eftXDR, ".cpt", "state", "-cp", "Checkpoint file"},
165 { eftASC, ".log", "run", "-l", "Log file"},
166 { eftASC, ".xvg", "graph", "-o", "xvgr/xmgr file"},
167 { eftASC, ".out", "hello", "-o", "Generic output file"},
168 { eftASC, ".ndx", "index", "-n", "Index file", },
169 { eftASC, ".top", "topol", "-p", "Topology file"},
170 { eftASC, ".itp", "topinc", NULL, "Include file for topology"},
171 { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
172 { eftXDR, ".tpr", "topol", "-s", "Portable xdr run input file"},
173 { eftASC, ".tex", "doc", "-o", "LaTeX file"},
174 { eftASC, ".rtp", "residue", NULL, "Residue Type file used by pdb2gmx" },
175 { eftASC, ".atp", "atomtp", NULL, "Atomtype file used by pdb2gmx" },
176 { eftASC, ".hdb", "polar", NULL, "Hydrogen data base"},
177 { eftASC, ".dat", "nnnice", NULL, "Generic data file"},
178 { eftASC, ".dlg", "user", NULL, "Dialog Box data for ngmx"},
179 { eftASC, ".map", "ss", NULL, "File that maps matrix data to colors" },
180 { eftASC, ".eps", "plot", NULL, "Encapsulated PostScript (tm) file" },
181 { eftASC, ".mat", "ss", NULL, "Matrix Data file"},
182 { eftASC, ".m2p", "ps", NULL, "Input file for mat2ps"},
183 { eftXDR, ".mtx", "hessian", "-m", "Hessian matrix"},
184 { eftASC, ".edi", "sam", NULL, "ED sampling input"},
185 { eftASC, ".cub", "pot", NULL, "Gaussian cube file" },
186 { eftASC, ".xpm", "root", NULL, "X PixMap compatible matrix file" },
187 { eftASC, "", "rundir", NULL, "Run directory" }
191 static const char *z_ext[NZEXT] =
194 const char *ftp2ext(int ftp)
196 if ((0 <= ftp) && (ftp < efNR))
198 return deffile[ftp].ext[0] != '\0' ? deffile[ftp].ext + 1 : "";
206 const char *ftp2ext_generic(int ftp)
208 if ((0 <= ftp) && (ftp < efNR))
232 const char *ftp2ext_with_dot(int ftp)
234 if ((0 <= ftp) && (ftp < efNR))
236 return deffile[ftp].ext;
244 int ftp2generic_count(int ftp)
246 if ((0 <= ftp) && (ftp < efNR))
248 return deffile[ftp].ntps;
256 const int *ftp2generic_list(int ftp)
258 if ((0 <= ftp) && (ftp < efNR))
260 return deffile[ftp].tps;
268 const char *ftp2desc(int ftp)
270 if ((0 <= ftp) && (ftp < efNR))
272 return deffile[ftp].descr;
276 return "unknown filetype";
280 const char *ftp2ftype(int ftp)
282 if ((ftp >= 0) && (ftp < efNR))
284 switch (deffile[ftp].ftype)
291 return "XDR portable";
297 gmx_fatal(FARGS, "Unknown filetype %d in ftp2ftype", deffile[ftp].ftype);
304 const char *ftp2defnm(int ftp)
306 if ((0 <= ftp) && (ftp < efNR))
308 return deffile[ftp].defnm;
316 const char *ftp2defopt(int ftp)
318 if ((0 <= ftp) && (ftp < efNR))
320 return deffile[ftp].defopt;
328 int fn2ftp(const char *fn)
340 if ((len >= 4) && (fn[len - 4] == '.'))
342 feptr = &(fn[len - 4]);
349 for (i = 0; (i < efNR); i++)
351 if ((eptr = deffile[i].ext) != NULL)
353 if (gmx_strcasecmp(feptr, eptr) == 0)
363 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
367 for (i = 0; (i < nfile); i++)
369 if (strcmp(opt, fnm[i].opt) == 0)
371 return fnm[i].fns[0];
375 fprintf(stderr, "No option %s\n", opt);
380 const char *opt2fn_master(const char *opt, int nfile, const t_filenm fnm[],
383 return SIMMASTER(cr) ? opt2fn(opt, nfile, fnm) : NULL;
386 int opt2fns(char **fns[], const char *opt, int nfile, const t_filenm fnm[])
390 for (i = 0; (i < nfile); i++)
392 if (strcmp(opt, fnm[i].opt) == 0)
395 return fnm[i].nfiles;
399 fprintf(stderr, "No option %s\n", opt);
403 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[])
407 for (i = 0; (i < nfile); i++)
409 if (ftp == fnm[i].ftp)
411 return fnm[i].fns[0];
415 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
419 int ftp2fns(char **fns[], int ftp, int nfile, const t_filenm fnm[])
423 for (i = 0; (i < nfile); i++)
425 if (ftp == fnm[i].ftp)
428 return fnm[i].nfiles;
432 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
436 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[])
440 for (i = 0; (i < nfile); i++)
442 if (ftp == fnm[i].ftp)
444 return (gmx_bool) IS_SET(fnm[i]);
448 fprintf(stderr, "ftp2bSet: No filetype %s\n", deffile[ftp].ext);
453 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[])
457 for (i = 0; (i < nfile); i++)
459 if (strcmp(opt, fnm[i].opt) == 0)
461 return (gmx_bool) IS_SET(fnm[i]);
465 fprintf(stderr, "No option %s\n", opt);
470 const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[])
474 for (i = 0; (i < nfile); i++)
476 if (strcmp(opt, fnm[i].opt) == 0)
478 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
484 return fnm[i].fns[0];
488 fprintf(stderr, "No option %s\n", opt);
492 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[])
496 for (i = 0; (i < nfile); i++)
498 if (ftp == fnm[i].ftp)
500 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
506 return fnm[i].fns[0];
510 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
514 gmx_bool is_optional(const t_filenm *fnm)
516 return ((fnm->flag & ffOPT) == ffOPT);
519 gmx_bool is_output(const t_filenm *fnm)
521 return ((fnm->flag & ffWRITE) == ffWRITE);
524 gmx_bool is_set(const t_filenm *fnm)
526 return ((fnm->flag & ffSET) == ffSET);
529 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
532 char buf[STRLEN], newname[STRLEN];
535 for (i = 0; i < nfile; i++)
537 if (is_output(&fnm[i]) && fnm[i].ftp != efCPT)
539 /* We never use multiple _outputs_, but we might as well check
540 for it, just in case... */
541 for (j = 0; j < fnm[i].nfiles; j++)
543 strncpy(buf, fnm[i].fns[j], STRLEN - 1);
544 extpos = strrchr(buf, '.');
546 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
547 sfree(fnm[i].fns[j]);
548 fnm[i].fns[j] = gmx_strdup(newname);
555 t_filenm *dup_tfn(int nf, const t_filenm tfn[])
561 for (i = 0; i < nf; i++)
563 ret[i] = tfn[i]; /* just directly copy all non-string fields */
566 ret[i].opt = gmx_strdup(tfn[i].opt);
575 ret[i].fn = gmx_strdup(tfn[i].fn);
582 if (tfn[i].nfiles > 0)
584 snew(ret[i].fns, tfn[i].nfiles);
585 for (j = 0; j < tfn[i].nfiles; j++)
587 ret[i].fns[j] = gmx_strdup(tfn[i].fns[j]);
594 void done_filenms(int nf, t_filenm fnm[])
598 for (i = 0; i < nf; ++i)
600 for (j = 0; j < fnm[i].nfiles; ++j)
602 sfree(fnm[i].fns[j]);