zaxis.c 49 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 "cdi_uuid.h"
15
#include "resource_handle.h"
16
#include "resource_unpack.h"
17
#include "varscan.h"
Deike Kleberg's avatar
Deike Kleberg committed
18
#include "namespace.h"
19
#include "serialize.h"
20
#include "zaxis.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
21

Deike Kleberg's avatar
Deike Kleberg committed
22
23
24
25
#define  LevelUp    1
#define  LevelDown  2


Thomas Jahns's avatar
Thomas Jahns committed
26
static const struct {
27
  unsigned char positive;   // 1: up;  2: down
Oliver Heidmann's avatar
Oliver Heidmann committed
28
29
30
31
  const char *name;
  const char *longname;
  const char *stdname;
  const char *units;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
}
33
ZaxistypeEntry[] = {
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  { /*  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",              "",               ""},
59
  { /* 25 */ 0, "height",            "generalized_height",     "height",         ""},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
60
61
};

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
66
67

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

96
static int    zaxisCompareP    (zaxis_t *z1, zaxis_t *z2);
Deike Kleberg's avatar
Deike Kleberg committed
97
98
static void   zaxisDestroyP    ( void * zaxisptr );
static void   zaxisPrintP      ( void * zaxisptr, FILE * fp );
99
100
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
101
static int    zaxisTxCode      ( void );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102

Thomas Jahns's avatar
Thomas Jahns committed
103
static const resOps zaxisOps = {
104
  (int (*)(void *, void *))zaxisCompareP,
105
106
107
108
109
  zaxisDestroyP,
  zaxisPrintP,
  zaxisGetPackSize,
  zaxisPack,
  zaxisTxCode
110
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111

112
const resOps *getZaxisOps(void)
113
114
115
116
{
  return &zaxisOps;
}

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

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
void zaxisGetTypeDescription(int zaxisType, int* outPositive, const char** outName, const char** outLongName, const char** outStdName, const char** outUnit)
{
  if(zaxisType < 0 || zaxisType >= CDI_NumZaxistype)
    {
      if(outPositive) *outPositive = 0;
      if(outName) *outName = NULL;
      if(outLongName) *outLongName = NULL;
      if(outStdName) *outStdName = NULL;
      if(outUnit) *outUnit = NULL;
    }
  else
    {
      if(outPositive) *outPositive = ZaxistypeEntry[zaxisType].positive;
      if(outName) *outName = ZaxistypeEntry[zaxisType].name;
      if(outLongName) *outLongName = ZaxistypeEntry[zaxisType].longname;
      if(outStdName) *outStdName = ZaxistypeEntry[zaxisType].stdname;
      if(outUnit) *outUnit = ZaxistypeEntry[zaxisType].units;
    }
}

139
static
140
void zaxisDefaultValue(zaxis_t *zaxisptr)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
141
{
142
  zaxisptr->self        = CDI_UNDEFID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
144
  zaxisptr->name[0]     = 0;
  zaxisptr->longname[0] = 0;
Deike Kleberg's avatar
Deike Kleberg committed
145
  zaxisptr->stdname[0]  = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
146
  zaxisptr->units[0]    = 0;
147
  zaxisptr->psname[0]   = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
150
151
152
  zaxisptr->vals        = NULL;
  zaxisptr->ubounds     = NULL;
  zaxisptr->lbounds     = NULL;
  zaxisptr->weights     = NULL;
  zaxisptr->type        = CDI_UNDEFID;
153
  zaxisptr->ltype       = 0;
154
  zaxisptr->ltype2      = -1;
Deike Kleberg's avatar
Deike Kleberg committed
155
  zaxisptr->positive    = 0;
156
  zaxisptr->scalar      = 0;
Deike Kleberg's avatar
Deike Kleberg committed
157
  zaxisptr->direction   = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
159
160
161
  zaxisptr->prec        = 0;
  zaxisptr->size        = 0;
  zaxisptr->vctsize     = 0;
  zaxisptr->vct         = NULL;
162
  zaxisptr->number      = 0;
163
  zaxisptr->nhlev       = 0;
Thomas Jahns's avatar
Thomas Jahns committed
164
  memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
166

167

168
static
169
zaxis_t *zaxisNewEntry(int id)
170
{
171
  zaxis_t *zaxisptr = (zaxis_t *) Malloc(sizeof(zaxis_t));
172
173

  zaxisDefaultValue ( zaxisptr );
174

175
176
177
178
179
180
181
  if (id == CDI_UNDEFID)
    zaxisptr->self = reshPut(zaxisptr, &zaxisOps);
  else
    {
      zaxisptr->self = id;
      reshReplace(id, zaxisptr, &zaxisOps);
    }
182
183

  return (zaxisptr);
184
185
}

186
187
188
189
190
191
192
static inline zaxis_t *
zaxisID2Ptr(int id)
{
  return (zaxis_t *)reshGetVal(id, &zaxisOps);
}


193
static
194
void zaxisInit(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
195
{
196
197
  static int zaxisInitialized = 0;
  char *env;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
198

199
  if ( zaxisInitialized ) return;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200

Thomas Jahns's avatar
Thomas Jahns committed
201
  zaxisInitialized = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
202

203
204
  env = getenv("ZAXIS_DEBUG");
  if ( env ) ZAXIS_Debug = atoi(env);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
205
206
}

207
208
static
void zaxis_copy(zaxis_t *zaxisptr2, zaxis_t *zaxisptr1)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
209
{
210
  int zaxisID2 = zaxisptr2->self;
211
  memcpy(zaxisptr2, zaxisptr1, sizeof(zaxis_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
212
213
214
  zaxisptr2->self = zaxisID2;
}

215
unsigned cdiZaxisCount(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
216
{
217
  return reshCountType(&zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
218
219
}

220

221
222
223
224
225
static int
zaxisCreate_(int zaxistype, int size, int id)
{
  zaxis_t *zaxisptr = zaxisNewEntry(id);

226
  xassert(size >= 0);
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
  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;

243
  double *vals = zaxisptr->vals
244
    = (double *) Malloc((size_t)size * sizeof(double));
245
246
247
248
249
250
251

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

  return zaxisID;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
252
253

/*
254
@Function  zaxisCreate
255
@Title     Create a vertical Z-axis
Uwe Schulzweida's avatar
Uwe Schulzweida committed
256

257
@Prototype int zaxisCreate(int zaxistype, int size)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
259
@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
260
                      The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
261
                      @func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
262
263
                      @func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
                      @func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
264
                      @func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
265
266
                      @func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
                      @func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
267
                      @func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Deike Kleberg's avatar
Deike Kleberg committed
268
    @Item  size       Number of levels.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
269
270

@Description
271
The function @func{zaxisCreate} creates a vertical Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
272
273

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
276
@Example
277
Here is an example using @func{zaxisCreate} to create a pressure level Z-axis:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
279
280
281

@Source
#include "cdi.h"
   ...
282
#define  nlev    5
Uwe Schulzweida's avatar
Uwe Schulzweida committed
283
   ...
284
double levs[nlev] = {101300, 92500, 85000, 50000, 20000};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
286
int zaxisID;
   ...
287
zaxisID = zaxisCreate(ZAXIS_PRESSURE, nlev);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
288
289
290
zaxisDefLevels(zaxisID, levs);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
291
292
@EndFunction
*/
293
int zaxisCreate(int zaxistype, int size)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
294
{
295
296
  if ( CDI_Debug )
    Message("zaxistype: %d size: %d ", zaxistype, size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
297

298
299
  zaxisInit ();
  return zaxisCreate_(zaxistype, size, CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
300
301
}

302

303
static void zaxisDestroyKernel( zaxis_t * zaxisptr )
304
{
Deike Kleberg's avatar
Deike Kleberg committed
305
  xassert ( zaxisptr );
306

307
  int id = zaxisptr->self;
308

Uwe Schulzweida's avatar
Uwe Schulzweida committed
309
310
311
312
313
  if ( zaxisptr->vals )    Free( zaxisptr->vals );
  if ( zaxisptr->lbounds ) Free( zaxisptr->lbounds );
  if ( zaxisptr->ubounds ) Free( zaxisptr->ubounds );
  if ( zaxisptr->weights ) Free( zaxisptr->weights );
  if ( zaxisptr->vct )     Free( zaxisptr->vct );
314

Uwe Schulzweida's avatar
Uwe Schulzweida committed
315
  Free( zaxisptr );
316

317
  reshRemove ( id, &zaxisOps );
318
319
}

320
321
322
323
324
325
/*
@Function  zaxisDestroy
@Title     Destroy a vertical Z-axis

@Prototype void zaxisDestroy(int zaxisID)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
326
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
327
328
329
330
331

@EndFunction
*/
void zaxisDestroy(int zaxisID)
{
332
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
333

334
  zaxisDestroyKernel ( zaxisptr );
335
336
337
}


338
static
339
void zaxisDestroyP ( void * zaxisptr )
340
{
341
  zaxisDestroyKernel (( zaxis_t * ) zaxisptr );
342
343
344
}


Oliver Heidmann's avatar
Oliver Heidmann committed
345
const char *zaxisNamePtr(int zaxistype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
{
Oliver Heidmann's avatar
Oliver Heidmann committed
347
  const char *name = (zaxistype >= 0 && zaxistype < CDI_NumZaxistype)
348
349
    ? ZaxistypeEntry[zaxistype].longname
    : ZaxistypeEntry[ZAXIS_GENERIC].longname;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
350
351
352
353
354
355
356
357
358
  return (name);
}


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

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
static inline
void zaxisSetString(char *zaxisstrname, const char *name, size_t len)
{
  if ( len > CDI_MAX_NAME ) len = CDI_MAX_NAME;
  strncpy(zaxisstrname, name, len);
  zaxisstrname[len - 1] = 0;
}

static inline
void zaxisGetString(char *name, const char *zaxisstrname, size_t len)
{
  if ( len > CDI_MAX_NAME ) len = CDI_MAX_NAME;
  strncpy(name, zaxisstrname, len);
  name[len - 1] = 0;
}

static
char *zaxis_key_to_string(zaxis_t *zaxisptr, int key)
{
  char *zaxisstring = NULL;

  switch (key)
    {
    case CDI_ZAXIS_DIMNAME:  zaxisstring = zaxisptr->dimname; break;
    case CDI_ZAXIS_VDIMNAME: zaxisstring = zaxisptr->vdimname; break;
    }

  return zaxisstring;
}

/*
@Function  cdiZaxisDefString
@Title     Define a CDI Z-axis string value from a key

@Prototype int cdiZaxisDefString(int zaxisID, int key, int size, const char *mesg)
@Parameter
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  key      The key to be searched
    @Item  size     The allocated length of the string on input
    @Item  mesg     The address of a string where the data will be read

@Description
The function @func{cdiZaxisDefString} defines a CDI Z-axis string value from a key.

@Result
@func{cdiZaxisDefString} returns 0 if OK and integer value on error.

@EndFunction
*/
int cdiZaxisDefString(int zaxisID, int key, int size, const char *mesg)
{
  if ( size == 0 || mesg == NULL || *mesg == 0 ) return -1;

  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);

  char *zaxisstring = zaxis_key_to_string(zaxisptr, key);
  if ( zaxisstring == NULL)
    {
      Warning("CDI zaxis string key %d not supported!", key);
      return -1;
    }

  zaxisSetString(zaxisstring, mesg, size);
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);

  return 0;
}

/*
@Function  cdiZaxisInqString
@Title     Get a CDI Z-axis string value from a key

@Prototype int cdiZaxisInqString(int zaxisID, int key, int size, char *mesg)
@Parameter
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
    @Item  key      The key to be searched.
    @Item  size     The allocated length of the string on input.
    @Item  mesg     The address of a string where the data will be retrieved.
                    The caller must allocate space for the returned string.
                    The maximum possible length, in characters, of the string
                    is given by the predefined constant @func{CDI_MAX_NAME}.

@Description
The function @func{cdiZaxisInqString} return a CDI Z-axis string value from a key.

@Result
@func{cdiZaxisInqString} returns 0 if OK and integer value on error.

@EndFunction
*/
int cdiZaxisInqString(int zaxisID, int key, int size, char *mesg)
{
  if ( size == 0 || mesg == NULL ) return -1;

  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
  const char *zaxisstring = zaxis_key_to_string(zaxisptr, key);
  if ( zaxisstring == NULL)
    {
      Warning("CDI zaxis string key %d not supported!", key);
      return -1;
    }

  zaxisGetString(mesg, zaxisstring, size);

  return 0;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
466
467
468
469
470
471
/*
@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
472
473
    @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
474
475

@Description
476
The function @func{zaxisDefName} defines the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
477
478
479
480
481

@EndFunction
*/
void zaxisDefName(int zaxisID, const char *name)
{
482
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
483

Uwe Schulzweida's avatar
Uwe Schulzweida committed
484
  if ( name )
485
486
487
    {
      strncpy(zaxisptr->name, name, CDI_MAX_NAME - 1);
      zaxisptr->name[CDI_MAX_NAME - 1] = '\0';
488
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
489
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
490
491
492
493
494
495
496
497
}

/*
@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
498
499
    @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
500
501

@Description
502
The function @func{zaxisDefLongname} defines the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
503
504
505
506
507

@EndFunction
*/
void zaxisDefLongname(int zaxisID, const char *longname)
{
508
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
509

Uwe Schulzweida's avatar
Uwe Schulzweida committed
510
  if ( longname )
511
512
513
    {
      strncpy(zaxisptr->longname, longname, CDI_MAX_NAME - 1);
      zaxisptr->longname[CDI_MAX_NAME - 1] = '\0';
514
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
515
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
516
517
518
519
520
521
522
523
}

/*
@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
524
525
    @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
526
527

@Description
528
The function @func{zaxisDefUnits} defines the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
529
530
531
532
533

@EndFunction
*/
void zaxisDefUnits(int zaxisID, const char *units)
{
534
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
535

Uwe Schulzweida's avatar
Uwe Schulzweida committed
536
  if ( units )
537
538
539
    {
      strncpy(zaxisptr->units, units, CDI_MAX_NAME - 1);
      zaxisptr->units[CDI_MAX_NAME - 1] = '\0';
540
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
541
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
542
543
}

544
545
546
547
548
549
550
551
552
553
554
555
556

void zaxisDefPsName(int zaxisID, const char *psname)
{
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);

  if ( psname )
    {
      strncpy(zaxisptr->psname, psname, CDI_MAX_NAME - 1);
      zaxisptr->name[CDI_MAX_NAME - 1] = '\0';
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
557
558
559
560
561
562
/*
@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
563
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
564
    @Item  name     Name of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
565
                    returned string. The maximum possible length, in characters, of
566
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
567
568

@Description
569
The function @func{zaxisInqName} returns the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
570
571

@Result
572
@func{zaxisInqName} returns the name of the Z-axis to the parameter name.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
573
574
575
576
577

@EndFunction
*/
void zaxisInqName(int zaxisID, char *name)
{
578
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
  strcpy(name, zaxisptr->name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
581
582
583
584
585
586
587
}

/*
@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
588
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
589
    @Item  longname Longname of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
590
                    returned string. The maximum possible length, in characters, of
591
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
592
593

@Description
594
The function @func{zaxisInqLongname} returns the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
595
596

@Result
597
@func{zaxisInqLongname} returns the longname of the Z-axis to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
598
599
600
601
602

@EndFunction
*/
void zaxisInqLongname(int zaxisID, char *longname)
{
603
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
604
  strcpy(longname, zaxisptr->longname);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
605
606
607
608
609
610
611
612
}

/*
@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
613
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
614
    @Item  units    Units of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
615
                    returned string. The maximum possible length, in characters, of
616
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
617
618

@Description
619
The function @func{zaxisInqUnits} returns the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
620
621

@Result
622
@func{zaxisInqUnits} returns the units of the Z-axis to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
624
625
626
627

@EndFunction
*/
void zaxisInqUnits(int zaxisID, char *units)
{
628
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
629
  strcpy(units, zaxisptr->units);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
630
631
632
}


Deike Kleberg's avatar
Deike Kleberg committed
633
634
void zaxisInqStdname(int zaxisID, char *stdname)
{
635
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Deike Kleberg's avatar
Deike Kleberg committed
636
637
638
639
  strcpy(stdname, zaxisptr->stdname);
}


640
641
642
643
644
645
646
void zaxisInqPsName(int zaxisID, char *psname)
{
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
  strcpy(psname, zaxisptr->psname);
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
647
648
void zaxisDefPrec(int zaxisID, int prec)
{
649
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
650

651
652
653
654
655
  if (zaxisptr->prec != prec)
    {
      zaxisptr->prec = prec;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
656
657
658
659
660
}


int zaxisInqPrec(int zaxisID)
{
661
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
  return (zaxisptr->prec);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
663
664
665
}


666
667
void zaxisDefPositive(int zaxisID, int positive)
{
668
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
669

670
671
  if (zaxisptr->positive != positive)
    {
672
      zaxisptr->positive = (unsigned char)positive;
673
674
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
675
676
677
}


Deike Kleberg's avatar
Deike Kleberg committed
678
679
int zaxisInqPositive(int zaxisID)
{
680
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
681
  return zaxisptr->positive;
Deike Kleberg's avatar
Deike Kleberg committed
682
683
684
}


685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
void zaxisDefScalar(int zaxisID)
{
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);

  zaxisptr->scalar = 1;
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
}

int zaxisInqScalar(int zaxisID)
{
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
  return zaxisptr->scalar;
}


700
701
void zaxisDefLtype(int zaxisID, int ltype)
{
702
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
703

704
705
706
707
708
  if (zaxisptr->ltype != ltype)
    {
      zaxisptr->ltype = ltype;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
709
710
711
712
713
}


int zaxisInqLtype(int zaxisID)
{
714
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
715
  return zaxisptr->ltype;
716
717
}

718
719
720

void zaxisDefLtype2(int zaxisID, int ltype2)
{
721
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
722
723
724
725
726
727
728
729
730
731
732

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


int zaxisInqLtype2(int zaxisID)
{
733
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
734
  return zaxisptr->ltype2;
735
736
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
737
738
739
740
/*
@Function  zaxisDefLevels
@Title     Define the levels of a Z-axis

Uwe Schulzweida's avatar
Uwe Schulzweida committed
741
@Prototype void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
742
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
743
744
    @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
745
746

@Description
747
The function @func{zaxisDefLevels} defines the levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
748
749
750

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
751
void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
752
{
753
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
754

755
  int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
756

757
  double *vals = zaxisptr->vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
758

759
  for (int ilev = 0; ilev < size; ilev++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
760
    vals[ilev] = levels[ilev];
761
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
762
763
764
765
766
767
768
769
}

/*
@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
770
771
772
    @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
773
774

@Description
775
The function @func{zaxisDefLevel} defines one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
776
777
778
779
780

@EndFunction
*/
void zaxisDefLevel(int zaxisID, int levelID, double level)
{
781
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
782
783
  if ( levelID >= 0 && levelID < zaxisptr->size )
    zaxisptr->vals[levelID] = level;
784
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
785
786
}

787
788
789

void zaxisDefNlevRef(int zaxisID, const int nhlev)
{
790
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
791
792
793
794
795
  if (zaxisptr->nhlev != nhlev)
    {
      zaxisptr->nhlev = nhlev;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
796
797
798
799
800
}


int zaxisInqNlevRef(int zaxisID)
{
801
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
802
  return zaxisptr->nhlev;
803
804
}

805
/*
806
807
@Function  zaxisDefNumber
@Title     Define the reference number for a generalized Z-axis
808

809
@Prototype void zaxisDefNumber(int zaxisID, const int number)
810
811
@Parameter
    @Item  zaxisID     Z-axis ID, from a previous call to @fref{zaxisCreate}.
812
    @Item  number      Reference number for a generalized Z-axis.
813
814

@Description
815
The function @func{zaxisDefNumber} defines the reference number for a generalized Z-axis.
816
817
818

@EndFunction
*/
819
void zaxisDefNumber(int zaxisID, const int number)
820
{
821
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
822
823
824
825
826
  if (zaxisptr->number != number)
    {
      zaxisptr->number = number;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
827
828
}

829
830
831
832
833
834
/*
@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
835
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
836
837
838
839
840
841
842
843
844
845

@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)
{
846
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
847
  return zaxisptr->number;
848
849
}

850
851
852
853
854
855
856
857
858
859
860
861
862
863
/*
@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
*/
864
void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
865
{
866
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
867
  memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
868
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
869
870
871
872
}

/*
@Function  zaxisInqUUID
873
@Title     Get the uuid to a generalized Z-axis
874

875
@Prototype void zaxisInqUUID(int zaxisID, char *uuid)
876
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
877
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
878
    @Item uuid A user supplied buffer of at least 16 bytes.
879
880
881
882
883

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

@Result
884
@func{zaxisInqUUID} returns the UUID to a generalized Z-axis to the parameter uuid.
885
886
@EndFunction
*/
887
void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
888
{
889
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
890
  memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
891
892
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
893
894
895
896
897
898
/*
@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
899
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
900
    @Item  levelID  Level index (range: 0 to nlevel-1).
Uwe Schulzweida's avatar
Uwe Schulzweida committed
901
902

@Description
903
The function @func{zaxisInqLevel} returns one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
904
905

@Result
906
@func{zaxisInqLevel} returns the level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
907
908
909
910
911
@EndFunction
*/
double zaxisInqLevel(int zaxisID, int levelID)
{
  double level = 0;
912
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
913

Uwe Schulzweida's avatar
Uwe Schulzweida committed
914
915
  if ( levelID >= 0 && levelID < zaxisptr->size )
    level = zaxisptr->vals[levelID];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
916

917
  return level;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
918
919
920
921
922
}

double zaxisInqLbound(int zaxisID, int index)
{
  double level = 0;
923
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
924

925
  if ( zaxisptr->lbounds && ( index >= 0 && index < zaxisptr->size ) )
926
      level = zaxisptr->lbounds[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
927

928
  return level;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
929
930
931
932
933
934
}


double zaxisInqUbound(int zaxisID, int index)
{
  double level = 0;
935
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
936

937
938
939
  if ( zaxisptr->ubounds && ( index >= 0 && index < zaxisptr->size ) )
    level = zaxisptr->ubounds[index];
  return level;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
940
941
942
943
944
}


const double *zaxisInqLevelsPtr(int zaxisID)
{
945
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
946
  return zaxisptr->vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
947
948
949
950
951
952
953
954
}

/*
@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
955
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
956
957
    @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
958

Uwe Schulzweida's avatar
Uwe Schulzweida committed
959
@Description
960
The function @func{zaxisInqLevels} returns all levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
961
962

@Result
963
@func{zaxisInqLevels} saves all levels to the parameter @func{levels}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
964
965
966
967
@EndFunction
*/
void zaxisInqLevels(int zaxisID, double *levels)
{
968
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Thomas Jahns's avatar
Thomas Jahns committed
969
970
  int size = zaxisptr->size;
  for (int i = 0; i < size; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
971
    levels[i] =  zaxisptr->vals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
972
973
974
975
976
977
}


int zaxisInqLbounds(int zaxisID, double *lbounds)
{
  int size = 0;
978
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
979

Uwe Schulzweida's avatar
Uwe Schulzweida committed
980
  if ( zaxisptr->lbounds )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
981
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
982
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
983
984

      if ( lbounds )
Thomas Jahns's avatar
Thomas Jahns committed
985
        for (int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
986
          lbounds[i] =  zaxisptr->lbounds[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
987
988
989
990
991
992
993
994
995
    }

  return (size);
}


int zaxisInqUbounds(int zaxisID, double *ubounds)
{
  int size = 0;
996
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
997

Uwe Schulzweida's avatar
Uwe Schulzweida committed
998
  if ( zaxisptr->ubounds )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
999
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1000
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1001
1002

      if ( ubounds )
Thomas Jahns's avatar
Thomas Jahns committed
1003
        for (int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
1004
          ubounds[i] =  zaxisptr->ubounds[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1005
1006
1007
1008
1009
1010
1011
1012
1013
    }

  return (size);
}


int zaxisInqWeights(int zaxisID, double *weights)
{
  int size = 0;
1014
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1015

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1016
  if ( zaxisptr->weights )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1017
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1018
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1019
1020

      if ( weights )
Thomas Jahns's avatar
Thomas Jahns committed
1021
        for ( int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
1022
          weights[i] =  zaxisptr->weights[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1023
1024
1025
1026
1027
1028
1029
1030
1031
    }

  return (size);
}


int zaxisInqLevelID(int zaxisID, double level)
{
  int levelID = CDI_UNDEFID;
1032
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1033

Thomas Jahns's avatar
Thomas Jahns committed
1034
1035
1036
1037
1038
1039
1040
  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
1041

1042
  return levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1043
1044
1045
1046
1047
1048
1049
1050
}

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

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

@Description
1054
The function @func{zaxisInqType} returns the type of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1055
1056

@Result
1057
@func{zaxisInqType} returns the type of the Z-axis,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1058
one of the set of predefined CDI Z-axis types.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1059
The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1060
@func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
1061
1062
@func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
@func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
1063
@func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
1064
1065
@func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
@func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
1066
@func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1067
1068
1069
1070
1071

@EndFunction
*/
int zaxisInqType(int zaxisID)
{
1072
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1073
  return (zaxisptr->type);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1074
1075
1076
1077
1078
1079
1080
1081
}

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

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

@Description
1085
The function @func{zaxisInqSize} returns the size of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1086
1087

@Result
1088
@func{zaxisInqSize} returns the number of levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1089
1090
1091
1092
1093

@EndFunction
*/
int zaxisInqSize(int zaxisID)
{
1094
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
1095
  return (zaxisptr->size);