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/types/commrec.h"
45 #include "gromacs/utility/arraysize.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" }
172 const char *ftp2ext(int ftp
)
174 if ((0 <= ftp
) && (ftp
< efNR
))
176 return deffile
[ftp
].ext
[0] != '\0' ? deffile
[ftp
].ext
+ 1 : "";
184 const char *ftp2ext_generic(int ftp
)
186 if ((0 <= ftp
) && (ftp
< efNR
))
210 const char *ftp2ext_with_dot(int ftp
)
212 if ((0 <= ftp
) && (ftp
< efNR
))
214 return deffile
[ftp
].ext
;
222 int ftp2generic_count(int ftp
)
224 if ((0 <= ftp
) && (ftp
< efNR
))
226 return deffile
[ftp
].ntps
;
234 const int *ftp2generic_list(int ftp
)
236 if ((0 <= ftp
) && (ftp
< efNR
))
238 return deffile
[ftp
].tps
;
246 const char *ftp2desc(int ftp
)
248 if ((0 <= ftp
) && (ftp
< efNR
))
250 return deffile
[ftp
].descr
;
254 return "unknown filetype";
258 gmx_bool
ftp_is_text(int ftp
)
260 if ((ftp
>= 0) && (ftp
< efNR
))
262 return deffile
[ftp
].ftype
== eftASC
;
267 gmx_bool
ftp_is_xdr(int ftp
)
269 if ((ftp
>= 0) && (ftp
< efNR
))
271 return deffile
[ftp
].ftype
== eftXDR
;
276 const char *ftp2defnm(int ftp
)
278 if ((0 <= ftp
) && (ftp
< efNR
))
280 return deffile
[ftp
].defnm
;
288 const char *ftp2defopt(int ftp
)
290 if ((0 <= ftp
) && (ftp
< efNR
))
292 return deffile
[ftp
].defopt
;
300 int fn2ftp(const char *fn
)
311 len
= std::strlen(fn
);
312 if ((len
>= 4) && (fn
[len
- 4] == '.'))
314 feptr
= &(fn
[len
- 4]);
321 for (i
= 0; (i
< efNR
); i
++)
323 if ((eptr
= deffile
[i
].ext
) != NULL
)
325 if (gmx_strcasecmp(feptr
, eptr
) == 0)
335 const char *opt2fn(const char *opt
, int nfile
, const t_filenm fnm
[])
339 for (i
= 0; (i
< nfile
); i
++)
341 if (std::strcmp(opt
, fnm
[i
].opt
) == 0)
343 return fnm
[i
].fns
[0];
347 fprintf(stderr
, "No option %s\n", opt
);
352 const char *opt2fn_master(const char *opt
, int nfile
, const t_filenm fnm
[],
355 return SIMMASTER(cr
) ? opt2fn(opt
, nfile
, fnm
) : NULL
;
358 int opt2fns(char **fns
[], const char *opt
, int nfile
, const t_filenm fnm
[])
362 for (i
= 0; (i
< nfile
); i
++)
364 if (strcmp(opt
, fnm
[i
].opt
) == 0)
367 return fnm
[i
].nfiles
;
371 fprintf(stderr
, "No option %s\n", opt
);
375 const char *ftp2fn(int ftp
, int nfile
, const t_filenm fnm
[])
379 for (i
= 0; (i
< nfile
); i
++)
381 if (ftp
== fnm
[i
].ftp
)
383 return fnm
[i
].fns
[0];
387 fprintf(stderr
, "ftp2fn: No filetype %s\n", deffile
[ftp
].ext
);
391 int ftp2fns(char **fns
[], int ftp
, int nfile
, const t_filenm fnm
[])
395 for (i
= 0; (i
< nfile
); i
++)
397 if (ftp
== fnm
[i
].ftp
)
400 return fnm
[i
].nfiles
;
404 fprintf(stderr
, "ftp2fn: No filetype %s\n", deffile
[ftp
].ext
);
408 gmx_bool
ftp2bSet(int ftp
, int nfile
, const t_filenm fnm
[])
412 for (i
= 0; (i
< nfile
); i
++)
414 if (ftp
== fnm
[i
].ftp
)
416 return (gmx_bool
) IS_SET(fnm
[i
]);
420 fprintf(stderr
, "ftp2bSet: No filetype %s\n", deffile
[ftp
].ext
);
425 gmx_bool
opt2bSet(const char *opt
, int nfile
, const t_filenm fnm
[])
429 for (i
= 0; (i
< nfile
); i
++)
431 if (std::strcmp(opt
, fnm
[i
].opt
) == 0)
433 return (gmx_bool
) IS_SET(fnm
[i
]);
437 fprintf(stderr
, "No option %s\n", opt
);
442 const char *opt2fn_null(const char *opt
, int nfile
, const t_filenm fnm
[])
446 for (i
= 0; (i
< nfile
); i
++)
448 if (std::strcmp(opt
, fnm
[i
].opt
) == 0)
450 if (IS_OPT(fnm
[i
]) && !IS_SET(fnm
[i
]))
456 return fnm
[i
].fns
[0];
460 fprintf(stderr
, "No option %s\n", opt
);
464 const char *ftp2fn_null(int ftp
, int nfile
, const t_filenm fnm
[])
468 for (i
= 0; (i
< nfile
); i
++)
470 if (ftp
== fnm
[i
].ftp
)
472 if (IS_OPT(fnm
[i
]) && !IS_SET(fnm
[i
]))
478 return fnm
[i
].fns
[0];
482 fprintf(stderr
, "ftp2fn: No filetype %s\n", deffile
[ftp
].ext
);
486 gmx_bool
is_optional(const t_filenm
*fnm
)
488 return ((fnm
->flag
& ffOPT
) == ffOPT
);
491 gmx_bool
is_output(const t_filenm
*fnm
)
493 return ((fnm
->flag
& ffWRITE
) == ffWRITE
);
496 gmx_bool
is_set(const t_filenm
*fnm
)
498 return ((fnm
->flag
& ffSET
) == ffSET
);
501 int add_suffix_to_output_names(t_filenm
*fnm
, int nfile
, const char *suffix
)
504 char buf
[STRLEN
], newname
[STRLEN
];
507 for (i
= 0; i
< nfile
; i
++)
509 if (is_output(&fnm
[i
]) && fnm
[i
].ftp
!= efCPT
)
511 /* We never use multiple _outputs_, but we might as well check
512 for it, just in case... */
513 for (j
= 0; j
< fnm
[i
].nfiles
; j
++)
515 std::strncpy(buf
, fnm
[i
].fns
[j
], STRLEN
- 1);
516 extpos
= strrchr(buf
, '.');
518 sprintf(newname
, "%s%s.%s", buf
, suffix
, extpos
+ 1);
519 sfree(fnm
[i
].fns
[j
]);
520 fnm
[i
].fns
[j
] = gmx_strdup(newname
);
527 t_filenm
*dup_tfn(int nf
, const t_filenm tfn
[])
533 for (i
= 0; i
< nf
; i
++)
535 ret
[i
] = tfn
[i
]; /* just directly copy all non-string fields */
538 ret
[i
].opt
= gmx_strdup(tfn
[i
].opt
);
547 ret
[i
].fn
= gmx_strdup(tfn
[i
].fn
);
554 if (tfn
[i
].nfiles
> 0)
556 snew(ret
[i
].fns
, tfn
[i
].nfiles
);
557 for (j
= 0; j
< tfn
[i
].nfiles
; j
++)
559 ret
[i
].fns
[j
] = gmx_strdup(tfn
[i
].fns
[j
]);
566 void done_filenms(int nf
, t_filenm fnm
[])
570 for (i
= 0; i
< nf
; ++i
)
572 for (j
= 0; j
< fnm
[i
].nfiles
; ++j
)
574 sfree(fnm
[i
].fns
[j
]);