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"
46 #include "gromacs/utility/basedefinitions.h"
47 #include "gromacs/utility/cstringutil.h"
48 #include "gromacs/utility/fatalerror.h"
49 #include "gromacs/utility/smalloc.h"
51 /* XDR should be available on all platforms now,
52 * but we keep the possibility of turning it off...
57 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
58 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
62 eftASC, eftBIN, eftXDR, eftTNG, eftGEN, eftNR
65 /* To support multiple file types with one general (eg TRX) we have
68 static const int trxs[] =
73 efGRO, efG96, efPDB, efTNG
75 #define NTRXS asize(trxs)
77 static const int trcompressed[] =
84 #define NTRCOMPRESSED asize(trcompressed)
86 static const int tros[] =
91 efGRO, efG96, efPDB, efTNG
93 #define NTROS asize(tros)
95 static const int trns[] =
102 #define NTRNS asize(trns)
104 static const int stos[] =
105 { efGRO, efG96, efPDB, efBRK, efENT, efESP };
106 #define NSTOS asize(stos)
108 static const int stxs[] =
110 efGRO, efG96, efPDB, efBRK, efENT, efESP
115 #define NSTXS asize(stxs)
117 static const int tpss[] =
122 efGRO, efG96, efPDB, efBRK, efENT
124 #define NTPSS asize(tpss)
137 /* this array should correspond to the enum in filenm.h */
138 static const t_deffile
141 { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
142 { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
143 { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
144 { eftGEN, ".???", "traj", NULL,
145 "Full precision trajectory", NTRNS, trns },
146 { eftXDR, ".trr", "traj", NULL, "Trajectory in portable xdr format" },
147 { eftGEN, ".???", "traj_comp", NULL,
148 "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED, trcompressed},
149 { eftXDR, ".xtc", "traj", NULL,
150 "Compressed trajectory (portable xdr format): xtc" },
151 { eftTNG, ".tng", "traj", NULL,
152 "Trajectory file (tng format)" },
153 { eftXDR, ".edr", "ener", NULL, "Energy file"},
154 { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
155 { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
156 { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
157 { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
158 { eftASC, ".pdb", "eiwit", "-f", "Protein data bank file"},
159 { eftASC, ".brk", "eiwit", "-f", "Brookhaven data bank file"},
160 { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
161 { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
162 { eftASC, ".pqr", "state", "-o", "Coordinate file for MEAD"},
163 { eftXDR, ".cpt", "state", "-cp", "Checkpoint file"},
164 { eftASC, ".log", "run", "-l", "Log file"},
165 { eftASC, ".xvg", "graph", "-o", "xvgr/xmgr file"},
166 { eftASC, ".out", "hello", "-o", "Generic output file"},
167 { eftASC, ".ndx", "index", "-n", "Index file", },
168 { eftASC, ".top", "topol", "-p", "Topology file"},
169 { eftASC, ".itp", "topinc", NULL, "Include file for topology"},
170 { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
171 { eftXDR, ".tpr", "topol", "-s", "Portable xdr run input file"},
172 { eftASC, ".tex", "doc", "-o", "LaTeX file"},
173 { eftASC, ".rtp", "residue", NULL, "Residue Type file used by pdb2gmx" },
174 { eftASC, ".atp", "atomtp", NULL, "Atomtype file used by pdb2gmx" },
175 { eftASC, ".hdb", "polar", NULL, "Hydrogen data base"},
176 { eftASC, ".dat", "nnnice", NULL, "Generic data file"},
177 { eftASC, ".dlg", "user", NULL, "Dialog Box data for ngmx"},
178 { eftASC, ".map", "ss", NULL, "File that maps matrix data to colors" },
179 { eftASC, ".eps", "plot", NULL, "Encapsulated PostScript (tm) file" },
180 { eftASC, ".mat", "ss", NULL, "Matrix Data file"},
181 { eftASC, ".m2p", "ps", NULL, "Input file for mat2ps"},
182 { eftXDR, ".mtx", "hessian", "-m", "Hessian matrix"},
183 { eftASC, ".edi", "sam", NULL, "ED sampling input"},
184 { eftASC, ".cub", "pot", NULL, "Gaussian cube file" },
185 { eftASC, ".xpm", "root", NULL, "X PixMap compatible matrix file" },
186 { eftASC, "", "rundir", NULL, "Run directory" }
190 static const char *z_ext[NZEXT] =
193 const char *ftp2ext(int ftp)
195 if ((0 <= ftp) && (ftp < efNR))
197 return deffile[ftp].ext[0] != '\0' ? deffile[ftp].ext + 1 : "";
205 const char *ftp2ext_generic(int ftp)
207 if ((0 <= ftp) && (ftp < efNR))
231 const char *ftp2ext_with_dot(int ftp)
233 if ((0 <= ftp) && (ftp < efNR))
235 return deffile[ftp].ext;
243 int ftp2generic_count(int ftp)
245 if ((0 <= ftp) && (ftp < efNR))
247 return deffile[ftp].ntps;
255 const int *ftp2generic_list(int ftp)
257 if ((0 <= ftp) && (ftp < efNR))
259 return deffile[ftp].tps;
267 const char *ftp2desc(int ftp)
269 if ((0 <= ftp) && (ftp < efNR))
271 return deffile[ftp].descr;
275 return "unknown filetype";
279 const char *ftp2ftype(int ftp)
281 if ((ftp >= 0) && (ftp < efNR))
283 switch (deffile[ftp].ftype)
290 return "XDR portable";
296 gmx_fatal(FARGS, "Unknown filetype %d in ftp2ftype", deffile[ftp].ftype);
303 const char *ftp2defnm(int ftp)
305 if ((0 <= ftp) && (ftp < efNR))
307 return deffile[ftp].defnm;
315 const char *ftp2defopt(int ftp)
317 if ((0 <= ftp) && (ftp < efNR))
319 return deffile[ftp].defopt;
327 int fn2ftp(const char *fn)
339 if ((len >= 4) && (fn[len - 4] == '.'))
341 feptr = &(fn[len - 4]);
348 for (i = 0; (i < efNR); i++)
350 if ((eptr = deffile[i].ext) != NULL)
352 if (gmx_strcasecmp(feptr, eptr) == 0)
362 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
366 for (i = 0; (i < nfile); i++)
368 if (strcmp(opt, fnm[i].opt) == 0)
370 return fnm[i].fns[0];
374 fprintf(stderr, "No option %s\n", opt);
379 const char *opt2fn_master(const char *opt, int nfile, const t_filenm fnm[],
382 return SIMMASTER(cr) ? opt2fn(opt, nfile, fnm) : NULL;
385 int opt2fns(char **fns[], const char *opt, int nfile, const t_filenm fnm[])
389 for (i = 0; (i < nfile); i++)
391 if (strcmp(opt, fnm[i].opt) == 0)
394 return fnm[i].nfiles;
398 fprintf(stderr, "No option %s\n", opt);
402 const char *ftp2fn(int ftp, int nfile, const t_filenm fnm[])
406 for (i = 0; (i < nfile); i++)
408 if (ftp == fnm[i].ftp)
410 return fnm[i].fns[0];
414 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
418 int ftp2fns(char **fns[], int ftp, int nfile, const t_filenm fnm[])
422 for (i = 0; (i < nfile); i++)
424 if (ftp == fnm[i].ftp)
427 return fnm[i].nfiles;
431 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
435 gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[])
439 for (i = 0; (i < nfile); i++)
441 if (ftp == fnm[i].ftp)
443 return (gmx_bool) IS_SET(fnm[i]);
447 fprintf(stderr, "ftp2bSet: No filetype %s\n", deffile[ftp].ext);
452 gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[])
456 for (i = 0; (i < nfile); i++)
458 if (strcmp(opt, fnm[i].opt) == 0)
460 return (gmx_bool) IS_SET(fnm[i]);
464 fprintf(stderr, "No option %s\n", opt);
469 const char *opt2fn_null(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 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
483 return fnm[i].fns[0];
487 fprintf(stderr, "No option %s\n", opt);
491 const char *ftp2fn_null(int ftp, int nfile, const t_filenm fnm[])
495 for (i = 0; (i < nfile); i++)
497 if (ftp == fnm[i].ftp)
499 if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
505 return fnm[i].fns[0];
509 fprintf(stderr, "ftp2fn: No filetype %s\n", deffile[ftp].ext);
513 gmx_bool is_optional(const t_filenm *fnm)
515 return ((fnm->flag & ffOPT) == ffOPT);
518 gmx_bool is_output(const t_filenm *fnm)
520 return ((fnm->flag & ffWRITE) == ffWRITE);
523 gmx_bool is_set(const t_filenm *fnm)
525 return ((fnm->flag & ffSET) == ffSET);
528 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
531 char buf[STRLEN], newname[STRLEN];
534 for (i = 0; i < nfile; i++)
536 if (is_output(&fnm[i]) && fnm[i].ftp != efCPT)
538 /* We never use multiple _outputs_, but we might as well check
539 for it, just in case... */
540 for (j = 0; j < fnm[i].nfiles; j++)
542 strncpy(buf, fnm[i].fns[j], STRLEN - 1);
543 extpos = strrchr(buf, '.');
545 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
546 sfree(fnm[i].fns[j]);
547 fnm[i].fns[j] = gmx_strdup(newname);
554 t_filenm *dup_tfn(int nf, const t_filenm tfn[])
560 for (i = 0; i < nf; i++)
562 ret[i] = tfn[i]; /* just directly copy all non-string fields */
565 ret[i].opt = gmx_strdup(tfn[i].opt);
574 ret[i].fn = gmx_strdup(tfn[i].fn);
581 if (tfn[i].nfiles > 0)
583 snew(ret[i].fns, tfn[i].nfiles);
584 for (j = 0; j < tfn[i].nfiles; j++)
586 ret[i].fns[j] = gmx_strdup(tfn[i].fns[j]);
593 void done_filenms(int nf, t_filenm fnm[])
597 for (i = 0; i < nf; ++i)
599 for (j = 0; j < fnm[i].nfiles; ++j)
601 sfree(fnm[i].fns[j]);