"IVEC", "STRING"
};
+void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble)
+{
+ gmx_fio_lock(fio);
+ fio->bDouble = bDouble;
+ gmx_fio_unlock(fio);
+}
+
XDR *gmx_fio_getxdr(t_fileio *fio)
{
XDR *ret = NULL;
default:
gmx_fio_fe(fio, eio, desc, srcfile, line);
}
- if ((res == 0) && (fio->bDebug))
- {
- fprintf(stderr, "Error in xdr I/O %s %s to file %s (source %s, line %d)\n",
- eioNames[eio], desc, fio->fn, srcfile, line);
- }
return (res != 0);
}
{
rc = fflush(fio->fp);
}
- else if (fio->xdr)
- {
- rc = fflush((FILE *) fio->xdr->x_private);
- }
return rc;
}
/* Check if it should be opened as a binary file */
if (!ftp_is_text(fn2ftp(fn)))
{
- /* Not ascii, add b to file mode */
- if ((strchr(newmode, 'b') == NULL) && (strchr(newmode, 'B') == NULL))
- {
- strcat(newmode, "b");
- }
+ strcat(newmode, "b");
}
snew(fio, 1);
fio->iFTP = fn2ftp(fn);
fio->fn = gmx_strdup(fn);
+ fio->fp = gmx_ffopen(fn, newmode);
/* If this file type is in the list of XDR files, open it like that */
if (ftp_is_xdr(fio->iFTP))
{
- /* First check whether we have to make a backup,
- * only for writing, not for read or append.
- */
- if (newmode[0] == 'w')
- {
-#ifndef GMX_FAHCORE
- /* only make backups for normal gromacs */
- make_backup(fn);
-#endif
- }
- else
- {
- /* Check whether file exists */
- if (!gmx_fexist(fn))
- {
- gmx_open(fn);
- }
- }
- /* Open the file */
- fio->fp = gmx_ffopen(fn, newmode);
-
/* determine the XDR direction */
if (newmode[0] == 'w' || newmode[0] == 'a')
{
{
fio->xdrmode = XDR_DECODE;
}
-
snew(fio->xdr, 1);
xdrstdio_create(fio->xdr, fio->fp, fio->xdrmode);
}
- else
- {
- /* If it is not, open it as a regular file */
- fio->fp = gmx_ffopen(fn, newmode);
- }
/* for appending seek to end of file to make sure ftell gives correct position
* important for checkpointing */
fio->bRead = bRead;
fio->bReadWrite = bReadWrite;
fio->bDouble = (sizeof(real) == sizeof(double));
- fio->bDebug = FALSE;
- fio->bOpen = TRUE;
/* and now insert this file into the list of open files. */
gmx_fio_insert(fio);
{
int rc = 0;
- if (!fio->bOpen)
- {
- gmx_fatal(FARGS, "File %s closed twice!\n", fio->fn);
- }
-
- if (ftp_is_xdr(fio->iFTP))
+ if (fio->xdr != NULL)
{
xdr_destroy(fio->xdr);
sfree(fio->xdr);
rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
}
- fio->bOpen = FALSE;
return rc;
}
/* We don't want two processes operating on the list at the same time */
tMPI_Thread_mutex_lock(&open_file_mutex);
- if (fio->iFTP == efTNG)
- {
- gmx_incons("gmx_fio_close should not be called on a TNG file");
- }
gmx_fio_lock(fio);
/* first remove it from the list */
gmx_fio_remove(fio);
{
int rc = 0;
gmx_fio_lock(fio);
- if (!ftp_is_xdr(fio->iFTP))
+ if (fio->xdr == NULL)
{
rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
fio->fp = NULL;
{
/* Skip the checkpoint files themselves, since they could be open when
we call this routine... */
- if (cur->bOpen && !cur->bRead && cur->iFTP != efCPT)
+ if (!cur->bRead && cur->iFTP != efCPT)
{
/* This is an output file currently open for writing, add it */
if (nfiles == nalloc)
}
-void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble)
-{
- gmx_fio_lock(fio);
- fio->bDouble = bDouble;
- gmx_fio_unlock(fio);
-}
-
-void gmx_fio_setdebug(t_fileio *fio, gmx_bool bDebug)
-{
- gmx_fio_lock(fio);
- fio->bDebug = bDebug;
- gmx_fio_unlock(fio);
-}
-
char *gmx_fio_getname(t_fileio *fio)
{
char *ret;
{
rc = gmx_fsync(fio->fp);
}
- else if (fio->xdr) /* this should normally not happen */
- {
- rc = gmx_fsync((FILE*) fio->xdr->x_private);
- /* ^ is this actually OK? */
- }
return rc;
}
cur = gmx_fio_get_first();
while (cur)
{
- if (cur->bOpen && !cur->bRead)
+ if (!cur->bRead)
{
/* if any of them fails, return failure code */
int rc = gmx_fio_int_fsync(cur);
* Change properties of the open file
********************************************************/
-void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble);
-/* Select the floating point precision for reading and writing files */
-
char *gmx_fio_getname(t_fileio *fio);
/* Return the filename corresponding to the fio index */
was opened as a specific file type and changing that midway is most
likely an evil hack. */
-void gmx_fio_setdebug(t_fileio *fio, gmx_bool bDebug);
-/* Set the debug mode */
-
gmx_bool gmx_fio_getread(t_fileio *fio);
/* Return whether read mode is on in fio */