1
#if defined (HAVE_CONFIG_H)
12
#include "stream_int.h"
21
{"sfc", "surface", ""},
22
{"lev", "generic", "level"},
23
{"lev", "hybrid", "level"},
24
{"lev", "hybrid_half", "level"},
25
{"lev", "pressure", "Pa"},
26
{"height", "height", "m"},
27
{"depth", "depth_below_sea", "m"},
28
{"depth", "depth_below_land", "cm"},
29
{"lev", "isentropic", "K"},
30
{"lev", "trajectory", ""},
31
{"alt", "altitude", "m"},
32
{"lev", "sigma", "level"},
33
{"lev", "meansea", "level"},
36
static int CDI_MaxZaxistype = sizeof(ZaxistypeEntry) / sizeof(ZaxistypeEntry[0]);
53
int ltype; /* GRIB level type */
61
static int ZAXIS_Debug = 0; /* If set to 1, debugging */
63
static int _zaxis_max = MAX_ZAXES;
65
static void zaxis_initialize(void);
67
static int _zaxis_init = FALSE;
69
#if defined (HAVE_LIBPTHREAD)
72
static pthread_once_t _zaxis_init_thread = PTHREAD_ONCE_INIT;
73
static pthread_mutex_t _zaxis_mutex;
75
# define ZAXIS_LOCK pthread_mutex_lock(&_zaxis_mutex);
76
# define ZAXIS_UNLOCK pthread_mutex_unlock(&_zaxis_mutex);
78
if ( _zaxis_init == FALSE ) pthread_once(&_zaxis_init_thread, zaxis_initialize);
85
if ( _zaxis_init == FALSE ) zaxis_initialize();
90
typedef struct _zaxisPtrToIdx {
93
struct _zaxisPtrToIdx *next;
97
static zaxisPtrToIdx *_zaxisList = NULL;
98
static zaxisPtrToIdx *_zaxisAvail = NULL;
101
static void zaxis_list_new(void)
103
static const char *func = "zaxis_list_new";
105
assert(_zaxisList == NULL);
107
_zaxisList = (zaxisPtrToIdx *) malloc(_zaxis_max*sizeof(zaxisPtrToIdx));
111
static void zaxis_list_delete(void)
113
static const char *func = "zaxis_list_delete";
115
if ( _zaxisList ) free(_zaxisList);
119
static void zaxis_init_pointer(void)
123
for ( i = 0; i < _zaxis_max; i++ )
125
_zaxisList[i].next = _zaxisList + i + 1;
126
_zaxisList[i].idx = i;
127
_zaxisList[i].ptr = 0;
130
_zaxisList[_zaxis_max-1].next = 0;
132
_zaxisAvail = _zaxisList;
136
ZAXIS *zaxis_to_pointer(int idx)
138
static const char *func = "zaxis_to_pointer";
139
ZAXIS *zaxisptr = NULL;
143
if ( idx >= 0 && idx < _zaxis_max )
147
zaxisptr = _zaxisList[idx].ptr;
152
Error(func, "zaxis index %d undefined!", idx);
158
/* Create an index from a pointer */
159
static int zaxis_from_pointer(ZAXIS *ptr)
161
static const char *func = "zaxis_from_pointer";
163
zaxisPtrToIdx *newptr;
171
newptr = _zaxisAvail;
172
_zaxisAvail = _zaxisAvail->next;
178
Message(func, "Pointer %p has idx %d from zaxis list", ptr, idx);
181
Warning(func, "Too many open zaxis (limit is %d)!", _zaxis_max);
186
Error(func, "Internal problem (pointer %p undefined)", ptr);
192
static void zaxis_init_entry(ZAXIS *zaxisptr)
194
zaxisptr->self = zaxis_from_pointer(zaxisptr);
196
zaxisptr->name[0] = 0;
197
zaxisptr->longname[0] = 0;
198
zaxisptr->units[0] = 0;
199
zaxisptr->vals = NULL;
200
zaxisptr->ubounds = NULL;
201
zaxisptr->lbounds = NULL;
202
zaxisptr->weights = NULL;
203
zaxisptr->type = CDI_UNDEFID;
205
zaxisptr->direction = CDI_UNDEFID;
208
zaxisptr->vctsize = 0;
209
zaxisptr->vct = NULL;
213
static ZAXIS *zaxis_new_entry(void)
215
static const char *func = "zaxis_new_entry";
218
zaxisptr = (ZAXIS *) malloc(sizeof(ZAXIS));
220
if ( zaxisptr ) zaxis_init_entry(zaxisptr);
226
static void zaxis_delete_entry(ZAXIS *zaxisptr)
228
static const char *func = "zaxis_delete_entry";
231
idx = zaxisptr->self;
237
_zaxisList[idx].next = _zaxisAvail;
238
_zaxisList[idx].ptr = 0;
239
_zaxisAvail = &_zaxisList[idx];
244
Message(func, "Removed idx %d from zaxis list", idx);
248
static void zaxis_initialize(void)
252
#if defined (HAVE_LIBPTHREAD)
253
/* initialize global API mutex lock */
254
pthread_mutex_init(&_zaxis_mutex, NULL);
257
env = getenv("ZAXIS_DEBUG");
258
if ( env ) ZAXIS_Debug = atoi(env);
261
atexit(zaxis_list_delete);
265
zaxis_init_pointer();
273
static void zaxis_copy(ZAXIS *zaxisptr2, ZAXIS *zaxisptr1)
277
zaxisID2 = zaxisptr2->self;
278
memcpy(zaxisptr2, zaxisptr1, sizeof(ZAXIS));
279
zaxisptr2->self = zaxisID2;
283
static void zaxis_check_ptr(const char *func, ZAXIS *zaxisptr)
285
if ( zaxisptr == NULL )
286
Error(func, "zaxis undefined!");
299
for ( i = 0; i < _zaxis_max; i++ )
300
if ( _zaxisList[i].ptr ) zaxissize++;
309
@Function zaxisCreate
310
@Title Create a vertical Z-axis
312
@Prototype int zaxisCreate(int zaxistype, int size)
314
@Item zaxistype The type of the Z-axis, one of the set of predefined CDI Z-axis types.
315
The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
316
@func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
317
@func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
318
@Item size Number of levels
321
The function @func{zaxisCreate} creates a vertical Z-axis.
324
@func{zaxisCreate} returns an identifier to the Z-axis.
327
Here is an example using @func{zaxisCreate} to create a pressure level Z-axis:
334
double levs[NLEV] = {101300, 92500, 85000, 50000, 20000};
337
zaxisID = zaxisCreate(ZAXIS_PRESSURE, NLEV);
338
zaxisDefLevels(zaxisID, levs);
343
int zaxisCreate(int zaxistype, int size)
345
static const char *func = "zaxisCreate";
352
Message(func, "zaxistype: %d size: %d ", zaxistype, size);
356
zaxisptr = zaxis_new_entry();
357
if ( ! zaxisptr ) Error(func, "No memory");
359
zaxisID = zaxisptr->self;
361
zaxisptr->type = zaxistype;
362
zaxisptr->size = size;
364
if ( zaxistype > CDI_MaxZaxistype )
365
Error(func, "Internal problem! zaxistype > CDI_MaxZaxistype");
367
zaxisDefName(zaxisID, ZaxistypeEntry[zaxistype].name);
368
zaxisDefLongname(zaxisID, ZaxistypeEntry[zaxistype].longname);
369
zaxisDefUnits(zaxisID, ZaxistypeEntry[zaxistype].units);
371
vals = (double *) malloc(size*sizeof(double));
373
for ( ilev = 0; ilev < size; ilev++ )
376
zaxisptr->vals = vals;
383
@Function zaxisDestroy
384
@Title Destroy a vertical Z-axis
386
@Prototype void zaxisDestroy(int zaxisID)
388
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
392
void zaxisDestroy(int zaxisID)
396
zaxisptr = zaxis_to_pointer(zaxisID);
400
char *zaxisNamePtr(int zaxistype)
404
if ( zaxistype >= 0 && zaxistype < CDI_MaxZaxistype )
405
name = ZaxistypeEntry[zaxistype].longname;
407
name = ZaxistypeEntry[ZAXIS_GENERIC].longname;
413
void zaxisName(int zaxistype, char *zaxisname)
415
strcpy(zaxisname, zaxisNamePtr(zaxistype));
420
@Function zaxisDefName
421
@Title Define the name of a Z-axis
423
@Prototype void zaxisDefName(int zaxisID, const char *name)
425
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
426
@Item name Name of the Z-axis
429
The function @func{zaxisDefName} defines the name of a Z-axis.
433
void zaxisDefName(int zaxisID, const char *name)
437
zaxisptr = zaxis_to_pointer(zaxisID);
440
strcpy(zaxisptr->name, name);
445
@Function zaxisDefLongname
446
@Title Define the longname of a Z-axis
448
@Prototype void zaxisDefLongname(int zaxisID, const char *longname)
450
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
451
@Item longname Longname of the Z-axis
454
The function @func{zaxisDefLongname} defines the longname of a Z-axis.
458
void zaxisDefLongname(int zaxisID, const char *longname)
462
zaxisptr = zaxis_to_pointer(zaxisID);
465
strcpy(zaxisptr->longname, longname);
470
@Function zaxisDefUnits
471
@Title Define the units of a Z-axis
473
@Prototype void zaxisDefUnits(int zaxisID, const char *units)
475
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
476
@Item units Units of the Z-axis
479
The function @func{zaxisDefUnits} defines the units of a Z-axis.
483
void zaxisDefUnits(int zaxisID, const char *units)
487
zaxisptr = zaxis_to_pointer(zaxisID);
490
strcpy(zaxisptr->units, units);
495
@Function zaxisInqName
496
@Title Get the name of a Z-axis
498
@Prototype void zaxisInqName(int zaxisID, char *name)
500
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
501
@Item name Name of the Z-axis
504
The function @func{zaxisInqName} returns the name of a Z-axis.
507
@func{zaxisInqName} returns the name of the Z-axis to the parameter name.
511
void zaxisInqName(int zaxisID, char *name)
515
zaxisptr = zaxis_to_pointer(zaxisID);
517
strcpy(name, zaxisptr->name);
522
@Function zaxisInqLongname
523
@Title Get the longname of a Z-axis
525
@Prototype void zaxisInqLongname(int zaxisID, char *longname)
527
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
528
@Item longname Longname of the Z-axis
531
The function @func{zaxisInqLongname} returns the longname of a Z-axis.
534
@func{zaxisInqLongname} returns the longname of the Z-axis to the parameter longname.
538
void zaxisInqLongname(int zaxisID, char *longname)
542
zaxisptr = zaxis_to_pointer(zaxisID);
544
strcpy(longname, zaxisptr->longname);
549
@Function zaxisInqUnits
550
@Title Get the units of a Z-axis
552
@Prototype void zaxisInqUnits(int zaxisID, char *units)
554
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
555
@Item units Units of the Z-axis
558
The function @func{zaxisInqUnits} returns the units of a Z-axis.
561
@func{zaxisInqUnits} returns the units of the Z-axis to the parameter units.
565
void zaxisInqUnits(int zaxisID, char *units)
569
zaxisptr = zaxis_to_pointer(zaxisID);
571
strcpy(units, zaxisptr->units);
575
void zaxisDefPrec(int zaxisID, int prec)
577
static const char *func = "zaxisDefPrec";
580
zaxisptr = zaxis_to_pointer(zaxisID);
582
zaxis_check_ptr(func, zaxisptr);
584
zaxisptr->prec = prec;
588
int zaxisInqPrec(int zaxisID)
590
static const char *func = "zaxisInqPrec";
593
zaxisptr = zaxis_to_pointer(zaxisID);
595
zaxis_check_ptr(func, zaxisptr);
597
return (zaxisptr->prec);
601
void zaxisDefLtype(int zaxisID, int ltype)
603
static const char *func = "zaxisDefLtype";
606
zaxisptr = zaxis_to_pointer(zaxisID);
608
zaxis_check_ptr(func, zaxisptr);
610
zaxisptr->ltype = ltype;
614
int zaxisInqLtype(int zaxisID)
616
static const char *func = "zaxisInqLtype";
619
zaxisptr = zaxis_to_pointer(zaxisID);
621
zaxis_check_ptr(func, zaxisptr);
623
return (zaxisptr->ltype);
628
@Function zaxisDefLevels
629
@Title Define the levels of a Z-axis
631
@Prototype void zaxisDefLevels(int zaxisID, const double *levels)
633
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
634
@Item levels All levels of the Z-axis
637
The function @func{zaxisDefLevels} defines the levels of a Z-axis.
641
void zaxisDefLevels(int zaxisID, const double *levels)
643
static const char *func = "zaxisDefLevels";
649
zaxisptr = zaxis_to_pointer(zaxisID);
651
zaxis_check_ptr(func, zaxisptr);
653
size = zaxisptr->size;
655
vals = zaxisptr->vals;
657
for ( ilev = 0; ilev < size; ilev++ )
658
vals[ilev] = levels[ilev];
663
@Function zaxisDefLevel
664
@Title Define one level of a Z-axis
666
@Prototype void zaxisDefLevel(int zaxisID, int levelID, double level)
668
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
669
@Item levelID Level identifier
673
The function @func{zaxisDefLevel} defines one level of a Z-axis.
677
void zaxisDefLevel(int zaxisID, int levelID, double level)
679
static const char *func = "zaxisDefLevel";
682
zaxisptr = zaxis_to_pointer(zaxisID);
684
zaxis_check_ptr(func, zaxisptr);
686
if ( levelID >= 0 && levelID < zaxisptr->size )
687
zaxisptr->vals[levelID] = level;
692
@Function zaxisInqLevel
693
@Title Get one level of a Z-axis
695
@Prototype double zaxisInqLevel(int zaxisID, int levelID)
697
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
698
@Item levelID Level index (range: 0 to nlevel-1)
701
The function @func{zaxisInqLevel} returns one level of a Z-axis.
704
@func{zaxisInqLevel} returns the level of a Z-axis.
707
double zaxisInqLevel(int zaxisID, int levelID)
709
static const char *func = "zaxisInqLevel";
713
zaxisptr = zaxis_to_pointer(zaxisID);
715
zaxis_check_ptr(func, zaxisptr);
717
if ( levelID >= 0 && levelID < zaxisptr->size )
718
level = zaxisptr->vals[levelID];
724
double zaxisInqLbound(int zaxisID, int index)
726
static const char *func = "zaxisInqLbound";
730
zaxisptr = zaxis_to_pointer(zaxisID);
732
zaxis_check_ptr(func, zaxisptr);
734
if ( zaxisptr->lbounds )
735
if ( index >= 0 && index < zaxisptr->size )
736
level = zaxisptr->lbounds[index];
742
double zaxisInqUbound(int zaxisID, int index)
744
static const char *func = "zaxisInqUbound";
748
zaxisptr = zaxis_to_pointer(zaxisID);
750
zaxis_check_ptr(func, zaxisptr);
752
if ( zaxisptr->ubounds )
753
if ( index >= 0 && index < zaxisptr->size )
754
level = zaxisptr->ubounds[index];
760
const double *zaxisInqLevelsPtr(int zaxisID)
764
zaxisptr = zaxis_to_pointer(zaxisID);
766
return ( zaxisptr->vals );
771
@Function zaxisInqLevels
772
@Title Get all levels of a Z-axis
774
@Prototype void zaxisInqLevels(int zaxisID, double *levels)
776
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
777
@Item levels Levels of the Z-axis
780
The function @func{zaxisInqLevels} returns all levels of a Z-axis.
783
@func{zaxisInqLevels} saves all levels to the parameter @func{levels}.
786
void zaxisInqLevels(int zaxisID, double *levels)
788
static const char *func = "zaxisInqLevels";
793
zaxisptr = zaxis_to_pointer(zaxisID);
795
zaxis_check_ptr(func, zaxisptr);
797
size = zaxisptr->size;
798
for ( i = 0; i < size; i++ )
799
levels[i] = zaxisptr->vals[i];
803
int zaxisInqLbounds(int zaxisID, double *lbounds)
805
static const char *func = "zaxisInqLbounds";
810
zaxisptr = zaxis_to_pointer(zaxisID);
812
zaxis_check_ptr(func, zaxisptr);
814
if ( zaxisptr->lbounds )
816
size = zaxisptr->size;
819
for ( i = 0; i < size; i++ )
820
lbounds[i] = zaxisptr->lbounds[i];
827
int zaxisInqUbounds(int zaxisID, double *ubounds)
829
static const char *func = "zaxisInqUbounds";
834
zaxisptr = zaxis_to_pointer(zaxisID);
836
zaxis_check_ptr(func, zaxisptr);
838
if ( zaxisptr->ubounds )
840
size = zaxisptr->size;
843
for ( i = 0; i < size; i++ )
844
ubounds[i] = zaxisptr->ubounds[i];
851
int zaxisInqWeights(int zaxisID, double *weights)
853
static const char *func = "zaxisInqWeights";
858
zaxisptr = zaxis_to_pointer(zaxisID);
860
zaxis_check_ptr(func, zaxisptr);
862
if ( zaxisptr->weights )
864
size = zaxisptr->size;
867
for ( i = 0; i < size; i++ )
868
weights[i] = zaxisptr->weights[i];
875
int zaxisInqLevelID(int zaxisID, double level)
877
static const char *func = "zaxisInqLevelID";
879
int levelID = CDI_UNDEFID;
883
zaxisptr = zaxis_to_pointer(zaxisID);
885
zaxis_check_ptr(func, zaxisptr);
887
size = zaxisptr->size;
888
for ( i = 0; i < size; i++ )
889
if ( fabs(level-zaxisptr->vals[i]) < DBL_EPSILON ) break;
891
if ( i < size ) levelID = i;
898
@Function zaxisInqType
899
@Title Get the type of a Z-axis
901
@Prototype int zaxisInqType(int zaxisID)
903
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
906
The function @func{zaxisInqType} returns the type of a Z-axis.
909
@func{zaxisInqType} returns the type of the Z-axis,
910
one of the set of predefined CDI Z-axis types.
911
The valid CDI Z-axis types are @func{ZAXIS_GENERIC}, @func{ZAXIS_SURFACE},
912
@func{ZAXIS_HYBRID}, @func{ZAXIS_SIGMA}, @func{ZAXIS_PRESSURE}, @func{ZAXIS_HEIGHT},
913
@func{ZAXIS_DEPTH_BELOW_SEA} and @func{ZAXIS_DEPTH_BELOW_LAND}.
917
int zaxisInqType(int zaxisID)
919
static const char *func = "zaxisInqType";
922
zaxisptr = zaxis_to_pointer(zaxisID);
924
zaxis_check_ptr(func, zaxisptr);
926
return (zaxisptr->type);
931
@Function zaxisInqSize
932
@Title Get the size of a Z-axis
934
@Prototype int zaxisInqSize(int zaxisID)
936
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}
939
The function @func{zaxisInqSize} returns the size of a Z-axis.
942
@func{zaxisInqSize} returns the number of levels of a Z-axis.
946
int zaxisInqSize(int zaxisID)
948
static const char *func = "zaxisInqSize";
952
zaxisptr = zaxis_to_pointer(zaxisID);
954
zaxis_check_ptr(func, zaxisptr);
956
size = zaxisptr->size;
962
void cdiCheckZaxis(int zaxisID)
964
static const char *func = "cdiCheckZaxis";
968
zaxisptr = zaxis_to_pointer(zaxisID);
970
zaxis_check_ptr(func, zaxisptr);
972
if ( zaxisInqType(zaxisID) == ZAXIS_GENERIC )
974
size = zaxisptr->size;
977
/* check direction */
978
if ( zaxisptr->direction == CDI_UNDEFID )
981
for ( i = 1; i < size; i++ )
982
if ( zaxisptr->vals[i] > zaxisptr->vals[i-1] )
984
if ( found == size-1 )
986
zaxisptr->direction = LevelUp;
991
for ( i = 1; i < size; i++ )
992
if ( zaxisptr->vals[i] < zaxisptr->vals[i-1] )
994
if ( found == size-1 )
996
zaxisptr->direction = LevelDown;
1000
/* check consistent */
1001
if ( zaxisptr->direction == CDI_UNDEFID )
1003
Warning(func, "direction undefined for zaxisID %d", zaxisID);
1010
void zaxisDefVct(int zaxisID, int size, const double *vct)
1012
static const char *func = "zaxisDefVct";
1015
zaxisptr = zaxis_to_pointer(zaxisID);
1017
zaxis_check_ptr(func, zaxisptr);
1019
if ( zaxisptr->vct == 0 )
1021
zaxisptr->vctsize = size;
1022
zaxisptr->vct = (double *) malloc(size*sizeof(double));
1023
memcpy(zaxisptr->vct, vct, size*sizeof(double));
1026
if ( zaxisptr->vctsize != size )
1027
Warning(func, "VCT was already defined");
1031
int zaxisInqVctSize(int zaxisID)
1033
static const char *func = "zaxisInqVctSize";
1036
zaxisptr = zaxis_to_pointer(zaxisID);
1038
zaxis_check_ptr(func, zaxisptr);
1040
return (zaxisptr->vctsize);
1044
const double *zaxisInqVctPtr(int zaxisID)
1046
static const char *func = "zaxisInqVctPtr";
1049
zaxisptr = zaxis_to_pointer(zaxisID);
1051
zaxis_check_ptr(func, zaxisptr);
1053
return (zaxisptr->vct);
1057
void zaxisDefLbounds(int zaxisID, const double *lbounds)
1059
static const char *func = "zaxisDefLbounds";
1063
zaxisptr = zaxis_to_pointer(zaxisID);
1065
zaxis_check_ptr(func, zaxisptr);
1067
size = zaxisptr->size;
1070
if ( zaxisptr->lbounds != NULL )
1071
Warning(func, "Lower bounds already defined for zaxisID = %d", zaxisID);
1073
if ( zaxisptr->lbounds == NULL )
1074
zaxisptr->lbounds = (double *) malloc(size*sizeof(double));
1076
memcpy(zaxisptr->lbounds, lbounds, size*sizeof(double));
1080
void zaxisDefUbounds(int zaxisID, const double *ubounds)
1082
static const char *func = "zaxisDefUbounds";
1086
zaxisptr = zaxis_to_pointer(zaxisID);
1088
zaxis_check_ptr(func, zaxisptr);
1090
size = zaxisptr->size;
1093
if ( zaxisptr->ubounds != NULL )
1094
Warning(func, "Upper bounds already defined for zaxisID = %d", zaxisID);
1096
if ( zaxisptr->ubounds == NULL )
1097
zaxisptr->ubounds = (double *) malloc(size*sizeof(double));
1099
memcpy(zaxisptr->ubounds, ubounds, size*sizeof(double));
1103
void zaxisDefWeights(int zaxisID, const double *weights)
1105
static const char *func = "zaxisDefWeights";
1109
zaxisptr = zaxis_to_pointer(zaxisID);
1111
zaxis_check_ptr(func, zaxisptr);
1113
size = zaxisptr->size;
1116
if ( zaxisptr->weights != NULL )
1117
Warning(func, "Weights already defined for zaxisID = %d", zaxisID);
1119
if ( zaxisptr->weights == NULL )
1120
zaxisptr->weights = (double *) malloc(size*sizeof(double));
1122
memcpy(zaxisptr->weights, weights, size*sizeof(double));
1126
void zaxisChangeType(int zaxisID, int zaxistype)
1128
static const char *func = "zaxisChangeType";
1131
zaxisptr = zaxis_to_pointer(zaxisID);
1133
zaxis_check_ptr(func, zaxisptr);
1135
Message(func, "Changed zaxis type from %s to %s\n",
1136
zaxisNamePtr(zaxisptr->type),
1137
zaxisNamePtr(zaxistype));
1139
zaxisptr->type = zaxistype;
1143
void zaxisResize(int zaxisID, int size)
1145
static const char *func = "zaxisResize";
1148
zaxisptr = zaxis_to_pointer(zaxisID);
1150
zaxis_check_ptr(func, zaxisptr);
1152
zaxisptr->size = size;
1154
if ( zaxisptr->vals )
1155
zaxisptr->vals = (double *) realloc(zaxisptr->vals, size*sizeof(double));
1159
int zaxisDuplicate(int zaxisID)
1161
static const char *func = "zaxisDuplicate";
1163
int zaxistype, zaxissize;
1165
ZAXIS *zaxisptr, *zaxisptrnew;
1167
zaxisptr = zaxis_to_pointer(zaxisID);
1169
zaxistype = zaxisInqType(zaxisID);
1170
zaxissize = zaxisInqSize(zaxisID);
1172
zaxisIDnew = zaxisCreate(zaxistype, zaxissize);
1173
zaxisptrnew = zaxis_to_pointer(zaxisIDnew);
1175
zaxis_copy(zaxisptrnew, zaxisptr);
1177
strcpy(zaxisptrnew->name, zaxisptr->name);
1178
strcpy(zaxisptrnew->longname, zaxisptr->longname);
1179
strcpy(zaxisptrnew->units, zaxisptr->units);
1181
if ( zaxisptr->vals != NULL )
1185
zaxisptrnew->vals = (double *) malloc(size*sizeof(double));
1186
memcpy(zaxisptrnew->vals, zaxisptr->vals, size*sizeof(double));
1189
if ( zaxisptr->lbounds )
1193
zaxisptrnew->lbounds = (double *) malloc(size*sizeof(double));
1194
memcpy(zaxisptrnew->lbounds, zaxisptr->lbounds, size*sizeof(double));
1197
if ( zaxisptr->ubounds )
1201
zaxisptrnew->ubounds = (double *) malloc(size*sizeof(double));
1202
memcpy(zaxisptrnew->ubounds, zaxisptr->ubounds, size*sizeof(double));
1205
if ( zaxisptr->vct != NULL )
1207
size = zaxisptr->vctsize;
1211
zaxisptrnew->vctsize = size;
1212
zaxisptrnew->vct = (double *) malloc(size*sizeof(double));
1213
memcpy(zaxisptrnew->vct, zaxisptr->vct, size*sizeof(double));
1217
return (zaxisIDnew);
1221
void zaxisPrint(int zaxisID)
1225
int nlevels, levelID;
1230
zaxisptr = zaxis_to_pointer(zaxisID);
1232
type = zaxisInqType(zaxisID);
1233
nlevels = zaxisInqSize(zaxisID);
1237
fprintf(fp, "# zaxisID %d\n", zaxisID);
1239
fprintf(fp, "zaxistype = %s\n", zaxisNamePtr(type));
1240
fprintf(fp, "size = %d\n", nlevels);
1241
if ( zaxisptr->name[0] ) fprintf(fp, "name = %s\n", zaxisptr->name);
1242
if ( zaxisptr->longname[0] ) fprintf(fp, "longname = %s\n", zaxisptr->longname);
1243
if ( zaxisptr->units[0] ) fprintf(fp, "units = %s\n", zaxisptr->units);
1245
nbyte0 = fprintf(fp, "levels = ");
1247
for ( levelID = 0; levelID < nlevels; levelID++ )
1251
fprintf(stdout, "\n");
1252
fprintf(stdout, "%*s", nbyte0, "");
1255
level = zaxisInqLevel(zaxisID, levelID);
1256
nbyte += fprintf(stdout, "%.9g ", level);
1258
fprintf(stdout, "\n");
1260
if ( zaxisptr->lbounds && zaxisptr->ubounds )
1262
double level1, level2;
1264
nbyte0 = fprintf(stdout, "%32s = ", "bounds");
1265
for ( levelID = 0; levelID < nlevels; levelID++ )
1269
fprintf(stdout, "\n");
1270
fprintf(stdout, "%*s", nbyte0, "");
1273
level1 = zaxisInqLbound(zaxisID, levelID);
1274
level2 = zaxisInqUbound(zaxisID, levelID);
1275
nbyte += fprintf(stdout, "%.9g-%.9g ", level1, level2);
1277
fprintf(stdout, "\n");
1280
if ( type == ZAXIS_HYBRID || type == ZAXIS_HYBRID_HALF )
1286
vctsize = zaxisInqVctSize(zaxisID);
1287
vct = zaxisInqVctPtr(zaxisID);
1288
fprintf(stdout, "vctsize = %d\n", vctsize);
1291
nbyte0 = fprintf(stdout, "vct = ");
1293
for ( i = 0; i < vctsize; i++ )
1295
if ( nbyte > 70 || i == vctsize/2 )
1297
fprintf(stdout, "\n%*s", nbyte0, "");
1300
nbyte += fprintf(stdout, "%.9g ", vct[i]);
1302
fprintf(stdout, "\n");
1304
nbyte0 = fprintf(stdout, "vct_b = ");
1306
for ( i = 0; i < vctsize/2; i++ )
1310
fprintf(stdout, "\n%*s", nbyte0, "");
1313
nbyte += fprintf(stdout, "%.9g ", vct[vctsize/2+i]);
1315
fprintf(stdout, "\n");