vlist_var.c 64.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
6
#include <limits.h>

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

18
19
20
21
22
23
#if  defined  (HAVE_LIBGRIB_API)
#  include "file.h"

#  include <grib_api.h>
#endif

24

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

Deike Kleberg's avatar
Deike Kleberg committed
30
31
32
33
34
35
36
37
  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;
38
39
  vlistptr->vars[varID].typeOfGeneratingProcess   = 0;
  vlistptr->vars[varID].productDefinitionTemplate = -1;
40
  vlistptr->vars[varID].chunktype     = cdiChunkType;
41
  vlistptr->vars[varID].xyz           = 321;
Deike Kleberg's avatar
Deike Kleberg committed
42
43
  vlistptr->vars[varID].gridID        = CDI_UNDEFID;
  vlistptr->vars[varID].zaxisID       = CDI_UNDEFID;
44
  vlistptr->vars[varID].subtypeID     = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
45
46
47
48
49
50
51
52
53
54
55
  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;
56
  vlistptr->vars[varID].extra         = NULL;
Deike Kleberg's avatar
Deike Kleberg committed
57
58
59
60
61
62
63
64
  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;
65
  vlistptr->vars[varID].ensdata       = NULL;
66
  vlistptr->vars[varID].iorank        = CDI_UNDEFID;
67
  vlistptr->vars[varID].opt_grib_kvpair_size = 0;
68
  vlistptr->vars[varID].opt_grib_kvpair      = NULL;
69
  vlistptr->vars[varID].opt_grib_nentries    = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
71
}

72
73


74
75
static
int vlistvarNewEntry(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
77
78
{
  int varID = 0;
  int vlistvarSize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
  var_t *vlistvar;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
82
83
84
85
86
87
88
89
90

  vlistvarSize = vlistptr->varsAllocated;
  vlistvar     = vlistptr->vars;
  /*
    Look for a free slot in vlistvar.
    (Create the table the first time through).
  */
  if ( ! vlistvarSize )
    {
      vlistvarSize = 2;
91
      vlistvar = (var_t *) Malloc((size_t)vlistvarSize * sizeof (var_t));
92
      for (int i = 0; i < vlistvarSize; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
94
95
96
	vlistvar[i].isUsed = FALSE;
    }
  else
    {
Thomas Jahns's avatar
Thomas Jahns committed
97
98
      while (varID < vlistvarSize && vlistvar[varID].isUsed)
        ++varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
99
100
101
102
103
104
    }
  /*
    If the table overflows, double its size.
  */
  if ( varID == vlistvarSize )
    {
105
      vlistvar = (var_t *) Realloc(vlistvar,
Thomas Jahns's avatar
Thomas Jahns committed
106
107
                                   (size_t)(vlistvarSize *= 2) * sizeof(var_t));
      for ( int i = varID; i < vlistvarSize; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108
109
110
111
112
113
114
115
116
117
118
119
120
	vlistvar[i].isUsed = FALSE;
    }

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

  vlistvarInitEntry(vlistID, varID);

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

  return (varID);
}

121
void vlistCheckVarID(const char *caller, int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
124
125

  if ( vlistptr == NULL )
126
    Errorc("vlist undefined!");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128

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

  if ( ! vlistptr->vars[varID].isUsed )
132
    Errorc("varID %d undefined!", varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
134
}

135

136
137
138
139
140
141
142
143
144
int vlistDefVarTiles(int vlistID, int gridID, int zaxisID, int tsteptype, int tilesetID)
{
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
  if ( CDI_Debug )
    Message("gridID = %d  zaxisID = %d  tsteptype = %d", gridID, zaxisID, tsteptype);

  int varID = vlistvarNewEntry(vlistID);

  vlistptr->nvars++;
145
146
  vlistptr->vars[varID].gridID    = gridID;
  vlistptr->vars[varID].zaxisID   = zaxisID;
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  vlistptr->vars[varID].tsteptype = tsteptype;
  vlistptr->vars[varID].subtypeID = tilesetID;

  if ( tsteptype < 0 )
    {
      Message("Unexpected tstep type %d, set to TSTEP_INSTANT!", tsteptype);
      vlistptr->vars[varID].tsteptype = TSTEP_INSTANT;
    }

  vlistAdd2GridIDs(vlistptr, gridID);
  vlistAdd2ZaxisIDs(vlistptr, zaxisID);
  vlistAdd2SubtypeIDs(vlistptr, tilesetID);

  vlistptr->vars[varID].param = cdiEncodeParam(-(varID + 1), 255, 255);
  reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
  return (varID);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
166
/*
@Function  vlistDefVar
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
@Title     Define a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
168

169
@Prototype int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
170
@Parameter
171
172
173
174
175
    @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
176
177

@Description
178
The function @func{vlistDefVar} adds a new variable to vlistID.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
179
180

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
183
184
185
186
187
188
189
190
191
192
@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();
193
varID = vlistDefVar(vlistID, gridID, zaxisID, TIME_INSTANT);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
194
195
196
197
198
199
   ...
streamDefVlist(streamID, vlistID);
   ...
vlistDestroy(vlistID);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
201
@EndFunction
*/
202
int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
203
{
204
205
  /* call "vlistDefVarTiles" with a trivial tile index: */
  return vlistDefVarTiles(vlistID, gridID, zaxisID, tsteptype, CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
206
207
}

208
209
210
211
212
213
void
cdiVlistCreateVarLevInfo(vlist_t *vlistptr, int varID)
{
  xassert(varID >= 0 && varID < vlistptr->nvars
          && vlistptr->vars[varID].levinfo == NULL);
  int zaxisID = vlistptr->vars[varID].zaxisID;
214
  size_t nlevs = (size_t)zaxisInqSize(zaxisID);
215

216
  vlistptr->vars[varID].levinfo
217
    = (levinfo_t*) Malloc((size_t)nlevs * sizeof(levinfo_t));
218

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

223
224
225
226
227
228
/*
@Function  vlistDefVarParam
@Title     Define the parameter number of a Variable

@Prototype void vlistDefVarParam(int vlistID, int varID, int param)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
229
230
231
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  param    Parameter number.
232
233
234
235
236
237
238
239

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

@EndFunction
*/
void vlistDefVarParam(int vlistID, int varID, int param)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
241

242
  vlistCheckVarID(__func__, vlistID, varID);
243

244
245
246
  if (vlistptr->vars[varID].param != param)
    {
      vlistptr->vars[varID].param = param;
Thomas Jahns's avatar
Thomas Jahns committed
247
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
248
    }
249
250
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
251
252
/*
@Function  vlistDefVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
@Title     Define the code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
255
256

@Prototype void vlistDefVarCode(int vlistID, int varID, int code)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
257
258
259
    @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
260
261

@Description
262
The function @func{vlistDefVarCode} defines the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
263
264
265
266
267

@EndFunction
*/
void vlistDefVarCode(int vlistID, int varID, int code)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
268
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
269

270
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
271

272
273
  int param = vlistptr->vars[varID].param;
  int pnum, pcat, pdis;
274
  cdiDecodeParam(param, &pnum, &pcat, &pdis);
275
276
277
278
  int newParam = cdiEncodeParam(code, pcat, pdis);
  if (vlistptr->vars[varID].param != newParam)
    {
      vlistptr->vars[varID].param = newParam;
Thomas Jahns's avatar
Thomas Jahns committed
279
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
280
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
281
282
283
}


284
void vlistInqVar(int vlistID, int varID, int *gridID, int *zaxisID, int *tsteptype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
286
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
287

288
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
289

290
291
292
  *gridID    = vlistptr->vars[varID].gridID;
  *zaxisID   = vlistptr->vars[varID].zaxisID;
  *tsteptype = vlistptr->vars[varID].tsteptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
293
294
295
296

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
297
298
299
300
301
302
/*
@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
303
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
304
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
305
306
307
308
309
310
311
312
313

@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
314
315
int vlistInqVarGrid(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
317

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

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

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

@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
340
341
int vlistInqVarZaxis(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
343

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

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

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

/*
@Function  vlistInqVarSubtype
@Title     Get the Subtype ID of a Variable

@Description
The function @func{vlistInqVarSubtype} returns the subtype ID of a variable.

@Result
@func{vlistInqVarSubtype} returns the subtype ID of the variable.

@EndFunction
*/
int vlistInqVarSubtype(int vlistID, int varID)
{
  vlist_t *vlistptr = vlist_to_pointer(vlistID);

  vlistCheckVarID(__func__, vlistID, varID);
  return (vlistptr->vars[varID].subtypeID);
}


371
372
373
374
375
376
/*
@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
377
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
378
    @Item  varID    Variable identifier.
379
380
381
382
383
384
385
386
387
388
389

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

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

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

392
  vlistCheckVarID(__func__, vlistID, varID);
393

Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
  return (vlistptr->vars[varID].param);
395
396
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
397
398
/*
@Function  vlistInqVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
399
@Title     Get the Code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
400
401
402

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

@Description
407
The function @func{vlistInqVarCode} returns the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
408
409

@Result
410
@func{vlistInqVarCode} returns the code number of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
411
412
413
414
415

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

418
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
419

420
421
  int param = vlistptr->vars[varID].param;
  int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
  cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
423
424
  int code = pnum;
  if ( pdis != 255 ) code = -varID-1; // GRIB2 Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
426
427
428
429
430
431

  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
432
433
434
}


435
const char *vlistInqVarNamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
436
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
437
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
438

439
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
440
441
442
443

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

444

445
const char *vlistInqVarLongnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
446
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
447
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
448

449
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
450
451
452
453

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

454

455
const char *vlistInqVarStdnamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
456
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
457
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
458

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

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

464

465
const char *vlistInqVarUnitsPtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
466
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
467
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
468

469
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
470
471
472
473
474
475

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

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

478
@Prototype void vlistInqVarName(int vlistID, int varID, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
479
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
480
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
481
    @Item  varID    Variable identifier.
482
    @Item  name     Returned variable name. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
483
                    returned string. The maximum possible length, in characters, of
484
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
485
486

@Description
487
The function @func{vlistInqVarName} returns the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488
489

@Result
490
491
@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
492
493
494
495
496

@EndFunction
*/
void vlistInqVarName(int vlistID, int varID, char *name)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
497
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
498

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

  if ( vlistptr->vars[varID].name == NULL )
    {
503
504
      int param = vlistptr->vars[varID].param;
      int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
505
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
506
507
508
      if ( pdis == 255 )
	{
	  int code = pnum;
509
	  int tableID = vlistptr->vars[varID].tableID;
510
511
512
513
514
515
516
	  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
517
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
518
  else
519
    strcpy(name, vlistptr->vars[varID].name);   //FIXME: This may overrun the provided buffer.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
521
522
523

  return;
}

524
525
526
527
528
529
530
531
532
/*
@Function vlistCopyVarName
@Tatle    Get the name of a Variable in a safe way

@Prototype char* vlistCopyVarName(int vlistId, int varId)
@Parameter
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
    @Item  varID    Variable identifier.

533
@Return A pointer to a malloc'ed string. Must be cleaned up with Free().
534
535
536

@Description
This is the buffer overflow immune version of vlistInqVarName().
537
The memory for the returned string is allocated to fit the string via Malloc().
538
539
540
541
542
543
544
545
546
547

@EndFunction
*/
char* vlistCopyVarName(int vlistId, int varId)
{
  vlist_t* vlistptr = vlist_to_pointer(vlistId);
  vlistCheckVarID(__func__, vlistId, varId);

  //If a name is set in the variable description, use that.
  const char* name = vlistptr->vars[varId].name;
548
  if(name) return strdup(name);
549
550
551
552
553

  //Otherwise we check if we should use the table of parameter descriptions.
  int param = vlistptr->vars[varId].param;
  int discipline, category, number;
  cdiDecodeParam(param, &number, &category, &discipline);
554
  char *result = NULL;
555
556
557
  if(discipline == 255)
    {
      int tableId = vlistptr->vars[varId].tableID;
558
559
560
561
      if(( name = tableInqParNamePtr(tableId, number) ))
        result = strdup(name);
      {
        //No luck, fall back to outputting a name of the format "var<num>".
562
        result = (char *) Malloc(3 + 3 * sizeof (int) * CHAR_BIT / 8 + 2);
563
564
565
566
567
        sprintf(result, "var%d", number);
      }
    }
  else
    {
568
      result = (char *) Malloc(5 + 2 + 3 * (3 * sizeof (int) * CHAR_BIT + 1) + 1);
569
      sprintf(result, "param%d.%d.%d", number, category, discipline);
570
571
    }
  //Finally, we fall back to outputting a name of the format "param<num>.<cat>.<dis>".
572
  return result;
573
574
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
575
576
/*
@Function  vlistInqVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
577
@Title     Get the longname of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
578
579
580

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

@Description
588
589
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
590
591

@Result
592
@func{vlistInqVaeLongname} returns the longname of the variable to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
593
594
595
596
597

@EndFunction
*/
void vlistInqVarLongname(int vlistID, int varID, char *longname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
598
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
599

600
601
602
  vlistCheckVarID(__func__, vlistID, varID);

  longname[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
603
604
605

  if ( vlistptr->vars[varID].longname == NULL )
    {
606
607
      int param = vlistptr->vars[varID].param;
      int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
608
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
609
610
611
      if ( pdis == 255 )
	{
	  int code = pnum;
612
          int tableID = vlistptr->vars[varID].tableID;
613
614
615
	  if ( tableInqParLongname(tableID, code, longname) != 0 )
	    longname[0] = '\0';
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
616
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
617
618
619
620
621
622
  else
    strcpy(longname, vlistptr->vars[varID].longname);

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
624
625
626
627
628
/*
@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
629
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
630
    @Item  varID    Variable identifier.
631
    @Item  stdname  Standard name of the variable. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
632
                    returned string. The maximum possible length, in characters, of
633
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
634
635

@Description
636
637
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
638
639
640
641
642
643

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

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
644
645
void vlistInqVarStdname(int vlistID, int varID, char *stdname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
646
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
647

648
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
649
650
651

  if ( vlistptr->vars[varID].stdname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
652
      stdname[0] = '\0';
653
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
654
655
656
657
658
659
660
661
  else
    strcpy(stdname, vlistptr->vars[varID].stdname);

  return;
}

/*
@Function  vlistInqVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
@Title     Get the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
663
664
665

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

@Description
673
674
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
675
676

@Result
677
@func{vlistInqVarUnits} returns the units of the variable to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
678
679
680
681
682

@EndFunction
*/
void vlistInqVarUnits(int vlistID, int varID, char *units)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
683
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
684

685
686
687
  vlistCheckVarID(__func__, vlistID, varID);

  units[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
688
689
690

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

  return;
}

708
/* used in MPIOM ! */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709
int vlistInqVarID(int vlistID, int code)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
710
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
711
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
712

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

721
  return (CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
722
}
723

Uwe Schulzweida's avatar
Uwe Schulzweida committed
724

Uwe Schulzweida's avatar
Uwe Schulzweida committed
725
726
int vlistInqVarSize(int vlistID, int varID)
{
727
  vlistCheckVarID(__func__, vlistID, varID);
728

729
730
  int zaxisID, gridID;
  int tsteptype;
731
732
  vlistInqVar(vlistID, varID, &gridID, &zaxisID, &tsteptype);

733
  int nlevs = zaxisInqSize(zaxisID);
734

735
  int gridsize = gridInqSize(gridID);
736

737
  int size = gridsize*nlevs;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
738
739
740
741
742
743

  return (size);
}

/*
@Function  vlistInqVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
744
@Title     Get the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
745
746
747

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

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
752
The function @func{vlistInqVarDatatype} returns the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
754

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
755
@func{vlistInqVarDatatype} returns an identifier to the data type of the variable.
756
The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16}, @func{DATATYPE_PACK24},
757
758
@func{DATATYPE_FLT32}, @func{DATATYPE_FLT64}, @func{DATATYPE_INT8}, @func{DATATYPE_INT16} and 
@func{DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
759
760
761
762
763

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

766
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
767
768
769
770
771

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


772
773
int vlistInqVarNumber(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
774
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
775

776
  vlistCheckVarID(__func__, vlistID, varID);
777

778
  int number = CDI_REAL;
779
780
  if ( vlistptr->vars[varID].datatype == DATATYPE_CPX32 ||
       vlistptr->vars[varID].datatype == DATATYPE_CPX64 )
781
782
783
784
785
    number = CDI_COMP;

  return (number);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
786
787
/*
@Function  vlistDefVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
788
@Title     Define the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
789
790
791

@Prototype void vlistDefVarDatatype(int vlistID, int varID, int datatype)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
792
793
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
    @Item  datatype The data type identifier.
795
                    The valid CDI data types are @func{DATATYPE_PACK8}, @func{DATATYPE_PACK16},
796
797
                    @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
798
799

@Description
800
The function @func{vlistDefVarDatatype} defines the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
801
802
803
804
805

@EndFunction
*/
void vlistDefVarDatatype(int vlistID, int varID, int datatype)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
806
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807

808
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
809

810
811
812
813
814
815
816
817
818
819
820
821
822
823
  if (vlistptr->vars[varID].datatype != datatype)
    {
      vlistptr->vars[varID].datatype = datatype;

      if ( vlistptr->vars[varID].missvalused == FALSE )
        switch (datatype)
          {
          case DATATYPE_INT8:   vlistptr->vars[varID].missval = -SCHAR_MAX; break;
          case DATATYPE_UINT8:  vlistptr->vars[varID].missval =  UCHAR_MAX; break;
          case DATATYPE_INT16:  vlistptr->vars[varID].missval = -SHRT_MAX;  break;
          case DATATYPE_UINT16: vlistptr->vars[varID].missval =  USHRT_MAX; break;
          case DATATYPE_INT32:  vlistptr->vars[varID].missval = -INT_MAX;   break;
          case DATATYPE_UINT32: vlistptr->vars[varID].missval =  UINT_MAX;  break;
          }
Thomas Jahns's avatar
Thomas Jahns committed
824
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
825
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
826
827
}

828

Uwe Schulzweida's avatar
Uwe Schulzweida committed
829
830
void vlistDefVarInstitut(int vlistID, int varID, int instID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
831
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
832
833
834
  if (vlistptr->vars[varID].instID != instID)
    {
      vlistptr->vars[varID].instID = instID;
Thomas Jahns's avatar
Thomas Jahns committed
835
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
836
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
837
838
}

839

Uwe Schulzweida's avatar
Uwe Schulzweida committed
840
841
int vlistInqVarInstitut(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
842
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
843
844
845
  return (vlistptr->vars[varID].instID);
}

846

Uwe Schulzweida's avatar
Uwe Schulzweida committed
847
848
void vlistDefVarModel(int vlistID, int varID, int modelID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
849
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
850
851
852
  if (vlistptr->vars[varID].modelID != modelID)
    {
      vlistptr->vars[varID].modelID = modelID;
Thomas Jahns's avatar
Thomas Jahns committed
853
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
854
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
855
856
}

857

Uwe Schulzweida's avatar
Uwe Schulzweida committed
858
859
int vlistInqVarModel(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
860
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
861
862
863
  return (vlistptr->vars[varID].modelID);
}

864

Uwe Schulzweida's avatar
Uwe Schulzweida committed
865
866
void vlistDefVarTable(int vlistID, int varID, int tableID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
867
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
868

869
870
871
872
  if (vlistptr->vars[varID].tableID != tableID)
    {
      vlistptr->vars[varID].tableID = tableID;
      int tablenum = tableInqNum(tableID);
873

874
      int param = vlistptr->vars[varID].param;
875

876
877
878
      int pnum, pcat, pdis;
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
      vlistptr->vars[varID].param = cdiEncodeParam(pnum, tablenum, pdis);
Thomas Jahns's avatar
Thomas Jahns committed
879
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
880
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
881
882
}

883

Uwe Schulzweida's avatar
Uwe Schulzweida committed
884
885
int vlistInqVarTable(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
886
887
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
  return (vlistptr->vars[varID].tableID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
888
889
890
891
}

/*
@Function  vlistDefVarName
Uwe Schulzweida's avatar
Uwe Schulzweida committed
892
@Title     Define the name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
893
894
895

@Prototype void vlistDefVarName(int vlistID, int varID, const char *name)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
896
897
898
    @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
899
900

@Description
901
The function @func{vlistDefVarName} defines the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
902
903
904
905
906

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

909
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
910

911
  if ( name )
912
    {
913
914
      if ( vlistptr->vars[varID].name )
	{
915
	  Free(vlistptr->vars[varID].name);
916
917
	  vlistptr->vars[varID].name = NULL;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
918

919
      vlistptr->vars[varID].name = strdupx(name);
Thomas Jahns's avatar
Thomas Jahns committed
920
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
921
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
922
923
924
925
}

/*
@Function  vlistDefVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
926
@Title     Define the long name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
927
928
929

@Prototype void vlistDefVarLongname(int vlistID, int varID, const char *longname)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
930
931
932
    @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
933
934

@Description
935
The function @func{vlistDefVarLongname} defines the long name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
936
937
938
939
940

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

943
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
944

945
  if ( longname )
946
    {
947
948
      if ( vlistptr->vars[varID].longname )
	{
949
	  Free(vlistptr->vars[varID].longname);
950
951
	  vlistptr->vars[varID].longname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
952

953
      vlistptr->vars[varID].longname = strdupx(longname);
Thomas Jahns's avatar
Thomas Jahns committed
954
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
955
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
956
957
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
958
959
960
961
962
963
/*
@Function  vlistDefVarStdname
@Title     Define the standard name of a Variable

@Prototype void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
964
965
966
    @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
967
968
969
970
971
972

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

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
973
974
void vlistDefVarStdname(int vlistID, int varID, const char *stdname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
975
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
976

977
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
978

979
  if ( stdname )
980
    {
981
982
      if ( vlistptr->vars[varID].stdname )
	{
983
	  Free(vlistptr->vars[varID].stdname);
984
985
	  vlistptr->vars[varID].stdname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
986

987
      vlistptr->vars[varID].stdname = strdupx(stdname);
Thomas Jahns's avatar
Thomas Jahns committed
988
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
989
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
990
991
992
993
}

/*
@Function  vlistDefVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
994
@Title     Define the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
995
996
997

@Prototype void vlistDefVarUnits(int vlistID, int varID, const char *units)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
998
999
1000
    @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
1001
1002

@Description
1003
The function @func{vlistDefVarUnits} defines the units of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1004
1005
1006
1007
1008

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

1011
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1012

1013
  if ( units )