Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / legacyheaders / types / simple.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  * GRoups of Organic Molecules in ACtion for Science
34  */
35
36 #ifndef _simple_h
37 #define _simple_h
38
39 /* Dont remove this instance of HAVE_CONFIG_H!!!
40  *
41  * We dont _require_ config.h here, but IF one is
42  * available it might contain valuable information about simple types 
43  * that helps us automate things better and avoid bailing out.
44  *
45  * Note that this does not have to be the gromacs config.h - several
46  * package setups define these simple types. 
47  */
48 #ifdef HAVE_CONFIG_H
49 #  include <config.h>
50 #endif
51
52 /* Information about integer data type sizes */
53 #include <limits.h>
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 #if 0
59 }
60 #endif
61
62
63 #define XX          0                   /* Defines for indexing in      */
64 #define YY          1                   /* vectors                      */
65 #define ZZ      2
66 #define DIM     3                       /* Dimension of vectors         */
67 #define XXXX    0                       /* defines to index matrices */
68 #define XXYY    1
69 #define XXZZ    2
70 #define YYXX    3
71 #define YYYY    4
72 #define YYZZ    5
73 #define ZZXX    6
74 #define ZZYY    7
75 #define ZZZZ    8
76
77   /* There is no standard size for 'bool' in C++, so when
78    * we previously defined it to int for C code the data types
79    * (and structs) would have different size depending on your compiler,
80    * both at gromacs build time and when you use the library.
81    * The only way around this is to NOT assume anything about the C++ type,
82    * so we cannot use the name 'bool' in our C code anymore.
83    */
84
85 typedef int gmx_bool;
86
87 #ifndef FALSE
88 #  define FALSE   0
89 #endif
90 #ifndef TRUE
91 #  define TRUE    1
92 #endif
93 #define BOOL_NR 2
94
95
96 typedef int             atom_id;        /* To indicate an atoms id         */
97 #define NO_ATID         (atom_id)(~0)   /* Use this to indicate invalid atid */
98
99     /*! \brief Double precision accuracy */
100 #define GMX_DOUBLE_EPS   1.11022302E-16
101     
102     /*! \brief Maximum double precision value - reduced 1 unit in last digit for MSVC */
103 #define GMX_DOUBLE_MAX   1.79769312E+308
104     
105     /*! \brief Minimum double precision value */
106 #define GMX_DOUBLE_MIN   2.22507386E-308
107     
108     /*! \brief Single precision accuracy */
109 #define GMX_FLOAT_EPS    5.96046448E-08
110     
111     /*! \brief Maximum single precision value - reduced 1 unit in last digit for MSVC */
112 #define GMX_FLOAT_MAX    3.40282346E+38
113     
114     /*! \brief Minimum single precision value */
115 #define GMX_FLOAT_MIN    1.17549435E-38
116
117
118   /* Check whether we already have a real type! */
119 #ifdef GMX_DOUBLE
120
121 #ifndef HAVE_REAL
122 typedef double          real;
123 #define HAVE_REAL
124 #endif
125
126 #define GMX_MPI_REAL    MPI_DOUBLE
127 #define GMX_REAL_EPS    GMX_DOUBLE_EPS
128 #define GMX_REAL_MIN    GMX_DOUBLE_MIN
129 #define GMX_REAL_MAX    GMX_DOUBLE_MAX
130 #define gmx_real_fullprecision_pfmt "%21.14e"
131 #else
132
133 #ifndef HAVE_REAL
134 typedef float           real;
135 #define HAVE_REAL
136 #endif
137
138 #define GMX_MPI_REAL    MPI_FLOAT
139 #define GMX_REAL_EPS    GMX_FLOAT_EPS
140 #define GMX_REAL_MIN    GMX_FLOAT_MIN
141 #define GMX_REAL_MAX    GMX_FLOAT_MAX
142 #define gmx_real_fullprecision_pfmt "%14.7e"
143 #endif
144
145 typedef real            rvec[DIM];
146
147 typedef double          dvec[DIM];
148
149 typedef real            matrix[DIM][DIM];
150
151 typedef real            tensor[DIM][DIM];
152
153 typedef int             ivec[DIM];
154
155 typedef int             imatrix[DIM][DIM];
156
157
158 /* For the step count type gmx_large_int_t we aim for 8 bytes (64bit),
159  * but we might only be able to get 4 bytes (32bit).
160  *
161  * We first try to find a type without reyling on any SIZEOF_XXX defines.
162  *
163  * Avoid using "long int" if we can. This type is really dangerous,
164  * since the width frequently depends on compiler options, and they
165  * might not be set correctly when (buggy) Cmake is detecting things.
166  * Instead, start by looking for "long long", and just go down if we
167  * have to (rarely on new systems). /EL 20100810
168  */
169 #if ( (defined SIZEOF_LONG_LONG_INT && SIZEOF_LONG_LONG_INT==8) || (defined LLONG_MAX && LLONG_MAX==9223372036854775807LL) )
170
171 /* Long long int is 64 bit */
172 typedef long long int gmx_large_int_t;
173 #define gmx_large_int_fmt   "lld"
174 #define gmx_large_int_pfmt "%lld"
175 #define SIZEOF_GMX_LARGE_INT  8
176 #define GMX_LARGE_INT_MAX     9223372036854775807LL
177 #define GMX_LARGE_INT_MIN     (-GMX_LARGE_INT_MAX - 1LL)
178 #define GMX_MPI_LARGE_INT MPI_LONG_LONG_INT
179
180 #elif ( (defined SIZEOF_LONG_INT && SIZEOF_LONG_INT==8) || (defined LONG_MAX && LONG_MAX==9223372036854775807L) )
181
182 /* Long int is 64 bit */
183 typedef long int gmx_large_int_t;
184 #define gmx_large_int_fmt   "ld"
185 #define gmx_large_int_pfmt "%ld"
186 #define SIZEOF_GMX_LARGE_INT  8
187 #define GMX_LARGE_INT_MAX     9223372036854775807LL
188 #define GMX_LARGE_INT_MIN     (-GMX_LARGE_INT_MAX - 1LL)
189 #define GMX_MPI_LARGE_INT MPI_LONG_INT
190
191 #elif ( (defined SIZEOF_INT && SIZEOF_INT==8) || (defined INT_MAX && INT_MAX==9223372036854775807L) )
192
193 /* int is 64 bit */
194 typedef int gmx_large_int_t;
195 #define gmx_large_int_fmt   "d"
196 #define gmx_large_int_pfmt  "%d"
197 #define SIZEOF_GMX_LARGE_INT  8
198 #define GMX_LARGE_INT_MAX     9223372036854775807LL
199 #define GMX_LARGE_INT_MIN     (-GMX_LARGE_INT_MAX - 1LL)
200 #define GMX_MPI_LARGE_INT MPI_INT
201
202 #elif ( (defined INT_MAX && INT_MAX==2147483647) || (defined SIZEOF_INT && SIZEOF_INT==4) )
203
204 /* None of the above worked, try a 32 bit integer */
205 typedef int gmx_large_int_t;
206 #define gmx_large_int_fmt   "d"
207 #define gmx_large_int_pfmt "%d"
208 #define SIZEOF_GMX_LARGE_INT  4
209 #define GMX_LARGE_INT_MAX     2147483647
210 #define GMX_LARGE_INT_MIN     (-GMX_LARGE_INT_MAX - 1)
211 #define GMX_MPI_LARGE_INT MPI_INT
212
213 #else
214
215 #error "Cannot find any 32 or 64 bit integer data type. Please extend the gromacs simple.h file!"
216
217 #endif
218     
219     
220 #ifndef gmx_inline
221 /* config.h tests for inline definitions and should work on a much wider range
222  * of compilers, but does not work with installed headers. These compiler checks
223  * still enable a real inline keyword for the most common compilers.
224  */
225
226 /* Try to define suitable inline keyword for gmx_inline.
227  * Set it to empty if we cannot find one (and dont complain to the user)
228  */
229 #ifndef __cplusplus
230
231 #ifdef __GNUC__
232    /* GCC */
233 #  define gmx_inline   __inline__
234 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && defined(__ia64__)
235    /* ICC */
236 #  define gmx_inline __inline__
237 #elif defined(__PATHSCALE__)
238    /* Pathscale */
239 #  define gmx_inline __inline__
240 #elif defined(__PGIC__)
241    /* Portland */
242 #  define gmx_inline __inline
243 #elif defined _MSC_VER
244    /* MSVC */
245 #  define gmx_inline __inline
246 #elif defined(__xlC__)
247    /* IBM */
248 #  define gmx_inline __inline
249 #else
250 #  define gmx_inline
251 #endif
252
253 #else
254 /* C++ */
255 #  define gmx_inline inline
256 #endif
257
258 #endif /* ifndef gmx_inline */
259
260
261 /* Restrict keywords. Note that this has to be done for C++ too, unless
262  * it was set from the more general checks if we had config.h (gmx internal)
263  */
264 #ifndef gmx_restrict
265
266 #ifdef __GNUC__
267 /* GCC */
268 #  define gmx_restrict   __restrict__
269 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && defined(__ia64__)
270 /* ICC */
271 #  define gmx_restrict __restrict__
272 #elif defined(__PATHSCALE__)
273 /* Pathscale */
274 #  define gmx_restrict __restrict
275 #elif defined(__PGIC__)
276 /* Portland */
277 #  define gmx_restrict __restrict
278 #elif defined _MSC_VER
279 /* MSVC */
280 #  define gmx_restrict __restrict
281 #elif defined(__xlC__)
282 /* IBM */
283 #  define gmx_restrict __restrict
284 #else
285 #  define gmx_restrict
286 #endif
287
288 #endif
289
290 /* Standard sizes for char* string buffers */
291 #define STRLEN 4096
292 #define BIG_STRLEN 1048576
293
294
295 #ifdef __cplusplus
296 }
297 #endif
298
299 #endif
300