added Verlet scheme and NxN non-bonded functionality
[alexxy/gromacs.git] / include / futil.h
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Gromacs Runs On Most of All Computer Systems
34  */
35
36 #ifndef _futil_h
37 #define _futil_h
38
39 #include <stdio.h>
40 #include "typedefs.h"
41 #include "types/commrec.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 #if 0
47 }
48 #endif
49
50 /* Native windows uses backslash path separators.
51  * Cygwin and everybody else in the world use slash.
52  * When reading the PATH environment variable, Unix separates entries
53  * with colon, while windows uses semicolon.
54  */
55 #include "gmx_header_config.h"
56 #ifdef GMX_NATIVE_WINDOWS
57 #define DIR_SEPARATOR '\\'
58 #define PATH_SEPARATOR ";"
59 #else
60 #define DIR_SEPARATOR '/'
61 #define PATH_SEPARATOR ":"
62 #endif
63
64
65 /* Now get the maximum path size. */
66 #ifdef PATH_MAX
67 #  define GMX_PATH_MAX PATH_MAX
68 #elif defined MAX_PATH
69 #  define GMX_PATH_MAX MAX_PATH
70 #else
71 #  define GMX_PATH_MAX 4096
72 #endif
73
74
75 #ifdef HAVE_FSEEKO
76    typedef off_t              gmx_off_t;
77 #  define SIZEOF_GMX_OFF_T   SIZEOF_OFF_T
78 #elif defined HAVE__FSEEKI64 
79    typedef __int64            gmx_off_t;
80 #  define SIZEOF_GMX_OFF_T   8
81 #else
82    /* Almost certainly 64 bits, and guaranteed to be available */
83    typedef gmx_large_int_t    gmx_off_t;
84 #  define SIZEOF_GMX_OFF_T   SIZEOF_GMX_LARGE_INT
85 #endif    
86
87
88   
89 void no_buffers(void);
90 /* Turn off buffering of files (which is default) for debugging purposes */
91
92 gmx_bool gmx_fexist(const char *fname);
93 /* Return TRUE when fname exists, FALSE otherwise */
94
95 gmx_bool gmx_fexist_master(const char *fname, t_commrec *cr);
96 /* Return TRUE when fname exists, FALSE otherwise, bcast from master to others */
97
98 gmx_bool gmx_eof(FILE *fp);
99 /* Return TRUE on end-of-file, FALSE otherwise */
100
101 gmx_bool is_pipe(FILE *fp);
102 /* Check whether the file (opened by ffopen) is a pipe */
103
104 /*  Make a backup of file if necessary.  
105     Return false if there was a problem.
106 */
107 gmx_bool make_backup(const char * file);
108
109 FILE *ffopen(const char *file, const char *mode);
110 /* Return a valid file pointer when successful, exits otherwise 
111  * If the file is in compressed format, open a pipe which uncompresses
112  * the file! Therefore, files must be closed with ffclose (see below)
113  */
114
115 int ffclose(FILE *fp);
116 /* Close files or pipes */
117
118
119 void frewind(FILE *fp);
120 /* Does not rewind pipes, but does so for normal files */
121
122 #define rewind frewind
123
124
125 int gmx_fseek(FILE *stream, gmx_off_t offset, int whence); 
126 /* OS-independent fseek. 64-bit when available */
127
128 gmx_off_t gmx_ftell(FILE *stream); 
129 /* OS-independent fseek. 64-bit when available. */
130
131
132 gmx_bool is_pipe(FILE *fp);
133
134 char *gmxlibfn(const char *file);
135 /* allocates and returns a string with the full file name for a library file */
136
137 FILE *libopen(const char *file);
138 /* Open a library file for reading. This looks in the current directory
139  * first, and then in the library directory. If the file is not found,
140  * it terminates with a fatal_error
141  */
142
143 /* Opaque data type to list directories */
144 typedef struct gmx_directory *
145 gmx_directory_t;
146
147 /* Open a directory for reading. The first argument should be a pointer
148  * to a declared gmx_directory_t variable. Returns 0 on success.
149  */
150 int
151 gmx_directory_open(gmx_directory_t *p_gmxdir,const char *dirname);
152
153     
154 /* Given an initialized gmx_directory_t, if there are more files in
155  * the directory this routine returns 0 and write the next name
156  * into the USER-PROVIDED buffer name. The last argument is the max
157  * number of characters that will be written. Just as strncpy, the
158  * string will NOT be terminated it it is longer than maxlength_name.
159  */
160 int
161 gmx_directory_nextfile(gmx_directory_t gmxdir,char *name,int maxlength_name);
162     
163 /* Release all data for a directory structure */
164 int 
165 gmx_directory_close(gmx_directory_t gmxdir);
166     
167
168     
169 gmx_bool get_libdir(char *libdir);
170
171 char *low_gmxlibfn(const char *file,gmx_bool bAddCWD,gmx_bool bFatal);
172
173 FILE *low_libopen(const char *file,gmx_bool bFatal);
174 /* The same as the above, but does not terminate if (!bFatal) */
175
176 /* Create unique name for temp file (wrapper around mkstemp). 
177  * Buf should be at least 7 bytes long 
178  */
179 void gmx_tmpnam(char *buf);
180
181 /* truncte the file to the specified length */
182 int gmx_truncatefile(char *path, gmx_off_t length);
183
184 /* rename/move the file (atomically, if the OS makes that available) oldname 
185    to newname */
186 int gmx_file_rename(const char *oldname, const char *newname);
187
188 /* copy the file (data only) oldname to newname. if copy_if_empty==FALSE,
189    the file won't be copied if it's empty.*/
190 int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_empty);
191
192 /* do an fsync() on an open file pointer. 
193    Only use this during checkpointing! */
194 int gmx_fsync(FILE *fp);
195
196 #ifdef GMX_NATIVE_WINDOWS
197 #define chdir _chdir
198 #define getcwd _getcwd
199 #endif
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif  /* _futil_h */