Commit 09cae606 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

CDI_cmor_mode: Convert Zaxis with one level to Scalar Z-Coordinate on all input streams.

parent ee2d44d6
2016-08-29 Uwe Schulzweida
* CDI_cmor_mode: Convert Zaxis with one level to Scalar Z-Coordinate on all input streams
2016-08-18 Uwe Schulzweida 2016-08-18 Uwe Schulzweida
* Version 1.8.0rc2 released * Version 1.8.0rc2 released
......
...@@ -2682,10 +2682,6 @@ static ...@@ -2682,10 +2682,6 @@ static
void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars,
size_t vctsize_echam, double *vct_echam, unsigned char *uuidOfVGrid) size_t vctsize_echam, double *vct_echam, unsigned char *uuidOfVGrid)
{ {
int ncvarid2;
int i, ilev;
int zaxisindex;
int nbdims, nvertex, nlevel;
int psvarid = -1; int psvarid = -1;
char *pname, *plongname, *punits; char *pname, *plongname, *punits;
size_t vctsize = vctsize_echam; size_t vctsize = vctsize_echam;
...@@ -2714,7 +2710,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2714,7 +2710,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
} }
else else
{ {
for ( i = 0; i < ndims; i++ ) for ( int i = 0; i < ndims; i++ )
{ {
if ( ncvar->dimtype[i] == Z_AXIS ) if ( ncvar->dimtype[i] == Z_AXIS )
zdimid = ncvar->dimids[i]; zdimid = ncvar->dimids[i];
...@@ -2763,11 +2759,11 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2763,11 +2759,11 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
if ( ncvars[zvarid].bounds != UNDEFID ) if ( ncvars[zvarid].bounds != UNDEFID )
{ {
nbdims = ncvars[ncvars[zvarid].bounds].ndims; int nbdims = ncvars[ncvars[zvarid].bounds].ndims;
if ( nbdims == 2 ) if ( nbdims == 2 )
{ {
nlevel = (int)ncdims[ncvars[ncvars[zvarid].bounds].dimids[0]].len; int nlevel = (int)ncdims[ncvars[ncvars[zvarid].bounds].dimids[0]].len;
nvertex = (int)ncdims[ncvars[ncvars[zvarid].bounds].dimids[1]].len; int nvertex = (int)ncdims[ncvars[ncvars[zvarid].bounds].dimids[1]].len;
if ( nlevel == zsize && nvertex == 2 ) if ( nlevel == zsize && nvertex == 2 )
{ {
with_bounds = true; with_bounds = true;
...@@ -2775,7 +2771,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2775,7 +2771,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
ubounds = (double *) Malloc((size_t)nlevel*sizeof(double)); ubounds = (double *) Malloc((size_t)nlevel*sizeof(double));
double zbounds[2*nlevel]; double zbounds[2*nlevel];
cdf_get_var_double(ncvars[zvarid].ncid, ncvars[zvarid].bounds, zbounds); cdf_get_var_double(ncvars[zvarid].ncid, ncvars[zvarid].bounds, zbounds);
for ( i = 0; i < nlevel; ++i ) for ( int i = 0; i < nlevel; ++i )
{ {
lbounds[i] = zbounds[i*2]; lbounds[i] = zbounds[i*2];
ubounds[i] = zbounds[i*2+1]; ubounds[i] = zbounds[i*2+1];
...@@ -2807,14 +2803,16 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2807,14 +2803,16 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
} }
else else
{ {
for ( ilev = 0; ilev < zsize; ilev++ ) zvar[ilev] = ilev + 1; for ( int ilev = 0; ilev < zsize; ilev++ ) zvar[ilev] = ilev + 1;
} }
} }
ncvar->zaxisID = varDefZaxis(vlistID, zaxisType, (int) zsize, zvar, (int)with_bounds, lbounds, ubounds, ncvar->zaxisID = varDefZaxis(vlistID, zaxisType, (int) zsize, zvar, (int)with_bounds, lbounds, ubounds,
(int)vctsize, vct, pname, plongname, punits, zprec, 1, 0); (int)vctsize, vct, pname, plongname, punits, zprec, 1, 0);
if ( uuidOfVGrid[0] != 0 ) if ( CDI_cmor_mode && zsize == 1 && zaxisType != ZAXIS_HYBRID ) zaxisDefScalar(ncvar->zaxisID);
if ( uuidOfVGrid[0] != 0 )
{ {
// printf("uuidOfVGrid: defined\n"); // printf("uuidOfVGrid: defined\n");
zaxisDefUUID(ncvar->zaxisID, uuidOfVGrid); zaxisDefUUID(ncvar->zaxisID, uuidOfVGrid);
...@@ -2835,13 +2833,13 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2835,13 +2833,13 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
Free(lbounds); Free(lbounds);
Free(ubounds); Free(ubounds);
zaxisindex = vlistZaxisIndex(vlistID, ncvar->zaxisID); int zaxisindex = vlistZaxisIndex(vlistID, ncvar->zaxisID);
streamptr->zaxisID[zaxisindex] = zdimid; streamptr->zaxisID[zaxisindex] = zdimid;
if ( CDI_Debug ) if ( CDI_Debug )
Message("zaxisID %d %d %s", ncvar->zaxisID, ncvarid, ncvar->name); Message("zaxisID %d %d %s", ncvar->zaxisID, ncvarid, ncvar->name);
for ( ncvarid2 = ncvarid+1; ncvarid2 < nvars; ncvarid2++ ) for ( int ncvarid2 = ncvarid+1; ncvarid2 < nvars; ncvarid2++ )
if ( ncvars[ncvarid2].isvar == TRUE && ncvars[ncvarid2].zaxisID == UNDEFID /*&& ncvars[ncvarid2].zaxistype == UNDEFID*/ ) if ( ncvars[ncvarid2].isvar == TRUE && ncvars[ncvarid2].zaxisID == UNDEFID /*&& ncvars[ncvarid2].zaxistype == UNDEFID*/ )
{ {
int zvarid2 = UNDEFID; int zvarid2 = UNDEFID;
...@@ -2850,7 +2848,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int ...@@ -2850,7 +2848,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
int zdimid2 = UNDEFID; int zdimid2 = UNDEFID;
ndims = ncvars[ncvarid2].ndims; ndims = ncvars[ncvarid2].ndims;
for ( i = 0; i < ndims; i++ ) for ( int i = 0; i < ndims; i++ )
{ {
if ( ncvars[ncvarid2].dimtype[i] == Z_AXIS ) if ( ncvars[ncvarid2].dimtype[i] == Z_AXIS )
zdimid2 = ncvars[ncvarid2].dimids[i]; zdimid2 = ncvars[ncvarid2].dimids[i];
......
...@@ -158,11 +158,11 @@ varGetEntry(int param, int zaxistype, int ltype1, int tsteptype, const char *nam ...@@ -158,11 +158,11 @@ varGetEntry(int param, int zaxistype, int ltype1, int tsteptype, const char *nam
{ {
if ( name && name[0] && vartable[varID].name && vartable[varID].name[0] ) if ( name && name[0] && vartable[varID].name && vartable[varID].name[0] )
{ {
if ( strcmp(name, vartable[varID].name) == 0 ) return (varID); if ( strcmp(name, vartable[varID].name) == 0 ) return varID;
} }
else else
{ {
return (varID); return varID;
} }
} }
} }
...@@ -326,7 +326,7 @@ static int levelNewEntry(unsigned varID, int level1, int level2, int tileID) ...@@ -326,7 +326,7 @@ static int levelNewEntry(unsigned varID, int level1, int level2, int tileID)
vartable[varID].recordTable[tileID].levelTableSize = levelTableSize; vartable[varID].recordTable[tileID].levelTableSize = levelTableSize;
vartable[varID].recordTable[tileID].levelTable = levelTable; vartable[varID].recordTable[tileID].levelTable = levelTable;
return (levelID); return levelID;
} }
#define UNDEF_PARAM -4711 #define UNDEF_PARAM -4711
...@@ -385,7 +385,7 @@ paramNewEntry(int param) ...@@ -385,7 +385,7 @@ paramNewEntry(int param)
paramInitEntry(varID, param); paramInitEntry(varID, param);
return (varID); return varID;
} }
...@@ -505,37 +505,37 @@ int dblcmp(const void *s1, const void *s2) ...@@ -505,37 +505,37 @@ int dblcmp(const void *s1, const void *s2)
if ( *((double *) s1) < *((double *) s2) ) cmp = -1; if ( *((double *) s1) < *((double *) s2) ) cmp = -1;
else if ( *((double *) s1) > *((double *) s2) ) cmp = 1; else if ( *((double *) s1) > *((double *) s2) ) cmp = 1;
return (cmp); return cmp;
} }
*/ */
static static
int cmpLevelTable(const void* s1, const void* s2) int cmpLevelTable(const void* s1, const void* s2)
{ {
int cmp = 0; int cmp = 0;
const leveltable_t* x = (const leveltable_t*) s1; const leveltable_t *x = (const leveltable_t*) s1;
const leveltable_t* y = (const leveltable_t*) s2; const leveltable_t *y = (const leveltable_t*) s2;
/* /*
printf("%g %g %d %d\n", x->leve11, y->level1, x, y); printf("%g %g %d %d\n", x->leve11, y->level1, x, y);
*/ */
if ( x->level1 < y->level1 ) cmp = -1; if ( x->level1 < y->level1 ) cmp = -1;
else if ( x->level1 > y->level1 ) cmp = 1; else if ( x->level1 > y->level1 ) cmp = 1;
return (cmp); return cmp;
} }
static static
int cmpLevelTableInv(const void* s1, const void* s2) int cmpLevelTableInv(const void* s1, const void* s2)
{ {
int cmp = 0; int cmp = 0;
const leveltable_t* x = (const leveltable_t*) s1; const leveltable_t *x = (const leveltable_t*) s1;
const leveltable_t* y = (const leveltable_t*) s2; const leveltable_t *y = (const leveltable_t*) s2;
/* /*
printf("%g %g %d %d\n", x->leve11, y->level1, x, y); printf("%g %g %d %d\n", x->leve11, y->level1, x, y);
*/ */
if ( x->level1 < y->level1 ) cmp = 1; if ( x->level1 < y->level1 ) cmp = 1;
else if ( x->level1 > y->level1 ) cmp = -1; else if ( x->level1 > y->level1 ) cmp = -1;
return (cmp); return cmp;
} }
...@@ -551,32 +551,19 @@ param_t; ...@@ -551,32 +551,19 @@ param_t;
static static
int cmpparam(const void* s1, const void* s2) int cmpparam(const void* s1, const void* s2)
{ {
const param_t* x = (const param_t*) s1; const param_t *x = (const param_t*) s1;
const param_t* y = (const param_t*) s2; const param_t *y = (const param_t*) s2;
int cmp = (( x->param > y->param ) - ( x->param < y->param )) * 2 int cmp = (( x->param > y->param ) - ( x->param < y->param )) * 2
+ ( x->ltype > y->ltype ) - ( x->ltype < y->ltype ); + ( x->ltype > y->ltype ) - ( x->ltype < y->ltype );
return (cmp); return cmp;
} }
void cdi_generate_vars(stream_t *streamptr) void cdi_generate_vars(stream_t *streamptr)
{ {
int gridID, zaxisID;
int instID, modelID, tableID;
int param, zaxistype, ltype1, ltype2;
int prec;
int tsteptype;
int timave, timaccu;
int lbounds;
int comptype;
char name[CDI_MAX_NAME], longname[CDI_MAX_NAME], units[CDI_MAX_NAME]; char name[CDI_MAX_NAME], longname[CDI_MAX_NAME], units[CDI_MAX_NAME];
double *dlevels = NULL;
double *dlevels1 = NULL;
double *dlevels2 = NULL;
double level_sf = 1;
int vlistID = streamptr->vlistID; int vlistID = streamptr->vlistID;
int *varids = (int *) Malloc(nvars*sizeof(int)); int *varids = (int *) Malloc(nvars*sizeof(int));
...@@ -604,32 +591,30 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -604,32 +591,30 @@ void cdi_generate_vars(stream_t *streamptr)
{ {
int varid = varids[index]; int varid = varids[index];
gridID = vartable[varid].gridID; int gridID = vartable[varid].gridID;
param = vartable[varid].param; int param = vartable[varid].param;
ltype1 = vartable[varid].ltype1; int ltype1 = vartable[varid].ltype1;
ltype2 = vartable[varid].ltype2; int ltype2 = vartable[varid].ltype2;
zaxistype = vartable[varid].zaxistype; int zaxistype = vartable[varid].zaxistype;
if ( ltype1 == 0 && zaxistype == ZAXIS_GENERIC && cdiDefaultLeveltype != -1 ) if ( ltype1 == 0 && zaxistype == ZAXIS_GENERIC && cdiDefaultLeveltype != -1 )
zaxistype = cdiDefaultLeveltype; zaxistype = cdiDefaultLeveltype;
lbounds = vartable[varid].lbounds; int lbounds = vartable[varid].lbounds;
prec = vartable[varid].prec; int prec = vartable[varid].prec;
instID = vartable[varid].instID; int instID = vartable[varid].instID;
modelID = vartable[varid].modelID; int modelID = vartable[varid].modelID;
tableID = vartable[varid].tableID; int tableID = vartable[varid].tableID;
tsteptype = vartable[varid].tsteptype; int tsteptype = vartable[varid].tsteptype;
timave = vartable[varid].timave; int timave = vartable[varid].timave;
timaccu = vartable[varid].timaccu; int timaccu = vartable[varid].timaccu;
comptype = vartable[varid].comptype; int comptype = vartable[varid].comptype;
level_sf = 1; double level_sf = 1;
if ( vartable[varid].level_sf != 0 ) level_sf = 1./vartable[varid].level_sf; if ( vartable[varid].level_sf != 0 ) level_sf = 1./vartable[varid].level_sf;
zaxisID = UNDEFID;
/* consistency check: test if all subtypes have the same levels: */ /* consistency check: test if all subtypes have the same levels: */
unsigned nlevels = vartable[varid].recordTable[0].nlevels; unsigned nlevels = vartable[varid].recordTable[0].nlevels;
for (int isub=1; isub<vartable[varid].nsubtypes; isub++) { for ( int isub = 1; isub < vartable[varid].nsubtypes; isub++ ) {
if (vartable[varid].recordTable[isub].nlevels != nlevels) if ( vartable[varid].recordTable[isub].nlevels != nlevels )
{ {
fprintf(stderr, "var \"%s\": isub = %d / %d :: " fprintf(stderr, "var \"%s\": isub = %d / %d :: "
"nlevels = %d, vartable[varid].recordTable[isub].nlevels = %d\n", "nlevels = %d, vartable[varid].recordTable[isub].nlevels = %d\n",
...@@ -640,7 +625,7 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -640,7 +625,7 @@ void cdi_generate_vars(stream_t *streamptr)
leveltable_t *t1 = vartable[varid].recordTable[isub-1].levelTable; leveltable_t *t1 = vartable[varid].recordTable[isub-1].levelTable;
leveltable_t *t2 = vartable[varid].recordTable[isub ].levelTable; leveltable_t *t2 = vartable[varid].recordTable[isub ].levelTable;
for (unsigned ilev=0; ilev<nlevels; ilev++) for ( unsigned ilev = 0; ilev < nlevels; ilev++ )
if ((t1[ilev].level1 != t2[ilev].level1) || if ((t1[ilev].level1 != t2[ilev].level1) ||
(t1[ilev].level2 != t2[ilev].level2) || (t1[ilev].level2 != t2[ilev].level2) ||
(t1[ilev].lindex != t2[ilev].lindex)) (t1[ilev].lindex != t2[ilev].lindex))
...@@ -649,32 +634,31 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -649,32 +634,31 @@ void cdi_generate_vars(stream_t *streamptr)
"nlevels = %d, vartable[varid].recordTable[isub].nlevels = %d\n", "nlevels = %d, vartable[varid].recordTable[isub].nlevels = %d\n",
vartable[varid].name, varid, isub, vartable[varid].nsubtypes, vartable[varid].name, varid, isub, vartable[varid].nsubtypes,
nlevels, vartable[varid].recordTable[isub].nlevels); nlevels, vartable[varid].recordTable[isub].nlevels);
Message("t1[ilev].level1=%d / t2[ilev].level1=%d",t1[ilev].level1, t2[ilev].level1); Message("t1[ilev].level1=%d / t2[ilev].level1=%d", t1[ilev].level1, t2[ilev].level1);
Message("t1[ilev].level2=%d / t2[ilev].level2=%d",t1[ilev].level2, t2[ilev].level2); Message("t1[ilev].level2=%d / t2[ilev].level2=%d", t1[ilev].level2, t2[ilev].level2);
Message("t1[ilev].lindex=%d / t2[ilev].lindex=%d",t1[ilev].lindex, t2[ilev].lindex); Message("t1[ilev].lindex=%d / t2[ilev].lindex=%d", t1[ilev].lindex, t2[ilev].lindex);
Error("zaxis type must not change for same parameter!"); Error("zaxis type must not change for same parameter!");
} }
} }
leveltable_t *levelTable = vartable[varid].recordTable[0].levelTable; leveltable_t *levelTable = vartable[varid].recordTable[0].levelTable;
if ( ltype1 == 0 && zaxistype == ZAXIS_GENERIC && nlevels == 1 && if ( ltype1 == 0 && zaxistype == ZAXIS_GENERIC && nlevels == 1 && levelTable[0].level1 == 0 )
levelTable[0].level1 == 0 )
zaxistype = ZAXIS_SURFACE; zaxistype = ZAXIS_SURFACE;
dlevels = (double *) Malloc(nlevels*sizeof(double)); double *dlevels = (double *) Malloc(nlevels*sizeof(double));
if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF ) if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
for (unsigned levelID = 0; levelID < nlevels; levelID++ ) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
dlevels[levelID] = (level_sf*levelTable[levelID].level1 + dlevels[levelID] = (level_sf*levelTable[levelID].level1 +
level_sf*levelTable[levelID].level2)/2; level_sf*levelTable[levelID].level2)/2;
else else
for (unsigned levelID = 0; levelID < nlevels; levelID++ ) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
dlevels[levelID] = level_sf*levelTable[levelID].level1; dlevels[levelID] = level_sf*levelTable[levelID].level1;
if ( nlevels > 1 ) if ( nlevels > 1 )
{ {
bool linc = true, ldec = true, lsort = false; bool linc = true, ldec = true, lsort = false;
for (unsigned levelID = 1; levelID < nlevels; levelID++ ) for ( unsigned levelID = 1; levelID < nlevels; levelID++ )
{ {
/* check increasing of levels */ /* check increasing of levels */
linc &= (dlevels[levelID] > dlevels[levelID-1]); linc &= (dlevels[levelID] > dlevels[levelID-1]);
...@@ -707,33 +691,34 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -707,33 +691,34 @@ void cdi_generate_vars(stream_t *streamptr)
if ( lsort ) if ( lsort )
{ {
if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF ) if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
for (unsigned levelID = 0; levelID < nlevels; levelID++ ) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
dlevels[levelID] = (level_sf*levelTable[levelID].level1 + dlevels[levelID] = (level_sf*levelTable[levelID].level1 +
level_sf*levelTable[levelID].level2)/2.; level_sf*levelTable[levelID].level2)/2.;
else else
for (unsigned levelID = 0; levelID < nlevels; levelID++ ) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
dlevels[levelID] = level_sf*levelTable[levelID].level1; dlevels[levelID] = level_sf*levelTable[levelID].level1;
} }
} }
double *dlevels1 = NULL;
double *dlevels2 = NULL;
if ( lbounds ) if ( lbounds )
{ {
dlevels1 = (double *) Malloc(nlevels*sizeof(double)); dlevels1 = (double *) Malloc(nlevels*sizeof(double));
for (unsigned levelID = 0; levelID < nlevels; levelID++) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
dlevels1[levelID] = level_sf*levelTable[levelID].level1; dlevels1[levelID] = level_sf*levelTable[levelID].level1;
dlevels2 = (double *) Malloc(nlevels*sizeof(double)); dlevels2 = (double *) Malloc(nlevels*sizeof(double));
for (unsigned levelID = 0; levelID < nlevels; levelID++) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
dlevels2[levelID] = level_sf*levelTable[levelID].level2; dlevels2[levelID] = level_sf*levelTable[levelID].level2;
} }
const char *unitptr = cdiUnitNamePtr(vartable[varid].level_unit); const char *unitptr = cdiUnitNamePtr(vartable[varid].level_unit);
zaxisID = varDefZaxis(vlistID, zaxistype, (int)nlevels, dlevels, lbounds, dlevels1, dlevels2, int zaxisID = varDefZaxis(vlistID, zaxistype, (int)nlevels, dlevels, lbounds, dlevels1, dlevels2,
(int)Vctsize, Vct, NULL, NULL, unitptr, 0, 0, ltype1); (int)Vctsize, Vct, NULL, NULL, unitptr, 0, 0, ltype1);
if ( ltype1 != ltype2 && ltype2 != -1 ) if ( CDI_cmor_mode && nlevels == 1 && zaxistype != ZAXIS_HYBRID ) zaxisDefScalar(zaxisID);
{
zaxisDefLtype2(zaxisID, ltype2); if ( ltype1 != ltype2 && ltype2 != -1 ) zaxisDefLtype2(zaxisID, ltype2);
}
if ( zaxisInqType(zaxisID) == ZAXIS_REFERENCE ) if ( zaxisInqType(zaxisID) == ZAXIS_REFERENCE )
{ {
...@@ -776,10 +761,8 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -776,10 +761,8 @@ void cdi_generate_vars(stream_t *streamptr)
vartable[varid].ensdata->ens_count, vartable[varid].ensdata->ens_count,
vartable[varid].ensdata->forecast_init_type); vartable[varid].ensdata->forecast_init_type);
int i; vlist_t *vlistptr = vlist_to_pointer(vlistID);
vlist_t *vlistptr; for ( int i = 0; i < vartable[varid].opt_grib_nentries; i++ )
vlistptr = vlist_to_pointer(vlistID);
for (i=0; i<vartable[varid].opt_grib_nentries; i++)
{ {
resize_opt_grib_entries(&vlistptr->vars[varID], vlistptr->vars[varID].opt_grib_nentries+1); resize_opt_grib_entries(&vlistptr->vars[varID], vlistptr->vars[varID].opt_grib_nentries+1);
vlistptr->vars[varID].opt_grib_nentries += 1; vlistptr->vars[varID].opt_grib_nentries += 1;
...@@ -787,8 +770,8 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -787,8 +770,8 @@ void cdi_generate_vars(stream_t *streamptr)
vlistptr->vars[varID].opt_grib_kvpair[idx] = vartable[varid].opt_grib_kvpair[i]; vlistptr->vars[varID].opt_grib_kvpair[idx] = vartable[varid].opt_grib_kvpair[i];
vlistptr->vars[varID].opt_grib_kvpair[idx].keyword = NULL; vlistptr->vars[varID].opt_grib_kvpair[idx].keyword = NULL;
if (vartable[varid].opt_grib_kvpair[i].keyword) if ( vartable[varid].opt_grib_kvpair[i].keyword )
vlistptr->vars[varID].opt_grib_kvpair[idx].keyword = vlistptr->vars[varID].opt_grib_kvpair[idx].keyword =
strdupx(vartable[varid].opt_grib_kvpair[i].keyword); strdupx(vartable[varid].opt_grib_kvpair[i].keyword);
vlistptr->vars[varID].opt_grib_kvpair[i].update = TRUE; vlistptr->vars[varID].opt_grib_kvpair[i].update = TRUE;
} }
...@@ -832,29 +815,18 @@ void cdi_generate_vars(stream_t *streamptr) ...@@ -832,29 +815,18 @@ void cdi_generate_vars(stream_t *streamptr)
int varid = varids[index]; int varid = varids[index];
unsigned nlevels = vartable[varid].recordTable[0].nlevels; unsigned nlevels = vartable[varid].recordTable[0].nlevels;
/* unsigned nsub = vartable[varid].nsubtypes >= 0 ? (unsigned)vartable[varid].nsubtypes : 0U;
for ( levelID = 0; levelID < nlevels; levelID++ ) for ( size_t isub = 0; isub < nsub; isub++ )
{
printf("%d %d %d %d %d\n", varid, levelID,
vartable[varid].levelTable[levelID].lindex,
vartable[varid].levelTable[levelID].recID,
vartable[varid].levelTable[levelID].level1);
}
*/
unsigned nsub = vartable[varid].nsubtypes >= 0
? (unsigned)vartable[varid].nsubtypes : 0U;
for (size_t isub=0; isub < nsub; isub++)
{ {
sleveltable_t *restrict streamRecordTable sleveltable_t *restrict streamRecordTable
= streamptr->vars[index].recordTable + isub; = streamptr->vars[index].recordTable + isub;
leveltable_t *restrict vartableLevelTable leveltable_t *restrict vartableLevelTable
= vartable[varid].recordTable[isub].levelTable; = vartable[varid].recordTable[isub].levelTable;
for (unsigned levelID = 0; levelID < nlevels; levelID++) for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
{ {
streamRecordTable->recordID[levelID] streamRecordTable->recordID[levelID] = vartableLevelTable[levelID].recID;
= vartableLevelTable[levelID].recID;
unsigned lindex; unsigned lindex;
for (lindex = 0; lindex < nlevels; lindex++ ) for ( lindex = 0; lindex < nlevels; lindex++ )
if ( levelID == (unsigned)vartableLevelTable[lindex].lindex ) if ( levelID == (unsigned)vartableLevelTable[lindex].lindex )
break; break;
if ( lindex == nlevels ) if ( lindex == nlevels )
...@@ -932,7 +904,7 @@ int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const dou ...@@ -932,7 +904,7 @@ int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const dou
} }
} }
return (differ); return differ;
} }
struct varDefZAxisSearchState struct varDefZAxisSearchState
...@@ -1041,7 +1013,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, const double *levels, i ...@@ -1041,7 +1013,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, const double *levels, i
vlistptr->nzaxis++; vlistptr->nzaxis++;
} }
return (zaxisID); return zaxisID;
} }