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

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

17
#if  defined  (HAVE_LIBGRIB_API)
18
19
#include "file.h"
#include <grib_api.h>
20
21
#endif

22

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

Deike Kleberg's avatar
Deike Kleberg committed
28
29
30
31
32
  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;
33
  vlistptr->vars[varID].timetype      = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
34
35
36
  vlistptr->vars[varID].tsteptype     = TSTEP_INSTANT;
  vlistptr->vars[varID].timave        = 0;
  vlistptr->vars[varID].timaccu       = 0;
37
  vlistptr->vars[varID].productDefinitionTemplate = -1;
38
  vlistptr->vars[varID].chunktype     = cdiChunkType;
39
  vlistptr->vars[varID].xyz           = 321;
Deike Kleberg's avatar
Deike Kleberg committed
40
41
  vlistptr->vars[varID].gridID        = CDI_UNDEFID;
  vlistptr->vars[varID].zaxisID       = CDI_UNDEFID;
42
  vlistptr->vars[varID].subtypeID     = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
43
44
45
  vlistptr->vars[varID].instID        = CDI_UNDEFID;
  vlistptr->vars[varID].modelID       = CDI_UNDEFID;
  vlistptr->vars[varID].tableID       = CDI_UNDEFID;
46
  vlistptr->vars[varID].missvalused   = false;
Deike Kleberg's avatar
Deike Kleberg committed
47
48
49
50
51
52
53
  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;
54
  vlistptr->vars[varID].extra         = NULL;
Deike Kleberg's avatar
Deike Kleberg committed
55
  vlistptr->vars[varID].levinfo       = NULL;
56
  vlistptr->vars[varID].comptype      = CDI_COMPRESS_NONE;
Deike Kleberg's avatar
Deike Kleberg committed
57
  vlistptr->vars[varID].complevel     = 1;
58
59
  vlistptr->vars[varID].keys.nalloc   = MAX_KEYS;
  vlistptr->vars[varID].keys.nelems   = 0;
Deike Kleberg's avatar
Deike Kleberg committed
60
61
  vlistptr->vars[varID].atts.nalloc   = MAX_ATTRIBUTES;
  vlistptr->vars[varID].atts.nelems   = 0;
62
  vlistptr->vars[varID].lvalidrange   = false;
Deike Kleberg's avatar
Deike Kleberg committed
63
64
  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
static
int vlistvarNewEntry(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
74
75
{
  int varID = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
77
78
  int vlistvarSize = vlistptr->varsAllocated;
  var_t *vlistvar = vlistptr->vars;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
80
81
82
83
84
85
  /*
    Look for a free slot in vlistvar.
    (Create the table the first time through).
  */
  if ( ! vlistvarSize )
    {
      vlistvarSize = 2;
86
      vlistvar = (var_t *) Malloc((size_t)vlistvarSize * sizeof (var_t));
87
88
      for ( int i = 0; i < vlistvarSize; i++ )
	vlistvar[i].isUsed = false;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
90
91
    }
  else
    {
Thomas Jahns's avatar
Thomas Jahns committed
92
93
      while (varID < vlistvarSize && vlistvar[varID].isUsed)
        ++varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
95
96
97
98
99
    }
  /*
    If the table overflows, double its size.
  */
  if ( varID == vlistvarSize )
    {
100
      vlistvar = (var_t *) Realloc(vlistvar,
Thomas Jahns's avatar
Thomas Jahns committed
101
102
                                   (size_t)(vlistvarSize *= 2) * sizeof(var_t));
      for ( int i = varID; i < vlistvarSize; i++ )
103
	vlistvar[i].isUsed = false;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
104
105
106
107
108
109
110
    }

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

  vlistvarInitEntry(vlistID, varID);

111
  vlistptr->vars[varID].isUsed = true;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112

Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
  return varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
115
}

116
void vlistCheckVarID(const char *caller, int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
120

  if ( vlistptr == NULL )
121
    Errorc("vlist undefined!");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
123

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

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

130

131
int vlistDefVarTiles(int vlistID, int gridID, int zaxisID, int timetype, int tilesetID)
132
133
{
  if ( CDI_Debug )
134
    Message("gridID = %d  zaxisID = %d  timetype = %d", gridID, zaxisID, timetype);
135
136
137

  int varID = vlistvarNewEntry(vlistID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
139
  vlistptr->nvars++;
140
141
  vlistptr->vars[varID].gridID    = gridID;
  vlistptr->vars[varID].zaxisID   = zaxisID;
142
  vlistptr->vars[varID].timetype = timetype;
143
144
  vlistptr->vars[varID].subtypeID = tilesetID;

145
  if ( timetype < 0 )
146
    {
147
148
      Message("Unexpected time type %d, set to TIME_VARYING!", timetype);
      vlistptr->vars[varID].timetype = TIME_VARYING;
149
150
151
152
153
154
155
156
    }

  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);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
158

  return varID;
159
160
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
162
/*
@Function  vlistDefVar
Uwe Schulzweida's avatar
Uwe Schulzweida committed
163
@Title     Define a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
164

165
@Prototype int vlistDefVar(int vlistID, int gridID, int zaxisID, int timetype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
166
@Parameter
167
168
169
    @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}.
170
171
    @Item  timetype  One of the set of predefined CDI timestep types.
                     The valid CDI timestep types are @func{TIME_CONSTANT} and @func{TIME_VARYING}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
172
173

@Description
174
The function @func{vlistDefVar} adds a new variable to vlistID.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
175
176

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

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

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

212
  vlistptr->vars[varID].levinfo
213
    = (levinfo_t*) Malloc((size_t)nlevs * sizeof(levinfo_t));
214

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

219
220
221
222
223
224
/*
@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
225
226
227
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
    @Item  param    Parameter number.
228
229
230
231
232
233
234
235

@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
236
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
237

238
  vlistCheckVarID(__func__, vlistID, varID);
239

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
247
248
/*
@Function  vlistDefVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
@Title     Define the code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
251
252

@Prototype void vlistDefVarCode(int vlistID, int varID, int code)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
253
254
255
    @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
256
257

@Description
258
The function @func{vlistDefVarCode} defines the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
260
261
262
263

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

266
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
267

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


280
void vlistInqVar(int vlistID, int varID, int *gridID, int *zaxisID, int *timetype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
281
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
282
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
283

284
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285

286
287
288
  *gridID   = vlistptr->vars[varID].gridID;
  *zaxisID  = vlistptr->vars[varID].zaxisID;
  *timetype = vlistptr->vars[varID].timetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
289
290
291
292

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
293
294
295
296
297
298
/*
@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
299
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
300
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
301
302

@Description
303
The function @func{vlistInqVarGrid} returns the grid ID of a Variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
304
305

@Result
306
@func{vlistInqVarGrid} returns the grid ID of the Variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
307
308
309

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
310
311
int vlistInqVarGrid(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
312
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
313

314
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
315

Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
  return vlistptr->vars[varID].gridID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
317
318
}

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

@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
336
337
int vlistInqVarZaxis(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
339

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
  return vlistptr->vars[varID].zaxisID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
343
344
}

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362

/*
@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);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
363
364

  return vlistptr->vars[varID].subtypeID;
365
366
367
}


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

@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
387
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
388

389
  vlistCheckVarID(__func__, vlistID, varID);
390

Uwe Schulzweida's avatar
Uwe Schulzweida committed
391
  return vlistptr->vars[varID].param;
392
393
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
/*
@Function  vlistInqVarCode
Uwe Schulzweida's avatar
Uwe Schulzweida committed
396
@Title     Get the Code number of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
397
398
399

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

@Description
404
The function @func{vlistInqVarCode} returns the code number of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
405
406

@Result
407
@func{vlistInqVarCode} returns the code number of the variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
408
409
410
411
412

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

415
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
416

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
428
  return code;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
429
430
431
}


432
const char *vlistInqVarNamePtr(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
433
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
434
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
435

436
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
437

Uwe Schulzweida's avatar
Uwe Schulzweida committed
438
  return vlistptr->vars[varID].name;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
439
440
441
442
}

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

445
@Prototype void vlistInqVarName(int vlistID, int varID, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
446
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
447
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
448
    @Item  varID    Variable identifier.
449
    @Item  name     Returned variable name. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
450
                    returned string. The maximum possible length, in characters, of
451
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
452
453

@Description
454
The function @func{vlistInqVarName} returns the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
455
456

@Result
457
458
@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
459
460
461
462
463

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

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

  if ( vlistptr->vars[varID].name == NULL )
    {
470
471
      int param = vlistptr->vars[varID].param;
      int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
472
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
473
474
475
      if ( pdis == 255 )
	{
	  int code = pnum;
476
	  int tableID = vlistptr->vars[varID].tableID;
477
478
479
          name[0] = 0;
          tableInqEntry(tableID, code, -1, name, NULL, NULL);
	  if ( !name[0] ) sprintf(name, "var%d", code);
480
481
482
483
484
	}
      else
	{
	  sprintf(name, "param%d.%d.%d", pnum, pcat, pdis);
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
485
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
486
  else
487
    strcpy(name, vlistptr->vars[varID].name);   //FIXME: This may overrun the provided buffer.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488
489
490
491

  return;
}

492
493
494
495
496
497
498
499
500
/*
@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.

501
@Return A pointer to a malloc'ed string. Must be cleaned up with Free().
502
503
504

@Description
This is the buffer overflow immune version of vlistInqVarName().
505
The memory for the returned string is allocated to fit the string via Malloc().
506
507
508
509
510
511
512
513
514

@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.
515
516
517
518
  {
    const char* name = vlistptr->vars[varId].name;
    if (name) return strdup(name);
  }
519
520
521
522
523

  //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);
524
  char *result = NULL;
525
  if (discipline == 255)
526
527
    {
      int tableId = vlistptr->vars[varId].tableID;
528
      char name[CDI_MAX_NAME]; name[0] = 0;
529
      tableInqEntry(tableId, number, -1, name, NULL, NULL);
530
      if ( name[0] )
531
        result = strdup(name);
532
533
534
535
536
537
      else
        {
          //No luck, fall back to outputting a name of the format "var<num>".
          result = (char *) Malloc(3 + 3 * sizeof (int) * CHAR_BIT / 8 + 2);
          sprintf(result, "var%d", number);
        }
538
539
540
    }
  else
    {
541
      result = (char *) Malloc(5 + 2 + 3 * (3 * sizeof (int) * CHAR_BIT + 1) + 1);
542
      sprintf(result, "param%d.%d.%d", number, category, discipline);
543
544
    }
  //Finally, we fall back to outputting a name of the format "param<num>.<cat>.<dis>".
545
  return result;
546
547
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
548
549
/*
@Function  vlistInqVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
550
@Title     Get the longname of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
551
552
553

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

@Description
561
562
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
563
564

@Result
565
@func{vlistInqVaeLongname} returns the longname of the variable to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
566
567
568
569
570

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

573
574
575
  vlistCheckVarID(__func__, vlistID, varID);

  longname[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
576
577
578

  if ( vlistptr->vars[varID].longname == NULL )
    {
579
580
      int param = vlistptr->vars[varID].param;
      int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
581
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
582
583
584
      if ( pdis == 255 )
	{
	  int code = pnum;
585
          int tableID = vlistptr->vars[varID].tableID;
586
          tableInqEntry(tableID, code, -1, NULL, longname, NULL);
587
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
588
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
589
590
591
592
593
594
  else
    strcpy(longname, vlistptr->vars[varID].longname);

  return;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
595
596
597
598
599
600
/*
@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
601
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}.
Deike Kleberg's avatar
Deike Kleberg committed
602
    @Item  varID    Variable identifier.
603
    @Item  stdname  Standard name of the variable. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
604
                    returned string. The maximum possible length, in characters, of
605
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
606
607

@Description
608
609
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
610
611

@Result
612
@func{vlistInqVarStdname} returns the standard name of the variable to the parameter stdname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
613
614
615

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
616
617
void vlistInqVarStdname(int vlistID, int varID, char *stdname)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
618
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
619

620
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
621
622
623

  if ( vlistptr->vars[varID].stdname == NULL )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
624
      stdname[0] = '\0';
625
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
626
627
628
629
630
631
632
633
  else
    strcpy(stdname, vlistptr->vars[varID].stdname);

  return;
}

/*
@Function  vlistInqVarUnits
Uwe Schulzweida's avatar
Uwe Schulzweida committed
634
@Title     Get the units of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
635
636
637

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

@Description
645
646
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
647
648

@Result
649
@func{vlistInqVarUnits} returns the units of the variable to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
650
651
652
653
654

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

657
658
659
  vlistCheckVarID(__func__, vlistID, varID);

  units[0] = '\0';
Uwe Schulzweida's avatar
Uwe Schulzweida committed
660
661
662

  if ( vlistptr->vars[varID].units == NULL )
    {
663
664
      int param = vlistptr->vars[varID].param;
      int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
665
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
666
667
668
      if ( pdis == 255 )
	{
	  int code = pnum;
669
	  int tableID = vlistptr->vars[varID].tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
670
          tableInqEntry(tableID, code, -1, NULL, NULL, units);
671
	}
672
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
673
674
675
676
677
678
  else
    strcpy(units, vlistptr->vars[varID].units);

  return;
}

679
/* used in MPIOM ! */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
680
int vlistInqVarID(int vlistID, int code)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
681
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
682
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
683

684
  for ( int varID = 0; varID < vlistptr->nvars; varID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
685
    {
686
687
      int param = vlistptr->vars[varID].param;
      int pdis, pcat, pnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
688
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
689
      if ( pnum == code ) return varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
690
691
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
692
  return CDI_UNDEFID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
693
}
694

Uwe Schulzweida's avatar
Uwe Schulzweida committed
695

696
size_t vlistInqVarSize(int vlistID, int varID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
697
{
698
  vlistCheckVarID(__func__, vlistID, varID);
699

700
701
  int zaxisID, gridID, timetype;
  vlistInqVar(vlistID, varID, &gridID, &zaxisID, &timetype);
702

703
  size_t nlevs = (size_t)zaxisInqSize(zaxisID);
704

705
  size_t gridsize = gridInqSize(gridID);
706

707
  size_t size = gridsize*nlevs;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
708

Uwe Schulzweida's avatar
Uwe Schulzweida committed
709
  return size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
710
711
712
713
}

/*
@Function  vlistInqVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
714
@Title     Get the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
715
716
717

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

@Description
Uwe Schulzweida's avatar
Uwe Schulzweida committed
722
The function @func{vlistInqVarDatatype} returns the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
723
724

@Result
Uwe Schulzweida's avatar
Uwe Schulzweida committed
725
@func{vlistInqVarDatatype} returns an identifier to the data type of the variable.
726
727
728
The valid CDI data types are @func{CDI_DATATYPE_PACK8}, @func{CDI_DATATYPE_PACK16}, @func{CDI_DATATYPE_PACK24},
@func{CDI_DATATYPE_FLT32}, @func{CDI_DATATYPE_FLT64}, @func{CDI_DATATYPE_INT8}, @func{CDI_DATATYPE_INT16} and 
@func{CDI_DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
729
730
731
732
733

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

736
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
737

Uwe Schulzweida's avatar
Uwe Schulzweida committed
738
  return vlistptr->vars[varID].datatype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
739
740
741
}


742
743
int vlistInqVarNumber(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
744
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
745

746
  vlistCheckVarID(__func__, vlistID, varID);
747

748
  int number = CDI_REAL;
749
750
  if ( vlistptr->vars[varID].datatype == CDI_DATATYPE_CPX32 ||
       vlistptr->vars[varID].datatype == CDI_DATATYPE_CPX64 )
751
752
    number = CDI_COMP;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
  return number;
754
755
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
756
757
/*
@Function  vlistDefVarDatatype
Uwe Schulzweida's avatar
Uwe Schulzweida committed
758
@Title     Define the data type of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
759
760
761

@Prototype void vlistDefVarDatatype(int vlistID, int varID, int datatype)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
762
763
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
764
    @Item  datatype The data type identifier.
765
766
767
                    The valid CDI data types are @func{CDI_DATATYPE_PACK8}, @func{CDI_DATATYPE_PACK16},
                    @func{CDI_DATATYPE_PACK24}, @func{CDI_DATATYPE_FLT32}, @func{CDI_DATATYPE_FLT64},
                    @func{CDI_DATATYPE_INT8}, @func{CDI_DATATYPE_INT16} and @func{CDI_DATATYPE_INT32}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
768
769

@Description
770
The function @func{vlistDefVarDatatype} defines the data type of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
771
772
773
774
775

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

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

780
781
782
783
  if (vlistptr->vars[varID].datatype != datatype)
    {
      vlistptr->vars[varID].datatype = datatype;

784
      if ( !vlistptr->vars[varID].missvalused )
785
786
        switch (datatype)
          {
787
788
789
790
791
792
          case CDI_DATATYPE_INT8:   vlistptr->vars[varID].missval = -SCHAR_MAX; break;
          case CDI_DATATYPE_UINT8:  vlistptr->vars[varID].missval =  UCHAR_MAX; break;
          case CDI_DATATYPE_INT16:  vlistptr->vars[varID].missval = -SHRT_MAX;  break;
          case CDI_DATATYPE_UINT16: vlistptr->vars[varID].missval =  USHRT_MAX; break;
          case CDI_DATATYPE_INT32:  vlistptr->vars[varID].missval = -INT_MAX;   break;
          case CDI_DATATYPE_UINT32: vlistptr->vars[varID].missval =  UINT_MAX;  break;
793
          }
Thomas Jahns's avatar
Thomas Jahns committed
794
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
795
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
796
797
}

798

Uwe Schulzweida's avatar
Uwe Schulzweida committed
799
800
void vlistDefVarInstitut(int vlistID, int varID, int instID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
801
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
802
803
804
  if (vlistptr->vars[varID].instID != instID)
    {
      vlistptr->vars[varID].instID = instID;
Thomas Jahns's avatar
Thomas Jahns committed
805
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
806
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
808
}

809

Uwe Schulzweida's avatar
Uwe Schulzweida committed
810
811
int vlistInqVarInstitut(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
812
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
813
  return vlistptr->vars[varID].instID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
814
815
}

816

Uwe Schulzweida's avatar
Uwe Schulzweida committed
817
818
void vlistDefVarModel(int vlistID, int varID, int modelID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
819
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
820
821
822
  if (vlistptr->vars[varID].modelID != modelID)
    {
      vlistptr->vars[varID].modelID = modelID;
Thomas Jahns's avatar
Thomas Jahns committed
823
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
824
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
825
826
}

827

Uwe Schulzweida's avatar
Uwe Schulzweida committed
828
829
int vlistInqVarModel(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
830
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
831
  return vlistptr->vars[varID].modelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
832
833
}

834

Uwe Schulzweida's avatar
Uwe Schulzweida committed
835
836
void vlistDefVarTable(int vlistID, int varID, int tableID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
837
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
838

839
840
841
842
  if (vlistptr->vars[varID].tableID != tableID)
    {
      vlistptr->vars[varID].tableID = tableID;
      int tablenum = tableInqNum(tableID);
843

844
      int param = vlistptr->vars[varID].param;
845

846
847
848
      int pnum, pcat, pdis;
      cdiDecodeParam(param, &pnum, &pcat, &pdis);
      vlistptr->vars[varID].param = cdiEncodeParam(pnum, tablenum, pdis);
Thomas Jahns's avatar
Thomas Jahns committed
849
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
850
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
851
852
}

853

Uwe Schulzweida's avatar
Uwe Schulzweida committed
854
855
int vlistInqVarTable(int vlistID, int varID)
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
856
  vlist_t *vlistptr = vlist_to_pointer(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
857
  return vlistptr->vars[varID].tableID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
858
859
860
861
}

/*
@Function  vlistDefVarName
Uwe Schulzweida's avatar
Uwe Schulzweida committed
862
@Title     Define the name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
863
864
865

@Prototype void vlistDefVarName(int vlistID, int varID, const char *name)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
866
867
868
    @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
869
870

@Description
871
The function @func{vlistDefVarName} defines the name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
872
873
874
875
876

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

879
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
880

881
  if ( name )
882
    {
883
884
      if ( vlistptr->vars[varID].name )
	{
885
	  Free(vlistptr->vars[varID].name);
886
887
	  vlistptr->vars[varID].name = NULL;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
888

889
      vlistptr->vars[varID].name = strdupx(name);
Thomas Jahns's avatar
Thomas Jahns committed
890
      reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
891
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
892
893
894
895
}

/*
@Function  vlistDefVarLongname
Uwe Schulzweida's avatar
Uwe Schulzweida committed
896
@Title     Define the long name of a Variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
897
898
899

@Prototype void vlistDefVarLongname(int vlistID, int varID, const char *longname)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
900
901
902
    @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
903
904

@Description
905
The function @func{vlistDefVarLongname} defines the long name of a variable.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
906
907
908
909
910

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

913
  vlistCheckVarID(__func__, vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
914

915
  if ( longname )
916
    {
917
918
      if ( vlistptr->vars[varID].longname )
	{
919
	  Free(vlistptr->vars[varID].longname);
920
921
	  vlistptr->vars[varID].longname = 0;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
922

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