* 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.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
+
+#include "gmxfio.h"
-#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "config.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 "filenm.h"
-#include "string2.h"
-#include "gmxfio.h"
-#include "md5.h"
-
-#include "gromacs/legacyheaders/thread_mpi/threads.h"
+#include "thread_mpi/threads.h"
-#include "gmxfio_int.h"
+#include "gromacs/fileio/filenm.h"
+#include "gromacs/fileio/gmxfio_int.h"
+#include "gromacs/fileio/md5.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/smalloc.h"
/* This is the new improved and thread safe version of gmxfio. */
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:
gmx_bool bRead, bReadWrite;
int xdrid;
- if (fn2ftp(fn) == efTPA)
+ /* sanitize the mode string */
+ if (strncmp(mode, "r+", 2) == 0)
{
- strcpy(newmode, mode);
+ 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
{
- /* 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 */
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 */
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')
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
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));
/* 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;
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);
{
/*1MB: large size important to catch almost identical files */
#define CPT_CHK_LEN 1048576
- md5_state_t state;
- unsigned char buf[CPT_CHK_LEN];
- gmx_off_t read_len;
- gmx_off_t seek_offset;
- int ret = -1;
+ md5_state_t state;
+ unsigned char *buf;
+ gmx_off_t read_len;
+ gmx_off_t seek_offset;
+ int ret = -1;
seek_offset = offset - CPT_CHK_LEN;
if (seek_offset < 0)
return -1;
}
+ snew(buf, CPT_CHK_LEN);
/* the read puts the file position back to offset */
if ((gmx_off_t)fread(buf, 1, read_len, fio->fp) != read_len)
{
if (!ret)
{
- md5_init(&state);
- md5_append(&state, buf, read_len);
- md5_finish(&state, digest);
- return read_len;
- }
- else
- {
- return ret;
+ gmx_md5_init(&state);
+ gmx_md5_append(&state, buf, read_len);
+ gmx_md5_finish(&state, digest);
+ ret = read_len;
}
+ sfree(buf);
+ return ret;
}