Work around memory leak in t_state
[gromacs.git] / src / gromacs / fileio / gmxfio.h
blobd08249e4a15ac045784afb177c6f1d46d60cc510
1 /*
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.
38 #ifndef GMX_FILEIO_GMXFIO_H
39 #define GMX_FILEIO_GMXFIO_H
41 #include <stdio.h>
43 #include "gromacs/math/vectypes.h"
44 #include "gromacs/utility/cstringutil.h"
45 #include "gromacs/utility/futil.h"
46 #include "gromacs/utility/real.h"
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
52 typedef struct t_fileio t_fileio;
54 /* NOTE ABOUT THREAD SAFETY:
56 The functions are all thread-safe, provided that two threads don't
57 do something silly like closing the same file, or one thread
58 accesses a file that has been closed by another.
61 /********************************************************
62 * Open and Close
63 ********************************************************/
65 t_fileio *gmx_fio_open(const char *fn, const char *mode);
66 /* Open a new file for reading or writing.
67 * The file type will be deduced from the file name.
70 int gmx_fio_close(t_fileio *fp);
71 /* Close the file corresponding to fp (if not stdio)
72 * The routine will exit when an invalid fio is handled.
73 * Returns 0 on success.
76 int gmx_fio_fp_close(t_fileio *fp);
77 /* Close the file corresponding to fp without closing the FIO entry
78 * Needed e.g. for trxio because the FIO entries are used to store
79 * additional data.
80 * NOTE that the fp still needs to be properly closed with gmx_fio_close().
81 * The routine will exit when an invalid fio is handled.
82 * Returns 0 on success.
86 /* Open a file, return a stream, record the entry in internal FIO object */
87 FILE* gmx_fio_fopen(const char *fn, const char *mode);
89 /* Close a file previously opened with gmx_fio_fopen.
90 * Do not mix these calls with standard fopen/fclose ones!
91 * Returns 0 on success. */
92 int gmx_fio_fclose(FILE *fp);
96 /********************************************************
97 * Change properties of the open file
98 ********************************************************/
100 char *gmx_fio_getname(t_fileio *fio);
101 /* Return the filename corresponding to the fio index */
103 int gmx_fio_getftp(t_fileio *fio);
104 /* Return the filetype corresponding to the fio index.
105 There is as of now no corresponding setftp function because the file
106 was opened as a specific file type and changing that midway is most
107 likely an evil hack. */
109 gmx_bool gmx_fio_getread(t_fileio *fio);
110 /* Return whether read mode is on in fio */
112 /***************************************************
113 * FILE Operations
114 ***************************************************/
116 void gmx_fio_rewind(t_fileio *fio);
117 /* Rewind the file in fio */
119 int gmx_fio_flush(t_fileio *fio);
120 /* Flush the fio, returns 0 on success */
122 int gmx_fio_fsync(t_fileio *fio);
123 /* fsync the fio, returns 0 on success.
124 NOTE: don't use fsync function unless you're absolutely sure you need it
125 because it deliberately interferes with the OS's caching mechanisms and
126 can cause dramatically slowed down IO performance. Some OSes (Linux,
127 for example), may implement fsync as a full sync() point. */
129 gmx_off_t gmx_fio_ftell(t_fileio *fio);
130 /* Return file position if possible */
132 int gmx_fio_seek(t_fileio *fio, gmx_off_t fpos);
133 /* Set file position if possible, quit otherwise */
135 FILE *gmx_fio_getfp(t_fileio *fio);
136 /* Return the file pointer itself */
139 /* Element with information about position in a currently open file.
140 * gmx_off_t should be defined by autoconf if your system does not have it.
141 * If you do not have it on some other platform you do not have largefile
142 * support at all, and you can define it to int (or better, find out how to
143 * enable large files). */
144 typedef struct gmx_file_position_t
146 char filename[STRLEN];
147 gmx_off_t offset;
148 unsigned char chksum[16];
149 int chksum_size;
151 gmx_file_position_t;
153 int gmx_fio_get_output_file_positions(gmx_file_position_t ** outputfiles,
154 int *nfiles );
155 /* Return the name and file pointer positions for all currently open
156 * output files. This is used for saving in the checkpoint files, so we
157 * can truncate output files upon restart-with-appending.
159 * For the first argument you should use a pointer, which will be set to
160 * point to a list of open files.
163 t_fileio *gmx_fio_all_output_fsync(void);
164 /* fsync all open output files. This is used for checkpointing, where
165 we need to ensure that all output is actually written out to
166 disk.
167 This is most important in the case of some networked file systems,
168 where data is not synced with the file server until close() or
169 fsync(), so data could remain in cache for days.
170 Note the caveats reported with gmx_fio_fsync().
172 returns: NULL if no error occurred, or a pointer to the first file that
173 failed if an error occurred
177 int gmx_fio_get_file_md5(t_fileio *fio, gmx_off_t offset,
178 unsigned char digest[]);
181 int xtc_seek_time(t_fileio *fio, real time, int natoms, gmx_bool bSeekForwardOnly);
184 #ifdef __cplusplus
186 #endif
188 #endif