vlist_var.c 56.9 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

5
6
#include <limits.h>

Uwe Schulzweida's avatar
Uwe Schulzweida committed
7
8
#include "dmemory.h"
#include "cdi.h"
9
#include "cdi_int.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
10
#include "vlist.h"
Deike Kleberg's avatar
Deike Kleberg committed
11
#include "vlist_var.h"
12
#include "resource_handle.h"
13
#include "vlist_att.h"
Deike Kleberg's avatar
Deike Kleberg committed
14
#include "namespace.h"
15
#include "serialize.h"
16
#include "error.h"
17

18
19
20
21
22
extern
#if !defined(__cplusplus)
const
#endif
resOps vlist_ops;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
23

Uwe Schulzweida's avatar
Uwe Schulzweida committed
24
#define RESH_ISCLOSED_VLIST(vlistID)    (reshGetStatus(vlistID, &vlist_ops) == RESH_CLOSED)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
25
26
#define RETURN_IFCLOSED_VLIST(vlistID)         if ( RESH_ISCLOSED_VLIST(vlistID) ) {Warning("%s", "Operation not executed."); return;}
#define RETURN_IFCLOSED_VLIST2(vlistID, rval)  if ( RESH_ISCLOSED_VLIST(vlistID) ) {Warning("%s", "Operation not executed."); return rval;}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
27
28


29
30
static
void vlistvarInitEntry(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
31
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33

Deike Kleberg's avatar
Deike Kleberg committed
34
35
36
37
38
39
40
41
  vlistptr->vars[varID].fvarID        = varID;
  vlistptr->vars[varID].mvarID        = varID;
  vlistptr->vars[varID].flag          = 0;
  vlistptr->vars[varID].param         = 0;
  vlistptr->vars[varID].datatype      = CDI_UNDEFID;
  vlistptr->vars[varID].tsteptype     = TSTEP_INSTANT;
  vlistptr->vars[varID].timave        = 0;
  vlistptr->vars[varID].timaccu       = 0;
42
43
  vlistptr->vars[varID].typeOfGeneratingProcess   = 0;
  vlistptr->vars[varID].productDefinitionTemplate = -1;
44
  vlistptr->vars[varID].chunktype     = cdiChunkType;
Deike Kleberg's avatar
Deike Kleberg committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  vlistptr->vars[varID].xyz           = 0;
  vlistptr->vars[varID].gridID        = CDI_UNDEFID;
  vlistptr->vars[varID].zaxisID       = CDI_UNDEFID;
  vlistptr->vars[varID].instID        = CDI_UNDEFID;
  vlistptr->vars[varID].modelID       = CDI_UNDEFID;
  vlistptr->vars[varID].tableID       = CDI_UNDEFID;
  vlistptr->vars[varID].missvalused   = FALSE;
  vlistptr->vars[varID].missval       = cdiDefaultMissval;
  vlistptr->vars[varID].addoffset     = 0.0;
  vlistptr->vars[varID].scalefactor   = 1.0;
  vlistptr->vars[varID].name          = NULL;
  vlistptr->vars[varID].longname      = NULL;
  vlistptr->vars[varID].stdname       = NULL;
  vlistptr->vars[varID].units         = NULL;
59
  vlistptr->vars[varID].extra         = NULL;
Deike Kleberg's avatar
Deike Kleberg committed
60
61
62
63
64
65
66
67
  vlistptr->vars[varID].levinfo       = NULL;
  vlistptr->vars[varID].comptype      = COMPRESS_NONE;
  vlistptr->vars[varID].complevel     = 1;
  vlistptr->vars[varID].atts.nalloc   = MAX_ATTRIBUTES;
  vlistptr->vars[varID].atts.nelems   = 0;
  vlistptr->vars[varID].lvalidrange   = 0;
  vlistptr->vars[varID].validrange[0] = VALIDMISS;
  vlistptr->vars[varID].validrange[1] = VALIDMISS;
68
  vlistptr->vars[varID].ensdata       = NULL;
69
70
  vlistptr->vars[varID].iorank        = CDI_UNDEFID;

71
#if  defined  (HAVE_LIBGRIB_API)
72
73
74
75
76
77
78
79
80
  /* ---------------------------------- */
  /* Local change: 2013-01-28, FP (DWD) */
  /* ---------------------------------- */

  vlistptr->vars[varID].opt_grib_dbl_nentries = 0;
  vlistptr->vars[varID].opt_grib_int_nentries = 0;
  int i;
  for (i=0; i<MAX_OPT_GRIB_ENTRIES; i++) {
    vlistptr->vars[varID].opt_grib_int_val[i] =   0;
81
82
83
    vlistptr->vars[varID].opt_grib_dbl_val[i] = 0.0;
    vlistptr->vars[varID].opt_grib_int_update[i] = FALSE;
    vlistptr->vars[varID].opt_grib_dbl_update[i] = FALSE;
84
85
86
    vlistptr->vars[varID].opt_grib_int_keyword[i] = NULL;
    vlistptr->vars[varID].opt_grib_dbl_keyword[i] = NULL;
  } // for
87
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
89
}

90
91
static
int vlistvarNewEntry(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
93
94
{
  int varID = 0;
  int vlistvarSize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
95
  var_t *vlistvar;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97
98
99
100
101
102
103
104
105
106
107
108

  vlistvarSize = vlistptr->varsAllocated;
  vlistvar     = vlistptr->vars;
  /*
    Look for a free slot in vlistvar.
    (Create the table the first time through).
  */
  if ( ! vlistvarSize )
    {
      int i;

      vlistvarSize = 2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
109
      vlistvar = (var_t *) malloc(vlistvarSize*sizeof(var_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
      if ( vlistvar == NULL )
	{
112
113
          Message("vlistvarSize = %d", vlistvarSize);
	  SysError("Allocation of var_t failed");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
115
116
117
118
119
120
	}

      for ( i = 0; i < vlistvarSize; i++ )
	vlistvar[i].isUsed = FALSE;
    }
  else
    {
Thomas Jahns's avatar
Thomas Jahns committed
121
122
      while (varID < vlistvarSize && vlistvar[varID].isUsed)
        ++varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124
125
126
127
128
129
130
131
    }
  /*
    If the table overflows, double its size.
  */
  if ( varID == vlistvarSize )
    {
      int i;

      vlistvarSize = 2*vlistvarSize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
      vlistvar = (var_t *) realloc(vlistvar, vlistvarSize*sizeof(var_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
134
      if ( vlistvar == NULL )
	{
135
136
          Message("vlistvarSize = %d", vlistvarSize);
	  SysError("Reallocation of var_t failed");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
	}
      varID = vlistvarSize/2;

      for ( i = varID; i < vlistvarSize; i++ )
	vlistvar[i].isUsed = FALSE;
    }

  vlistptr->varsAllocated = vlistvarSize;
  vlistptr->vars          = vlistvar;

  vlistvarInitEntry(vlistID, varID);

  vlistptr->vars[varID].isUsed = TRUE;

  return (varID);
}

154
155
static
void vlistCheckVarID(const char *caller, int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
159

  if ( vlistptr == NULL )
160
    Errorc("vlist undefined!");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
162

  if ( varID < 0 || varID >= vlistptr->nvars )
163
    Errorc("varID %d undefined!", varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
164
165

  if ( ! vlistptr->vars[varID].isUsed )
166
    Errorc("varID %d undefined!", varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
168
169
170
}

/*
@Function  vlistDefVar
Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
@Title     Define a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
172

173
@Prototype int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
174
@Parameter
175
176
177
178
179
    @Item  vlistID   Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  gridID    Grid ID, from a previous call to @fref{gridCreate}.
    @Item  zaxisID   Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  tsteptype One of the set of predefined CDI timestep types.
                     The valid CDI timestep types are @func{TSTEP_CONSTANT} and @func{TSTEP_INSTANT}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
180
181

@Description
182
The function @func{vlistDefVar} adds a new variable to vlistID.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
183
184

@Result
185
@func{vlistDefVar} returns an identifier to the new variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
186

Uwe Schulzweida's avatar
Uwe Schulzweida committed
187
188
189
190
191
192
193
194
195
196
@Example
Here is an example using @func{vlistCreate} to create a variable list
and add a variable with @func{vlistDefVar}.

@Source
#include "cdi.h"
   ...
int vlistID, varID;
   ...
vlistID = vlistCreate();
197
varID = vlistDefVar(vlistID, gridID, zaxisID, TIME_INSTANT);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
198
199
200
201
202
203
   ...
streamDefVlist(streamID, vlistID);
   ...
vlistDestroy(vlistID);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
205
@EndFunction
*/
206
int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
208
209
{
  int varID;
  int index;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
210
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
211
  RETURN_IFCLOSED_VLIST2(vlistID, CDI_UNDEFID);
212

Uwe Schulzweida's avatar
Uwe Schulzweida committed
213
  if ( CDI_Debug )
214
    Message("gridID = %d  zaxisID = %d  tsteptype = %d", gridID, zaxisID, tsteptype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
215
216
217
218
219
220
221

  varID = vlistvarNewEntry(vlistID);

  vlistptr->nvars++;

  vlistptr->vars[varID].gridID  = gridID;
  vlistptr->vars[varID].zaxisID = zaxisID;
222
  vlistptr->vars[varID].tsteptype = tsteptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
223

224
  if ( tsteptype < 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
225
    {
226
227
      Message("Unexpected tstep type %d, set to TSTEP_INSTANT!", tsteptype);
      vlistptr->vars[varID].tsteptype = TSTEP_INSTANT;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
228
    }
229

Uwe Schulzweida's avatar
Uwe Schulzweida committed
230
231
232
233
234
  for ( index = 0; index < vlistptr->ngrids; index++ )
    if ( gridID == vlistptr->gridIDs[index] ) break;

  if ( index == vlistptr->ngrids )
    {
235
      if ( vlistptr->ngrids + 1 >= MAX_GRIDS_PS )
236
	Error("Maximum of %d grids reached", MAX_GRIDS_PS);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
238
239
240
241
242
243
244
245
246

      vlistptr->gridIDs[vlistptr->ngrids] = gridID;
      vlistptr->ngrids++;
    }

  for ( index = 0; index < vlistptr->nzaxis; index++ )
    if ( zaxisID == vlistptr->zaxisIDs[index] ) break;

  if ( index == vlistptr->nzaxis )
    {
247
248
      if ( vlistptr->nzaxis + 1 >= MAX_ZAXES_PS )
	Error("Maximum of %d zaxis reached", MAX_ZAXES_PS);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
250
251
252
253

      vlistptr->zaxisIDs[vlistptr->nzaxis] = zaxisID;
      vlistptr->nzaxis++;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
  vlistptr->vars[varID].param = cdiEncodeParam(-(varID + 1), 255, 255);
255

Uwe Schulzweida's avatar
Uwe Schulzweida committed
256
257
258
  return (varID);
}

259
260
261
262
263
264
265
266
void
cdiVlistCreateVarLevInfo(vlist_t *vlistptr, int varID)
{
  xassert(varID >= 0 && varID < vlistptr->nvars
          && vlistptr->vars[varID].levinfo == NULL);
  int zaxisID = vlistptr->vars[varID].zaxisID;
  int nlevs = zaxisInqSize(zaxisID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
  vlistptr->vars[varID].levinfo = (levinfo_t*) malloc(nlevs * sizeof(levinfo_t));
268
269
270
271
272

  for (int levID = 0; levID < nlevs; levID++ )
      vlistptr->vars[varID].levinfo[levID] = DEFAULT_LEVINFO(levID);
}

273
274
275
276
277
278
/*
@Function  vlistDefVarParam
@Title     Define the parameter number of a Variable

@Prototype void vlistDefVarParam(int vlistID, int varID, int param)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
279
280
281
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  param    Parameter number.
282
283
284
285
286
287
288
289

@Description
The function @func{vlistDefVarParam} defines the parameter number of a variable.

@EndFunction
*/
void vlistDefVarParam(int vlistID, int varID, int param)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
290
  RETURN_IFCLOSED_VLIST(vlistID);
291

Uwe Schulzweida's avatar
Uwe Schulzweida committed
292
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
293

294
  vlistCheckVarID(__func__, vlistID, varID);
295
296
297
298

  vlistptr->vars[varID].param = param;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
299
300
/*
@Function  vlistDefVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
301
@Title     Define the code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
302
303
304

@Prototype void vlistDefVarCode(int vlistID, int varID, int code)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
305
306
307
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  code     Code number.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
308
309

@Description
310
The function @func{vlistDefVarCode} defines the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
311
312
313
314
315

@EndFunction
*/
void vlistDefVarCode(int vlistID, int varID, int code)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
  RETURN_IFCLOSED_VLIST(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
317

Uwe Schulzweida's avatar
Uwe Schulzweida committed
318
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
319

320
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
321

Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
  int param, pnum, pcat, pdis;
323

324
325
326
  param = vlistptr->vars[varID].param;

  cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
327

328
  vlistptr->vars[varID].param = cdiEncodeParam(code, pcat, pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
329
330
331
}


332
void vlistInqVar(int vlistID, int varID, int *gridID, int *zaxisID, int *tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
333
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
335

336
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
337

338
339
340
  *gridID    = vlistptr->vars[varID].gridID;
  *zaxisID   = vlistptr->vars[varID].zaxisID;
  *tsteptype = vlistptr->vars[varID].tsteptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
341
342
343
344

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
345
346
347
348
349
350
/*
@Function  vlistInqVarGrid
@Title     Get the Grid ID of a Variable

@Prototype int vlistInqVarGrid(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
351
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
352
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
353
354
355
356
357
358
359
360
361

@Description
The function @func{vlistInqVarGrid} returns the grid ID of a variable.

@Result
@func{vlistInqVarGrid} returns the grid ID of the variable.

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
int vlistInqVarGrid(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
364
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
365

366
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
368
369
370

  return (vlistptr->vars[varID].gridID);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
371
372
373
374
375
376
/*
@Function  vlistInqVarZaxis
@Title     Get the Zaxis ID of a Variable

@Prototype int vlistInqVarZaxis(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
377
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
378
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
380
381
382
383
384
385
386
387

@Description
The function @func{vlistInqVarZaxis} returns the zaxis ID of a variable.

@Result
@func{vlistInqVarZaxis} returns the zaxis ID of the variable.

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
388
389
int vlistInqVarZaxis(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
390
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
391

392
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
393
394
395
396

  return (vlistptr->vars[varID].zaxisID);
}

397
398
399
400
401
402
/*
@Function  vlistInqVarParam
@Title     Get the parameter number of a Variable

@Prototype int vlistInqVarParam(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
403
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
404
    @Item  varID    Variable identifier.
405
406
407
408
409
410
411
412
413
414
415

@Description
The function @func{vlistInqVarParam} returns the parameter number of a variable.

@Result
@func{vlistInqVarParam} returns the parameter number of the variable.

@EndFunction
*/
int vlistInqVarParam(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
416
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
417

418
  vlistCheckVarID(__func__, vlistID, varID);
419

Uwe Schulzweida's avatar
Uwe Schulzweida committed
420
  return (vlistptr->vars[varID].param);
421
422
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
423
424
/*
@Function  vlistInqVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
@Title     Get the Code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
426
427
428

@Prototype int vlistInqVarCode(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
429
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
430
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
431
432

@Description
433
The function @func{vlistInqVarCode} returns the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
434
435

@Result
436
@func{vlistInqVarCode} returns the code number of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
437
438
439
440
441

@EndFunction
*/
int vlistInqVarCode(int vlistID, int varID)
{
442
  int param, code = -varID-1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
443
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
444
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
445

446
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
447

Uwe Schulzweida's avatar
Uwe Schulzweida committed
448
  param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
449
  cdiDecodeParam(param, &pnum, &pcat, &pdis);
450
451

  if ( pdis == 255 ) code = pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
452
453
454
455
456
457
458

  if ( code < 0 && vlistptr->vars[varID].tableID != -1 && vlistptr->vars[varID].name != NULL )
    {
      tableInqParCode(vlistptr->vars[varID].tableID, vlistptr->vars[varID].name, &code);
    }

  return (code);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
459
460
461
}


462
const char *vlistInqVarNamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
463
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
464
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
465

466
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
467
468
469
470

  return (vlistptr->vars[varID].name);
}

471

472
const char *vlistInqVarLongnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
473
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
474
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
475

476
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
477
478
479
480

  return (vlistptr->vars[varID].longname);
}

481

482
const char *vlistInqVarStdnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
483
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
484
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
485

486
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
487
488
489
490

  return (vlistptr->vars[varID].stdname);
}

491

492
const char *vlistInqVarUnitsPtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
493
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
494
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
495

496
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
497
498
499
500
501
502

  return (vlistptr->vars[varID].units);
}

/*
@Function  vlistInqVarName
Uwe Schulzweida's avatar
Uwe Schulzweida committed
503
@Title     Get the name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
504

505
@Prototype void vlistInqVarName(int vlistID, int varID, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
506
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
507
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
508
509
510
    @Item  varID    Variable identifier.
    @Item  name     Returned variable name. The caller must allocate space for the 
                    returned string. The maximum possible length, in characters, of
511
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
512
513

@Description
514
The function @func{vlistInqVarName} returns the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
515
516

@Result
517
518
@func{vlistInqVarName} returns the name of the variable to the parameter name if available,
otherwise the result is an empty string.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
519
520
521
522
523

@EndFunction
*/
void vlistInqVarName(int vlistID, int varID, char *name)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
524
  int tableID;
525
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
526
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
527
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
528

529
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
530
531
532

  if ( vlistptr->vars[varID].name == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
533
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
534
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
535
536
537
538
539
540
541
542
543
544
545
      if ( pdis == 255 )
	{
	  int code = pnum;
	  tableID = vlistptr->vars[varID].tableID;
	  if ( tableInqParName(tableID, code, name) != 0 )
	    sprintf(name, "var%d", code);
	}
      else
	{
	  sprintf(name, "param%d.%d.%d", pnum, pcat, pdis);
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
546
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
547
548
549
550
551
552
553
554
  else
    strcpy(name, vlistptr->vars[varID].name);

  return;
}

/*
@Function  vlistInqVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
555
@Title     Get the longname of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
556
557
558

@Prototype void vlistInqVarLongname(int vlistID, int varID, char *longname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
559
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
560
561
562
    @Item  varID    Variable identifier.
    @Item  longname Long name of the variable. The caller must allocate space for the 
                    returned string. The maximum possible length, in characters, of
563
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
564
565

@Description
566
567
The function @func{vlistInqVarLongname} returns the longname of a variable if available,
otherwise the result is an empty string.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
568
569

@Result
570
@func{vlistInqVaeLongname} returns the longname of the variable to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
571
572
573
574
575

@EndFunction
*/
void vlistInqVarLongname(int vlistID, int varID, char *longname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
576
  int tableID;
577
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
578
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580

581
582
583
  vlistCheckVarID(__func__, vlistID, varID);

  longname[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
584
585
586

  if ( vlistptr->vars[varID].longname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
587
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
588
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
589
590
591
592
593
594
595
      if ( pdis == 255 )
	{
	  int code = pnum;
	  tableID = vlistptr->vars[varID].tableID;
	  if ( tableInqParLongname(tableID, code, longname) != 0 )
	    longname[0] = '\0';
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
596
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
597
598
599
600
601
602
  else
    strcpy(longname, vlistptr->vars[varID].longname);

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
603
604
605
606
607
608
/*
@Function  vlistInqVarStdname
@Title     Get the standard name of a Variable

@Prototype void vlistInqVarStdname(int vlistID, int varID, char *stdname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
609
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
610
611
612
    @Item  varID    Variable identifier.
    @Item  stdname  Standard name of the variable. The caller must allocate space for the 
                    returned string. The maximum possible length, in characters, of
613
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
614
615

@Description
616
617
The function @func{vlistInqVarStdname} returns the standard name of a variable if available,
otherwise the result is an empty string.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
618
619
620
621
622
623

@Result
@func{vlistInqVarName} returns the standard name of the variable to the parameter stdname.

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
624
625
void vlistInqVarStdname(int vlistID, int varID, char *stdname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
626
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
627

628
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
629
630
631

  if ( vlistptr->vars[varID].stdname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
632
      stdname[0] = '\0';
633
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
634
635
636
637
638
639
640
641
  else
    strcpy(stdname, vlistptr->vars[varID].stdname);

  return;
}

/*
@Function  vlistInqVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
642
@Title     Get the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
643
644
645

@Prototype void vlistInqVarUnits(int vlistID, int varID, char *units)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
646
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
647
    @Item  varID    Variable identifier.
648
    @Item  units    Units of the variable. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
649
                    returned string. The maximum possible length, in characters, of
650
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
651
652

@Description
653
654
The function @func{vlistInqVarUnits} returns the units of a variable if available,
otherwise the result is an empty string.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
655
656

@Result
657
@func{vlistInqVarUnits} returns the units of the variable to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
658
659
660
661
662

@EndFunction
*/
void vlistInqVarUnits(int vlistID, int varID, char *units)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
663
  int tableID;
664
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
665
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
666
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
667

668
669
670
  vlistCheckVarID(__func__, vlistID, varID);

  units[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
671
672
673

  if ( vlistptr->vars[varID].units == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
674
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
675
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
676
677
678
679
680
681
682
      if ( pdis == 255 )
	{
	  int code = pnum;
	  tableID = vlistptr->vars[varID].tableID;
	  if ( tableInqParUnits(tableID, code, units) != 0 )
	    units[0] = '\0';
	}
683
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
684
685
686
687
688
689
  else
    strcpy(units, vlistptr->vars[varID].units);

  return;
}

690
/* used in MPIOM ! */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
691
int vlistInqVarID(int vlistID, int code)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
692
693
{
  int varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
694
  int param, pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
695
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
696
697

  for ( varID = 0; varID < vlistptr->nvars; varID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
698
699
    {
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
700
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
701
      if ( pnum == code ) return (varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
702
703
    }

704
  return (CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
705
}
706

Uwe Schulzweida's avatar
Uwe Schulzweida committed
707

Uwe Schulzweida's avatar
Uwe Schulzweida committed
708
709
710
711
712
int vlistInqVarSize(int vlistID, int varID)
{
  int size;
  int zaxisID, gridID;
  int nlevs, gridsize;
713
  int tsteptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
714

715
  vlistCheckVarID(__func__, vlistID, varID);
716
717
718

  vlistInqVar(vlistID, varID, &gridID, &zaxisID, &tsteptype);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
719
  nlevs = zaxisInqSize(zaxisID);
720

Uwe Schulzweida's avatar
Uwe Schulzweida committed
721
  gridsize = gridInqSize(gridID);
722

Uwe Schulzweida's avatar
Uwe Schulzweida committed
723
724
725
726
727
728
729
  size = gridsize*nlevs;

  return (size);
}

/*
@Function  vlistInqVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
730
@Title     Get the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
731
732
733

@Prototype int vlistInqVarDatatype(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
734
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
735
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
736
737

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
738
The function @func{vlistInqVarDatatype} returns the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
739
740

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
741
@func{vlistInqVarDatatype} returns an identifier to the data type of the variable.
742
The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16}, @func{DATATYPE_PACK24},
743
744
@func{DATATYPE_FLT32}, @func{DATATYPE_FLT64}, @func{DATATYPE_INT8}, @func{DATATYPE_INT16} and 
@func{DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
745
746
747
748
749

@EndFunction
*/
int vlistInqVarDatatype(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
750
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
751

752
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
754
755
756
757

  return (vlistptr->vars[varID].datatype);
}


758
759
760
int vlistInqVarNumber(int vlistID, int varID)
{
  int number = CDI_REAL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
761
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
762

763
  vlistCheckVarID(__func__, vlistID, varID);
764

765
766
  if ( vlistptr->vars[varID].datatype == DATATYPE_CPX32 ||
       vlistptr->vars[varID].datatype == DATATYPE_CPX64 )
767
768
769
770
771
    number = CDI_COMP;

  return (number);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
772
773
/*
@Function  vlistDefVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
774
@Title     Define the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
775
776
777

@Prototype void vlistDefVarDatatype(int vlistID, int varID, int datatype)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
778
779
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
780
    @Item  datatype The data type identifier.
781
                    The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16},
782
783
                    @func{DATATYPE_PACK24}, @func{DATATYPE_FLT32}, @func{DATATYPE_FLT64},
                    @func{DATATYPE_INT8}, @func{DATATYPE_INT16} and @func{DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
784
785

@Description
786
The function @func{vlistDefVarDatatype} defines the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
787
788
789
790
791

@EndFunction
*/
void vlistDefVarDatatype(int vlistID, int varID, int datatype)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
792
  RETURN_IFCLOSED_VLIST(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
793

Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
795

796
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
797

798
  vlistptr->vars[varID].datatype = datatype;
799

800
  if ( vlistptr->vars[varID].missvalused == FALSE )
801
802
    switch (datatype)
      {
803
804
805
806
807
808
      case DATATYPE_INT8:   vlistptr->vars[varID].missval = -SCHAR_MAX; break;
      case DATATYPE_UINT8:  vlistptr->vars[varID].missval =  UCHAR_MAX; break;
      case DATATYPE_INT16:  vlistptr->vars[varID].missval = -SHRT_MAX;  break;
      case DATATYPE_UINT16: vlistptr->vars[varID].missval =  USHRT_MAX; break;
      case DATATYPE_INT32:  vlistptr->vars[varID].missval = -INT_MAX;   break;
      case DATATYPE_UINT32: vlistptr->vars[varID].missval =  UINT_MAX;  break;
809
      }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
810
811
}

812

Uwe Schulzweida's avatar
Uwe Schulzweida committed
813
814
void vlistDefVarInstitut(int vlistID, int varID, int instID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
815
  RETURN_IFCLOSED_VLIST(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816

Uwe Schulzweida's avatar
Uwe Schulzweida committed
817
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
818

Uwe Schulzweida's avatar
Uwe Schulzweida committed
819
820
821
  vlistptr->vars[varID].instID = instID;
}

822

Uwe Schulzweida's avatar
Uwe Schulzweida committed
823
824
int vlistInqVarInstitut(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
825
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
826
827
828
829

  return (vlistptr->vars[varID].instID);
}

830

Uwe Schulzweida's avatar
Uwe Schulzweida committed
831
832
void vlistDefVarModel(int vlistID, int varID, int modelID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
833
  RETURN_IFCLOSED_VLIST(vlistID);
834

Uwe Schulzweida's avatar
Uwe Schulzweida committed
835
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
836
837
838
839

  vlistptr->vars[varID].modelID = modelID;
}

840

Uwe Schulzweida's avatar
Uwe Schulzweida committed
841
842
int vlistInqVarModel(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
843
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
844
845
846
847

  return (vlistptr->vars[varID].modelID);
}

848

Uwe Schulzweida's avatar
Uwe Schulzweida committed
849
850
void vlistDefVarTable(int vlistID, int varID, int tableID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
851
  RETURN_IFCLOSED_VLIST(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
852

Uwe Schulzweida's avatar
Uwe Schulzweida committed
853
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
854
855

  vlistptr->vars[varID].tableID = tableID;
856
857
858
859
860
861
862
863
864

  {
    int param, pnum, pcat, pdis;
    int tablenum;
    tablenum = tableInqNum(tableID);

    param = vlistptr->vars[varID].param;

    cdiDecodeParam(param, &pnum, &pcat, &pdis);
865

866
867
    vlistptr->vars[varID].param = cdiEncodeParam(pnum, tablenum, pdis);
  }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
868
869
}

870

Uwe Schulzweida's avatar
Uwe Schulzweida committed
871
872
int vlistInqVarTable(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
873
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
874

Uwe Schulzweida's avatar
Uwe Schulzweida committed
875
  return (vlistptr->vars[varID].tableID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
876
877
878
879
}

/*
@Function  vlistDefVarName
Uwe Schulzweida's avatar
Uwe Schulzweida committed
880
@Title     Define the name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
881
882
883

@Prototype void vlistDefVarName(int vlistID, int varID, const char *name)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
884
885
886
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  name     Name of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
887
888

@Description
889
The function @func{vlistDefVarName} defines the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
890
891
892
893
894

@EndFunction
*/
void vlistDefVarName(int vlistID, int varID, const char *name)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
895
  RETURN_IFCLOSED_VLIST(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
896

Uwe Schulzweida's avatar
Uwe Schulzweida committed
897
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
898

899
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
900

901
  if ( name )
902
    {
903
904
905
906
907
      if ( vlistptr->vars[varID].name )
	{
	  free(vlistptr->vars[varID].name);
	  vlistptr->vars[varID].name = NULL;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
908

909
910
      vlistptr->vars[varID].name = strdupx(name);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
911
912
913
914
}

/*
@Function  vlistDefVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
915
@Title     Define the long name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
916
917
918

@Prototype void vlistDefVarLongname(int vlistID, int varID, const char *longname)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
919
920
921
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  longname Long name of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
922
923

@Description
924
The function @func{vlistDefVarLongname} defines the long name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
925
926
927
928
929

@EndFunction
*/
void vlistDefVarLongname(int vlistID, int varID, const char *longname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
930
  RETURN_IFCLOSED_VLIST(vlistID);
931

Uwe Schulzweida's avatar
Uwe Schulzweida committed
932
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
933

934
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
935

936
  if ( longname )
937
    {
938
939
940
941
942
      if ( vlistptr->vars[varID].longname )
	{
	  free(vlistptr->vars[varID].longname);
	  vlistptr->vars[varID].longname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
943

944
945
      vlistptr->vars[varID].longname = strdupx(longname);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
946
947
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
948
949
950
951
952
953
/*
@Function  vlistDefVarStdname
@Title     Define the standard name of a Variable

@Prototype void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
954
955
956
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  stdname  Standard name of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
957
958
959
960
961
962

@Description
The function @func{vlistDefVarStdname} defines the standard name of a variable.

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
963
964
void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
965
  RETURN_IFCLOSED_VLIST(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
966

Uwe Schulzweida's avatar
Uwe Schulzweida committed
967
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
968

969
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
970

971
  if ( stdname )
972
    {
973
974
975
976
977
      if ( vlistptr->vars[varID].stdname )
	{
	  free(vlistptr->vars[varID].stdname);
	  vlistptr->vars[varID].stdname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
978

979
980
      vlistptr->vars[varID].stdname = strdupx(stdname);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
981
982
983
984
}

/*
@Function  vlistDefVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
985
@Title     Define the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
986
987
988

@Prototype void vlistDefVarUnits(int vlistID, int varID, const char *units)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
989
990
991
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  units    Units of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
992
993

@Description
994
The function @func{vlistDefVarUnits} defines the units of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
995
996
997
998
999

@EndFunction
*/
void vlistDefVarUnits(int vlistID, int varID, const char *units)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1000
  RETURN_IFCLOSED_VLIST(vlistID);
1001

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1002
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1003

1004
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1005

1006
  if ( units )
1007
    {
1008
1009
1010
1011
1012
      if ( vlistptr->vars[varID].units )
	{
	  free(vlistptr->vars[varID].units);
	  vlistptr->vars[varID].units = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1013

1014
1015
      vlistptr->vars[varID].units = strdupx(units);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1016
1017
1018
1019
}

/*
@Function  vlistInqVarMissval
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1020
@Title     Get the missing value of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1021
1022
1023

@Prototype double vlistInqVarMissval(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1024
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
1025
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1026
1027

@Description
1028
The function @func{vlistInqVarMissval} returns the missing value of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1029
1030

@Result
1031
@func{vlistInqVarMissval} returns the missing value of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1032
1033
1034
1035
1036

@EndFunction
*/
double vlistInqVarMissval(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1037
  vlist_t *vlistptr = vlist_to_pointer(vlistID);