Remove .tpa, .tpb, .tpx, .trj files. Part of #1500.
[alexxy/gromacs.git] / src / gromacs / fileio / filenm.c
index 7cb81ca54e6424e875409fa174c83742dcba7c14..bf8212d2c85468be4e88b97aa65d9cf92146be9c 100644 (file)
@@ -2,8 +2,8 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#include "filenm.h"
+#include "gmxpre.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "filenm.h"
 
+#include <stdio.h>
 #include <string.h>
-#include "sysstuff.h"
-#include "typedefs.h"
-#include "smalloc.h"
-#include "string2.h"
-#include "gmx_fatal.h"
-#include "futil.h"
-#include "xdrf.h"
-#include "macros.h"
-
-#include "gromacs/onlinehelp/wman.h"
-
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
 
-/* NOTE: this was a cesspool of thread-unsafe code, has now been
-   properly proteced by mutexes (hopefully). */
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 
 /* XDR should be available on all platforms now,
  * but we keep the possibility of turning it off...
 /* Use bitflag ... */
 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
-#define IS_MULT(fn) ((fn.flag & ffMULT) != 0)
-#define UN_SET(fn) (fn.flag = (fn.flag & ~ffSET))
-#define DO_SET(fn) (fn.flag = (fn.flag |  ffSET))
 
 enum
 {
-    eftASC, eftBIN, eftXDR, eftGEN, eftNR
+    eftASC, eftBIN, eftXDR, eftTNG, eftGEN, eftNR
 };
 
 /* To support multiple file types with one general (eg TRX) we have
@@ -84,16 +71,25 @@ static const int trxs[] =
 #ifdef USE_XDR
     efXTC, efTRR, efCPT,
 #endif
-    efTRJ, efGRO, efG96, efPDB, efG87
+    efGRO, efG96, efPDB, efTNG
 };
 #define NTRXS asize(trxs)
 
+static const int trcompressed[] =
+{
+#ifdef USE_XDR
+    efXTC,
+#endif
+    efTNG
+};
+#define NTRCOMPRESSED asize(trcompressed)
+
 static const int tros[] =
 {
 #ifdef USE_XDR
     efXTC, efTRR,
 #endif
-    efTRJ, efGRO, efG96, efPDB, efG87
+    efGRO, efG96, efPDB, efTNG
 };
 #define NTROS asize(tros)
 
@@ -102,39 +98,29 @@ static const int trns[] =
 #ifdef USE_XDR
     efTRR, efCPT,
 #endif
-    efTRJ
+    efTNG
 };
 #define NTRNS asize(trns)
 
 static const int stos[] =
-{ efGRO, efG96, efPDB, efBRK, efENT, efESP, efXYZ };
+{ efGRO, efG96, efPDB, efBRK, efENT, efESP };
 #define NSTOS asize(stos)
 
 static const int stxs[] =
 {
-    efGRO, efG96, efPDB, efBRK, efENT, efESP, efXYZ,
+    efGRO, efG96, efPDB, efBRK, efENT, efESP
 #ifdef USE_XDR
-    efTPR,
+    , efTPR
 #endif
-    efTPB, efTPA
 };
 #define NSTXS asize(stxs)
 
-static const int tpxs[] =
-{
-#ifdef USE_XDR
-    efTPR,
-#endif
-    efTPB, efTPA
-};
-#define NTPXS asize(tpxs)
-
 static const int tpss[] =
 {
 #ifdef USE_XDR
     efTPR,
 #endif
-    efTPB, efTPA, efGRO, efG96, efPDB, efBRK, efENT
+    efGRO, efG96, efPDB, efBRK, efENT
 };
 #define NTPSS asize(tpss)
 
@@ -154,22 +140,20 @@ static const t_deffile
     deffile[efNR] =
 {
     { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
-    { eftGEN, ".???", "traj", "-f",
-      "Trajectory: xtc trr trj gro g96 pdb cpt", NTRXS, trxs },
-    { eftGEN, ".???", "trajout", "-f",
-      "Trajectory: xtc trr trj gro g96 pdb", NTROS, tros },
+    { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
+    { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
     { eftGEN, ".???", "traj", NULL,
-      "Full precision trajectory: trr trj cpt", NTRNS, trns },
+      "Full precision trajectory", NTRNS, trns },
     { eftXDR, ".trr", "traj", NULL, "Trajectory in portable xdr format" },
-    { eftBIN, ".trj", "traj", NULL, "Trajectory file (architecture specific)" },
+    { eftGEN, ".???", "traj_comp", NULL,
+      "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED, trcompressed},
     { eftXDR, ".xtc", "traj", NULL,
-      "Compressed trajectory (portable xdr format)" },
-    { eftASC, ".g87", "gtraj", NULL, "Gromos-87 ASCII trajectory format" },
+      "Compressed trajectory (portable xdr format): xtc" },
+    { eftTNG, ".tng", "traj", NULL,
+      "Trajectory file (tng format)" },
     { eftXDR, ".edr", "ener",   NULL, "Energy file"},
-    { eftGEN, ".???", "conf", "-c", "Structure file: gro g96 pdb tpr etc.",
-      NSTXS, stxs },
-    { eftGEN, ".???", "out", "-o", "Structure file: gro g96 pdb etc.",
-      NSTOS, stos },
+    { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
+    { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
     { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
     { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
     { eftASC, ".pdb", "eiwit",  "-f", "Protein data bank file"},
@@ -177,7 +161,6 @@ static const t_deffile
     { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
     { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
     { eftASC, ".pqr", "state",  "-o", "Coordinate file for MEAD"},
-    { eftASC, ".xyz", "conf", "-o", "Coordinate file for some other programs" },
     { eftXDR, ".cpt", "state",  "-cp", "Checkpoint file"},
     { eftASC, ".log", "run",    "-l", "Log file"},
     { eftASC, ".xvg", "graph",  "-o", "xvgr/xmgr file"},
@@ -185,13 +168,8 @@ static const t_deffile
     { eftASC, ".ndx", "index",  "-n", "Index file", },
     { eftASC, ".top", "topol",  "-p", "Topology file"},
     { eftASC, ".itp", "topinc", NULL, "Include file for topology"},
-    { eftGEN, ".???", "topol", "-s", "Run input file: tpr tpb tpa",
-      NTPXS, tpxs },
-    { eftGEN, ".???", "topol", "-s",
-      "Structure+mass(db): tpr tpb tpa gro g96 pdb", NTPSS, tpss },
+    { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
     { eftXDR, ".tpr", "topol",  "-s", "Portable xdr run input file"},
-    { eftASC, ".tpa", "topol",  "-s", "Ascii run input file"},
-    { eftBIN, ".tpb", "topol",  "-s", "Binary run input file"},
     { eftASC, ".tex", "doc",    "-o", "LaTeX file"},
     { eftASC, ".rtp", "residue", NULL, "Residue Type file used by pdb2gmx" },
     { eftASC, ".atp", "atomtp", NULL, "Atomtype file used by pdb2gmx" },
@@ -209,29 +187,10 @@ static const t_deffile
     { eftASC, "", "rundir", NULL, "Run directory" }
 };
 
-static char *default_file_name = NULL;
-
-#ifdef GMX_THREAD_MPI
-static tMPI_Thread_mutex_t filenm_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
-
 #define NZEXT 2
-const char *z_ext[NZEXT] =
+static const char *z_ext[NZEXT] =
 { ".gz", ".Z" };
 
-void set_default_file_name(const char *name)
-{
-    int i;
-#ifdef GMX_THREAD_MPI
-    tMPI_Thread_mutex_lock(&filenm_mutex);
-#endif
-    default_file_name = strdup(name);
-#ifdef GMX_THREAD_MPI
-    tMPI_Thread_mutex_unlock(&filenm_mutex);
-#endif
-
-}
-
 const char *ftp2ext(int ftp)
 {
     if ((0 <= ftp) && (ftp < efNR))
@@ -258,8 +217,6 @@ const char *ftp2ext_generic(int ftp)
                 return "sto";
             case efSTX:
                 return "stx";
-            case efTPX:
-                return "tpx";
             case efTPS:
                 return "tps";
             default:
@@ -332,6 +289,8 @@ const char *ftp2ftype(int ftp)
                 return "Binary";
             case eftXDR:
                 return "XDR portable";
+            case eftTNG:
+                return "TNG";
             case eftGEN:
                 return "";
             default:
@@ -344,198 +303,25 @@ const char *ftp2ftype(int ftp)
 
 const char *ftp2defnm(int ftp)
 {
-    const char *buf = NULL;
-
-#ifdef GMX_THREAD_MPI
-    tMPI_Thread_mutex_lock(&filenm_mutex);
-#endif
-
-    if (default_file_name)
+    if ((0 <= ftp) && (ftp < efNR))
     {
-        buf = default_file_name;
+        return deffile[ftp].defnm;
     }
     else
     {
-        if ((0 <= ftp) && (ftp < efNR))
-        {
-            buf = deffile[ftp].defnm;
-        }
+        return NULL;
     }
-#ifdef GMX_THREAD_MPI
-    tMPI_Thread_mutex_unlock(&filenm_mutex);
-#endif
-
-    return buf;
 }
 
-void pr_fns(FILE *fp, int nf, const t_filenm tfn[])
+const char *ftp2defopt(int ftp)
 {
-    int    i, f;
-    size_t j;
-    char   buf[256], *wbuf, opt_buf[32];
-#define OPTLEN 4
-#define NAMELEN 14
-    fprintf(fp, "%6s %12s  %-12s %s\n", "Option", "Filename", "Type",
-            "Description");
-    fprintf(fp,
-            "------------------------------------------------------------\n");
-    for (i = 0; (i < nf); i++)
-    {
-        for (f = 0; (f < tfn[i].nfiles); f++)
-        {
-            sprintf(buf, "%4s %14s  %-12s ", (f == 0) ? tfn[i].opt : "",
-                    tfn[i].fns[f], (f == 0) ? fileopt(tfn[i].flag, opt_buf)
-                    : "");
-            if (f < tfn[i].nfiles - 1)
-            {
-                fprintf(fp, "%s\n", buf);
-            }
-        }
-        if (tfn[i].nfiles > 0)
-        {
-            strcat(buf, deffile[tfn[i].ftp].descr);
-            if ((strlen(tfn[i].opt) > OPTLEN)
-                && (strlen(tfn[i].opt) <= ((OPTLEN + NAMELEN)
-                                           - strlen(tfn[i].fns[tfn[i].nfiles - 1]))))
-            {
-                for (j = strlen(tfn[i].opt); j < strlen(buf)
-                     - (strlen(tfn[i].opt) - OPTLEN) + 1; j++)
-                {
-                    buf[j] = buf[j + strlen(tfn[i].opt) - OPTLEN];
-                }
-            }
-            wbuf = wrap_lines(buf, 78, 35, FALSE);
-            fprintf(fp, "%s\n", wbuf);
-            sfree(wbuf);
-        }
-    }
-    fprintf(fp, "\n");
-    fflush(fp);
-}
-
-void pr_fopts(FILE *fp, int nf, const t_filenm tfn[], int shell)
-{
-    int i, j;
-
-    switch (shell)
+    if ((0 <= ftp) && (ftp < efNR))
     {
-        case eshellCSH:
-            for (i = 0; (i < nf); i++)
-            {
-                fprintf(fp, " \"n/%s/f:*.", tfn[i].opt);
-                if (deffile[tfn[i].ftp].ntps)
-                {
-                    fprintf(fp, "{");
-                    for (j = 0; j < deffile[tfn[i].ftp].ntps; j++)
-                    {
-                        if (j > 0)
-                        {
-                            fprintf(fp, ",");
-                        }
-                        fprintf(fp, "%s", deffile[deffile[tfn[i].ftp].tps[j]].ext
-                                + 1);
-                    }
-                    fprintf(fp, "}");
-                }
-                else
-                {
-                    fprintf(fp, "%s", deffile[tfn[i].ftp].ext + 1);
-                }
-                fprintf(fp, "{");
-                for (j = 0; j < NZEXT; j++)
-                {
-                    fprintf(fp, ",%s", z_ext[j]);
-                }
-                fprintf(fp, "}/\"");
-            }
-            break;
-        case eshellBASH:
-            for (i = 0; (i < nf); i++)
-            {
-                fprintf(fp, "%s) COMPREPLY=( $(compgen -X '!*.", tfn[i].opt);
-                if (deffile[tfn[i].ftp].ntps)
-                {
-                    fprintf(fp, "+(");
-                    for (j = 0; j < deffile[tfn[i].ftp].ntps; j++)
-                    {
-                        if (j > 0)
-                        {
-                            fprintf(fp, "|");
-                        }
-                        fprintf(fp, "%s", deffile[deffile[tfn[i].ftp].tps[j]].ext
-                                + 1);
-                    }
-                    fprintf(fp, ")");
-                }
-                else
-                {
-                    fprintf(fp, "%s", deffile[tfn[i].ftp].ext + 1);
-                }
-                fprintf(fp, "*(");
-                for (j = 0; j < NZEXT; j++)
-                {
-                    if (j > 0)
-                    {
-                        fprintf(fp, "|");
-                    }
-                    fprintf(fp, "%s", z_ext[j]);
-                }
-                fprintf(fp, ")' -f $c ; compgen -S '/' -X '.*' -d $c ));;\n");
-            }
-            break;
-        case eshellZSH:
-            for (i = 0; (i < nf); i++)
-            {
-                fprintf(fp, "- 'c[-1,%s]' -g '*.", tfn[i].opt);
-                if (deffile[tfn[i].ftp].ntps)
-                {
-                    fprintf(fp, "(");
-                    for (j = 0; j < deffile[tfn[i].ftp].ntps; j++)
-                    {
-                        if (j > 0)
-                        {
-                            fprintf(fp, "|");
-                        }
-                        fprintf(fp, "%s", deffile[deffile[tfn[i].ftp].tps[j]].ext
-                                + 1);
-                    }
-                    fprintf(fp, ")");
-                }
-                else
-                {
-                    fprintf(fp, "%s", deffile[tfn[i].ftp].ext + 1);
-                }
-                fprintf(fp, "(");
-                for (j = 0; j < NZEXT; j++)
-                {
-                    fprintf(fp, "|%s", z_ext[j]);
-                }
-                fprintf(fp, ") *(/)' ");
-            }
-            break;
+        return deffile[ftp].defopt;
     }
-}
-
-static void check_opts(int nf, t_filenm fnm[])
-{
-    int              i;
-    const t_deffile *df;
-
-    for (i = 0; (i < nf); i++)
+    else
     {
-        df = &(deffile[fnm[i].ftp]);
-        if (fnm[i].opt == NULL)
-        {
-            if (df->defopt == NULL)
-            {
-                gmx_fatal(FARGS, "No default cmd-line option for %s (type %d)\n",
-                          deffile[fnm[i].ftp].ext, fnm[i].ftp);
-            }
-            else
-            {
-                fnm[i].opt = df->defopt;
-            }
-        }
+        return NULL;
     }
 }
 
@@ -574,239 +360,6 @@ int fn2ftp(const char *fn)
     return i;
 }
 
-static void set_extension(char *buf, int ftp)
-{
-    int              len, extlen;
-    const t_deffile *df;
-
-    /* check if extension is already at end of filename */
-    df     = &(deffile[ftp]);
-    len    = strlen(buf);
-    extlen = strlen(df->ext);
-    if ((len <= extlen) || (gmx_strcasecmp(&(buf[len - extlen]), df->ext) != 0))
-    {
-        strcat(buf, df->ext);
-    }
-}
-
-static void add_filenm(t_filenm *fnm, const char *filenm)
-{
-    srenew(fnm->fns, fnm->nfiles+1);
-    fnm->fns[fnm->nfiles] = strdup(filenm);
-    fnm->nfiles++;
-}
-
-static void set_grpfnm(t_filenm *fnm, const char *name, gmx_bool bCanNotOverride)
-{
-    char       buf[256], buf2[256];
-    int        i, type;
-    gmx_bool   bValidExt;
-    int        nopts;
-    const int *ftps;
-
-    nopts = deffile[fnm->ftp].ntps;
-    ftps  = deffile[fnm->ftp].tps;
-    if ((nopts == 0) || (ftps == NULL))
-    {
-        gmx_fatal(FARGS, "nopts == 0 || ftps == NULL");
-    }
-
-    bValidExt = FALSE;
-    if (name && (bCanNotOverride || (default_file_name == NULL)))
-    {
-        strcpy(buf, name);
-        /* First check whether we have a valid filename already */
-        type = fn2ftp(name);
-        if ((fnm->flag & ffREAD) && (fnm->ftp == efTRX))
-        {
-            /*if file exist don't add an extension for trajectory reading*/
-            bValidExt = gmx_fexist(name);
-        }
-        for (i = 0; (i < nopts) && !bValidExt; i++)
-        {
-            if (type == ftps[i])
-            {
-                bValidExt = TRUE;
-            }
-        }
-    }
-    else
-    {
-        /* No name given, set the default name */
-        strcpy(buf, ftp2defnm(fnm->ftp));
-    }
-
-    if (!bValidExt && (fnm->flag & ffREAD))
-    {
-        /* for input-files only: search for filenames in the directory */
-        for (i = 0; (i < nopts) && !bValidExt; i++)
-        {
-            type = ftps[i];
-            strcpy(buf2, buf);
-            set_extension(buf2, type);
-            if (gmx_fexist(buf2))
-            {
-                bValidExt = TRUE;
-                strcpy(buf, buf2);
-            }
-        }
-    }
-
-    if (!bValidExt)
-    {
-        /* Use the first extension type */
-        set_extension(buf, ftps[0]);
-    }
-
-    add_filenm(fnm, buf);
-}
-
-static void set_filenm(t_filenm *fnm, const char *name, gmx_bool bCanNotOverride,
-                       gmx_bool bReadNode)
-{
-    /* Set the default filename, extension and option for those fields that
-     * are not already set. An extension is added if not present, if fn = NULL
-     * or empty, the default filename is given.
-     */
-    char buf[256];
-    int  i, len, extlen;
-
-    if ((fnm->flag & ffREAD) && !bReadNode)
-    {
-        return;
-    }
-
-    if ((fnm->ftp < 0) || (fnm->ftp >= efNR))
-    {
-        gmx_fatal(FARGS, "file type out of range (%d)", fnm->ftp);
-    }
-
-    if (name)
-    {
-        strcpy(buf, name);
-    }
-    if ((fnm->flag & ffREAD) && name && gmx_fexist(name))
-    {
-        /* check if filename ends in .gz or .Z, if so remove that: */
-        len = strlen(name);
-        for (i = 0; i < NZEXT; i++)
-        {
-            extlen = strlen(z_ext[i]);
-            if (len > extlen)
-            {
-                if (gmx_strcasecmp(name+len-extlen, z_ext[i]) == 0)
-                {
-                    buf[len-extlen] = '\0';
-                    break;
-                }
-            }
-        }
-    }
-
-    if (deffile[fnm->ftp].ntps)
-    {
-        set_grpfnm(fnm, name ? buf : NULL, bCanNotOverride);
-    }
-    else
-    {
-        if ((name == NULL) || !(bCanNotOverride || (default_file_name == NULL)))
-        {
-            const char *defnm = ftp2defnm(fnm->ftp);
-            strcpy(buf, defnm);
-        }
-        set_extension(buf, fnm->ftp);
-
-        add_filenm(fnm, buf);
-    }
-}
-
-static void set_filenms(int nf, t_filenm fnm[], gmx_bool bReadNode)
-{
-    int i;
-
-    for (i = 0; (i < nf); i++)
-    {
-        if (!IS_SET(fnm[i]))
-        {
-            set_filenm(&(fnm[i]), fnm[i].fn, FALSE, bReadNode);
-        }
-    }
-}
-
-void parse_file_args(int *argc, char *argv[], int nf, t_filenm fnm[],
-                     gmx_bool bKeep, gmx_bool bReadNode)
-{
-    int       i, j;
-    gmx_bool *bRemove;
-
-    check_opts(nf, fnm);
-
-    for (i = 0; (i < nf); i++)
-    {
-        UN_SET(fnm[i]);
-    }
-
-    if (*argc > 1)
-    {
-        snew(bRemove, (*argc)+1);
-        i = 1;
-        do
-        {
-            for (j = 0; (j < nf); j++)
-            {
-                if (strcmp(argv[i], fnm[j].opt) == 0)
-                {
-                    DO_SET(fnm[j]);
-                    bRemove[i] = TRUE;
-                    i++;
-                    /* check if we are out of arguments for this option */
-                    if ((i >= *argc) || (argv[i][0] == '-'))
-                    {
-                        set_filenm(&fnm[j], fnm[j].fn, FALSE, bReadNode);
-                    }
-                    /* sweep up all file arguments for this option */
-                    while ((i < *argc) && (argv[i][0] != '-'))
-                    {
-                        set_filenm(&fnm[j], argv[i], TRUE, bReadNode);
-                        bRemove[i] = TRUE;
-                        i++;
-                        /* only repeat for 'multiple' file options: */
-                        if (!IS_MULT(fnm[j]))
-                        {
-                            break;
-                        }
-                    }
-
-                    break; /* jump out of 'j' loop */
-                }
-            }
-            /* No file found corresponding to option argv[i] */
-            if (j == nf)
-            {
-                i++;
-            }
-        }
-        while (i < *argc);
-
-        if (!bKeep)
-        {
-            /* Remove used entries */
-            for (i = j = 0; (i <= *argc); i++)
-            {
-                if (!bRemove[i])
-                {
-                    argv[j++] = argv[i];
-                }
-            }
-            (*argc) = j - 1;
-        }
-        sfree(bRemove);
-    }
-
-    set_filenms(nf, fnm, bReadNode);
-
-}
-
 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
 {
     int i;
@@ -991,8 +544,8 @@ int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
                 extpos  = strrchr(buf, '.');
                 *extpos = '\0';
                 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
-                free(fnm[i].fns[j]);
-                fnm[i].fns[j] = strdup(newname);
+                sfree(fnm[i].fns[j]);
+                fnm[i].fns[j] = gmx_strdup(newname);
             }
         }
     }
@@ -1010,7 +563,7 @@ t_filenm *dup_tfn(int nf, const t_filenm tfn[])
         ret[i] = tfn[i]; /* just directly copy all non-string fields */
         if (tfn[i].opt)
         {
-            ret[i].opt = strdup(tfn[i].opt);
+            ret[i].opt = gmx_strdup(tfn[i].opt);
         }
         else
         {
@@ -1019,7 +572,7 @@ t_filenm *dup_tfn(int nf, const t_filenm tfn[])
 
         if (tfn[i].fn)
         {
-            ret[i].fn = strdup(tfn[i].fn);
+            ret[i].fn = gmx_strdup(tfn[i].fn);
         }
         else
         {
@@ -1031,7 +584,7 @@ t_filenm *dup_tfn(int nf, const t_filenm tfn[])
             snew(ret[i].fns, tfn[i].nfiles);
             for (j = 0; j < tfn[i].nfiles; j++)
             {
-                ret[i].fns[j] = strdup(tfn[i].fns[j]);
+                ret[i].fns[j] = gmx_strdup(tfn[i].fns[j]);
             }
         }
     }