Remove .tpa, .tpb, .tpx, .trj files. Part of #1500.
[alexxy/gromacs.git] / src / gromacs / fileio / gmxfio.c
index 0c8931847e85fbb06eed9ab06e4fc92cbe9a6b30..24dbc9f54a26b3b2ef46c767432d48d5e749c27a 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
+
+#include "config.h"
 
-#include <ctype.h>
-#include <stdio.h>
 #include <errno.h>
+#include <stdio.h>
+#include <string.h>
 #ifdef HAVE_IO_H
 #include <io.h>
 #endif
 #include <unistd.h>
 #endif
 
-#include "gmx_fatal.h"
-#include "macros.h"
-#include "smalloc.h"
-#include "futil.h"
+#include "thread_mpi/threads.h"
+
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/futil.h"
 #include "filenm.h"
-#include "string2.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gmxfio.h"
 #include "md5.h"
 
-#include "gromacs/legacyheaders/thread_mpi/threads.h"
-
 #include "gmxfio_int.h"
 
 /* This is the new improved and thread safe version of gmxfio. */
@@ -86,51 +86,20 @@ static tMPI_Thread_mutex_t open_file_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
 static const int ftpXDR[] =
 { efTPR, efTRR, efEDR, efXTC, efTNG, efMTX, efCPT };
 static const int ftpASC[] =
-{ efTPA, efGRO, efPDB };
+{ efGRO, efPDB, efG96 };
 static const int ftpBIN[] =
-{ efTPB, efTRJ, efTNG };
+{ efTNG };
 #ifdef HAVE_XML
 static const int ftpXML[] =
 {   efXML};
 #endif
 
-const char *itemstr[eitemNR] =
-{
-    "[header]", "[inputrec]", "[box]", "[topology]", "[coordinates]",
-    "[velocities]", "[forces]"
-};
-
 const char *eioNames[eioNR] =
 {
     "REAL", "INT", "GMX_STE_T", "UCHAR", "NUCHAR", "USHORT", "RVEC", "NRVEC",
     "IVEC", "STRING"
 };
 
-
-
-/* Comment strings for TPA only */
-const char *comment_str[eitemNR] = {
-    "; The header holds information on the number of atoms etc. and on whether\n"
-    "; certain items are present in the file or not.\n"
-    "; \n"
-    ";                             WARNING\n"
-    ";                   DO NOT EDIT THIS FILE BY HAND\n"
-    "; The GROMACS preprocessor performs a lot of checks on your input that\n"
-    "; you ignore when editing this. Your simulation may crash because of this\n",
-    "; The inputrec holds the parameters for MD such as the number of steps,\n"
-    "; the timestep and the cut-offs.\n",
-    "; The simulation box in nm.\n",
-    "; The topology section describes the topology of the molecules\n"
-    "; i.e. bonds, angles and dihedrals etc. and also holds the force field\n"
-    "; parameters.\n",
-    "; The atomic coordinates in nm\n",
-    "; The atomic velocities in nm/ps\n",
-    "; The forces on the atoms in nm/ps^2\n"
-};
-
-
-
-
 /******************************************************************
  *
  * Internal functions:
@@ -433,41 +402,34 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
     gmx_bool  bRead, bReadWrite;
     int       xdrid;
 
-    if (fn2ftp(fn) == efTPA)
+    /* sanitize the mode string */
+    if (strncmp(mode, "r+", 2) == 0)
+    {
+        strcpy(newmode, "r+");
+    }
+    else if (mode[0] == 'r')
+    {
+        strcpy(newmode, "r");
+    }
+    else if (strncmp(mode, "w+", 2) == 0)
+    {
+        strcpy(newmode, "w+");
+    }
+    else if (mode[0] == 'w')
     {
-        strcpy(newmode, mode);
+        strcpy(newmode, "w");
+    }
+    else if (strncmp(mode, "a+", 2) == 0)
+    {
+        strcpy(newmode, "a+");
+    }
+    else if (mode[0] == 'a')
+    {
+        strcpy(newmode, "a");
     }
     else
     {
-        /* sanitize the mode string */
-        if (strncmp(mode, "r+", 2) == 0)
-        {
-            strcpy(newmode, "r+");
-        }
-        else if (mode[0] == 'r')
-        {
-            strcpy(newmode, "r");
-        }
-        else if (strncmp(mode, "w+", 2) == 0)
-        {
-            strcpy(newmode, "w+");
-        }
-        else if (mode[0] == 'w')
-        {
-            strcpy(newmode, "w");
-        }
-        else if (strncmp(mode, "a+", 2) == 0)
-        {
-            strcpy(newmode, "a+");
-        }
-        else if (mode[0] == 'a')
-        {
-            strcpy(newmode, "a");
-        }
-        else
-        {
-            gmx_fatal(FARGS, "DEATH HORROR in gmx_fio_open, mode is '%s'", mode);
-        }
+        gmx_fatal(FARGS, "DEATH HORROR in gmx_fio_open, mode is '%s'", mode);
     }
 
     /* Check if it should be opened as a binary file */
@@ -489,7 +451,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
     if (fn)
     {
         fio->iFTP   = fn2ftp(fn);
-        fio->fn     = strdup(fn);
+        fio->fn     = gmx_strdup(fn);
         fio->bStdio = FALSE;
 
         /* If this file type is in the list of XDR files, open it like that */
@@ -518,7 +480,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
                 gmx_incons("gmx_fio_open may not be used to open TNG files");
             }
             /* Open the file */
-            fio->fp = ffopen(fn, newmode);
+            fio->fp = gmx_ffopen(fn, newmode);
 
             /* determine the XDR direction */
             if (newmode[0] == 'w' || newmode[0] == 'a')
@@ -536,7 +498,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
         else
         {
             /* If it is not, open it as a regular file */
-            fio->fp = ffopen(fn, newmode);
+            fio->fp = gmx_ffopen(fn, newmode);
         }
 
         /* for appending seek to end of file to make sure ftell gives correct position
@@ -546,14 +508,6 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
             gmx_fseek(fio->fp, 0, SEEK_END);
         }
     }
-    else
-    {
-        /* Use stdin/stdout for I/O */
-        fio->iFTP   = efTPA;
-        fio->fp     = bRead ? stdin : stdout;
-        fio->fn     = strdup("STDIO");
-        fio->bStdio = TRUE;
-    }
     fio->bRead             = bRead;
     fio->bReadWrite        = bReadWrite;
     fio->bDouble           = (sizeof(real) == sizeof(double));
@@ -586,7 +540,7 @@ static int gmx_fio_close_locked(t_fileio *fio)
     /* Don't close stdin and stdout! */
     if (!fio->bStdio && fio->fp != NULL)
     {
-        rc = ffclose(fio->fp); /* fclose returns 0 if happy */
+        rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
 
     }
     fio->bOpen = FALSE;
@@ -627,7 +581,7 @@ int gmx_fio_fp_close(t_fileio *fio)
     gmx_fio_lock(fio);
     if (!in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR) && !fio->bStdio)
     {
-        rc      = ffclose(fio->fp); /* fclose returns 0 if happy */
+        rc      = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
         fio->fp = NULL;
     }
     gmx_fio_unlock(fio);
@@ -751,9 +705,9 @@ static int gmx_fio_int_get_file_md5(t_fileio *fio, gmx_off_t offset,
 
     if (!ret)
     {
-        md5_init(&state);
-        md5_append(&state, buf, read_len);
-        md5_finish(&state, digest);
+        gmx_md5_init(&state);
+        gmx_md5_append(&state, buf, read_len);
+        gmx_md5_finish(&state, digest);
         ret = read_len;
     }
     sfree(buf);