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

5
#include <limits.h>
6
7
8
9
#ifdef USE_MPI
#include <mpi.h>
#include "pio_comm.h"
#endif
10

Uwe Schulzweida's avatar
Uwe Schulzweida committed
11
12
13
14
#include "dmemory.h"
#include "cdi.h"
#include "stream_int.h"
#include "vlist.h"
15
16
17
18
19
#include "vlist_var.h"
#include "resource_handle.h"
#include "vlist_att.h"
#include "namespace.h"
#include "pio_util.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
20

21
extern resOps vlist_ops;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
22

23
24
static
void vlistvarInitEntry(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
25
{
26
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
27
28
29

  vlistptr = vlist_to_pointer(vlistID);

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  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;
  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;
61
  vlistptr->vars[varID].ensdata       = NULL;
62
63
64
  vlistptr->vars[varID].iorank       = CDI_UNDEFID;
  vlistptr->vars[varID].decoSize     = 0;
  vlistptr->vars[varID].deco         = NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
65
66
}

67
68
static
int vlistvarNewEntry(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
69
70
71
{
  int varID = 0;
  int vlistvarSize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
  var_t *vlistvar;
73
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87

  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
88
      vlistvar = (var_t *) malloc(vlistvarSize*sizeof(var_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
90
      if ( vlistvar == NULL )
	{
91
92
          Message("vlistvarSize = %d", vlistvarSize);
	  SysError("Allocation of var_t failed");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	}

      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
114
      vlistvar = (var_t *) realloc(vlistvar, vlistvarSize*sizeof(var_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
116
      if ( vlistvar == NULL )
	{
117
118
          Message("vlistvarSize = %d", vlistvarSize);
	  SysError("Reallocation of var_t failed");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
	}
      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);
}

136
137
static
void vlistCheckVarID(const char *caller, int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
{
139
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
141
142
143

  vlistptr = vlist_to_pointer(vlistID);

  if ( vlistptr == NULL )
144
    Errorc("vlist undefined!");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146

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

  if ( ! vlistptr->vars[varID].isUsed )
150
    Errorc("varID %d undefined!", varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
}

/*
@Function  vlistDefVar
Uwe Schulzweida's avatar
Uwe Schulzweida committed
155
@Title     Define a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156

157
@Prototype int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
@Parameter
159
160
161
162
163
    @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
164
165

@Description
166
The function @func{vlistDefVar} adds a new variable to vlistID.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
168

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
172
173
174
175
176
177
178
179
180
@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();
181
varID = vlistDefVar(vlistID, gridID, zaxisID, TIME_INSTANT);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
183
184
185
186
187
   ...
streamDefVlist(streamID, vlistID);
   ...
vlistDestroy(vlistID);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
189
@EndFunction
*/
190
int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
191
192
193
194
195
{
  int varID;
  int nlevs;
  int levID;
  int index;
196
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
197
198

  vlistptr = vlist_to_pointer(vlistID);
199
200
201
202
203
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return CDI_UNDEFID;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
205

  if ( CDI_Debug )
206
    Message("gridID = %d  zaxisID = %d  tsteptype = %d", gridID, zaxisID, tsteptype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
208
209
210
211
212
213

  varID = vlistvarNewEntry(vlistID);

  vlistptr->nvars++;

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

216
  if ( tsteptype < 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
217
    {
218
219
      Message("Unexpected tstep type %d, set to TSTEP_INSTANT!", tsteptype);
      vlistptr->vars[varID].tsteptype = TSTEP_INSTANT;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
220
221
222
223
    }

  nlevs = zaxisInqSize(zaxisID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
224
  vlistptr->vars[varID].levinfo = (levinfo_t *) malloc(nlevs*sizeof(levinfo_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
225
226
227
228
229
230

  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;
231
      vlistptr->vars[varID].levinfo[levID].mlevelID = levID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
232
233
234
235
236
237
238
239
240
    }

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

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

  if ( index == vlistptr->ngrids )
    {
241
      if ( vlistptr->ngrids + 1 >= MAX_GRIDS_PS )
242
	Error("Maximum of %d grids reached", MAX_GRIDS_PS);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
243
244
245
246
247
248
249
250
251
252

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

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

  if ( index == vlistptr->nzaxis )
    {
253
      if ( vlistptr->nzaxis + 1 >= MAX_ZAXES_PS )
254
	Error("Maximum of %d zaxis reached", MAX_ZAXES_PS);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
255
256
257
258
259

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

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

  return (varID);
}

265
266
267
268
269
270
/*
@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
271
272
273
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  param    Parameter number.
274
275
276
277
278
279
280
281
282
283
284
285

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

286
  vlistCheckVarID(__func__, vlistID, varID);
287

288
289
290
291
292
293
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

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

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

@Prototype void vlistDefVarCode(int vlistID, int varID, int code)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
303
304
305
    @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
306
307

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

@EndFunction
*/
void vlistDefVarCode(int vlistID, int varID, int code)
{
314
  vlist_t *vlistptr;
315
  int param, pnum, pcat, pdis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
317
318

  vlistptr = vlist_to_pointer(vlistID);

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

321
322
323
324
325
326
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

327
328
329
330
331
  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
332
333
334
}


335
void vlistInqVar(int vlistID, int varID, int *gridID, int *zaxisID, int *tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
336
{
337
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
339
340

  vlistptr = vlist_to_pointer(vlistID);

341
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
342

343
344
345
  *gridID    = vlistptr->vars[varID].gridID;
  *zaxisID   = vlistptr->vars[varID].zaxisID;
  *tsteptype = vlistptr->vars[varID].tsteptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
347
348
349

  return;
}

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

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

  vlistptr = vlist_to_pointer(vlistID);

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
378
379
380
381
382
383
/*
@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
384
385
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
386
387
388
389
390
391
392
393
394

@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
395
396
int vlistInqVarZaxis(int vlistID, int varID)
{
397
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
398
399
400

  vlistptr = vlist_to_pointer(vlistID);

401
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
402
403
404
405

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

406
407
408
409
410
411
/*
@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
412
413
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

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

430
  vlistCheckVarID(__func__, vlistID, varID);
431
432
433
434
435
436

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

  return (param);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
437
438
/*
@Function  vlistInqVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
439
@Title     Get the Code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
440
441
442

@Prototype int vlistInqVarCode(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
443
444
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
445
446

@Description
447
The function @func{vlistInqVarCode} returns the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
448
449

@Result
450
@func{vlistInqVarCode} returns the code number of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
451
452
453
454
455

@EndFunction
*/
int vlistInqVarCode(int vlistID, int varID)
{
456
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
457
458
  int param, code;
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
459
460
461

  vlistptr = vlist_to_pointer(vlistID);

462
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
463

Uwe Schulzweida's avatar
Uwe Schulzweida committed
464
  param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
465
  cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
466
  code = pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
467
468
469
470
471
472
473

  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
474
475
476
}


477
const char *vlistInqVarNamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
478
{
479
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
480
481
482

  vlistptr = vlist_to_pointer(vlistID);

483
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
484
485
486
487

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

488

489
const char *vlistInqVarLongnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
490
{
491
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
492
493
494

  vlistptr = vlist_to_pointer(vlistID);

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

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

500

501
const char *vlistInqVarStdnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
502
{
503
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
504
505
506

  vlistptr = vlist_to_pointer(vlistID);

507
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
508
509
510
511

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

512

513
const char *vlistInqVarUnitsPtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
514
{
515
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
516
517
518

  vlistptr = vlist_to_pointer(vlistID);

519
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
521
522
523
524
525

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

/*
@Function  vlistInqVarName
Uwe Schulzweida's avatar
Uwe Schulzweida committed
526
@Title     Get the name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
527
528
529

@Prototype void vlistInqVarName(int vlistID, int varID, char *name)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
530
531
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
532
    @Item  name     Returned variable name. The caller must allocate space for the 
Uwe Schulzweida's avatar
Uwe Schulzweida committed
533
                    returned string. The maximum possible length, in characters, of
Uwe Schulzweida's avatar
Uwe Schulzweida committed
534
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
535
536

@Description
537
The function @func{vlistInqVarName} returns the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
538
539

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
540
541
@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
542
543
544
545
546

@EndFunction
*/
void vlistInqVarName(int vlistID, int varID, char *name)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
547
  int tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
548
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
549
  int pdis, pcat, pnum;
550
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
551
552
553

  vlistptr = vlist_to_pointer(vlistID);

554
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
555
556
557

  if ( vlistptr->vars[varID].name == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
558
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
559
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
560
561
562
563
564
565
566
567
568
569
570
      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
571
572
573
574
575
576
577
578
579
    }  
  else
    strcpy(name, vlistptr->vars[varID].name);

  return;
}

/*
@Function  vlistInqVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
@Title     Get the longname of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
581
582
583

@Prototype void vlistInqVarLongname(int vlistID, int varID, char *longname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
584
585
586
587
    @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
Uwe Schulzweida's avatar
Uwe Schulzweida committed
588
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
589
590

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
591
592
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
593
594

@Result
595
@func{vlistInqVaeLongname} returns the longname of the variable to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
596
597
598
599
600

@EndFunction
*/
void vlistInqVarLongname(int vlistID, int varID, char *longname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
601
  int tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
602
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
603
  int pdis, pcat, pnum;
604
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
605
606
607

  vlistptr = vlist_to_pointer(vlistID);

608
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
609

Uwe Schulzweida's avatar
Uwe Schulzweida committed
610
611
  longname[0] = '\0';

Uwe Schulzweida's avatar
Uwe Schulzweida committed
612
613
  if ( vlistptr->vars[varID].longname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
614
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
615
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
616
617
618
619
620
621
622
      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
623
624
625
626
627
628
629
    }  
  else
    strcpy(longname, vlistptr->vars[varID].longname);

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
630
631
632
633
634
635
/*
@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
636
637
638
639
    @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
Uwe Schulzweida's avatar
Uwe Schulzweida committed
640
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
641
642

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
643
644
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
645
646
647
648
649
650

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

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
651
652
void vlistInqVarStdname(int vlistID, int varID, char *stdname)
{
653
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
654
655
656

  vlistptr = vlist_to_pointer(vlistID);

657
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
658
659
660

  if ( vlistptr->vars[varID].stdname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
661
      stdname[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
663
664
665
666
667
668
669
670
    }  
  else
    strcpy(stdname, vlistptr->vars[varID].stdname);

  return;
}

/*
@Function  vlistInqVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
671
@Title     Get the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
672
673
674

@Prototype void vlistInqVarUnits(int vlistID, int varID, char *units)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
675
676
677
678
    @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
Uwe Schulzweida's avatar
Uwe Schulzweida committed
679
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
680
681

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
682
683
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
684
685

@Result
686
@func{vlistInqVarUnits} returns the units of the variable to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
687
688
689
690
691

@EndFunction
*/
void vlistInqVarUnits(int vlistID, int varID, char *units)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
692
  int tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
693
  int param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
694
  int pdis, pcat, pnum;
695
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
696
697
698

  vlistptr = vlist_to_pointer(vlistID);

699
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
700

Uwe Schulzweida's avatar
Uwe Schulzweida committed
701
702
  units[0] = '\0';

Uwe Schulzweida's avatar
Uwe Schulzweida committed
703
704
  if ( vlistptr->vars[varID].units == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
705
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
706
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
707
708
709
710
711
712
713
      if ( pdis == 255 )
	{
	  int code = pnum;
	  tableID = vlistptr->vars[varID].tableID;
	  if ( tableInqParUnits(tableID, code, units) != 0 )
	    units[0] = '\0';
	}
714
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
715
716
717
718
719
720
  else
    strcpy(units, vlistptr->vars[varID].units);

  return;
}

721
/* used in MPIOM ! */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
722
int vlistInqVarID(int vlistID, int code)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
723
724
{
  int varID;
725
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
726
  int param, pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
727
728
729
730

  vlistptr = vlist_to_pointer(vlistID);

  for ( varID = 0; varID < vlistptr->nvars; varID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
731
732
    {
      param = vlistptr->vars[varID].param;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
733
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
734
      if ( pnum == code ) return (varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
735
736
    }

737
  return (CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
738
}
739

Uwe Schulzweida's avatar
Uwe Schulzweida committed
740

Uwe Schulzweida's avatar
Uwe Schulzweida committed
741
742
743
744
745
int vlistInqVarSize(int vlistID, int varID)
{
  int size;
  int zaxisID, gridID;
  int nlevs, gridsize;
746
  int tsteptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
747

748
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
749

750
  vlistInqVar(vlistID, varID, &gridID, &zaxisID, &tsteptype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
751
752
753
754
755
756
757
758
759
760
761
762

  nlevs = zaxisInqSize(zaxisID);

  gridsize = gridInqSize(gridID);

  size = gridsize*nlevs;

  return (size);
}

/*
@Function  vlistInqVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
763
@Title     Get the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
764
765
766

@Prototype int vlistInqVarDatatype(int vlistID, int varID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
767
768
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
769
770

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
771
The function @func{vlistInqVarDatatype} returns the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
772
773

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
774
@func{vlistInqVarDatatype} returns an identifier to the data type of the variable.
775
The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16}, @func{DATATYPE_PACK24},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
776
777
@func{DATATYPE_FLT32}, @func{DATATYPE_FLT64}, @func{DATATYPE_INT8}, @func{DATATYPE_INT16} and 
@func{DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
778
779
780
781
782

@EndFunction
*/
int vlistInqVarDatatype(int vlistID, int varID)
{
783
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
784
785
786

  vlistptr = vlist_to_pointer(vlistID);

787
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
788
789
790
791
792

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


793
794
795
796
797
798
799
int vlistInqVarNumber(int vlistID, int varID)
{
  vlist_t *vlistptr;
  int number = CDI_REAL;

  vlistptr = vlist_to_pointer(vlistID);

800
  vlistCheckVarID(__func__, vlistID, varID);
801

Uwe Schulzweida's avatar
Uwe Schulzweida committed
802
803
  if ( vlistptr->vars[varID].datatype == DATATYPE_CPX32 ||
       vlistptr->vars[varID].datatype == DATATYPE_CPX64 )
804
805
806
807
808
    number = CDI_COMP;

  return (number);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
809
810
/*
@Function  vlistDefVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
811
@Title     Define the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
812
813
814

@Prototype void vlistDefVarDatatype(int vlistID, int varID, int datatype)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
815
816
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
817
    @Item  datatype The data type identifier.
818
                    The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
819
820
                    @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
821
822

@Description
823
The function @func{vlistDefVarDatatype} defines the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
824
825
826
827
828

@EndFunction
*/
void vlistDefVarDatatype(int vlistID, int varID, int datatype)
{
829
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
830
831
832

  vlistptr = vlist_to_pointer(vlistID);

833
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
834

835
836
837
838
839
840
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

841
842
843
  vlistptr->vars[varID].datatype = datatype;
  
  if ( vlistptr->vars[varID].missvalused == FALSE )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
844
845
846
847
848
849
850
851
852
    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
853
854
}

855

Uwe Schulzweida's avatar
Uwe Schulzweida committed
856
857
void vlistDefVarInstitut(int vlistID, int varID, int instID)
{
858
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
859
860
861

  vlistptr = vlist_to_pointer(vlistID);

862
863
864
865
866
867
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
868
869
870
  vlistptr->vars[varID].instID = instID;
}

871

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

  vlistptr = vlist_to_pointer(vlistID);

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

881

Uwe Schulzweida's avatar
Uwe Schulzweida committed
882
883
void vlistDefVarModel(int vlistID, int varID, int modelID)
{
884
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
885

886
887
888
889
890
891
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
892
893
894
895
896
  vlistptr = vlist_to_pointer(vlistID);

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

897

Uwe Schulzweida's avatar
Uwe Schulzweida committed
898
899
int vlistInqVarModel(int vlistID, int varID)
{
900
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
901
902
903
904
905
906

  vlistptr = vlist_to_pointer(vlistID);

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

907

Uwe Schulzweida's avatar
Uwe Schulzweida committed
908
909
void vlistDefVarTable(int vlistID, int varID, int tableID)
{
910
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
911

912
913
914
915
916
917
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
918
919
920
  vlistptr = vlist_to_pointer(vlistID);

  vlistptr->vars[varID].tableID = tableID;
921
922
923
924
925
926
927
928
929
930
931
932

  {
    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
933
934
}

935

Uwe Schulzweida's avatar
Uwe Schulzweida committed
936
937
938
int vlistInqVarTable(int vlistID, int varID)
{
  int tableID;
939
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
940
941
942
943
944
945
946
947
948
949

  vlistptr = vlist_to_pointer(vlistID);

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

  return (tableID);
}

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

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

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

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

967
968
969
970
971
972
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
973
974
  vlistptr = vlist_to_pointer(vlistID);

975
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
976

977
  if ( name )
978
    {
979
980
981
982
983
      if ( vlistptr->vars[varID].name )
	{
	  free(vlistptr->vars[varID].name);
	  vlistptr->vars[varID].name = NULL;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
984

985
986
      vlistptr->vars[varID].name = strdupx(name);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
987
988
989
990
}

/*
@Function  vlistDefVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
991
@Title     Define the long name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
992
993
994

@Prototype void vlistDefVarLongname(int vlistID, int varID, const char *longname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
995
996
997
    @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
998
999

@Description
1000
The function @func{vlistDefVarLongname} defines the long name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1001
1002
1003
1004
1005

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

1008
1009
1010
1011
1012
1013
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1014
1015
  vlistptr = vlist_to_pointer(vlistID);

1016
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1017

1018
  if ( longname )
1019
    {
1020
1021
1022
1023
1024
      if ( vlistptr->vars[varID].longname )
	{
	  free(vlistptr->vars[varID].longname);
	  vlistptr->vars[varID].longname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1025

1026
1027
      vlistptr->vars[varID].longname = strdupx(longname);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1028
1029
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1030
1031
1032
1033
1034
1035
/*
@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
1036
1037
1038
    @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
1039
1040
1041
1042
1043
1044

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

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1045
1046
void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
{
1047
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1048

1049
1050
1051
1052
1053
1054
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed.");
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1055
1056
  vlistptr = vlist_to_pointer(vlistID);

1057
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1058

1059
  if ( stdname )
1060
    {
1061
1062
1063
1064
1065
      if ( vlistptr->vars[varID].stdname )
	{
	  free(vlistptr->vars[varID].stdname);
	  vlistptr->vars[varID].stdname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1066

1067
1068
      vlistptr->vars[varID].stdname = strdupx(stdname);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1069
1070
1071
1072
}

/*
@Function  vlistDefVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1073
@Title     Define the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1074
1075
1076

@Prototype void vlistDefVarUnits(int vlistID, int varID, const char *units)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1077
1078
1079
    @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
1080
1081

@Description
1082
The function @func{vlistDefVarUnits} defines the units of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1083
1084
1085
1086
1087

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

1090
1091
1092
1093
1094
1095
  if ( reshGetStatus ( vlistID, &vlist_ops ) == CLOSED )
    {
      xwarning("%s", "Operation not executed." );
      return;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1096
1097
  vlistptr = vlist_to_pointer(vlistID);

1098
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1099

1100
  if ( units )
1101
    {
1102
1103
1104
1105
1106
      if ( vlistptr->vars[varID].units )
	{
	  free(vlistptr->vars[varID].units);
	  vlistptr->vars[varID].units = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1107

1108
1109
      vlistptr->vars[varID].units = strdupx(units);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1110
1111
1112
1113
}

/*
@Function  vlistInqVarMissval
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1114
@Title     Get the missing value of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1115
1116
1117

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

@Description
1122
The function @func{vlistInqVarMissval} returns the missing value of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1123
1124

@Result
1125
@func{vlistInqVarMissval} returns the missing value of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1126
1127
1128
1129
1130

@EndFunction
*/
double vlistInqVarMissval(int vlistID, int varID)
{
1131
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1132
1133
1134

  vlistptr = vlist_to_pointer(vlistID);

1135
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1136
1137
1138
1139

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

1140
1141
1142
/*
@Function  vlistDefVarMissval
@Title     Define the missing value of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1143

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
@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
1156
{
1157
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1158
1159
1160

  vlistptr = vlist_to_pointer(vlistID);

1161
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1162

1163
1164
  vlistptr->vars[varID].missval = missval;
  vlistptr->vars[varID].missvalused = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1165
1166
}

1167

1168
int vlistInqVarValidrange(int vlistID, int varID, double *validrange)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1169
{
1170
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1171
1172
1173

  vlistptr = vlist_to_pointer(vlistID);

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

1176
1177
1178
1179
1180
1181
1182
  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
1183
1184
1185
}


1186
1187
1188
void vlistDefVarValidrange(int vlistID, int varID, const double *validrange)
{
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1189

1190
  vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
  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
1201
{
1202
  vlist_t *vlistptr;