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 efTRJ, 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 efTRJ, 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,
117 #define NSTXS asize(stxs)
119 static const int tpxs[] =
126 #define NTPXS asize(tpxs)
128 static const int tpss[] =
133 efTPB, efTPA, efGRO, efG96, efPDB, efBRK, efENT
135 #define NTPSS asize(tpss)
148 /* this array should correspond to the enum in filenm.h */
149 static const t_deffile
152 { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
153 { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
154 { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
155 { eftGEN, ".???", "traj", NULL,
156 "Full precision trajectory", NTRNS, trns },
157 { eftXDR, ".trr", "traj", NULL, "Trajectory in portable xdr format" },
158 { eftBIN, ".trj", "traj", NULL, "Trajectory file (architecture specific)" },
159 { eftGEN, ".???", "traj_comp", NULL,
160 "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED, trcompressed},
161 { eftXDR, ".xtc", "traj", NULL,
162 "Compressed trajectory (portable xdr format): xtc" },
163 { eftTNG, ".tng", "traj", NULL,
164 "Trajectory file (tng format)" },
165 { eftXDR, ".edr", "ener", NULL, "Energy file"},
166 { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
167 { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
168 { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
169 { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
170 { eftASC, ".pdb", "eiwit", "-f", "Protein data bank file"},
171 { eftASC, ".brk", "eiwit", "-f", "Brookhaven data bank file"},
172 { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
173 { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
174 { eftASC, ".pqr", "state", "-o", "Coordinate file for MEAD"},
175 { eftXDR, ".cpt", "state", "-cp", "Checkpoint file"},
176 { eftASC, ".log", "run", "-l", "Log file"},
177 { eftASC, ".xvg", "graph", "-o", "xvgr/xmgr file"},
178 { eftASC, ".out", "hello", "-o", "Generic output file"},
179 { eftASC, ".ndx", "index", "-n", "Index file", },
180 { eftASC, ".top", "topol", "-p", "Topology file"},
181 { eftASC, ".itp", "topinc", NULL, "Include file for topology"},
182 { eftGEN, ".???", "topol", "-s", "Run input file", NTPXS, tpxs },
183 { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
184 { eftXDR, ".tpr", "topol", "-s", "Portable xdr run input file"},
185 { eftASC, ".tpa", "topol", "-s", "Ascii run input file"},
186 { eftBIN, ".tpb", "topol", "-s", "Binary run input file"},
187 { eftASC, ".tex", "doc", "-o", "LaTeX file"},
188 { eftASC, ".rtp", "residue", NULL, "Residue Type file used by pdb2gmx" },
189 { eftASC, ".atp", "atomtp", NULL, "Atomtype file used by pdb2gmx" },
190 { eftASC, ".hdb", "polar", NULL, "Hydrogen data base"},
191 { eftASC, ".dat", "nnnice", NULL, "Generic data file"},
192 { eftASC, ".dlg", "user", NULL, "Dialog Box data for ngmx"},
193 { eftASC, ".map", "ss", NULL, "File that maps matrix data to colors" },
194 { eftASC, ".eps", "plot", NULL, "Encapsulated PostScript (tm) file" },
195 { eftASC, ".mat", "ss", NULL, "Matrix Data file"},
196 { eftASC, ".m2p", "ps", NULL, "Input file for mat2ps"},
197 { eftXDR, ".mtx", "hessian", "-m", "Hessian matrix"},
198 { eftASC, ".edi", "sam", NULL, "ED sampling input"},
199 { eftASC, ".cub", "pot", NULL, "Gaussian cube file" },
200 { eftASC, ".xpm", "root", NULL, "X PixMap compatible matrix file" },
201 { eftASC, "", "rundir", NULL, "Run directory" }
205 static const char *z_ext[NZEXT] =
208 const char *ftp2ext(int ftp)
210 if ((0 <= ftp) && (ftp < efNR))
212 return deffile[ftp].ext[0] != '\0' ? deffile[ftp].ext + 1 : "";
220 const char *ftp2ext_generic(int ftp)
222 if ((0 <= ftp) && (ftp < efNR))
248 const char *ftp2ext_with_dot(int ftp)
250 if ((0 <= ftp) && (ftp < efNR))
252 return deffile[ftp].ext;
260 int ftp2generic_count(int ftp)
262 if ((0 <= ftp) && (ftp < efNR))
264 return deffile[ftp].ntps;
272 const int *ftp2generic_list(int ftp)
274 if ((0 <= ftp) && (ftp < efNR))
276 return deffile[ftp].tps;
284 const char *ftp2desc(int ftp)
286 if ((0 <= ftp) && (ftp < efNR))
288 return deffile[ftp].descr;
292 return "unknown filetype";
296 const char *ftp2ftype(int ftp)
298 if ((ftp >= 0) && (ftp < efNR))
300 switch (deffile[ftp].ftype)
307 return "XDR portable";
313 gmx_fatal(FARGS, "Unknown filetype %d in ftp2ftype", deffile[ftp].ftype);
320 const char *ftp2defnm(int ftp)
322 if ((0 <= ftp) && (ftp < efNR))
324 return deffile[ftp].defnm;
332 const char *ftp2defopt(int ftp)
334 if ((0 <= ftp) && (ftp < efNR))
336 return deffile[ftp].defopt;
344 int fn2ftp(const char *fn)
356 if ((len >= 4) && (fn[len - 4] == '.'))
358 feptr = &(fn[len - 4]);
365 for (i = 0; (i < efNR); i++)
367 if ((eptr = deffile[i].ext) != NULL)
369 if (gmx_strcasecmp(feptr, eptr) == 0)
379 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
383 for (i = 0; (i < nfile); i++)
385 if (strcmp(opt, fnm[i].opt) == 0)
387 return fnm[i].fns[0];
391 fprintf(stderr, "No option %s\n", opt);
396 const char *opt2fn_master(const char *opt, int nfile, const t_filenm fnm[],
399 return SIMMASTER(cr) ? opt2fn(opt, nfile, fnm) : NULL;
402 int opt2fns(char **fns[], const char *opt, int nfile, const t_filenm fnm[])
406 for (i = 0; (i < nfile); i++)
408 if (strcmp(opt, fnm[i].opt) == 0)
411 return fnm[i].nfiles;
415 fprintf(stderr, "No option %s\n", opt);
419 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[])
423 for (i = 0; (i < nfile); i++)
425 if (ftp == fnm[i].ftp)
427 return fnm[i].fns[0];
431 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
435 int ftp2fns(char **fns[], int ftp, int nfile, const t_filenm fnm[])
439 for (i = 0; (i < nfile); i++)
441 if (ftp == fnm[i].ftp)
444 return fnm[i].nfiles;
448 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
452 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[])
456 for (i = 0; (i < nfile); i++)
458 if (ftp == fnm[i].ftp)
460 return (gmx_bool) IS_SET(fnm[i]);
464 fprintf(stderr, "ftp2bSet: No filetype %s\n", deffile[ftp].ext);
469 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[])
473 for (i = 0; (i < nfile); i++)
475 if (strcmp(opt, fnm[i].opt) == 0)
477 return (gmx_bool) IS_SET(fnm[i]);
481 fprintf(stderr, "No option %s\n", opt);
486 const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[])
490 for (i = 0; (i < nfile); i++)
492 if (strcmp(opt, fnm[i].opt) == 0)
494 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
500 return fnm[i].fns[0];
504 fprintf(stderr, "No option %s\n", opt);
508 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[])
512 for (i = 0; (i < nfile); i++)
514 if (ftp == fnm[i].ftp)
516 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
522 return fnm[i].fns[0];
526 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
530 gmx_bool is_optional(const t_filenm *fnm)
532 return ((fnm->flag & ffOPT) == ffOPT);
535 gmx_bool is_output(const t_filenm *fnm)
537 return ((fnm->flag & ffWRITE) == ffWRITE);
540 gmx_bool is_set(const t_filenm *fnm)
542 return ((fnm->flag & ffSET) == ffSET);
545 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
548 char buf[STRLEN], newname[STRLEN];
551 for (i = 0; i < nfile; i++)
553 if (is_output(&fnm[i]) && fnm[i].ftp != efCPT)
555 /* We never use multiple _outputs_, but we might as well check
556 for it, just in case... */
557 for (j = 0; j < fnm[i].nfiles; j++)
559 strncpy(buf, fnm[i].fns[j], STRLEN - 1);
560 extpos = strrchr(buf, '.');
562 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
563 sfree(fnm[i].fns[j]);
564 fnm[i].fns[j] = gmx_strdup(newname);
571 t_filenm *dup_tfn(int nf, const t_filenm tfn[])
577 for (i = 0; i < nf; i++)
579 ret[i] = tfn[i]; /* just directly copy all non-string fields */
582 ret[i].opt = gmx_strdup(tfn[i].opt);
591 ret[i].fn = gmx_strdup(tfn[i].fn);
598 if (tfn[i].nfiles > 0)
600 snew(ret[i].fns, tfn[i].nfiles);
601 for (j = 0; j < tfn[i].nfiles; j++)
603 ret[i].fns[j] = gmx_strdup(tfn[i].fns[j]);
610 void done_filenms(int nf, t_filenm fnm[])
614 for (i = 0; i < nf; ++i)
616 for (j = 0; j < fnm[i].nfiles; ++j)
618 sfree(fnm[i].fns[j]);