1 /*
2 Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
3 LLNL-CODE-425250.
4 All rights reserved.
5 
6 This file is part of Silo. For details, see silo.llnl.gov.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11 
12    * Redistributions of source code must retain the above copyright
13      notice, this list of conditions and the disclaimer below.
14    * Redistributions in binary form must reproduce the above copyright
15      notice, this list of conditions and the disclaimer (as noted
16      below) in the documentation and/or other materials provided with
17      the distribution.
18    * Neither the name of the LLNS/LLNL nor the names of its
19      contributors may be used to endorse or promote products derived
20      from this software without specific prior written permission.
21 
22 THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
23 "AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
24 LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
26 LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
27 CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
29 PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
32 NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 This work was produced at Lawrence Livermore National Laboratory under
36 Contract No.  DE-AC52-07NA27344 with the DOE.
37 
38 Neither the  United States Government nor  Lawrence Livermore National
39 Security, LLC nor any of  their employees, makes any warranty, express
40 or  implied,  or  assumes  any  liability or  responsibility  for  the
41 accuracy, completeness,  or usefulness of  any information, apparatus,
42 product, or  process disclosed, or  represents that its use  would not
43 infringe privately-owned rights.
44 
45 Any reference herein to  any specific commercial products, process, or
46 services by trade name,  trademark, manufacturer or otherwise does not
47 necessarily  constitute or imply  its endorsement,  recommendation, or
48 favoring  by  the  United  States  Government  or  Lawrence  Livermore
49 National Security,  LLC. The views  and opinions of  authors expressed
50 herein do not necessarily state  or reflect those of the United States
51 Government or Lawrence Livermore National Security, LLC, and shall not
52 be used for advertising or product endorsement purposes.
53 */
54 
55 /*
56  * SILO Private header file.
57  *
58  * This file contains the private parts of SILO and is included
59  * by every SILO source file.
60  */
61 #ifndef SILO_PRIVATE_H
62 #define SILO_PRIVATE_H
63 
64 #include "config.h" /*silo configuration settings */
65 #if HAVE_STDLIB_H
66 #include <stdlib.h> /*for malloc,calloc,realloc, etc */
67 #endif
68 #include <setjmp.h> /*for unwind_protect(), etc */
69 #if HAVE_STRING_H
70 #include <string.h> /*for STR_BEGINSWITH, etc */
71 #endif
72 #if defined(_WIN32)
73 #include <silo_win32_compatibility.h>
74 #else
75 #if HAVE_UNISTD_H
76 #include <unistd.h> /*for access() F_OK, R_OK */
77 #endif
78 #endif
79 #include "silo.h"
80 
81 /*
82  * The error mechanism....
83  *
84  * All application programming interface (API) function bodies are
85  * surrounded by an `API_BEGIN' and an `API_END.'  Inside this construct,
86  * the `return' statement should not be used is it would result in
87  * leaving an invalid jump structure on the jump stack, Jstk.
88  * If an error occurs which causes db_perror() to longjump back to the
89  * inside of the API_BEGIN macro, the API_BEGIN macro will remove the invalid
90  * entries from the jump stack.  But just to be safe, all occurances of
91  * a `return' statement inside the API_BEGIN/API_END construct should be
92  * coded as an `API_RETURN(x)' macro call.  As a convenience, returning
93  * the failure value as registered with API_BEGIN may be done by calling
94  * API_ERROR().  API_BEGIN and API_BEGIN2 cannot be used in routines that
95  * are recursive.  This is because there are two local variables that are
96  * declared static so that setjmp and longjmp work properly.
97  *
98  * Synopsis:
99  *
100  *  API_BEGIN (name, type, failure) {
101  *
102  *    if (...) API_ERROR(string, errno) ;
103  *
104  *    API_RETURN (retval) ;
105  *
106  *  } API_END ;
107  *
108  * Where:
109  *   `name' is a string that is the name of the API function.
110  *
111  *   `type' is the API function return type.
112  *
113  *   `failure' is the API function failure return value.
114  *
115  *   `string' is an error message auxilliary string--1st arg to db_perror()
116  *
117  *   `errno' is the error number--one of the E_... constants.
118  *
119  *   `retval' is a return value, which can be a function call and the
120  *   function call is protected by the API_BEGIN/API_END.
121  *
122  * Example:
123  *
124  * > This is an application program interface function that calls
125  * > one of the functions in the `DBOpenCB' callback vector.  The
126  * > callback might fail by calling db_perror() in which case this
127  * > API function might be responsible for issuing the error message.
128  *
129  *  PUBLIC DBfile *DBOpen (char *name, int type, int mode) {
130  *
131  *    API_BEGIN ("DBOpen", DBfile*, NULL) {
132  *       if (!name || !*name) API_ERROR ("name", E_BADARG) ;
133  *       if (!DBOpenCB[type]) API_ERROR (NULL, E_NOTIMP) ;
134  *       API_RETURN ((DBOpenCB[type])(name, mode)) ;
135  *    } API_END ;
136  * }
137  *
138  *
139  * > This is an example `open' callback function for the PDB device
140  * > driver.  The function allocates some memory on the heap and then
141  * > calls functions that might fail via db_perror().  The failures
142  * > cause the clean-up body to be executed.  The clean-up code is
143  * > activated in one of three ways:
144  * >   Implicitly by calling db_perror() which may longjmp to the
145  * >     cleanup section.
146  * >   Implicitly by calling a function that might call db_perror()
147  * >     that might longjmp to the cleanup section (possibly after
148  * >     going through other clean-up sections on the jump stack)
149  * >   Explicitly through the UNWIND() macro.  A `return' statement
150  * > should never appear in a PROTECT/CLEANUP/END_PROTECT construct
151  * > as this would bypass the END_PROTECT.
152  * >
153  * > SILO_CALLBACK int db_pdb_open (char *name, int mode)
154  * > {
155  * >     char  *path=NULL, *fullname=NULL;
156  * >     int  fd;
157  * >
158  * >     PROTECT {
159  * >         path = search_paths (name);
160  * >         fullname = MALLOC (strlen(path)+strlen(name)+2);
161  * >         if (!fullname) {
162  * >             db_perror (NULL, E_NOMEM, "db_pdb_open");
163  * >             UNWIND();
164  * >         }
165  * >         sprintf (fullname, "%s/%s", path, name);
166  * >         fd = db_pdb_open_file (fullname);
167  * >         if (fd<0)
168  * >            UNWIND();
169  * >     } CLEANUP {
170  * >             FREE (path);
171  * >             FREE (fullname);
172  * >     } END_PROTECT;
173  * >     return fd;
174  * > }
175  *
176  *
177  * API_END_NOPOP should be used in place of API_END if an API_RETURN is
178  * used in the body and will always be executed.  This is to eliminate
179  * warning messages from some compilers that the API_END coding will never
180  * be reached.
181  *
182  * Why is it needed/How does it work?
183  *
184  * SILO has a function, DBShowErrors, that sets a flag to indicate what
185  * level of error reporting should be used.  The DB_TOP level indicates
186  * that when an error occurs deep within SILO or a device driver, that
187  * the error should actually be reported by the API function called by
188  * the application.  The jump stack is the mechanism used to transfer
189  * the error signal to the top-level API function without the need for
190  * device driver developers to constantly worry about the error handling
191  * mechanism.
192  *
193  * Each time an API function is called and the global jump stack, Jstk, is
194  * empty (as it should be at the application level) the API function will
195  * call setjmp() and add the resulting jump buffer to the jump stack.  The
196  * API_END macro conditionally removes this item from the jump stack.  When
197  * an error is detected in the API function or in any SILO or device driver
198  * function in the call stack below the API function, and db_perror is
199  * called as a result of the error, and the error reporting level is
200  * set to DB_TOP, a call to longjmp() will occur with the contents of the
201  * jump buffer at the top of the jump stack.  This causes the corresponding
202  * setjmp() call to return again, and results in db_perror() being called
203  * by the API_BEGIN macro whose setjmp() returned.  The top (only) item from
204  * the jump stack is removed and the API function returns an error status.
205  *
206  * A jump `stack' is used instead of a scalar jump variable so that any
207  * function can register cleanup code to be executed as we are longjmp'ing
208  * back to the top-level API.  This typically includes freeing memory and
209  * continuing the jumping.  However, this mechanism can also be used
210  * to tentatively execute a piece of code without issuing error messages
211  * and then, based on whether an error actually occured, execute some other
212  * chunk of code instead.
213  *
214  * The `CANCEL_UNWIND' statement can be used in the CLEANUP body to
215  * indicate that the cleanup code has handled the error and we shouldn't
216  * continue the unwind process.  This can be used for a piece of code
217  * we expect to fail as in:
218  *
219  *  PROTECT {
220  *    int status = expected_to_fail();
221  * } CLEANUP {
222  *    fix_the_failure();
223  *    CANCEL_UNWIND;
224  * } END_PROTECT;
225  *      -- we continue here regardless of status --
226  */
227 typedef struct jstk_t {
228     struct jstk_t *prev;
229     jmp_buf        jbuf;
230 } jstk_t;
231 
232 typedef struct context_t {
233     int            dirid;
234     char          *name;
235 } context_t;
236 
237 #define jstk_push()     {jstk_t*jt=ALLOC(jstk_t);jt->prev=SILO_Globals.Jstk;SILO_Globals.Jstk=jt;}
238 #define jstk_pop()      if(SILO_Globals.Jstk){jstk_t*jt=SILO_Globals.Jstk;SILO_Globals.Jstk=SILO_Globals.Jstk->prev;FREE(jt);}
239 
240 #define DEPRECATE_MSG(M,Maj,Min,Alt)                                          \
241 {                                                                             \
242    static int ncalls = 0;                                                     \
243    if (ncalls < SILO_Globals.maxDeprecateWarnings) {                          \
244       fprintf(stderr, "Silo warning %d of %d: \"%s\" was deprecated in version %d.%d.\n", \
245           ncalls+1, SILO_Globals.maxDeprecateWarnings, M,Maj,Min);            \
246       if (strlen(Alt) > 0)                                                                \
247           fprintf(stderr, "Use \"%s\" instead\n", Alt);                       \
248       fprintf(stderr, "Use DBSetDeprecateWarnings(0) to disable this message.\n");    \
249       fflush(stderr);                                                         \
250    }                                                                          \
251    ncalls++;                                                                  \
252 }                                                                             \
253 
254 #define API_DEPRECATE(M,T,R,Maj,Min,Alt)                                      \
255    DEPRECATE_MSG(M,Maj,Min,Alt)                                               \
256    API_BEGIN(M,T,R)
257 
258 #define API_BEGIN(M,T,R) {                                                    \
259                         char    *me = M ;                                     \
260                         static int     jstat ;                                \
261                         static context_t *jold ;                              \
262                         DBfile  *jdbfile = NULL ;                             \
263                         T jrv = R ;                                           \
264                         jstat = 0 ;                                           \
265                         jold = NULL ;                                         \
266                         if (DBDebugAPI>0) {                                   \
267                            write (DBDebugAPI, M, strlen(M));                  \
268                            write (DBDebugAPI, "\n", 1);                       \
269                         }                                                     \
270                         if (!SILO_Globals.Jstk){                              \
271                            jstk_push() ;                                      \
272                            if (setjmp(SILO_Globals.Jstk->jbuf)) {             \
273                               while (SILO_Globals.Jstk) jstk_pop () ;         \
274                               db_perror ("", db_errno, me) ;                  \
275                               return R ;                                      \
276                            }                                                  \
277                            jstat = 1 ;                                        \
278                         }
279 
280 #define API_DEPRECATE2(M,T,R,NM,Maj,Min,Alt)                                  \
281    DEPRECATE_MSG(M,Maj,Min,Alt)                                               \
282    API_BEGIN2(M,T,R,NM)
283 
284 #define API_BEGIN2(M,T,R,NM) {                                                \
285                         char    *me = M ;                                     \
286                         static int     jstat ;                                \
287                         static context_t *jold ;                              \
288                         DBfile  *jdbfile = dbfile ;                           \
289                         T jrv = R ;                                           \
290                         jstat = 0 ;                                           \
291                         jold = NULL ;                                         \
292                         if (db_isregistered_file(dbfile,0) == -1)             \
293                         {                                                     \
294                             db_perror("", E_NOTREG, me);                      \
295                             return R;                                         \
296                         }                                                     \
297                         if (DBDebugAPI>0) {                                   \
298                            write (DBDebugAPI, M, strlen(M));                  \
299                            write (DBDebugAPI, "\n", 1);                       \
300                         }                                                     \
301                         if (!SILO_Globals.Jstk){                              \
302                            jstk_push() ;                                      \
303                            if (setjmp(SILO_Globals.Jstk->jbuf)) {             \
304                               if (jold) {                                     \
305                                  context_restore (jdbfile, jold) ;            \
306                               }                                               \
307                               while (SILO_Globals.Jstk) jstk_pop () ;         \
308                               db_perror ("", db_errno, me) ;                  \
309                               return R ;                                      \
310                            }                                                  \
311                            jstat = 1 ;                                        \
312                            if (NM && jdbfile && !jdbfile->pub.pathok) {       \
313                               char const *jr ;                                \
314                               jold = context_switch (jdbfile,NM,&jr) ;        \
315                               if (!jold) longjmp (SILO_Globals.Jstk->jbuf, -1) ;\
316                               NM = jr ;                                       \
317                            }                                                  \
318                         }
319 
320 #define API_END         if (jold) context_restore (jdbfile, jold) ;     \
321                         if (jstat) jstk_pop() ;                         \
322                      }                        /*API_BEGIN or API_BEGIN2 */
323 
324 #define API_END_NOPOP   }         /*API_BEGIN or API_BEGIN2 */
325 
326 #define API_ERROR(S,N)  {                                               \
327                            db_perror (S,N,me) ; /*might never return*/  \
328                            if (jold) context_restore (jdbfile, jold) ;  \
329                            if (jstat) jstk_pop() ;                      \
330                            return jrv ;                                 \
331                         }
332 
333 #define API_RETURN(R)   {                                               \
334                            jrv = R ; /*might be a calculation*/         \
335                            if (jold) context_restore (jdbfile, jold) ;  \
336                            if (jstat) jstk_pop() ;                      \
337                            return jrv ;                                 \
338                         }
339 
340 #define PROTECT         {jstk_push();if(!setjmp(SILO_Globals.Jstk->jbuf)){
341 #define UNWIND()        longjmp(SILO_Globals.Jstk->jbuf,-1)
342 #define CLEANUP         jstk_pop();}else{int jcan=0;
343 #define END_PROTECT     jstk_pop();if(!jcan&&SILO_Globals.Jstk)longjmp(SILO_Globals.Jstk->jbuf,-1);}}
344 #define CANCEL_UNWIND   jcan=1
345 
346 /*
347  * Some convenience macros.
348  * We define some new function return types:
349  *    PRIVATE -- the function is used internally by defining file only.
350  *    INTERNAL -- the function is public, but not part of the API.
351  *    SILO_CALLBACK -- the function is a callback--never called directly
352  *    PUBLIC -- the function can be called publicly
353  *    FORTRAN -- the function is part of the fortran interface.
354  */
355 #define PRIVATE         static
356 #define INTERNAL                /*semi-private */
357 #ifndef CALLBACK
358 #define SILO_CALLBACK        static
359 #endif
360 #define PUBLIC                  /*public */
361 #define FORTRAN         int
362 
363 #define OOPS            -1                /*DONT CHANGE THIS */
364 #define OKAY            0                 /*DONT CHANGE THIS */
365 #define MAXDIMS_VARWRITE 7
366 #define OVER_WRITE      0x0001            /*overwrite DBobject */
367 #define FREE_MEM        0x0002            /*free DBobject memory */
368 #define NELMTS(X)       (sizeof(X)/sizeof(X[0]))  /*Number of elements */
369 
370 #define STR_EQUAL(S1,S2) (!strcmp((S1),(S2)))
371 #define STR_BEGINSWITH(S,P) ((strstr((S),(P))==(S))?1:0)
372 #define STR_LASTCHAR(S) ((S)[strlen((S))-1])
373 #define STR_HASCHAR(S,C) (strchr((S),(C))?1:0)
374 #define copy_var(FROM,TO,N) (memmove((TO),(FROM),(N)))
375 
376 /*
377  * Memory management macros.  All memory allocated by device
378  * drivers which is visible to any other device driver or
379  * SILO proper must be allocated with the C library memory
380  * management (malloc, calloc, realloc, strdup, free...).
381  */
382 #define ALLOC(T)                ((T*)calloc((size_t)1,sizeof(T)))
383 #define ALLOC_N(T,N)            ((T*)((N)>0?calloc((size_t)(N),sizeof(T)):0))
384 #define REALLOC(P,T,N)  REALLOC_N((P),(T),(N))
385 #define REALLOC_N(P,T,N)        ((T*)((N)>0?realloc((P),(size_t)((N)*sizeof(T))):0))
386 #define FREE(M)         if(M){free(M);(M)=NULL;}
387 #define STRDUP(S)               _db_safe_strdup((S))
388 #define STRNDUP(S,N)            db_strndup((S),(N))
389 
390 #define SW_strndup(S,N) db_strndup((S),(N))
391 #define SW_GetDatatypeString(N) db_GetDatatypeString((N))
392 #define SW_GetDatatypeID(S) db_GetDatatypeID((S))
393 #define SW_file_exists(S)       (access((S),F_OK)>=0?1:0)
394 #define SW_file_readable(S)     (access((S),R_OK)>=0?1:0)
395 #define INDEX(col,row,ncol) (((row)*(ncol))+(col))  /* Zero - origin ! */
396 #define INDEX3(i,j,k,nx,nxy) ((k)*(nxy)+(j)*(nx)+(i))  /* Zero - origin ! */
397 
398 #ifndef MAX
399 #define MAX(X,Y)        ((X)>(Y)?(X):(Y))
400 #define MIN(X,Y)        ((X)<(Y)?(X):(Y))
401 #endif
402 
403 #ifdef   DEREF
404 #undef   DEREF
405 #endif
406 #define  DEREF(type,x)       (* ((type *) (x)))
407 
408 /*
409  * File status, maintained by DBOpen, DBCreate, and DBClose.
410  */
411 #define DB_ISOPEN       0x01          /*database is open; ID is in use */
412 
413 #define db_SetMissingValueForGet(DST, SRC) \
414 {                                          \
415     DST = SRC;                             \
416     if (DST == DB_MISSING_VALUE_NOT_SET)   \
417         DST = 0.0;                         \
418     else if (DST == 0.0)                   \
419         DST = DB_MISSING_VALUE_NOT_SET;    \
420 }
421 
422 #define db_SetMissingValueForPut(DST, SRC) \
423 {                                          \
424     if (SRC != DB_MISSING_VALUE_NOT_SET)   \
425     {                                      \
426         if (SRC == 0)                      \
427             DST = DB_MISSING_VALUE_NOT_SET;\
428         else                               \
429             DST = SRC;                     \
430     }                                      \
431 }
432 
433 /*
434  * Global data for Material
435  */
436 struct _ma {
437     int            _origin;
438     int            _majororder;
439     char         **_matnames;
440     char         **_matcolors;
441     int            _allowmat0;
442     int            _guihide;
443 };
444 
445 /*
446  * Global data for Material Species.
447  */
448 struct _ms {
449     int            _majororder;
450     int            _guihide;
451     char         **_specnames;
452     char         **_speccolors;
453 };
454 
455 /*
456  * Global data for PointMesh and PointVar objects.
457  */
458 struct _pm {
459     float          _time;
460     int            _time_set;
461     double         _dtime;
462     int            _dtime_set;
463     int            _cycle;
464     int            _hi_offset;
465     int            _lo_offset;
466     int            _ndims;
467     int            _nspace;
468     int            _nels;
469     int            _origin;
470     int            _minindex;
471     int            _maxindex;
472     char          *_label;
473     char          *_unit;
474     char          *_labels[3];
475     char          *_units[3];
476     char          *_coordnames[3];
477     char           _nm_time[64];
478     char           _nm_dtime[64];
479     char           _nm_cycle[64];
480     int            _group_no;
481     int            _guihide;
482     int            _ascii_labels;
483     int           *_gnodeno;
484     char          *_mrgtree_name;
485     char         **_region_pnames;
486     int            _llong_gnodeno;
487     int            _conserved;
488     int            _extensive;
489     double         _missing_value;
490     char          *_ghost_node_labels;
491     char         **_alt_nodenum_vars;
492 
493     /*These used only by NetCDF driver */
494     int            _dim_ndims;
495     int            _dim_nels;
496     int            _dim_scalar;
497     int            _dim_2Xndims;
498     int            _dim_nspace;
499     int            _id_time;
500     int            _id_dtime;
501     int            _id_cycle;
502 };
503 
504 /*
505  * Global data for Quadmesh and Quadvar objects.
506  */
507 struct _qm {
508     float          _time;
509     int            _time_set;
510     double         _dtime;
511     int            _dtime_set;
512     float          _align[3];
513     int            _cycle;
514     int            _coord_sys;
515     int            _facetype;
516     int            _hi_offset[3];
517     int            _lo_offset[3];
518     int            _majororder;
519     int            _ndims;
520     int            _nspace;
521     int            _nnodes;
522     int            _nzones;
523     int            _origin;
524     int            _planar;
525     int            _dims[3];
526     int            _zones[3];
527     int            _minindex[3];
528     int            _maxindex_n[3];
529     int            _maxindex_z[3];
530     int            _nmat;
531     int            _use_specmf;
532     int            _ascii_labels;
533     char          *_label;
534     char          *_unit;
535     char          *_labels[3];
536     char          *_units[3];
537     char          *_meshname;
538     int            _baseindex[3];
539     int            _baseindex_set;
540     int            _group_no;
541     int            _guihide;
542     char          *_mrgtree_name;
543     char         **_region_pnames;
544     int            _conserved;
545     int            _extensive;
546     double         _missing_value;
547     char          *_ghost_node_labels;
548     char          *_ghost_zone_labels;
549     char         **_alt_nodenum_vars;
550     char         **_alt_zonenum_vars;
551 
552     /* These are probably only used by the pdb driver */
553     char           _nm_dims[64];
554     char           _nm_zones[64];
555     char           _nm_alignz[64];
556     char           _nm_alignn[64];
557     char           _nm_time[64];
558     char           _nm_dtime[64];
559     char           _nm_cycle[64];
560     char           _nm_minindex[64];
561     char           _nm_maxindex_n[64];
562     char           _nm_maxindex_z[64];
563     char           _nm_baseindex[64];
564 
565     /*These are used only by the NetCDF driver */
566     int            _dim_nnode[3];
567     int            _dim_nzone[3];
568     int            _dim_ndims;
569     int            _id_dims;
570     int            _id_minindex;
571     int            _id_maxindex_n;
572     int            _id_maxindex_z;
573     int            _id_time;
574     int            _id_dtime;
575     int            _id_alignn;
576     int            _id_alignz;
577     int            _id_zones;
578 
579 };
580 
581 /*
582  * Global data for Ucdmesh
583  */
584 struct _um {
585     float          _time;
586     int            _time_set;
587     double         _dtime;
588     int            _dtime_set;
589     float          _align[3];
590     int            _cycle;
591     int            _hi_offset;
592     int            _lo_offset;
593     int            _hi_offset_set;
594     int            _lo_offset_set;
595     int            _coord_sys;
596     int            _topo_dim;
597     int            _facetype;
598     int            _ndims;
599     int            _nspace;
600     int            _nnodes;
601     int            _nzones;
602     int            _origin;
603     int            _planar;
604     int            _dims[3];
605     int            _zones[3];
606     int            _nmat;
607     int            _use_specmf;
608     int            _ascii_labels;
609     char          *_label;
610     char          *_unit;
611     char          *_labels[3];
612     char          *_units[3];
613     char           _meshname[256];
614     char           _nm_dims[64];
615     char           _nm_zones[64];
616     char           _nm_alignz[64];
617     char           _nm_alignn[64];
618     char           _nm_time[64];
619     char           _nm_dtime[64];
620     char           _nm_cycle[64];
621     int           *_gnodeno;
622     int            _group_no;
623     char          *_phzl_name;
624     int            _guihide;
625     char          *_mrgtree_name;
626     char         **_region_pnames;
627     int            _tv_connectivity;
628     int            _disjoint_mode;
629     int            _llong_gnodeno;
630     int            _conserved;
631     int            _extensive;
632     double         _missing_value;
633     char          *_ghost_node_labels;
634     char         **_alt_nodenum_vars;
635 };
636 
637 /*
638  * Global data for Csgmesh
639  */
640 struct _csgm {
641     float          _time;
642     int            _time_set;
643     double         _dtime;
644     int            _dtime_set;
645     int            _cycle;
646     int            _ndims;
647     int            _nbounds;
648     int            _use_specmf;
649     int            _hi_offset;
650     int            _lo_offset;
651     int            _hi_offset_set;
652     int            _lo_offset_set;
653     int            _ascii_labels;
654     char          *_label;
655     char          *_unit;
656     char          *_labels[3];
657     char          *_units[3];
658     char           _meshname[256];
659     char           _nm_time[64];
660     char           _nm_dtime[64];
661     char           _nm_cycle[64];
662     int            _group_no;
663     int            _origin;
664     char          *_csgzl_name;
665     char         **_bndnames;
666     int            _guihide;
667     char          *_mrgtree_name;
668     char         **_region_pnames;
669     int            _tv_connectivity;
670     int            _disjoint_mode;
671     int            _conserved;
672     int            _extensive;
673     double         _missing_value;
674     char         **_alt_nodenum_vars;
675 };
676 
677 /*
678  * Global data for UCD Zonelist
679  */
680 struct _uzl {
681     int           *_gzoneno;
682     int            _llong_gzoneno;
683     char          *_ghost_zone_labels;
684     char         **_alt_zonenum_vars;
685 };
686 
687 /*
688  * Global data for Poly Zonelist
689  */
690 struct _phzl {
691     int           *_gzoneno;
692     int            _llong_gzoneno;
693     char          *_ghost_zone_labels;
694     char         **_alt_zonenum_vars;
695 };
696 
697 /*
698  * Global data for CSG Zonelist
699  */
700 struct _csgzl {
701     char         **_regnames;
702     char         **_zonenames;
703     char         **_alt_zonenum_vars;
704 };
705 
706 /*
707  * Global data for Mulimesh, Multimat, Multivar, and Multimatspecies
708  */
709 struct _mm {
710     float          _time;
711     int            _time_set;
712     double         _dtime;
713     int            _dtime_set;
714     int            _cycle;
715     char           _nm_time[64];
716     char           _nm_dtime[64];
717     char           _nm_cycle[64];
718     int            *_matnos;
719     int            _nmatnos;
720     char           *_matname;
721     int            _nmat;
722     int            *_nmatspec;
723     int            _blockorigin;
724     int            _grouporigin;
725     int            _ngroups;
726     int            _extentssize;
727     double         *_extents;
728     int            *_zonecounts;
729     int            *_mixlens;
730     int            *_matcounts;
731     int            *_matlists;
732     int            *_has_external_zones;
733     int            _allowmat0;
734     int            _guihide;
735     int            _lgroupings;
736     int            *_groupings;
737     char           **_groupnames;
738     char           **_matcolors;
739     char           **_matnames;
740     char           *_mrgtree_name;
741     char          **_region_pnames;
742     char           *_mmesh_name;
743     int             _tensor_rank;
744     int             _tv_connectivity;
745     int             _disjoint_mode;
746     int             _topo_dim;
747     char          **_specnames;
748     char          **_speccolors;
749     int            _conserved;
750     int            _extensive;
751     char          *_file_ns;
752     char          *_block_ns;
753     int            _block_type;
754     int           *_empty_list;
755     int            _empty_cnt;
756     int            _repr_block_idx;
757     double         _missing_value;
758     char         **_alt_zonenum_vars;
759     char         **_alt_nodenum_vars;
760 };
761 
762 /*
763  * Global data for curves.
764  */
765 struct _cu {
766    char         *_label ;
767    char         *_varname[2] ;
768    char         *_labels[2] ;
769    char         *_units[2] ;
770     int          _guihide;
771    char         *_reference ;
772     int          _coord_sys ;
773     double       _missing_value;
774 };
775 
776 /*
777  * Global data for defvars
778  */
779 struct _dv {
780     int         _guihide; /* for this object type, its an array */
781 };
782 
783 /*
784  * Global data for mrgtree
785  */
786 struct _mrgt {
787     char      **_mrgvar_onames;
788     char      **_mrgvar_rnames;
789 };
790 
791 extern struct _ma _ma;
792 extern struct _ms _ms;
793 extern struct _csgm _csgm;
794 extern struct _pm _pm;
795 extern struct _qm _qm;
796 extern struct _um _um;
797 extern struct _uzl _uzl;
798 extern struct _phzl _phzl;
799 extern struct _csgzl _csgzl;
800 extern struct _mm _mm;
801 extern struct _cu _cu;
802 extern struct _dv _dv;
803 extern struct _mrgt _mrgt;
804 
805 /*-------------------------------------------------------------------------
806  * Filter Name Table.  Filters are modules inserted between the API and the
807  * device driver that are able to perform preprocessing of the parameters
808  * and postprocessing of the return values.  This table associates the
809  * filter name (which must be unique) with a filter init routine
810  * which is called just after a database is opened whether the database
811  * requests the filter or not.  There is also a filter open routine which
812  * is called after the init routine, but only if the database requests the
813  * filter.  Either function can be null; if both are null then the entry
814  * is removed from the table.
815  *-------------------------------------------------------------------------
816  */
817 typedef struct filter_t {
818     char          *name;        /*filter name    */
819     int            (*init) (DBfile *, char *);
820     int            (*open) (DBfile *, char *);
821 } filter_t;
822 
823 #define MAX_FILE_OPTIONS_SETS 32
824 #define NUM_DEFAULT_FILE_OPTIONS_SETS (DB_FILE_OPTS_LAST+1)
825 #define DEFAULT_DRIVER_PRIORITIES \
826    {      /* unknown driver priorities */ \
827         1, 2, 7, 0, 3, 6, -1, 0, \
828         0, 0, 0, 0, 0, 0, 0, 0, \
829         0, 0, 0, 0, 0, 0, 0, 0, \
830         0, 0, 0, 0, 0, 0, 0, 0, \
831         0, 0, 0, 0, 0, 0, 0, 0, \
832         0, 0, 0 \
833     }
834 
835 
836 /* Namespace struct for Silo's global variables */
837 typedef struct SILO_Globals_t {
838     unsigned long long dataReadMask;
839     int allowOverwrites;
840     int allowEmptyObjects;
841     int enableChecksums;
842     int enableFriendlyHDF5Names;
843     int enableGrabDriver;
844     int maxDeprecateWarnings;
845     char *compressionParams;
846     float compressionMinratio;
847     int compressionErrmode;
848     const DBoptlist *fileOptionsSets[MAX_FILE_OPTIONS_SETS];
849     int _db_err_level;
850     void  (*_db_err_func)(char *);
851     int _db_err_level_drvr;
852     jstk_t *Jstk;   /*error jump stack  */
853     int unknownDriverPriorities[MAX_FILE_OPTIONS_SETS+10+1];
854 } SILO_Globals_t;
855 extern SILO_Globals_t SILO_Globals;
856 
857 struct db_PathnameComponentTag
858 {  char                            *name;
859    struct db_PathnameComponentTag *prevComponent;
860    struct db_PathnameComponentTag *nextComponent;
861 };
862 
863 typedef struct db_PathnameComponentTag   db_PathnameComponent;
864 
865 struct db_PathnameTag
866 {  db_PathnameComponent *firstComponent;
867    db_PathnameComponent *lastComponent;
868 };
869 
870 typedef struct db_PathnameTag            db_Pathname;
871 
872 /*
873  * Private functions.
874  */
875 INTERNAL context_t *context_switch (DBfile *, char const *, char const **);
876 INTERNAL int context_restore (DBfile *, context_t *);
877 INTERNAL DBfile *silo_db_close (DBfile *);
878 INTERNAL int db_num_registered_files();
879 INTERNAL DBtoc *db_AllocToc (void);
880 INTERNAL int db_FreeToc (DBfile *);
881 INTERNAL int db_GetMachDataSize (int);
882 INTERNAL char *DBGetObjtypeName (int);
883 INTERNAL char *db_strndup (const char *, int);
884 INTERNAL char *db_GetDatatypeString (int);
885 INTERNAL int db_GetDatatypeID (char const * const);
886 INTERNAL int db_perror (char const *, int, char const *);
887 INTERNAL void _DBQQCalcStride (int *, int *, int, int);
888 INTERNAL void _DBQMSetStride (DBquadmesh *);
889 INTERNAL int _DBstrprint (FILE *, char **, int, int, int, int, int);
890 INTERNAL void _DBsort_list (char **, int);
891 INTERNAL int _DBarrminmax (float *, int, float *, float *);
892 INTERNAL int _DBiarrminmax (int *, int, int *, int *);
893 INTERNAL int _DBdarrminmax (double *, int, double *, double *);
894 INTERNAL char *db_strerror (int);
895 INTERNAL int db_ListDir2 (DBfile *, char **, int, int, char **,
896                               int *);
897 INTERNAL int CSGM_CalcExtents (int, int, int, const int*,
898                                  const void *, double *, double *);
899 INTERNAL int _DBQMCalcExtents (DBVCP2_t, int, int const *, int const *, int const *, int,
900                                    int, void *, void *);
901 INTERNAL int UM_CalcExtents (DBVCP2_t, int, int, int, void *,
902                                  void *);
903 INTERNAL int _DBSubsetMinMax2 (DBVCP1_t, int, float *, float *, int,
904                                    int, int, int, int);
905 INTERNAL int _DBSubsetMinMax3 (float *, int, float *, float *, int, int,
906                                int, int, int, int, int, int);
907 INTERNAL int db_ProcessOptlist (int, DBoptlist const * const);
908 INTERNAL int db_VariableNameValid(char const *);
909 INTERNAL int db_SplitShapelist (DBucdmesh *um);
910 INTERNAL int db_ResetGlobalData_Csgmesh ();
911 INTERNAL int db_ResetGlobalData_Mrgtree();
912 INTERNAL int db_ResetGlobalData_PointMesh (int ndims);
913 INTERNAL int db_ResetGlobalData_QuadMesh (int ndims);
914 INTERNAL void db_ResetGlobalData_Curve (void);
915 INTERNAL int db_ResetGlobalData_Ucdmesh (int ndims, int nnodes, int nzones);
916 INTERNAL int db_ResetGlobalData_Ucdzonelist (void);
917 INTERNAL int db_ResetGlobalData_MultiMesh (void);
918 INTERNAL int db_ResetGlobalData_Defvars(void);
919 INTERNAL char *db_FullName2BaseName(const char *);
920 INTERNAL void db_StringArrayToStringList(char**, int, char **, int*);
921 INTERNAL char ** db_StringListToStringArray(char *, int, int, int);
922 INTERNAL void db_DriverTypeAndFileOptionsSetId(int driver, int *type,
923                                                int *opts_set_id);
924 INTERNAL char *db_absoluteOf_path ( const char *cwg, const char *pathname );
925 INTERNAL char *db_basename ( const char *pathname );
926 INTERNAL char *db_dirname ( const char *pathname );
927 INTERNAL int   db_isAbsolute_path ( const char *pathname );
928 INTERNAL int   db_isRelative_path ( const char *pathname );
929 INTERNAL char *db_join_path ( const char *a, const char *b );
930 INTERNAL char *db_normalize_path ( const char *p );
931 INTERNAL int   db_relative_path ( char *pathname );
932 INTERNAL char *db_unsplit_path ( const db_Pathname *p );
933 INTERNAL db_Pathname *db_split_path ( const char *pathname );
934 INTERNAL const int *db_get_used_file_options_sets_ids();
935 //char   *_db_safe_strdup (const char *);
936 #undef strdup /*prevent a warning for the following definition*/
937 #define strdup(s) _db_safe_strdup(s)
938 
939 INTERNAL int db_StringListToStringArrayMBOpt(char *strList, char ***strArray, char **alloc_flag, int nblocks);
940 
941 #endif /* !SILO_PRIVATE_H */
942