1 #ifndef _ECS_DEF_H_
2 #define _ECS_DEF_H_
3 
4 /*============================================================================
5  * Definitions, global variables, and base functions
6  *============================================================================*/
7 
8 /*
9   This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11   Copyright (C) 1998-2021 EDF S.A.
12 
13   This program is free software; you can redistribute it and/or modify it under
14   the terms of the GNU General Public License as published by the Free Software
15   Foundation; either version 2 of the License, or (at your option) any later
16   version.
17 
18   This program is distributed in the hope that it will be useful, but WITHOUT
19   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21   details.
22 
23   You should have received a copy of the GNU General Public License along with
24   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25   Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #include "cs_config.h"
31 
32 /*
33  * Standard C library headers
34  */
35 
36 /*============================================================================
37  * Definition of C99 type which may not be available with older tools.
38  *============================================================================*/
39 
40 #if HAVE_STDDEF_H
41 # include <stddef.h>
42 #else
43 # include <stdio.h>
44 #endif
45 
46 /*
47  * Usually, stdint.h is included by inttypes.h, but only inttypes.h
48  * may be found on some systems, such as Tru64Unix.
49  */
50 
51 #if HAVE_STDINT_H
52 # include <stdint.h>
53 #elif HAVE_INTTYPES_H
54 # include <inttypes.h>
55 #endif
56 
57 /* _Bool */
58 
59 #if HAVE_STDBOOL_H
60 #  include <stdbool.h>
61 #else
62 #  ifndef HAVE__BOOL
63 #    ifdef __cplusplus
64 typedef bool _Bool;
65 #    else
66 #      define _Bool signed char;
67 #    endif
68 #  endif
69 #  define bool _Bool
70 #  define false 0
71 #  define true 1
72 #  define __bool_true_false_are_defined 1
73 #endif
74 
75 /* int32_t type */
76 
77 #if !defined(HAVE_INT32_T)
78 #  if (SIZEOF_INT == 4)
79 typedef int int32_t;
80 #  elif (SIZEOF_SHORT == 4)
81 typedef short int32_t;
82 #  else
83 #    error
84 #  endif
85 #endif
86 
87 /* int64_t type */
88 
89 #if !defined(HAVE_INT64_T)
90 #  if (SIZEOF_INT == 8)
91 typedef int int64_t;
92 #  elif (SIZEOF_LONG == 8)
93 typedef long int64_t;
94 #  elif (HAVE_LONG_LONG == 8)  /* SIZEOF_LONG_LONG not generally available */
95 typedef long long int64_t;
96 #  else
97 #    error
98 #  endif
99 #endif
100 
101 /* uint32_t type */
102 
103 #if !defined(HAVE_UINT32_T)
104 #  if (SIZEOF_INT == 4)
105 typedef unsigned uint32_t;
106 #  elif (SIZEOF_SHORT == 4)
107 typedef unsigned short uint32_t;
108 #  else
109 #    error
110 #  endif
111 #endif
112 
113 /* uint64_t type */
114 
115 #if !defined(HAVE_UINT64_T)
116 #  if (SIZEOF_INT == 8)
117 typedef unsigned uint64_t;
118 #  elif (SIZEOF_LONG == 8)
119 typedef unsigned long uint64_t;
120 #  elif (HAVE_LONG_LONG) /* SIZEOF_LONG_LONG not generally available */
121 typedef unsigned long long uint64_t;
122 #  else
123 #    error
124 #  endif
125 #endif
126 
127 /*-----------------------------------------------------------------------------
128  * Local type definitions
129  *----------------------------------------------------------------------------*/
130 
131 #if defined(HAVE_LONG_GNUM)
132   #if (SIZEOF_LONG == 8)
133     typedef long                ecs_int_t;   /* Integer */
134     typedef unsigned long       ecs_size_t;  /* Index size */
135   #elif (SIZEOF_LONG_LONG == 8)
136     typedef long long           ecs_int_t;   /* Integer */
137     typedef unsigned long long  ecs_size_t;  /* Index size */
138   #else
139     #error
140   #endif
141 #else
142   typedef int           ecs_int_t;      /* Integer */
143   typedef size_t        ecs_size_t;     /* Index size */
144 #endif
145 
146 typedef double          ecs_coord_t;    /* Real (floating point) */
147 typedef char            ecs_byte_t;     /* Byte (untyped memory) */
148 
149 /* Type enumeration */
150 
151 typedef enum {
152   ECS_TYPE_char,
153   ECS_TYPE_ecs_coord_t,
154   ECS_TYPE_ecs_int_t,
155   ECS_TYPE_ecs_size_t,
156   ECS_TYPE_size_t,
157   ECS_TYPE_void
158 } ecs_type_t;
159 
160 /* Element types */
161 
162 typedef enum {
163 
164   ECS_ELT_TYP_NUL,         /*  No type */
165 
166   ECS_ELT_TYP_FAC_TRIA,    /*  Triangle */
167   ECS_ELT_TYP_FAC_QUAD,    /*  Quadrangle */
168 
169   ECS_ELT_TYP_CEL_TETRA,   /*  Tetrahedron */
170   ECS_ELT_TYP_CEL_PYRAM,   /*  Pyramid */
171   ECS_ELT_TYP_CEL_PRISM,   /*  Prism */
172   ECS_ELT_TYP_CEL_HEXA,    /*  Hexahedron */
173 
174   ECS_ELT_TYP_FAC_POLY,    /*  Polygon */
175   ECS_ELT_TYP_CEL_POLY,    /*  Polyhedron */
176 
177   ECS_ELT_TYP_FIN
178 
179 } ecs_elt_typ_t ;
180 
181 /* Restrict qualifier (standard in C99) */
182 
183 #if defined(__GNUC__)
184 #define restrict __restrict
185 #else
186 #define restrict
187 #endif
188 
189 /*=============================================================================
190  * Macro definitions
191  *============================================================================*/
192 
193 /* Classical macros */
194 
195 #define ECS_ABS(a)     ((a) <  0  ? -(a) : (a))  /* Absolute value */
196 #define ECS_MIN(a, b)  ((a) > (b) ?  (b) : (a))  /* Minimum */
197 #define ECS_MAX(a, b)  ((a) < (b) ?  (b) : (a))  /* Maximum */
198 
199 /* Directory separator character */
200 
201 #define ECS_PATH_SEP             '/'
202 
203 #define ECS_REAL_PRECISION    1.e-13
204 
205 #define ECS_STR_SIZE       80
206 
207 #define ECS_PAS_NUL         0
208 #define ECS_PAS_UNITE       1
209 
210 #define ECS_LNG_AFF_STR           43
211 #define ECS_LNG_AFF_ENT            8
212 #define ECS_LNG_AFF_REE_MANTIS    11
213 #define ECS_LNG_AFF_REE_PRECIS     2
214 
215 #define ECS_FMT_AFF_REE_PARAM     "%.15E"
216 
217 /*
218  * Internationalization macros.
219  */
220 
221 #if defined(ENABLE_NLS)
222 
223 #include <libintl.h>
224 #define _(String) gettext(String)
225 #define gettext_noop(String) String
226 #define N_(String) gettext_noop(String)
227 
228 #else
229 
230 #define _(String) String
231 #define N_(String) String
232 #define textdomain(Domain)
233 #define bindtextdomain(Package, Directory)
234 
235 #endif
236 
237 /* Macros for compilation with a C++ compiler */
238 /*--------------------------------------------*/
239 
240 #undef BEGIN_C_DECLS
241 #undef   END_C_DECLS
242 
243 #if defined(__cplusplus)
244 #  define BEGIN_C_DECLS  extern "C" {
245 #  define   END_C_DECLS  }
246 #else
247 #  define BEGIN_C_DECLS
248 #  define   END_C_DECLS
249 #endif
250 
251 /*=============================================================================
252  * Global variable definitions
253  *============================================================================*/
254 
255 extern char      ecs_glob_build_date[];
256 
257 extern int       ecs_glob_have_cgns;    /* CGNS library support*/
258 extern int       ecs_glob_cgns_ver_maj;
259 extern int       ecs_glob_cgns_ver_min;
260 extern int       ecs_glob_cgns_ver_rel;
261 
262 extern int       ecs_glob_have_med;     /* MED library support */
263 
264 /* Element type determination based on an element's number of vertices,
265    for elements of dimension 2 (faces) or 3 (cells);
266    Beyond 8 vertices, we always have ECS_ELT_TYP_FAC_POLY for faces
267    and ECS_ELT_TYP_FAC_POLY for cells */
268 
269 extern  const ecs_elt_typ_t  ecs_glob_typ_elt[2][9];
270 
271 /*=============================================================================
272  * Public function prototypes
273  *============================================================================*/
274 
275 /*----------------------------------------------------------------------------
276  * Initialize error handling
277  *----------------------------------------------------------------------------*/
278 
279 void
280 ecs_init_gestion_erreur(void);
281 
282 /*----------------------------------------------------------------------------
283  * Exit function.
284  *----------------------------------------------------------------------------*/
285 
286 void
287 ecs_exit(int  statut);
288 
289 /*----------------------------------------------------------------------------
290  * Print a warning.
291  *----------------------------------------------------------------------------*/
292 
293 void
294 ecs_warn(void);
295 
296 /*----------------------------------------------------------------------------
297  * Abort on error.
298  *----------------------------------------------------------------------------*/
299 
300 void
301 ecs_error(const char  *file_name,
302           const int    line_num,
303           const int    sys_error_code,
304           const char  *format,
305           ...);
306 
307 /*----------------------------------------------------------------------------
308  * Print a string with a given column width.
309  *----------------------------------------------------------------------------*/
310 
311 void
312 ecs_print_padded_str(const char  *str,
313                      int          width);
314 
315 /*----------------------------------------------------------------------------*/
316 
317 #endif /* _ECS_DEF_H_ */
318