vlist.h 6.99 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
#ifndef _VLIST_H
#define _VLIST_H

Thomas Jahns's avatar
Thomas Jahns committed
4
5
6
7
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

8
#ifndef  _ERROR_H
9
#include "error.h"
10
#endif
11

12
13
#include <stddef.h>  /* size_t */

Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
#ifndef _CDI_LIMITS_H
15
#include "cdi_limits.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
16
17
#endif

Deike Kleberg's avatar
Deike Kleberg committed
18
#define VALIDMISS 1.e+303
Uwe Schulzweida's avatar
Uwe Schulzweida committed
19

20
21
22
23
/*
 * CDI attribute
 */
typedef struct {
24
25
26
27
28
29
30
31
32
33
34
  size_t    xsz;	  /* amount of space at xvalue                      */
  size_t    namesz;       /* size of name                                   */
  char     *name;         /* attribute name                                 */
  int       indtype;	  /* internal data type of xvalue (INT, FLT or TXT) */
  int       exdtype;      /* external data type                             */
                          /* indtype    exdtype                             */
                          /* TXT        TXT                                 */
                          /* INT        INT16, INT32                        */
                          /* FLT        FLT32, FLT64                        */
  size_t    nelems;    	  /* number of elements                             */
  void     *xvalue;       /* the actual data                                */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
35
} cdi_att_t;
36
37
38


typedef struct {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
39
40
41
42
  size_t     nalloc;		/* number allocated >= nelems */
  size_t     nelems;		/* length of the array */
  cdi_att_t  value[MAX_ATTRIBUTES];
} cdi_atts_t;
43
44


Uwe Schulzweida's avatar
Uwe Schulzweida committed
45
46
47
48
typedef struct
{
  int      flag;
  int      index;
49
  int      mlevelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
51
  int      flevelID;
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
52
levinfo_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
53

54
55
56
#define DEFAULT_LEVINFO(levID) \
  (levinfo_t){ 0, -1, levID, levID}
/*
57
58
#define DEFAULT_LEVINFO(levID) \
  (levinfo_t){ .flag = 0, .index = -1, .flevelID = levID, .mlevelID = levID}
59
*/
60
61
62
63
64
65
66
67
typedef struct
{
  int ens_index;
  int ens_count;
  int forecast_init_type;
}
ensinfo_t;

68

Deike Kleberg's avatar
Deike Kleberg committed
69

Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
71
typedef struct
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
73
74
75
76
77
78
  int         flag;
  int         isUsed;
  int         mvarID;
  int         fvarID;
  int         param;
  int         gridID;
  int         zaxisID;
79
  int         tsteptype; /* TSTEP_* */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
81
82
83
84
85
  int         datatype;  /* DATATYPE_PACKX for GRIB data, else DATATYPE_FLT32 or DATATYPE_FLT64 */
  int         instID;
  int         modelID;
  int         tableID;
  int         timave;
  int         timaccu;
86
  int         typeOfGeneratingProcess;
87
  int         productDefinitionTemplate;
88
  int         chunktype;
89
  int         xyz;
90
  int         missvalused; /* TRUE if missval is defined */
Deike Kleberg's avatar
Deike Kleberg committed
91
  int         lvalidrange;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
93
94
95
  char       *name;
  char       *longname;
  char       *stdname;
  char       *units;
96
  char       *extra;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97
98
99
  double      missval;
  double      scalefactor;
  double      addoffset;
Deike Kleberg's avatar
Deike Kleberg committed
100
  double      validrange[2];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
  levinfo_t  *levinfo;
Deike Kleberg's avatar
Deike Kleberg committed
102
103
  int         comptype;     // compression type
  int         complevel;    // compression level
104
  ensinfo_t  *ensdata;      /* Ensemble information */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
  cdi_atts_t  atts;
Deike Kleberg's avatar
Deike Kleberg committed
106
  int         iorank;
107
108
109

  int         subtypeID;   /* subtype ID for tile-related meta-data, currently for GRIB-API only. */

110
111
112
  int                 opt_grib_nentries;       /* current no. key-value pairs            */
  int                 opt_grib_kvpair_size;    /* current allocated size                 */
  opt_key_val_pair_t *opt_grib_kvpair;         /* (optional) list of keyword/value pairs */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
var_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115

Uwe Schulzweida's avatar
Uwe Schulzweida committed
116

Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
118
typedef struct
{
119
120
  unsigned    immutable : 1;    //set when a vlist is passed to streamDefVlist() to safeguard against modifications of the wrong vlist object
  unsigned    internal : 1;     //set if this vlist has been created by CDI itself, and must not be destroyed by the user, consequently
Uwe Schulzweida's avatar
Uwe Schulzweida committed
121
122
123
124
  int         self;
  int         nvars;        /* number of variables                */
  int         ngrids;
  int         nzaxis;
125
  int         nsubtypes;    /* no. of variable subtypes (e.g. sets of tiles) */
126
  long        ntsteps;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128
129
130
131
132
  int         taxisID;
  int         tableID;
  int         instID;
  int         modelID;
  int         varsAllocated;
  int         gridIDs[MAX_GRIDS_PS];
133
  int         zaxisIDs[MAX_ZAXES_PS];
134
  int         subtypeIDs[MAX_SUBTYPES_PS];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
135
136
  var_t      *vars;
  cdi_atts_t  atts;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
}
138
139
140
141
vlist_t;


vlist_t *vlist_to_pointer(int vlistID);
142
143
void cdiVlistMakeInternal(int vlistID);
void cdiVlistMakeImmutable(int vlistID);
144
void vlistCheckVarID(const char *caller, int vlistID, int varID);
145
const char *vlistInqVarStdnamePtr(int vlistID, int varID);
146
147
void     vlistDestroyVarName(int vlistID, int varID);
void     vlistDestroyVarLongname(int vlistID, int varID);
Thomas Jahns's avatar
Thomas Jahns committed
148
void     vlistDestroyVarStdname(int vlistID, int varID);
149
void     vlistDestroyVarUnits(int vlistID, int varID);
150
void     cdiVlistDestroy_(int vlistID);
151
void     vlistDefVarTsteptype(int vlistID, int varID, int tsteptype);
152
153
154
155
156
int      vlistInqVarMissvalUsed(int vlistID, int varID);
int      vlistHasTime(int vlistID);

int      vlistDelAtts(int vlistID, int varID);
int      vlistCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
157

158
159
void     vlistUnpack(char * buffer, int bufferSize, int * pos,
                     int originNamespace, void *context, int force_id);
Thomas Jahns's avatar
Thomas Jahns committed
160

Deike Kleberg's avatar
Deike Kleberg committed
161
162
163
164
165
166
/*      vlistDefVarValidrange: Define the valid range of a Variable */
void    vlistDefVarValidrange(int vlistID, int varID, const double *validrange);

/*      vlistInqVarValidrange: Get the valid range of a Variable */
int     vlistInqVarValidrange(int vlistID, int varID, double *validrange);

167
168
void vlistInqVarDimorder(int vlistID, int varID, int (*outDimorder)[3]);

169
170
int vlist_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int attnum);

171
172
173
174
void resize_opt_grib_entries(var_t *var, int nentries);



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
static inline void
vlistAdd2GridIDs(vlist_t *vlistptr, int gridID)
{
  int index, ngrids = vlistptr->ngrids;
  for ( index = 0; index < ngrids; index++ )
    if (vlistptr->gridIDs[index] == gridID ) break;
  if ( index == ngrids )
    {
      if (ngrids >= MAX_GRIDS_PS)
        Error("Internal limit exceeded: more than %d grids.", MAX_GRIDS_PS);
      ++(vlistptr->ngrids);
      vlistptr->gridIDs[ngrids] = gridID;
    }
}

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
static inline void
vlistAdd2ZaxisIDs(vlist_t *vlistptr, int zaxisID)
{
  int index, nzaxis = vlistptr->nzaxis;
  for ( index = 0; index < nzaxis; index++ )
    if ( zaxisID == vlistptr->zaxisIDs[index] ) break;

  if ( index == nzaxis )
    {
      if ( nzaxis >= MAX_ZAXES_PS )
	Error("Internal limit exceeded: more than %d zaxis.", MAX_ZAXES_PS);
      vlistptr->zaxisIDs[nzaxis] = zaxisID;
      vlistptr->nzaxis++;
    }
}

206
207
208
static inline void
vlistAdd2SubtypeIDs(vlist_t *vlistptr, int subtypeID)
{
209
210
  if ( subtypeID == CDI_UNDEFID ) return;

211
212
213
214
215
216
217
218
219
220
221
222
  int index, nsubs = vlistptr->nsubtypes;
  for ( index = 0; index < nsubs; index++ )
    if (vlistptr->subtypeIDs[index] == subtypeID ) break;
  if ( index == nsubs )
    {
      if (nsubs >= MAX_SUBTYPES_PS)
        Error("Internal limit exceeded: more than %d subs.", MAX_SUBTYPES_PS);
      ++(vlistptr->nsubtypes);
      vlistptr->subtypeIDs[nsubs] = subtypeID;
    }
}

223

224

225
226
227
228
229
#if  defined  (HAVE_LIBGRIB_API)
extern int   cdiNAdditionalGRIBKeys;
extern char* cdiAdditionalGRIBKeys[];
#endif

Thomas Jahns's avatar
Thomas Jahns committed
230
231
232
233
234
235
extern
#ifndef __cplusplus
const
#endif
resOps vlistOps;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
236
#endif  /* _VLIST_H */
237
238
239
240
241
242
243
244
245
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */