diff --git a/ChangeLog b/ChangeLog index dc90f14dc0928de9b6fa524179d596fa8ad3b523..a88a950948eb673d5398103f3dfc3d608fe99b31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2024-05-21 Uwe Schulzweida + + * Version 2.4.1 released + +2024-04-19 Uwe Schulzweida + + * cdfVerifyVars: disable check failed with cdo option --cmor + +2024-04-15 Uwe Schulzweida + + * gribapi: added support for sortname option + +2024-03-22 Uwe Schulzweida + + * gribapi_get_timeunits: check unitsOfTime (bug fix) [report: Chris Barnard] + +2024-03-20 Uwe Schulzweida + + * calc_chunk_cache_size: improved for 4D chunked data + +2024-03-11 Uwe Schulzweida + + * GRIB1: add check for full pressure levels + +2024-03-08 Uwe Schulzweida + + * Removed interface function vlistCopy(), use vlistDuplicate() + 2024-02-22 Uwe Schulzweida * Version 2.4.0 released diff --git a/NEWS b/NEWS index dffb7bc9ac9a876f2e0de483f963435f0dbee855..166765c7a4049a10dc29cc93c9e32fb52fb35e6c 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,14 @@ CDI NEWS -------- +Version 2.4.1 (21 May 2024): + + Changes: + * Removed interface function vlistCopy(), use vlistDuplicate() + * calc_chunk_cache_size: improved for 4D chunked data + Fixed bugs: + * gribapi_get_timeunits: check unitsOfTime (bug fix) [report: Chris Barnard] + Version 2.4.0 (22 February 2024): New features: diff --git a/app/printinfo.c b/app/printinfo.c index 51cbd1866408195b1c1fbeeef2587d2e9d604e19..b17bec1b6a2d20e98d099c9c3e6640425edc300c 100644 --- a/app/printinfo.c +++ b/app/printinfo.c @@ -416,7 +416,7 @@ printGridInfoKernel(int gridID, int index, bool lproj) void printGridInfo(int vlistID) { - int ngrids = vlistNgrids(vlistID); + int ngrids = vlistNumGrids(vlistID); for (int index = 0; index < ngrids; index++) { int gridID = vlistGrid(vlistID, index); @@ -526,7 +526,7 @@ printZaxisInfo(int vlistID) { char zaxisname[CDI_MAX_NAME], zname[CDI_MAX_NAME], zunits[CDI_MAX_NAME]; - int nzaxis = vlistNzaxis(vlistID); + int nzaxis = vlistNumZaxis(vlistID); for (int index = 0; index < nzaxis; index++) { int dig = 7; diff --git a/configure.ac b/configure.ac index 0723a979d5a61bec35377b01527438f7cca5c46e..eb38aa8e9c1b6ebb5c5f7b07b294dc100b48b429 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ AC_PREREQ([2.69]) LT_PREREQ([2.4.6]) -AC_INIT([cdi],[2.4.0],[https://mpimet.mpg.de/cdi]) +AC_INIT([cdi],[2.4.1],[https://mpimet.mpg.de/cdi]) AC_DEFINE_UNQUOTED(CDI, ["$PACKAGE_VERSION"], [CDI version]) AC_CONFIG_AUX_DIR([config]) diff --git a/doc/tex/FUNCTIONS b/doc/tex/FUNCTIONS index b2188d1bc9c0cb438e792f2ba7fe99789e9e06bb..849ccdf41bd5b2929b1f74d4ba6eef6cba5bb556 100644 --- a/doc/tex/FUNCTIONS +++ b/doc/tex/FUNCTIONS @@ -45,8 +45,8 @@ Function catalog: vlistCat Concatenate two variable lists vlistCopyFlag Copy some entries of a variable list vlistNvars Number of variables in a variable list - vlistNgrids Number of grids in a variable list - vlistNzaxis Number of zaxis in a variable list + vlistNumGrids Number of grids in a variable list + vlistNumZaxis Number of zaxis in a variable list vlistDefTaxis Define the time axis vlistInqTaxis Get the time axis ------------------------------------------------------------- diff --git a/doc/tex/Modules b/doc/tex/Modules index 9bfb430113f7d9b3a495ad9b2ce81a760e11124c..9eb53108f8f7292f3c93907a13ab2c3bd1f54a4d 100644 --- a/doc/tex/Modules +++ b/doc/tex/Modules @@ -28,8 +28,8 @@ vlistDuplicate vlist vlistCat vlist vlistCopyFlag vlist vlistNvars vlist -vlistNgrids vlist -vlistNzaxis vlist +vlistNumGrids vlist +vlistNumZaxis vlist vlistDefTaxis vlist vlistInqTaxis vlist vlistDefVar vlist_var diff --git a/doc/tex/c_ref.tex b/doc/tex/c_ref.tex index 9e00ec8e279e5a9b1286fa5733f8385302f700f2..67356dcc756dc5d3818645e545a6264cb1a41682 100644 --- a/doc/tex/c_ref.tex +++ b/doc/tex/c_ref.tex @@ -1271,47 +1271,47 @@ Get the Zaxis ID of a Variable \section*{\texttt{ \ifpdf -\hyperref[vlistNgrids]{vlistNgrids} +\hyperref[vlistNumGrids]{vlistNumGrids} \else -vlistNgrids +vlistNumGrids \fi }} \begin{verbatim} - int vlistNgrids(int vlistID); + int vlistNumGrids(int vlistID); \end{verbatim} Number of grids in a variable list -\ifpdfoutput{}{(\ref{vlistNgrids})} +\ifpdfoutput{}{(\ref{vlistNumGrids})} \section*{\texttt{ \ifpdf -\hyperref[vlistNvars]{vlistNvars} +\hyperref[vlistNumZaxis]{vlistNumZaxis} \else -vlistNvars +vlistNumZaxis \fi }} \begin{verbatim} - int vlistNvars(int vlistID); + int vlistNumZaxis(int vlistID); \end{verbatim} -Number of variables in a variable list -\ifpdfoutput{}{(\ref{vlistNvars})} +Number of zaxis in a variable list +\ifpdfoutput{}{(\ref{vlistNumZaxis})} \section*{\texttt{ \ifpdf -\hyperref[vlistNzaxis]{vlistNzaxis} +\hyperref[vlistNvars]{vlistNvars} \else -vlistNzaxis +vlistNvars \fi }} \begin{verbatim} - int vlistNzaxis(int vlistID); + int vlistNvars(int vlistID); \end{verbatim} -Number of zaxis in a variable list -\ifpdfoutput{}{(\ref{vlistNzaxis})} +Number of variables in a variable list +\ifpdfoutput{}{(\ref{vlistNvars})} \section*{\texttt{ diff --git a/doc/tex/c_vlist.tex b/doc/tex/c_vlist.tex index 8a2382a9324d3f924140abae5f1b9c22309ccbf3..34cac79de65461b8467ddd5c3f2e8da6c7240002 100644 --- a/doc/tex/c_vlist.tex +++ b/doc/tex/c_vlist.tex @@ -61,11 +61,11 @@ The function {\texttt{vlistCopy}} copies all entries from vlistID1 to vlistID2. \end{verbatim} \hspace*{4mm}\begin{minipage}[]{15cm} -\begin{deflist}{\texttt{vlistID2}\ } -\item[\texttt{vlistID2}] -Target variable list ID. +\begin{deflist}{\texttt{vlistID1}\ } \item[\texttt{vlistID1}] Source variable list ID. +\item[\texttt{vlistID2}] +Target variable list ID. \end{deflist} \end{minipage} @@ -169,16 +169,16 @@ Variable list ID, from a previous call to {\htmlref{\texttt{vlistCreate}}{vlistC -\subsection{Number of grids in a variable list: \texttt{vlistNgrids}} -\index{vlistNgrids} -\label{vlistNgrids} +\subsection{Number of grids in a variable list: \texttt{vlistNumGrids}} +\index{vlistNumGrids} +\label{vlistNumGrids} -The function {\texttt{vlistNgrids}} returns the number of grids in the variable list vlistID. +The function {\texttt{vlistNumGrids}} returns the number of grids in the variable list vlistID. \subsubsection*{Usage} \begin{verbatim} - int vlistNgrids(int vlistID); + int vlistNumGrids(int vlistID); \end{verbatim} \hspace*{4mm}\begin{minipage}[]{15cm} @@ -191,20 +191,20 @@ Variable list ID, from a previous call to {\htmlref{\texttt{vlistCreate}}{vlistC \subsubsection*{Result} -{\texttt{vlistNgrids}} returns the number of grids in a variable list. +{\texttt{vlistNumGrids}} returns the number of grids in a variable list. -\subsection{Number of zaxis in a variable list: \texttt{vlistNzaxis}} -\index{vlistNzaxis} -\label{vlistNzaxis} +\subsection{Number of zaxis in a variable list: \texttt{vlistNumZaxis}} +\index{vlistNumZaxis} +\label{vlistNumZaxis} -The function {\texttt{vlistNzaxis}} returns the number of zaxis in the variable list vlistID. +The function {\texttt{vlistNumZaxis}} returns the number of zaxis in the variable list vlistID. \subsubsection*{Usage} \begin{verbatim} - int vlistNzaxis(int vlistID); + int vlistNumZaxis(int vlistID); \end{verbatim} \hspace*{4mm}\begin{minipage}[]{15cm} @@ -217,7 +217,7 @@ Variable list ID, from a previous call to {\htmlref{\texttt{vlistCreate}}{vlistC \subsubsection*{Result} -{\texttt{vlistNzaxis}} returns the number of zaxis in a variable list. +{\texttt{vlistNumZaxis}} returns the number of zaxis in a variable list. diff --git a/doc/tex/f_ref.tex b/doc/tex/f_ref.tex index 6c5302257bbd415e34b02aa52c508630c2a0d993..b2679b51c9419c704f74cf05bd33685af07ae618 100644 --- a/doc/tex/f_ref.tex +++ b/doc/tex/f_ref.tex @@ -1286,47 +1286,47 @@ Get the Zaxis ID of a Variable \section*{\texttt{ \ifpdf -\hyperref[vlistNgrids]{vlistNgrids} +\hyperref[vlistNumGrids]{vlistNumGrids} \else -vlistNgrids +vlistNumGrids \fi }} \begin{verbatim} - INTEGER FUNCTION vlistNgrids(INTEGER vlistID) + INTEGER FUNCTION vlistNumGrids(INTEGER vlistID) \end{verbatim} Number of grids in a variable list -\ifpdfoutput{}{(\ref{vlistNgrids})} +\ifpdfoutput{}{(\ref{vlistNumGrids})} \section*{\texttt{ \ifpdf -\hyperref[vlistNvars]{vlistNvars} +\hyperref[vlistNumZaxis]{vlistNumZaxis} \else -vlistNvars +vlistNumZaxis \fi }} \begin{verbatim} - INTEGER FUNCTION vlistNvars(INTEGER vlistID) + INTEGER FUNCTION vlistNumZaxis(INTEGER vlistID) \end{verbatim} -Number of variables in a variable list -\ifpdfoutput{}{(\ref{vlistNvars})} +Number of zaxis in a variable list +\ifpdfoutput{}{(\ref{vlistNumZaxis})} \section*{\texttt{ \ifpdf -\hyperref[vlistNzaxis]{vlistNzaxis} +\hyperref[vlistNvars]{vlistNvars} \else -vlistNzaxis +vlistNvars \fi }} \begin{verbatim} - INTEGER FUNCTION vlistNzaxis(INTEGER vlistID) + INTEGER FUNCTION vlistNvars(INTEGER vlistID) \end{verbatim} -Number of zaxis in a variable list -\ifpdfoutput{}{(\ref{vlistNzaxis})} +Number of variables in a variable list +\ifpdfoutput{}{(\ref{vlistNvars})} \section*{\texttt{ diff --git a/doc/tex/f_vlist.tex b/doc/tex/f_vlist.tex index 675b28c41310012b4c67438821d2f3fd0acbbf86..592d2b2ac273bb98fc1cb83b8384339a974f918a 100644 --- a/doc/tex/f_vlist.tex +++ b/doc/tex/f_vlist.tex @@ -61,11 +61,11 @@ The function {\texttt{vlistCopy}} copies all entries from vlistID1 to vlistID2. \end{verbatim} \hspace*{4mm}\begin{minipage}[]{15cm} -\begin{deflist}{\texttt{vlistID2}\ } -\item[\texttt{vlistID2}] -Target variable list ID. +\begin{deflist}{\texttt{vlistID1}\ } \item[\texttt{vlistID1}] Source variable list ID. +\item[\texttt{vlistID2}] +Target variable list ID. \end{deflist} \end{minipage} @@ -169,16 +169,16 @@ Variable list ID, from a previous call to {\htmlref{\texttt{vlistCreate}}{vlistC -\subsection{Number of grids in a variable list: \texttt{vlistNgrids}} -\index{vlistNgrids} -\label{vlistNgrids} +\subsection{Number of grids in a variable list: \texttt{vlistNumGrids}} +\index{vlistNumGrids} +\label{vlistNumGrids} -The function {\texttt{vlistNgrids}} returns the number of grids in the variable list vlistID. +The function {\texttt{vlistNumGrids}} returns the number of grids in the variable list vlistID. \subsubsection*{Usage} \begin{verbatim} - INTEGER FUNCTION vlistNgrids(INTEGER vlistID) + INTEGER FUNCTION vlistNumGrids(INTEGER vlistID) \end{verbatim} \hspace*{4mm}\begin{minipage}[]{15cm} @@ -191,20 +191,20 @@ Variable list ID, from a previous call to {\htmlref{\texttt{vlistCreate}}{vlistC \subsubsection*{Result} -{\texttt{vlistNgrids}} returns the number of grids in a variable list. +{\texttt{vlistNumGrids}} returns the number of grids in a variable list. -\subsection{Number of zaxis in a variable list: \texttt{vlistNzaxis}} -\index{vlistNzaxis} -\label{vlistNzaxis} +\subsection{Number of zaxis in a variable list: \texttt{vlistNumZaxis}} +\index{vlistNumZaxis} +\label{vlistNumZaxis} -The function {\texttt{vlistNzaxis}} returns the number of zaxis in the variable list vlistID. +The function {\texttt{vlistNumZaxis}} returns the number of zaxis in the variable list vlistID. \subsubsection*{Usage} \begin{verbatim} - INTEGER FUNCTION vlistNzaxis(INTEGER vlistID) + INTEGER FUNCTION vlistNumZaxis(INTEGER vlistID) \end{verbatim} \hspace*{4mm}\begin{minipage}[]{15cm} @@ -217,7 +217,7 @@ Variable list ID, from a previous call to {\htmlref{\texttt{vlistCreate}}{vlistC \subsubsection*{Result} -{\texttt{vlistNzaxis}} returns the number of zaxis in a variable list. +{\texttt{vlistNumZaxis}} returns the number of zaxis in a variable list. diff --git a/interfaces/cdi.cpp b/interfaces/cdi.cpp index 6a842450dd7c21f763b54af8160690a399345aa6..c57100da4e43dbee5cca9357a80d8f18fc3d8f3a 100644 --- a/interfaces/cdi.cpp +++ b/interfaces/cdi.cpp @@ -401,7 +401,7 @@ void Cdi::getZaxes() { int zaxisID; - nzaxes = vlistNzaxis(vlistID); + nzaxes = vlistNumZaxis(vlistID); for (int i = 0; i < nzaxes; i++) { zaxisID = vlistZaxis(vlistID, i); @@ -414,7 +414,7 @@ void Cdi::getGrids() { int gridID; - ngrids = vlistNgrids(vlistID); + ngrids = vlistNumGrids(vlistID); std::cout << "ngrids=" << ngrids << std::endl; for (int i = 0; i < ngrids; i++) { diff --git a/m4/acx_options.m4 b/m4/acx_options.m4 index d35722fc3785f32c74abf6f44c52e255ff85c113..a869f477ebb12f6d27c7cbec99e8d5eeaaa1aa61 100644 --- a/m4/acx_options.m4 +++ b/m4/acx_options.m4 @@ -253,43 +253,7 @@ AC_ARG_WITH([eccodes], AC_MSG_RESULT([suppressed])]) AC_SUBST([ECCODES_INCLUDE]) AC_SUBST([ECCODES_LIBS]) -# AM_CONDITIONAL([HAVE_LIBGRIB_API],[test "x$with_eccodes" != 'x' -a "x$with_eccodes" != 'xno' ]) -# ---------------------------------------------------------------------- -# Compile application with GRIB_API library (for GRIB2 support) -GRIB_API_INCLUDE='' -GRIB_API_LIBS='' -AC_ARG_WITH([grib_api], - [AS_HELP_STRING([--with-grib_api=<yes|no|directory>], - [location of GRIB_API library for grib2 encoding/decoding (lib and include subdirs)])], - [AS_CASE(["$with_grib_api"], - [no],[AC_MSG_CHECKING([for GRIB_API library]) - AC_MSG_RESULT([suppressed])], - [yes],[AC_CHECK_HEADERS([grib_api.h],, - [AC_MSG_ERROR([Could not find grib_api.h])], - [AC_INCLUDES_DEFAULT]) - AC_SEARCH_LIBS([grib_get_message], - [grib_api], - [AC_DEFINE([HAVE_LIBGRIB_API],[1],[GRIB_API library is present if defined to 1])], - [AC_MSG_ERROR([Could not link to grib_api library])])], - [*],[GRIB_API_ROOT=$with_grib_api - AS_IF([test -d "$GRIB_API_ROOT"], - [LDFLAGS="-L$GRIB_API_ROOT/lib $LDFLAGS" - CPPFLAGS="-I$GRIB_API_ROOT/include $CPPFLAGS" - AC_CHECK_HEADERS([grib_api.h],, - [AC_MSG_ERROR([Could not find grib_api.h])], - [AC_INCLUDES_DEFAULT]) - AC_SEARCH_LIBS([grib_get_message], - [grib_api], - [AC_DEFINE([HAVE_LIBGRIB_API],[1],[GRIB_API library is present if defined to 1])], - [AC_MSG_ERROR([Could not link to grib_api library])]) - GRIB_API_LIBS=" -L$GRIB_API_ROOT/lib -lgrib_api" - GRIB_API_INCLUDE=" -I$GRIB_API_ROOT/include"], - [AC_MSG_ERROR([$GRIB_API_ROOT is not a directory! GRIB_API suppressed])])])], - [AC_MSG_CHECKING([for the GRIB_API library]) - AC_MSG_RESULT([suppressed])]) -AC_SUBST([GRIB_API_INCLUDE]) -AC_SUBST([GRIB_API_LIBS]) -AM_CONDITIONAL([HAVE_LIBGRIB_API],[test \( "x$with_grib_api" != 'x' -a "x$with_grib_api" != 'xno' \) -o \( "x$with_eccodes" != 'x' -a "x$with_eccodes" != 'xno' \) ]) +AM_CONDITIONAL([HAVE_LIBGRIB_API],[test "x$with_eccodes" != 'x' -a "x$with_eccodes" != 'xno' ]) # ---------------------------------------------------------------------- # Enable GRIB support AC_MSG_CHECKING([for GRIB support]) diff --git a/src/cdf_records.c b/src/cdf_records.c index 6b873fbdea426f1adcec21d98f856cfef68d47ff..050c837abff7bc9fc290c7680b6c64549d18ce0a 100644 --- a/src/cdf_records.c +++ b/src/cdf_records.c @@ -70,7 +70,7 @@ cdf_create_records(stream_t *streamptr, int tsID) tsteps_t *sourceTstep = streamptr->tsteps; tsteps_t *destTstep = sourceTstep + tsID; - int numRecs = vlistNrecs(vlistID); + int numRecs = vlistNumRecords(vlistID); if (numRecs <= 0) return; if (tsID == 0) diff --git a/src/cdf_write.c b/src/cdf_write.c index 89f459aade4aaf937777e5ee50d061685d0a1404..e37d1cc448a9fd87874c7ebd5be11e549264d4db 100644 --- a/src/cdf_write.c +++ b/src/cdf_write.c @@ -432,7 +432,7 @@ nc_grid_index(stream_t *streamptr, int gridID) { int index = 0; int vlistID = streamptr->vlistID; - int ngrids = vlistNgrids(vlistID); + int ngrids = vlistNumGrids(vlistID); for (index = 0; index < ngrids; ++index) if (streamptr->ncgrid[index].gridID == gridID) break; @@ -981,7 +981,7 @@ cdfDefVar(stream_t *streamptr, int varID) cdfGenVarname(fileID, name, pnum, pcat, &pdis, &code); int dtype = vlistInqVarDatatype(vlistID, varID); - const nc_type xtype = cdfDefDatatype(dtype, streamptr); + nc_type xtype = cdfDefDatatype(dtype, streamptr); if (streamptr->ncmode == 2) { @@ -1364,7 +1364,7 @@ cdfDefineStartAndCount(stream_t *streamptr, int varID, int xid, int yid, int zid int vlistID = streamptr->vlistID; int fileID = streamptr->fileID; - const long ntsteps = streamptr->ntsteps; + long ntsteps = streamptr->ntsteps; if (CDI_Debug) Message("ntsteps = %ld", ntsteps); int timetype = vlistInqVarTimetype(vlistID, varID); @@ -1457,7 +1457,7 @@ cdfDefineStartAndCountChunk(stream_t *streamptr, const int rect[][2], int varID, int vlistID = streamptr->vlistID; int fileID = streamptr->fileID; - const long ntsteps = streamptr->ntsteps; + long ntsteps = streamptr->ntsteps; if (CDI_Debug) Message("ntsteps = %ld", ntsteps); int timetype = vlistInqVarTimetype(vlistID, varID); @@ -1554,7 +1554,7 @@ cdfDefineStartAndCountSlice(stream_t *streamptr, int varID, int levelID, int dim int vlistID = streamptr->vlistID; int fileID = streamptr->fileID; - const long ntsteps = streamptr->ntsteps; + long ntsteps = streamptr->ntsteps; if (CDI_Debug) Message("ntsteps = %ld", ntsteps); int timetype = vlistInqVarTimetype(vlistID, varID); diff --git a/src/cdi.h b/src/cdi.h index 9e4e48c311de2192b3875cd2ff00be71f36783bf..f72751b12bb0b6eff42d69120826f45fabdb698d 100644 --- a/src/cdi.h +++ b/src/cdi.h @@ -526,9 +526,6 @@ void vlistDestroy(int vlistID); // vlistDuplicate: Duplicate a variable list int vlistDuplicate(int vlistID); -// vlistCopy: Copy a variable list -void vlistCopy(int vlistID2, int vlistID1); - // vlistCopyFlag: Copy some entries of a variable list void vlistCopyFlag(int vlistID2, int vlistID1); @@ -548,11 +545,11 @@ int vlistNumber(int vlistID); // vlistNvars: Number of variables in a variable list int vlistNvars(int vlistID); -// vlistNgrids: Number of grids in a variable list -int vlistNgrids(int vlistID); +// vlistNumGrids: Number of grids in a variable list +int vlistNumGrids(int vlistID); -// vlistNzaxis: Number of zaxis in a variable list -int vlistNzaxis(int vlistID); +// vlistNumZaxis: Number of zaxis in a variable list +int vlistNumZaxis(int vlistID); // vlistNsubtypes: Number of subtypes in a variable list int vlistNsubtypes(int vlistID); @@ -568,7 +565,7 @@ int vlistZaxis(int vlistID, int index); int vlistZaxisIndex(int vlistID, int zaxisID); void vlistChangeZaxisIndex(int vlistID, int index, int zaxisID); void vlistChangeZaxis(int vlistID, int zaxisID1, int zaxisID2); -int vlistNrecs(int vlistID); +int vlistNumRecords(int vlistID); int vlistSubtype(int vlistID, int index); int vlistSubtypeIndex(int vlistID, int subtypeID); diff --git a/src/cdi_att.c b/src/cdi_att.c index b6bbe6e5d2066393acb19bb2b46ecb7cdbe4d830..69e6b8f55b4e09a6b4774dca9d7571442b7f9df7 100644 --- a/src/cdi_att.c +++ b/src/cdi_att.c @@ -1,4 +1,3 @@ -#include <assert.h> #include <limits.h> #include <stdio.h> #include <string.h> diff --git a/src/cdi_att.h b/src/cdi_att.h index 7ceee76c547490567059ca1c78b2d61a76436a4f..2c337b6b6a0ae78e9bbc4371deae200be5e51fc1 100644 --- a/src/cdi_att.h +++ b/src/cdi_att.h @@ -9,6 +9,8 @@ #include "cdi_limits.h" #endif +#include <stdio.h> + // CDI attribute // clang-format off typedef struct diff --git a/src/cdi_fdb.c b/src/cdi_fdb.c index 49a902263ac5912a42a189a1fd94c6b76f9f82f2..36d448c353c64a4c8c56068436f27c321c2009a8 100644 --- a/src/cdi_fdb.c +++ b/src/cdi_fdb.c @@ -4,11 +4,11 @@ int cdi_fdb_dummy; #ifdef HAVE_LIBFDB5 -#include <string.h> #include <stdlib.h> +#include <string.h> -#include "error.h" #include "cdi_int.h" +#include "error.h" void ensureBufferSize(size_t requiredSize, size_t *curSize, void **buffer); @@ -413,15 +413,15 @@ decode_keyvalue(int numItems, fdbKeyValueEntry *keyValueList, RecordInfoEntry *r bool foundParam = false; bool foundLtype = false; bool foundLlist = false; - for (int i = 0; i < keyValue->numKeys; i++) + for (int k = 0; k < keyValue->numKeys; k++) { - // printf("key <%s> value <%s>\n", itemKeys[i], itemValues[i]); + // printf("key <%s> value <%s>\n", keys[k], values[k]); // clang-format off - if (!foundDate && str_is_equal(keys[i], "date")) { foundDate = true; numKeyDate++; rentry->date = atoi(values[i]); } - else if (!foundTime && str_is_equal(keys[i], "time")) { foundTime = true; numKeyTime++; rentry->time = atoi(values[i]); } - else if (!foundParam && str_is_equal(keys[i], "param")) { foundParam = true; numKeyParam++; rentry->param = atoi(values[i]); } - else if (!foundLtype && str_is_equal(keys[i], "levtype")) { foundLtype = true; numKeyLtype++; rentry->levtype = get_ilevtype(values[i]); } - else if (!foundLlist && str_is_equal(keys[i], "levelist")) { foundLlist = true; rentry->ilevel = atoi(values[i]); } + if (!foundDate && str_is_equal(keys[k], "date")) { foundDate = true; numKeyDate++; rentry->date = atoi(values[k]); } + else if (!foundTime && str_is_equal(keys[k], "time")) { foundTime = true; numKeyTime++; rentry->time = atoi(values[k]); } + else if (!foundParam && str_is_equal(keys[k], "param")) { foundParam = true; numKeyParam++; rentry->param = atoi(values[k]); } + else if (!foundLtype && str_is_equal(keys[k], "levtype")) { foundLtype = true; numKeyLtype++; rentry->levtype = get_ilevtype(values[k]); } + else if (!foundLlist && str_is_equal(keys[k], "levelist")) { foundLlist = true; rentry->ilevel = atoi(values[k]); } // clang-format on if (foundDate && foundTime && foundParam && foundLtype && foundLlist) break; } diff --git a/src/cdi_int.h b/src/cdi_int.h index c44667b7957901f48645fc4b96909659a5c493ca..2d0e9422a2463dc2dfa2eb790675b34a01d41d0b 100644 --- a/src/cdi_int.h +++ b/src/cdi_int.h @@ -110,7 +110,7 @@ str_is_equal(const char *x, const char *y) #endif #ifndef DBL_IS_EQUAL -//#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) +// #define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) #define DBL_IS_EQUAL(x, y) (DBL_IS_NAN(x) || DBL_IS_NAN(y) ? (DBL_IS_NAN(x) && DBL_IS_NAN(y)) : !(x < y || y < x)) #endif diff --git a/src/cdi_key.h b/src/cdi_key.h index 7064d90b1b67caff72ab04f8b439841db80bc598..71755838c36dd14983b189ceeada51516a09a59c 100644 --- a/src/cdi_key.h +++ b/src/cdi_key.h @@ -1,6 +1,7 @@ #ifndef CDI_KEY_H #define CDI_KEY_H +#include <stdio.h> #include "cdi_limits.h" // CDI key diff --git a/src/institution.c b/src/institution.c index b93bd7580d90f57bcad1b959748d97384b47637f..1d7ed15a998501dea2c2bb1c47f60d4f6a9cf8d2 100644 --- a/src/institution.c +++ b/src/institution.c @@ -1,7 +1,7 @@ #include <assert.h> +#include <stdlib.h> #include <limits.h> -#include "dmemory.h" #include "cdi.h" #include "cdi_int.h" #include "resource_handle.h" @@ -147,7 +147,7 @@ institutInq(int center, int subcenter, const char *name, const char *longname) static institute_t * instituteNewEntry(cdiResH resH, int center, int subcenter, const char *name, const char *longname) { - institute_t *instituteptr = (institute_t *) Malloc(sizeof(institute_t)); + institute_t *instituteptr = (institute_t *) malloc(sizeof(institute_t)); instituteDefaultValue(instituteptr); if (resH == CDI_UNDEFID) instituteptr->self = reshPut(instituteptr, &instituteOps); @@ -205,9 +205,9 @@ static void instituteDestroyP(institute_t *instituteptr) { xassert(instituteptr); - Free(instituteptr->name); - Free(instituteptr->longname); - Free(instituteptr); + free(instituteptr->name); + free(instituteptr->longname); + free(instituteptr); } static void @@ -277,7 +277,7 @@ instituteUnpack(void *buf, int size, int *position, int originNamespace, void *c int tempbuf[institute_nints]; int instituteID; serializeUnpack(buf, size, position, tempbuf, institute_nints, CDI_DATATYPE_INT, context); - char *name = (char *) Malloc((size_t) tempbuf[INSTITUTE_PACK_INT_NAMELEN] + (size_t) tempbuf[INSTITUTE_PACK_INT_LNAMELEN]), + char *name = (char *) malloc((size_t) tempbuf[INSTITUTE_PACK_INT_NAMELEN] + (size_t) tempbuf[INSTITUTE_PACK_INT_LNAMELEN]), *longname = name + tempbuf[INSTITUTE_PACK_INT_NAMELEN]; serializeUnpack(buf, size, position, name, tempbuf[INSTITUTE_PACK_INT_NAMELEN], CDI_DATATYPE_TXT, context); serializeUnpack(buf, size, position, longname, tempbuf[INSTITUTE_PACK_INT_LNAMELEN], CDI_DATATYPE_TXT, context); @@ -286,7 +286,7 @@ instituteUnpack(void *buf, int size, int *position, int originNamespace, void *c = instituteNewEntry(targetID, tempbuf[INSTITUTE_PACK_INT_CENTER], tempbuf[INSTITUTE_PACK_INT_SUBCENTER], name, longname); instituteID = ip->self; xassert(!force_id || instituteID == targetID); - Free(name); + free(name); reshSetStatus(instituteID, &instituteOps, reshGetStatus(instituteID, &instituteOps) & ~RESH_SYNC_BIT); #undef adaptKey return instituteID; diff --git a/src/model.c b/src/model.c index ef3ad02235d378a760bbda88f4262249f26e4ae0..bf28ce120f54269d8c5952d981413dd3bb19a31b 100644 --- a/src/model.c +++ b/src/model.c @@ -1,6 +1,6 @@ +#include <stdlib.h> #include <limits.h> -#include "dmemory.h" #include "cdi.h" #include "cdi_int.h" #include "model.h" @@ -43,7 +43,7 @@ modelDefaultValue(model_t *modelptr) static model_t * modelNewEntry(cdiResH resH, int instID, int modelgribID, const char *name) { - model_t *modelptr = (model_t *) Malloc(sizeof(model_t)); + model_t *modelptr = (model_t *) malloc(sizeof(model_t)); modelDefaultValue(modelptr); if (resH == CDI_UNDEFID) modelptr->self = reshPut(modelptr, &modelOps); @@ -220,8 +220,8 @@ void modelDestroyP(void *modelptr) { model_t *mp = (model_t *) modelptr; - if (mp->name) Free(mp->name); - Free(mp); + if (mp->name) free(mp->name); + free(mp); } void @@ -288,7 +288,7 @@ modelUnpack(void *buf, int size, int *position, int originNamespace, void *conte if (tempbuf[MODEL_PACK_INT_NAMELEN] != 0) { size_t len = (size_t) tempbuf[MODEL_PACK_INT_NAMELEN]; - name = (char *) Malloc(len + 1); + name = (char *) malloc(len + 1); serializeUnpack(buf, size, position, name, tempbuf[MODEL_PACK_INT_NAMELEN], CDI_DATATYPE_TXT, context); name[len] = '\0'; } @@ -299,7 +299,7 @@ modelUnpack(void *buf, int size, int *position, int originNamespace, void *conte int targetID = adaptKey(tempbuf[MODEL_PACK_INT_SELF]); model_t *mp = modelNewEntry(force_id ? targetID : CDI_UNDEFID, adaptKey(tempbuf[MODEL_PACK_INT_INSTID]), tempbuf[MODEL_PACK_INT_MODELGRIBID], name); - if (tempbuf[MODEL_PACK_INT_NAMELEN] != 0) Free(name); + if (tempbuf[MODEL_PACK_INT_NAMELEN] != 0) free(name); xassert(!force_id || (mp->self == adaptKey(tempbuf[0]))); reshSetStatus(mp->self, &modelOps, reshGetStatus(mp->self, &modelOps) & ~RESH_SYNC_BIT); #undef adaptKey diff --git a/src/pio_server.c b/src/pio_server.c index b013c79fb84cb9f3c1845331e33b9131ba8fbe21..91167f68ad131407059b6759f805ac3d8424360b 100644 --- a/src/pio_server.c +++ b/src/pio_server.c @@ -1901,7 +1901,7 @@ cdiPioCdfGridAccess(int streamID, int vlistID) if (cdiPioStream2Owner(streamID) != CDI_PIO_COLLECTIVE_OPEN) #endif { - int nGrids = vlistNgrids(vlistID); + int nGrids = vlistNumGrids(vlistID); for (int gridIdx = 0; gridIdx < nGrids; ++gridIdx) { int gridID = vlistGrid(vlistID, gridIdx); diff --git a/src/resource_handle.c b/src/resource_handle.c index ac790c427ae2f6407eb29d4496d4c79fed00ff06..c06d137ffd7b14251990bdd36abbc3b671182426 100644 --- a/src/resource_handle.c +++ b/src/resource_handle.c @@ -31,7 +31,6 @@ show_stackframe(void) #endif } -#include "dmemory.h" #include "resource_handle.h" #include "namespace.h" #include "serialize.h" @@ -196,7 +195,7 @@ listInitResources(int nsp) xassert(nsp < resHListSize && nsp >= 0); int size = resHList[nsp].size = MIN_LIST_SIZE; xassert(resHList[nsp].resources == NULL); - resHList[nsp].resources = (listElem_t *) Calloc(MIN_LIST_SIZE, sizeof(listElem_t)); + resHList[nsp].resources = (listElem_t *) calloc(MIN_LIST_SIZE, sizeof(listElem_t)); listElem_t *p = resHList[nsp].resources; for (int i = 0; i < size; i++) @@ -232,7 +231,7 @@ reshListCreate(int namespaceID) LIST_LOCK(); if (resHListSize <= namespaceID) { - resHList = (struct resHList_t *) Realloc(resHList, (size_t) (namespaceID + 1) * sizeof(resHList[0])); + resHList = (struct resHList_t *) realloc(resHList, (size_t) (namespaceID + 1) * sizeof(resHList[0])); for (int i = resHListSize; i <= namespaceID; ++i) reshListClearEntry(i); resHListSize = namespaceID + 1; } @@ -261,7 +260,7 @@ reshListDestruct(int namespaceID) reshRemove_(namespaceID, j, __func__); } } - Free(resHList[namespaceID].resources); + free(resHList[namespaceID].resources); resHList[namespaceID].resources = NULL; reshListClearEntry(namespaceID); } @@ -276,7 +275,7 @@ listDestroy(void) for (int i = resHListSize; i > 0; --i) if (resHList[i - 1].resources) namespaceDelete(i - 1); resHListSize = 0; - Free(resHList); + free(resHList); resHList = NULL; cdiReset(); LIST_UNLOCK(); @@ -315,7 +314,7 @@ listSizeExtend(void) int oldSize = resHList[nsp].size; size_t newListSize = (size_t) oldSize + MIN_LIST_SIZE; - resHList[nsp].resources = (listElem_t *) Realloc(resHList[nsp].resources, newListSize * sizeof(listElem_t)); + resHList[nsp].resources = (listElem_t *) realloc(resHList[nsp].resources, newListSize * sizeof(listElem_t)); listElem_t *r = resHList[nsp].resources; for (size_t i = (size_t) oldSize; i < newListSize; ++i) @@ -710,7 +709,7 @@ reshPackBufferCreate(char **packBuffer, int *packBufferSize, void *context) int nsp = namespaceGetActive(); int pBSize = *packBufferSize = getPackBufferSize(context); - char *pB = *packBuffer = (char *) Malloc((size_t) pBSize); + char *pB = *packBuffer = (char *) malloc((size_t) pBSize); { int header[resHPackHeaderNInt] = { START, nsp }; diff --git a/src/stream_cdf_i.c b/src/stream_cdf_i.c index e75a983c631c1b89c54a19069eeb77b67c18f0fd..6a84e170b9c611ee9d1466f31f7e394fab982f7b 100644 --- a/src/stream_cdf_i.c +++ b/src/stream_cdf_i.c @@ -110,6 +110,8 @@ typedef struct size_t chunkCacheNelems; float chunkCachePreemption; size_t gridSize; + size_t xSize; + size_t ySize; size_t numLevels; int natts; int *atts; @@ -644,6 +646,8 @@ init_ncvars(int nvars, ncvar_t *ncvars, int ncid) ncvar->chunkCacheNelems = 0; ncvar->chunkCachePreemption = 0.0; ncvar->gridSize = 0; + ncvar->xSize = 0; + ncvar->ySize = 0; ncvar->numLevels = 0; ncvar->natts = 0; ncvar->atts = NULL; @@ -1362,7 +1366,14 @@ cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int timed cdf_set_var(ncvar, CoordVar); } else - Warning("%s - %s", nc_strerror(status), attstring); + { + static bool printWarning = true; + if (printWarning) + { + printWarning = false; + Warning("%s - %s", nc_strerror(status), attstring); + } + } } else if (isText && str_is_equal(attname, "formula_terms")) { @@ -1898,11 +1909,13 @@ verify_coordinates_vars_1(int ncid, int ndims, ncdim_t *ncdims, ncvar_t *ncvars, else if (str_is_equal(ncvar->units, "level") || str_is_equal(ncvar->units, "1")) { // clang-format off - if (str_is_equal(ncvar->longname, "hybrid level at layer midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; - else if (strStartsWith(ncvar->longname, "hybrid level at midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; - else if (str_is_equal(ncvar->longname, "hybrid level at layer interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; - else if (strStartsWith(ncvar->longname, "hybrid level at interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; - else if (str_is_equal(ncvar->units, "level")) ncvar->zaxistype = ZAXIS_GENERIC; + if (str_is_equal(ncvar->longname, "hybrid level at layer midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; + else if (str_is_equal(ncvar->longname, "hybrid model level at layer midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; + else if (strStartsWith(ncvar->longname, "hybrid level at midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; + else if (str_is_equal(ncvar->longname, "hybrid level at layer interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; + else if (str_is_equal(ncvar->longname, "hybrid model level at layer interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; + else if (strStartsWith(ncvar->longname, "hybrid level at interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; + else if (str_is_equal(ncvar->units, "level")) ncvar->zaxistype = ZAXIS_GENERIC; // clang-format on } else if (is_DBL_axis(ncvar->longname)) @@ -1985,11 +1998,13 @@ verify_coordinates_vars_2(stream_t *streamptr, int nvars, ncvar_t *ncvars) else if (ncvar->zaxistype == CDI_UNDEFID && (str_is_equal(ncvar->units, "level") || str_is_equal(ncvar->units, "1"))) { // clang-format off - if (str_is_equal(ncvar->longname, "hybrid level at layer midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; - else if (strStartsWith(ncvar->longname, "hybrid level at midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; - else if (str_is_equal(ncvar->longname, "hybrid level at layer interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; - else if (strStartsWith(ncvar->longname, "hybrid level at interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; - else if (str_is_equal(ncvar->units, "level")) ncvar->zaxistype = ZAXIS_GENERIC; + if (str_is_equal(ncvar->longname, "hybrid level at layer midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; + else if (str_is_equal(ncvar->longname, "hybrid model level at layer midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; + else if (strStartsWith(ncvar->longname, "hybrid level at midpoints")) ncvar->zaxistype = ZAXIS_HYBRID; + else if (str_is_equal(ncvar->longname, "hybrid level at layer interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; + else if (str_is_equal(ncvar->longname, "hybrid model level at layer interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; + else if (strStartsWith(ncvar->longname, "hybrid level at interfaces")) ncvar->zaxistype = ZAXIS_HYBRID_HALF; + else if (str_is_equal(ncvar->units, "level")) ncvar->zaxistype = ZAXIS_GENERIC; // clang-format on continue; } @@ -2914,6 +2929,8 @@ cdf_set_grid_to_similar_vars(ncvar_t *ncvar1, ncvar_t *ncvar2, int gridtype, int ncvar2->chunkType = ncvar1->chunkType; ncvar2->chunkSize = ncvar1->chunkSize; ncvar2->gridSize = ncvar1->gridSize; + ncvar2->xSize = ncvar1->xSize; + ncvar2->ySize = ncvar1->ySize; } } } @@ -3073,6 +3090,8 @@ cdf_define_all_grids(stream_t *streamptr, ncgrid_t *ncgrid, int vlistID, ncdim_t gridAdded = cdiVlistAddGridIfNew(vlistID, grid, 1); ncvar->gridID = gridAdded.Id; ncvar->gridSize = grid->size; + ncvar->xSize = grid->x.size; + ncvar->ySize = grid->y.size; int gridID = ncvar->gridID; @@ -3504,22 +3523,32 @@ cdf_xtype_to_numbytes(int xtype) return numBytes; } +static inline size_t +size_of_dim_chunks(size_t n, size_t c) +{ + return (n / c + (n % c > 0)) * c; +} + static size_t calc_chunk_cache_size(int timedimid, ncvar_t *ncvar) { - size_t chunkCacheSize = ncvar->gridSize; - - chunkCacheSize *= (ncvar->dimids[0] == timedimid) ? ncvar->chunks[0] : 1; - + size_t nx = 0, ny = 0, nz = 0; + size_t cx = 0, cy = 0, cz = 0; for (int i = 0; i < ncvar->ndims; i++) { - if (ncvar->dimtypes[i] == Z_AXIS) - { - chunkCacheSize *= ncvar->chunks[i]; - break; - } + int dimtype = ncvar->dimtypes[i]; + // clang-format off + if (dimtype == Z_AXIS) { cz = ncvar->chunks[i]; nz = ncvar->numLevels; } + else if (dimtype == Y_AXIS) { cy = ncvar->chunks[i]; ny = ncvar->ySize; } + else if (dimtype == X_AXIS) { cx = ncvar->chunks[i]; nx = ncvar->xSize; } + // clang-format on } + size_t chunkCacheSize = (ncvar->dimids[0] == timedimid) ? ncvar->chunks[0] : 1; + if (nz > 0 && cz > 0) chunkCacheSize *= (chunkCacheSize == 1) ? cz : size_of_dim_chunks(nz, cz); + if (ny > 0 && cy > 0) chunkCacheSize *= size_of_dim_chunks(ny, cy); + if (nx > 0 && cx > 0) chunkCacheSize *= size_of_dim_chunks(nx, cx); + chunkCacheSize *= cdf_xtype_to_numbytes(ncvar->xtype); if (CDI_Chunk_Cache_Max > 0 && chunkCacheSize > CDI_Chunk_Cache_Max) chunkCacheSize = CDI_Chunk_Cache_Max; @@ -4211,7 +4240,7 @@ cdfVerifyVars(int nvars, ncvar_t *ncvars, ncdim_t *ncdims) ncvar->varStatus = CoordVar; Warning("Inconsistent number of dimensions, skipped variable %s!", ncvar->name); } - + /* check failed with cdo option --cmor int zdimid = -1; for (int i = 0; i < ncvar->ndims; ++i) { @@ -4224,6 +4253,7 @@ cdfVerifyVars(int nvars, ncvar_t *ncvars, ncdim_t *ncdims) ncvar->varStatus = CoordVar; Warning("Unsupported dimension >%s<, skipped variable %s!", ncdims[zdimid].name, ncvar->name); } + */ } } } diff --git a/src/stream_cdf_o.c b/src/stream_cdf_o.c index cc6126fd8f20cf948bbd6291c6acd4bb614db982..e5c595dc1bf027c6b6f912122e7616632c8f0697 100644 --- a/src/stream_cdf_o.c +++ b/src/stream_cdf_o.c @@ -1722,7 +1722,7 @@ cdfDefZaxis(stream_t *streamptr, int zaxisID) int length = CDI_MAX_NAME; cdiInqKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_NAME, axisname, &length); int zaxisindex = vlistZaxisIndex(vlistID, zaxisID); - int nzaxis = vlistNzaxis(vlistID); + int nzaxis = vlistNumZaxis(vlistID); int fileID = streamptr->fileID; checkZaxisName(axisname, fileID, vlistID, zaxisID, nzaxis); @@ -2236,7 +2236,7 @@ cdfDefCoordinateVars(stream_t *streamptr) if (vlistHasTime(vlistID)) cdfDefTime(streamptr); - int ngrids = vlistNgrids(vlistID); + int ngrids = vlistNumGrids(vlistID); if (2 * ngrids > MAX_GRIDS_PS) Error("Internal problem! Too many grids per stream (max=%d)\n", MAX_GRIDS_PS); struct cdfPostDefActionList *delayed = NULL; @@ -2270,7 +2270,7 @@ cdfDefCoordinateVars(stream_t *streamptr) } } - int nzaxis = vlistNzaxis(vlistID); + int nzaxis = vlistNumZaxis(vlistID); for (int index = 0; index < nzaxis; ++index) { int zaxisID = vlistZaxis(vlistID, index); diff --git a/src/stream_cdf_time.c b/src/stream_cdf_time.c index 29851b32ede1217e9479e5c3ac27ca50177bb4ca..9781f2617d10c47fef60d05d2ca6d0df2f3b43d4 100644 --- a/src/stream_cdf_time.c +++ b/src/stream_cdf_time.c @@ -67,7 +67,7 @@ cdfGetTimeUnits(taxis_t *taxis) if (taxis->type == TAXIS_ABSOLUTE) { static const char *const unitstrfmt[3] = { "year as %Y.%f", "month as %Y%m.%f", "day as %Y%m%d.%f" }; - size_t fmtidx = (taxis->unit == TUNIT_YEAR ? 0 : (taxis->unit == TUNIT_MONTH ? 1 : 2)); + size_t fmtidx = ((taxis->unit == TUNIT_YEAR) ? 0 : ((taxis->unit == TUNIT_MONTH) ? 1 : 2)); unitstr = unitstrfmt[fmtidx]; } else diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c index 41c5a87a4966dcb990cad73c5996fe82298ae8a0..2442e6203d9a3bbe41ac03079daeabe2133714b8 100644 --- a/src/stream_cgribex.c +++ b/src/stream_cgribex.c @@ -1974,6 +1974,13 @@ cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int levelID) else level = level / 100; + static bool lwarn = true; + if (lwarn && modf(level, &dum) > 0.001) + { + lwarn = false; + Message("GRIB1 can store only full pressure levels! Level changed from %ghPa to %dhPa.", level, level2int(level)); + } + isec1DefLevel(isec1, grib_ltype, level2int(level), 0); break; } diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c index 5bbdafb8a5040199f96aa6cc6ae3ea4fbe92271b..d7b18f3fe9db1b6138570421dc6b85d0de421ba8 100644 --- a/src/stream_gribapi.c +++ b/src/stream_gribapi.c @@ -87,8 +87,14 @@ gribapi_get_timeunits(grib_handle *gh) { long unitsOfTime = -1; grib_get_long(gh, "indicatorOfUnitOfTimeRange", &unitsOfTime); + if (unitsOfTime == -1) grib_get_long(gh, "indicatorOfUnitForTimeIncrement", &unitsOfTime); - GRIB_CHECK(my_grib_set_long(gh, "stepUnits", unitsOfTime), 0); + if (unitsOfTime != -1) + { + long stepUnits = -1; + grib_get_long(gh, "stepUnits", &stepUnits); + if (stepUnits == -1 && stepUnits != unitsOfTime) GRIB_CHECK(my_grib_set_long(gh, "stepUnits", unitsOfTime), 0); + } return get_timeunits(unitsOfTime); } @@ -114,7 +120,7 @@ gribapiGetSteps(grib_handle *gh, int timeunits, int *startStep, int *endStep) *endStep = *startStep; status = grib_get_long(gh, "endStep", &lpar); if (status == 0) *endStep = (int) (((double) lpar * timeunits_factor(timeunits, timeunits2)) + 0.5); - // printf("%d %d %d %d %d %g\n", *startStep, *endStep, lpar, timeunits, timeunits2, timeunits_factor(timeunits, timeunits2)); + // printf("%d %d %ld %d %d %g\n", *startStep, *endStep, lpar, timeunits, timeunits2, timeunits_factor(timeunits, timeunits2)); } static CdiDateTime @@ -1206,6 +1212,21 @@ fdbScanTimesteps(stream_t *streamptr) return 0; } +static int +records_cmp_varname(const void *s1, const void *s2) +{ + const record_t *x = (const record_t *) s1, *y = (const record_t *) s2; + return strcmp(x->varname, y->varname); +} + +void +sort_records(stream_t *streamptr) +{ + record_t *records = streamptr->tsteps[0].records; + int numRecords = streamptr->tsteps[0].recordSize; + qsort(records, numRecords, sizeof(records[0]), records_cmp_varname); +} + int gribapiScanTimestep1(stream_t *streamptr) { @@ -1354,6 +1375,8 @@ gribapiScanTimestep1(stream_t *streamptr) streamScanTsFixNtsteps(streamptr, recpos); streamScanTimeConstAdjust(streamptr, taxis); + if (streamptr->sortname) sort_records(streamptr); + return 0; } @@ -2818,9 +2841,18 @@ gribapiDefLevel(int editionNumber, grib_handle *gh, int zaxisID, int levelID, in grib_ltype = GRIB1_LTYPE_ISOBARIC_PA; else level /= 100; + + static bool lwarn = true; + if (lwarn && modf(level, &dum) > 0.001) + { + lwarn = false; + Warning("GRIB1 can store only full pressure levels! Level changed from %ghPa to %dhPa.", level, + (int) lround(level)); + } } else if (ltype2 == -1) ltype2 = GRIB2_LTYPE_ISOBARIC; + defLevel(gh, gcinit, grib_ltype, ltype2, hasBounds, level, dlevel1, dlevel2); break; diff --git a/src/table.c b/src/table.c index 07cff4e2a363d07a29a3decb66fd23c1f90cb815..538d9619116ffc136aa3e5cdf5ca634ed02226ee 100644 --- a/src/table.c +++ b/src/table.c @@ -1,8 +1,8 @@ +#include <stdlib.h> #include <stddef.h> #include <string.h> #include <ctype.h> -#include "dmemory.h" #include "cdi.h" #include "cdi_int.h" @@ -110,12 +110,13 @@ parTableFinalize(void) int npars = parTable[tableID].npars; for (int item = 0; item < npars; ++item) { - if (parTable[tableID].pars[item].dupflags & TABLE_DUP_NAME) Free((void *) parTable[tableID].pars[item].name); - if (parTable[tableID].pars[item].dupflags & TABLE_DUP_LONGNAME) Free((void *) parTable[tableID].pars[item].longname); - if (parTable[tableID].pars[item].dupflags & TABLE_DUP_UNITS) Free((void *) parTable[tableID].pars[item].units); + param_type *param = &parTable[tableID].pars[item]; + if (param->dupflags & TABLE_DUP_NAME) free((void *) param->name); + if (param->dupflags & TABLE_DUP_LONGNAME) free((void *) param->longname); + if (param->dupflags & TABLE_DUP_UNITS) free((void *) param->units); } - Free(parTable[tableID].pars); - Free(parTable[tableID].name); + free(parTable[tableID].pars); + free(parTable[tableID].name); } } @@ -390,7 +391,7 @@ tableFromEnv(int modelID, int tablenum) if (tablePath) lenp = strlen(tablePath); // if (tablePath) printf("tablePath = %s\n", tablePath); // if (tablename) printf("tableName = %s\n", tablename); - char *tablefile = (char *) Malloc(lenp + lenf + 3); + char *tablefile = (char *) malloc(lenp + lenf + 3); if (tablePath) { strcpy(tablefile, tablePath); @@ -408,7 +409,7 @@ tableFromEnv(int modelID, int tablenum) tableDefNum(tableID, tablenum); } // printf("tableID = %d %s\n", tableID, tablefile); - Free(tablefile); + free(tablefile); return tableID; } @@ -502,7 +503,7 @@ tableDef(int modelID, int tablenum, const char *tablename) parTable[tableID].number = tablenum; if (tablename) parTable[tableID].name = strdup(tablename); - parTable[tableID].pars = (param_type *) Malloc(MAX_PARS * sizeof(param_type)); + parTable[tableID].pars = (param_type *) malloc(MAX_PARS * sizeof(param_type)); } return tableID; diff --git a/src/taxis.c b/src/taxis.c index facf2778d9a2f97bb0890e01921fa5d38c2da6bf..9b013281bb3a36a7c3f8173d46f8c3c91ae488e6 100644 --- a/src/taxis.c +++ b/src/taxis.c @@ -83,9 +83,7 @@ tunitNamePtr(int unitID) size = sizeof(Timeunits) / sizeof(Timeunits[0]) }; - const char *name = unitID > 0 && unitID < size ? Timeunits[unitID] : Timeunits[0]; - - return name; + return (unitID > 0 && unitID < size) ? Timeunits[unitID] : Timeunits[0]; } void diff --git a/src/varscan.c b/src/varscan.c index dfded42ddac68b1484c58c8c6c0bd30872a2f657..04c9320f7ab7128389a2b5ec9b4fabef86ef80af 100644 --- a/src/varscan.c +++ b/src/varscan.c @@ -481,14 +481,13 @@ varCopyKeys(int vlistID, int varID) cdiInitKeys(&vlistptr->vars[varID].keys); cdiCopyVarKeys(&vartable[varID].keys, &vlistptr->vars[varID].keys); } - +/* struct cdi_generate_varinfo { int varid; const char *name; }; -/* static int cdi_generate_cmp_varname(const void *s1, const void *s2) { @@ -496,7 +495,6 @@ cdi_generate_cmp_varname(const void *s1, const void *s2) return strcmp(x->name, y->name); } */ - void cdi_generate_vars(stream_t *streamptr) { @@ -505,30 +503,30 @@ cdi_generate_vars(stream_t *streamptr) int *varids = (int *) Malloc(varTableUsed * sizeof(int)); for (int varID = 0; varID < varTableUsed; varID++) varids[varID] = (int) varID; /* - if ( streamptr->sortname ) - { - size_t varID; - for (varID = 0; varID < varTableUsed; varID++) - if (!vartable[varID].name) break; + if (streamptr->sortname) + { + bool hasName = true; + for (int varID = 0; varID < varTableUsed; varID++) + if (!vartable[varID].name) hasName = false; - if ( varID == varTableUsed ) - { - struct cdi_generate_varinfo *varInfo - = (struct cdi_generate_varinfo *) Malloc((size_t)varTableUsed * sizeof(struct cdi_generate_varinfo)); + if (hasName) + { + struct cdi_generate_varinfo *varInfo + = (struct cdi_generate_varinfo *) Malloc((size_t) varTableUsed * sizeof(struct cdi_generate_varinfo)); - for (size_t varID = 0; varID < varTableUsed; varID++) - { - varInfo[varID].varid = varids[varID]; - varInfo[varID].name = vartable[varids[varID]].name; - } - qsort(varInfo, varTableUsed, sizeof(varInfo[0]), cdi_generate_cmp_varname); - for (size_t varID = 0; varID < varTableUsed; varID++) - { - varids[varID] = varInfo[varID].varid; - } - Free(varInfo); - } - } + for (int varID = 0; varID < varTableUsed; varID++) + { + varInfo[varID].varid = varids[varID]; + varInfo[varID].name = vartable[varids[varID]].name; + } + qsort(varInfo, varTableUsed, sizeof(varInfo[0]), cdi_generate_cmp_varname); + for (int varID = 0; varID < varTableUsed; varID++) + { + varids[varID] = varInfo[varID].varid; + } + Free(varInfo); + } + } */ for (int index = 0; index < varTableUsed; index++) { diff --git a/src/vlist.c b/src/vlist.c index 1190212745134ca8cf081b30b811084360cf88a4..d5a0a120b7f1cabe2d0d51f3672d557c56342022 100644 --- a/src/vlist.c +++ b/src/vlist.c @@ -316,8 +316,8 @@ var_copy_entries(var_t *var2, var_t *var1) @Prototype void vlistCopy(int vlistID2, int vlistID1) @Parameter - @Item vlistID2 Target variable list ID. @Item vlistID1 Source variable list ID. + @Item vlistID2 Target variable list ID. @Description The function @func{vlistCopy} copies all entries from vlistID1 to vlistID2. @@ -325,7 +325,7 @@ The function @func{vlistCopy} copies all entries from vlistID1 to vlistID2. @EndFunction */ void -vlistCopy(int vlistID2, int vlistID1) +vlistCopy(int vlistID1, int vlistID2) { vlist_t *vlistptr1 = vlist_to_pointer(vlistID1); vlist_t *vlistptr2 = vlist_to_pointer(vlistID2); @@ -391,7 +391,7 @@ vlistDuplicate(int vlistID) if (CDI_Debug) Message("call to vlistDuplicate"); int vlistIDnew = vlistCreate(); - vlistCopy(vlistIDnew, vlistID); + vlistCopy(vlistID, vlistIDnew); return vlistIDnew; } @@ -952,7 +952,7 @@ vlistNvars(int vlistID) } int -vlistNrecs(int vlistID) +vlistNumRecords(int vlistID) { vlist_t *vlistptr = vlist_to_pointer(vlistID); @@ -985,23 +985,23 @@ vlistNumber(int vlistID) } /* -@Function vlistNgrids +@Function vlistNumGrids @Title Number of grids in a variable list -@Prototype int vlistNgrids(int vlistID) +@Prototype int vlistNumGrids(int vlistID) @Parameter @Item vlistID Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}. @Description -The function @func{vlistNgrids} returns the number of grids in the variable list vlistID. +The function @func{vlistNumGrids} returns the number of grids in the variable list vlistID. @Result -@func{vlistNgrids} returns the number of grids in a variable list. +@func{vlistNumGrids} returns the number of grids in a variable list. @EndFunction */ int -vlistNgrids(int vlistID) +vlistNumGrids(int vlistID) { vlist_t *vlistptr = vlist_to_pointer(vlistID); @@ -1009,23 +1009,23 @@ vlistNgrids(int vlistID) } /* -@Function vlistNzaxis +@Function vlistNumZaxis @Title Number of zaxis in a variable list -@Prototype int vlistNzaxis(int vlistID) +@Prototype int vlistNumZaxis(int vlistID) @Parameter @Item vlistID Variable list ID, from a previous call to @fref{vlistCreate} or @fref{streamInqVlist}. @Description -The function @func{vlistNzaxis} returns the number of zaxis in the variable list vlistID. +The function @func{vlistNumZaxis} returns the number of zaxis in the variable list vlistID. @Result -@func{vlistNzaxis} returns the number of zaxis in a variable list. +@func{vlistNumZaxis} returns the number of zaxis in a variable list. @EndFunction */ int -vlistNzaxis(int vlistID) +vlistNumZaxis(int vlistID) { vlist_t *vlistptr = vlist_to_pointer(vlistID); @@ -1586,7 +1586,7 @@ vlistUnpack(char *buf, int size, int *position, int originNamespace, void *conte void vlist_check_contents(int vlistID) { - int nzaxis = vlistNzaxis(vlistID); + int nzaxis = vlistNumZaxis(vlistID); for (int index = 0; index < nzaxis; index++) { int zaxisID = vlistZaxis(vlistID, index); diff --git a/tests/stream_cksum.c b/tests/stream_cksum.c index 06e8d9f70d92b9978fe6fcd59fe220c3253fb35a..b07f455499d152fa96fc01a7754ec1bbae98d675 100644 --- a/tests/stream_cksum.c +++ b/tests/stream_cksum.c @@ -50,8 +50,8 @@ cksum_stream(const char *fname, size_t *table_len) int fileType = streamInqFiletype(streamID); bool isLegacyFile = fileType == CDI_FILETYPE_SRV || fileType == CDI_FILETYPE_EXT; nvars = vlistNvars(vlistID); - int ngrids = vlistNgrids(vlistID); - int nzaxis = vlistNzaxis(vlistID); + int ngrids = vlistNumGrids(vlistID); + int nzaxis = vlistNumZaxis(vlistID); if (nzaxis < 0 || ngrids < 0) { fprintf(stderr, "Error in grid/zaxis count query %d:%d\n", ngrids, nzaxis); diff --git a/tests/test_resource_copy.c b/tests/test_resource_copy.c index e4c8494130702db6c5e7d1d21fce72e57cc1fb3b..ce789c30dabe9dfd5fbf8f62c897b1481afd9b83 100644 --- a/tests/test_resource_copy.c +++ b/tests/test_resource_copy.c @@ -163,9 +163,7 @@ defineVlist(int gridID, int zaxisID, int taxisID) vlistDefVarName(vlistID, varID2, "varname2"); cdiDefAttTxt(vlistID, varID2, "txt demo", 6, "banana"); vlistDefTaxis(vlistID, taxisID); - int vlistID2 = vlistCreate(); - vlistDefVar(vlistID2, gridID, zaxisID, TIME_VARIABLE); - vlistCopy(vlistID2, vlistID); + int vlistID2 = vlistDuplicate(vlistID); return (struct idPair){ vlistID, vlistID2 }; }