vlist_var.c 37.2 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
9
10
11
12
#include "dmemory.h"
#include "cdi.h"
#include "stream_int.h"
#include "vlist.h"


13
14
static
void vlistvarInitEntry(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
{
16
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
17
18
19

  vlistptr = vlist_to_pointer(vlistID);

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  vlistptr->vars[varID].fvarID        = varID;
  vlistptr->vars[varID].mvarID        = varID;
  vlistptr->vars[varID].flag          = 0;
  vlistptr->vars[varID].param         = 0;
  vlistptr->vars[varID].timeID        = CDI_UNDEFID;
  vlistptr->vars[varID].datatype      = CDI_UNDEFID;
  vlistptr->vars[varID].tsteptype     = TSTEP_INSTANT;
  vlistptr->vars[varID].timave        = 0;
  vlistptr->vars[varID].timaccu       = 0;
  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;
  vlistptr->vars[varID].nlevs         = 0;
  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;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
52
53
}

54
55
static
int vlistvarNewEntry(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
56
57
58
{
  int varID = 0;
  int vlistvarSize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
59
  var_t *vlistvar;
60
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74

  vlistptr = vlist_to_pointer(vlistID);

  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
75
      vlistvar = (var_t *) malloc(vlistvarSize*sizeof(var_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
77
      if ( vlistvar == NULL )
	{
78
79
          Message("vlistvarSize = %d", vlistvarSize);
	  SysError("Allocation of var_t failed");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	}

      for ( i = 0; i < vlistvarSize; i++ )
	vlistvar[i].isUsed = FALSE;
    }
  else
    {
      while ( varID < vlistvarSize )
	{
	  if ( ! vlistvar[varID].isUsed ) break;
	  varID++;
	}
    }
  /*
    If the table overflows, double its size.
  */
  if ( varID == vlistvarSize )
    {
      int i;

      vlistvarSize = 2*vlistvarSize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
      vlistvar = (var_t *) realloc(vlistvar, vlistvarSize*sizeof(var_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102
103
      if ( vlistvar == NULL )
	{
104
105
          Message("vlistvarSize = %d", vlistvarSize);
	  SysError("Reallocation of var_t failed");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	}
      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);
}

123
124
static
void vlistCheckVarID(const char *caller, int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
125
{
126
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128
129
130

  vlistptr = vlist_to_pointer(vlistID);

  if ( vlistptr == NULL )
131
    Errorc("vlist undefined!");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
133

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

  if ( ! vlistptr->vars[varID].isUsed )
137
    Errorc("varID %d undefined!", varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
139
140
141
}

/*
@Function  vlistDefVar
Uwe Schulzweida's avatar
Uwe Schulzweida committed
142
@Title     Define a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
144
145

@Prototype int vlistDefVar(int vlistID, int gridID, int zaxisID, int timeID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
146
147
148
    @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}.
149
    @Item  timeID   One of the set of predefined CDI time identifiers.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
150
                    The valid CDI time identifiers are @func{TIME_CONSTANT} and @func{TIME_VARIABLE}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152

@Description
153
The function @func{vlistDefVar} adds a new variable to vlistID.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154
155

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@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();
varID = vlistDefVar(vlistID, gridID, zaxisID, TIME_VARIABLE);
   ...
streamDefVlist(streamID, vlistID);
   ...
vlistDestroy(vlistID);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
175
176
177
178
179
180
181
182
@EndFunction
*/
int vlistDefVar(int vlistID, int gridID, int zaxisID, int timeID)
{
  int varID;
  int nlevs;
  int levID;
  int index;
183
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
184
185
186
187

  vlistptr = vlist_to_pointer(vlistID);

  if ( CDI_Debug )
188
    Message("gridID = %d  zaxisID = %d  timeID = %d", gridID, zaxisID, timeID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
191
192
193
194
195
196
197
198
199

  varID = vlistvarNewEntry(vlistID);

  vlistptr->nvars++;

  vlistptr->vars[varID].gridID  = gridID;
  vlistptr->vars[varID].zaxisID = zaxisID;
  vlistptr->vars[varID].timeID  = timeID;

  if ( timeID != TIME_VARIABLE && timeID != TIME_CONSTANT )
    {
200
      Message("unexpected timeID %d. Set to TIME_VARIABLE", timeID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
201
202
203
204
205
      vlistptr->vars[varID].timeID = TIME_VARIABLE;	  
    }

  nlevs = zaxisInqSize(zaxisID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
206
  vlistptr->vars[varID].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
208
209
210
211
212

  for ( levID = 0; levID < nlevs; levID++ )
    {
      vlistptr->vars[varID].levinfo[levID].flag     = 0;
      vlistptr->vars[varID].levinfo[levID].index    = -1;
      vlistptr->vars[varID].levinfo[levID].flevelID = levID;
213
      vlistptr->vars[varID].levinfo[levID].mlevelID = levID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
214
215
216
217
218
219
220
221
222
    }

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

  for ( index = 0; index < vlistptr->ngrids; index++ )
    if ( gridID == vlistptr->gridIDs[index] ) break;

  if ( index == vlistptr->ngrids )
    {
223
      if ( vlistptr->ngrids + 1 >= MAX_GRIDS_PS )
224
	Error("Maximum of %d grids reached", MAX_GRIDS_PS);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
225
226
227
228
229
230
231
232
233
234

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

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

  if ( index == vlistptr->nzaxis )
    {
235
      if ( vlistptr->nzaxis + 1 >= MAX_ZAXES_PS )
236
	Error("Maximum of %d zaxis reached", MAX_ZAXES_PS);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
238
239
240
241

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

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

  return (varID);
}

247
248
249
250
251
252
/*
@Function  vlistDefVarParam
@Title     Define the parameter number of a Variable

@Prototype void vlistDefVarParam(int vlistID, int varID, int param)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
254
255
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  param    Parameter number.
256
257
258
259
260
261
262
263
264
265
266
267

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

@EndFunction
*/
void vlistDefVarParam(int vlistID, int varID, int param)
{
  vlist_t *vlistptr;

  vlistptr = vlist_to_pointer(vlistID);

268
  vlistCheckVarID(__func__, vlistID, varID);
269
270
271
272

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
274
/*
@Function  vlistDefVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
275
@Title     Define the code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
276
277
278

@Prototype void vlistDefVarCode(int vlistID, int varID, int code)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
279
280
281
    @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
282
283

@Description
284
The function @func{vlistDefVarCode} defines the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
286
287
288
289

@EndFunction
*/
void vlistDefVarCode(int vlistID, int varID, int code)
{
290
  vlist_t *vlistptr;
291
  int param, pnum, pcat, pdis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
292
293
294

  vlistptr = vlist_to_pointer(vlistID);

295
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
296

297
298
299
300
301
  param = vlistptr->vars[varID].param;

  cdiDecodeParam(param, &pnum, &pcat, &pdis);
  
  vlistptr->vars[varID].param = cdiEncodeParam(code, pcat, pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
302
303
304
305
306
}


void vlistInqVar(int vlistID, int varID, int *gridID, int *zaxisID, int *timeID)
{
307
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
308
309
310

  vlistptr = vlist_to_pointer(vlistID);

311
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
312
313
314
315
316
317
318
319

  *gridID  = vlistptr->vars[varID].gridID;
  *zaxisID = vlistptr->vars[varID].zaxisID;
  *timeID  = vlistptr->vars[varID].timeID;

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
320
321
322
323
324
325
/*
@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
326
327
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
328
329
330
331
332
333
334
335
336

@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
337
338
int vlistInqVarGrid(int vlistID, int varID)
{
339
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
340
341
342

  vlistptr = vlist_to_pointer(vlistID);

343
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
344
345
346
347

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
349
350
351
352
353
/*
@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
354
355
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
356
357
358
359
360
361
362
363
364

@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
365
366
int vlistInqVarZaxis(int vlistID, int varID)
{
367
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
369
370

  vlistptr = vlist_to_pointer(vlistID);

371
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
372
373
374
375

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
376

Uwe Schulzweida's avatar
Uwe Schulzweida committed
377
378
int vlistInqVarTime(int vlistID, int varID)
{
379
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
380
381
382

  vlistptr = vlist_to_pointer(vlistID);

383
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
384
385
386
387

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

388
389
390
391
392
393
/*
@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
394
395
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

@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)
{
  vlist_t *vlistptr;
  int param;

  vlistptr = vlist_to_pointer(vlistID);

412
  vlistCheckVarID(__func__, vlistID, varID);
413
414
415
416
417
418

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

  return (param);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
419
420
/*
@Function  vlistInqVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
421
@Title     Get the Code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
423
424

@Prototype int vlistInqVarCode(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
426
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
427
428

@Description
429
The function @func{vlistInqVarCode} returns the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
430
431

@Result
432
@func{vlistInqVarCode} returns the code number of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
433
434
435
436
437

@EndFunction
*/
int vlistInqVarCode(int vlistID, int varID)
{
438
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
439
440
  int param, code;
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
441
442
443

  vlistptr = vlist_to_pointer(vlistID);

444
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
445

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

  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
456
457
458
}


459
const char *vlistInqVarNamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
460
{
461
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
462
463
464

  vlistptr = vlist_to_pointer(vlistID);

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

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

470

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

  vlistptr = vlist_to_pointer(vlistID);

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

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

482

483
const char *vlistInqVarStdnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
484
{
485
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
486
487
488

  vlistptr = vlist_to_pointer(vlistID);

489
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
490
491
492
493

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

494

495
const char *vlistInqVarUnitsPtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
496
{
497
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
498
499
500

  vlistptr = vlist_to_pointer(vlistID);

501
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
502
503
504
505
506
507

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

/*
@Function  vlistInqVarName
Uwe Schulzweida's avatar
Uwe Schulzweida committed
508
@Title     Get the name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
509
510
511

@Prototype void vlistInqVarName(int vlistID, int varID, char *name)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
512
513
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
514
    @Item  name     Returned variable name. The caller must allocate space for the 
Uwe Schulzweida's avatar
Uwe Schulzweida committed
515
516
                    returned string. The maximum possible length, in characters, of
                    the string is given by the predefined constant CDI_MAX_NAME.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
517
518

@Description
519
The function @func{vlistInqVarName} returns the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
521

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
522
523
@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
524
525
526
527
528

@EndFunction
*/
void vlistInqVarName(int vlistID, int varID, char *name)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
529
  int tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
530
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
531
  int pdis, pcat, pnum;
532
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
533
534
535

  vlistptr = vlist_to_pointer(vlistID);

536
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
537
538
539

  if ( vlistptr->vars[varID].name == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
540
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
541
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
542
543
544
545
546
547
548
549
550
551
552
      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
553
554
555
556
557
558
559
560
561
    }  
  else
    strcpy(name, vlistptr->vars[varID].name);

  return;
}

/*
@Function  vlistInqVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
562
@Title     Get the longname of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
563
564
565

@Prototype void vlistInqVarLongname(int vlistID, int varID, char *longname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
566
567
568
569
570
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @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
                    the string is given by the predefined constant CDI_MAX_NAME.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
571
572

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
573
574
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
575
576

@Result
577
@func{vlistInqVaeLongname} returns the longname of the variable to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
578
579
580
581
582

@EndFunction
*/
void vlistInqVarLongname(int vlistID, int varID, char *longname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
583
  int tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
584
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
585
  int pdis, pcat, pnum;
586
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
587
588
589

  vlistptr = vlist_to_pointer(vlistID);

590
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
591

Uwe Schulzweida's avatar
Uwe Schulzweida committed
592
593
  longname[0] = '\0';

Uwe Schulzweida's avatar
Uwe Schulzweida committed
594
595
  if ( vlistptr->vars[varID].longname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
596
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
597
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
598
599
600
601
602
603
604
      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
605
606
607
608
609
610
611
    }  
  else
    strcpy(longname, vlistptr->vars[varID].longname);

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
612
613
614
615
616
617
/*
@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
618
619
620
621
622
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @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
                    the string is given by the predefined constant CDI_MAX_NAME.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
624

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
625
626
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
627
628
629
630
631
632

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

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
633
634
void vlistInqVarStdname(int vlistID, int varID, char *stdname)
{
635
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
637
638

  vlistptr = vlist_to_pointer(vlistID);

639
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
640
641
642

  if ( vlistptr->vars[varID].stdname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
643
      stdname[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
644
645
646
647
648
649
650
651
652
    }  
  else
    strcpy(stdname, vlistptr->vars[varID].stdname);

  return;
}

/*
@Function  vlistInqVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
653
@Title     Get the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
654
655
656

@Prototype void vlistInqVarUnits(int vlistID, int varID, char *units)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
657
658
659
660
661
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  units    Units of the variable. The caller must allocate space for the 
                    returned string. The maximum possible length, in characters, of
                    the string is given by the predefined constant CDI_MAX_NAME.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
663

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
664
665
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
666
667

@Result
668
@func{vlistInqVarUnits} returns the units of the variable to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
669
670
671
672
673

@EndFunction
*/
void vlistInqVarUnits(int vlistID, int varID, char *units)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
674
  int tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
675
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
676
  int pdis, pcat, pnum;
677
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
678
679
680

  vlistptr = vlist_to_pointer(vlistID);

681
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
682

Uwe Schulzweida's avatar
Uwe Schulzweida committed
683
684
  units[0] = '\0';

Uwe Schulzweida's avatar
Uwe Schulzweida committed
685
686
  if ( vlistptr->vars[varID].units == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
687
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
688
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
689
690
691
692
693
694
695
      if ( pdis == 255 )
	{
	  int code = pnum;
	  tableID = vlistptr->vars[varID].tableID;
	  if ( tableInqParUnits(tableID, code, units) != 0 )
	    units[0] = '\0';
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
696
697
698
699
700
701
702
    }  
  else
    strcpy(units, vlistptr->vars[varID].units);

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
703
/* not used 
Uwe Schulzweida's avatar
Uwe Schulzweida committed
704
int vlistInqVarID(int vlistID, int code)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
705
706
{
  int varID;
707
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
708
  int param, pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709
710
711
712

  vlistptr = vlist_to_pointer(vlistID);

  for ( varID = 0; varID < vlistptr->nvars; varID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
713
714
    {
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
715
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
716
717
      if ( pnum == code ) break;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
718
719
720
721
722
723
724
725

  if ( varID == vlistptr->nvars )
    {
      varID = CDI_UNDEFID;
    }

  return (varID);
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
726
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
727

Uwe Schulzweida's avatar
Uwe Schulzweida committed
728
729
730
731
732
733
int vlistInqVarSize(int vlistID, int varID)
{
  int size;
  int zaxisID, gridID;
  int nlevs, gridsize;
  int timeID;
734
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
735
736
737

  vlistptr = vlist_to_pointer(vlistID);

738
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
739
740
741
742
743
744
745
746
747
748
749
750
751
752

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

  nlevs = zaxisInqSize(zaxisID);

  gridsize = gridInqSize(gridID);

  size = gridsize*nlevs;

  return (size);
}

/*
@Function  vlistInqVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
@Title     Get the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
754
755
756

@Prototype int vlistInqVarDatatype(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
757
758
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
759
760

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
761
The function @func{vlistInqVarDatatype} returns the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
762
763

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
764
@func{vlistInqVarDatatype} returns an identifier to the data type of the variable.
765
The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16}, @func{DATATYPE_PACK24},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
766
767
@func{DATATYPE_FLT32}, @func{DATATYPE_FLT64}, @func{DATATYPE_INT8}, @func{DATATYPE_INT16} and 
@func{DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
768
769
770
771
772

@EndFunction
*/
int vlistInqVarDatatype(int vlistID, int varID)
{
773
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
774
775
776

  vlistptr = vlist_to_pointer(vlistID);

777
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
778
779
780
781
782

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


783
784
785
786
787
788
789
int vlistInqVarNumber(int vlistID, int varID)
{
  vlist_t *vlistptr;
  int number = CDI_REAL;

  vlistptr = vlist_to_pointer(vlistID);

790
  vlistCheckVarID(__func__, vlistID, varID);
791

Uwe Schulzweida's avatar
Uwe Schulzweida committed
792
793
  if ( vlistptr->vars[varID].datatype == DATATYPE_CPX32 ||
       vlistptr->vars[varID].datatype == DATATYPE_CPX64 )
794
795
796
797
798
    number = CDI_COMP;

  return (number);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
799
800
/*
@Function  vlistDefVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
801
@Title     Define the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
802
803
804

@Prototype void vlistDefVarDatatype(int vlistID, int varID, int datatype)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
805
806
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
    @Item  datatype The data type identifier.
808
                    The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
809
810
                    @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
811
812

@Description
813
The function @func{vlistDefVarDatatype} defines the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
814
815
816
817
818

@EndFunction
*/
void vlistDefVarDatatype(int vlistID, int varID, int datatype)
{
819
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
820
821
822

  vlistptr = vlist_to_pointer(vlistID);

823
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
824

825
826
827
  vlistptr->vars[varID].datatype = datatype;
  
  if ( vlistptr->vars[varID].missvalused == FALSE )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
828
829
830
831
832
833
834
835
836
    switch (datatype)
      {
      case DATATYPE_INT8:   vlistptr->vars[varID].missval = SCHAR_MIN; break;
      case DATATYPE_UINT8:  vlistptr->vars[varID].missval = UCHAR_MAX; break;
      case DATATYPE_INT16:  vlistptr->vars[varID].missval = SHRT_MIN;  break;
      case DATATYPE_UINT16: vlistptr->vars[varID].missval = USHRT_MAX; break;
      case DATATYPE_INT32:  vlistptr->vars[varID].missval = INT_MIN;   break;
      case DATATYPE_UINT32: vlistptr->vars[varID].missval = UINT_MAX;  break;
      }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
837
838
}

839

Uwe Schulzweida's avatar
Uwe Schulzweida committed
840
841
void vlistDefVarInstitut(int vlistID, int varID, int instID)
{
842
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
843
844
845
846
847
848

  vlistptr = vlist_to_pointer(vlistID);

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

849

Uwe Schulzweida's avatar
Uwe Schulzweida committed
850
851
int vlistInqVarInstitut(int vlistID, int varID)
{
852
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
853
854
855
856
857
858

  vlistptr = vlist_to_pointer(vlistID);

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

859

Uwe Schulzweida's avatar
Uwe Schulzweida committed
860
861
void vlistDefVarModel(int vlistID, int varID, int modelID)
{
862
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
863
864
865
866
867
868

  vlistptr = vlist_to_pointer(vlistID);

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

869

Uwe Schulzweida's avatar
Uwe Schulzweida committed
870
871
int vlistInqVarModel(int vlistID, int varID)
{
872
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
873
874
875
876
877
878

  vlistptr = vlist_to_pointer(vlistID);

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

879

Uwe Schulzweida's avatar
Uwe Schulzweida committed
880
881
void vlistDefVarTable(int vlistID, int varID, int tableID)
{
882
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
883
884
885
886

  vlistptr = vlist_to_pointer(vlistID);

  vlistptr->vars[varID].tableID = tableID;
887
888
889
890
891
892
893
894
895
896
897
898

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

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

    cdiDecodeParam(param, &pnum, &pcat, &pdis);
  
    vlistptr->vars[varID].param = cdiEncodeParam(pnum, tablenum, pdis);
  }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
899
900
}

901

Uwe Schulzweida's avatar
Uwe Schulzweida committed
902
903
904
int vlistInqVarTable(int vlistID, int varID)
{
  int tableID;
905
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
906
907
908
909
910
911
912
913
914
915

  vlistptr = vlist_to_pointer(vlistID);

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

  return (tableID);
}

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

@Prototype void vlistDefVarName(int vlistID, int varID, const char *name)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
920
921
922
    @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
923
924

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

@EndFunction
*/
void vlistDefVarName(int vlistID, int varID, const char *name)
{
931
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
932
933
934

  vlistptr = vlist_to_pointer(vlistID);

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

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

945
946
      vlistptr->vars[varID].name = strdupx(name);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
947
948
949
950
}

/*
@Function  vlistDefVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
951
@Title     Define the long name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
952
953
954

@Prototype void vlistDefVarLongname(int vlistID, int varID, const char *longname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
955
956
957
    @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
958
959

@Description
960
The function @func{vlistDefVarLongname} defines the long name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
961
962
963
964
965

@EndFunction
*/
void vlistDefVarLongname(int vlistID, int varID, const char *longname)
{
966
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
967
968
969

  vlistptr = vlist_to_pointer(vlistID);

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

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
984
985
986
987
988
989
/*
@Function  vlistDefVarStdname
@Title     Define the standard name of a Variable

@Prototype void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
990
991
992
    @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
993
994
995
996
997
998

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

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
999
1000
void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
{
1001
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1002
1003
1004

  vlistptr = vlist_to_pointer(vlistID);

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

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

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

/*
@Function  vlistDefVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1021
@Title     Define the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1022
1023
1024

@Prototype void vlistDefVarUnits(int vlistID, int varID, const char *units)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1025
1026
1027
    @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
1028
1029

@Description
1030
The function @func{vlistDefVarUnits} defines the units of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1031
1032
1033
1034
1035

@EndFunction
*/
void vlistDefVarUnits(int vlistID, int varID, const char *units)
{
1036
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1037
1038
1039

  vlistptr = vlist_to_pointer(vlistID);

1040
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1041

1042
  if ( units )
1043
    {
1044
1045
1046
1047
1048
      if ( vlistptr->vars[varID].units )
	{
	  free(vlistptr->vars[varID].units);
	  vlistptr->vars[varID].units = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1049

1050
1051
      vlistptr->vars[varID].units = strdupx(units);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1052
1053
1054
1055
}

/*
@Function  vlistInqVarMissval
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1056
@Title     Get the missing value of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1057
1058
1059

@Prototype double vlistInqVarMissval(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1060
1061
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1062
1063

@Description
1064
The function @func{vlistInqVarMissval} returns the missing value of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1065
1066

@Result
1067
@func{vlistInqVarMissval} returns the missing value of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1068
1069
1070
1071
1072

@EndFunction
*/
double vlistInqVarMissval(int vlistID, int varID)
{
1073
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1074
1075
1076

  vlistptr = vlist_to_pointer(vlistID);

1077
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1078
1079
1080
1081

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

1082
1083
1084
/*
@Function  vlistDefVarMissval
@Title     Define the missing value of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1085

1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
@Prototype void vlistDefVarMissval(int vlistID, int varID, double missval)
@Parameter
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  missval  Missing value.

@Description
The function @func{vlistDefVarMissval} defines the missing value of a variable.

@EndFunction
*/
void vlistDefVarMissval(int vlistID, int varID, double missval)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1098
{
1099
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1100
1101
1102

  vlistptr = vlist_to_pointer(vlistID);

1103
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1104

1105
1106
  vlistptr->vars[varID].missval = missval;
  vlistptr->vars[varID].missvalused = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1107
1108
}

1109

1110
int vlistInqVarValidrange(int vlistID, int varID, double *validrange)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1111
{
1112
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1113
1114
1115

  vlistptr = vlist_to_pointer(vlistID);

1116
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1117

1118
1119
1120
1121
1122
1123
1124
  if ( validrange != NULL && vlistptr->vars[varID].lvalidrange )
    {
      validrange[0] = vlistptr->vars[varID].validrange[0];
      validrange[1] = vlistptr->vars[varID].validrange[1];
    }

  return (vlistptr->vars[varID].lvalidrange);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1125
1126
1127
}


1128
1129
1130
void vlistDefVarValidrange(int vlistID, int varID, const double *validrange)
{
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1131

1132
  vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1133

1134
1135
1136
1137
1138
1139
1140
1141
1142
  vlistCheckVarID(__func__, vlistID, varID);

  vlistptr->vars[varID].validrange[0] = validrange[0];
  vlistptr->vars[varID].validrange[1] = validrange[1];
  vlistptr->vars[varID].lvalidrange = TRUE;
}


double vlistInqVarScalefactor(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1143
{
1144
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1145
1146
1147

  vlistptr = vlist_to_pointer(vlistID);

1148
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1149

1150
  return (vlistptr->vars[varID].scalefactor);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1151
1152
}

1153

1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
double vlistInqVarAddoffset(int vlistID, int varID)
{
  vlist_t *vlistptr;

  vlistptr = vlist_to_pointer(vlistID);

  vlistCheckVarID(__func__, vlistID, varID);

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1165
1166
void vlistDefVarScalefactor(int vlistID, int varID, double scalefactor)
{
1167
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1168
1169
1170

  vlistptr = vlist_to_pointer(vlistID);

1171
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1172
1173
1174
1175

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

1176

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1177
1178
void vlistDefVarAddoffset(int vlistID, int varID, double addoffset)
{
1179
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1180
1181
1182

  vlistptr = vlist_to_pointer(vlistID);

1183
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1184
1185
1186
1187

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

1188

1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
void vlistDefVarTsteptype(int vlistID, int varID, int tsteptype)
{
  vlist_t *vlistptr;

  vlistptr = vlist_to_pointer(vlistID);

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


int vlistInqVarTsteptype(int vlistID, int varID)
{
  vlist_t *vlistptr;

  vlistptr = vlist_to_pointer(vlistID);

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


1209
1210
void vlistDefVarTimave(int vlistID, int varID, int timave)
{
1211
  vlist_t *vlistptr;
1212
1213
1214
1215
1216
1217
1218
1219
1220

  vlistptr = vlist_to_pointer(vlistID);

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


int vlistInqVarTimave(int vlistID, int varID)
{
1221
  vlist_t *vlistptr;
1222
1223
1224
1225
1226
1227
1228
1229

  vlistptr = vlist_to_pointer(vlistID);

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


void vlistDefVarTimaccu(int vlistID, int varID, int timaccu)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1230
{
1231
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1232
1233
1234

  vlistptr = vlist_to_pointer(vlistID);

1235
  vlistptr->vars[varID].timaccu = timaccu;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1236
1237
}

1238
1239

int vlistInqVarTimaccu(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1240
{
1241
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1242
1243
1244

  vlistptr = vlist_to_pointer(vlistID);

1245
  return (vlistptr->vars[varID].timaccu);