stream_int.h 6.82 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
#ifndef _STREAM_INT_H
#define _STREAM_INT_H

#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
10
11
12
13
14
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>

#ifndef strdupx
Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
16
17
18
19
#ifndef strdup
char *strdup(const char *s);
#endif
#define strdupx  strdup
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
20
21
22
23
24
25
26
#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
27
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
28
29
30
31
32
33
34
35
36
37
38
39
40
#endif

#ifndef M_PI
#define M_PI		3.14159265358979323846	/* pi */
#endif


#ifndef  _ERROR_H
#  include "error.h"
#endif
#ifndef _BASETIME_H
#  include "basetime.h"
#endif
41
42
43
#ifndef _TIMEBASE_H
#  include "timebase.h"
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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

60

Uwe Schulzweida's avatar
cleanup    
Uwe Schulzweida committed
61
62
63
64
65
#if defined (__ibm__) /* performance problems on IBM */
#ifndef DBL_IS_NAN
#  define DBL_IS_NAN(x)     ((x) != (x))
#endif
#else
66
67
#ifndef DBL_IS_NAN
#if  defined  (HAVE_ISNAN)
68
#  define DBL_IS_NAN(x)     (isnan(x))
69
#elif  defined  (FP_NAN)
70
#  define DBL_IS_NAN(x)     (fpclassify(x) == FP_NAN)
71
#else
72
#  define DBL_IS_NAN(x)     ((x) != (x))
73
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
74
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76

77
78
79
80
81
#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

82
83
84
85
86
87
#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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef INT
#  define  INT(x)  ((int)(x))
#endif

#ifndef NINT
#  define  NINT(x)  ((x) < 0 ? (int)((x)-.5) : (int)((x)+.5))
#endif

#define  FALSE  0
#define  TRUE   1

#define  TYPE_REC  0
#define  TYPE_VAR  1


typedef struct
{
  void     *buffer;
  size_t    buffersize;
  off_t     position;
  int       recsize;
  int       size;
  int       dataread;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111
  int       param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
113
114
115
116
117
118
119
120
121
122
  int       level;
  int       date;
  int       time;
  int       gridID;
  int       zaxisID;
  int       used;
  int       nrec;
  int       varID;
  int       levelID;
  int       recid;
  int       prec;
123
  int       number;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
124
125
126
127
128
129
130
131
132
  int       sec0[2];
  int       sec1[1024];
  int       sec2[4096];
  int       sec3[2];
  int       sec4[512];
#if  defined  (HAVE_LIBSERVICE)
  SRVREC   *srvp;
#endif
#if  defined  (HAVE_LIBEXTRA)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
  extrec_t *extp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
134
135
136
137
138
139
140
141
142
143
144
145
#endif
#if  defined  (HAVE_LIBIEG)
  IEGREC   *iegp;
#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
154
  int       ilevel;
  int       ilevel2;
  int       ltype;
  short     used;
  short     varID;
  short     levelID;
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
155
record_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
157
158


typedef struct {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
159
  record_t *records;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  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                */
  TAXIS     taxis;
}
TSTEPS;


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;
  int       timeID;      /* ( TIME_VARIABLE or TIME_CONSTANT ) */
  int       nlevel;
}
SVARINFO;


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


typedef struct {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
  int       self;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
201
202
203
204
205
206
207
  int       accesstype;   /* TYPE_REC or TYPE_VAR */
  int       accessmode;
  int       filetype;
  int       byteorder;
  int       fileID;
  int       dimgroupID;
  int       filemode;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
208
  off_t     numvals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  char     *filename;
  Record   *record;
  int       nrecs;        /* number of records                  */
  int       nvars;        /* number of variables                */
  int       varlocked;    /* variables locked                   */
  SVARINFO *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   *tsteps;
  int       tstepsTableSize;
  int       tstepsNextID;
  BaseTime  basetime;
  int       ncmode;
  int       vlistID;
227
228
229
230
231
232
  int       xdimID[MAX_GRIDS_PS];
  int       ydimID[MAX_GRIDS_PS];
  int       zaxisID[MAX_ZAXIS_PS];
  int       ncxvarID[MAX_GRIDS_PS];
  int       ncyvarID[MAX_GRIDS_PS];
  int       ncavarID[MAX_GRIDS_PS];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
233
234
235
236
237
  int       historyID;
  int       globalatts;
  int       localatts;
  VCT       vct;
  int       unreduced;
238
  int       sortname;
239
240
  int       ztype;
  int       zlevel;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
241
242
243
  int       curfile;
  int       nfiles;
  char    **fnames;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
244
  int       gribHandleNums;
245
  void    **gribHandle;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
247
stream_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
248
249
250
251
252
253
254
255


extern int CDI_Debug;      /* If set to 1, debuggig (default 0)            */
extern double cdiDefaultMissval;
extern int cdiDefaultInstID;
extern int cdiDefaultModelID;
extern int cdiDefaultTableID;
extern int cdiDefaultLeveltype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
256
extern int cdiNcMissingValue;
257
extern int cdiSplitLtype105;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258

Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
260
261
extern char *cdiPartabPath;
extern int   cdiPartabIntern;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
262
263
264
265
stream_t *stream_to_pointer(int idx);
stream_t *stream_new_entry(void);
void stream_delete_entry(stream_t *streamptr);
void stream_check_ptr(const char *func, stream_t *streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
266

Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
int     streamInqFileID(int streamID);

int     zaxisInqLevelID(int zaxisID, double level);
char   *gridNamePtr(int gridtype);
char   *zaxisNamePtr(int leveltype);

void    streamCheckID(const char *func, int streamID);

void    streamDefineTaxis(int streamID);

int     streamsNewEntry(int filetype);
void    streamsInitEntry(int streamID);
int     streamNewVar(int streamID, int gridID, int zaxisID);

int     tstepsNewEntry(int streamID);

char   *strfiletype(int filetype);

void    cdiGenVars(int streamID);

void    cdiCheckContents(int streamID);

void    cdiCreateRecords(int streamID, int tsID);

int     recordNewEntry(int streamID, int tsID);

void    cdiCreateTimesteps(int streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
295
void    recordInitEntry(record_t *record);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
296
297
298
299
300
301
302
303
304
305
306
307
308

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);

int getByteswap(int byteorder);

309

Uwe Schulzweida's avatar
Uwe Schulzweida committed
310
#endif  /* _STREAM_INT_H */