zaxis.c 45.7 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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;
    }
}

128
static
129
void zaxisDefaultValue(zaxis_t *zaxisptr)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
{
131
  zaxisptr->self        = CDI_UNDEFID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
133
  zaxisptr->name[0]     = 0;
  zaxisptr->longname[0] = 0;
Deike Kleberg's avatar
Deike Kleberg committed
134
  zaxisptr->stdname[0]  = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
135
136
137
138
139
140
  zaxisptr->units[0]    = 0;
  zaxisptr->vals        = NULL;
  zaxisptr->ubounds     = NULL;
  zaxisptr->lbounds     = NULL;
  zaxisptr->weights     = NULL;
  zaxisptr->type        = CDI_UNDEFID;
141
  zaxisptr->ltype       = 0;
142
  zaxisptr->ltype2      = -1;
Deike Kleberg's avatar
Deike Kleberg committed
143
144
  zaxisptr->positive    = 0;
  zaxisptr->direction   = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146
147
148
  zaxisptr->prec        = 0;
  zaxisptr->size        = 0;
  zaxisptr->vctsize     = 0;
  zaxisptr->vct         = NULL;
149
  zaxisptr->number      = 0;
150
  zaxisptr->nhlev       = 0;
Thomas Jahns's avatar
Thomas Jahns committed
151
  memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
153

154

155
static
156
zaxis_t *zaxisNewEntry(int id)
157
{
158
  zaxis_t *zaxisptr = (zaxis_t *)xmalloc(sizeof(zaxis_t));
159
160

  zaxisDefaultValue ( zaxisptr );
161

162
163
164
165
166
167
168
  if (id == CDI_UNDEFID)
    zaxisptr->self = reshPut(zaxisptr, &zaxisOps);
  else
    {
      zaxisptr->self = id;
      reshReplace(id, zaxisptr, &zaxisOps);
    }
169
170

  return (zaxisptr);
171
172
}

173
static
174
void zaxisInit(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
175
{
176
177
  static int zaxisInitialized = 0;
  char *env;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
178

179
  if ( zaxisInitialized ) return;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
180

Thomas Jahns's avatar
Thomas Jahns committed
181
  zaxisInitialized = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182

183
184
  env = getenv("ZAXIS_DEBUG");
  if ( env ) ZAXIS_Debug = atoi(env);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
185
186
}

187
188
static
void zaxis_copy(zaxis_t *zaxisptr2, zaxis_t *zaxisptr1)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
{
190
  int zaxisID2 = zaxisptr2->self;
191
  memcpy(zaxisptr2, zaxisptr1, sizeof(zaxis_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
192
193
194
  zaxisptr2->self = zaxisID2;
}

195
unsigned cdiZaxisCount(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
{
197
  return reshCountType(&zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
198
199
}

200
201
202
203
204
static int
zaxisCreate_(int zaxistype, int size, int id)
{
  zaxis_t *zaxisptr = zaxisNewEntry(id);

205
  xassert(size >= 0);
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
  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;

222
223
  double *vals = zaxisptr->vals
    = (double *)xmalloc((size_t)size * sizeof(double));
224
225
226
227
228
229
230

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

  return zaxisID;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
231
232

/*
233
@Function  zaxisCreate
234
@Title     Create a vertical Z-axis
Uwe Schulzweida's avatar
Uwe Schulzweida committed
235

236
@Prototype int zaxisCreate(int zaxistype, int size)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
238
@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
239
                      The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
                      @func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
241
242
                      @func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
                      @func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
243
                      @func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
244
245
                      @func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
                      @func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
246
                      @func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Deike Kleberg's avatar
Deike Kleberg committed
247
    @Item  size       Number of levels.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
248
249

@Description
250
The function @func{zaxisCreate} creates a vertical Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
251
252

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
255
@Example
256
Here is an example using @func{zaxisCreate} to create a pressure level Z-axis:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257
258
259
260

@Source
#include "cdi.h"
   ...
261
#define  nlev    5
Uwe Schulzweida's avatar
Uwe Schulzweida committed
262
   ...
263
double levs[nlev] = {101300, 92500, 85000, 50000, 20000};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
264
265
int zaxisID;
   ...
266
zaxisID = zaxisCreate(ZAXIS_PRESSURE, nlev);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
268
269
zaxisDefLevels(zaxisID, levs);
   ...
@EndSource
Uwe Schulzweida's avatar
Uwe Schulzweida committed
270
271
@EndFunction
*/
272
int zaxisCreate(int zaxistype, int size)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
{
274
275
  if ( CDI_Debug )
    Message("zaxistype: %d size: %d ", zaxistype, size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
276

277
278
  zaxisInit ();
  return zaxisCreate_(zaxistype, size, CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
279
280
}

281

282
static void zaxisDestroyKernel( zaxis_t * zaxisptr )
283
284
285
{
  int id;

Deike Kleberg's avatar
Deike Kleberg committed
286
  xassert ( zaxisptr );
287
288
289

  id = zaxisptr->self;

290
  if ( zaxisptr->vals )    free ( zaxisptr->vals );
291
292
293
  if ( zaxisptr->lbounds ) free ( zaxisptr->lbounds );
  if ( zaxisptr->ubounds ) free ( zaxisptr->ubounds );
  if ( zaxisptr->weights ) free ( zaxisptr->weights );
294
  if ( zaxisptr->vct )     free ( zaxisptr->vct );
295
296
297

  free ( zaxisptr );

298
  reshRemove ( id, &zaxisOps );
299
300
}

301
302
303
304
305
306
/*
@Function  zaxisDestroy
@Title     Destroy a vertical Z-axis

@Prototype void zaxisDestroy(int zaxisID)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
307
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate}.
308
309
310
311
312

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

315
  zaxisDestroyKernel ( zaxisptr );
316
317
318
}


319
static
320
void zaxisDestroyP ( void * zaxisptr )
321
{
322
  zaxisDestroyKernel (( zaxis_t * ) zaxisptr );
323
324
325
}


326
char *zaxisNamePtr(int zaxistype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
327
328
329
{
  char *name;

330
  if ( zaxistype >= 0 && zaxistype < CDI_NumZaxistype )
331
    name = ZaxistypeEntry[zaxistype].longname;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
332
  else
333
    name = ZaxistypeEntry[ZAXIS_GENERIC].longname;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

  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
350
351
    @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
352
353

@Description
354
The function @func{zaxisDefName} defines the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
355
356
357
358
359

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
  if ( name )
363
364
365
    {
      strncpy(zaxisptr->name, name, CDI_MAX_NAME - 1);
      zaxisptr->name[CDI_MAX_NAME - 1] = '\0';
366
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
367
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
369
370
371
372
373
374
375
}

/*
@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
376
377
    @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
378
379

@Description
380
The function @func{zaxisDefLongname} defines the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
381
382
383
384
385

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
388
  if ( longname )
389
390
391
    {
      strncpy(zaxisptr->longname, longname, CDI_MAX_NAME - 1);
      zaxisptr->longname[CDI_MAX_NAME - 1] = '\0';
392
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
393
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
396
397
398
399
400
401
}

/*
@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
402
403
    @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
404
405

@Description
406
The function @func{zaxisDefUnits} defines the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
407
408
409
410
411

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
414
  if ( units )
415
416
417
    {
      strncpy(zaxisptr->units, units, CDI_MAX_NAME - 1);
      zaxisptr->units[CDI_MAX_NAME - 1] = '\0';
418
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
419
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
420
421
422
423
424
425
426
427
}

/*
@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
428
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
429
    @Item  name     Name of the Z-axis. The caller must allocate space for the
Deike Kleberg's avatar
Deike Kleberg committed
430
                    returned string. The maximum possible length, in characters, of
431
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
432
433

@Description
434
The function @func{zaxisInqName} returns the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
435
436

@Result
437
@func{zaxisInqName} returns the name of the Z-axis to the parameter name.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
438
439
440
441
442

@EndFunction
*/
void zaxisInqName(int zaxisID, char *name)
{
443
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
444
  strcpy(name, zaxisptr->name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
445
446
447
448
449
450
451
452
}

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

@Description
459
The function @func{zaxisInqLongname} returns the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
460
461

@Result
462
@func{zaxisInqLongname} returns the longname of the Z-axis to the parameter longname.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
463
464
465
466
467

@EndFunction
*/
void zaxisInqLongname(int zaxisID, char *longname)
{
468
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
469
  strcpy(longname, zaxisptr->longname);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
470
471
472
473
474
475
476
477
}

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

@Description
484
The function @func{zaxisInqUnits} returns the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
485
486

@Result
487
@func{zaxisInqUnits} returns the units of the Z-axis to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488
489
490
491
492

@EndFunction
*/
void zaxisInqUnits(int zaxisID, char *units)
{
493
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
494
  strcpy(units, zaxisptr->units);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
495
496
497
}


Deike Kleberg's avatar
Deike Kleberg committed
498
499
void zaxisInqStdname(int zaxisID, char *stdname)
{
500
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Deike Kleberg's avatar
Deike Kleberg committed
501
502
503
504
  strcpy(stdname, zaxisptr->stdname);
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
505
506
void zaxisDefPrec(int zaxisID, int prec)
{
507
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
508

509
510
511
512
513
  if (zaxisptr->prec != prec)
    {
      zaxisptr->prec = prec;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
514
515
516
517
518
}


int zaxisInqPrec(int zaxisID)
{
519
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520

Uwe Schulzweida's avatar
Uwe Schulzweida committed
521
  return (zaxisptr->prec);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
522
523
524
}


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

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


Deike Kleberg's avatar
Deike Kleberg committed
537
538
int zaxisInqPositive(int zaxisID)
{
539
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Deike Kleberg's avatar
Deike Kleberg committed
540
541
542
543
544

  return (zaxisptr->positive);
}


545
546
void zaxisDefLtype(int zaxisID, int ltype)
{
547
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
548

549
550
551
552
553
  if (zaxisptr->ltype != ltype)
    {
      zaxisptr->ltype = ltype;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
554
555
556
557
558
}


int zaxisInqLtype(int zaxisID)
{
559
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
560
561
562
563

  return (zaxisptr->ltype);
}

564
565
566

void zaxisDefLtype2(int zaxisID, int ltype2)
{
567
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
568
569
570
571
572
573
574
575
576
577
578

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


int zaxisInqLtype2(int zaxisID)
{
579
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
580
581
582
583

  return (zaxisptr->ltype2);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
584
585
586
587
/*
@Function  zaxisDefLevels
@Title     Define the levels of a Z-axis

Uwe Schulzweida's avatar
Uwe Schulzweida committed
588
@Prototype void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
589
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
590
591
    @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
592
593

@Description
594
The function @func{zaxisDefLevels} defines the levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
595
596
597

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
598
void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
599
{
600
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
601

602
  int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
603

604
  double *vals = zaxisptr->vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
605

606
  for (int ilev = 0; ilev < size; ilev++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
607
    vals[ilev] = levels[ilev];
608
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
609
610
611
612
613
614
615
616
}

/*
@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
617
618
619
    @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
620
621

@Description
622
The function @func{zaxisDefLevel} defines one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
624
625
626
627

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
630
631
  if ( levelID >= 0 && levelID < zaxisptr->size )
    zaxisptr->vals[levelID] = level;
632
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
633
634
}

635
636
637

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

640
641
642
643
644
  if (zaxisptr->nhlev != nhlev)
    {
      zaxisptr->nhlev = nhlev;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
645
646
647
648
649
}


int zaxisInqNlevRef(int zaxisID)
{
650
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
651

Thomas Jahns's avatar
Thomas Jahns committed
652
  return (zaxisptr->nhlev);
653
654
}

655
/*
656
657
@Function  zaxisDefNumber
@Title     Define the reference number for a generalized Z-axis
658

659
@Prototype void zaxisDefNumber(int zaxisID, const int number)
660
661
@Parameter
    @Item  zaxisID     Z-axis ID, from a previous call to @fref{zaxisCreate}.
662
    @Item  number      Reference number for a generalized Z-axis.
663
664

@Description
665
The function @func{zaxisDefNumber} defines the reference number for a generalized Z-axis.
666
667
668

@EndFunction
*/
669
void zaxisDefNumber(int zaxisID, const int number)
670
{
671
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
672

673
674
675
676
677
  if (zaxisptr->number != number)
    {
      zaxisptr->number = number;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
678
679
}

680
681
682
683
684
685
/*
@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
686
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
687
688
689
690
691
692
693
694
695
696

@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)
{
697
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
698

Thomas Jahns's avatar
Thomas Jahns committed
699
  return (zaxisptr->number);
700
701
}

702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
@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
*/
716
void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
717
{
718
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
719

720
  memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
721
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
722
723
724
725
}

/*
@Function  zaxisInqUUID
726
@Title     Get the uuid to a generalized Z-axis
727

728
@Prototype void zaxisInqUUID(int zaxisID, char *uuid)
729
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
730
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
731
    @Item uuid A user supplied buffer of at least 16 bytes.
732
733
734
735
736

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

@Result
737
@func{zaxisInqUUID} returns the UUID to a generalized Z-axis to the parameter uuid.
738
739
@EndFunction
*/
740
void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
741
{
742
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
743
  memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
744
745
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
746
747
748
749
750
751
/*
@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
752
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
753
    @Item  levelID  Level index (range: 0 to nlevel-1).
Uwe Schulzweida's avatar
Uwe Schulzweida committed
754
755

@Description
756
The function @func{zaxisInqLevel} returns one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
757
758

@Result
759
@func{zaxisInqLevel} returns the level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
760
761
762
763
764
@EndFunction
*/
double zaxisInqLevel(int zaxisID, int levelID)
{
  double level = 0;
765
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
766

Uwe Schulzweida's avatar
Uwe Schulzweida committed
767
768
  if ( levelID >= 0 && levelID < zaxisptr->size )
    level = zaxisptr->vals[levelID];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
769
770
771
772
773
774
775

  return (level);
}

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

778
779
780
  if ( zaxisptr->lbounds )
    if ( index >= 0 && index < zaxisptr->size )
      level = zaxisptr->lbounds[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
781
782
783
784
785
786
787
788

  return (level);
}


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

791
792
793
  if ( zaxisptr->ubounds )
    if ( index >= 0 && index < zaxisptr->size )
      level = zaxisptr->ubounds[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
795
796
797
798
799
800

  return (level);
}


const double *zaxisInqLevelsPtr(int zaxisID)
{
801
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
802
  return ( zaxisptr->vals );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
803
804
805
806
807
808
809
810
}

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
815
@Description
816
The function @func{zaxisInqLevels} returns all levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
817
818

@Result
819
@func{zaxisInqLevels} saves all levels to the parameter @func{levels}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
820
821
822
823
@EndFunction
*/
void zaxisInqLevels(int zaxisID, double *levels)
{
824
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Thomas Jahns's avatar
Thomas Jahns committed
825
826
  int size = zaxisptr->size;
  for (int i = 0; i < size; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
827
    levels[i] =  zaxisptr->vals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
828
829
830
831
832
833
}


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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
836
  if ( zaxisptr->lbounds )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
837
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
838
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
839
840

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

  return (size);
}


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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
854
  if ( zaxisptr->ubounds )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
855
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
856
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
857
858

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

  return (size);
}


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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
872
  if ( zaxisptr->weights )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
873
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
874
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
875
876

      if ( weights )
Thomas Jahns's avatar
Thomas Jahns committed
877
        for ( int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
878
          weights[i] =  zaxisptr->weights[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
879
880
881
882
883
884
885
886
887
    }

  return (size);
}


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

Thomas Jahns's avatar
Thomas Jahns committed
890
891
892
893
894
895
896
  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
897
898
899
900
901
902
903
904
905
906

  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
907
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
908
909

@Description
910
The function @func{zaxisInqType} returns the type of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
911
912

@Result
913
@func{zaxisInqType} returns the type of the Z-axis,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
914
one of the set of predefined CDI Z-axis types.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
915
The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
916
@func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
917
918
@func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
@func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
919
@func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
920
921
@func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
@func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
922
@func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
923
924
925
926
927

@EndFunction
*/
int zaxisInqType(int zaxisID)
{
928
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
929
  return (zaxisptr->type);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
930
931
932
933
934
935
936
937
}

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

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

@Description
941
The function @func{zaxisInqSize} returns the size of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
942
943

@Result
944
@func{zaxisInqSize} returns the number of levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
945
946
947
948
949

@EndFunction
*/
int zaxisInqSize(int zaxisID)
{
950
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
951
  return (zaxisptr->size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
952
953
954
955
956
}


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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
959
960
  if ( zaxisInqType(zaxisID) == ZAXIS_GENERIC )
    {
Thomas Jahns's avatar
Thomas Jahns committed
961
      int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
962
      if ( size > 1 )
963
964
965
966
        {
          /* check direction */
          if ( ! zaxisptr->direction )
            {
Thomas Jahns's avatar
Thomas Jahns committed
967
968
969
970
971
972
973
              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 )
974
975
976
                {
                  zaxisptr->direction = LevelUp;
                }
Thomas Jahns's avatar
Thomas Jahns committed
977
              else if ( downs == size-1 )
978
                {
Thomas Jahns's avatar
Thomas Jahns committed
979
980
981
982
983
                  zaxisptr->direction = LevelDown;
                }
              else /* !zaxisptr->direction */
                {
                  Warning("Direction undefined for zaxisID %d", zaxisID);
984
985
986
                }
            }
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
987
988
989
990
991
992
    }
}


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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
995
  if ( zaxisptr->vct == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
996
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
997
      zaxisptr->vctsize = size;
998
999
      zaxisptr->vct = (double *)xmalloc((size_t)size * sizeof (double));
      memcpy(zaxisptr->vct, vct, (size_t)size * sizeof (double));
1000
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1001
1002
    }
  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1003
    if ( zaxisptr->vctsize != size )
1004
      Warning("VCT was already defined");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1005
1006
1007
}


1008
1009
void zaxisInqVct(int zaxisID, double *vct)
{
1010
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);
1011
  memcpy(vct, zaxisptr->vct, (size_t)zaxisptr->vctsize * sizeof (double));
1012
1013
1014
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
1015
1016
int zaxisInqVctSize(int zaxisID)
{
1017
  zaxis_t *zaxisptr = (zaxis_t *)reshGetVal(zaxisID, &zaxisOps);