diff --git a/ChangeLog b/ChangeLog index 23fe4d40bdf272713024ef5d287b7dbeca48cb77..94862ae32617b509e4cb363a2c5b471314d3e543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2017-01-?? Uwe Schulzweida +2017-02-14 Uwe Schulzweida * using CGRIBEX library version 1.7.6 * Version 1.8.0 released diff --git a/NEWS b/NEWS index 487f9727fb9c78fa975780e9ec369fbbafc9b551..8bda3a1c06753d61f78d558a20b54eb080aa2c2c 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ CDI NEWS -------- -Version 1.8.0 (26 October 2016): +Version 1.8.0 (14 February 2017): New features: * Refactor horizontal and vertical grid module diff --git a/configure b/configure index 2aa8ebb65e25567e28a39afd0ce57f7aa4c70556..412985104e8f880fb4da5b917bcfe402fa7bd950 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for cdi 1.8.0rc7. +# Generated by GNU Autoconf 2.68 for cdi 1.8.0. # # Report bugs to <http://mpimet.mpg.de/cdi>. # @@ -570,8 +570,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='cdi' PACKAGE_TARNAME='cdi' -PACKAGE_VERSION='1.8.0rc7' -PACKAGE_STRING='cdi 1.8.0rc7' +PACKAGE_VERSION='1.8.0' +PACKAGE_STRING='cdi 1.8.0' PACKAGE_BUGREPORT='http://mpimet.mpg.de/cdi' PACKAGE_URL='' @@ -1460,7 +1460,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures cdi 1.8.0rc7 to adapt to many kinds of systems. +\`configure' configures cdi 1.8.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1530,7 +1530,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of cdi 1.8.0rc7:";; + short | recursive ) echo "Configuration of cdi 1.8.0:";; esac cat <<\_ACEOF @@ -1723,7 +1723,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -cdi configure 1.8.0rc7 +cdi configure 1.8.0 generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. @@ -2568,7 +2568,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by cdi $as_me 1.8.0rc7, which was +It was created by cdi $as_me 1.8.0, which was generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -3520,7 +3520,7 @@ fi # Define the identity of the package. PACKAGE='cdi' - VERSION='1.8.0rc7' + VERSION='1.8.0' cat >>confdefs.h <<_ACEOF @@ -23389,7 +23389,7 @@ Usage: $0 [OPTIONS] Report bugs to <bug-libtool@gnu.org>." lt_cl_version="\ -cdi config.lt 1.8.0rc7 +cdi config.lt 1.8.0 configured by $0, generated by GNU Autoconf 2.68. Copyright (C) 2011 Free Software Foundation, Inc. @@ -30534,7 +30534,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by cdi $as_me 1.8.0rc7, which was +This file was extended by cdi $as_me 1.8.0, which was generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -30600,7 +30600,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -cdi config.status 1.8.0rc7 +cdi config.status 1.8.0 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 100dbbba5fc6da9c650d4895cc63e501f746e124..63bedadf757817cbb9279fb2429c093770ea5d83 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ # autoconf 2.68 # libtool 2.4.2 -AC_INIT([cdi], [1.8.0rc7], [http://mpimet.mpg.de/cdi]) +AC_INIT([cdi], [1.8.0], [http://mpimet.mpg.de/cdi]) AC_DEFINE_UNQUOTED(CDI, ["$PACKAGE_VERSION"], [CDI version]) diff --git a/src/cdi.h b/src/cdi.h index b736662f67699e7472e3c02c0176b4c036329717..c9cc8cb70ccc5acaea58151664ad622ab0be5494 100644 --- a/src/cdi.h +++ b/src/cdi.h @@ -707,6 +707,8 @@ int cdiInqNatts(int cdiID, int varID, int *nattsp); int cdiInqAtt(int cdiID, int varID, int attrnum, char *name, int *typep, int *lenp); int cdiDelAtt(int cdiID, int varID, const char *name); +int cdiCopyAtts(int cdiID1, int varID1, int cdiID2, int varID2); + /* cdiDefAttInt: Define an integer attribute */ int cdiDefAttInt(int cdiID, int varID, const char *name, int type, int len, const int ip[]); /* cdiDefAttFlt: Define a floating point attribute */ @@ -965,6 +967,7 @@ int gridInqComplexPacking(int gridID); /* ZAXIS routines */ void zaxisName(int zaxistype, char *zaxisname); +const char *zaxisNamePtr(int leveltype); /* zaxisCreate: Create a vertical Z-axis */ int zaxisCreate(int zaxistype, int size); diff --git a/src/cdi.inc b/src/cdi.inc index 5c469f15ee2a9296163c5c46cc6afff6f8a69808..103b388686ecff859c1918cc9977cec917057c31 100644 --- a/src/cdi.inc +++ b/src/cdi.inc @@ -4,7 +4,7 @@ ! ! Author: ! ------- -! Uwe Schulzweida, MPI-MET, Hamburg, January 2017 +! Uwe Schulzweida, MPI-MET, Hamburg, February 2017 ! INTEGER CDI_MAX_NAME @@ -1407,6 +1407,13 @@ ! CHARACTER*(*) name) EXTERNAL cdiDelAtt + INTEGER cdiCopyAtts +! (INTEGER cdiID1, +! INTEGER varID1, +! INTEGER cdiID2, +! INTEGER varID2) + EXTERNAL cdiCopyAtts + INTEGER cdiDefAttInt ! (INTEGER cdiID, ! INTEGER varID, @@ -1600,10 +1607,10 @@ PARAMETER (CDI_KEY_YUNITS = 914) INTEGER CDI_KEY_VDIMNAME PARAMETER (CDI_KEY_VDIMNAME = 920) - INTEGER CDI_KEY_MAPNAME - PARAMETER (CDI_KEY_MAPNAME = 921) INTEGER CDI_KEY_MAPPING - PARAMETER (CDI_KEY_MAPPING = 922) + PARAMETER (CDI_KEY_MAPPING = 921) + INTEGER CDI_KEY_MAPNAME + PARAMETER (CDI_KEY_MAPNAME = 922) ! ! CDI zaxis string key values ! @@ -1939,6 +1946,10 @@ ! CHARACTER*(*) zaxisname) EXTERNAL zaxisName + CHARACTER(80) zaxisNamePtr +! (INTEGER leveltype) + EXTERNAL zaxisNamePtr + INTEGER zaxisCreate ! (INTEGER zaxistype, ! INTEGER size) diff --git a/src/cdiFortran.c b/src/cdiFortran.c index 840dbd4bd8d245824d85c2e24f41121c80d8f746..2202400b709df42896e9401f7dcb4e0fecacf670 100644 --- a/src/cdiFortran.c +++ b/src/cdiFortran.c @@ -292,6 +292,7 @@ FCALLSCFUN2 (STRING, vlistInqVarUnitsPtr, VLISTINQVARUNITSPTR, vlistinqvarunitsp FCALLSCFUN3 (INT, cdiInqNatts, CDIINQNATTS, cdiinqnatts, INT, INT, PINT) FCALLSCFUN6 (INT, cdiInqAtt, CDIINQATT, cdiinqatt, INT, INT, INT, PSTRING, PINT, PINT) FCALLSCFUN3 (INT, cdiDelAtt, CDIDELATT, cdidelatt, INT, INT, STRING) +FCALLSCFUN4 (INT, cdiCopyAtts, CDICOPYATTS, cdicopyatts, INT, INT, INT, INT) FCALLSCFUN6 (INT, cdiDefAttInt, CDIDEFATTINT, cdidefattint, INT, INT, STRING, INT, INT, INTV) FCALLSCFUN6 (INT, cdiDefAttFlt, CDIDEFATTFLT, cdidefattflt, INT, INT, STRING, INT, INT, DOUBLEV) FCALLSCFUN5 (INT, cdiDefAttTxt, CDIDEFATTTXT, cdidefatttxt, INT, INT, STRING, INT, PPSTRING) @@ -404,6 +405,7 @@ FCALLSCFUN1 (INT, gridInqComplexPacking, GRIDINQCOMPLEXPACKING, gridinqcomplexpa /* ZAXIS routines */ FCALLSCSUB2 (zaxisName, ZAXISNAME, zaxisname, INT, PSTRING) +FCALLSCFUN1 (STRING, zaxisNamePtr, ZAXISNAMEPTR, zaxisnameptr, INT) FCALLSCFUN2 (INT, zaxisCreate, ZAXISCREATE, zaxiscreate, INT, INT) FCALLSCSUB1 (zaxisDestroy, ZAXISDESTROY, zaxisdestroy, INT) FCALLSCFUN1 (INT, zaxisInqType, ZAXISINQTYPE, zaxisinqtype, INT) diff --git a/src/cdi_att.c b/src/cdi_att.c index 5a3a0cac99b2a34ee41b1d3f754643e7509f24ff..2f1450d6b7f1f62d24b8373acf284b4ca6dff698 100644 --- a/src/cdi_att.c +++ b/src/cdi_att.c @@ -289,17 +289,17 @@ int cdi_inq_att(int indtype, int cdiID, int varID, const char *name, size_t mxsz } -int cdiCopyVarAtts(int cdiID1, int varID_1, int cdiID2, int varID_2) +int cdiCopyAtts(int cdiID1, int varID1, int cdiID2, int varID2) { int status = CDI_NOERR; - cdi_atts_t *attsp1 = cdi_get_attsp(cdiID1, varID_1); + cdi_atts_t *attsp1 = cdi_get_attsp(cdiID1, varID1); xassert(attsp1 != NULL); for ( int attid = 0; attid < (int)attsp1->nelems; attid++ ) { cdi_att_t *attp = &(attsp1->value[attid]); - cdi_def_att(attp->indtype, attp->exdtype, cdiID2, varID_2, attp->name, attp->nelems, attp->xsz, attp->xvalue); + cdi_def_att(attp->indtype, attp->exdtype, cdiID2, varID2, attp->name, attp->nelems, attp->xsz, attp->xvalue); } return status; 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 8e02463b320f9c18729ef94fd0363230766a82a2..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; @@ -351,7 +353,6 @@ int streamInqFileID(int streamID); void gridDefHasDims(int gridID, int hasdims); int gridInqHasDims(int gridID); -const char *zaxisNamePtr(int leveltype); int zaxisInqLevelID(int zaxisID, double level); void streamCheckID(const char *caller, int streamID); 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..8eb7510800bc453b41e8ac6e16cad6b28f0fb97d 100644 --- a/src/stream_cdf_i.c +++ b/src/stream_cdf_i.c @@ -2894,17 +2894,18 @@ 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); } @@ -2917,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 9263609d1a3178f16586c93795d0032555b4698d..5173931cffeb78aa824ba9f9abdf5dd88601b4f5 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); @@ -1636,14 +1631,23 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI } else if ( gridtype == GRID_CURVILINEAR ) { - static bool lwarning = true; - if ( lwarning && gridInqSize(gridID) > 1 ) - { - lwarning = false; - Warning("Curvilinear grids are unsupported in GRIB1! Created wrong Grid Description Section!"); - } - gridtype = GRID_LONLAT; - lcurvi = true; + int projID = gridInqProj(gridID); + if ( projID != CDI_UNDEFID && gridInqType(projID) == GRID_PROJECTION ) + { + gridID = projID; + gridtype = GRID_PROJECTION; + } + else + { + static bool lwarning = true; + if ( lwarning && gridInqSize(gridID) > 1 ) + { + lwarning = false; + Warning("Curvilinear grid is unsupported in GRIB1! Created wrong Grid Description Section!"); + } + lcurvi = true; + gridtype = GRID_LONLAT; + } } if ( gridtype == GRID_PROJECTION && gridInqProjType(gridID) == CDI_PROJ_RLL ) diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c index 759b854522cb8764b21bcf6fea1f99d9a8b3afc7..79ed40b25cef35e94bd835372c9fbbaa75249c87 100644 --- a/src/stream_gribapi.c +++ b/src/stream_gribapi.c @@ -20,10 +20,10 @@ #include "subtype.h" -# include "cgribex.h" /* gribGetSize, gribRead, gribGetZip, GRIB1_LTYPE_99 */ -# include "gribapi.h" +#include "cgribex.h" /* gribGetSize, gribRead, gribGetZip, GRIB1_LTYPE_99 */ +#include "gribapi.h" -# include <grib_api.h> +#include <grib_api.h> extern int cdiInventoryMode; @@ -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; @@ -1918,14 +1908,23 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype } else if ( gridtype == GRID_CURVILINEAR ) { - static bool lwarning = true; - if ( lwarning && gridsize > 1 ) - { - lwarning = false; - Warning("Curvilinear grids are unsupported in GRIB format! Created wrong Grid Description Section!"); - } - gridtype = GRID_LONLAT; - lcurvi = true; + int projID = gridInqProj(gridID); + if ( projID != CDI_UNDEFID && gridInqType(projID) == GRID_PROJECTION ) + { + gridID = projID; + gridtype = GRID_PROJECTION; + } + else + { + static bool lwarning = true; + if ( lwarning && gridsize > 1 ) + { + lwarning = false; + Warning("Curvilinear grid is unsupported in GRIB format! Created wrong Grid Description Section!"); + } + lcurvi = true; + gridtype = GRID_LONLAT; + } } if ( gridtype == GRID_PROJECTION && gridInqProjType(gridID) == CDI_PROJ_RLL ) @@ -2259,7 +2258,7 @@ static void gribapiDefLevelType(grib_handle *gh, int gcinit, const char *keyname, long leveltype) { bool lset = false; - if ( (leveltype == 99 || leveltype == 100) && gribEditionNumber(gh) == 1 ) + if ( (leveltype == GRIB1_LTYPE_ISOBARIC_PA || leveltype == 99 || leveltype == 100) && gribEditionNumber(gh) == 1 ) { if ( gribGetLong(gh, "indicatorOfTypeOfLevel") != leveltype ) lset = true; } diff --git a/src/stream_record.c b/src/stream_record.c index ed0b588a1a376ba0138bcbb8ff13503720719320..c41d54ac9a08de6874e34b3a9909d40a957697ce 100644 --- a/src/stream_record.c +++ b/src/stream_record.c @@ -243,7 +243,7 @@ void streamCopyRecord(int streamID2, int streamID1) case CDI_FILETYPE_NC2: case CDI_FILETYPE_NC4: case CDI_FILETYPE_NC4C: - Warning("Streams have different file types (%s -> %s)!", strfiletype(filetype1), strfiletype(filetype2)); + // Warning("Streams have different file types (%s -> %s)!", strfiletype(filetype1), strfiletype(filetype2)); filetype = filetype2; break; } diff --git a/src/varscan.c b/src/varscan.c index 6b3d99a66e3358310fbfc8f2ade5ee06654f271b..810bc3d2be0b0903a1aec343c42cc2d006bbc939 100644 --- a/src/varscan.c +++ b/src/varscan.c @@ -45,6 +45,7 @@ typedef struct typedef struct { + int varID; int param; int prec; int tsteptype; @@ -95,6 +96,7 @@ static unsigned nvars = 0; static void paramInitEntry(unsigned varID, int param) { + vartable[varID].varID = varID; vartable[varID].param = param; vartable[varID].prec = 0; vartable[varID].tsteptype = TSTEP_INSTANT; @@ -534,20 +536,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) +int cmp_param(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 ); @@ -555,6 +553,28 @@ int cmpparam(const void* s1, const void* s2) return cmp; } +struct varinfo +{ + int varid; + const char *name; +}; +/* +static +int cmp_varname(const void *s1, const void *s2) +{ + const struct varinfo *x = (const struct varinfo *)s1, + *y = (const struct varinfo *)s2; + return strcmp(x->name, y->name); +} +*/ +static +int cmp_varname(const void *s1, const void *s2) +{ + const vartable_t *x = (const vartable_t *)s1, + *y = (const vartable_t *)s2; + return strcmp(x->name, y->name); +} + void cdi_generate_vars(stream_t *streamptr) { @@ -563,10 +583,10 @@ 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 +594,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), cmp_param); for ( unsigned varID = 0; varID < nvars; varID++ ) { varids[varID] = varInfo[varID].varid; @@ -582,6 +602,11 @@ void cdi_generate_vars(stream_t *streamptr) Free(varInfo); } + if ( streamptr->sortname ) + { + qsort(vartable, (size_t)nvars, sizeof(vartable_t), cmp_varname); + } + */ for ( unsigned index = 0; index < nvars; index++ ) { int varid = varids[index]; diff --git a/src/vlist.c b/src/vlist.c index eddd332cb3e08c85f470dea8fa38b68c2099bd7e..672108793e245f983d10fd15ac5455e25d5e4fb7 100644 --- a/src/vlist.c +++ b/src/vlist.c @@ -344,7 +344,7 @@ void vlistCopy(int vlistID2, int vlistID1) var_t *vars2 = vlistptr2->vars; vlist_copy(vlistptr2, vlistptr1); - cdiCopyVarAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL); + cdiCopyAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL); if ( vars1 ) { @@ -361,7 +361,7 @@ void vlistCopy(int vlistID2, int vlistID1) var_copy_entries(&vars2[varID], &vars1[varID]); vlistptr2->vars[varID].atts.nelems = 0; - cdiCopyVarAtts(vlistID1, varID, vlistID2, varID); + cdiCopyAtts(vlistID1, varID, vlistID2, varID); if ( vars1[varID].levinfo ) { @@ -526,7 +526,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1) vlist_copy(vlistptr2, vlistptr1); - cdiCopyVarAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL); + cdiCopyAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL); if ( vlistptr1->vars ) { @@ -567,7 +567,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1) var_copy_entries(&vars2[varID2], &vars1[varID]); vlistptr2->vars[varID2].atts.nelems = 0; - cdiCopyVarAtts(vlistID1, varID, vlistID2, varID2); + cdiCopyAtts(vlistID1, varID, vlistID2, varID2); int nlevs = zaxisInqSize(vars1[varID].zaxisID); int nlevs2 = 0; @@ -741,7 +741,7 @@ void vlistCat(int vlistID2, int vlistID1) } vars2[varID2].atts.nelems = 0; - cdiCopyVarAtts(vlistID1, varID, vlistID2, varID2); + cdiCopyAtts(vlistID1, varID, vlistID2, varID2); vlistAdd2GridIDs(vlistptr2, vars1[varID].gridID); vlistAdd2ZaxisIDs(vlistptr2, vars1[varID].zaxisID); diff --git a/src/vlist.h b/src/vlist.h index 60542387c827f2cd41c3368315ac90a60ff26855..0b633a7b1b8baac84da13544d9232bc4f229fcec 100644 --- a/src/vlist.h +++ b/src/vlist.h @@ -133,7 +133,6 @@ int vlistInqVarMissvalUsed(int vlistID, int varID); int vlistHasTime(int vlistID); int cdiDelAtts(int vlistID, int varID); -int cdiCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2); void vlistUnpack(char * buffer, int bufferSize, int * pos, int originNamespace, void *context, int force_id);