diff --git a/.travis.yml b/.travis.yml index 8a5dc0fd0..3234d4be0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ matrix: - libnetcdf-dev - os: osx - osx_image: xcode10.1 + osx_image: xcode10.2 addons: homebrew: packages: diff --git a/CMakeLists.txt b/CMakeLists.txt index 26b95389e..e3878778b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,7 @@ ecbuild_add_option( FEATURE PYTHON REQUIRED_PACKAGES "Python VERSION 2.6 NO_LIBS" NumPy ) # For Python2 we build our own bindings (using SWIG) in the build directory -# but for Python3 one has to add the eccodes-python from pip AFTER the install +# but for Python3 one has to add the eccodes-python from pip3 AFTER the install if( PYTHON_VERSION_MAJOR EQUAL 3 ) set( HAVE_PYTHON 0 ) endif() @@ -337,8 +337,6 @@ configure_file( eccodes_config.h.in eccodes_config.h ) add_definitions( -DHAVE_ECCODES_CONFIG_H ) -install( FILES ${CMAKE_CURRENT_BINARY_DIR}/eccodes_config.h DESTINATION ${INSTALL_INCLUDE_DIR} ) - if( CMAKE_COMPILER_IS_GNUCC ) ecbuild_add_c_flags("-pedantic") endif() @@ -389,7 +387,7 @@ add_subdirectory( fortran ) if (PYTHON_VERSION_MAJOR GREATER 2) # Python3 is no longer built with SWIG but is a separate - # package. User should do: pip install eccodes-python + # package. User should do: pip3 install eccodes-python #add_subdirectory( python3 ) set( ECCODES_PYTHON_DIR "python3" ) else() @@ -481,6 +479,6 @@ ecbuild_info(" | Please note: |") ecbuild_info(" | For Python3 support, first install |") ecbuild_info(" | ecCodes and then install the Python |") ecbuild_info(" | bindings from PyPI with: |") -ecbuild_info(" | $ pip install eccodes-python |") +ecbuild_info(" | $ pip3 install eccodes-python |") ecbuild_info(" +--------------------------------------+") ecbuild_info("") diff --git a/INSTALL b/INSTALL index 6162c7992..299775237 100644 --- a/INSTALL +++ b/INSTALL @@ -33,10 +33,10 @@ However it requires that cmake be installed on your system. > ctest > make install -To add the Python3 bindings, use pip install from PyPI as follows: - > pip install eccodes-python +To add the Python3 bindings, use pip3 install from PyPI as follows: + > pip3 install eccodes-python or - > pip install --install-option="--prefix=/path/to/where/you/install/eccodes" eccodes-python + > pip3 install --install-option="--prefix=/path/to/where/you/install/eccodes" eccodes-python You can also pass options to the cmake command above. Some typical examples are: diff --git a/README.md b/README.md index 4e9e9ac9e..d84fc865b 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,13 @@ INSTALLATION make install ``` -To add the Python3 bindings, use pip install from PyPI as follows: +To add the Python3 bindings, use pip3 install from PyPI as follows: ``` - pip install eccodes-python + pip3 install eccodes-python ``` or ``` - pip install --install-option="--prefix=/path/to/where/you/install/eccodes" eccodes-python + pip3 install --install-option="--prefix=/path/to/where/you/install/eccodes" eccodes-python ``` diff --git a/definitions/grib1/2.98.171.table b/definitions/grib1/2.98.171.table index 18666a4f5..39cf33bfe 100644 --- a/definitions/grib1/2.98.171.table +++ b/definitions/grib1/2.98.171.table @@ -137,7 +137,7 @@ 204 204 - Precipitation analysis weights 205 205 - Runoff (m) 206 206 - Total column ozone (kg m**-2) -207 207 - 10 metre wind speed (m s**-1) +207 207 10SIA 10 metre wind speed (m s**-1) 208 208 - Top net solar radiation, clear sky (W m**-2 s) 209 209 - Top net thermal radiation, clear sky (W m**-2 s) 210 210 - Surface net solar radiation, clear sky (W m**-2 s) diff --git a/definitions/grib1/2.98.172.table b/definitions/grib1/2.98.172.table index 37a3c2f15..5d8f8653c 100644 --- a/definitions/grib1/2.98.172.table +++ b/definitions/grib1/2.98.172.table @@ -4,22 +4,22 @@ 44 44 ESRATE Snow evaporation (m of water s**-1) 45 45 - Snowmelt (m of water s**-1) 48 48 - Magnitude of turbulent surface stress (N m**-2) -50 50 - Large-scale precipitation fraction (~) +50 50 MLSPFR Mean large-scale precipitation fraction (~) 142 142 MLSPRT Mean large-scale precipitation rate (m s**-1) 143 143 CPRATE Mean convective precipitation rate (m s**-1) 144 144 - Snowfall (convective + stratiform) (m of water equivalent s**-1) 145 145 BLDRATE Boundary layer dissipation (W m**-2) -146 146 - Surface sensible heat flux (W m**-2) -147 147 - Surface latent heat flux (W m**-2) -149 149 - Surface net radiation (W m**-2) -153 153 - Short-wave heating rate (K s**-1) -154 154 - Long-wave heating rate (K s**-1) -169 169 - Surface solar radiation downwards (W m**-2) -175 175 - Surface thermal radiation downwards (W m**-2) -176 176 - Surface solar radiation (W m**-2) -177 177 - Surface thermal radiation (W m**-2) -178 178 - Top solar radiation (W m**-2) -179 179 - Top thermal radiation (W m**-2) +146 146 MSSHFL Mean surface sensible heat flux (W m**-2) +147 147 MSLHFL Mean surface latent heat flux (W m**-2) +149 149 MSNRF Mean surface net radiation flux (W m**-2) +153 153 MSWHR Mean short-wave heating rate (K s**-1) +154 154 MLWHR Mean long-wave heating rate (K s**-1) +169 169 MSDSRF Mean surface downward solar radiation flux (W m**-2) +175 175 MSDTRF Mean surface downward thermal radiation flux (W m**-2) +176 176 MSNSRF Mean surface net solar radiation flux (W m**-2) +177 177 MSNTRF Mean surface net thermal radiation flux (W m**-2) +178 178 MTNSRF Mean top net solar radiation flux (W m**-2) +179 179 MTNTRF Mean top net thermal radiation flux (W m**-2) 180 180 EWSSRA East-West surface stress rate of accumulation (N m**-2) 181 181 NSSSRA North-South surface stress rate of accumulation (N m**-2) 182 182 ERATE Evaporation (m of water s**-1) @@ -27,7 +27,7 @@ 195 195 - Longitudinal component of gravity wave stress (N m**-2) 196 196 - Meridional component of gravity wave stress (N m**-2) 197 197 GWDRATE Gravity wave dissipation (W m**-2) -205 205 - Runoff (m s**-1) +205 205 MRORT Mean runoff rate (m s**-1) 208 208 - Top net solar radiation, clear sky (W m**-2) 209 209 - Top net thermal radiation, clear sky (W m**-2) 210 210 - Surface net solar radiation, clear sky (W m**-2) diff --git a/definitions/grib1/2.98.173.table b/definitions/grib1/2.98.173.table index 3e5342965..e16e9a700 100644 --- a/definitions/grib1/2.98.173.table +++ b/definitions/grib1/2.98.173.table @@ -6,7 +6,7 @@ 48 48 - Magnitude of turbulent surface stress anomaly (N m**-2) 50 50 - Large-scale precipitation fraction anomaly (~) 142 142 LSPARA Stratiform precipitation (Large-scale precipitation) anomalous rate of accumulation (m s**-1) -143 143 - Convective precipitation anomaly (m s**-1) +143 143 MCPRA Mean convective precipitation rate anomaly (m s**-1) 144 144 SFARA Snowfall (convective + stratiform) anomalous rate of accumulation (m of water equivalent s**-1) 145 145 - Boundary layer dissipation anomaly (J m**-2) 146 146 SSHFARA Surface sensible heat flux anomalous rate of accumulation (J m**-2) diff --git a/definitions/grib1/localConcepts/ecmf/cfVarName.def b/definitions/grib1/localConcepts/ecmf/cfVarName.def index e83fa6b8f..70819a846 100644 --- a/definitions/grib1/localConcepts/ecmf/cfVarName.def +++ b/definitions/grib1/localConcepts/ecmf/cfVarName.def @@ -14629,8 +14629,8 @@ table2Version = 172 ; indicatorOfParameter = 48 ; } -#Large-scale precipitation fraction -'p50.172' = { +#Mean large-scale precipitation fraction +'mlspfr' = { table2Version = 172 ; indicatorOfParameter = 50 ; } @@ -14654,58 +14654,58 @@ table2Version = 172 ; indicatorOfParameter = 145 ; } -#Surface sensible heat flux -'p146.172' = { +#Mean surface sensible heat flux +'msshfl' = { table2Version = 172 ; indicatorOfParameter = 146 ; } -#Surface latent heat flux -'p147.172' = { +#Mean surface latent heat flux +'mslhfl' = { table2Version = 172 ; indicatorOfParameter = 147 ; } -#Surface net radiation -'p149.172' = { +#Mean surface net radiation flux +'msnrf' = { table2Version = 172 ; indicatorOfParameter = 149 ; } -#Short-wave heating rate -'p153.172' = { +#Mean short-wave heating rate +'mswhr' = { table2Version = 172 ; indicatorOfParameter = 153 ; } -#Long-wave heating rate -'p154.172' = { +#Mean long-wave heating rate +'mlwhr' = { table2Version = 172 ; indicatorOfParameter = 154 ; } -#Surface solar radiation downwards -'p169.172' = { +#Mean surface downward solar radiation flux +'msdsrf' = { table2Version = 172 ; indicatorOfParameter = 169 ; } -#Surface thermal radiation downwards -'p175.172' = { +#Mean surface downward thermal radiation flux +'msdtrf' = { table2Version = 172 ; indicatorOfParameter = 175 ; } -#Surface solar radiation -'p176.172' = { +#Mean surface net solar radiation flux +'msnsrf' = { table2Version = 172 ; indicatorOfParameter = 176 ; } -#Surface thermal radiation -'p177.172' = { +#Mean surface net thermal radiation flux +'msntrf' = { table2Version = 172 ; indicatorOfParameter = 177 ; } -#Top solar radiation -'p178.172' = { +#Mean top net solar radiation flux +'mtnsrf' = { table2Version = 172 ; indicatorOfParameter = 178 ; } -#Top thermal radiation -'p179.172' = { +#Mean top net thermal radiation flux +'mtntrf' = { table2Version = 172 ; indicatorOfParameter = 179 ; } @@ -14744,8 +14744,8 @@ table2Version = 172 ; indicatorOfParameter = 197 ; } -#Runoff -'p205.172' = { +#Mean runoff rate +'mrort' = { table2Version = 172 ; indicatorOfParameter = 205 ; } @@ -14819,8 +14819,8 @@ table2Version = 173 ; indicatorOfParameter = 142 ; } -#Convective precipitation anomaly -'p143.173' = { +#Mean convective precipitation rate anomaly +'mcpra' = { table2Version = 173 ; indicatorOfParameter = 143 ; } diff --git a/definitions/grib1/localConcepts/ecmf/name.def b/definitions/grib1/localConcepts/ecmf/name.def index 275de73d2..8bb75fe63 100644 --- a/definitions/grib1/localConcepts/ecmf/name.def +++ b/definitions/grib1/localConcepts/ecmf/name.def @@ -14629,8 +14629,8 @@ table2Version = 172 ; indicatorOfParameter = 48 ; } -#Large-scale precipitation fraction -'Large-scale precipitation fraction' = { +#Mean large-scale precipitation fraction +'Mean large-scale precipitation fraction' = { table2Version = 172 ; indicatorOfParameter = 50 ; } @@ -14654,58 +14654,58 @@ table2Version = 172 ; indicatorOfParameter = 145 ; } -#Surface sensible heat flux -'Surface sensible heat flux' = { +#Mean surface sensible heat flux +'Mean surface sensible heat flux' = { table2Version = 172 ; indicatorOfParameter = 146 ; } -#Surface latent heat flux -'Surface latent heat flux' = { +#Mean surface latent heat flux +'Mean surface latent heat flux' = { table2Version = 172 ; indicatorOfParameter = 147 ; } -#Surface net radiation -'Surface net radiation' = { +#Mean surface net radiation flux +'Mean surface net radiation flux' = { table2Version = 172 ; indicatorOfParameter = 149 ; } -#Short-wave heating rate -'Short-wave heating rate' = { +#Mean short-wave heating rate +'Mean short-wave heating rate' = { table2Version = 172 ; indicatorOfParameter = 153 ; } -#Long-wave heating rate -'Long-wave heating rate' = { +#Mean long-wave heating rate +'Mean long-wave heating rate' = { table2Version = 172 ; indicatorOfParameter = 154 ; } -#Surface solar radiation downwards -'Surface solar radiation downwards' = { +#Mean surface downward solar radiation flux +'Mean surface downward solar radiation flux' = { table2Version = 172 ; indicatorOfParameter = 169 ; } -#Surface thermal radiation downwards -'Surface thermal radiation downwards' = { +#Mean surface downward thermal radiation flux +'Mean surface downward thermal radiation flux' = { table2Version = 172 ; indicatorOfParameter = 175 ; } -#Surface solar radiation -'Surface solar radiation' = { +#Mean surface net solar radiation flux +'Mean surface net solar radiation flux' = { table2Version = 172 ; indicatorOfParameter = 176 ; } -#Surface thermal radiation -'Surface thermal radiation' = { +#Mean surface net thermal radiation flux +'Mean surface net thermal radiation flux' = { table2Version = 172 ; indicatorOfParameter = 177 ; } -#Top solar radiation -'Top solar radiation' = { +#Mean top net solar radiation flux +'Mean top net solar radiation flux' = { table2Version = 172 ; indicatorOfParameter = 178 ; } -#Top thermal radiation -'Top thermal radiation' = { +#Mean top net thermal radiation flux +'Mean top net thermal radiation flux' = { table2Version = 172 ; indicatorOfParameter = 179 ; } @@ -14744,8 +14744,8 @@ table2Version = 172 ; indicatorOfParameter = 197 ; } -#Runoff -'Runoff' = { +#Mean runoff rate +'Mean runoff rate' = { table2Version = 172 ; indicatorOfParameter = 205 ; } @@ -14819,8 +14819,8 @@ table2Version = 173 ; indicatorOfParameter = 142 ; } -#Convective precipitation anomaly -'Convective precipitation anomaly' = { +#Mean convective precipitation rate anomaly +'Mean convective precipitation rate anomaly' = { table2Version = 173 ; indicatorOfParameter = 143 ; } diff --git a/definitions/grib1/localConcepts/ecmf/paramId.def b/definitions/grib1/localConcepts/ecmf/paramId.def index 5501d85f7..e7e57b9be 100644 --- a/definitions/grib1/localConcepts/ecmf/paramId.def +++ b/definitions/grib1/localConcepts/ecmf/paramId.def @@ -14629,7 +14629,7 @@ table2Version = 172 ; indicatorOfParameter = 48 ; } -#Large-scale precipitation fraction +#Mean large-scale precipitation fraction '172050' = { table2Version = 172 ; indicatorOfParameter = 50 ; @@ -14654,57 +14654,57 @@ table2Version = 172 ; indicatorOfParameter = 145 ; } -#Surface sensible heat flux +#Mean surface sensible heat flux '172146' = { table2Version = 172 ; indicatorOfParameter = 146 ; } -#Surface latent heat flux +#Mean surface latent heat flux '172147' = { table2Version = 172 ; indicatorOfParameter = 147 ; } -#Surface net radiation +#Mean surface net radiation flux '172149' = { table2Version = 172 ; indicatorOfParameter = 149 ; } -#Short-wave heating rate +#Mean short-wave heating rate '172153' = { table2Version = 172 ; indicatorOfParameter = 153 ; } -#Long-wave heating rate +#Mean long-wave heating rate '172154' = { table2Version = 172 ; indicatorOfParameter = 154 ; } -#Surface solar radiation downwards +#Mean surface downward solar radiation flux '172169' = { table2Version = 172 ; indicatorOfParameter = 169 ; } -#Surface thermal radiation downwards +#Mean surface downward thermal radiation flux '172175' = { table2Version = 172 ; indicatorOfParameter = 175 ; } -#Surface solar radiation +#Mean surface net solar radiation flux '172176' = { table2Version = 172 ; indicatorOfParameter = 176 ; } -#Surface thermal radiation +#Mean surface net thermal radiation flux '172177' = { table2Version = 172 ; indicatorOfParameter = 177 ; } -#Top solar radiation +#Mean top net solar radiation flux '172178' = { table2Version = 172 ; indicatorOfParameter = 178 ; } -#Top thermal radiation +#Mean top net thermal radiation flux '172179' = { table2Version = 172 ; indicatorOfParameter = 179 ; @@ -14744,7 +14744,7 @@ table2Version = 172 ; indicatorOfParameter = 197 ; } -#Runoff +#Mean runoff rate '172205' = { table2Version = 172 ; indicatorOfParameter = 205 ; @@ -14819,7 +14819,7 @@ table2Version = 173 ; indicatorOfParameter = 142 ; } -#Convective precipitation anomaly +#Mean convective precipitation rate anomaly '173143' = { table2Version = 173 ; indicatorOfParameter = 143 ; diff --git a/definitions/grib1/localConcepts/ecmf/shortName.def b/definitions/grib1/localConcepts/ecmf/shortName.def index f91795872..92c1dd09e 100644 --- a/definitions/grib1/localConcepts/ecmf/shortName.def +++ b/definitions/grib1/localConcepts/ecmf/shortName.def @@ -14375,7 +14375,7 @@ indicatorOfParameter = 206 ; } #10 metre wind speed anomaly -'10ua' = { +'10sia' = { table2Version = 171 ; indicatorOfParameter = 207 ; } @@ -14629,8 +14629,8 @@ table2Version = 172 ; indicatorOfParameter = 48 ; } -#Large-scale precipitation fraction -'~' = { +#Mean large-scale precipitation fraction +'mlspfr' = { table2Version = 172 ; indicatorOfParameter = 50 ; } @@ -14654,58 +14654,58 @@ table2Version = 172 ; indicatorOfParameter = 145 ; } -#Surface sensible heat flux -'~' = { +#Mean surface sensible heat flux +'msshfl' = { table2Version = 172 ; indicatorOfParameter = 146 ; } -#Surface latent heat flux -'~' = { +#Mean surface latent heat flux +'mslhfl' = { table2Version = 172 ; indicatorOfParameter = 147 ; } -#Surface net radiation -'~' = { +#Mean surface net radiation flux +'msnrf' = { table2Version = 172 ; indicatorOfParameter = 149 ; } -#Short-wave heating rate -'~' = { +#Mean short-wave heating rate +'mswhr' = { table2Version = 172 ; indicatorOfParameter = 153 ; } -#Long-wave heating rate -'~' = { +#Mean long-wave heating rate +'mlwhr' = { table2Version = 172 ; indicatorOfParameter = 154 ; } -#Surface solar radiation downwards -'~' = { +#Mean surface downward solar radiation flux +'msdsrf' = { table2Version = 172 ; indicatorOfParameter = 169 ; } -#Surface thermal radiation downwards -'~' = { +#Mean surface downward thermal radiation flux +'msdtrf' = { table2Version = 172 ; indicatorOfParameter = 175 ; } -#Surface solar radiation -'~' = { +#Mean surface net solar radiation flux +'msnsrf' = { table2Version = 172 ; indicatorOfParameter = 176 ; } -#Surface thermal radiation -'~' = { +#Mean surface net thermal radiation flux +'msntrf' = { table2Version = 172 ; indicatorOfParameter = 177 ; } -#Top solar radiation -'~' = { +#Mean top net solar radiation flux +'mtnsrf' = { table2Version = 172 ; indicatorOfParameter = 178 ; } -#Top thermal radiation -'~' = { +#Mean top net thermal radiation flux +'mtntrf' = { table2Version = 172 ; indicatorOfParameter = 179 ; } @@ -14744,8 +14744,8 @@ table2Version = 172 ; indicatorOfParameter = 197 ; } -#Runoff -'~' = { +#Mean runoff rate +'mrort' = { table2Version = 172 ; indicatorOfParameter = 205 ; } @@ -14819,8 +14819,8 @@ table2Version = 173 ; indicatorOfParameter = 142 ; } -#Convective precipitation anomaly -'~' = { +#Mean convective precipitation rate anomaly +'mcpra' = { table2Version = 173 ; indicatorOfParameter = 143 ; } diff --git a/definitions/grib1/localConcepts/ecmf/units.def b/definitions/grib1/localConcepts/ecmf/units.def index 8c9197dfd..1c8093d7b 100644 --- a/definitions/grib1/localConcepts/ecmf/units.def +++ b/definitions/grib1/localConcepts/ecmf/units.def @@ -14629,7 +14629,7 @@ table2Version = 172 ; indicatorOfParameter = 48 ; } -#Large-scale precipitation fraction +#Mean large-scale precipitation fraction '~' = { table2Version = 172 ; indicatorOfParameter = 50 ; @@ -14654,57 +14654,57 @@ table2Version = 172 ; indicatorOfParameter = 145 ; } -#Surface sensible heat flux +#Mean surface sensible heat flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 146 ; } -#Surface latent heat flux +#Mean surface latent heat flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 147 ; } -#Surface net radiation +#Mean surface net radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 149 ; } -#Short-wave heating rate +#Mean short-wave heating rate 'K s**-1' = { table2Version = 172 ; indicatorOfParameter = 153 ; } -#Long-wave heating rate +#Mean long-wave heating rate 'K s**-1' = { table2Version = 172 ; indicatorOfParameter = 154 ; } -#Surface solar radiation downwards +#Mean surface downward solar radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 169 ; } -#Surface thermal radiation downwards +#Mean surface downward thermal radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 175 ; } -#Surface solar radiation +#Mean surface net solar radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 176 ; } -#Surface thermal radiation +#Mean surface net thermal radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 177 ; } -#Top solar radiation +#Mean top net solar radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 178 ; } -#Top thermal radiation +#Mean top net thermal radiation flux 'W m**-2' = { table2Version = 172 ; indicatorOfParameter = 179 ; @@ -14744,7 +14744,7 @@ table2Version = 172 ; indicatorOfParameter = 197 ; } -#Runoff +#Mean runoff rate 'm s**-1' = { table2Version = 172 ; indicatorOfParameter = 205 ; @@ -14819,7 +14819,7 @@ table2Version = 173 ; indicatorOfParameter = 142 ; } -#Convective precipitation anomaly +#Mean convective precipitation rate anomaly 'm s**-1' = { table2Version = 173 ; indicatorOfParameter = 143 ; diff --git a/definitions/grib2/localConcepts/ecmf/cfVarName.def b/definitions/grib2/localConcepts/ecmf/cfVarName.def index 1e9c28427..9cbe41085 100644 --- a/definitions/grib2/localConcepts/ecmf/cfVarName.def +++ b/definitions/grib2/localConcepts/ecmf/cfVarName.def @@ -18583,7 +18583,7 @@ parameterNumber = 206 ; } #10 metre wind speed anomaly -'ua10' = { +'sia10' = { discipline = 192 ; parameterCategory = 171 ; parameterNumber = 207 ; @@ -18888,8 +18888,8 @@ parameterCategory = 172 ; parameterNumber = 48 ; } -#Large-scale precipitation fraction -'p50.172' = { +#Mean large-scale precipitation fraction +'mlspfr' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 50 ; @@ -18918,68 +18918,68 @@ parameterCategory = 172 ; parameterNumber = 145 ; } -#Surface sensible heat flux -'p146.172' = { +#Mean surface sensible heat flux +'msshfl' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 146 ; } -#Surface latent heat flux -'p147.172' = { +#Mean surface latent heat flux +'mslhfl' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 147 ; } -#Surface net radiation -'p149.172' = { +#Mean surface net radiation flux +'msnrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 149 ; } -#Short-wave heating rate -'p153.172' = { +#Mean short-wave heating rate +'mswhr' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 153 ; } -#Long-wave heating rate -'p154.172' = { +#Mean long-wave heating rate +'mlwhr' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 154 ; } -#Surface solar radiation downwards -'p169.172' = { +#Mean surface downward solar radiation flux +'msdsrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 169 ; } -#Surface thermal radiation downwards -'p175.172' = { +#Mean surface downward thermal radiation flux +'msdtrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 175 ; } -#Surface solar radiation -'p176.172' = { +#Mean surface net solar radiation flux +'msnsrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 176 ; } -#Surface thermal radiation -'p177.172' = { +#Mean surface net thermal radiation flux +'msntrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 177 ; } -#Top solar radiation -'p178.172' = { +#Mean top net solar radiation flux +'mtnsrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 178 ; } -#Top thermal radiation -'p179.172' = { +#Mean top net thermal radiation flux +'mtntrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 179 ; @@ -19026,8 +19026,8 @@ parameterCategory = 172 ; parameterNumber = 197 ; } -#Runoff -'p205.172' = { +#Mean runoff rate +'mrort' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 205 ; @@ -19116,8 +19116,8 @@ parameterCategory = 173 ; parameterNumber = 142 ; } -#Convective precipitation anomaly -'p143.173' = { +#Mean convective precipitation rate anomaly +'mcpra' = { discipline = 192 ; parameterCategory = 173 ; parameterNumber = 143 ; diff --git a/definitions/grib2/localConcepts/ecmf/name.def b/definitions/grib2/localConcepts/ecmf/name.def index 7c803d7a1..d75472401 100644 --- a/definitions/grib2/localConcepts/ecmf/name.def +++ b/definitions/grib2/localConcepts/ecmf/name.def @@ -18888,8 +18888,8 @@ parameterCategory = 172 ; parameterNumber = 48 ; } -#Large-scale precipitation fraction -'Large-scale precipitation fraction' = { +#Mean large-scale precipitation fraction +'Mean large-scale precipitation fraction' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 50 ; @@ -18918,68 +18918,68 @@ parameterCategory = 172 ; parameterNumber = 145 ; } -#Surface sensible heat flux -'Surface sensible heat flux' = { +#Mean surface sensible heat flux +'Mean surface sensible heat flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 146 ; } -#Surface latent heat flux -'Surface latent heat flux' = { +#Mean surface latent heat flux +'Mean surface latent heat flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 147 ; } -#Surface net radiation -'Surface net radiation' = { +#Mean surface net radiation flux +'Mean surface net radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 149 ; } -#Short-wave heating rate -'Short-wave heating rate' = { +#Mean short-wave heating rate +'Mean short-wave heating rate' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 153 ; } -#Long-wave heating rate -'Long-wave heating rate' = { +#Mean long-wave heating rate +'Mean long-wave heating rate' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 154 ; } -#Surface solar radiation downwards -'Surface solar radiation downwards' = { +#Mean surface downward solar radiation flux +'Mean surface downward solar radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 169 ; } -#Surface thermal radiation downwards -'Surface thermal radiation downwards' = { +#Mean surface downward thermal radiation flux +'Mean surface downward thermal radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 175 ; } -#Surface solar radiation -'Surface solar radiation' = { +#Mean surface net solar radiation flux +'Mean surface net solar radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 176 ; } -#Surface thermal radiation -'Surface thermal radiation' = { +#Mean surface net thermal radiation flux +'Mean surface net thermal radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 177 ; } -#Top solar radiation -'Top solar radiation' = { +#Mean top net solar radiation flux +'Mean top net solar radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 178 ; } -#Top thermal radiation -'Top thermal radiation' = { +#Mean top net thermal radiation flux +'Mean top net thermal radiation flux' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 179 ; @@ -19026,8 +19026,8 @@ parameterCategory = 172 ; parameterNumber = 197 ; } -#Runoff -'Runoff' = { +#Mean runoff rate +'Mean runoff rate' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 205 ; @@ -19116,8 +19116,8 @@ parameterCategory = 173 ; parameterNumber = 142 ; } -#Convective precipitation anomaly -'Convective precipitation anomaly' = { +#Mean convective precipitation rate anomaly +'Mean convective precipitation rate anomaly' = { discipline = 192 ; parameterCategory = 173 ; parameterNumber = 143 ; diff --git a/definitions/grib2/localConcepts/ecmf/paramId.def b/definitions/grib2/localConcepts/ecmf/paramId.def index 5d4a5eb47..043e71747 100644 --- a/definitions/grib2/localConcepts/ecmf/paramId.def +++ b/definitions/grib2/localConcepts/ecmf/paramId.def @@ -18888,7 +18888,7 @@ parameterCategory = 172 ; parameterNumber = 48 ; } -#Large-scale precipitation fraction +#Mean large-scale precipitation fraction '172050' = { discipline = 192 ; parameterCategory = 172 ; @@ -18918,67 +18918,67 @@ parameterCategory = 172 ; parameterNumber = 145 ; } -#Surface sensible heat flux +#Mean surface sensible heat flux '172146' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 146 ; } -#Surface latent heat flux +#Mean surface latent heat flux '172147' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 147 ; } -#Surface net radiation +#Mean surface net radiation flux '172149' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 149 ; } -#Short-wave heating rate +#Mean short-wave heating rate '172153' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 153 ; } -#Long-wave heating rate +#Mean long-wave heating rate '172154' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 154 ; } -#Surface solar radiation downwards +#Mean surface downward solar radiation flux '172169' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 169 ; } -#Surface thermal radiation downwards +#Mean surface downward thermal radiation flux '172175' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 175 ; } -#Surface solar radiation +#Mean surface net solar radiation flux '172176' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 176 ; } -#Surface thermal radiation +#Mean surface net thermal radiation flux '172177' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 177 ; } -#Top solar radiation +#Mean top net solar radiation flux '172178' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 178 ; } -#Top thermal radiation +#Mean top net thermal radiation flux '172179' = { discipline = 192 ; parameterCategory = 172 ; @@ -19026,7 +19026,7 @@ parameterCategory = 172 ; parameterNumber = 197 ; } -#Runoff +#Mean runoff rate '172205' = { discipline = 192 ; parameterCategory = 172 ; @@ -19116,7 +19116,7 @@ parameterCategory = 173 ; parameterNumber = 142 ; } -#Convective precipitation anomaly +#Mean convective precipitation rate anomaly '173143' = { discipline = 192 ; parameterCategory = 173 ; diff --git a/definitions/grib2/localConcepts/ecmf/shortName.def b/definitions/grib2/localConcepts/ecmf/shortName.def index c45131dd7..49501d40d 100644 --- a/definitions/grib2/localConcepts/ecmf/shortName.def +++ b/definitions/grib2/localConcepts/ecmf/shortName.def @@ -18583,7 +18583,7 @@ parameterNumber = 206 ; } #10 metre wind speed anomaly -'10ua' = { +'10sia' = { discipline = 192 ; parameterCategory = 171 ; parameterNumber = 207 ; @@ -18888,8 +18888,8 @@ parameterCategory = 172 ; parameterNumber = 48 ; } -#Large-scale precipitation fraction -'~' = { +#Mean large-scale precipitation fraction +'mlspfr' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 50 ; @@ -18918,68 +18918,68 @@ parameterCategory = 172 ; parameterNumber = 145 ; } -#Surface sensible heat flux -'~' = { +#Mean surface sensible heat flux +'msshfl' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 146 ; } -#Surface latent heat flux -'~' = { +#Mean surface latent heat flux +'mslhfl' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 147 ; } -#Surface net radiation -'~' = { +#Mean surface net radiation flux +'msnrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 149 ; } -#Short-wave heating rate -'~' = { +#Mean short-wave heating rate +'mswhr' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 153 ; } -#Long-wave heating rate -'~' = { +#Mean long-wave heating rate +'mlwhr' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 154 ; } -#Surface solar radiation downwards -'~' = { +#Mean surface downward solar radiation flux +'msdsrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 169 ; } -#Surface thermal radiation downwards -'~' = { +#Mean surface downward thermal radiation flux +'msdtrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 175 ; } -#Surface solar radiation -'~' = { +#Mean surface net solar radiation flux +'msnsrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 176 ; } -#Surface thermal radiation -'~' = { +#Mean surface net thermal radiation flux +'msntrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 177 ; } -#Top solar radiation -'~' = { +#Mean top net solar radiation flux +'mtnsrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 178 ; } -#Top thermal radiation -'~' = { +#Mean top net thermal radiation flux +'mtntrf' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 179 ; @@ -19026,8 +19026,8 @@ parameterCategory = 172 ; parameterNumber = 197 ; } -#Runoff -'~' = { +#Mean runoff rate +'mrort' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 205 ; @@ -19116,8 +19116,8 @@ parameterCategory = 173 ; parameterNumber = 142 ; } -#Convective precipitation anomaly -'~' = { +#Mean convective precipitation rate anomaly +'mcpra' = { discipline = 192 ; parameterCategory = 173 ; parameterNumber = 143 ; diff --git a/definitions/grib2/localConcepts/ecmf/units.def b/definitions/grib2/localConcepts/ecmf/units.def index e8bcf332e..3ffe24ed1 100644 --- a/definitions/grib2/localConcepts/ecmf/units.def +++ b/definitions/grib2/localConcepts/ecmf/units.def @@ -18888,7 +18888,7 @@ parameterCategory = 172 ; parameterNumber = 48 ; } -#Large-scale precipitation fraction +#Mean large-scale precipitation fraction '~' = { discipline = 192 ; parameterCategory = 172 ; @@ -18918,67 +18918,67 @@ parameterCategory = 172 ; parameterNumber = 145 ; } -#Surface sensible heat flux +#Mean surface sensible heat flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 146 ; } -#Surface latent heat flux +#Mean surface latent heat flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 147 ; } -#Surface net radiation +#Mean surface net radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 149 ; } -#Short-wave heating rate +#Mean short-wave heating rate 'K s**-1' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 153 ; } -#Long-wave heating rate +#Mean long-wave heating rate 'K s**-1' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 154 ; } -#Surface solar radiation downwards +#Mean surface downward solar radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 169 ; } -#Surface thermal radiation downwards +#Mean surface downward thermal radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 175 ; } -#Surface solar radiation +#Mean surface net solar radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 176 ; } -#Surface thermal radiation +#Mean surface net thermal radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 177 ; } -#Top solar radiation +#Mean top net solar radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; parameterNumber = 178 ; } -#Top thermal radiation +#Mean top net thermal radiation flux 'W m**-2' = { discipline = 192 ; parameterCategory = 172 ; @@ -19026,7 +19026,7 @@ parameterCategory = 172 ; parameterNumber = 197 ; } -#Runoff +#Mean runoff rate 'm s**-1' = { discipline = 192 ; parameterCategory = 172 ; @@ -19116,7 +19116,7 @@ parameterCategory = 173 ; parameterNumber = 142 ; } -#Convective precipitation anomaly +#Mean convective precipitation rate anomaly 'm s**-1' = { discipline = 192 ; parameterCategory = 173 ; diff --git a/definitions/grib2/template.3.shape_of_the_earth.def b/definitions/grib2/template.3.shape_of_the_earth.def index 56c664440..bf906f796 100755 --- a/definitions/grib2/template.3.shape_of_the_earth.def +++ b/definitions/grib2/template.3.shape_of_the_earth.def @@ -5,7 +5,7 @@ codetable[1] shapeOfTheEarth ('3.2.table',masterDir,localDir) : dump; # Scale factor of radius of spherical earth unsigned[1] scaleFactorOfRadiusOfSphericalEarth = missing() : can_be_missing, edition_specific; -# Scaled value of radius of spherical earth +# Scaled value of radius of spherical earth (in metres) unsigned[4] scaledValueOfRadiusOfSphericalEarth = missing(): can_be_missing, edition_specific; # Scale factor of major axis of oblate spheroid earth diff --git a/fortran/CMakeLists.txt b/fortran/CMakeLists.txt index 119f09c2c..c0099c342 100644 --- a/fortran/CMakeLists.txt +++ b/fortran/CMakeLists.txt @@ -44,6 +44,15 @@ if( HAVE_FORTRAN ) SOURCES grib_fortran.c grib_f90.f90 eccodes_f90.f90 grib_kinds.h GENERATED grib_f90.f90 eccodes_f90.f90 LIBS eccodes ) + if( DEFINED ecbuild_VERSION AND NOT ${ecbuild_VERSION} VERSION_LESS 3.1 ) + # Installed module directory is not in the PUBLIC INCLUDES! + target_include_directories( eccodes_f90 PUBLIC $ ) + + # NOTE: When eccodes accepts ecbuild 3.0 as minimum requirement, + # this should instead be written inside the ecbuild_add_library macro with: + # PUBLIC_INCLUDES $ + endif() + add_custom_command( TARGET eccodes_f90 POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/include COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_Fortran_MODULE_DIRECTORY}/${CMAKE_CFG_INTDIR}/eccodes.mod ${CMAKE_BINARY_DIR}/include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c85c9c48..7d43d4995 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -434,14 +434,13 @@ endif() ecbuild_add_library(TARGET eccodes SOURCES grib_api_version.c # griby.c gribl.c - ${grib_api_srcs} + ${grib_api_srcs} GENERATED grib_api_version.c LIBS ${ECCODES_EXTRA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CMATH_LIBRARIES} - TEMPLATES ${grib_api_extra_srcs}) - - -install( FILES grib_api.h eccodes.h eccodes_windef.h DESTINATION ${INSTALL_INCLUDE_DIR} ) -install( FILES ${CMAKE_CURRENT_BINARY_DIR}/eccodes_version.h DESTINATION ${INSTALL_INCLUDE_DIR} ) - - - + TEMPLATES ${grib_api_extra_srcs} + INSTALL_HEADERS_LIST + grib_api.h + eccodes.h + eccodes_windef.h + ${CMAKE_CURRENT_BINARY_DIR}/eccodes_version.h + ${PROJECT_BINARY_DIR}/eccodes_config.h ) diff --git a/src/action_class_section.c b/src/action_class_section.c index 7fb102a80..56a28dcc0 100644 --- a/src/action_class_section.c +++ b/src/action_class_section.c @@ -79,14 +79,14 @@ static void init_class(grib_action_class* c) /* new GCC compiler v4.5.0 complains function is defined but not used*/ static void check_sections(grib_section *s,grib_handle* h) { - grib_accessor *a = s?s->block->first:NULL; - if(s) Assert(s->h == h); - while(a) - { - Assert(grib_handle_of_accessor(a) == h); - check_sections(a->sub_section,h); - a = a->next; - } + grib_accessor *a = s?s->block->first:NULL; + if(s) Assert(s->h == h); + while(a) + { + Assert(grib_handle_of_accessor(a) == h); + check_sections(a->sub_section,h); + a = a->next; + } } #endif diff --git a/src/grib_accessor.c b/src/grib_accessor.c index 01d11fc46..023390bfd 100644 --- a/src/grib_accessor.c +++ b/src/grib_accessor.c @@ -647,12 +647,12 @@ const char* grib_get_type_name(int type) { switch(type) { - case GRIB_TYPE_LONG: return "long"; break; - case GRIB_TYPE_STRING: return "string"; break; - case GRIB_TYPE_BYTES: return "bytes"; break; - case GRIB_TYPE_DOUBLE: return "double"; break; - case GRIB_TYPE_LABEL: return "label"; break; - case GRIB_TYPE_SECTION: return "section"; break; + case GRIB_TYPE_LONG: return "long"; + case GRIB_TYPE_STRING: return "string"; + case GRIB_TYPE_BYTES: return "bytes"; + case GRIB_TYPE_DOUBLE: return "double"; + case GRIB_TYPE_LABEL: return "label"; + case GRIB_TYPE_SECTION: return "section"; } return "unknown"; } @@ -756,14 +756,14 @@ int grib_accessor_has_attributes(grib_accessor* a) return a->attributes[0] ? 1 : 0 ; } -grib_accessor* grib_accessor_get_attribute(grib_accessor* a,const char* name) +grib_accessor* grib_accessor_get_attribute(grib_accessor* a, const char* name) { int index=0; - char* p=0; + const char* p=0; char* basename=NULL; - char* attribute_name=NULL; + const char* attribute_name=NULL; grib_accessor* acc=NULL; - p=(char*)name; + p=name; while ( *(p+1) != '\0' && ( *p != '-' || *(p+1)!= '>' ) ) p++; if (*(p+1) == '\0') { return _grib_accessor_get_attribute(a,name,&index); diff --git a/src/grib_accessor_class_ascii.c b/src/grib_accessor_class_ascii.c index fe09b6c23..386004548 100644 --- a/src/grib_accessor_class_ascii.c +++ b/src/grib_accessor_class_ascii.c @@ -137,156 +137,159 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len , grib_arguments* arg ) { - a->length = len; - Assert(a->length>=0); + a->length = len; + Assert(a->length>=0); } -static int value_count(grib_accessor* a,long* count){ - *count=1; - return 0; +static int value_count(grib_accessor* a,long* count) +{ + *count=1; + return 0; } -static size_t string_length(grib_accessor* a){ - return a->length; +static size_t string_length(grib_accessor* a) +{ + return a->length; } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_string(dumper,a,NULL); + grib_dump_string(dumper,a,NULL); } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_STRING; +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; } static int unpack_string(grib_accessor* a, char* val, size_t *len) { - int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); + int i = 0; + grib_handle* hand = grib_handle_of_accessor(a); - if(len[0] < (a->length+1)) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } + if(len[0] < (a->length+1)) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } - for ( i = 0; i < a->length; i++) - val[i] = hand->buffer->data[a->offset+i]; - val[i] = 0; - len[0] = i; - return GRIB_SUCCESS; + for ( i = 0; i < a->length; i++) + val[i] = hand->buffer->data[a->offset+i]; + val[i] = 0; + len[0] = i; + return GRIB_SUCCESS; } static int pack_string(grib_accessor* a, const char* val, size_t *len) { - int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - if(len[0] > (a->length)+1) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); - len[0] = 0; - return GRIB_BUFFER_TOO_SMALL; - } + int i = 0; + grib_handle* hand = grib_handle_of_accessor(a); + if(len[0] > (a->length)+1) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); + len[0] = 0; + return GRIB_BUFFER_TOO_SMALL; + } - for ( i = 0; i < a->length; i++) - { - if( i < len[0] ) - hand->buffer->data[a->offset+i] = val[i]; - else - hand->buffer->data[a->offset+i] = 0; - } + for ( i = 0; i < a->length; i++) + { + if( i < len[0] ) + hand->buffer->data[a->offset+i] = val[i]; + else + hand->buffer->data[a->offset+i] = 0; + } - return GRIB_SUCCESS; + return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_long(grib_accessor* a, const long* v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); + return GRIB_NOT_IMPLEMENTED; } -static int pack_double(grib_accessor* a, const double*v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_double(grib_accessor* a, const double*v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); + return GRIB_NOT_IMPLEMENTED; } +static int unpack_long (grib_accessor* a, long* v, size_t *len) +{ + char val[1024]={0,}; + size_t l = sizeof(val); + size_t i =0; + char *last = NULL; + int err=grib_unpack_string (a , val, &l); -static int unpack_long (grib_accessor* a, long* v, size_t *len){ + if (err) return err; - char val[1024]={0,}; - size_t l = sizeof(val); - size_t i =0; - char *last = NULL; - int err=grib_unpack_string (a , val, &l); + i=0; + while ( val[i]==' ' && val[i]!=0 && icontext,GRIB_LOG_DEBUG, " Casting string %s to long", a->name); - return GRIB_SUCCESS; - -} - -static int unpack_double (grib_accessor* a, double*v, size_t *len){ - char val[1024]; - size_t l = sizeof(val); - char *last = NULL; - grib_unpack_string (a , val, &l); - - *v = strtod(val,&last); - - if(*last == 0) - { grib_context_log(a->context,GRIB_LOG_DEBUG, " Casting string %s to long", a->name); return GRIB_SUCCESS; - } - - return GRIB_NOT_IMPLEMENTED; } +static int unpack_double (grib_accessor* a, double*v, size_t *len) +{ + char val[1024]; + size_t l = sizeof(val); + char *last = NULL; + grib_unpack_string (a , val, &l); -static int compare(grib_accessor* a,grib_accessor* b) { - int retval=0; - char *aval=0; - char *bval=0; - int err=0; + *v = strtod(val,&last); - size_t alen = 0; - size_t blen = 0; - long count=0; + if(*last == 0) + { + grib_context_log(a->context,GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + return GRIB_SUCCESS; + } - err=grib_value_count(a,&count); - if (err) return err; - alen=count; - - err=grib_value_count(b,&count); - if (err) return err; - blen=count; - - if (alen != blen) return GRIB_COUNT_MISMATCH; - - aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); - bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); - - grib_unpack_string(a,aval,&alen); - grib_unpack_string(b,bval,&blen); - - retval = GRIB_SUCCESS; - if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; - - grib_context_free(a->context,aval); - grib_context_free(b->context,bval); - - return retval; + return GRIB_NOT_IMPLEMENTED; } +static int compare(grib_accessor* a,grib_accessor* b) +{ + int retval=0; + char *aval=0; + char *bval=0; + int err=0; + + size_t alen = 0; + size_t blen = 0; + long count=0; + + err=grib_value_count(a,&count); + if (err) return err; + alen=count; + + err=grib_value_count(b,&count); + if (err) return err; + blen=count; + + if (alen != blen) return GRIB_COUNT_MISMATCH; + + aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); + bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); + + grib_unpack_string(a,aval,&alen); + grib_unpack_string(b,bval,&blen); + + retval = GRIB_SUCCESS; + if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; + + grib_context_free(a->context,aval); + grib_context_free(b->context,bval); + + return retval; +} diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index 9747a0eab..fb121ba7e 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -368,7 +368,7 @@ static void tableB_override_dump(grib_accessor_bufr_data_array *self) ++i; } } -*/ + */ #define DYN_ARRAY_SIZE_INIT 1000 /* Initial size for grib_iarray_new and grib_darray_new */ #define DYN_ARRAY_SIZE_INCR 1000 /* Increment size for grib_iarray_new and grib_darray_new */ @@ -631,7 +631,7 @@ static grib_darray* decode_double_array(grib_context* c,unsigned char* data,long localReference=(long)lval+modifiedReference; localWidth=grib_decode_unsigned_long(data,pos,6); grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tlocalWidth=%ld",localWidth); - ret=grib_darray_new(c,DYN_ARRAY_SIZE_INIT,DYN_ARRAY_SIZE_INCR); + ret=grib_darray_new(c,self->numberOfSubsets,50); if (localWidth) { CHECK_END_DATA_RETURN(c, self, localWidth*self->numberOfSubsets, NULL); if (*err) { @@ -2139,7 +2139,7 @@ static int is_bitmap_start_descriptor(grib_accessors_list* al, int* err) static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_accessors_list* bitmapStart, int bitmapSize) { int i = 0, ret = 0; - printf("ECCODES DEBUG: bitmap_init: bitmapSize=%d\n", bitmapSize); + fprintf(stderr, "ECCODES DEBUG: bitmap_init: bitmapSize=%d\n", bitmapSize); bitmap->cursor=bitmapStart->next; bitmap->referredElement=bitmapStart; @@ -2156,7 +2156,7 @@ static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_acce for (i=1;ireferredElement) { - printf("ECCODES DEBUG:\t bitmap_init: i=%d |%s|\n", i,bitmap->referredElement->accessor->name); + fprintf(stderr, "ECCODES DEBUG:\t bitmap_init: i=%d |%s|\n", i,bitmap->referredElement->accessor->name); bitmap->referredElement=bitmap->referredElement->prev; } } @@ -2696,7 +2696,7 @@ static int process_elements(grib_accessor* a,int flag,long onlySubset,long start } if (flag!=PROCESS_ENCODE) { - self->numericValues=grib_vdarray_new(c,100,100); + self->numericValues=grib_vdarray_new(c,1000,1000); self->stringValues=grib_vsarray_new(c,10,10); if (self->elementsDescriptorsIndex) grib_viarray_delete(c,self->elementsDescriptorsIndex); diff --git a/src/grib_accessor_class_data_g1complex_packing.c b/src/grib_accessor_class_data_g1complex_packing.c index d73f57664..e68a407c6 100644 --- a/src/grib_accessor_class_data_g1complex_packing.c +++ b/src/grib_accessor_class_data_g1complex_packing.c @@ -169,98 +169,95 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long v, grib_arguments* args) { - grib_accessor_data_g1complex_packing *self =(grib_accessor_data_g1complex_packing*)a; - self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->N = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->precision = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->edition=1; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - } - + grib_accessor_data_g1complex_packing *self =(grib_accessor_data_g1complex_packing*)a; + self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->N = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->precision = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->edition=1; + a->flags |= GRIB_ACCESSOR_FLAG_DATA; +} static int pack_double(grib_accessor* a, const double* val, size_t *len) { - grib_accessor_data_g1complex_packing* self = - (grib_accessor_data_g1complex_packing*)a; - int ret = GRIB_SUCCESS; - long seclen=0; - long sub_j= 0; - long sub_k= 0; - long sub_m= 0; - long n= 0; - long half_byte= 0; - long bits_per_value =0; - size_t buflen =0; - grib_context* c=a->context; - grib_handle* h=grib_handle_of_accessor(a); - char* ieee_packing_s=NULL; - char* packingType_s=NULL; - char* precision_s=NULL; + grib_accessor_data_g1complex_packing* self = + (grib_accessor_data_g1complex_packing*)a; + int ret = GRIB_SUCCESS; + long seclen=0; + long sub_j= 0; + long sub_k= 0; + long sub_m= 0; + long n= 0; + long half_byte= 0; + long bits_per_value =0; + size_t buflen =0; + grib_context* c=a->context; + grib_handle* h=grib_handle_of_accessor(a); + char* ieee_packing_s=NULL; + char* packingType_s=NULL; + char* precision_s=NULL; - grib_accessor_class* super = *(a->cclass->super); + grib_accessor_class* super = *(a->cclass->super); + if (*len ==0) return GRIB_NO_VALUES; - if (*len ==0) return GRIB_NO_VALUES; + if (c->ieee_packing && self->ieee_packing) { + long precision=c->ieee_packing==32 ? 1 : 2; + size_t lenstr=strlen(self->ieee_packing); - if (c->ieee_packing && self->ieee_packing) { - long precision=c->ieee_packing==32 ? 1 : 2; - size_t lenstr=strlen(self->ieee_packing); - - packingType_s=grib_context_strdup(c,self->packingType); - ieee_packing_s=grib_context_strdup(c,self->ieee_packing); - precision_s=grib_context_strdup(c,self->precision); - - grib_set_string(h,packingType_s,ieee_packing_s,&lenstr); - grib_set_long(h,precision_s,precision); - - grib_context_free(c,packingType_s); - grib_context_free(c,ieee_packing_s); - grib_context_free(c,precision_s); - return grib_set_double_array(h,"values",val,*len); - } + packingType_s=grib_context_strdup(c,self->packingType); + ieee_packing_s=grib_context_strdup(c,self->ieee_packing); + precision_s=grib_context_strdup(c,self->precision); - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_j,&sub_j)) != GRIB_SUCCESS) - return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_k,&sub_k)) != GRIB_SUCCESS) - return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_m,&sub_m)) != GRIB_SUCCESS) - return ret; + grib_set_string(h,packingType_s,ieee_packing_s,&lenstr); + grib_set_long(h,precision_s,precision); - self->dirty=1; + grib_context_free(c,packingType_s); + grib_context_free(c,ieee_packing_s); + grib_context_free(c,precision_s); + return grib_set_double_array(h,"values",val,*len); + } - Assert ((sub_j== sub_k) && (sub_m== sub_j)); + if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_j,&sub_j)) != GRIB_SUCCESS) + return ret; + if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_k,&sub_k)) != GRIB_SUCCESS) + return ret; + if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_m,&sub_m)) != GRIB_SUCCESS) + return ret; - ret = super->pack_double(a,val,len); + self->dirty=1; - if(ret == GRIB_SUCCESS){ + Assert ((sub_j== sub_k) && (sub_m== sub_j)); + + ret = super->pack_double(a,val,len); + + if(ret == GRIB_SUCCESS){ n = a->offset + 4*((sub_k+1)*(sub_k+2)); #if 1 - /* Octet number starts from beginning of message but shouldn't */ - if((ret = grib_set_long_internal(grib_handle_of_accessor(a),self->N,n)) != GRIB_SUCCESS) - return ret; + /* Octet number starts from beginning of message but shouldn't */ + if((ret = grib_set_long_internal(grib_handle_of_accessor(a),self->N,n)) != GRIB_SUCCESS) + return ret; #else - ret = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetsection,&offsetsection); - if(ret != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a),self->N,n-offsetsection)) - != GRIB_SUCCESS) return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetsection,&offsetsection); + if(ret != GRIB_SUCCESS) return ret; + if((ret = grib_set_long_internal(grib_handle_of_accessor(a),self->N,n-offsetsection)) + != GRIB_SUCCESS) return ret; #endif - ret = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value); - if(ret != GRIB_SUCCESS) return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value); + if(ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a),self->seclen,&seclen); - if(ret != GRIB_SUCCESS) return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a),self->seclen,&seclen); + if(ret != GRIB_SUCCESS) return ret; - buflen = 32*(sub_k+1)*(sub_k+2)+(*len-(sub_k+1)*(sub_k+2))*bits_per_value+18*8; - half_byte = seclen*8-buflen; - if (a->context->debug==-1) { - printf("ECCODES DEBUG: half_byte=%ld\n",half_byte); - } + buflen = 32*(sub_k+1)*(sub_k+2)+(*len-(sub_k+1)*(sub_k+2))*bits_per_value+18*8; + half_byte = seclen*8-buflen; + if (a->context->debug==-1) { + fprintf(stderr, "ECCODES DEBUG: half_byte=%ld\n",half_byte); + } - ret = grib_set_long_internal(grib_handle_of_accessor(a),self->half_byte, half_byte); - if(ret != GRIB_SUCCESS) return ret; - } - return ret; + ret = grib_set_long_internal(grib_handle_of_accessor(a),self->half_byte, half_byte); + if(ret != GRIB_SUCCESS) return ret; + } + return ret; } - diff --git a/src/grib_accessor_class_data_jpeg2000_packing.c b/src/grib_accessor_class_data_jpeg2000_packing.c index 40a786e7e..787c89a77 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.c +++ b/src/grib_accessor_class_data_jpeg2000_packing.c @@ -204,11 +204,11 @@ static void init(grib_accessor* a,const long v, grib_arguments* args) if (a->context->debug==-1) { switch (self->jpeg_lib) { case 0: - printf("ECCODES DEBUG jpeg2000_packing: jpeg_lib not set!\n"); break; + fprintf(stderr, "ECCODES DEBUG jpeg2000_packing: jpeg_lib not set!\n"); break; case JASPER_LIB: - printf("ECCODES DEBUG jpeg2000_packing: using JASPER_LIB\n"); break; + fprintf(stderr, "ECCODES DEBUG jpeg2000_packing: using JASPER_LIB\n"); break; case OPENJPEG_LIB: - printf("ECCODES DEBUG jpeg2000_packing: using OPENJPEG_LIB\n"); break; + fprintf(stderr, "ECCODES DEBUG jpeg2000_packing: using OPENJPEG_LIB\n"); break; default: Assert(0); break; } diff --git a/src/grib_accessor_class_from_scale_factor_scaled_value.c b/src/grib_accessor_class_from_scale_factor_scaled_value.c index 49d2b5004..484c4a60e 100644 --- a/src/grib_accessor_class_from_scale_factor_scaled_value.c +++ b/src/grib_accessor_class_from_scale_factor_scaled_value.c @@ -139,56 +139,63 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; - int n = 0; + grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; + int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); - self->scaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->scaledValue = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->scaleFactor = grib_arguments_get_name(hand,c,n++); + self->scaledValue = grib_arguments_get_name(hand,c,n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } static int unpack_double(grib_accessor* a, double* val, size_t *len) { - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; - int ret = 0; - long scaleFactor=0; - long scaledValue=0; + grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; + int ret = 0; + long scaleFactor=0; + long scaledValue=0; + grib_handle* hand = grib_handle_of_accessor(a); - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaleFactor,&scaleFactor)) != GRIB_SUCCESS) - return ret; + if((ret = grib_get_long_internal(hand, self->scaleFactor,&scaleFactor)) != GRIB_SUCCESS) + return ret; + /* ECC-966: If scale factor is missing, print error and treat it as zero (as a fallback) */ + if (grib_is_missing(hand, self->scaleFactor, &ret) && ret == GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "unpack_double for %s: %s is missing! Setting it to zero", a->name, self->scaleFactor); + scaleFactor = 0; + } - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaledValue,&scaledValue)) != GRIB_SUCCESS) - return ret; + if((ret = grib_get_long_internal(hand, self->scaledValue,&scaledValue)) != GRIB_SUCCESS) + return ret; - *val=scaledValue; + *val=scaledValue; - /* The formula is: - * real_value = scaled_value / pow(10, scale_factor) - */ - while (scaleFactor <0) {*val*=10;scaleFactor++;} - while (scaleFactor >0) {*val/=10;scaleFactor--;} + /* The formula is: + * real_value = scaled_value / pow(10, scale_factor) + */ + while (scaleFactor <0) {*val*=10;scaleFactor++;} + while (scaleFactor >0) {*val/=10;scaleFactor--;} - if (ret == GRIB_SUCCESS) *len = 1; + if (ret == GRIB_SUCCESS) *len = 1; - return ret; + return ret; } static int is_missing(grib_accessor* a) { - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; - int ret = 0; - long scaleFactor=0; - long scaledValue=0; + grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; + int ret = 0; + long scaleFactor=0; + long scaledValue=0; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaleFactor,&scaleFactor)) - != GRIB_SUCCESS) - return ret; + if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaleFactor,&scaleFactor)) + != GRIB_SUCCESS) + return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaledValue,&scaledValue)) - != GRIB_SUCCESS) - return ret; + if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaledValue,&scaledValue)) + != GRIB_SUCCESS) + return ret; - return ((scaleFactor == GRIB_MISSING_LONG) | (scaledValue == GRIB_MISSING_LONG)); + return ((scaleFactor == GRIB_MISSING_LONG) | (scaledValue == GRIB_MISSING_LONG)); } - diff --git a/src/grib_accessor_class_g1end_of_interval_monthly.c b/src/grib_accessor_class_g1end_of_interval_monthly.c index a3f2f58f7..5d888fde8 100644 --- a/src/grib_accessor_class_g1end_of_interval_monthly.c +++ b/src/grib_accessor_class_g1end_of_interval_monthly.c @@ -137,114 +137,115 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - int n = 0; + grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; + int n = 0; - self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - self->number_of_elements=6; - self->v=(double*)grib_context_malloc(a->context, - sizeof(double)*self->number_of_elements); + self->number_of_elements=6; + self->v=(double*)grib_context_malloc(a->context, + sizeof(double)*self->number_of_elements); - a->length=0; - a->dirty=1; + a->length=0; + a->dirty=1; } static int unpack_double (grib_accessor* a, double* val, size_t *len) { - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - int ret = 0; - char verifyingMonth[7]={0,}; - size_t slen=7; - long year=0,month=0,date=0; - long mdays[]={31,28,31,30,31,30,31,31,30,31,30,31}; - long days=0; + grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; + int ret = 0; + char verifyingMonth[7]={0,}; + size_t slen=7; + long year=0,month=0,date=0; + long mdays[]={31,28,31,30,31,30,31,31,30,31,30,31}; + long days=0; - if (!a->dirty) return GRIB_SUCCESS; + if (!a->dirty) return GRIB_SUCCESS; - if((ret=grib_get_string(grib_handle_of_accessor(a),self->verifyingMonth,verifyingMonth,&slen)) - != GRIB_SUCCESS) return ret; + if((ret=grib_get_string(grib_handle_of_accessor(a),self->verifyingMonth,verifyingMonth,&slen)) + != GRIB_SUCCESS) return ret; - date=atoi(verifyingMonth); - year=date/100; - month=date-year*100; - if ( month == 2 ) { - days=28; - if (year%400 == 0 || ( year%4 == 0 && year%100 != 0) ) days=29; - } else days=mdays[month-1]; + date=atoi(verifyingMonth); + year=date/100; + month=date-year*100; + if ( month == 2 ) { + days=28; + if (year%400 == 0 || ( year%4 == 0 && year%100 != 0) ) days=29; + } else days=mdays[month-1]; - self->v[0]=year; - self->v[1]=month; - - self->v[2]=days; - self->v[3]=24; - self->v[4]=00; - self->v[5]=00; + self->v[0]=year; + self->v[1]=month; - a->dirty=0; + self->v[2]=days; + self->v[3]=24; + self->v[4]=00; + self->v[5]=00; - val[0]=self->v[0]; - val[1]=self->v[1]; - val[2]=self->v[2]; - val[3]=self->v[3]; - val[4]=self->v[4]; - val[5]=self->v[5]; + a->dirty=0; - return ret; + val[0]=self->v[0]; + val[1]=self->v[1]; + val[2]=self->v[2]; + val[3]=self->v[3]; + val[4]=self->v[4]; + val[5]=self->v[5]; + + return ret; } static int value_count(grib_accessor* a,long *count) { - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - *count=self->number_of_elements; - return 0; + grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; + *count=self->number_of_elements; + return 0; } static void destroy(grib_context* c,grib_accessor* a) { - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - grib_context_free(c,self->v); + grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; + grib_context_free(c,self->v); } -static int compare(grib_accessor* a, grib_accessor* b) { - int retval = GRIB_SUCCESS; - double *aval=0; - double *bval=0; +static int compare(grib_accessor* a, grib_accessor* b) +{ + int retval = GRIB_SUCCESS; + double *aval=0; + double *bval=0; - long count=0; - size_t alen = 0; - size_t blen = 0; - int err=0; + long count=0; + size_t alen = 0; + size_t blen = 0; + int err=0; - err=grib_value_count(a,&count); - if (err) return err; - alen=count; + err=grib_value_count(a,&count); + if (err) return err; + alen=count; - err=grib_value_count(b,&count); - if (err) return err; - blen=count; + err=grib_value_count(b,&count); + if (err) return err; + blen=count; - if (alen != blen) return GRIB_COUNT_MISMATCH; + if (alen != blen) return GRIB_COUNT_MISMATCH; - aval=(double*)grib_context_malloc(a->context,alen*sizeof(double)); - bval=(double*)grib_context_malloc(b->context,blen*sizeof(double)); + aval=(double*)grib_context_malloc(a->context,alen*sizeof(double)); + bval=(double*)grib_context_malloc(b->context,blen*sizeof(double)); - b->dirty=1; - a->dirty=1; + b->dirty=1; + a->dirty=1; - grib_unpack_double(a,aval,&alen); - grib_unpack_double(b,bval,&blen); + grib_unpack_double(a,aval,&alen); + grib_unpack_double(b,bval,&blen); - while (alen != 0) { - if (*bval != *aval) retval = GRIB_DOUBLE_VALUE_MISMATCH; - alen--; - } + while (alen != 0) { + if (*bval != *aval) retval = GRIB_DOUBLE_VALUE_MISMATCH; + alen--; + } - grib_context_free(a->context,aval); - grib_context_free(b->context,bval); + grib_context_free(a->context,aval); + grib_context_free(b->context,bval); - return retval; + return retval; } diff --git a/src/grib_accessor_class_g2_eps.c b/src/grib_accessor_class_g2_eps.c index ae996591a..979285bf7 100644 --- a/src/grib_accessor_class_g2_eps.c +++ b/src/grib_accessor_class_g2_eps.c @@ -175,6 +175,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len) static int pack_long(grib_accessor* a, const long* val, size_t *len) { grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; + grib_handle* hand=grib_handle_of_accessor(a); long productDefinitionTemplateNumber=-1; long productDefinitionTemplateNumberNew=-1; long type=-1; @@ -187,16 +188,16 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) int isInstant=0; long derivedForecast=-1; - if (grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber)!=GRIB_SUCCESS) + if (grib_get_long(hand, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber)!=GRIB_SUCCESS) return GRIB_SUCCESS; - grib_get_long(grib_handle_of_accessor(a), self->type,&type); - grib_get_long(grib_handle_of_accessor(a), self->stream,&stream); - grib_get_string(grib_handle_of_accessor(a), self->stepType,stepType,&slen); + grib_get_long(hand, self->type,&type); + grib_get_long(hand, self->stream,&stream); + grib_get_string(hand, self->stepType,stepType,&slen); if (!strcmp(stepType,"instant")) isInstant=1; - grib_get_long(grib_handle_of_accessor(a), "is_chemical",&chemical); - grib_get_long(grib_handle_of_accessor(a), "is_aerosol",&aerosol); - if (chemical && aerosol) { + grib_get_long(hand, "is_chemical",&chemical); + grib_get_long(hand, "is_aerosol",&aerosol); + if (chemical==1 && aerosol==1) { grib_context_log(a->context,GRIB_LOG_ERROR,"Parameter cannot be both chemical and aerosol!"); return GRIB_ENCODING_ERROR; } @@ -269,9 +270,9 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) } if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - grib_set_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew); + grib_set_long(hand, self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew); if (derivedForecast>=0) - grib_set_long(grib_handle_of_accessor(a), self->derivedForecast,derivedForecast); + grib_set_long(hand, self->derivedForecast,derivedForecast); } return 0; diff --git a/src/grib_accessor_class_g2grid.c b/src/grib_accessor_class_g2grid.c index ff1e9fc27..cca4bb776 100644 --- a/src/grib_accessor_class_g2grid.c +++ b/src/grib_accessor_class_g2grid.c @@ -156,16 +156,17 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; + grib_handle* hand = grib_handle_of_accessor(a); int n = 0; - self->latitude_first = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->longitude_first = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->latitude_last = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->longitude_last = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->i_increment = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->j_increment = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->basic_angle = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->sub_division = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->latitude_first = grib_arguments_get_name(hand,c,n++); + self->longitude_first = grib_arguments_get_name(hand,c,n++); + self->latitude_last = grib_arguments_get_name(hand,c,n++); + self->longitude_last = grib_arguments_get_name(hand,c,n++); + self->i_increment = grib_arguments_get_name(hand,c,n++); + self->j_increment = grib_arguments_get_name(hand,c,n++); + self->basic_angle = grib_arguments_get_name(hand,c,n++); + self->sub_division = grib_arguments_get_name(hand,c,n++); a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC | @@ -181,6 +182,7 @@ static int value_count(grib_accessor* a,long* count) static int unpack_double(grib_accessor* a, double* val, size_t *len) { grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret = 0; long basic_angle = 0; @@ -194,10 +196,10 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) return ret; } - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->basic_angle,&basic_angle)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->basic_angle,&basic_angle)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_division,&sub_division)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->sub_division,&sub_division)) != GRIB_SUCCESS) return ret; @@ -208,27 +210,27 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) basic_angle = 1; n = 0; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->latitude_first,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->latitude_first,&v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->longitude_first,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->longitude_first,&v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->latitude_last,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->latitude_last,&v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->longitude_last,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->longitude_last,&v[n++])) != GRIB_SUCCESS) return ret; if(!self->i_increment) v[n++] = GRIB_MISSING_LONG; else - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->i_increment,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->i_increment,&v[n++])) != GRIB_SUCCESS) return ret; if(!self->j_increment) v[n++] = GRIB_MISSING_LONG; else if(self->j_increment) - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->j_increment,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->j_increment,&v[n++])) != GRIB_SUCCESS) return ret; for(i = 0 ; i < n ; i++) @@ -314,6 +316,7 @@ static int trial(const double* val,long v[6],long* basic_angle,long* sub_divisio static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret; long v[6]; int n; @@ -334,7 +337,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } else if(trial(val,v,&basic_angle,&sub_division)) { - } else { @@ -351,33 +353,33 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) sub_division = GRIB_MISSING_LONG; } - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->basic_angle,basic_angle)) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->basic_angle,basic_angle)) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->sub_division,sub_division)) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->sub_division,sub_division)) != GRIB_SUCCESS) return ret; n = 0; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->latitude_first,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->latitude_first,v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->longitude_first,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->longitude_first,v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->latitude_last,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->latitude_last,v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->longitude_last,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->longitude_last,v[n++])) != GRIB_SUCCESS) return ret; if(!self->i_increment) n++; else - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->i_increment,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->i_increment,v[n++])) != GRIB_SUCCESS) return ret; if(!self->j_increment) n++; else - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->j_increment,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->j_increment,v[n++])) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; diff --git a/src/grib_accessor_class_local_definition.c b/src/grib_accessor_class_local_definition.c index 098c33070..952683fae 100644 --- a/src/grib_accessor_class_local_definition.c +++ b/src/grib_accessor_class_local_definition.c @@ -156,17 +156,18 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_local_definition* self = (grib_accessor_local_definition*)a; + grib_handle* hand=grib_handle_of_accessor(a); int n = 0; - self->grib2LocalSectionNumber = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->productDefinitionTemplateNumber = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->productDefinitionTemplateNumberInternal = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->type = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->stream = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->the_class = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->eps = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->stepType = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->derivedForecast = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->grib2LocalSectionNumber = grib_arguments_get_name(hand,c,n++); + self->productDefinitionTemplateNumber = grib_arguments_get_name(hand,c,n++); + self->productDefinitionTemplateNumberInternal = grib_arguments_get_name(hand,c,n++); + self->type = grib_arguments_get_name(hand,c,n++); + self->stream = grib_arguments_get_name(hand,c,n++); + self->the_class = grib_arguments_get_name(hand,c,n++); + self->eps = grib_arguments_get_name(hand,c,n++); + self->stepType = grib_arguments_get_name(hand,c,n++); + self->derivedForecast = grib_arguments_get_name(hand,c,n++); } static int unpack_long(grib_accessor* a, long* val, size_t *len) @@ -179,6 +180,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len) static int pack_long(grib_accessor* a, const long* val, size_t *len) { grib_accessor_local_definition* self = (grib_accessor_local_definition*)a; + grib_handle* hand=grib_handle_of_accessor(a); long productDefinitionTemplateNumber=-1; long productDefinitionTemplateNumberInternal=-1; long productDefinitionTemplateNumberNew=-1; @@ -199,25 +201,25 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) long derivedForecast=-1; long editionNumber = 0; - if (grib_get_long(grib_handle_of_accessor(a), "editionNumber", &editionNumber)==GRIB_SUCCESS) { + if (grib_get_long(hand, "editionNumber", &editionNumber)==GRIB_SUCCESS) { Assert(editionNumber != 1); } - if (grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber)!=GRIB_SUCCESS) + if (grib_get_long(hand, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber)!=GRIB_SUCCESS) tooEarly=1; - grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumberInternal,&productDefinitionTemplateNumberInternal); - grib_get_long(grib_handle_of_accessor(a), self->type,&type); - grib_get_long(grib_handle_of_accessor(a), self->stream,&stream); - grib_get_long(grib_handle_of_accessor(a), self->the_class,&the_class); - grib_get_long(grib_handle_of_accessor(a), self->eps,&eps); - grib_get_string(grib_handle_of_accessor(a), self->stepType,stepType,&slen); + grib_get_long(hand, self->productDefinitionTemplateNumberInternal,&productDefinitionTemplateNumberInternal); + grib_get_long(hand, self->type,&type); + grib_get_long(hand, self->stream,&stream); + grib_get_long(hand, self->the_class,&the_class); + grib_get_long(hand, self->eps,&eps); + grib_get_string(hand, self->stepType,stepType,&slen); if (!strcmp(stepType,"instant")) isInstant=1; - grib_get_long(grib_handle_of_accessor(a), self->grib2LocalSectionNumber,&grib2LocalSectionNumber); - grib_get_long(grib_handle_of_accessor(a), "is_chemical",&chemical); - grib_get_long(grib_handle_of_accessor(a), "is_chemical_distfn",&chemical_distfn); - grib_get_long(grib_handle_of_accessor(a), "is_aerosol",&aerosol); - grib_get_long(grib_handle_of_accessor(a), "is_aerosol_optical",&aerosol_optical); - if (chemical && aerosol) { + grib_get_long(hand, self->grib2LocalSectionNumber,&grib2LocalSectionNumber); + grib_get_long(hand, "is_chemical",&chemical); + grib_get_long(hand, "is_chemical_distfn",&chemical_distfn); + grib_get_long(hand, "is_aerosol",&aerosol); + grib_get_long(hand, "is_aerosol_optical",&aerosol_optical); + if (chemical==1 && aerosol==1) { grib_context_log(a->context,GRIB_LOG_ERROR,"Parameter cannot be both chemical and aerosol!"); return GRIB_ENCODING_ERROR; } @@ -383,14 +385,14 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { if (tooEarly) - grib_set_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumberInternal,productDefinitionTemplateNumberNew); + grib_set_long(hand, self->productDefinitionTemplateNumberInternal,productDefinitionTemplateNumberNew); else - grib_set_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew); + grib_set_long(hand, self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew); } if (derivedForecast>=0) - grib_set_long(grib_handle_of_accessor(a), self->derivedForecast,derivedForecast); + grib_set_long(hand, self->derivedForecast,derivedForecast); - grib_set_long(grib_handle_of_accessor(a), self->grib2LocalSectionNumber,*val); + grib_set_long(hand, self->grib2LocalSectionNumber,*val); return 0; } diff --git a/src/grib_accessor_class_number_of_points_gaussian.c b/src/grib_accessor_class_number_of_points_gaussian.c index 20bdcadbd..f2195a45e 100644 --- a/src/grib_accessor_class_number_of_points_gaussian.c +++ b/src/grib_accessor_class_number_of_points_gaussian.c @@ -565,7 +565,7 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t * if (get_number_of_data_values(h, &numDataValues) == GRIB_SUCCESS) { if (*val != numDataValues) { if (h->context->debug) - printf("ECCODES DEBUG number_of_points_gaussian: LEGACY MODE activated. " + fprintf(stderr, "ECCODES DEBUG number_of_points_gaussian: LEGACY MODE activated. " "Count(=%ld) changed to num values(=%ld)\n",*val,(long)numDataValues); *val = numDataValues; } diff --git a/src/grib_accessor_class_section.c b/src/grib_accessor_class_section.c index bd5476e35..ae855cd5a 100644 --- a/src/grib_accessor_class_section.c +++ b/src/grib_accessor_class_section.c @@ -132,96 +132,91 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ - - - static void init(grib_accessor* a, const long len , grib_arguments* arg ) { - a->sub_section = grib_section_create(grib_handle_of_accessor(a),a); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->sub_section = grib_section_create(grib_handle_of_accessor(a),a); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_section(dumper,a,a->sub_section->block); + grib_dump_section(dumper,a,a->sub_section->block); } static long byte_count(grib_accessor* a) { - if( !a->length || grib_handle_of_accessor(a)->loader ) - { - if(a->name[1]=='_') return 0; + if( !a->length || grib_handle_of_accessor(a)->loader ) + { + if(a->name[1]=='_') return 0; - /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ - grib_section_adjust_sizes(a->sub_section,grib_handle_of_accessor(a)->loader != NULL,0); - /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ - } + /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ + grib_section_adjust_sizes(a->sub_section,grib_handle_of_accessor(a)->loader != NULL,0); + /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ + } - - /* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */ - - return a->length; + /* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */ + return a->length; } static long next_offset(grib_accessor* a) { - return a->offset + byte_count(a); + return a->offset + byte_count(a); } static void destroy(grib_context* ct, grib_accessor* a) { - grib_section_delete(ct,a->sub_section); + grib_section_delete(ct,a->sub_section); } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_SECTION; +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_SECTION; } -static grib_section* sub_section(grib_accessor* a){ - /* grib_accessor_section* self = (grib_accessor_section*)a; */ - return a->sub_section; +static grib_section* sub_section(grib_accessor* a) +{ + /* grib_accessor_section* self = (grib_accessor_section*)a; */ + return a->sub_section; } - static void update_size(grib_accessor* a,size_t length) { + size_t size = 1; + long len = length; + Assert(length <= 0x7fffffff); + if(a->sub_section->aclength) + { + int e=grib_pack_long(a->sub_section->aclength,&len,&size); + Assert( e == GRIB_SUCCESS); + printf("update_length %s %ld %ld\n",a->sub_section->aclength->name, + (long)a->sub_section->aclength->offset, + (long)a->sub_section->aclength->length - size_t size = 1; - long len = length; - Assert(length <= 0x7fffffff); - if(a->sub_section->aclength) - { - int e=grib_pack_long(a->sub_section->aclength,&len,&size); - Assert( e == GRIB_SUCCESS); - printf("update_length %s %ld %ld\n",a->sub_section->aclength->name, - (long)a->sub_section->aclength->offset, - (long)a->sub_section->aclength->length + ); + } - ); - } + a->sub_section->length = a->length = length; + a->sub_section->padding = 0; - a->sub_section->length = a->length = length; - a->sub_section->padding = 0; + printf("update_size %s %ld\n",a->name,a->length); - printf("update_size %s %ld\n",a->name,a->length); - - Assert(a->length>=0); + Assert(a->length>=0); } -static grib_accessor* next(grib_accessor* a,int explore) { - grib_accessor* next=NULL; - if (explore) { - next=a->sub_section->block->first; - if (!next) next=a->next; - } else { - next=a->next; - } - if (!next) { - if (a->parent->owner) - next=a->parent->owner->cclass->next(a->parent->owner,0); - } - return next; +static grib_accessor* next(grib_accessor* a,int explore) +{ + grib_accessor* next=NULL; + if (explore) { + next=a->sub_section->block->first; + if (!next) next=a->next; + } else { + next=a->next; + } + if (!next) { + if (a->parent->owner) + next=a->parent->owner->cclass->next(a->parent->owner,0); + } + return next; } - diff --git a/src/grib_accessor_class_validity_date.c b/src/grib_accessor_class_validity_date.c index 697fe8c3e..a900594c7 100644 --- a/src/grib_accessor_class_validity_date.c +++ b/src/grib_accessor_class_validity_date.c @@ -178,15 +178,16 @@ static long convert_to_minutes(long step, long stepUnits) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; + grib_handle* hand = grib_handle_of_accessor(a); int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->time = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->step = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->stepUnits = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->year = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->month = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->day = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->date = grib_arguments_get_name(hand,c,n++); + self->time = grib_arguments_get_name(hand,c,n++); + self->step = grib_arguments_get_name(hand,c,n++); + self->stepUnits = grib_arguments_get_name(hand,c,n++); + self->year = grib_arguments_get_name(hand,c,n++); + self->month = grib_arguments_get_name(hand,c,n++); + self->day = grib_arguments_get_name(hand,c,n++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } @@ -199,6 +200,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret=0; long date = 0; long time = 0; @@ -208,22 +210,22 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len) if (self->year) { long year,month,day; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->year,&year))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->month,&month))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->day,&day))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->year,&year))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->month,&month))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->day,&day))!=GRIB_SUCCESS) return ret; *val=year*10000+month*100+day; return GRIB_SUCCESS; } - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->date,&date))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->time,&time))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long(grib_handle_of_accessor(a), self->step,&step))!=GRIB_SUCCESS) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), "endStep",&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, self->date,&date))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->time,&time))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long(hand, self->step,&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, "endStep",&step))!=GRIB_SUCCESS) { return ret; /* See ECC-817 */ } } if (self->stepUnits) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } diff --git a/src/grib_accessor_class_validity_time.c b/src/grib_accessor_class_validity_time.c index 0636cd058..f38416bd2 100644 --- a/src/grib_accessor_class_validity_time.c +++ b/src/grib_accessor_class_validity_time.c @@ -176,14 +176,15 @@ static long convert_to_minutes(long step, long stepUnits) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; + grib_handle* hand = grib_handle_of_accessor(a); int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->time = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->step = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->stepUnits = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->hours = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->minutes = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->date = grib_arguments_get_name(hand,c,n++); + self->time = grib_arguments_get_name(hand,c,n++); + self->step = grib_arguments_get_name(hand,c,n++); + self->stepUnits = grib_arguments_get_name(hand,c,n++); + self->hours = grib_arguments_get_name(hand,c,n++); + self->minutes = grib_arguments_get_name(hand,c,n++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } @@ -196,6 +197,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret=0; long date = 0; long time = 0; @@ -204,22 +206,22 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len) long hours = 0, minutes=0, step_mins=0, tmp, tmp_hrs, tmp_mins; if (self->hours) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->hours,&hours))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->minutes,&minutes))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->hours,&hours))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->minutes,&minutes))!=GRIB_SUCCESS) return ret; *val=hours*100+minutes; return GRIB_SUCCESS; } - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->date,&date))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->time,&time))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long(grib_handle_of_accessor(a), self->step,&step))!=GRIB_SUCCESS) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), "endStep",&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, self->date,&date))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->time,&time))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long(hand, self->step,&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, "endStep",&step))!=GRIB_SUCCESS) { return ret; /* See ECC-817 */ } } /* Seconds will always be zero. So convert to minutes */ if (self->stepUnits) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 023b2b219..9c8411188 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -1446,7 +1446,7 @@ struct grib_codetable { }; typedef struct grib_smart_table_entry { - int code; + /*int code;*/ char* abbreviation; char* column[MAX_SMART_TABLE_COLUMNS]; } grib_smart_table_entry; diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index ed6b93fa6..8edd7b1fe 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -808,8 +808,8 @@ long accessor_raw_get_offset(grib_accessor *a); /* grib_gaussian_reduced.c */ void grib_get_reduced_row_wrapper(grib_handle *h, long pl, double lon_first, double lon_last, long *npoints, long *ilon_first, long *ilon_last); -void grib_get_reduced_row(long pl, double lon_first, double lon_last, long *npoints, long *ilon_first, long *ilon_last); void grib_get_reduced_row_legacy(long pl, double lon_first, double lon_last, long *npoints, long *ilon_first, long *ilon_last); +void grib_get_reduced_row(long pl, double lon_first, double lon_last, long *npoints, long *ilon_first, long *ilon_last); void grib_get_reduced_row_p(long pl, double lon_first, double lon_last, long *npoints, double *olon_first, double *olon_last); /* grib_accessor_class_abstract_vector.c */ @@ -943,6 +943,8 @@ void grib_dump_footer(grib_dumper *d, grib_handle *h); /* grib_dumper_class_bufr_decode_python.c */ +/* grib_dumper_class_bufr_simple.c */ + /* grib_dumper_class_json.c */ /* grib_dumper_class_grib_encode_C.c */ @@ -1010,6 +1012,13 @@ bufr_descriptors_array* grib_context_expanded_descriptors_list_get(grib_context* void grib_context_expanded_descriptors_list_push(grib_context* c,const char* key,bufr_descriptors_array* expanded,bufr_descriptors_array* unexpanded); void codes_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc); void codes_assertion_failed(const char *message, const char *file, int line); +int grib_get_gribex_mode(grib_context* c); +void grib_gribex_mode_on(grib_context* c); +void grib_gribex_mode_off(grib_context* c); +void grib_gts_header_on(grib_context* c); +void grib_gts_header_off(grib_context* c); +void grib_multi_support_on(grib_context* c); +void grib_multi_support_off(grib_context* c); /* grib_date.c */ int grib_julian_to_datetime(double jd, long *year, long *month, long *day, long *hour, long *minute, long *second); @@ -1088,6 +1097,9 @@ int grib_get_partial_message(grib_handle *h, const void **msg, size_t *len, int int grib_get_partial_message_copy(grib_handle *h, void *message, size_t *len, int start_section); int grib_get_message_copy(grib_handle *h, void *message, size_t *len); int grib_get_message_offset(grib_handle *h, off_t *offset); +int codes_get_product_kind(grib_handle *h, ProductKind *product_kind); +int codes_check_message_header(const void *bytes, size_t length, ProductKind product); +int codes_check_message_footer(const void *bytes, size_t length, ProductKind product); int grib_get_message_size(grib_handle *h, size_t *size); int grib_get_message(grib_handle *h, const void **msg, size_t *size); int grib_get_message_headers(grib_handle *h, const void **msg, size_t *size); @@ -1095,14 +1107,7 @@ grib_handle *grib_handle_new(grib_context *c); grib_action *grib_action_from_filter(const char *filter); int grib_handle_apply_action(grib_handle *h, grib_action *a); int grib_handle_prepare_action(grib_handle *h, grib_action *a); -void grib_multi_support_on(grib_context *c); -void grib_multi_support_off(grib_context *c); void grib_multi_support_reset_file(grib_context *c, FILE *f); -void grib_gts_header_on(grib_context *c); -void grib_gts_header_off(grib_context *c); -int grib_get_gribex_mode(grib_context *c); -void grib_gribex_mode_on(grib_context *c); -void grib_gribex_mode_off(grib_context *c); void grib_multi_support_reset(grib_context *c); /* grib_header_compute.c */ @@ -1403,6 +1408,8 @@ grib_nearest *grib_nearest_factory(grib_handle *h, grib_arguments *args); /* grib_nearest_class_lambert_conformal.c */ +/* grib_nearest_class_polar_stereographic.c */ + /* grib_iterator_class_polar_stereographic.c */ /* grib_iterator_class_lambert_azimuthal_equal_area.c */ @@ -1525,6 +1532,8 @@ const char *grib_unop_double_proc_name(grib_unop_double_proc proc); FILE *codes_fopen(const char *name, const char *mode); int codes_access(const char *name, int mode); +/* grib_accessor_class_data_g2bifourier_packing.c */ + /* grib_optimize_decimal_factor.c */ int grib_optimize_decimal_factor(grib_accessor *a, const char *reference_value, const double pmax, const double pmin, const int knbit, const int compat_gribex, const int compat_32bit, long *kdec, long *kbin, double *ref); diff --git a/src/grib_context.c b/src/grib_context.c index 027168792..5a99093fd 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -1107,3 +1107,41 @@ void codes_assertion_failed(const char* message, const char* file, int line) assertion(buffer); } } + +int grib_get_gribex_mode(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + return c->gribex_mode_on; +} +void grib_gribex_mode_on(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gribex_mode_on=1; +} +void grib_gribex_mode_off(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gribex_mode_on=0; +} + +void grib_gts_header_on(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gts_header_on=1; +} +void grib_gts_header_off(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gts_header_on=0; +} + +void grib_multi_support_on(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->multi_support_on=1; +} +void grib_multi_support_off(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->multi_support_on=0; +} diff --git a/src/grib_darray.c b/src/grib_darray.c index 5dfe35f60..21f09023d 100644 --- a/src/grib_darray.c +++ b/src/grib_darray.c @@ -30,91 +30,91 @@ void grib_darray_print(const char* title, const grib_darray* darray) grib_darray* grib_darray_new_from_array(grib_context* c,double* a,size_t size) { - size_t i; - grib_darray* v; + size_t i; + grib_darray* v; - if (!c) c=grib_context_get_default(); + if (!c) c=grib_context_get_default(); - v=grib_darray_new(c,size,100); - for (i=0;iv[i]=a[i]; - v->n=size; - v->context=c; - return v; + v=grib_darray_new(c,size,100); + for (i=0;iv[i]=a[i]; + v->n=size; + v->context=c; + return v; } grib_darray* grib_darray_new(grib_context* c,size_t size,size_t incsize) { - grib_darray* v=NULL; - if (!c) c=grib_context_get_default(); - v=(grib_darray*)grib_context_malloc_clear(c,sizeof(grib_darray)); - if (!v) { - grib_context_log(c,GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %d bytes\n",sizeof(grib_darray)); - return NULL; - } - v->size=size; - v->n=0; - v->incsize=incsize; - v->v=(double*)grib_context_malloc_clear(c,sizeof(double)*size); - if (!v->v) { - grib_context_log(c,GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %d bytes\n",sizeof(double)*size); - return NULL; - } - return v; + grib_darray* v=NULL; + if (!c) c=grib_context_get_default(); + v=(grib_darray*)grib_context_malloc_clear(c,sizeof(grib_darray)); + if (!v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_darray_new unable to allocate %d bytes\n",sizeof(grib_darray)); + return NULL; + } + v->size=size; + v->n=0; + v->incsize=incsize; + v->v=(double*)grib_context_malloc_clear(c,sizeof(double)*size); + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_darray_new unable to allocate %d bytes\n",sizeof(double)*size); + return NULL; + } + return v; } grib_darray* grib_darray_resize(grib_context* c,grib_darray* v) { - int newsize=v->incsize+v->size; + int newsize=v->incsize+v->size; - if (!c) c=grib_context_get_default(); + if (!c) c=grib_context_get_default(); - v->v = (double*)grib_context_realloc(c,v->v,newsize*sizeof(double)); - v->size=newsize; - if (!v->v) { - grib_context_log(c,GRIB_LOG_ERROR, - "grib_darray_resize unable to allocate %d bytes\n",sizeof(double)*newsize); - return NULL; - } - return v; + v->v = (double*)grib_context_realloc(c,v->v,newsize*sizeof(double)); + v->size=newsize; + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_darray_resize unable to allocate %d bytes\n",sizeof(double)*newsize); + return NULL; + } + return v; } grib_darray* grib_darray_push(grib_context* c,grib_darray* v,double val) { - size_t start_size=100; - size_t start_incsize=100; - if (!v) v=grib_darray_new(c,start_size,start_incsize); + size_t start_size=100; + size_t start_incsize=100; + if (!v) v=grib_darray_new(c,start_size,start_incsize); - if (v->n >= v->size) v=grib_darray_resize(c,v); - v->v[v->n]=val; - v->n++; - return v; + if (v->n >= v->size) v=grib_darray_resize(c,v); + v->v[v->n]=val; + v->n++; + return v; } void grib_darray_delete(grib_context* c,grib_darray* v) { - if (!v) return; - if (!c) grib_context_get_default(); - if (v->v) grib_context_free(c,v->v); - grib_context_free(c,v); + if (!v) return; + if (!c) grib_context_get_default(); + if (v->v) grib_context_free(c,v->v); + grib_context_free(c,v); } double* grib_darray_get_array(grib_context* c,grib_darray* v) { - double* ret; - int i; - if (!v) return NULL; - ret=(double*)grib_context_malloc_clear(c,sizeof(double)*v->n); - for (i=0;in;i++) ret[i]=v->v[i]; - return ret; + double* ret; + int i; + if (!v) return NULL; + ret=(double*)grib_context_malloc_clear(c,sizeof(double)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; } int grib_darray_is_constant(grib_darray* v,double eps) { - int i; - double val; - if (v->n == 1) return 1; + int i; + double val; + if (v->n == 1) return 1; - val=v->v[0]; - for (i=1;in;i++) { - if (fabs(val-v->v[i]) > eps) return 0; - } - return 1; + val=v->v[0]; + for (i=1;in;i++) { + if (fabs(val-v->v[i]) > eps) return 0; + } + return 1; } size_t grib_darray_used_size(grib_darray* v) { return v->n;} diff --git a/src/grib_dumper_class_default.c b/src/grib_dumper_class_default.c index 36fed9693..44a8b0233 100644 --- a/src/grib_dumper_class_default.c +++ b/src/grib_dumper_class_default.c @@ -155,7 +155,7 @@ static void dump_long(grib_dumper* d,grib_accessor* a,const char* comment) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0){ fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"# type %s \n",a->creator->op); + fprintf(self->dumper.out,"# type %s (int)\n",a->creator->op); } if (size>1) { @@ -290,7 +290,7 @@ static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"# type %s \n",a->creator->op); + fprintf(self->dumper.out,"# type %s (double)\n",a->creator->op); } aliases(d,a); @@ -353,7 +353,7 @@ static void dump_string_array(grib_dumper* d,grib_accessor* a,const char* commen if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"# type %s \n",a->creator->op); + fprintf(self->dumper.out,"# type %s (str)\n",a->creator->op); } aliases(d,a); @@ -417,7 +417,7 @@ static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"# type %s \n",a->creator->op); + fprintf(self->dumper.out,"# type %s (str)\n",a->creator->op); } aliases(d,a); @@ -541,13 +541,19 @@ static void dump_values(grib_dumper* d,grib_accessor* a) dump_double(d,a,NULL); return ; } + buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); print_offset(self->dumper.out,d,a); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { + char type_name[32]=""; + const long native_type = grib_accessor_get_native_type(a); + if (native_type == GRIB_TYPE_LONG) strcpy(type_name, "(int)"); + else if (native_type == GRIB_TYPE_DOUBLE) strcpy(type_name, "(double)"); + else if (native_type == GRIB_TYPE_STRING) strcpy(type_name, "(str)"); fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"# type %s \n",a->creator->op); + fprintf(self->dumper.out,"# type %s %s\n",a->creator->op, type_name); } aliases(d,a); diff --git a/src/grib_geography.c b/src/grib_geography.c index 7fffce81e..84155de05 100644 --- a/src/grib_geography.c +++ b/src/grib_geography.c @@ -146,8 +146,8 @@ int is_gaussian_global( { grib_context* c=grib_context_get_default(); if (c->debug) { - printf("ECCODES DEBUG is_gaussian_global: lat1=%f, lat2=%f, glat0=%f, d=%f\n", lat1, lat2, latitudes[0], d); - printf("ECCODES DEBUG is_gaussian_global: lon1=%f, lon2=%f, glon2=%f, delta=%f\n", lon1, lon2, lon2_global, delta); + fprintf(stderr,"ECCODES DEBUG is_gaussian_global: lat1=%f, lat2=%f, glat0=%f, d=%f\n", lat1, lat2, latitudes[0], d); + fprintf(stderr,"ECCODES DEBUG is_gaussian_global: lon1=%f, lon2=%f, glon2=%f, delta=%f\n", lon1, lon2, lon2_global, delta); } } */ diff --git a/src/grib_handle.c b/src/grib_handle.c index adf54e7a0..d351cde5a 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -261,7 +261,7 @@ grib_handle* grib_handle_new_from_samples( grib_context* c, const char* name ) if(g) return g; */ if (c->debug) { - printf("ECCODES DEBUG: grib_handle_new_from_samples '%s'\n", name); + fprintf(stderr, "ECCODES DEBUG: grib_handle_new_from_samples '%s'\n", name); } g = grib_external_template( c,name ); @@ -284,7 +284,7 @@ grib_handle* codes_bufr_handle_new_from_samples ( grib_context* c, const char* n if(g) return g; */ if (c->debug) { - printf("ECCODES DEBUG: grib_handle_new_from_samples '%s'\n", name); + fprintf(stderr, "ECCODES DEBUG: grib_handle_new_from_samples '%s'\n", name); } g=bufr_external_template ( c,name ); @@ -1531,18 +1531,6 @@ static void grib2_build_message ( grib_context* context,unsigned char* sections[ *len=msglen; } -void grib_multi_support_on ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->multi_support_on=1; -} - -void grib_multi_support_off ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->multi_support_on=0; -} - /* For multi support mode: Reset all file handles equal to f. See GRIB-249 */ void grib_multi_support_reset_file(grib_context* c, FILE* f) { @@ -1557,36 +1545,6 @@ void grib_multi_support_reset_file(grib_context* c, FILE* f) } } -void grib_gts_header_on ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gts_header_on=1; -} - -void grib_gts_header_off ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gts_header_on=0; -} - -int grib_get_gribex_mode ( grib_context* c) -{ - if ( !c ) c=grib_context_get_default(); - return c->gribex_mode_on; -} - -void grib_gribex_mode_on ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gribex_mode_on=1; -} - -void grib_gribex_mode_off ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gribex_mode_on=0; -} - static grib_multi_support* grib_get_multi_support ( grib_context* c, FILE* f ) { int i=0; diff --git a/src/grib_hash_keys.c b/src/grib_hash_keys.c index e9e8ad85f..007220eff 100644 --- a/src/grib_hash_keys.c +++ b/src/grib_hash_keys.c @@ -49,9 +49,7 @@ struct grib_keys_hash { char* name; int id;}; #endif #endif static unsigned int -hash_keys (str, len) - register const char *str; - register unsigned int len; +hash_keys (const char *str, unsigned int len) { static const unsigned short asso_values[] = { @@ -8829,9 +8827,7 @@ static const struct grib_keys_hash wordlist[] = #endif #endif const struct grib_keys_hash * -grib_keys_hash_get (str, len) - register const char *str; - register unsigned int len; +grib_keys_hash_get (const char *str, unsigned int len) { if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { diff --git a/src/grib_iarray.c b/src/grib_iarray.c index 4e4e38b3c..09f798f09 100644 --- a/src/grib_iarray.c +++ b/src/grib_iarray.c @@ -227,14 +227,13 @@ long* grib_iarray_get_array(grib_iarray* v) size_t grib_iarray_used_size(grib_iarray* v) {return v==NULL ? 0 : v->n;} int grib_iarray_is_constant(grib_iarray* v) { - int i; - long val; - if (v->n == 1) return 1; + int i; + long val; + if (v->n == 1) return 1; - val=v->v[0]; - for (i=1;in;i++) { - if (val!=v->v[i]) return 0; - } - return 1; + val=v->v[0]; + for (i=1;in;i++) { + if (val!=v->v[i]) return 0; + } + return 1; } - diff --git a/src/grib_iterator_class_gaussian_reduced.c b/src/grib_iterator_class_gaussian_reduced.c index e1b12b630..f986f7471 100644 --- a/src/grib_iterator_class_gaussian_reduced.c +++ b/src/grib_iterator_class_gaussian_reduced.c @@ -167,7 +167,7 @@ static int iterate_reduced_gaussian_subarea_legacy(grib_iterator* iter, grib_han if (h->context->debug) { const size_t np = count_subarea_points(h, get_reduced_row, pl, plsize, lon_first, lon_last); - printf("ECCODES DEBUG grib_iterator_class_gaussian_reduced: Legacy sub-area num points=%ld\n", (long)np); + fprintf(stderr,"ECCODES DEBUG grib_iterator_class_gaussian_reduced: Legacy sub-area num points=%ld\n", (long)np); } /*find starting latitude */ @@ -219,7 +219,7 @@ static int iterate_reduced_gaussian_subarea_algorithm2(grib_iterator* iter, grib if (h->context->debug) { const size_t np = count_subarea_points(h, get_reduced_row, pl, plsize, lon_first, lon_last); - printf("ECCODES DEBUG grib_iterator_class_gaussian_reduced: sub-area num points=%ld\n", (long)np); + fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: sub-area num points=%ld\n", (long)np); } /* Find starting latitude */ @@ -368,7 +368,7 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) iter->e=0; if (h->context->debug) { const size_t np = count_global_points(pl, plsize); - printf("ECCODES DEBUG grib_iterator_class_gaussian_reduced: global num points=%ld\n", (long)np); + fprintf(stderr, "ECCODES DEBUG grib_iterator_class_gaussian_reduced: global num points=%ld\n", (long)np); } for (j=0;jcontext,GRIB_LOG_ERROR,"Lambert Azimuthal Equal Area only supported for spherical earth."); return ret; + } if((ret = grib_get_long_internal(h, snx,&nx)) != GRIB_SUCCESS) return ret; if((ret = grib_get_long_internal(h, sny,&ny)) != GRIB_SUCCESS) diff --git a/src/grib_templates.c b/src/grib_templates.c index 66251f873..cd217f96a 100644 --- a/src/grib_templates.c +++ b/src/grib_templates.c @@ -49,7 +49,7 @@ static grib_handle* try_template(grib_context* c,const char* dir,const char* nam sprintf(path,"%s/%s.tmpl",dir,name); if (c->debug==-1) { - printf("ECCODES DEBUG: try_template path='%s'\n", path); + fprintf(stderr, "ECCODES DEBUG: try_template path='%s'\n", path); } if(codes_access(path,F_OK) == 0) @@ -79,7 +79,7 @@ static grib_handle* try_bufr_template(grib_context* c,const char* dir,const char sprintf(path,"%s/%s.tmpl",dir,name); if (c->debug==-1) { - printf("ECCODES DEBUG: try_template path='%s'\n", path); + fprintf(stderr, "ECCODES DEBUG: try_template path='%s'\n", path); } if(codes_access(path,F_OK) == 0) diff --git a/src/grib_util.c b/src/grib_util.c index ffb4b4e88..532bf268f 100644 --- a/src/grib_util.c +++ b/src/grib_util.c @@ -345,22 +345,22 @@ static void print_values(grib_context* c, const grib_util_grid_spec2* spec, size_t i=0; int isConstant = 1; double v = 0, minVal=DBL_MAX, maxVal=-DBL_MAX; - printf("ECCODES DEBUG grib_util grib_set_values: setting %lu key/value pairs\n",(unsigned long)count); + fprintf(stderr, "ECCODES DEBUG grib_util grib_set_values: setting %lu key/value pairs\n",(unsigned long)count); for(i=0; i %s = %ld;\n" + case GRIB_TYPE_LONG: fprintf(stderr, "ECCODES DEBUG grib_util: => %s = %ld;\n" ,keyval_pairs[i].name,(long)keyval_pairs[i].long_value); break; - case GRIB_TYPE_DOUBLE: printf("ECCODES DEBUG grib_util: => %s = %.16e;\n" + case GRIB_TYPE_DOUBLE: fprintf(stderr, "ECCODES DEBUG grib_util: => %s = %.16e;\n" ,keyval_pairs[i].name,keyval_pairs[i].double_value); break; - case GRIB_TYPE_STRING: printf("ECCODES DEBUG grib_util: => %s = \"%s\";\n" + case GRIB_TYPE_STRING: fprintf(stderr, "ECCODES DEBUG grib_util: => %s = \"%s\";\n" ,keyval_pairs[i].name,keyval_pairs[i].string_value); break; } } - printf("ECCODES DEBUG grib_util: data_values_count=%lu;\n", (unsigned long)data_values_count); + fprintf(stderr, "ECCODES DEBUG grib_util: data_values_count=%lu;\n", (unsigned long)data_values_count); for (i=0; imissingValue) { @@ -380,9 +380,9 @@ static void print_values(grib_context* c, const grib_util_grid_spec2* spec, if (v > maxVal) maxVal=v; } } - printf("ECCODES DEBUG grib_util: data_values are CONSTANT? %d\t(min=%.16e, max=%.16e)\n", + fprintf(stderr, "ECCODES DEBUG grib_util: data_values are CONSTANT? %d\t(min=%.16e, max=%.16e)\n", isConstant, minVal, maxVal); - if (c->gribex_mode_on) printf("ECCODES DEBUG grib_util: GRIBEX mode is turned on!\n"); + if (c->gribex_mode_on) fprintf(stderr, "ECCODES DEBUG grib_util: GRIBEX mode is turned on!\n"); #if 0 if (spec->bitmapPresent) { @@ -523,7 +523,7 @@ static int expand_bounding_box(grib_handle* h, grib_values *values, const size_t if (is_angle && !angle_can_be_encoded(h, values[i].double_value)) { new_angle = adjust_angle(values[i].double_value, roundingPolicy, angle_subdivisions); if (h->context->debug) { - printf("ECCODES DEBUG grib_util EXPAND_BOUNDING_BOX %s: old=%.15e new=%.15e (%s)\n", + fprintf(stderr, "ECCODES DEBUG grib_util EXPAND_BOUNDING_BOX %s: old=%.15e new=%.15e (%s)\n", values[i].name, values[i].double_value, new_angle, (roundingPolicy==eROUND_ANGLE_UP?"Up":"Down")); } @@ -887,9 +887,9 @@ grib_handle* grib_util_set_spec2(grib_handle* h, grib_get_long(h,"bitsPerValue",&input_bits_per_value); grib_get_long(h,"decimalScaleFactor",&input_decimal_scale_factor); if (h->context->debug==-1) { - printf("ECCODES DEBUG grib_util: input_packing_type = %s\n",input_packing_type); - printf("ECCODES DEBUG grib_util: input_bits_per_value = %ld\n",input_bits_per_value); - printf("ECCODES DEBUG grib_util: input_decimal_scale_factor = %ld\n",input_decimal_scale_factor); + fprintf(stderr, "ECCODES DEBUG grib_util: input_packing_type = %s\n",input_packing_type); + fprintf(stderr, "ECCODES DEBUG grib_util: input_bits_per_value = %ld\n",input_bits_per_value); + fprintf(stderr, "ECCODES DEBUG grib_util: input_decimal_scale_factor = %ld\n",input_decimal_scale_factor); } /*if ( (*err=check_values(data_values, data_values_count))!=GRIB_SUCCESS ) { @@ -983,9 +983,9 @@ grib_handle* grib_util_set_spec2(grib_handle* h, } if (h->context->debug==-1) { int j=0; - printf("ECCODES DEBUG grib_util: grib_set_double_array\n"); - for (j=0;j<20;j++) printf("ECCODES DEBUG grib_util %g\n",data_values[j]); - printf("ECCODES DEBUG grib_util: data_values_count=%d \n",(int)data_values_count); + fprintf(stderr, "ECCODES DEBUG grib_util: grib_set_double_array\n"); + for (j=0;j<20;j++) fprintf(stderr, "ECCODES DEBUG grib_util %g\n",data_values[j]); + fprintf(stderr, "ECCODES DEBUG grib_util: data_values_count=%d \n",(int)data_values_count); } if((*err = grib_set_double_array(h,"values",data_values,data_values_count)) != 0) @@ -993,7 +993,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h, goto cleanup; } if (h->context->debug==-1) - printf("ECCODES DEBUG grib_util: done grib_set_double_array \n"); + fprintf(stderr, "ECCODES DEBUG grib_util: done grib_set_double_array \n"); /* convert to second_order if not constant field */ @@ -1460,8 +1460,8 @@ grib_handle* grib_util_set_spec2(grib_handle* h, } if (h->context->debug==-1) { - printf("ECCODES DEBUG grib_util: global_grid = %d\n", global_grid); - printf("ECCODES DEBUG grib_util: expandBoundingBox = %d\n", expandBoundingBox); + fprintf(stderr, "ECCODES DEBUG grib_util: global_grid = %d\n", global_grid); + fprintf(stderr, "ECCODES DEBUG grib_util: expandBoundingBox = %d\n", expandBoundingBox); print_values(h->context,spec,data_values,data_values_count,values,count); } @@ -1631,7 +1631,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h, } #endif if (h->context->debug==-1) - printf("ECCODES DEBUG: grib_util_set_spec end\n"); + fprintf(stderr, "ECCODES DEBUG: grib_util_set_spec end\n"); return outh; diff --git a/src/grib_value.c b/src/grib_value.c index 1d826440f..a6655c786 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -66,7 +66,7 @@ int grib_set_long_internal(grib_handle* h, const char* name, long val) a = grib_find_accessor(h, name); if (h->context->debug) - printf("ECCODES DEBUG grib_set_long_internal %s=%ld\n",name,(long)val); + fprintf(stderr, "ECCODES DEBUG grib_set_long_internal %s=%ld\n",name,(long)val); if(a){ ret = grib_pack_long(a, &val, &l); @@ -92,7 +92,7 @@ int grib_set_long(grib_handle* h, const char* name, long val) a = grib_find_accessor(h, name); if (h->context->debug) - printf("ECCODES DEBUG grib_set_long %s=%ld\n",name,(long)val); + fprintf(stderr, "ECCODES DEBUG grib_set_long %s=%ld\n",name,(long)val); if(a){ if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) @@ -116,7 +116,7 @@ int grib_set_double_internal(grib_handle* h, const char* name, double val) a = grib_find_accessor(h, name); if (h->context->debug) - printf("ECCODES DEBUG grib_set_double_internal %s=%g\n",name,val); + fprintf(stderr, "ECCODES DEBUG grib_set_double_internal %s=%g\n",name,val); if(a){ ret = grib_pack_double(a, &val, &l); @@ -309,7 +309,7 @@ int grib_set_double(grib_handle* h, const char* name, double val) a = grib_find_accessor(h, name); if (h->context->debug) - printf("ECCODES DEBUG grib_set_double %s=%g\n",name,val); + fprintf(stderr, "ECCODES DEBUG grib_set_double %s=%g\n",name,val); if(a){ @@ -334,7 +334,7 @@ int grib_set_string_internal(grib_handle* h, const char* name, a = grib_find_accessor(h, name); if (h->context->debug) - printf("ECCODES DEBUG grib_set_string_internal %s=%s\n",name,val); + fprintf(stderr, "ECCODES DEBUG grib_set_string_internal %s=%s\n",name,val); if(a){ ret = grib_pack_string(a, val, length); @@ -366,7 +366,7 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t *l grib_get_long(h,"bitsPerValue",&bitsPerValue); if (bitsPerValue==0) { if (h->context->debug) { - printf("ECCODES DEBUG grib_set_string packingType: Constant field cannot be encoded in second order. Packing not changed\n"); + fprintf(stderr, "ECCODES DEBUG grib_set_string packingType: Constant field cannot be encoded in second order. Packing not changed\n"); } return 0; } @@ -375,7 +375,7 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t *l ret = grib_get_size(h, "codedValues", &numCodedVals); if (ret == GRIB_SUCCESS && numCodedVals < 3) { if (h->context->debug) { - printf("ECCODES DEBUG grib_set_string packingType: not enough coded values for second order. Packing not changed\n"); + fprintf(stderr, "ECCODES DEBUG grib_set_string packingType: not enough coded values for second order. Packing not changed\n"); } return 0; } @@ -384,7 +384,7 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t *l a = grib_find_accessor(h, name); if (h->context->debug) - printf("ECCODES DEBUG grib_set_string %s=|%s|\n",name,val); + fprintf(stderr, "ECCODES DEBUG grib_set_string %s=|%s|\n",name,val); if(a) { @@ -408,7 +408,7 @@ int grib_set_string_array(grib_handle* h, const char* name, const char** val, si a = grib_find_accessor(h, name); if (h->context->debug) { - printf("ECCODES DEBUG grib_set_string_array key=%s %ld values\n",name,(long)length); + fprintf(stderr, "ECCODES DEBUG grib_set_string_array key=%s %ld values\n",name,(long)length); } if(a) @@ -521,7 +521,7 @@ int grib_set_missing(grib_handle* h, const char* name) return GRIB_READ_ONLY; if(a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - if (h->context->debug) printf("ECCODES DEBUG grib_set_missing %s\n",name); + if (h->context->debug) fprintf(stderr, "ECCODES DEBUG grib_set_missing %s\n",name); ret=grib_pack_missing(a); if(ret == GRIB_SUCCESS) @@ -672,7 +672,7 @@ int grib_set_double_array_internal(grib_handle* h, const char* name, const doubl int ret=0; if (h->context->debug) - printf("ECCODES DEBUG grib_set_double_array_internal key=%s %ld values\n",name,(long)length); + fprintf(stderr, "ECCODES DEBUG grib_set_double_array_internal key=%s %ld values\n",name,(long)length); if (length==0) { grib_accessor* a = grib_find_accessor(h, name); @@ -684,7 +684,7 @@ int grib_set_double_array_internal(grib_handle* h, const char* name, const doubl if (ret!=GRIB_SUCCESS) grib_context_log(h->context,GRIB_LOG_ERROR,"unable to set double array %s (%s)", name,grib_get_error_message(ret)); - /*if (h->context->debug) printf("ECCODES DEBUG grib_set_double_array_internal key=%s --DONE\n",name);*/ + /*if (h->context->debug) fprintf(stderr,"ECCODES DEBUG grib_set_double_array_internal key=%s --DONE\n",name);*/ return ret; } @@ -694,7 +694,7 @@ static int __grib_set_double_array(grib_handle* h, const char* name, const doubl int constant,i; if (h->context->debug) - printf("ECCODES DEBUG grib_set_double_array key=%s %ld values\n",name,(long)length); + fprintf(stderr, "ECCODES DEBUG grib_set_double_array key=%s %ld values\n",name,(long)length); if (length==0) { grib_accessor* a = grib_find_accessor(h, name); @@ -736,12 +736,12 @@ static int __grib_set_double_array(grib_handle* h, const char* name, const doubl ) { slen=11; /*length of 'grid_simple' */ if (h->context->debug) { - printf("ECCODES DEBUG __grib_set_double_array: Cannot use second order packing for constant fields. Using simple packing\n"); + fprintf(stderr, "ECCODES DEBUG __grib_set_double_array: Cannot use second order packing for constant fields. Using simple packing\n"); } ret = grib_set_string(h,"packingType","grid_simple",&slen); if (ret != GRIB_SUCCESS) { if (h->context->debug) { - printf("ECCODES DEBUG __grib_set_double_array: could not switch to simple packing!\n"); + fprintf(stderr, "ECCODES DEBUG __grib_set_double_array: could not switch to simple packing!\n"); } } } @@ -801,7 +801,7 @@ static int _grib_set_long_array(grib_handle* h, const char* name, const long* va if (!a) return GRIB_NOT_FOUND ; if (h->context->debug) { - printf("ECCODES DEBUG _grib_set_long_array key=%s %ld values\n",name,(long)length); + fprintf(stderr, "ECCODES DEBUG _grib_set_long_array key=%s %ld values\n",name,(long)length); } if (name[0]=='/' || name[0]=='#' ) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc5c8ffda..b2b427eee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,11 +10,12 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_S # Build the executables used by test scripts ################################################ list( APPEND test_bins + bpv_limit grib_double_cmp read_any julian index - multi_from_message + grib_multi_from_message read_index unit_tests bufr_keys_iter @@ -65,6 +66,7 @@ list( APPEND tests_no_data_reqd ) # These tests do require data downloads list( APPEND tests_data_reqd + bpv_limit grib_double_cmp grib_change_packing bufr_dump_data @@ -136,7 +138,7 @@ list( APPEND tests_data_reqd grib_octahedral grib_global grib_concept - decimalPrecision + grib_decimalPrecision grib_bitsPerValue get_fail grib_missing @@ -149,9 +151,9 @@ list( APPEND tests_data_reqd grib_level index grib_bitmap - list + grib_list grib_second_order - multi_from_message + grib_multi_from_message grib_change_scanning grib_statistics grib_tigge diff --git a/tests/Makefile.am b/tests/Makefile.am index 6c164100b..5067feb41 100755 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -44,7 +44,7 @@ TESTS = definitions.sh \ grib_level.sh \ index.sh \ grib_bitmap.sh \ - list.sh \ + grib_list.sh \ grib_second_order.sh \ multi_from_message.sh \ grib_change_scanning.sh \ @@ -61,7 +61,6 @@ TESTS = definitions.sh \ grib_jpeg.sh \ grib_ccsds.sh \ md5.sh \ - grib_util_set_spec.sh \ grib_neg_fctime.sh \ bufr_ecc-197.sh \ bufr_ecc-286.sh \ @@ -76,7 +75,7 @@ download_data: noinst_PROGRAMS = packing_check gauss_sub read_any grib_double_cmp packing pack_unpack \ multi_from_message julian read_index index gribex_perf\ jpeg_perf grib_ccsds_perf so_perf png_perf bpv_limit laplacian \ - unit_tests grib_util_set_spec + unit_tests multi_from_message_SOURCES = multi_from_message.c laplacian_SOURCES = laplacian.c @@ -95,7 +94,6 @@ png_perf_SOURCES = png_perf.c grib_ccsds_perf_SOURCES = grib_ccsds_perf.c gribex_perf_SOURCES = gribex_perf.c gauss_sub_SOURCES = gauss_sub.c -grib_util_set_spec_SOURCES = grib_util_set_spec.c LDADD = $(top_builddir)/src/libeccodes.la $(EMOS_LIB) diff --git a/tests/bpv_limit.c b/tests/bpv_limit.c index 50a1769d2..9bf2e4eb1 100644 --- a/tests/bpv_limit.c +++ b/tests/bpv_limit.c @@ -9,121 +9,107 @@ */ /* - * ===================================================================================== - * - * Filename: bpv_limit.c - * - * Description: test setting the number of bpv before decoding and then encoding; - * setting the wrong number of bpv should result in an exception - * - * Version: 1.0 - * Created: 30/03/10 16:07:51 - * Revision: none - * Compiler: gcc - * - * Author: Cristian Codorean (mow), mow@ecmwf.int - * Company: ECMWF - * - * ===================================================================================== + * Description: test setting the number of bits per value before decoding and then encoding; + * setting the wrong number of bpv should result in an error */ -#include -#include +#include #include "grib_api.h" -void usage(char* prog) { - printf("usage: %s filein\n",prog); - exit(1); +static double compare_double_absolute(double a,double b,double tolerance) +{ + double ret=0; + double d=fabs(a-b); + if (d > tolerance) { + ret=d; + } + return ret; } +static void usage(const char* prog) { + fprintf(stderr, "usage: %s input\n",prog); + exit(1); +} + +static int check_error_code(int err) +{ + if (err == GRIB_INVALID_BPV || err == GRIB_DECODING_ERROR) + return GRIB_SUCCESS; + return GRIB_INVALID_ARGUMENT; +} int main(int argc, char** argv) { - int err = 0; - size_t values_len=0; - double *values = NULL; - char error_msg[100] ; - - size_t slong = sizeof(long) * 8 ; + int err = 0, i; + size_t values_len=0; + double *values = NULL; + char error_msg[100] ; + const double tolerance = 1e-5; + size_t slong = sizeof(long) * 8 ; + grib_handle *h; + char* filename ; - int i; + if (argc<2) usage(argv[0]); + filename=argv[1]; - FILE* in = NULL; - char* filename ; + for (i=0;i<255;i++) { + FILE* in = fopen(filename,"r"); assert(in); + h = grib_handle_new_from_file(0,in,&err); assert(h); - grib_handle *h = NULL; + /* get the size of the values array*/ + GRIB_CHECK(grib_get_size(h,"values",&values_len),0); - if (argc<2) usage(argv[0]); - filename=argv[1]; + values = (double*)malloc(values_len*sizeof(double)); - in = fopen(filename,"r"); - if(!in) { - printf("ERROR: unable to open file %s\n",filename); - return 1; - } + err = grib_get_double_array(h,"values",values,&values_len); + if (compare_double_absolute(values[0], 2.7900000000e+02, tolerance) != 0) + printf("oops i=%d values[0]=%g\n", i,values[0]); + if (compare_double_absolute(values[1], 2.7996093750e+02, tolerance) != 0) + printf("oops i=%d values[1]=%g\n", i,values[1]); - /* create new handle from a message in a file*/ - h = grib_handle_new_from_file(0,in,&err); - if (h == NULL) { - printf("Error: unable to create handle from file %s\n",filename); - } + GRIB_CHECK(grib_set_long(h,"bitsPerValue",i),0); - for (i=0;i<255;i++) { + err = grib_set_double_array(h,"values",values,values_len); - /* get the size of the values array*/ - GRIB_CHECK(grib_get_size(h,"values",&values_len),0); + free(values); + values = 0; - values = (double*)malloc(values_len*sizeof(double)); + /* + * check if encoding of the data fails when the number of bpv + * is not supported; bpv allowed on decoding is bpv < size of long + */ - err = grib_get_double_array(h,"values",values,&values_len); + if (i < slong && err == 0) { + /* do nothing */ + } else if (i >= slong && check_error_code(err)==GRIB_SUCCESS) { + /* do nothing */ + } else { + sprintf(error_msg,"Error decoding when bpv=%d. Error message:%s",i,grib_get_error_message(err)); + perror(error_msg); + exit(1); + } - GRIB_CHECK(grib_set_long(h,"bitsPerValue",i),0); + values = (double*)malloc(values_len*sizeof(double)); + err = grib_get_double_array(h,"values",values,&values_len); - err = grib_set_double_array(h,"values",values,values_len); + /* + * check if decoding of the data fails when the number of bpv + * is not supported; bpv allowed on decoding is bpv <= size of long + */ - free(values); - values = 0; + if (i < slong && err == 0) { + /* do nothing */ + } else if (i >= slong && check_error_code(err)==GRIB_SUCCESS) { + /* do nothing */ + } else { + sprintf(error_msg,"Error decoding when bpv=%d. Error message:%s",i,grib_get_error_message(err)); + perror(error_msg); + exit(1); + } - /* - * check if encoding of the data fails when the number of bpv - * is not supported; bpv allowed on decoding is bpv < size of long - */ - - if (i < slong && err == 0) { - /* do nothing */ - } else if (i >= slong && err == GRIB_INVALID_BPV) { - /* do nothing */ - } else { - sprintf(error_msg,"Error decoding when bpv=%d. Error message:%s",i,grib_get_error_message(err)); - perror(error_msg); - exit(1); + free(values); values = 0; + grib_handle_delete(h); h = 0; + fclose(in); } - values = (double*)malloc(values_len*sizeof(double)); - err = grib_get_double_array(h,"values",values,&values_len); - - /* - * check if decoding of the data fails when the number of bpv - * is not supported; bpv allowed on decoding is bpv <= size of long - */ - - if (i <= slong && err == 0) { - /* do nothing */ - } else if (i > slong && err == GRIB_INVALID_BPV) { - /* do nothing */ - } else { - sprintf(error_msg,"Error decoding when bpv=%d. Error message:%s",i,grib_get_error_message(err)); - perror(error_msg); - exit(1); - } - - free(values); - values = 0; - } - - grib_handle_delete(h); - h=0; - - fclose(in); - - return 0; + return 0; } diff --git a/tests/bpv_limit.sh b/tests/bpv_limit.sh index 205ead64d..2e27c8c2b 100755 --- a/tests/bpv_limit.sh +++ b/tests/bpv_limit.sh @@ -17,6 +17,9 @@ REDIRECT=/dev/null -for file in ${data_dir}/regular_latlon_surface.grib?; do - ./bpv_limit $file 2> $REDIRECT > $REDIRECT -done +./bpv_limit ${data_dir}/regular_latlon_surface.grib2 + +# TODO: grib1 does not work yet. bpv=64 but decode does not fail as expected +#for file in ${data_dir}/regular_latlon_surface.grib?; do +# ./bpv_limit $file +#done diff --git a/tests/decimalPrecision.sh b/tests/grib_decimalPrecision.sh similarity index 100% rename from tests/decimalPrecision.sh rename to tests/grib_decimalPrecision.sh diff --git a/tests/list.sh b/tests/grib_list.sh similarity index 100% rename from tests/list.sh rename to tests/grib_list.sh diff --git a/tests/multi_from_message.c b/tests/grib_multi_from_message.c similarity index 100% rename from tests/multi_from_message.c rename to tests/grib_multi_from_message.c diff --git a/tests/multi_from_message.sh b/tests/grib_multi_from_message.sh similarity index 73% rename from tests/multi_from_message.sh rename to tests/grib_multi_from_message.sh index 873af94d0..263886083 100755 --- a/tests/multi_from_message.sh +++ b/tests/grib_multi_from_message.sh @@ -11,25 +11,19 @@ . ./include.sh -out1=${data_dir}/multi1.out -out2=${data_dir}/multi2.out +label='grib_multi_from_message' +out1=${data_dir}/temp.$label.1.out +out2=${data_dir}/temp.$label.2.out for infile in ${data_dir}/multi.grib2 ${data_dir}/reduced_gaussian_model_level.grib1 do - #if [ ! -f ${infile} ] - #then - # echo no data to test - # exit 0 - #fi - - $EXEC ${test_dir}/multi_from_message -m $infile > $out1 + $EXEC ${test_dir}/grib_multi_from_message -m $infile > $out1 ${tools_dir}/grib_get -p count,shortName,level $infile > $out2 diff $out1 $out2 - $EXEC ${test_dir}/multi_from_message $infile > $out1 + $EXEC ${test_dir}/grib_multi_from_message $infile > $out1 ${tools_dir}/grib_get -M -p count,shortName,level $infile > $out2 diff $out1 $out2 rm -f $out1 $out2 - done diff --git a/tools/bufr_compare.c b/tools/bufr_compare.c index 1f177022c..87b8054fc 100644 --- a/tools/bufr_compare.c +++ b/tools/bufr_compare.c @@ -19,8 +19,8 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b) GRIB_INLINE static int grib_inline_rstrcmp(const char* a,const char* b) { - char* p=(char*)a; - char* q=(char*)b; + const char* p=a; + const char* q=b; while (*p != 0) p++; while (*q != 0) q++; q--;p--; @@ -38,15 +38,14 @@ struct grib_error { grib_error* next; }; -grib_error* error_summary; - -compare_double_proc compare_double; -double global_tolerance=0; -int packingCompare=0; -grib_string_list* blacklist=0; -grib_string_list* keys_list = NULL; /* Used to determine rank of key */ -int isLeafKey = 0; /* 0 if key is top-level, 1 if key has no children attributes */ -int compareAbsolute=1; +static grib_error* error_summary; +static compare_double_proc compare_double; +static double global_tolerance=0; +static int packingCompare=0; +static grib_string_list* blacklist=0; +static grib_string_list* keys_list = NULL; /* Used to determine rank of key */ +static int isLeafKey = 0; /* 0 if key is top-level, 1 if key has no children attributes */ +static int compareAbsolute=1; static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options); static int compare_values(grib_runtime_options* options, grib_handle* handle1, grib_handle *handle2, const char *name, int type); @@ -55,27 +54,27 @@ static int compare_attributes(grib_handle* handle1, grib_handle* handle2, grib_r static int compare_attribute(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options, grib_accessor* a, const char* prefix, int* err); -int error=0; -int count=0; -int lastPrint=0; -int force=0; +static int error=0; +static int count=0; +static int lastPrint=0; +static int force=0; /* ECC-651: Boolean 'two_way' set to 1 when '-2' option used */ -int two_way=0; +static int two_way=0; /* Boolean 'handles_swapped' relevant in 'two_way' mode: * 0 means: h1 is first file, h2 is second file * 1 means: h1 is second file, h2 is first file */ -int handles_swapped=0; +static int handles_swapped=0; -double maxAbsoluteError = 1e-19; -int onlyListed=1; -int headerMode=0; -int morein1=0; -int morein2=0; -int listFromCommandLine; -int verbose=0; -int tolerance_factor=1; +static double maxAbsoluteError = 1e-19; +static int onlyListed=1; +static int headerMode=0; +static int morein1=0; +static int morein2=0; +static int listFromCommandLine; +static int verbose=0; +static int tolerance_factor=1; static int write_error=0; /* Create the list of keys (global variable keys_list) */ @@ -218,10 +217,10 @@ grib_option grib_options[]={ {"v",0,0,0,1,0} }; -grib_handle* global_handle=NULL; -int counter=0; -int start=-1; -int end=-1; +static grib_handle* global_handle=NULL; +static int counter=0; +static int start=-1; +static int end=-1; const char* grib_tool_description= "Compare BUFR messages contained in two files." @@ -628,8 +627,8 @@ static char* double_as_string(grib_context* c, double v) /* Return the part of the key name without the '#rank#' part */ static char* get_keyname_without_rank(const char* name) { - char* p=(char*)name; - char* pEnd=p; + const char* p=name; + char* pEnd; char* ret=NULL; if (*p=='#') { @@ -1122,7 +1121,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g save_error(c,name); printf("Cannot compare [%s], unsupported type %d\n",name,type1); return GRIB_UNABLE_TO_COMPARE_ACCESSORS; - break; } return GRIB_SUCCESS; @@ -1292,7 +1290,7 @@ static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runt if ( listFromCommandLine && onlyListed ) { for (i=0; i< options->compare_count; i++) { - if (blacklisted((char*)options->compare[i].name)) continue; + if (blacklisted(options->compare[i].name)) continue; if (options->compare[i].type == GRIB_NAMESPACE) { iter=grib_keys_iterator_new(handle1,0,options->compare[i].name); if (!iter) { diff --git a/tools/bufr_get.c b/tools/bufr_get.c index c1543fa6e..a2ff00a19 100644 --- a/tools/bufr_get.c +++ b/tools/bufr_get.c @@ -42,7 +42,6 @@ const char* grib_tool_name="bufr_get"; const char* grib_tool_usage="[options] file file ..."; int grib_options_count=sizeof(grib_options)/sizeof(grib_option); -grib_nearest* n=NULL; int main(int argc, char *argv[]) { diff --git a/tools/grib_compare.c b/tools/grib_compare.c index b86229d86..0686d7566 100644 --- a/tools/grib_compare.c +++ b/tools/grib_compare.c @@ -19,8 +19,8 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b) GRIB_INLINE static int grib_inline_rstrcmp(const char* a,const char* b) { - char* p=(char*)a; - char* q=(char*)b; + const char* p=a; + const char* q=b; while (*p != 0) p++; while (*q != 0) q++; q--;p--; @@ -38,37 +38,36 @@ struct grib_error { grib_error* next; }; -grib_error* error_summary; - -compare_double_proc compare_double; -double global_tolerance=0; -int packingCompare=0; -grib_string_list* blacklist=0; -int compareAbsolute=1; +static grib_error* error_summary; +static compare_double_proc compare_double; +static double global_tolerance=0; +static int packingCompare=0; +static grib_string_list* blacklist=0; +static int compareAbsolute=1; static int compare_handles(grib_handle* h1,grib_handle* h2,grib_runtime_options* options); static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_handle *h2,const char *name,int type); -int error=0; -int count=0; -int lastPrint=0; -int force=0; +static int error=0; +static int count=0; +static int lastPrint=0; +static int force=0; /* ECC-651: Boolean 'two_way' set to 1 when '-2' option used */ -int two_way=0; +static int two_way=0; /* Boolean 'handles_swapped' relevant in 'two_way' mode: * 0 means: h1 is first file, h2 is second file * 1 means: h1 is second file, h2 is first file */ -int handles_swapped=0; +static int handles_swapped=0; -double maxAbsoluteError = 1e-19; -int onlyListed=1; -int headerMode=0; -int morein1=0; -int morein2=0; -int listFromCommandLine; -int verbose=0; -double tolerance_factor=1; +static double maxAbsoluteError = 1e-19; +static int onlyListed=1; +static int headerMode=0; +static int morein1=0; +static int morein2=0; +static int listFromCommandLine; +static int verbose=0; +static double tolerance_factor=1; /* Returns 0 when the values are considered the same */ static double compare_double_absolute(double *a,double *b,double tolerance) @@ -150,10 +149,10 @@ grib_option grib_options[]={ {"v",0,0,0,1,0} }; -grib_handle* global_handle=NULL; -int global_counter=0; -int theStart=-1; -int theEnd=-1; +static grib_handle* global_handle=NULL; +static int global_counter=0; +static int theStart=-1; +static int theEnd=-1; const char* grib_tool_description= "Compare GRIB messages contained in two files." @@ -1074,7 +1073,6 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han save_error(c,name); printf("Cannot compare [%s], unsupported type %d\n",name,type1); return GRIB_UNABLE_TO_COMPARE_ACCESSORS; - break; } return GRIB_SUCCESS; diff --git a/tools/grib_get.c b/tools/grib_get.c index c1cb080a5..200078fd0 100644 --- a/tools/grib_get.c +++ b/tools/grib_get.c @@ -46,10 +46,10 @@ const char* grib_tool_name="grib_get"; const char* grib_tool_usage="[options] grib_file grib_file ..."; int grib_options_count=sizeof(grib_options)/sizeof(grib_option); -double lat=0; -double lon=0; -int mode=0; -grib_nearest* nearest=NULL; +static double lat=0; +static double lon=0; +static int mode=0; +static grib_nearest* nearest=NULL; int main(int argc, char *argv[]) { diff --git a/tools/grib_index_build.c b/tools/grib_index_build.c index 711d505aa..5cc416f42 100644 --- a/tools/grib_index_build.c +++ b/tools/grib_index_build.c @@ -18,9 +18,9 @@ const char* grib_tool_description="Build an index file for a set of input GRIB files."; const char* grib_tool_name="grib_index_build"; const char* grib_tool_usage="[options] grib_file grib_file ... "; -grib_index* idx=NULL; -char* keys; -char* default_keys = "mars"; +static grib_index* idx=NULL; +static char* keys; +static char* default_keys = "mars"; grib_option grib_options[]={ /* {id, args, help}, on, command_line, value */ @@ -39,7 +39,7 @@ grib_option grib_options[]={ } }; -int compress_index; +static int compress_index; int grib_options_count=sizeof(grib_options)/sizeof(grib_option); diff --git a/tools/grib_ls.c b/tools/grib_ls.c index b9d615715..0cfd9e129 100644 --- a/tools/grib_ls.c +++ b/tools/grib_ls.c @@ -49,12 +49,11 @@ const char* grib_tool_usage="[options] grib_file grib_file ..."; static char* new_handle=""; int grib_options_count=sizeof(grib_options)/sizeof(grib_option); -double lat=0; -double lon=0; -int mode=0; +static double lat=0; +static double lon=0; +static int mode=0; static int json_latlon=0; - -grib_nearest* nearest=NULL; +static grib_nearest* nearest=NULL; int main(int argc, char *argv[]) { diff --git a/tools/grib_options.c b/tools/grib_options.c index 9019a362e..bd470e913 100644 --- a/tools/grib_options.c +++ b/tools/grib_options.c @@ -21,11 +21,11 @@ extern int optind; #include "wingetopt.h" #endif -const char* names[]={"parameter","vertical","geography","data","mars","local"}; -int names_count=6; +static const char* names[]={"parameter","vertical","geography","data","mars","local"}; +static int names_count=6; /* id,args,help */ -grib_options_help grib_options_help_list[] ={ +static grib_options_help grib_options_help_list[] ={ {"a",0,"Dump aliases.\n"}, {"b:","key,key,...", "\n\t\tAll the keys in this list are skipped in the comparison. Bit-by-bit compare on.\n"}, @@ -111,7 +111,7 @@ grib_options_help grib_options_help_list[] ={ }; -int grib_options_help_count=sizeof(grib_options_help_list)/sizeof(grib_options_help); +static int grib_options_help_count=sizeof(grib_options_help_list)/sizeof(grib_options_help); void usage(void) diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index fa4e9da5b..8a3d14f7e 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -1798,8 +1798,7 @@ static hypercube *new_simple_hypercube_from_mars_request(const request *r) /*===========================================================================================*/ -/* Todo: - - BUILD A TEST SUITE !! +/* TODO: - Print usage in log file - consider FCMONTH and Climatology - Build logic to create validationtime when only one of DATE or TIME or STEP have multiple values: @@ -2046,7 +2045,7 @@ static void validation_time(request *r) } } v = julian * 24.0 + fcmonthdays * 24.0 + time / 100.0 + step * 1.0; - grib_context_log(ctx, GRIB_LOG_DEBUG, "grib_to_netcdf: date=%ld, julian=%ld, fcmonthdays=%ld, time=%ld, step=%g, validation=%ld", date, julian, fcmonthdays, time, step, v); + grib_context_log(ctx, GRIB_LOG_DEBUG, "grib_to_netcdf: date=%ld, julian=%ld, fcmonthdays=%ld, time=%ld, step=%g, validation=%.3f", date, julian, fcmonthdays, time, step, v); set_value(r, "_validation", "%lf", v); set_value(r, "_juliandate", "%ld", julian); diff --git a/tools/grib_tools.c b/tools/grib_tools.c index e5670444c..0af0b46e6 100644 --- a/tools/grib_tools.c +++ b/tools/grib_tools.c @@ -46,7 +46,7 @@ static int scan(grib_context* c,grib_runtime_options* options,const char* dir); FILE* dump_file; -grib_runtime_options global_options={ +static grib_runtime_options global_options={ 0, /* verbose */ 0, /* fail */ 0, /* skip */ @@ -196,7 +196,7 @@ static int grib_tool_with_orderby(grib_runtime_options* options) grib_handle* h=NULL; grib_tools_file* infile=options->infile; char** filenames; - size_t files_count=0; + int files_count=0; grib_fieldset* set=NULL; int i=0; grib_context* c=grib_context_get_default(); @@ -270,7 +270,7 @@ static int grib_tool_with_orderby(grib_runtime_options* options) return 0; } -char iobuf[1024*1024]; +static char iobuf[1024*1024]; static int grib_tool_without_orderby(grib_runtime_options* options) { @@ -669,8 +669,8 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle for (i=0;irequested_print_keys_count;i++) { options->print_keys[options->print_keys_count].name=options->requested_print_keys[i].name; - if (strlen(options->requested_print_keys[i].name)>options->default_print_width) - options->default_print_width=strlen(options->requested_print_keys[i].name); + if (strlen(options->requested_print_keys[i].name) > options->default_print_width) + options->default_print_width = (int)strlen(options->requested_print_keys[i].name); options->print_keys[options->print_keys_count].type=options->requested_print_keys[i].type; options->print_keys_count++; } @@ -693,7 +693,7 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle } options->print_keys[options->print_keys_count].name=strdup(name); if (strlen(name)>options->default_print_width) - options->default_print_width=strlen(name); + options->default_print_width=(int)strlen(name); options->print_keys[options->print_keys_count].type=GRIB_TYPE_STRING; options->print_keys_count++; } @@ -701,14 +701,14 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle grib_keys_iterator_delete(kiter); if (options->print_keys_count==0 && options->latlon == 0 ) { int j=0,k=0,ns_count=0; - char* all_namespace_vals[1024] = {NULL,}; /* sorted array containing all namespaces */ + const char* all_namespace_vals[1024] = {NULL,}; /* sorted array containing all namespaces */ printf("ERROR: namespace \"%s\" does not contain any key.\n",ns); printf("Here are the available namespaces in this message:\n"); for (i=0; iaccessors[i]; if (anAccessor) { for (j=0; jall_name_spaces[j]; + const char* a_namespace = anAccessor->all_name_spaces[j]; if (a_namespace) { all_namespace_vals[k++] = a_namespace; ns_count++; @@ -974,7 +974,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h) } } - strlenvalue = strlen(value); + strlenvalue = (int)strlen(value); width = strlenvalue < options->default_print_width ? options->default_print_width + 2 : @@ -999,7 +999,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h) written_to_dump=1; } else if (options->latlon_mode==1) { sprintf(value,options->format,options->values[options->latlon_idx]); - strlenvalue = strlen(value); + strlenvalue = (int)strlen(value); width = strlenvalue < options->default_print_width ? options->default_print_width + 2 : strlenvalue + 2; @@ -1035,7 +1035,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h) } sprintf(value,options->format,v); - strlenvalue = strlen(value); + strlenvalue = (int)strlen(value); width = strlenvalue < options->default_print_width ? options->default_print_width + 2 : strlenvalue + 2;