cdi_int.h 9.32 KB
Newer Older
1
2
#ifndef _CDI_INT_H
#define _CDI_INT_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
3
4
5
6
7

#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
8
#include <assert.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
9
#include <stdio.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
10
#include <stdbool.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
11
#include <string.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
12
#include <errno.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
13
14
15
16
#include <math.h>
#include <sys/types.h>

#ifndef strdupx
Uwe Schulzweida's avatar
Uwe Schulzweida committed
17
18
19
20
21
#ifndef strdup
char *strdup(const char *s);
#endif
#define strdupx  strdup
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
22
23
24
25
26
27
28
#define strdupx(s)			          \
({					      	  \
   const char *__old = (s);			  \
   size_t __len = strlen(__old) + 1;		  \
   char *__new = (char *) malloc(__len);	  \
   (char *) memcpy(__new, __old, __len);	  \
})
Uwe Schulzweida's avatar
Uwe Schulzweida committed
29
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
31
#endif

32
33
#ifndef  M_PI
#define  M_PI        3.14159265358979323846  /* pi */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
34
35
36
37
38
39
40
41
42
#endif


#ifndef  _ERROR_H
#  include "error.h"
#endif
#ifndef _BASETIME_H
#  include "basetime.h"
#endif
43
44
45
#ifndef _TIMEBASE_H
#  include "timebase.h"
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef  _TAXIS_H
#  include "taxis.h"
#endif
#ifndef  _CDI_LIMITS_H
#  include "cdi_limits.h"
#endif
#ifndef  _SERVICE_H
#  include "service.h"
#endif
#ifndef  _EXTRA_H
#  include "extra.h"
#endif
#ifndef  _IEG_H
#  include "ieg.h"
#endif
61
62
63
#ifndef RESOURCE_HANDLE_H
#  include "resource_handle.h"
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64

65

Deike Kleberg's avatar
Deike Kleberg committed
66
67
#define check_parg(arg)  if ( arg == 0 ) Warning("Argument '" #arg "' not allocated!")

Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
#if defined (__xlC__) /* performance problems on IBM */
Uwe Schulzweida's avatar
cleanup    
Uwe Schulzweida committed
69
70
71
72
#ifndef DBL_IS_NAN
#  define DBL_IS_NAN(x)     ((x) != (x))
#endif
#else
73
#ifndef DBL_IS_NAN
74
#if  defined  (HAVE_DECL_ISNAN)
75
#  define DBL_IS_NAN(x)     (isnan(x))
76
#elif  defined  (FP_NAN)
77
#  define DBL_IS_NAN(x)     (fpclassify(x) == FP_NAN)
78
#else
79
#  define DBL_IS_NAN(x)     ((x) != (x))
80
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
82
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
83

84
85
86
87
88
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif

89
90
91
92
93
94
#ifndef IS_EQUAL
#  define IS_NOT_EQUAL(x,y) (x < y || y < x)
#  define IS_EQUAL(x,y)     (!IS_NOT_EQUAL(x,y))
#endif


Uwe Schulzweida's avatar
Uwe Schulzweida committed
95
96
97
98
99
100
#define  FALSE  0
#define  TRUE   1

#define  TYPE_REC  0
#define  TYPE_VAR  1

101
102
103
#define  MEMTYPE_DOUBLE  1
#define  MEMTYPE_FLOAT   2

Uwe Schulzweida's avatar
Uwe Schulzweida committed
104
105
106
107
108
109
110
111
typedef struct
{
  void     *buffer;
  size_t    buffersize;
  off_t     position;
  int       recsize;
  int       size;
  int       dataread;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
  int       param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  int       level;
  int       date;
  int       time;
  int       gridID;
  int       zaxisID;
  int       used;
  int       nrec;
  int       varID;
  int       levelID;
  int       recid;
  int       prec;
  int       sec0[2];
  int       sec1[1024];
  int       sec2[4096];
  int       sec3[2];
  int       sec4[512];
#if  defined  (HAVE_LIBSERVICE)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
  srvrec_t   *srvp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
131
132
#endif
#if  defined  (HAVE_LIBEXTRA)
133
  extrec_t   *extp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
134
135
#endif
#if  defined  (HAVE_LIBIEG)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
136
  iegrec_t   *iegp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
138
139
140
141
142
143
144
145
#endif
}
Record;


typedef struct
{
  off_t     position;
  size_t    size;
146
  int       zip;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
147
  int       param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
150
151
152
153
  int       ilevel;
  int       ilevel2;
  int       ltype;
  short     used;
  short     varID;
  short     levelID;
154
  char      varname[32]; /* needed for grib decoding with GRIB_API */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
155
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
record_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
158
159


typedef struct {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
160
  record_t *records;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
162
163
164
165
166
167
168
169
  int       recordSize;  /* number of allocated records           */
  int      *recIDs;      /* IDs of non constant records           */
  int       nrecs;       /* number of used records                */
                         /* tsID=0 nallrecs                       */
                         /* tsID>0 number of non constant records */
  int       nallrecs;    /* number of all records                 */
  int       curRecID;    /* current record ID                     */
  long      next;
  off_t     position;    /* timestep file position                */
170
  taxis_t   taxis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
}
172
tsteps_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
173
174
175
176
177
178
179
180
181
182
183
184


typedef struct {
  int       ncvarid;
  int       nlevs;
  int      *level;       /* record IDs */
  int      *lindex;      /* level index */
  int       defmiss;     /* TRUE if missval is defined in file */

  int       isUsed;
  int       gridID;
  int       zaxisID;
185
  int       tsteptype;   /* TSTEP_* */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
186
}
187
svarinfo_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
189
190
191
192
193
194
195
196
197
198
199


typedef struct {
  int       ilev;
  int       mlev;
  int       ilevID;
  int       mlevID;
}
VCT;


typedef struct {
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  int         self;
  int         accesstype;   /* TYPE_REC or TYPE_VAR */
  int         accessmode;
  int         filetype;
  int         byteorder;
  int         fileID;
  int         dimgroupID;
  int         filemode;
  off_t       numvals;
  char       *filename;
  Record     *record;
  int        nrecs;        /* number of records                  */
  int         nvars;        /* number of variables                */
  int         varlocked;    /* variables locked                   */
  svarinfo_t *vars;
  int         varsAllocated;
  int         varinit;
  int         curTsID;      /* current timestep ID */
  int         rtsteps;      /* number of tsteps accessed       */
  long        ntsteps;      /* number of tsteps : only set if all records accessed */
  int         numTimestep;  /* number of tsteps : only set if all records accessed */
  tsteps_t   *tsteps;
  int         tstepsTableSize;
  int         tstepsNextID;
  BaseTime    basetime;
  int         ncmode;
  int         vlistID;
  int         xdimID[MAX_GRIDS_PS];
  int         ydimID[MAX_GRIDS_PS];
  int         zaxisID[MAX_ZAXES_PS];
  int         ncxvarID[MAX_GRIDS_PS];
  int         ncyvarID[MAX_GRIDS_PS];
  int         ncavarID[MAX_GRIDS_PS];
  int         historyID;
  int         globalatts;
  int         localatts;
  VCT         vct;
  int         unreduced;
  int         sortname;
  int         have_missval;
  int         comptype;      // compression type
  int         complevel;     // compression level
  int         curfile;
  int         nfiles;
  char      **fnames;
#if defined (GRIBCONTAINER2D)
  void      **gribContainers;
#else
  void       *gribContainers;
#endif
  int         vlistIDorig;
251
  /* only used by MPI-parallelized version of library */
252
  int       ownerRank;    // MPI rank of owner process
253
254
255
256
257
  /* ---------------------------------- */
  /* Local change: 2013-02-18, FP (DWD) */
  /* ---------------------------------- */

  void *gh; // grib handle
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
stream_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
260
261
262


extern int CDI_Debug;      /* If set to 1, debuggig (default 0)            */
263
extern int cdiGribApiDebug;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
264
265
266
267
268
extern double cdiDefaultMissval;
extern int cdiDefaultInstID;
extern int cdiDefaultModelID;
extern int cdiDefaultTableID;
extern int cdiDefaultLeveltype;
269
//extern int cdiNcMissingValue;
270
extern int cdiNcChunksizehint;
271
extern int cdiChunkType;
272
extern int cdiSplitLtype105;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273

Uwe Schulzweida's avatar
Uwe Schulzweida committed
274
275
276
extern char *cdiPartabPath;
extern int   cdiPartabIntern;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
277
278
279
stream_t *stream_to_pointer(int idx);
stream_t *stream_new_entry(void);
void stream_delete_entry(stream_t *streamptr);
280
void stream_check_ptr(const char *caller, stream_t *streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
281

Uwe Schulzweida's avatar
Uwe Schulzweida committed
282
283
int     streamInqFileID(int streamID);

284
285
void    gridDefHasDims(int gridID, int hasdims);
int     gridInqHasDims(int gridID);
286
const char *gridNamePtr(int gridtype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
287
char   *zaxisNamePtr(int leveltype);
288
int     zaxisInqLevelID(int zaxisID, double level);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
289

290
void    streamCheckID(const char *caller, int streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
291
292
293
294
295

void    streamDefineTaxis(int streamID);

int     streamsNewEntry(int filetype);
void    streamsInitEntry(int streamID);
296
void    cdiStreamSetupVlist(stream_t *streamptr, int vlistID, int vlistIDorig);
297
int     stream_new_var(stream_t *streamptr, int gridID, int zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
298

299
int     tstepsNewEntry(stream_t *streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
300

301
const char *strfiletype(int filetype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
302

303
void    cdi_generate_vars(stream_t *streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
304

305
void    vlist_check_contents(int vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
306

307
void    cdi_create_records(stream_t *streamptr, int tsID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
308

309
int     recordNewEntry(stream_t *streamptr, int tsID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
310

311
void    cdiCreateTimesteps(stream_t *streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
312

Uwe Schulzweida's avatar
Uwe Schulzweida committed
313
void    recordInitEntry(record_t *record);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
314
315
316
317
318
319
320
321
322
323
324

void    cdiCheckZaxis(int zaxisID);

void    cdiPrintDatatypes(void);

void    cdiDefAccesstype(int streamID, int type);
int     cdiInqAccesstype(int streamID);

void    streamDefDimgroupID(int streamID, int dimgroupID);
int     streamInqDimgroupID(int streamID);

Deike Kleberg's avatar
Deike Kleberg committed
325
326
327
int     getByteswap(int byteorder);

int     streamSize ();
328
void    streamGetIndexList ( int, int * );
Deike Kleberg's avatar
Deike Kleberg committed
329

Uwe Schulzweida's avatar
Uwe Schulzweida committed
330

331
332
333
334
void  cdiInitialize(void);

void stream_write_record(int streamID, int memtype, const void *data, int nmiss);

335
336
337
void uuid2str(const char *uuid, char *uuidstr);
void str2uuid(const char *uuidstr, char *uuid);

338
339
340
341
342
343
#define CDI_UNIT_PA   1
#define CDI_UNIT_HPA  2
#define CDI_UNIT_MM   3
#define CDI_UNIT_CM   4
#define CDI_UNIT_DM   5
#define CDI_UNIT_M    6
344

345
346
347
348
349
350
351
struct streamAssoc
{
  int streamID, vlistID, vlistIDorig;
};

struct streamAssoc
streamUnpack(char * unpackBuffer, int unpackBufferSize,
352
             int * unpackBufferPos, int originNamespace, void *context);
353

354
355
int
cdiStreamOpenDefaultDelegate(const char *filename, const char *filemode,
356
357
                             int filetype, stream_t *streamptr,
                             int recordBufIsToBeCreated);
358
359
360
361
362
363
364
365
366
367

void
cdiStreamDefVlist_(int streamID, int vlistID);
void
cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data,
                   int nmiss);
void
cdiStreamwriteVarChunk_(int streamID, int varID, int memtype,
                        const int rect[][2], const void *data, int nmiss);
void
368
369
cdiStreamCloseDefaultDelegate(stream_t *streamptr,
                              int recordBufIsToBeDeleted);
370

Thomas Jahns's avatar
Thomas Jahns committed
371
372
int cdiStreamDefTimestep_(stream_t *streamptr, int tsID);

Thomas Jahns's avatar
Thomas Jahns committed
373
374
void cdiStreamSync_(stream_t *streamptr);

375
376
char *cdiUnitNamePtr(int cdi_unit);

377
extern const resOps streamOps;
378
379

#endif  /* _CDI_INT_H */
380
381
382
383
384
385
386
387
388
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */