zaxis.c 44.4 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
8
9
10
11
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include <string.h>
#include <math.h>
#include <float.h>

#include "dmemory.h"

#include "cdi.h"
12
#include "cdi_cksum.h"
13
#include "cdi_int.h"
14
#include "resource_handle.h"
15
#include "resource_unpack.h"
16
#include "varscan.h"
Deike Kleberg's avatar
Deike Kleberg committed
17
#include "namespace.h"
18
#include "serialize.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
19

Deike Kleberg's avatar
Deike Kleberg committed
20
21
22
23
#define  LevelUp    1
#define  LevelDown  2


Thomas Jahns's avatar
Thomas Jahns committed
24
static const struct {
25
  unsigned char positive;   // 1: up;  2: down
Uwe Schulzweida's avatar
Uwe Schulzweida committed
26
27
  char *name;
  char *longname;
Deike Kleberg's avatar
Deike Kleberg committed
28
  char *stdname;
29
  char *units;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
}
31
ZaxistypeEntry[] = {
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
  { /*  0 */ 0, "sfc",               "surface",                "",               ""},
  { /*  1 */ 0, "lev",               "generic",                "",               "level"},
  { /*  2 */ 2, "lev",               "hybrid",                 "",               "level"},
  { /*  3 */ 2, "lev",               "hybrid_half",            "",               "level"},
  { /*  4 */ 2, "lev",               "pressure",               "air_pressure",   "Pa"},
  { /*  5 */ 1, "height",            "height",                 "height",         "m"},
  { /*  6 */ 2, "depth",             "depth_below_sea",        "depth",          "m"},
  { /*  7 */ 2, "depth",             "depth_below_land",       "",               "cm"},
  { /*  8 */ 0, "lev",               "isentropic",             "",               "K"},
  { /*  9 */ 0, "lev",               "trajectory",             "",               ""},
  { /* 10 */ 1, "alt",               "altitude",               "",               "m"},
  { /* 11 */ 0, "lev",               "sigma",                  "",               "level"},
  { /* 12 */ 0, "lev",               "meansea",                "",               "level"},
  { /* 13 */ 0, "toa",               "top_of_atmosphere",      "",               ""},
  { /* 14 */ 0, "seabottom",         "sea_bottom",             "",               ""},
  { /* 15 */ 0, "atmosphere",        "atmosphere",             "",               ""},
  { /* 16 */ 0, "cloudbase",         "cloud_base",             "",               ""},
  { /* 17 */ 0, "cloudtop",          "cloud_top",              "",               ""},
  { /* 18 */ 0, "isotherm0",         "isotherm_zero",          "",               ""},
  { /* 19 */ 0, "snow",              "snow",                   "",               ""},
  { /* 20 */ 0, "lakebottom",        "lake_bottom",            "",               ""},
  { /* 21 */ 0, "sedimentbottom",    "sediment_bottom",        "",               ""},
  { /* 22 */ 0, "sedimentbottomta",  "sediment_bottom_ta",     "",               ""},
  { /* 23 */ 0, "sedimentbottomtw",  "sediment_bottom_tw",     "",               ""},
  { /* 24 */ 0, "mixlayer",          "mix_layer",              "",               ""},
57
  { /* 25 */ 0, "height",            "generalized height",     "height",         ""},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
58
59
};

60
enum {
61
  CDI_NumZaxistype = sizeof(ZaxistypeEntry) / sizeof(ZaxistypeEntry[0]),
62
};
63

Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65

typedef struct {
Deike Kleberg's avatar
Deike Kleberg committed
66
  unsigned char positive;
Deike Kleberg's avatar
Deike Kleberg committed
67
68
69
70
  char     name[CDI_MAX_NAME];
  char     longname[CDI_MAX_NAME];
  char     stdname[CDI_MAX_NAME];
  char     units[CDI_MAX_NAME];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
71
72
73
74
  double  *vals;
  double  *lbounds;
  double  *ubounds;
  double  *weights;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
  int      self;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
77
  int      prec;
  int      type;
78
  int      ltype;    /* GRIB level type */
79
  int      ltype2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
81
82
83
  int      size;
  int      direction;
  int      vctsize;
  double  *vct;
84
  int      number;   /* Reference number to a generalized Z-axis */
85
  int      nhlev;
86
  unsigned char uuid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
}
88
zaxis_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89

90
static int zaxisCompareP(zaxis_t *z1, zaxis_t *z2);
Deike Kleberg's avatar
Deike Kleberg committed
91
92
static void   zaxisDestroyP    ( void * zaxisptr );
static void   zaxisPrintP      ( void * zaxisptr, FILE * fp );
93
94
static int    zaxisGetPackSize ( void * zaxisptr, void *context);
static void   zaxisPack        ( void * zaxisptr, void * buffer, int size, int *pos, void *context);
Deike Kleberg's avatar
Deike Kleberg committed
95
static int    zaxisTxCode      ( void );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96

97
static const resOps zaxisOps = {
98
  (int (*)(void *, void *))zaxisCompareP,
99
100
101
102
103
  zaxisDestroyP,
  zaxisPrintP,
  zaxisGetPackSize,
  zaxisPack,
  zaxisTxCode
104
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
105

106
static int  ZAXIS_Debug = 0;   /* If set to 1, debugging */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107

108
static
109
void zaxisDefaultValue(zaxis_t *zaxisptr)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
{
111
  zaxisptr->self        = CDI_UNDEFID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
113
  zaxisptr->name[0]     = 0;
  zaxisptr->longname[0] = 0;
Deike Kleberg's avatar
Deike Kleberg committed
114
  zaxisptr->stdname[0]  = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
116
117
118
119
120
  zaxisptr->units[0]    = 0;
  zaxisptr->vals        = NULL;
  zaxisptr->ubounds     = NULL;
  zaxisptr->lbounds     = NULL;
  zaxisptr->weights     = NULL;
  zaxisptr->type        = CDI_UNDEFID;
121
  zaxisptr->ltype       = 0;
122
  zaxisptr->ltype2      = -1;
Deike Kleberg's avatar
Deike Kleberg committed
123
124
  zaxisptr->positive    = 0;
  zaxisptr->direction   = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
125
126
127
128
  zaxisptr->prec        = 0;
  zaxisptr->size        = 0;
  zaxisptr->vctsize     = 0;
  zaxisptr->vct         = NULL;
129
  zaxisptr->number      = 0;
130
  zaxisptr->nhlev       = 0;
Thomas Jahns's avatar
Thomas Jahns committed
131
  memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133

134

135
static
136
zaxis_t *zaxisNewEntry(int id)
137
{
138
  zaxis_t *zaxisptr = (zaxis_t *)xmalloc(sizeof(zaxis_t));
139
140

  zaxisDefaultValue ( zaxisptr );
141

142
143
144
145
146
147
148
  if (id == CDI_UNDEFID)
    zaxisptr->self = reshPut(zaxisptr, &zaxisOps);
  else
    {
      zaxisptr->self = id;
      reshReplace(id, zaxisptr, &zaxisOps);
    }
149
150

  return (zaxisptr);
151
152
}

153
static
154
void zaxisInit(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
155
{
156
157
  static int zaxisInitialized = 0;
  char *env;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
158

159
  if ( zaxisInitialized ) return;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
160

Thomas Jahns's avatar
Thomas Jahns committed
161
  zaxisInitialized = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162

163
164
  env = getenv("ZAXIS_DEBUG");
  if ( env ) ZAXIS_Debug = atoi(env);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
166
}

167
168
static
void zaxis_copy(zaxis_t *zaxisptr2, zaxis_t *zaxisptr1)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
{
170
  int zaxisID2 = zaxisptr2->self;
171
  memcpy(zaxisptr2, zaxisptr1, sizeof(zaxis_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
172
173
174
175
  zaxisptr2->self = zaxisID2;
}

int zaxisSize(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
176
{
177
  return reshCountType ( &zaxisOps );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
178
179
}

180
181
182
183
184
static int
zaxisCreate_(int zaxistype, int size, int id)
{
  zaxis_t *zaxisptr = zaxisNewEntry(id);

185
  xassert(size >= 0);
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  zaxisptr->type = zaxistype;
  zaxisptr->size = size;

  if ( zaxistype >= CDI_NumZaxistype || zaxistype < 0 )
    Error("Internal problem! zaxistype > CDI_MaxZaxistype");

  int zaxisID = zaxisptr->self;
  zaxisDefName(zaxisID, ZaxistypeEntry[zaxistype].name);
  zaxisDefLongname(zaxisID, ZaxistypeEntry[zaxistype].longname);
  zaxisDefUnits(zaxisID, ZaxistypeEntry[zaxistype].units);

  if ( *ZaxistypeEntry[zaxistype].stdname )
    strcpy(zaxisptr->stdname, ZaxistypeEntry[zaxistype].stdname);

  zaxisptr->positive = ZaxistypeEntry[zaxistype].positive;

202
203
  double *vals = zaxisptr->vals
    = (double *)xmalloc((size_t)size * sizeof(double));
204
205
206
207
208
209
210

  for ( int ilev = 0; ilev < size; ilev++ )
    vals[ilev] = 0.0;

  return zaxisID;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
211
212

/*
213
@Function  zaxisCreate
214
@Title     Create a vertical Z-axis
Uwe Schulzweida's avatar
Uwe Schulzweida committed
215

216
@Prototype int zaxisCreate(int zaxistype, int size)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
217
218
@Parameter
    @Item  zaxistype  The type of the Z-axis, one of the set of predefined CDI Z-axis types.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
219
                      The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
220
                      @func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
221
222
                      @func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
                      @func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
223
                      @func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
224
225
                      @func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
                      @func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
226
                      @func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Deike Kleberg's avatar
Deike Kleberg committed
227
    @Item  size       Number of levels.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
228
229

@Description
230
The function @func{zaxisCreate} creates a vertical Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
231
232

@Result
233
@func{zaxisCreate} returns an identifier to the Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
234

Uwe Schulzweida's avatar
Uwe Schulzweida committed
235
@Example
236
Here is an example using @func{zaxisCreate} to create a pressure level Z-axis:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
238
239
240

@Source
#include "cdi.h"
   ...
241
#define  nlev    5
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
   ...
243
double levs[nlev] = {101300, 92500, 85000, 50000, 20000};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
244
245
int zaxisID;
   ...
246
zaxisID = zaxisCreate(ZAXIS_PRESSURE, nlev);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
247
248
249
zaxisDefLevels(zaxisID, levs);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
251
@EndFunction
*/
252
int zaxisCreate(int zaxistype, int size)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
{
254
255
  if ( CDI_Debug )
    Message("zaxistype: %d size: %d ", zaxistype, size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
256

257
258
  zaxisInit ();
  return zaxisCreate_(zaxistype, size, CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
260
}

261

262
static void zaxisDestroyKernel( zaxis_t * zaxisptr )
263
264
265
{
  int id;

Deike Kleberg's avatar
Deike Kleberg committed
266
  xassert ( zaxisptr );
267
268
269

  id = zaxisptr->self;

270
  if ( zaxisptr->vals )    free ( zaxisptr->vals );
271
272
273
  if ( zaxisptr->lbounds ) free ( zaxisptr->lbounds );
  if ( zaxisptr->ubounds ) free ( zaxisptr->ubounds );
  if ( zaxisptr->weights ) free ( zaxisptr->weights );
274
  if ( zaxisptr->vct )     free ( zaxisptr->vct );
275
276
277

  free ( zaxisptr );

278
  reshRemove ( id, &zaxisOps );
279
280
}

281
282
283
284
285
286
/*
@Function  zaxisDestroy
@Title     Destroy a vertical Z-axis

@Prototype void zaxisDestroy(int zaxisID)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
287
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
288
289
290
291
292

@EndFunction
*/
void zaxisDestroy(int zaxisID)
{
293
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
294

295
  zaxisDestroyKernel ( zaxisptr );
296
297
298
}


299
static
300
void zaxisDestroyP ( void * zaxisptr )
301
{
302
  zaxisDestroyKernel (( zaxis_t * ) zaxisptr );
303
304
305
}


306
char *zaxisNamePtr(int zaxistype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
307
308
309
{
  char *name;

310
  if ( zaxistype >= 0 && zaxistype < CDI_NumZaxistype )
311
    name = ZaxistypeEntry[zaxistype].longname;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
312
  else
313
    name = ZaxistypeEntry[ZAXIS_GENERIC].longname;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

  return (name);
}


void zaxisName(int zaxistype, char *zaxisname)
{
  strcpy(zaxisname, zaxisNamePtr(zaxistype));
}

/*
@Function  zaxisDefName
@Title     Define the name of a Z-axis

@Prototype void zaxisDefName(int zaxisID, const char *name)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
330
331
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  name     Name of the Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
332
333

@Description
334
The function @func{zaxisDefName} defines the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
335
336
337
338
339

@EndFunction
*/
void zaxisDefName(int zaxisID, const char *name)
{
340
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
341

Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
  if ( name )
343
344
345
    {
      strncpy(zaxisptr->name, name, CDI_MAX_NAME - 1);
      zaxisptr->name[CDI_MAX_NAME - 1] = '\0';
346
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
347
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
349
350
351
352
353
354
355
}

/*
@Function  zaxisDefLongname
@Title     Define the longname of a Z-axis

@Prototype void zaxisDefLongname(int zaxisID, const char *longname)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
356
357
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  longname Longname of the Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
358
359

@Description
360
The function @func{zaxisDefLongname} defines the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
361
362
363
364
365

@EndFunction
*/
void zaxisDefLongname(int zaxisID, const char *longname)
{
366
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367

Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
  if ( longname )
369
370
371
    {
      strncpy(zaxisptr->longname, longname, CDI_MAX_NAME - 1);
      zaxisptr->longname[CDI_MAX_NAME - 1] = '\0';
372
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
373
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
374
375
376
377
378
379
380
381
}

/*
@Function  zaxisDefUnits
@Title     Define the units of a Z-axis

@Prototype void zaxisDefUnits(int zaxisID, const char *units)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
382
383
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  units    Units of the Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
384
385

@Description
386
The function @func{zaxisDefUnits} defines the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
387
388
389
390
391

@EndFunction
*/
void zaxisDefUnits(int zaxisID, const char *units)
{
392
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
393

Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
  if ( units )
395
396
397
    {
      strncpy(zaxisptr->units, units, CDI_MAX_NAME - 1);
      zaxisptr->units[CDI_MAX_NAME - 1] = '\0';
398
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
399
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
400
401
402
403
404
405
406
407
}

/*
@Function  zaxisInqName
@Title     Get the name of a Z-axis

@Prototype void zaxisInqName(int zaxisID, char *name)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
408
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
409
    @Item  name     Name of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
410
                    returned string. The maximum possible length, in characters, of
411
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
412
413

@Description
414
The function @func{zaxisInqName} returns the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
415
416

@Result
417
@func{zaxisInqName} returns the name of the Z-axis to the parameter name.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
418
419
420
421
422

@EndFunction
*/
void zaxisInqName(int zaxisID, char *name)
{
Thomas Jahns's avatar
Thomas Jahns committed
423
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
424
  strcpy(name, zaxisptr->name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
426
427
428
429
430
431
432
}

/*
@Function  zaxisInqLongname
@Title     Get the longname of a Z-axis

@Prototype void zaxisInqLongname(int zaxisID, char *longname)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
433
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
434
    @Item  longname Longname of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
435
                    returned string. The maximum possible length, in characters, of
436
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
437
438

@Description
439
The function @func{zaxisInqLongname} returns the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
440
441

@Result
442
@func{zaxisInqLongname} returns the longname of the Z-axis to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
443
444
445
446
447

@EndFunction
*/
void zaxisInqLongname(int zaxisID, char *longname)
{
Thomas Jahns's avatar
Thomas Jahns committed
448
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
449
  strcpy(longname, zaxisptr->longname);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
450
451
452
453
454
455
456
457
}

/*
@Function  zaxisInqUnits
@Title     Get the units of a Z-axis

@Prototype void zaxisInqUnits(int zaxisID, char *units)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
458
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
459
    @Item  units    Units of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
460
                    returned string. The maximum possible length, in characters, of
461
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
462
463

@Description
464
The function @func{zaxisInqUnits} returns the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
465
466

@Result
467
@func{zaxisInqUnits} returns the units of the Z-axis to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
468
469
470
471
472

@EndFunction
*/
void zaxisInqUnits(int zaxisID, char *units)
{
Thomas Jahns's avatar
Thomas Jahns committed
473
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
474
  strcpy(units, zaxisptr->units);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
475
476
477
}


Deike Kleberg's avatar
Deike Kleberg committed
478
479
void zaxisInqStdname(int zaxisID, char *stdname)
{
Thomas Jahns's avatar
Thomas Jahns committed
480
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Deike Kleberg's avatar
Deike Kleberg committed
481
482
483
484
  strcpy(stdname, zaxisptr->stdname);
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
485
486
void zaxisDefPrec(int zaxisID, int prec)
{
487
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488

489
490
491
492
493
  if (zaxisptr->prec != prec)
    {
      zaxisptr->prec = prec;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
494
495
496
497
498
}


int zaxisInqPrec(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
499
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
500

Uwe Schulzweida's avatar
Uwe Schulzweida committed
501
  return (zaxisptr->prec);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
502
503
504
}


505
506
void zaxisDefPositive(int zaxisID, int positive)
{
507
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
508

509
510
  if (zaxisptr->positive != positive)
    {
511
      zaxisptr->positive = (unsigned char)positive;
512
513
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
514
515
516
}


Deike Kleberg's avatar
Deike Kleberg committed
517
518
int zaxisInqPositive(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
519
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Deike Kleberg's avatar
Deike Kleberg committed
520
521
522
523
524

  return (zaxisptr->positive);
}


525
526
void zaxisDefLtype(int zaxisID, int ltype)
{
527
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
528

529
530
531
532
533
  if (zaxisptr->ltype != ltype)
    {
      zaxisptr->ltype = ltype;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
534
535
536
537
538
}


int zaxisInqLtype(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
539
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
540
541
542
543

  return (zaxisptr->ltype);
}

544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563

void zaxisDefLtype2(int zaxisID, int ltype2)
{
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);

  if (zaxisptr->ltype2 != ltype2)
    {
      zaxisptr->ltype2 = ltype2;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
}


int zaxisInqLtype2(int zaxisID)
{
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);

  return (zaxisptr->ltype2);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
564
565
566
567
/*
@Function  zaxisDefLevels
@Title     Define the levels of a Z-axis

Uwe Schulzweida's avatar
Uwe Schulzweida committed
568
@Prototype void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
569
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
570
571
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  levels   All levels of the Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
572
573

@Description
574
The function @func{zaxisDefLevels} defines the levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
575
576
577

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
578
void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
{
580
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
581

582
  int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
583

584
  double *vals = zaxisptr->vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
585

586
  for (int ilev = 0; ilev < size; ilev++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
587
    vals[ilev] = levels[ilev];
588
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
589
590
591
592
593
594
595
596
}

/*
@Function  zaxisDefLevel
@Title     Define one level of a Z-axis

@Prototype void zaxisDefLevel(int zaxisID, int levelID, double level)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
597
598
599
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  levelID  Level identifier.
    @Item  level    Level.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
600
601

@Description
602
The function @func{zaxisDefLevel} defines one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
603
604
605
606
607

@EndFunction
*/
void zaxisDefLevel(int zaxisID, int levelID, double level)
{
608
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
609

Uwe Schulzweida's avatar
Uwe Schulzweida committed
610
611
  if ( levelID >= 0 && levelID < zaxisptr->size )
    zaxisptr->vals[levelID] = level;
612
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
613
614
}

615
616
617

void zaxisDefNlevRef(int zaxisID, const int nhlev)
{
618
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
619

620
621
622
623
624
  if (zaxisptr->nhlev != nhlev)
    {
      zaxisptr->nhlev = nhlev;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
625
626
627
628
629
}


int zaxisInqNlevRef(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
630
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
631

Thomas Jahns's avatar
Thomas Jahns committed
632
  return (zaxisptr->nhlev);
633
634
}

635
/*
636
637
@Function  zaxisDefNumber
@Title     Define the reference number for a generalized Z-axis
638

639
@Prototype void zaxisDefNumber(int zaxisID, const int number)
640
641
@Parameter
    @Item  zaxisID     Z-axis ID, from a previous call to @fref{zaxisCreate}.
642
    @Item  number      Reference number for a generalized Z-axis.
643
644

@Description
645
The function @func{zaxisDefNumber} defines the reference number for a generalized Z-axis.
646
647
648

@EndFunction
*/
649
void zaxisDefNumber(int zaxisID, const int number)
650
{
651
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
652

653
654
655
656
657
  if (zaxisptr->number != number)
    {
      zaxisptr->number = number;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
658
659
}

660
661
662
663
664
665
/*
@Function  zaxisInqNumber
@Title     Get the reference number to a generalized Z-axis

@Prototype int zaxisInqNumber(int zaxisID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
666
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
667
668
669
670
671
672
673
674
675
676

@Description
The function @func{zaxisInqNumber} returns the reference number to a generalized Z-axis.

@Result
@func{zaxisInqNumber} returns the reference number to a generalized Z-axis.
@EndFunction
*/
int zaxisInqNumber(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
677
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
678

Thomas Jahns's avatar
Thomas Jahns committed
679
  return (zaxisptr->number);
680
681
}

682
683
684
685
686
687
688
689
690
691
692
693
694
695
/*
@Function  zaxisDefUUID
@Title     Define the UUID for a genralized Z-axis

@Prototype void zaxisDefUUID(int zaxisID, const char *uuid)
@Parameter
    @Item  zaxisID     Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  uuid        UUID for a generalized Z-axis.

@Description
The function @func{zaxisDefUUID} defines the UUID for a generalized  Z-axis.

@EndFunction
*/
696
void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
697
{
698
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
699

700
  memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
701
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
702
703
704
705
}

/*
@Function  zaxisInqUUID
706
@Title     Get the uuid to a generalized Z-axis
707

708
@Prototype void zaxisInqUUID(int zaxisID, char *uuid)
709
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
710
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
711
712
713
714
715

@Description
The function @func{zaxisInqUUID} returns the UUID to a generalized Z-axis.

@Result
716
@func{zaxisInqUUID} returns the UUID to a generalized Z-axis to the parameter uuid.
717
718
@EndFunction
*/
719
void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
720
{
Thomas Jahns's avatar
Thomas Jahns committed
721
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
722
  memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
723
724
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
725
726
727
728
729
730
/*
@Function  zaxisInqLevel
@Title     Get one level of a Z-axis

@Prototype double zaxisInqLevel(int zaxisID, int levelID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
731
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
732
    @Item  levelID  Level index (range: 0 to nlevel-1).
Uwe Schulzweida's avatar
Uwe Schulzweida committed
733
734

@Description
735
The function @func{zaxisInqLevel} returns one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
736
737

@Result
738
@func{zaxisInqLevel} returns the level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
739
740
741
742
743
@EndFunction
*/
double zaxisInqLevel(int zaxisID, int levelID)
{
  double level = 0;
Thomas Jahns's avatar
Thomas Jahns committed
744
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
745

Uwe Schulzweida's avatar
Uwe Schulzweida committed
746
747
  if ( levelID >= 0 && levelID < zaxisptr->size )
    level = zaxisptr->vals[levelID];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
748
749
750
751
752
753
754

  return (level);
}

double zaxisInqLbound(int zaxisID, int index)
{
  double level = 0;
Thomas Jahns's avatar
Thomas Jahns committed
755
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
756

757
758
759
  if ( zaxisptr->lbounds )
    if ( index >= 0 && index < zaxisptr->size )
      level = zaxisptr->lbounds[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
760
761
762
763
764
765
766
767

  return (level);
}


double zaxisInqUbound(int zaxisID, int index)
{
  double level = 0;
Thomas Jahns's avatar
Thomas Jahns committed
768
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
769

770
771
772
  if ( zaxisptr->ubounds )
    if ( index >= 0 && index < zaxisptr->size )
      level = zaxisptr->ubounds[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
773
774
775
776
777
778
779

  return (level);
}


const double *zaxisInqLevelsPtr(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
780
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
781
  return ( zaxisptr->vals );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
782
783
784
785
786
787
788
789
}

/*
@Function  zaxisInqLevels
@Title     Get all levels of a Z-axis

@Prototype void zaxisInqLevels(int zaxisID, double *levels)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
790
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
791
792
    @Item  levels   Pointer to the location into which the levels are read.
                    The caller must allocate space for the returned values.
Deike Kleberg's avatar
Deike Kleberg committed
793

Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
@Description
795
The function @func{zaxisInqLevels} returns all levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
796
797

@Result
798
@func{zaxisInqLevels} saves all levels to the parameter @func{levels}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
799
800
801
802
@EndFunction
*/
void zaxisInqLevels(int zaxisID, double *levels)
{
Thomas Jahns's avatar
Thomas Jahns committed
803
804
805
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
  int size = zaxisptr->size;
  for (int i = 0; i < size; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
806
    levels[i] =  zaxisptr->vals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
808
809
810
811
812
}


int zaxisInqLbounds(int zaxisID, double *lbounds)
{
  int size = 0;
Thomas Jahns's avatar
Thomas Jahns committed
813
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
814

Uwe Schulzweida's avatar
Uwe Schulzweida committed
815
  if ( zaxisptr->lbounds )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
817
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
818
819

      if ( lbounds )
Thomas Jahns's avatar
Thomas Jahns committed
820
        for (int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
821
          lbounds[i] =  zaxisptr->lbounds[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
822
823
824
825
826
827
828
829
830
    }

  return (size);
}


int zaxisInqUbounds(int zaxisID, double *ubounds)
{
  int size = 0;
Thomas Jahns's avatar
Thomas Jahns committed
831
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
832

Uwe Schulzweida's avatar
Uwe Schulzweida committed
833
  if ( zaxisptr->ubounds )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
834
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
835
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
836
837

      if ( ubounds )
Thomas Jahns's avatar
Thomas Jahns committed
838
        for (int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
839
          ubounds[i] =  zaxisptr->ubounds[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
840
841
842
843
844
845
846
847
848
    }

  return (size);
}


int zaxisInqWeights(int zaxisID, double *weights)
{
  int size = 0;
Thomas Jahns's avatar
Thomas Jahns committed
849
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
850

Uwe Schulzweida's avatar
Uwe Schulzweida committed
851
  if ( zaxisptr->weights )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
852
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
853
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
854
855

      if ( weights )
Thomas Jahns's avatar
Thomas Jahns committed
856
        for ( int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
857
          weights[i] =  zaxisptr->weights[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
858
859
860
861
862
863
864
865
866
    }

  return (size);
}


int zaxisInqLevelID(int zaxisID, double level)
{
  int levelID = CDI_UNDEFID;
Thomas Jahns's avatar
Thomas Jahns committed
867
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
868

Thomas Jahns's avatar
Thomas Jahns committed
869
870
871
872
873
874
875
  int size = zaxisptr->size;
  for ( int i = 0; i < size; i++ )
    if ( fabs(level-zaxisptr->vals[i]) < DBL_EPSILON )
      {
        levelID = i;
        break;
      }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
876
877
878
879
880
881
882
883
884
885

  return (levelID);
}

/*
@Function  zaxisInqType
@Title     Get the type of a Z-axis

@Prototype int zaxisInqType(int zaxisID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
886
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
887
888

@Description
889
The function @func{zaxisInqType} returns the type of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
890
891

@Result
892
@func{zaxisInqType} returns the type of the Z-axis,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
893
one of the set of predefined CDI Z-axis types.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
894
The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
895
@func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
896
897
@func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
@func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
898
@func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
899
900
@func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
@func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
901
@func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
902
903
904
905
906

@EndFunction
*/
int zaxisInqType(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
907
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
908
  return (zaxisptr->type);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
909
910
911
912
913
914
915
916
}

/*
@Function  zaxisInqSize
@Title     Get the size of a Z-axis

@Prototype int zaxisInqSize(int zaxisID)
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
917
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
918
919

@Description
920
The function @func{zaxisInqSize} returns the size of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
921
922

@Result
923
@func{zaxisInqSize} returns the number of levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
924
925
926
927
928

@EndFunction
*/
int zaxisInqSize(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
929
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
930
  return (zaxisptr->size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
931
932
933
934
935
}


void cdiCheckZaxis(int zaxisID)
{
Thomas Jahns's avatar
Thomas Jahns committed
936
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Thomas Jahns's avatar
Thomas Jahns committed
937

Uwe Schulzweida's avatar
Uwe Schulzweida committed
938
939
  if ( zaxisInqType(zaxisID) == ZAXIS_GENERIC )
    {
Thomas Jahns's avatar
Thomas Jahns committed
940
      int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
941
      if ( size > 1 )
942
943
944
945
        {
          /* check direction */
          if ( ! zaxisptr->direction )
            {
Thomas Jahns's avatar
Thomas Jahns committed
946
947
948
949
950
951
952
              int ups = 0, downs = 0;
              for ( int i = 1; i < size; i++ )
                {
                  ups += (zaxisptr->vals[i] > zaxisptr->vals[i-1]);
                  downs += (zaxisptr->vals[i] < zaxisptr->vals[i-1]);
                }
              if ( ups == size-1 )
953
954
955
                {
                  zaxisptr->direction = LevelUp;
                }
Thomas Jahns's avatar
Thomas Jahns committed
956
              else if ( downs == size-1 )
957
                {
Thomas Jahns's avatar
Thomas Jahns committed
958
959
960
961
962
                  zaxisptr->direction = LevelDown;
                }
              else /* !zaxisptr->direction */
                {
                  Warning("Direction undefined for zaxisID %d", zaxisID);
963
964
965
                }
            }
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
966
967
968
969
970
971
    }
}


void zaxisDefVct(int zaxisID, int size, const double *vct)
{
972
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
973

Uwe Schulzweida's avatar
Uwe Schulzweida committed
974
  if ( zaxisptr->vct == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
975
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
976
      zaxisptr->vctsize = size;
977
978
      zaxisptr->vct = (double *)xmalloc((size_t)size * sizeof (double));
      memcpy(zaxisptr->vct, vct, (size_t)size * sizeof (double));
979
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
980
981
    }
  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
982
    if ( zaxisptr->vctsize != size )
983
      Warning("VCT was already defined");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
984
985
986
}


987
988
void zaxisInqVct(int zaxisID, double *vct)
{
989
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
990
  memcpy(vct, zaxisptr->vct, (size_t)zaxisptr->vctsize * sizeof (double));
991
992
993
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
994
995
int zaxisInqVctSize(int zaxisID)
{
996
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
997
  return (zaxisptr->vctsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
998
999
1000
1001
1002
}


const double *zaxisInqVctPtr(int zaxisID)
{
1003
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1004
  return (zaxisptr->vct);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1005
1006
1007
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
1008
void zaxisDefLbounds(int zaxisID, const double *lbounds)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1009
{
1010
  zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1011

1012
  size_t size = (size_t)zaxisptr->size;
Thomas Jahns's avatar
Thomas Jahns committed
1013

1014
1015
  if ( CDI_Debug )
    if ( zaxisptr->lbounds != NULL )
1016
      Warning("Lower bounds already defined for zaxisID = %d", zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1017

1018
  if ( zaxisptr->lbounds == NULL )
1019
    zaxisptr->lbounds = (double *)xmalloc(size*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1020