diff --git a/src/cdi_int.c b/src/cdi_int.c index 1ed0932e0210f132ef31b693e3d7997df759308e..0894198fdcc33163e6d97f94edf54b2d0e4f0b37 100644 --- a/src/cdi_int.c +++ b/src/cdi_int.c @@ -67,6 +67,7 @@ int cdiGribApiDebug = 0; int cdiDefaultLeveltype = -1; int cdiDataUnreduced = 0; int cdiSortName = 0; +int cdiSortParam = 0; int cdiHaveMissval = 0; @@ -297,6 +298,9 @@ void cdiInitialize(void) value = cdiGetenvInt("CDI_SORTNAME"); if ( value >= 0 ) cdiSortName = (int) value; + value = cdiGetenvInt("CDI_SORTPARAM"); + if ( value >= 0 ) cdiSortParam = (int) value; + value = cdiGetenvInt("CDI_HAVE_MISSVAL"); if ( value >= 0 ) cdiHaveMissval = (int) value; @@ -420,6 +424,7 @@ void cdiDefGlobal(const char *string, int val) if ( strcmp(string, "REGULARGRID") == 0 ) cdiDataUnreduced = val; else if ( strcmp(string, "GRIBAPI_DEBUG") == 0 ) cdiGribApiDebug = val; else if ( strcmp(string, "SORTNAME") == 0 ) cdiSortName = val; + else if ( strcmp(string, "SORTPARAM") == 0 ) cdiSortParam = val; else if ( strcmp(string, "HAVE_MISSVAL") == 0 ) cdiHaveMissval = val; else if ( strcmp(string, "NC_CHUNKSIZEHINT") == 0 ) cdiNcChunksizehint = val; else if ( strcmp(string, "CMOR_MODE") == 0 ) CDI_cmor_mode = val; diff --git a/src/cdi_int.h b/src/cdi_int.h index 3df41a5dbf3e5a38acbd88a9ca8c8832e8c82958..f01011e8efa9de78af0251e8f225e9326258db51 100644 --- a/src/cdi_int.h +++ b/src/cdi_int.h @@ -254,10 +254,11 @@ typedef struct { int globalatts; int localatts; int unreduced; - int sortname; int have_missval; int comptype; // compression type int complevel; // compression level + bool sortname; + bool sortparam; #if defined (GRIBCONTAINER2D) void **gribContainers; #else @@ -317,6 +318,7 @@ extern int cdiChunkType; extern int cdiSplitLtype105; extern int cdiDataUnreduced; extern int cdiSortName; +extern int cdiSortParam; extern int cdiHaveMissval; extern int cdiIgnoreAttCoordinates; extern int cdiIgnoreValidRange; diff --git a/src/stream.c b/src/stream.c index 85d536145697909d2bc25b91d26ae8f7026a9635..844d706e2d2c35d9a2c0fcb7bd5859ef77b2a073 100644 --- a/src/stream.c +++ b/src/stream.c @@ -872,7 +872,8 @@ void streamDefaultValue ( stream_t * streamptr ) streamptr->globalatts = 0; streamptr->localatts = 0; streamptr->unreduced = cdiDataUnreduced; - streamptr->sortname = cdiSortName; + streamptr->sortname = cdiSortName > 0; + streamptr->sortparam = cdiSortParam > 0; streamptr->have_missval = cdiHaveMissval; streamptr->comptype = CDI_COMPRESS_NONE; streamptr->complevel = 0; diff --git a/src/stream_cdf_i.c b/src/stream_cdf_i.c index 5df70a4494c4fe07730358b8310fc45bfeb9f7b8..c3fa8b00d859b20c093877561dabdc6066771fe8 100644 --- a/src/stream_cdf_i.c +++ b/src/stream_cdf_i.c @@ -2894,6 +2894,7 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int } } + struct varinfo { int ncvarid; diff --git a/src/varscan.c b/src/varscan.c index 6b3d99a66e3358310fbfc8f2ade5ee06654f271b..01942f05d902f02c75056d35452192c6b7e0a569 100644 --- a/src/varscan.c +++ b/src/varscan.c @@ -534,20 +534,16 @@ int cmpLevelTableInv(const void* s1, const void* s2) } -typedef struct +struct paraminfo { - int varid; - int param; - int ltype; -} -param_t; - + int varid, param, ltype; +}; static int cmpparam(const void* s1, const void* s2) { - const param_t *x = (const param_t*) s1; - const param_t *y = (const param_t*) s2; + const struct paraminfo *x = (const struct paraminfo*) s1; + const struct paraminfo *y = (const struct paraminfo*) s2; int cmp = (( x->param > y->param ) - ( x->param < y->param )) * 2 + ( x->ltype > y->ltype ) - ( x->ltype < y->ltype ); @@ -564,9 +560,9 @@ void cdi_generate_vars(stream_t *streamptr) int *varids = (int *) Malloc(nvars*sizeof(int)); for ( unsigned varID = 0; varID < nvars; varID++ ) varids[varID] = (int)varID; - if ( streamptr->sortname ) + if ( streamptr->sortparam ) { - param_t *varInfo = (param_t *) Malloc((size_t)nvars * sizeof (param_t)); + struct paraminfo *varInfo = (struct paraminfo *) Malloc((size_t)nvars * sizeof(struct paraminfo)); for ( unsigned varID = 0; varID < nvars; varID++ ) { @@ -574,7 +570,7 @@ void cdi_generate_vars(stream_t *streamptr) varInfo[varID].param = vartable[varID].param; varInfo[varID].ltype = vartable[varID].ltype1; } - qsort(varInfo, (size_t)nvars, sizeof(param_t), cmpparam); + qsort(varInfo, (size_t)nvars, sizeof(struct paraminfo), cmpparam); for ( unsigned varID = 0; varID < nvars; varID++ ) { varids[varID] = varInfo[varID].varid;