zaxis.c 45.3 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];
71
  char     psname[CDI_MAX_NAME];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
73
74
75
  double  *vals;
  double  *lbounds;
  double  *ubounds;
  double  *weights;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
  int      self;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
78
  int      prec;
  int      type;
79
  int      ltype;    /* GRIB level type */
80
  int      ltype2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
82
83
84
  int      size;
  int      direction;
  int      vctsize;
  double  *vct;
85
  int      number;   /* Reference number to a generalized Z-axis */
86
  int      nhlev;
87
  unsigned char uuid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
}
89
zaxis_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
90

91
static int    zaxisCompareP    (zaxis_t *z1, zaxis_t *z2);
Deike Kleberg's avatar
Deike Kleberg committed
92
93
static void   zaxisDestroyP    ( void * zaxisptr );
static void   zaxisPrintP      ( void * zaxisptr, FILE * fp );
94
95
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
96
static int    zaxisTxCode      ( void );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97

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

107
108
109
110
111
const resOps *getZaxisOps()
{
  return &zaxisOps;
}

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

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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;
    }
}

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

161

162
static
163
zaxis_t *zaxisNewEntry(int id)
164
{
165
  zaxis_t *zaxisptr = (zaxis_t *)xmalloc(sizeof(zaxis_t));
166
167

  zaxisDefaultValue ( zaxisptr );
168

169
170
171
172
173
174
175
  if (id == CDI_UNDEFID)
    zaxisptr->self = reshPut(zaxisptr, &zaxisOps);
  else
    {
      zaxisptr->self = id;
      reshReplace(id, zaxisptr, &zaxisOps);
    }
176
177

  return (zaxisptr);
178
179
}

180
181
182
183
184
185
186
static inline zaxis_t *
zaxisID2Ptr(int id)
{
  return (zaxis_t *)reshGetVal(id, &zaxisOps);
}


187
static
188
void zaxisInit(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
{
190
191
  static int zaxisInitialized = 0;
  char *env;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
192

193
  if ( zaxisInitialized ) return;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
194

Thomas Jahns's avatar
Thomas Jahns committed
195
  zaxisInitialized = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196

197
198
  env = getenv("ZAXIS_DEBUG");
  if ( env ) ZAXIS_Debug = atoi(env);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
199
200
}

201
202
static
void zaxis_copy(zaxis_t *zaxisptr2, zaxis_t *zaxisptr1)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
203
{
204
  int zaxisID2 = zaxisptr2->self;
205
  memcpy(zaxisptr2, zaxisptr1, sizeof(zaxis_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
206
207
208
  zaxisptr2->self = zaxisID2;
}

209
unsigned cdiZaxisCount(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
210
{
211
  return reshCountType(&zaxisOps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
212
213
}

214

215
216
217
218
219
static int
zaxisCreate_(int zaxistype, int size, int id)
{
  zaxis_t *zaxisptr = zaxisNewEntry(id);

220
  xassert(size >= 0);
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  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;

237
238
  double *vals = zaxisptr->vals
    = (double *)xmalloc((size_t)size * sizeof(double));
239
240
241
242
243
244
245

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

  return zaxisID;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
247

/*
248
@Function  zaxisCreate
249
@Title     Create a vertical Z-axis
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250

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

@Description
265
The function @func{zaxisCreate} creates a vertical Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
266
267

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
270
@Example
271
Here is an example using @func{zaxisCreate} to create a pressure level Z-axis:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
272
273
274
275

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

292
293
  zaxisInit ();
  return zaxisCreate_(zaxistype, size, CDI_UNDEFID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
294
295
}

296

297
static void zaxisDestroyKernel( zaxis_t * zaxisptr )
298
299
300
{
  int id;

Deike Kleberg's avatar
Deike Kleberg committed
301
  xassert ( zaxisptr );
302
303
304

  id = zaxisptr->self;

305
  if ( zaxisptr->vals )    free ( zaxisptr->vals );
306
307
308
  if ( zaxisptr->lbounds ) free ( zaxisptr->lbounds );
  if ( zaxisptr->ubounds ) free ( zaxisptr->ubounds );
  if ( zaxisptr->weights ) free ( zaxisptr->weights );
309
  if ( zaxisptr->vct )     free ( zaxisptr->vct );
310
311
312

  free ( zaxisptr );

313
  reshRemove ( id, &zaxisOps );
314
315
}

316
317
318
319
320
321
/*
@Function  zaxisDestroy
@Title     Destroy a vertical Z-axis

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

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

330
  zaxisDestroyKernel ( zaxisptr );
331
332
333
}


334
static
335
void zaxisDestroyP ( void * zaxisptr )
336
{
337
  zaxisDestroyKernel (( zaxis_t * ) zaxisptr );
338
339
340
}


341
char *zaxisNamePtr(int zaxistype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
{
343
344
345
  char *name = (zaxistype >= 0 && zaxistype < CDI_NumZaxistype)
    ? ZaxistypeEntry[zaxistype].longname
    : ZaxistypeEntry[ZAXIS_GENERIC].longname;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  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
361
362
    @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
363
364

@Description
365
The function @func{zaxisDefName} defines the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
367
368
369
370

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
373
  if ( name )
374
375
376
    {
      strncpy(zaxisptr->name, name, CDI_MAX_NAME - 1);
      zaxisptr->name[CDI_MAX_NAME - 1] = '\0';
377
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
378
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
380
381
382
383
384
385
386
}

/*
@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
387
388
    @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
389
390

@Description
391
The function @func{zaxisDefLongname} defines the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392
393
394
395
396

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
399
  if ( longname )
400
401
402
    {
      strncpy(zaxisptr->longname, longname, CDI_MAX_NAME - 1);
      zaxisptr->longname[CDI_MAX_NAME - 1] = '\0';
403
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
404
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
405
406
407
408
409
410
411
412
}

/*
@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
413
414
    @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
415
416

@Description
417
The function @func{zaxisDefUnits} defines the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
418
419
420
421
422

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
  if ( units )
426
427
428
    {
      strncpy(zaxisptr->units, units, CDI_MAX_NAME - 1);
      zaxisptr->units[CDI_MAX_NAME - 1] = '\0';
429
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
430
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
431
432
}

433
434
435
436
437
438
439
440
441
442
443
444
445

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

@Description
458
The function @func{zaxisInqName} returns the name of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
459
460

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

@EndFunction
*/
void zaxisInqName(int zaxisID, char *name)
{
467
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
468
  strcpy(name, zaxisptr->name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
469
470
471
472
473
474
475
476
}

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

@Description
483
The function @func{zaxisInqLongname} returns the longname of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
484
485

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

@EndFunction
*/
void zaxisInqLongname(int zaxisID, char *longname)
{
492
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
493
  strcpy(longname, zaxisptr->longname);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
494
495
496
497
498
499
500
501
}

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

@Description
508
The function @func{zaxisInqUnits} returns the units of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
509
510

@Result
511
@func{zaxisInqUnits} returns the units of the Z-axis to the parameter units.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
512
513
514
515
516

@EndFunction
*/
void zaxisInqUnits(int zaxisID, char *units)
{
517
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
518
  strcpy(units, zaxisptr->units);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
519
520
521
}


Deike Kleberg's avatar
Deike Kleberg committed
522
523
void zaxisInqStdname(int zaxisID, char *stdname)
{
524
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Deike Kleberg's avatar
Deike Kleberg committed
525
526
527
528
  strcpy(stdname, zaxisptr->stdname);
}


529
530
531
532
533
534
535
void zaxisInqPsName(int zaxisID, char *psname)
{
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
  strcpy(psname, zaxisptr->psname);
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
536
537
void zaxisDefPrec(int zaxisID, int prec)
{
538
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
539

540
541
542
543
544
  if (zaxisptr->prec != prec)
    {
      zaxisptr->prec = prec;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
545
546
547
548
549
}


int zaxisInqPrec(int zaxisID)
{
550
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
551
  return (zaxisptr->prec);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
552
553
554
}


555
556
void zaxisDefPositive(int zaxisID, int positive)
{
557
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
558

559
560
  if (zaxisptr->positive != positive)
    {
561
      zaxisptr->positive = (unsigned char)positive;
562
563
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
564
565
566
}


Deike Kleberg's avatar
Deike Kleberg committed
567
568
int zaxisInqPositive(int zaxisID)
{
569
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
570
  return zaxisptr->positive;
Deike Kleberg's avatar
Deike Kleberg committed
571
572
573
}


574
575
void zaxisDefLtype(int zaxisID, int ltype)
{
576
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
577

578
579
580
581
582
  if (zaxisptr->ltype != ltype)
    {
      zaxisptr->ltype = ltype;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
583
584
585
586
587
}


int zaxisInqLtype(int zaxisID)
{
588
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
589
  return zaxisptr->ltype;
590
591
}

592
593
594

void zaxisDefLtype2(int zaxisID, int ltype2)
{
595
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
596
597
598
599
600
601
602
603
604
605
606

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


int zaxisInqLtype2(int zaxisID)
{
607
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
608
  return zaxisptr->ltype2;
609
610
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
611
612
613
614
/*
@Function  zaxisDefLevels
@Title     Define the levels of a Z-axis

Uwe Schulzweida's avatar
Uwe Schulzweida committed
615
@Prototype void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
616
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
617
618
    @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
619
620

@Description
621
The function @func{zaxisDefLevels} defines the levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
622
623
624

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
625
void zaxisDefLevels(int zaxisID, const double *levels)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
626
{
627
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
628

629
  int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
630

631
  double *vals = zaxisptr->vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
632

633
  for (int ilev = 0; ilev < size; ilev++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
634
    vals[ilev] = levels[ilev];
635
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
637
638
639
640
641
642
643
}

/*
@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
644
645
646
    @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
647
648

@Description
649
The function @func{zaxisDefLevel} defines one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
650
651
652
653
654

@EndFunction
*/
void zaxisDefLevel(int zaxisID, int levelID, double level)
{
655
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
656
657
  if ( levelID >= 0 && levelID < zaxisptr->size )
    zaxisptr->vals[levelID] = level;
658
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
659
660
}

661
662
663

void zaxisDefNlevRef(int zaxisID, const int nhlev)
{
664
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
665
666
667
668
669
  if (zaxisptr->nhlev != nhlev)
    {
      zaxisptr->nhlev = nhlev;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
670
671
672
673
674
}


int zaxisInqNlevRef(int zaxisID)
{
675
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
676
  return zaxisptr->nhlev;
677
678
}

679
/*
680
681
@Function  zaxisDefNumber
@Title     Define the reference number for a generalized Z-axis
682

683
@Prototype void zaxisDefNumber(int zaxisID, const int number)
684
685
@Parameter
    @Item  zaxisID     Z-axis ID, from a previous call to @fref{zaxisCreate}.
686
    @Item  number      Reference number for a generalized Z-axis.
687
688

@Description
689
The function @func{zaxisDefNumber} defines the reference number for a generalized Z-axis.
690
691
692

@EndFunction
*/
693
void zaxisDefNumber(int zaxisID, const int number)
694
{
695
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
696
697
698
699
700
  if (zaxisptr->number != number)
    {
      zaxisptr->number = number;
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
    }
701
702
}

703
704
705
706
707
708
/*
@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
709
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
710
711
712
713
714
715
716
717
718
719

@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)
{
720
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
721
  return zaxisptr->number;
722
723
}

724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*
@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
*/
738
void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
739
{
740
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
741
  memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
742
  reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
743
744
745
746
}

/*
@Function  zaxisInqUUID
747
@Title     Get the uuid to a generalized Z-axis
748

749
@Prototype void zaxisInqUUID(int zaxisID, char *uuid)
750
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
751
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
752
    @Item uuid A user supplied buffer of at least 16 bytes.
753
754
755
756
757

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

@Result
758
@func{zaxisInqUUID} returns the UUID to a generalized Z-axis to the parameter uuid.
759
760
@EndFunction
*/
761
void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
762
{
763
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
764
  memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
765
766
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
767
768
769
770
771
772
/*
@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
773
    @Item  zaxisID  Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
Deike Kleberg's avatar
Deike Kleberg committed
774
    @Item  levelID  Level index (range: 0 to nlevel-1).
Uwe Schulzweida's avatar
Uwe Schulzweida committed
775
776

@Description
777
The function @func{zaxisInqLevel} returns one level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
778
779

@Result
780
@func{zaxisInqLevel} returns the level of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
781
782
783
784
785
@EndFunction
*/
double zaxisInqLevel(int zaxisID, int levelID)
{
  double level = 0;
786
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
787

Uwe Schulzweida's avatar
Uwe Schulzweida committed
788
789
  if ( levelID >= 0 && levelID < zaxisptr->size )
    level = zaxisptr->vals[levelID];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
790

791
  return level;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
792
793
794
795
796
}

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

799
  if ( zaxisptr->lbounds && ( index >= 0 && index < zaxisptr->size ) )
800
      level = zaxisptr->lbounds[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
801

802
  return level;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
803
804
805
806
807
808
}


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

811
812
813
  if ( zaxisptr->ubounds && ( index >= 0 && index < zaxisptr->size ) )
    level = zaxisptr->ubounds[index];
  return level;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
814
815
816
817
818
}


const double *zaxisInqLevelsPtr(int zaxisID)
{
819
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
820
  return zaxisptr->vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
821
822
823
824
825
826
827
828
}

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
833
@Description
834
The function @func{zaxisInqLevels} returns all levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
835
836

@Result
837
@func{zaxisInqLevels} saves all levels to the parameter @func{levels}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
838
839
840
841
@EndFunction
*/
void zaxisInqLevels(int zaxisID, double *levels)
{
842
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Thomas Jahns's avatar
Thomas Jahns committed
843
844
  int size = zaxisptr->size;
  for (int i = 0; i < size; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
845
    levels[i] =  zaxisptr->vals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
846
847
848
849
850
851
}


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

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

  return (size);
}


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

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

  return (size);
}


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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
890
  if ( zaxisptr->weights )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
891
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
892
      size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
893
894

      if ( weights )
Thomas Jahns's avatar
Thomas Jahns committed
895
        for ( int i = 0; i < size; i++ )
Thomas Jahns's avatar
Thomas Jahns committed
896
          weights[i] =  zaxisptr->weights[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
897
898
899
900
901
902
903
904
905
    }

  return (size);
}


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

Thomas Jahns's avatar
Thomas Jahns committed
908
909
910
911
912
913
914
  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
915

916
  return levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
917
918
919
920
921
922
923
924
}

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

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

@Description
928
The function @func{zaxisInqType} returns the type of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
929
930

@Result
931
@func{zaxisInqType} returns the type of the Z-axis,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
932
one of the set of predefined CDI Z-axis types.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
933
The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
934
@func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
935
936
@func{ZAXIS_ISENTROPIC}, @func{ZAXIS_ALTITUDE}, @func{ZAXIS_MEANSEA}, @func{ZAXIS_TOA},
@func{ZAXIS_SEA_BOTTOM}, @func{ZAXIS_ATMOSPHERE}, @func{ZAXIS_CLOUD_BASE},
937
@func{ZAXIS_CLOUD_TOP}, @func{ZAXIS_ISOTHERM_ZERO}, @func{ZAXIS_SNOW},
938
939
@func{ZAXIS_LAKE_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM}, @func{ZAXIS_SEDIMENT_BOTTOM_TA},
@func{ZAXIS_SEDIMENT_BOTTOM_TW}, @func{ZAXIS_MIX_LAYER},
940
@func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
941
942
943
944
945

@EndFunction
*/
int zaxisInqType(int zaxisID)
{
946
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
947
  return (zaxisptr->type);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
948
949
950
951
952
953
954
955
}

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

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

@Description
959
The function @func{zaxisInqSize} returns the size of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
960
961

@Result
962
@func{zaxisInqSize} returns the number of levels of a Z-axis.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
963
964
965
966
967

@EndFunction
*/
int zaxisInqSize(int zaxisID)
{
968
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
969
  return (zaxisptr->size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
970
971
972
973
974
}


void cdiCheckZaxis(int zaxisID)
{
975
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Thomas Jahns's avatar
Thomas Jahns committed
976

Uwe Schulzweida's avatar
Uwe Schulzweida committed
977
978
  if ( zaxisInqType(zaxisID) == ZAXIS_GENERIC )
    {
Thomas Jahns's avatar
Thomas Jahns committed
979
      int size = zaxisptr->size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
980
      if ( size > 1 )
981
982
983
984
        {
          /* check direction */
          if ( ! zaxisptr->direction )
            {
Thomas Jahns's avatar
Thomas Jahns committed
985
986
987
988
989
990
991
              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 )
992
993
994
                {
                  zaxisptr->direction = LevelUp;
                }
Thomas Jahns's avatar
Thomas Jahns committed
995
              else if ( downs == size-1 )
996
                {
Thomas Jahns's avatar
Thomas Jahns committed
997
998
999
1000
1001
                  zaxisptr->direction = LevelDown;
                }
              else /* !zaxisptr->direction */
                {
                  Warning("Direction undefined for zaxisID %d", zaxisID);
1002
1003
1004
                }
            }
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1005
1006
1007
1008
1009
1010
    }
}


void zaxisDefVct(int zaxisID, int size, const double *vct)
{
1011
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1012

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1013
  if ( zaxisptr->vct == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1014
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1015
      zaxisptr->vctsize = size;
1016
1017
      zaxisptr->vct = (double *)xmalloc((size_t)size * sizeof (double));
      memcpy(zaxisptr->vct, vct, (size_t)size * sizeof (double));
1018
      reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1019
1020
    }
  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1021
    if ( zaxisptr->vctsize != size )
1022
      Warning("VCT was already defined");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1023
1024
1025
}


1026
1027
void zaxisInqVct(int zaxisID, double *vct)
{
1028
  zaxis_t *zaxisptr = zaxisID2Ptr(zaxisID);
1029
  memcpy(vct, zaxisptr->vct, (size_t)zaxisptr->vctsize * sizeof (double));
Deike Kleberg's avatar