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.
46 #include "gromacs/legacyheaders/macros.h"
47 #include "gromacs/legacyheaders/types/commrec.h"
49 #include "gromacs/utility/basedefinitions.h"
50 #include "gromacs/utility/cstringutil.h"
51 #include "gromacs/utility/fatalerror.h"
52 #include "gromacs/utility/smalloc.h"
54 /* XDR should be available on all platforms now,
55 * but we keep the possibility of turning it off...
60 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
61 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
65 eftASC, eftBIN, eftXDR, eftTNG, eftGEN, eftNR
68 /* To support multiple file types with one general (eg TRX) we have
71 static const int trxs[] =
76 efTRJ, efGRO, efG96, efPDB, efTNG
78 #define NTRXS asize(trxs)
80 static const int trcompressed[] =
87 #define NTRCOMPRESSED asize(trcompressed)
89 static const int tros[] =
94 efTRJ, efGRO, efG96, efPDB, efTNG
96 #define NTROS asize(tros)
98 static const int trns[] =
105 #define NTRNS asize(trns)
107 static const int stos[] =
108 { efGRO, efG96, efPDB, efBRK, efENT, efESP };
109 #define NSTOS asize(stos)
111 static const int stxs[] =
113 efGRO, efG96, efPDB, efBRK, efENT, efESP,
119 #define NSTXS asize(stxs)
121 static const int tpxs[] =
128 #define NTPXS asize(tpxs)
130 static const int tpss[] =
135 efTPB, efTPA, efGRO, efG96, efPDB, efBRK, efENT
137 #define NTPSS asize(tpss)
150 /* this array should correspond to the enum in filenm.h */
151 static const t_deffile
154 { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
155 { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
156 { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
157 { eftGEN, ".???", "traj", NULL,
158 "Full precision trajectory", NTRNS, trns },
159 { eftXDR, ".trr", "traj", NULL, "Trajectory in portable xdr format" },
160 { eftBIN, ".trj", "traj", NULL, "Trajectory file (architecture specific)" },
161 { eftGEN, ".???", "traj_comp", NULL,
162 "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED, trcompressed},
163 { eftXDR, ".xtc", "traj", NULL,
164 "Compressed trajectory (portable xdr format): xtc" },
165 { eftTNG, ".tng", "traj", NULL,
166 "Trajectory file (tng format)" },
167 { eftXDR, ".edr", "ener", NULL, "Energy file"},
168 { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
169 { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
170 { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
171 { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
172 { eftASC, ".pdb", "eiwit", "-f", "Protein data bank file"},
173 { eftASC, ".brk", "eiwit", "-f", "Brookhaven data bank file"},
174 { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
175 { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
176 { eftASC, ".pqr", "state", "-o", "Coordinate file for MEAD"},
177 { eftXDR, ".cpt", "state", "-cp", "Checkpoint file"},
178 { eftASC, ".log", "run", "-l", "Log file"},
179 { eftASC, ".xvg", "graph", "-o", "xvgr/xmgr file"},
180 { eftASC, ".out", "hello", "-o", "Generic output file"},
181 { eftASC, ".ndx", "index", "-n", "Index file", },
182 { eftASC, ".top", "topol", "-p", "Topology file"},
183 { eftASC, ".itp", "topinc", NULL, "Include file for topology"},
184 { eftGEN, ".???", "topol", "-s", "Run input file", NTPXS, tpxs },
185 { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
186 { eftXDR, ".tpr", "topol", "-s", "Portable xdr run input file"},
187 { eftASC, ".tpa", "topol", "-s", "Ascii run input file"},
188 { eftBIN, ".tpb", "topol", "-s", "Binary run input file"},
189 { eftASC, ".tex", "doc", "-o", "LaTeX file"},
190 { eftASC, ".rtp", "residue", NULL, "Residue Type file used by pdb2gmx" },
191 { eftASC, ".atp", "atomtp", NULL, "Atomtype file used by pdb2gmx" },
192 { eftASC, ".hdb", "polar", NULL, "Hydrogen data base"},
193 { eftASC, ".dat", "nnnice", NULL, "Generic data file"},
194 { eftASC, ".dlg", "user", NULL, "Dialog Box data for ngmx"},
195 { eftASC, ".map", "ss", NULL, "File that maps matrix data to colors" },
196 { eftASC, ".eps", "plot", NULL, "Encapsulated PostScript (tm) file" },
197 { eftASC, ".mat", "ss", NULL, "Matrix Data file"},
198 { eftASC, ".m2p", "ps", NULL, "Input file for mat2ps"},
199 { eftXDR, ".mtx", "hessian", "-m", "Hessian matrix"},
200 { eftASC, ".edi", "sam", NULL, "ED sampling input"},
201 { eftASC, ".cub", "pot", NULL, "Gaussian cube file" },
202 { eftASC, ".xpm", "root", NULL, "X PixMap compatible matrix file" },
203 { eftASC, "", "rundir", NULL, "Run directory" }
207 static const char *z_ext[NZEXT] =
210 const char *ftp2ext(int ftp)
212 if ((0 <= ftp) && (ftp < efNR))
214 return deffile[ftp].ext[0] != '\0' ? deffile[ftp].ext + 1 : "";
222 const char *ftp2ext_generic(int ftp)
224 if ((0 <= ftp) && (ftp < efNR))
250 const char *ftp2ext_with_dot(int ftp)
252 if ((0 <= ftp) && (ftp < efNR))
254 return deffile[ftp].ext;
262 int ftp2generic_count(int ftp)
264 if ((0 <= ftp) && (ftp < efNR))
266 return deffile[ftp].ntps;
274 const int *ftp2generic_list(int ftp)
276 if ((0 <= ftp) && (ftp < efNR))
278 return deffile[ftp].tps;
286 const char *ftp2desc(int ftp)
288 if ((0 <= ftp) && (ftp < efNR))
290 return deffile[ftp].descr;
294 return "unknown filetype";
298 const char *ftp2ftype(int ftp)
300 if ((ftp >= 0) && (ftp < efNR))
302 switch (deffile[ftp].ftype)
309 return "XDR portable";
315 gmx_fatal(FARGS, "Unknown filetype %d in ftp2ftype", deffile[ftp].ftype);
322 const char *ftp2defnm(int ftp)
324 if ((0 <= ftp) && (ftp < efNR))
326 return deffile[ftp].defnm;
334 const char *ftp2defopt(int ftp)
336 if ((0 <= ftp) && (ftp < efNR))
338 return deffile[ftp].defopt;
346 int fn2ftp(const char *fn)
358 if ((len >= 4) && (fn[len - 4] == '.'))
360 feptr = &(fn[len - 4]);
367 for (i = 0; (i < efNR); i++)
369 if ((eptr = deffile[i].ext) != NULL)
371 if (gmx_strcasecmp(feptr, eptr) == 0)
381 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
385 for (i = 0; (i < nfile); i++)
387 if (strcmp(opt, fnm[i].opt) == 0)
389 return fnm[i].fns[0];
393 fprintf(stderr, "No option %s\n", opt);
398 const char *opt2fn_master(const char *opt, int nfile, const t_filenm fnm[],
401 return SIMMASTER(cr) ? opt2fn(opt, nfile, fnm) : NULL;
404 int opt2fns(char **fns[], const char *opt, int nfile, const t_filenm fnm[])
408 for (i = 0; (i < nfile); i++)
410 if (strcmp(opt, fnm[i].opt) == 0)
413 return fnm[i].nfiles;
417 fprintf(stderr, "No option %s\n", opt);
421 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[])
425 for (i = 0; (i < nfile); i++)
427 if (ftp == fnm[i].ftp)
429 return fnm[i].fns[0];
433 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
437 int ftp2fns(char **fns[], int ftp, int nfile, const t_filenm fnm[])
441 for (i = 0; (i < nfile); i++)
443 if (ftp == fnm[i].ftp)
446 return fnm[i].nfiles;
450 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
454 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[])
458 for (i = 0; (i < nfile); i++)
460 if (ftp == fnm[i].ftp)
462 return (gmx_bool) IS_SET(fnm[i]);
466 fprintf(stderr, "ftp2bSet: No filetype %s\n", deffile[ftp].ext);
471 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[])
475 for (i = 0; (i < nfile); i++)
477 if (strcmp(opt, fnm[i].opt) == 0)
479 return (gmx_bool) IS_SET(fnm[i]);
483 fprintf(stderr, "No option %s\n", opt);
488 const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[])
492 for (i = 0; (i < nfile); i++)
494 if (strcmp(opt, fnm[i].opt) == 0)
496 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
502 return fnm[i].fns[0];
506 fprintf(stderr, "No option %s\n", opt);
510 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[])
514 for (i = 0; (i < nfile); i++)
516 if (ftp == fnm[i].ftp)
518 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
524 return fnm[i].fns[0];
528 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
532 gmx_bool is_optional(const t_filenm *fnm)
534 return ((fnm->flag & ffOPT) == ffOPT);
537 gmx_bool is_output(const t_filenm *fnm)
539 return ((fnm->flag & ffWRITE) == ffWRITE);
542 gmx_bool is_set(const t_filenm *fnm)
544 return ((fnm->flag & ffSET) == ffSET);
547 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
550 char buf[STRLEN], newname[STRLEN];
553 for (i = 0; i < nfile; i++)
555 if (is_output(&fnm[i]) && fnm[i].ftp != efCPT)
557 /* We never use multiple _outputs_, but we might as well check
558 for it, just in case... */
559 for (j = 0; j < fnm[i].nfiles; j++)
561 strncpy(buf, fnm[i].fns[j], STRLEN - 1);
562 extpos = strrchr(buf, '.');
564 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
565 sfree(fnm[i].fns[j]);
566 fnm[i].fns[j] = strdup(newname);
573 t_filenm *dup_tfn(int nf, const t_filenm tfn[])
579 for (i = 0; i < nf; i++)
581 ret[i] = tfn[i]; /* just directly copy all non-string fields */
584 ret[i].opt = strdup(tfn[i].opt);
593 ret[i].fn = strdup(tfn[i].fn);
600 if (tfn[i].nfiles > 0)
602 snew(ret[i].fns, tfn[i].nfiles);
603 for (j = 0; j < tfn[i].nfiles; j++)
605 ret[i].fns[j] = strdup(tfn[i].fns[j]);
612 void done_filenms(int nf, t_filenm fnm[])
616 for (i = 0; i < nf; ++i)
618 for (j = 0; j < fnm[i].nfiles; ++j)
620 sfree(fnm[i].fns[j]);