From 2f84ae5f54d938f72aaec2d283376be64a23dc36 Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Fri, 10 Feb 2017 20:33:09 +0100 Subject: [PATCH] Merge declaration and definition. --- src/stream_cdf_i.c | 20 ++++++++++---------- src/stream_cgribex.c | 15 +++++---------- src/stream_gribapi.c | 26 ++++++++------------------ 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/src/stream_cdf_i.c b/src/stream_cdf_i.c index c3fa8b00d..8eb751080 100644 --- a/src/stream_cdf_i.c +++ b/src/stream_cdf_i.c @@ -2895,17 +2895,17 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int } -struct varinfo +struct cdf_varinfo { - int ncvarid; + int varid; const char *name; }; static -int cmpvarname(const void *s1, const void *s2) +int cdf_cmp_varname(const void *s1, const void *s2) { - const struct varinfo *x = (const struct varinfo *)s1, - *y = (const struct varinfo *)s2; + const struct cdf_varinfo *x = (const struct cdf_varinfo *)s1, + *y = (const struct cdf_varinfo *)s2; return strcmp(x->name, y->name); } @@ -2918,19 +2918,19 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model if ( streamptr->sortname ) { - struct varinfo *varInfo - = (struct varinfo *) Malloc((size_t)nvars * sizeof (struct varinfo)); + struct cdf_varinfo *varInfo + = (struct cdf_varinfo *) Malloc((size_t)nvars * sizeof(struct cdf_varinfo)); for ( int varID = 0; varID < nvars; varID++ ) { int ncvarid = varids[varID]; - varInfo[varID].ncvarid = ncvarid; + varInfo[varID].varid = ncvarid; varInfo[varID].name = ncvars[ncvarid].name; } - qsort(varInfo, (size_t)nvars, sizeof(varInfo[0]), cmpvarname); + qsort(varInfo, (size_t)nvars, sizeof(varInfo[0]), cdf_cmp_varname); for ( int varID = 0; varID < nvars; varID++ ) { - varids[varID] = varInfo[varID].ncvarid; + varids[varID] = varInfo[varID].varid; } Free(varInfo); if ( CDI_Debug ) diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c index d7afade35..5173931cf 100644 --- a/src/stream_cgribex.c +++ b/src/stream_cgribex.c @@ -424,10 +424,9 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d if ( varInqInst(varID) == CDI_UNDEFID ) { - int center, subcenter, instID; - center = ISEC1_CenterID; - subcenter = ISEC1_SubCenterID; - instID = institutInq(center, subcenter, NULL, NULL); + int center = ISEC1_CenterID; + int subcenter = ISEC1_SubCenterID; + int instID = institutInq(center, subcenter, NULL, NULL); if ( instID == CDI_UNDEFID ) instID = institutDef(center, subcenter, NULL, NULL); varDefInst(varID, instID); @@ -435,8 +434,7 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d if ( varInqModel(varID) == CDI_UNDEFID ) { - int modelID; - modelID = modelInq(varInqInst(varID), ISEC1_ModelID, NULL); + int modelID = modelInq(varInqInst(varID), ISEC1_ModelID, NULL); if ( modelID == CDI_UNDEFID ) modelID = modelDef(varInqInst(varID), ISEC1_ModelID, NULL); varDefModel(varID, modelID); @@ -444,10 +442,7 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d if ( varInqTable(varID) == CDI_UNDEFID ) { - int tableID; - - tableID = tableInq(varInqModel(varID), ISEC1_CodeTable, NULL); - + int tableID = tableInq(varInqModel(varID), ISEC1_CodeTable, NULL); if ( tableID == CDI_UNDEFID ) tableID = tableDef(varInqModel(varID), ISEC1_CodeTable, NULL); varDefTable(varID, tableID); diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c index 8dd6a920b..1a48553ac 100644 --- a/src/stream_gribapi.c +++ b/src/stream_gribapi.c @@ -430,11 +430,11 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, int vlistID = streamptr->vlistID; int tsID = streamptr->curTsID; int recID = recordNewEntry(streamptr, tsID); - record_t *record = &streamptr->tsteps[tsID].records[recID]; + record_t *record = &streamptr->tsteps[tsID].records[recID]; int tsteptype = gribapiGetTsteptype(gh); // numavg = ISEC1_AvgNum; - int numavg = 0; + int numavg = 0; // fprintf(stderr, "param %d %d %d %d\n", param, level1, level2, leveltype1); @@ -504,10 +504,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, unsigned char uuid[CDI_UUID_SIZE]; long lpar; GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0); - if ( lpar != 6 ) - { - fprintf(stderr, "Warning ...\n"); - } + if ( lpar != 6 ) fprintf(stderr, "Warning ...\n"); GRIB_CHECK(grib_get_long(gh, "nlev", &lpar), 0); int nhlev = (int)lpar; GRIB_CHECK(grib_get_long(gh, "numberOfVGridUsed", &lpar), 0); @@ -572,12 +569,11 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, if ( grib_get_long(gh, "productDefinitionTemplateNumber", &productDefinitionTemplate) == 0 ) varDefProductDefinitionTemplate(varID, (int) productDefinitionTemplate); - int i; long lval; double dval; if (lread_additional_keys) - for ( i = 0; i < cdiNAdditionalGRIBKeys; i++ ) + for ( int i = 0; i < cdiNAdditionalGRIBKeys; i++ ) { /* note: if the key is not defined, we do not throw an error! */ if ( grib_get_long(gh, cdiAdditionalGRIBKeys[i], &lval) == 0 ) @@ -589,10 +585,9 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, if ( varInqInst(varID) == CDI_UNDEFID ) { long center, subcenter; - int instID; GRIB_CHECK(grib_get_long(gh, "centre", ¢er), 0); GRIB_CHECK(grib_get_long(gh, "subCentre", &subcenter), 0); - instID = institutInq((int)center, (int)subcenter, NULL, NULL); + int instID = institutInq((int)center, (int)subcenter, NULL, NULL); if ( instID == CDI_UNDEFID ) instID = institutDef((int)center, (int)subcenter, NULL, NULL); varDefInst(varID, instID); @@ -600,12 +595,11 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, if ( varInqModel(varID) == CDI_UNDEFID ) { - int modelID; long processID; if ( grib_get_long(gh, "generatingProcessIdentifier", &processID) == 0 ) { /* FIXME: assert(processID >= INT_MIN && processID <= INT_MAX) */ - modelID = modelInq(varInqInst(varID), (int)processID, NULL); + int modelID = modelInq(varInqInst(varID), (int)processID, NULL); if ( modelID == CDI_UNDEFID ) modelID = modelDef(varInqInst(varID), (int)processID, NULL); varDefModel(varID, modelID); @@ -615,16 +609,12 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, if ( varInqTable(varID) == CDI_UNDEFID ) { int pdis, pcat, pnum; - cdiDecodeParam(param, &pnum, &pcat, &pdis); if ( pdis == 255 ) { - int tableID; int tabnum = pcat; - - tableID = tableInq(varInqModel(varID), tabnum, NULL); - + int tableID = tableInq(varInqModel(varID), tabnum, NULL); if ( tableID == CDI_UNDEFID ) tableID = tableDef(varInqModel(varID), tabnum, NULL); varDefTable(varID, tableID); @@ -639,7 +629,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, varID, param, zaxistype, gridID, levelID); } -static compvar2_t gribapiVarSet(int param, int level1, int level2, int leveltype, +static compvar2_t gribapiVarSet(int param, int level1, int level2, int leveltype, int tsteptype, char *name, var_tile_t tiles_data) { compvar2_t compVar; -- GitLab