Merge branch 'develop' into feature/FireInMars

This commit is contained in:
Sebastien Villaume 2022-03-10 16:38:40 +00:00
commit 7c73868638
114 changed files with 9343 additions and 8611 deletions

View File

@ -2,7 +2,7 @@
# general configuration #
#---------------------------------#
version: 2.25.0-{build}-{branch}
version: latest-{build}-{branch}
branches:
only:

View File

@ -21,7 +21,7 @@ cmake_minimum_required( VERSION 3.12 FATAL_ERROR )
find_package( ecbuild 3.4 REQUIRED HINTS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../ecbuild)
# Initialise project
project( eccodes VERSION 2.25.0 LANGUAGES C )
project( eccodes VERSION 2.26.0 LANGUAGES C )
###############################################################################
# system checks needed for eccodes_config.h and some options like MEMFS
@ -116,7 +116,10 @@ ecbuild_add_option( FEATURE NETCDF
find_package( AEC )
if(NOT DEFINED ENABLE_AEC AND NOT AEC_FOUND)
ecbuild_critical("AEC (Adaptive Entropy Coding) support is highly recommended from ecCodes >= 2.25.0\nTo force the build without it, use -DENABLE_AEC=OFF")
ecbuild_critical("AEC library was not found.\n"
"AEC (Adaptive Entropy Coding) provides the WMO GRIB CCSDS compression and decompression of data. "
"This is highly recommended from ecCodes >= 2.25.0"
"\nTo force the build without it, use -DENABLE_AEC=OFF")
endif()
ecbuild_add_option( FEATURE AEC
DESCRIPTION "Support for Adaptive Entropy Coding"

View File

@ -23,10 +23,10 @@
# LIBAEC_PATH
# libaec_PATH
find_path( AEC_INCLUDE_DIR szlib.h
find_path( AEC_INCLUDE_DIR libaec.h
PATHS ${AEC_DIR} ${AEC_PATH} ${LIBAEC_DIR} ${libaec_DIR} ${LIBAEC_PATH} ${libaec_PATH} ENV AEC_DIR ENV AEC_PATH ENV LIBAEC_DIR ENV libaec_DIR ENV LIBAEC_PATH ENV libaec_PATH
PATH_SUFFIXES include include/aec NO_DEFAULT_PATH )
find_path( AEC_INCLUDE_DIR szlib.h PATH_SUFFIXES include include/aec )
find_path( AEC_INCLUDE_DIR libaec.h PATH_SUFFIXES include include/aec )
find_library( AEC_LIBRARY NAMES aec
PATHS ${AEC_DIR} ${AEC_PATH} ${LIBAEC_DIR} ${libaec_DIR} ${LIBAEC_PATH} ${libaec_PATH} ENV AEC_DIR ENV AEC_PATH ENV LIBAEC_DIR ENV libaec_DIR ENV LIBAEC_PATH ENV libaec_PATH

View File

@ -10,9 +10,10 @@ add_subdirectory(gts)
file(READ "grib_data_files.txt" files_to_download)
string(REGEX REPLACE "\n" ";" files_to_download "${files_to_download}")
# Download the CCSDS file even if HAVE_AEC feature is disabled.
# Download the CCSDS files even if HAVE_AEC feature is disabled.
# This is for testing (See ECC-1352)
list(APPEND files_to_download ccsds.grib2)
list(APPEND files_to_download ccsds_szip.grib2) # See ECC-1362
if( ENABLE_EXTRA_TESTS )

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 13 May 2013
##

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 13 May 2013
##

View File

@ -61,7 +61,7 @@ if(matrixOfValues == 0)
# For grib1 -> grib2
constant bitMapIndicator = 0;
meta codedValues data_g1simple_packing (
meta codedValues data_g1simple_packing(
section4Length,
offsetBeforeData,
offsetSection4,

View File

@ -12,7 +12,7 @@
#model 52 I1 44 -
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 May 2013
#

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 20 Feb 2014
#

View File

@ -23,7 +23,7 @@
#PartDef 74 PAD n/a 7
################################################################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 20 Feb 2014
#

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 May 2013
#

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 13 May 2013
# modified:
#
#########################
"none"={matchAerosolBinNumber=0;}

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 13 May 2013
##

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 13 May 2013
# modified:
#
#########################
"all"={matchLandType=0;}

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 13 May 2013
##

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 13 May 2013
##

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 13 May 2013
# modified:
#
#########################
"none"={matchSort=0;}

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 13 May 2013
# modified:
#
#########################
"none"={matchTimeRepres=0;}

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 13 May 2013
##

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 May 2013
#

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 May 2013
#

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 Sep 2013
#

View File

@ -1,20 +1,14 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume (SMHI)
# created: 6 Oct 2011
# modified: 13 Sep 2013
#
#########################
constant conceptsMasterMarsDir="mars" : hidden;
constant conceptsLocalMarsDirAll="mars/[centre:s]" : hidden;
# Base MARS keywors
##########################
# #
# Base MARS keywors #
# #
##########################
alias mars.class = marsClass;
alias mars.type = marsType;
alias mars.stream = marsStream;
@ -22,22 +16,13 @@ alias mars.model = marsModel;
alias mars.expver = experimentVersionNumber;
alias mars.domain = globalDomain;
# local section 82
#########################
# #
# local section 82 #
# #
#########################
### nothing needed here...
# Local section 83
#########################
# #
# local section 83 #
# #
#########################
if ( localDefinitionNumber == 83 ) {
alias mars.sort = matchSort;
alias mars.timerepres = matchTimeRepres;
alias mars.landtype = matchLandType;
@ -45,6 +30,4 @@ if ( localDefinitionNumber == 83 ) {
concept_nofail matchAerosolPacking (unknown,"aerosolPackingConcept.def",conceptsLocalMarsDirAll,conceptsMasterMarsDir);
alias mars.aerosolpacking = matchAerosolPacking;
}

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#################################
### LOCAL SECTION DESCRIPTION ###

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#################################
### LOCAL SECTION DESCRIPTION ###

View File

@ -1,8 +1,7 @@
#################################################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#################################
### LOCAL SECTION DESCRIPTION ###

View File

@ -50,3 +50,22 @@ unsigned[1] minuteOfModelVersion = 0 : dump;
constant secondOfModelVersion = 0;
meta dateOfModelVersion g2date(yearOfModelVersion, monthOfModelVersion, dayOfModelVersion) : dump;
meta timeOfModelVersion time (hourOfModelVersion, minuteOfModelVersion, secondOfModelVersion) : dump;
# Note: the key inputOriginatingCentre is in the PDTNs 70, 71, 72 and 73
#concept efas_forecast {
# "griddedobs" = { inputOriginatingCentre=98; marsType = "an"; }
# # "reanalysis" = { inputOriginatingCentre=98; marsType = "an"; }
#
# "hres" = { inputOriginatingCentre=98; marsType = "fc"; } # deterministic
# "ens" = { inputOriginatingCentre=98; marsType = "pf"; } # ensemble
# "ens" = { inputOriginatingCentre=98; marsType = "cf"; } # ensemble
#
# DWD rules
# "global" = { inputOriginatingCentre=78; inputProcessIdentifier = 1; }
# "lam" = { inputOriginatingCentre=78; inputProcessIdentifier = 2; }
#
# TODO: For now anything coming from cnmc (COSMO) is local area
# "lam" = { inputOriginatingCentre=80; }
#
# "unknown" = { dummy = 1; }
#} : hidden;

View File

@ -8,4 +8,6 @@
typeOfSecondFixedSurface = 255 ;
scaledValueOfFirstFixedSurface = 0 ;
scaleFactorOfFirstFixedSurface = 0 ;
scaledValueOfSecondFixedSurface = missing() ;
scaleFactorOfSecondFixedSurface = missing() ;
}

View File

@ -158,4 +158,6 @@
typeOfSecondFixedSurface = 255 ;
scaledValueOfFirstFixedSurface = 0 ;
scaleFactorOfFirstFixedSurface = 0 ;
scaledValueOfSecondFixedSurface = missing() ;
scaleFactorOfSecondFixedSurface = missing() ;
}

View File

@ -158,4 +158,6 @@
typeOfSecondFixedSurface = 255 ;
scaledValueOfFirstFixedSurface = 0 ;
scaleFactorOfFirstFixedSurface = 0 ;
scaledValueOfSecondFixedSurface = missing() ;
scaleFactorOfSecondFixedSurface = missing() ;
}

View File

@ -158,4 +158,6 @@
typeOfSecondFixedSurface = 255 ;
scaledValueOfFirstFixedSurface = 0 ;
scaleFactorOfFirstFixedSurface = 0 ;
scaledValueOfSecondFixedSurface = missing() ;
scaleFactorOfSecondFixedSurface = missing() ;
}

View File

@ -158,4 +158,6 @@
typeOfSecondFixedSurface = 255 ;
scaledValueOfFirstFixedSurface = 0 ;
scaleFactorOfFirstFixedSurface = 0 ;
scaledValueOfSecondFixedSurface = missing() ;
scaleFactorOfSecondFixedSurface = missing() ;
}

View File

@ -158,4 +158,6 @@
typeOfSecondFixedSurface = 255 ;
scaledValueOfFirstFixedSurface = 0 ;
scaleFactorOfFirstFixedSurface = 0 ;
scaledValueOfSecondFixedSurface = missing() ;
scaleFactorOfSecondFixedSurface = missing() ;
}

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#########################

View File

@ -1,6 +1,5 @@
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#########################

View File

@ -1,4 +1,4 @@
"unknown" = { typeOfPostProcessing = 0; }
# For template.4.postproc.def
"lisflood" = { typeOfPostProcessing = 1; }
"lisflood_eric" = { typeOfPostProcessing = 2; }
"lisflood_season" = { typeOfPostProcessing = 3; }
@ -15,4 +15,3 @@
"mhm_mrm" = { typeOfPostProcessing = 203; }
"pcrg_mrm" = { typeOfPostProcessing = 204; }
"meteogrid" = { typeOfPostProcessing = 205; }

View File

@ -1,6 +1,5 @@
# (C) Copyright 2005- ECMWF.
# TEMPLATE 3.4, Variable resolution latitude/longitude
include "grib2/template.3.shape_of_the_earth.def";
include "grib2/template.3.latlon_vares.def";

View File

@ -1,4 +1,5 @@
# (C) Copyright 2005- ECMWF.
# Atmospheric chemical or physical constituent type
# Aerosol type
codetable[2] aerosolType ('4.233.table',masterDir,localDir) : dump;
meta aerosolTypeName codetable_title(aerosolType);

View File

@ -16,4 +16,3 @@ concept postProcessing (unknown,"postProcessingConcept.def",conceptsDir2,concept
if (datasetForLocal is "fire") {
template_nofail fireTemplate "grib2/fireTemplate.def";
}

View File

@ -47,7 +47,7 @@ ieeefloat coefsSecond[NC2]; # TODO: find proper names
alias data.coefsFirst = coefsFirst;
alias data.coefsSecond=coefsSecond;
if(matrixBitmapsPresent == 1) {
if (matrixBitmapsPresent == 1) {
constant datumSize = NC*NR;
constant secondaryBitmapsCount = numberOfValues + 0;
constant secondaryBitmapsSize = secondaryBitmapsCount/8;

View File

@ -31,7 +31,6 @@ transient numberOfPackedValues = numberOfValues - 1 : no_copy;
numberOfValues
) ;
meta packingError simple_packing_error(bitsPerValue,binaryScaleFactor,decimalScaleFactor,referenceValue,ieee) : no_copy;
meta unpackedError simple_packing_error(zero,binaryScaleFactor,decimalScaleFactor,referenceValue,ieee) : no_copy;

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#################################
### LOCAL SECTION DESCRIPTION ###

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#################################
### LOCAL SECTION DESCRIPTION ###

View File

@ -1,8 +1,7 @@
#################################################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#################################
### LOCAL SECTION DESCRIPTION ###

View File

@ -1,8 +1,7 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#########################

View File

@ -1,6 +1,5 @@
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 14 Feb 2014
# modified:
#
#########################

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 May 2013
#

View File

@ -1,6 +1,6 @@
#########################
##
## author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
## author: Sebastien Villaume
## created: 6 Oct 2011
## modified: 20 Feb 2014
##

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 20 Feb 2014
#

View File

@ -1,6 +1,6 @@
#########################
#
# author: Sebastien Villaume <Sebastien.Villaume@smhi.se>
# author: Sebastien Villaume
# created: 6 Oct 2011
# modified: 13 May 2013
#

View File

@ -82,6 +82,7 @@ if( HAVE_BUILD_TOOLS )
grib_set_bitmap
grib_list
grib_get_data
grib_nearest
grib_nearest_multiple
grib_multi
grib_set_missing

View File

@ -35,14 +35,14 @@ int main(int argc, char** argv)
int i = 0;
codes_fieldset* set = NULL;
codes_handle* h = NULL;
char param[20] = {0,};
char shortName[20] = {0,};
size_t len = 20;
double lats[4] = {0,};
double lons[4] = {0,};
double values[4] = {0,};
double distances[4] = {0,};
int indexes[4] = {0,};
char* order_by = "param,step";
char* order_by = "shortName,step:i";
size_t size = 4;
double lat = -40, lon = 15;
@ -63,7 +63,6 @@ int main(int argc, char** argv)
printf("\nordering by %s\n", order_by);
printf("\n%d fields in the fieldset\n", codes_fieldset_count(set));
printf("n,step,param\n");
mode = CODES_NEAREST_SAME_GRID | CODES_NEAREST_SAME_POINT;
count = 1;
@ -71,9 +70,9 @@ int main(int argc, char** argv)
while ((h = codes_fieldset_next_handle(set, &err)) != NULL) {
CODES_CHECK(codes_get_long(h, "step", &step), 0);
len = 20;
CODES_CHECK(codes_get_string(h, "shortName", param, &len), 0);
CODES_CHECK(codes_get_string(h, "shortName", shortName, &len), 0);
printf("%d %ld %s ", count, step, param);
printf("Msg #%d, step=%ld, shortName=%s", count, step, shortName);
if (!nearest) nearest = codes_grib_nearest_new(h, &err);
CODES_CHECK(err, 0);
CODES_CHECK(codes_grib_nearest_find(nearest, h, lat, lon, mode, lats, lons, values, distances, indexes, &size), 0);
@ -91,5 +90,9 @@ int main(int argc, char** argv)
if (set) codes_fieldset_delete(set);
for (i = 0; i < nfiles; i++)
free(filenames[i]);
free(filenames);
return 0;
}

66
examples/C/grib_nearest.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.sh
set -u
label="grib_nearest_c"
tempTxt=temp.$label.txt
tempRef=temp.$label.ref
input=${data_dir}/high_level_api.grib2
${examples_dir}/c_grib_nearest $input > $tempTxt
cat > $tempRef <<EOF
ordering by shortName,step:i
5 fields in the fieldset
Msg #1, step=0, shortName=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101524
58016 -40.85 14.40 107.078 101570
57617 -39.95 15.30 26.1625 101655
57616 -39.95 14.40 51.4303 101669
Msg #2, step=6, shortName=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101547
58016 -40.85 14.40 107.078 101605
57617 -39.95 15.30 26.1625 101589
57616 -39.95 14.40 51.4303 101641
Msg #3, step=12, shortName=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101606
58016 -40.85 14.40 107.078 101623
57617 -39.95 15.30 26.1625 101652
57616 -39.95 14.40 51.4303 101678
Msg #4, step=18, shortName=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101507
58016 -40.85 14.40 107.078 101486
57617 -39.95 15.30 26.1625 101573
57616 -39.95 14.40 51.4303 101571
Msg #5, step=24, shortName=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101379
58016 -40.85 14.40 107.078 101372
57617 -39.95 15.30 26.1625 101494
57616 -39.95 14.40 51.4303 101471
EOF
diff $tempRef $tempTxt
rm -f $tempTxt $tempRef

View File

@ -89,7 +89,7 @@ grib_handle* codes_fieldset_next_handle(grib_fieldset* set, int* err)
{
return grib_fieldset_next_handle(set, err);
}
int codes_fieldset_count(grib_fieldset* set)
int codes_fieldset_count(const grib_fieldset* set)
{
return grib_fieldset_count(set);
}

View File

@ -187,7 +187,7 @@ void codes_fieldset_delete(codes_fieldset* set);
void codes_fieldset_rewind(codes_fieldset* set);
int codes_fieldset_apply_order_by(codes_fieldset* set, const char* order_by_string);
codes_handle* codes_fieldset_next_handle(codes_fieldset* set, int* err);
int codes_fieldset_count(codes_fieldset* set);
int codes_fieldset_count(const codes_fieldset* set);
int codes_values_check(codes_handle* h, codes_values* values, int count);
/*! \defgroup codes_index The indexing feature

View File

@ -2467,7 +2467,8 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset
self->dataAccessors = grib_accessors_list_create(c);
if (self->dataAccessorsTrie) {
grib_trie_with_rank_delete(self->dataAccessorsTrie);
/* ECC-989: do not call grib_trie_with_rank_delete */
grib_trie_with_rank_delete_container(self->dataAccessorsTrie);
}
self->dataAccessorsTrie = grib_trie_with_rank_new(c);
@ -3466,8 +3467,10 @@ static void destroy(grib_context* c, grib_accessor* a)
self_clear(c, self);
if (self->dataAccessors)
grib_accessors_list_delete(c, self->dataAccessors);
if (self->dataAccessorsTrie)
if (self->dataAccessorsTrie) {
grib_trie_with_rank_delete_container(self->dataAccessorsTrie);
self->dataAccessorsTrie = NULL;
}
if (self->tempStrings) {
grib_sarray_delete_content(c, self->tempStrings);
grib_sarray_delete(c, self->tempStrings);

View File

@ -535,9 +535,10 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
*val = atol(p);
*len = 1;
#if 0
#ifdef DEBUG
/* ECC-980: Changes reverted because of side-effects!
* e.g. marsType being a codetable and concept! see ifsParam
* e.g. marsType being a codetable and concept! see ifsParam.
* Keep this check in DEBUG mode only
*/
{
char *endptr;

View File

@ -214,7 +214,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
grib_handle* hand = grib_handle_of_accessor(a);
int err = GRIB_SUCCESS, i = 0;
size_t buflen = grib_byte_count(a);
size_t buflen = 0;
struct aec_stream strm;
double bscale = 0;
double dscale = 0;
@ -260,9 +260,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
if ((err = grib_get_long_internal(hand, self->ccsds_rsi, &ccsds_rsi)) != GRIB_SUCCESS)
return err;
bscale = grib_power(binary_scale_factor, 2);
dscale = grib_power(-decimal_scale_factor, 10);
/* TODO: This should be called upstream */
if (*len < n_vals)
return GRIB_ARRAY_TOO_SMALL;
@ -275,6 +272,10 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return GRIB_SUCCESS;
}
bscale = grib_power(binary_scale_factor, 2);
dscale = grib_power(-decimal_scale_factor, 10);
buflen = grib_byte_count(a);
buf = (unsigned char*)hand->buffer->data;
buf += grib_byte_offset(a);

View File

@ -158,7 +158,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
{
grib_accessor_gaussian_grid_name* self = (grib_accessor_gaussian_grid_name*)a;
long N = 0, Ni = 0, isOctahedral = 0;
long N = 0, Ni = 0;
char tmp[MAX_GRIDNAME_LEN] = {0,};
size_t length = 0;
int ret = GRIB_SUCCESS;
@ -167,20 +167,21 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
return ret;
if ((ret = grib_get_long_internal(a->parent->h, self->Ni, &Ni)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(a->parent->h, self->isOctahedral, &isOctahedral)) != GRIB_SUCCESS)
return ret;
if (Ni == GRIB_MISSING_LONG) {
/* reduced gaussian grid */
/* Reduced gaussian grid */
long isOctahedral = 0;
if ((ret = grib_get_long_internal(a->parent->h, self->isOctahedral, &isOctahedral)) != GRIB_SUCCESS)
return ret;
if (isOctahedral == 1) {
sprintf(tmp, "O%ld", N);
}
else {
sprintf(tmp, "N%ld", N);
sprintf(tmp, "N%ld", N); /* Classic */
}
}
else {
/* regular gaussian grid */
/* Regular gaussian grid */
sprintf(tmp, "F%ld", N);
}
length = strlen(tmp) + 1;

View File

@ -321,8 +321,7 @@ static int unpack_double(grib_accessor* a, double* v, size_t* len)
grib_unpack_string(a, val, &l);
*v = strtod(val, &last);
if (*last == 0) {
if (*last == 0) { /* conversion of string to double worked */
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to long", a->name);
return GRIB_SUCCESS;
}
@ -515,7 +514,14 @@ static int pack_string(grib_accessor* a, const char* v, size_t* len)
{
if (a->cclass->pack_double && a->cclass->pack_double != &pack_double) {
size_t l = 1;
double val = atof(v);
char* endPtr = NULL; /* for error handling */
double val = strtod(v, &endPtr);
if (*endPtr) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"pack_string: Invalid value (%s) for %s. String cannot be converted to a double",
v, a->name);
return GRIB_WRONG_TYPE;
}
return grib_pack_double(a, &val, &l);
}
@ -525,8 +531,7 @@ static int pack_string(grib_accessor* a, const char* v, size_t* len)
return grib_pack_long(a, &val, &l);
}
grib_context_log(a->context, GRIB_LOG_ERROR,
"Should not grib_pack %s as string", a->name);
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack '%s' as string", a->name);
return GRIB_NOT_IMPLEMENTED;
}

View File

@ -294,8 +294,7 @@ static int compare(grib_accessor* a, grib_accessor* b)
static int pack_string(grib_accessor* a, const char* val, size_t* len)
{
char* theEnd = NULL;
long v = 0;
long v = 0; /* The converted value */
#if 0
/* Requires more work e.g. filter */
@ -304,9 +303,9 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
}
#endif
v = strtol(val, &theEnd, 10);
if (theEnd) {
grib_context_log(a->context, GRIB_LOG_ERROR, "trying to pack \"%s\" as long", val);
if (string_to_long(val, &v) != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"Trying to pack \"%s\" as long. String cannot be converted to an integer", val);
return GRIB_WRONG_TYPE;
}
return grib_pack_long(a, &v, len);

View File

@ -240,7 +240,7 @@ void grib_fieldset_delete(grib_fieldset* set);
void grib_fieldset_rewind(grib_fieldset* set);
int grib_fieldset_apply_order_by(grib_fieldset* set, const char* order_by_string);
grib_handle* grib_fieldset_next_handle(grib_fieldset* set, int* err);
int grib_fieldset_count(grib_fieldset* set);
int grib_fieldset_count(const grib_fieldset* set);
int grib_values_check(grib_handle* h, grib_values* values, int count);
/*! \defgroup grib_index The grib_index

View File

@ -219,7 +219,6 @@ size_t grib_sarray_used_size(grib_sarray* v);
grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize);
grib_oarray* grib_oarray_push(grib_context* c, grib_oarray* v, void* val);
void grib_oarray_delete(grib_context* c, grib_oarray* v);
void grib_oarray_delete_content(grib_context* c, grib_oarray* v);
void** grib_oarray_get_array(grib_context* c, grib_oarray* v);
void* grib_oarray_get(grib_oarray* v, int i);
size_t grib_oarray_used_size(grib_oarray* v);
@ -675,14 +674,12 @@ bufr_descriptors_array* grib_accessor_class_expanded_descriptors_get_expanded(gr
/* grib_accessor_class_md5.c */
/* grib_jasper_encoding.c */
int grib_jasper_decode(grib_context* c, unsigned char* buf, size_t* buflen, double* values, size_t* no_values);
int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper);
int grib_jasper_decode(grib_context* c, unsigned char* buf, size_t* buflen, double* val, size_t* n_vals);
int grib_jasper_decode(grib_context* c, unsigned char* buf, const size_t* buflen, double* values, const size_t* n_vals);
int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper);
/* grib_openjpeg_encoding.c */
int grib_openjpeg_decode(grib_context* c, unsigned char* buf, const size_t* buflen, double* values, const size_t* n_vals);
int grib_openjpeg_encode(grib_context* c, j2k_encode_helper* helper);
int grib_openjpeg_decode(grib_context* c, unsigned char* buf, const size_t* buflen, double* val, const size_t* n_vals);
/* action_class_set_missing.c */
grib_action* grib_action_create_set_missing(grib_context* context, const char* name);
@ -714,7 +711,6 @@ grib_index* grib_index_read(grib_context* c, const char* filename, int* err);
int grib_index_search_same(grib_index* index, grib_handle* h);
int grib_index_add_file(grib_index* index, const char* filename);
int _codes_index_add_file(grib_index* index, const char* filename, int message_type);
int grib_index_add_file(grib_index* index, const char* filename);
grib_index* grib_index_new_from_file(grib_context* c, const char* filename, const char* keys, int* err);
int grib_index_get_size(const grib_index* index, const char* key, size_t* size);
int grib_index_get_string(const grib_index* index, const char* key, char** values, size_t* size);
@ -815,14 +811,6 @@ void grib_timer_print(grib_timer* t);
void grib_timer_partial_rate(grib_timer* t, double start, long total);
void grib_print_all_timers(void);
void grib_reset_all_timers(void);
grib_timer* grib_get_timer(grib_context* c, const char* name, const char* statname, int elapsed);
int grib_timer_start(grib_timer* t);
int grib_timer_stop(grib_timer* t, long total);
double grib_timer_value(grib_timer* t);
void grib_timer_print(grib_timer* t);
void grib_timer_partial_rate(grib_timer* t, double start, long total);
void grib_print_all_timers(void);
void grib_reset_all_timers(void);
/* grib_ibmfloat.c */
unsigned long grib_ibm_to_long(double x);
@ -841,15 +829,10 @@ double grib_ieeefloat_error(double x);
double grib_long_to_ieee(unsigned long x);
unsigned long grib_ieee_nearest_smaller_to_long(double x);
int grib_nearest_smaller_ieee_float(double a, double* ret);
double grib_ieeefloat_error(double x);
double grib_long_to_ieee(unsigned long x);
int grib_nearest_smaller_ieee_float(double a, double* x);
unsigned long grib_ieee_to_long(double x);
unsigned long grib_ieee64_to_long(double x);
double grib_long_to_ieee64(unsigned long x);
int grib_ieee_decode_array(grib_context* c, unsigned char* buf, size_t nvals, int bytes, double* val);
int grib_ieee_decode_array(grib_context* c, unsigned char* buf, size_t nvals, int bytes, double* val);
int grib_ieee_encode_array(grib_context* c, double* val, size_t nvals, int bytes, unsigned char* buf);
int grib_ieee_encode_array(grib_context* c, double* val, size_t nvals, int bytes, unsigned char* buf);
/* grib_accessor_class_reference_value_error.c */
@ -1008,10 +991,10 @@ int grib_fieldset_apply_where(grib_fieldset* set, const char* where_string);
int grib_fieldset_apply_order_by(grib_fieldset* set, const char* order_by_string);
void grib_fieldset_delete_order_by(grib_context* c, grib_order_by* order_by);
void grib_fieldset_delete(grib_fieldset* set);
int grib_fieldset_add(grib_fieldset* set, char* filename);
int grib_fieldset_add(grib_fieldset* set, const char* filename);
void grib_fieldset_rewind(grib_fieldset* set);
grib_handle* grib_fieldset_next_handle(grib_fieldset* set, int* err);
int grib_fieldset_count(grib_fieldset* set);
int grib_fieldset_count(const grib_fieldset* set);
grib_handle* grib_fieldset_retrieve(grib_fieldset* set, int i, int* err);
/* grib_filepool.c */
@ -1138,8 +1121,6 @@ void* grib_trie_get(grib_trie* t, const char* key);
/* grib_trie_with_rank.c */
grib_trie_with_rank* grib_trie_with_rank_new(grib_context* c);
void grib_trie_with_rank_delete_container(grib_trie_with_rank* t);
void grib_trie_with_rank_delete(grib_trie_with_rank* t);
void grib_trie_with_rank_clear(grib_trie_with_rank* t);
int grib_trie_with_rank_insert(grib_trie_with_rank* t, const char* key, void* data);
void* grib_trie_with_rank_get(grib_trie_with_rank* t, const char* key, int rank);

View File

@ -44,13 +44,10 @@ static grib_fieldset* grib_fieldset_create_from_order_by(grib_context* c, grib_o
static int grib_fieldset_resize(grib_fieldset* set, size_t newsize);
static void grib_trim(char** x);
static grib_order_by* grib_fieldset_new_order_by(grib_context* c, const char* z);
static int grib_fieldset_compare(grib_fieldset* set, int* i, int* j);
static void grib_fieldset_sort(grib_fieldset* set, int beg, int theEnd);
static int grib_fieldset_columns_resize(grib_fieldset* set, size_t newsize);
static void grib_fieldset_sort(grib_fieldset* set, int theStart, int theEnd);
static grib_int_array* grib_fieldset_create_int_array(grib_context* c, size_t size);
static int grib_fieldset_resize_int_array(grib_int_array* a, size_t newsize);
static void grib_fieldset_delete_int_array(grib_int_array* f);
static void grib_fieldset_delete_columns(grib_fieldset* set);
static grib_field** grib_fieldset_create_fields(grib_context* c, size_t size);
static void grib_fieldset_delete_fields(grib_fieldset* set);
static int grib_fieldset_resize_fields(grib_fieldset* set, size_t newsize);
@ -60,7 +57,7 @@ static int grib_fieldset_set_order_by(grib_fieldset* set, grib_order_by* ob);
/* --------------- grib_column functions ------------------*/
int grib_fieldset_new_column(grib_fieldset* set, int id, char* key, int type)
{
grib_column* column = 0;
grib_column* column = NULL;
grib_context* c;
int err = 0;
@ -69,38 +66,34 @@ int grib_fieldset_new_column(grib_fieldset* set, int id, char* key, int type)
c = set->context;
set->columns[id].errors = (int*)grib_context_malloc_clear(c,
sizeof(int) * GRIB_START_ARRAY_SIZE);
set->columns[id].errors = (int*)grib_context_malloc_clear(c, sizeof(int) * GRIB_START_ARRAY_SIZE);
switch (type) {
case GRIB_TYPE_LONG:
set->columns[id].long_values = (long*)grib_context_malloc_clear(c,
sizeof(long) * GRIB_START_ARRAY_SIZE);
set->columns[id].long_values = (long*)grib_context_malloc_clear(c, sizeof(long) * GRIB_START_ARRAY_SIZE);
if (!set->columns[id].long_values) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_new_column : Cannot malloc %ld bytes",
"grib_fieldset_new_column: Cannot malloc %ld bytes",
sizeof(long) * GRIB_START_ARRAY_SIZE);
err = GRIB_OUT_OF_MEMORY;
return err;
}
break;
case GRIB_TYPE_DOUBLE:
set->columns[id].double_values = (double*)grib_context_malloc_clear(c,
sizeof(double) * GRIB_START_ARRAY_SIZE);
set->columns[id].double_values = (double*)grib_context_malloc_clear(c, sizeof(double) * GRIB_START_ARRAY_SIZE);
if (!set->columns[id].double_values) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_new_column : Cannot malloc %ld bytes",
"grib_fieldset_new_column: Cannot malloc %ld bytes",
sizeof(double) * GRIB_START_ARRAY_SIZE);
err = GRIB_OUT_OF_MEMORY;
return err;
}
break;
case GRIB_TYPE_STRING:
set->columns[id].string_values = (char**)grib_context_malloc_clear(c,
sizeof(char*) * GRIB_START_ARRAY_SIZE);
set->columns[id].string_values = (char**)grib_context_malloc_clear(c, sizeof(char*) * GRIB_START_ARRAY_SIZE);
if (!set->columns[id].string_values) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_new_column : Cannot malloc %ld bytes",
"grib_fieldset_new_column: Cannot malloc %ld bytes",
sizeof(char*) * GRIB_START_ARRAY_SIZE);
err = GRIB_OUT_OF_MEMORY;
return err;
@ -108,7 +101,7 @@ int grib_fieldset_new_column(grib_fieldset* set, int id, char* key, int type)
break;
default:
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_new_column : unknown column type %d", type);
"grib_fieldset_new_column: Unknown column type %d", type);
grib_context_free(c, column);
return err;
}
@ -146,7 +139,7 @@ static void grib_fieldset_delete_columns(grib_fieldset* set)
break;
default:
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_new_column : unknown column type %d", set->columns[i].type);
"grib_fieldset_new_column: Unknown column type %d", set->columns[i].type);
}
grib_context_free(c, set->columns[i].errors);
grib_context_free(c, set->columns[i].name);
@ -178,7 +171,8 @@ static int grib_fieldset_columns_resize(grib_fieldset* set, size_t newsize)
newsize * sizeof(long));
if (!newlongs) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_columns_resize : Cannot malloc %ld bytes", newsize - set->columns[i].values_array_size);
"grib_fieldset_columns_resize: Cannot malloc %ld bytes",
newsize - set->columns[i].values_array_size);
return GRIB_OUT_OF_MEMORY;
}
else
@ -189,7 +183,8 @@ static int grib_fieldset_columns_resize(grib_fieldset* set, size_t newsize)
newsize * sizeof(double));
if (!newdoubles) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_columns_resize : Cannot malloc %ld bytes", newsize - set->columns[i].values_array_size);
"grib_fieldset_columns_resize: Cannot malloc %ld bytes",
newsize - set->columns[i].values_array_size);
return GRIB_OUT_OF_MEMORY;
}
else
@ -200,7 +195,8 @@ static int grib_fieldset_columns_resize(grib_fieldset* set, size_t newsize)
newsize * sizeof(char*));
if (!newstrings) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_columns_resize : Cannot malloc %ld bytes", newsize - set->columns[i].values_array_size);
"grib_fieldset_columns_resize: Cannot malloc %ld bytes",
newsize - set->columns[i].values_array_size);
return GRIB_OUT_OF_MEMORY;
}
else
@ -210,7 +206,7 @@ static int grib_fieldset_columns_resize(grib_fieldset* set, size_t newsize)
newerrors = (int*)grib_context_realloc(c, set->columns[i].errors, newsize * sizeof(int));
if (!newerrors) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_columns_resize : Cannot malloc %ld bytes",
"grib_fieldset_columns_resize: Cannot malloc %ld bytes",
newsize * sizeof(int));
return GRIB_OUT_OF_MEMORY;
}
@ -266,7 +262,7 @@ grib_fieldset* grib_fieldset_new_from_files(grib_context* c, char* filenames[],
int ret = GRIB_SUCCESS;
grib_order_by* ob = NULL;
grib_fieldset* set = 0;
grib_fieldset* set = NULL;
if (!c)
c = grib_context_get_default();
@ -300,8 +296,13 @@ grib_fieldset* grib_fieldset_new_from_files(grib_context* c, char* filenames[],
}
}
if (where_string)
grib_fieldset_apply_where(set, where_string);
if (where_string) {
ret = grib_fieldset_apply_where(set, where_string);
if (ret != GRIB_SUCCESS) {
*err = ret;
return NULL;
}
}
if (order_by_string) {
if (!set->order_by && ob)
@ -315,10 +316,9 @@ grib_fieldset* grib_fieldset_new_from_files(grib_context* c, char* filenames[],
return set;
}
static grib_fieldset* grib_fieldset_create_from_keys(grib_context* c, char** keys, int nkeys,
int* err)
static grib_fieldset* grib_fieldset_create_from_keys(grib_context* c, char** keys, int nkeys, int* err)
{
grib_fieldset* set = 0;
grib_fieldset* set = NULL;
size_t msize = 0, size = 0;
int i = 0;
int type = 0;
@ -382,8 +382,7 @@ static grib_fieldset* grib_fieldset_create_from_keys(grib_context* c, char** key
return set;
}
static grib_fieldset* grib_fieldset_create_from_order_by(grib_context* c, grib_order_by* ob,
int* err)
static grib_fieldset* grib_fieldset_create_from_order_by(grib_context* c, grib_order_by* ob, int* err)
{
char** keys = NULL;
size_t nkeys = 0;
@ -411,20 +410,22 @@ static grib_fieldset* grib_fieldset_create_from_order_by(grib_context* c, grib_o
return set;
}
/* Experimental: Needs more work */
int grib_fieldset_apply_where(grib_fieldset* set, const char* where_string)
{
int err = GRIB_NOT_IMPLEMENTED;
grib_math* m = 0;
grib_math* m = NULL;
if (!set)
return GRIB_INVALID_ARGUMENT;
m = grib_math_new(set->context, where_string, &err);
if (err || !m) return err;
print_math(m);
printf("\n");
grib_math_delete(set->context, m);
return err;
return GRIB_NOT_IMPLEMENTED;
}
int grib_fieldset_apply_order_by(grib_fieldset* set, const char* order_by_string)
@ -457,9 +458,9 @@ static int grib_fieldset_compare(grib_fieldset* set, int* i, int* j)
int ret = 0;
double d = 0;
int idkey = 0;
grib_order_by* ob = 0;
grib_order_by* ob = NULL;
int ii = 0, jj = 0;
int* order = 0;
int* order = NULL;
if (!set || !set->order_by)
return GRIB_INVALID_ARGUMENT;
@ -505,18 +506,18 @@ static int grib_fieldset_compare(grib_fieldset* set, int* i, int* j)
return ret;
}
static void grib_fieldset_sort(grib_fieldset* set, int beg, int theEnd)
static void grib_fieldset_sort(grib_fieldset* set, int theStart, int theEnd)
{
double temp;
int l = 0, r = 0;
if (theEnd > beg) {
l = beg + 1;
if (theEnd > theStart) {
l = theStart + 1;
r = theEnd;
while (l < r) {
if (grib_fieldset_compare(set, &l, &beg) <= 0) {
if (grib_fieldset_compare(set, &l, &theStart) <= 0) {
l++;
}
else if (grib_fieldset_compare(set, &r, &beg) >= 0) {
else if (grib_fieldset_compare(set, &r, &theStart) >= 0) {
r--;
}
else {
@ -524,16 +525,16 @@ static void grib_fieldset_sort(grib_fieldset* set, int beg, int theEnd)
}
}
if (grib_fieldset_compare(set, &l, &beg) < 0) {
SWAP(set->order->el[l], set->order->el[beg])
if (grib_fieldset_compare(set, &l, &theStart) < 0) {
SWAP(set->order->el[l], set->order->el[theStart])
l--;
}
else {
l--;
SWAP(set->order->el[l], set->order->el[beg])
SWAP(set->order->el[l], set->order->el[theStart])
}
grib_fieldset_sort(set, beg, l);
grib_fieldset_sort(set, theStart, l);
grib_fieldset_sort(set, r, theEnd);
}
}
@ -560,7 +561,7 @@ static grib_order_by* grib_fieldset_new_order_by(grib_context* c, const char* ob
{
char *t1 = 0, *t2 = 0, *p = 0;
int id = 0;
char* z = 0;
char* z = NULL;
int mode, mode_default = GRIB_ORDER_BY_ASC;
grib_order_by *ob, *sob;
@ -628,7 +629,7 @@ static grib_order_by* grib_fieldset_new_order_by(grib_context* c, const char* ob
void grib_fieldset_delete(grib_fieldset* set)
{
grib_context* c = 0;
grib_context* c = NULL;
if (!set)
return;
@ -644,17 +645,17 @@ void grib_fieldset_delete(grib_fieldset* set)
grib_context_free(c, set);
}
int grib_fieldset_add(grib_fieldset* set, char* filename)
int grib_fieldset_add(grib_fieldset* set, const char* filename)
{
int ret = GRIB_SUCCESS;
int err = 0;
int i = 0;
grib_handle* h = 0;
grib_handle* h = NULL;
/* int nkeys; */
grib_file* file;
double offset = 0;
long length = 0;
grib_context* c = 0;
grib_context* c = NULL;
if (!set || !filename)
return GRIB_INVALID_ARGUMENT;
@ -742,15 +743,15 @@ grib_handle* grib_fieldset_next_handle(grib_fieldset* set, int* err)
return h;
}
int grib_fieldset_count(grib_fieldset* set)
int grib_fieldset_count(const grib_fieldset* set)
{
return set->size;
}
grib_handle* grib_fieldset_retrieve(grib_fieldset* set, int i, int* err)
{
grib_handle* h = 0;
grib_field* field = 0;
grib_handle* h = NULL;
grib_field* field = NULL;
*err = GRIB_SUCCESS;
if (!set) {
*err = GRIB_INVALID_ARGUMENT;
@ -783,10 +784,9 @@ static grib_int_array* grib_fieldset_create_int_array(grib_context* c, size_t si
c = grib_context_get_default();
a = (grib_int_array*)grib_context_malloc_clear(c, sizeof(grib_int_array));
if (!a) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_create_int_array : Cannot malloc %ld bytes",
"grib_fieldset_create_int_array: Cannot malloc %ld bytes",
sizeof(grib_int_array));
return NULL;
}
@ -794,7 +794,7 @@ static grib_int_array* grib_fieldset_create_int_array(grib_context* c, size_t si
a->el = (int*)grib_context_malloc_clear(c, sizeof(int) * size);
if (!a->el) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_fieldset_create_int_array : Cannot malloc %ld bytes",
"grib_fieldset_create_int_array: Cannot malloc %ld bytes",
sizeof(int) * size);
return NULL;
}
@ -896,7 +896,7 @@ static void grib_fieldset_delete_fields(grib_fieldset* set)
static void grib_trim(char** x)
{
char* p = 0;
char* p = NULL;
while (**x == ' ')
(*x)++;
if (**x == '\0')

File diff suppressed because it is too large Load Diff

View File

@ -445,9 +445,9 @@ void grib_math_delete(grib_context* c, grib_math* m)
grib_math* grib_math_new(grib_context* c, const char* formula, int* err)
{
grib_math* x;
char* f = 0;
char* fsave = 0;
grib_math* x = NULL;
char* f = NULL;
char* fsave = NULL;
*err = 0;
@ -467,6 +467,7 @@ grib_math* grib_math_new(grib_context* c, const char* formula, int* err)
if (*f) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_math_new : Part of the formula was not processed: '%s'", f);
*err = GRIB_INVALID_ARGUMENT;
return NULL;
}

View File

@ -170,8 +170,7 @@ static int init_sphere(grib_handle* h,
double Dx, double Dy, double radius,
double latFirstInRadians, double lonFirstInRadians,
double LoVInRadians, double Latin1InRadians, double Latin2InRadians,
double LaDInRadians,
long iScansNegatively, long jScansPositively, long jPointsAreConsecutive)
double LaDInRadians)
{
int i, j;
double f, n, rho, rho0, angle, x0, y0, x, y, tmp, tmp2;
@ -474,8 +473,7 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args)
LoVInDegrees,
Dx, Dy, radius,
latFirstInRadians, lonFirstInRadians,
LoVInRadians, Latin1InRadians, Latin2InRadians, LaDInRadians,
iScansNegatively, jScansPositively, jPointsAreConsecutive);
LoVInRadians, Latin1InRadians, Latin2InRadians, LaDInRadians);
}
if (err) return err;

View File

@ -18,18 +18,67 @@
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#include "jasper/jasper.h"
#define MAXOPTSSIZE 1024
int grib_jasper_decode(grib_context* c, unsigned char* buf, size_t* buflen, double* values, size_t* no_values)
static int ecc_jasper_initialise()
{
/*jas_setdbglevel(99999);*/
#if JASPER_VERSION_MAJOR == 3
int jaserr = 0;
jas_conf_clear();
jas_conf_set_max_mem_usage(jas_get_total_mem_size());
jaserr = jas_init_library();
if (jaserr) return jaserr;
jaserr = jas_init_thread();
if (jaserr) return jaserr;
#endif
return 0;
}
static jas_image_t* ecc_jasper_decode(jas_stream_t *in)
{
#if JASPER_VERSION_MAJOR == 3
/* Second argument (=fmt) < 0 means "If possible, try to determine the format of the input data" */
return jas_image_decode(in, -1, 0);
#else
return jpc_decode(in, NULL);
#endif
}
static int ecc_jasper_encode(jas_image_t *image, jas_stream_t *jpcstream, char *optstr)
{
#if JASPER_VERSION_MAJOR == 3
const int fmt = jas_image_strtofmt("jpc");
return jas_image_encode(image, jpcstream, fmt, optstr);
#else
return jpc_encode(image, jpcstream, optstr);
#endif
}
static void ecc_jasper_cleanup()
{
#if JASPER_VERSION_MAJOR == 3
jas_cleanup_thread();
jas_cleanup_library();
#endif
}
int grib_jasper_decode(grib_context* c, unsigned char* buf, const size_t* buflen, double* values, const size_t* n_vals)
{
/* jas_setdbglevel(99999); */
jas_image_t* image = NULL;
jas_stream_t* jpeg = NULL;
int code = GRIB_SUCCESS;
jas_matrix_t* matrix = NULL;
jas_image_cmpt_t* p;
int i, j, k;
int jaserr = 0; /* 0 means success */
jaserr = ecc_jasper_initialise();
if (jaserr) {
grib_context_log(c, GRIB_LOG_ERROR, "grib_jasper_decode: Failed to initialize JasPer library. JasPer error %d", jaserr);
code = GRIB_DECODING_ERROR;
goto cleanup;
}
jpeg = jas_stream_memopen((char*)buf, *buflen);
if (!jpeg) {
@ -37,9 +86,9 @@ int grib_jasper_decode(grib_context* c, unsigned char* buf, size_t* buflen, doub
goto cleanup;
}
grib_context_log(c, GRIB_LOG_DEBUG, "grib_jasper_decode: Jasper version %s", jas_getversion());
grib_context_log(c, GRIB_LOG_DEBUG, "grib_jasper_decode: JasPer version %s", jas_getversion());
image = jpc_decode(jpeg, NULL);
image = ecc_jasper_decode(jpeg);
if (!image) {
code = GRIB_DECODING_ERROR;
goto cleanup;
@ -54,15 +103,19 @@ int grib_jasper_decode(grib_context* c, unsigned char* buf, size_t* buflen, doub
}
matrix = jas_matrix_create(jas_image_height(image), jas_image_width(image));
if (!matrix) {
code = GRIB_DECODING_ERROR;
goto cleanup;
}
jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image), jas_image_height(image), matrix);
jaserr = jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image), jas_image_height(image), matrix);
if (jaserr) {
grib_context_log(c, GRIB_LOG_ERROR, "grib_jasper_decode: Failed to read JasPer component data. JasPer error %d", jaserr);
code = GRIB_DECODING_ERROR;
goto cleanup;
}
Assert(p->height_ * p->width_ == *no_values);
Assert(p->height_ * p->width_ == *n_vals);
k = 0;
for (i = 0; i < p->height_; i++)
@ -77,6 +130,7 @@ cleanup:
jas_image_destroy(image);
if (jpeg)
jas_stream_close(jpeg);
ecc_jasper_cleanup();
return code;
}
@ -84,7 +138,7 @@ cleanup:
int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper)
{
int code = GRIB_SUCCESS;
int jaserr;
int jaserr = 0;
char opts[MAXOPTSSIZE];
double reference_value = helper->reference_value;
@ -156,7 +210,7 @@ int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper)
}
}
/*jas_init();*/
ecc_jasper_initialise();
opts[0] = 0;
@ -166,7 +220,7 @@ int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper)
}
Assert(cmpt.width_ * cmpt.height_ * cmpt.cps_ == buflen);
grib_context_log(c, GRIB_LOG_DEBUG, "grib_jasper_encode: Jasper version %s", jas_getversion());
grib_context_log(c, GRIB_LOG_DEBUG, "grib_jasper_encode: JasPer version %s", jas_getversion());
pcmpt = &cmpt;
image.cmpts_ = &pcmpt;
@ -175,12 +229,12 @@ int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper)
cmpt.stream_ = istream;
jpcstream = jas_stream_memopen((char*)helper->jpeg_buffer, helper->buffer_size);
jaserr = jpc_encode(&image, jpcstream, opts);
if (jaserr != 0) {
/* increase the number of guard bits */
jaserr = ecc_jasper_encode(&image, jpcstream, opts);
if (jaserr) {
/* Failed to encode. Increase the number of guard bits */
strcat(opts, "\nnumgbits=4");
grib_context_log(c, GRIB_LOG_ERROR, "JASPER: error %d, increasing the number of guard bits", jaserr);
grib_context_log(c, GRIB_LOG_ERROR, "grib_jasper_encode: JasPer error %d, increasing the number of guard bits", jaserr);
jas_stream_close(istream);
istream = 0;
jas_stream_close(jpcstream);
@ -189,11 +243,11 @@ int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper)
istream = jas_stream_memopen((char*)encoded, buflen);
cmpt.stream_ = istream;
jpcstream = jas_stream_memopen((char*)helper->jpeg_buffer, helper->buffer_size);
jaserr = jpc_encode(&image, jpcstream, opts);
jaserr = ecc_jasper_encode(&image, jpcstream, opts);
}
if (jaserr != 0) {
grib_context_log(c, GRIB_LOG_ERROR, "JASPER: error %d", jaserr);
if (jaserr) {
grib_context_log(c, GRIB_LOG_ERROR, "grib_jasper_encode: Failed to encode. JasPer error %d", jaserr);
code = GRIB_ENCODING_ERROR;
goto cleanup;
}
@ -210,23 +264,23 @@ cleanup:
jas_stream_close(istream);
if (jpcstream)
jas_stream_close(jpcstream);
ecc_jasper_cleanup();
return code;
}
#else
int grib_jasper_decode(grib_context* c, unsigned char* buf, size_t* buflen, double* val, size_t* n_vals)
int grib_jasper_decode(grib_context* c, unsigned char* buf, const size_t* buflen, double* val, const size_t* n_vals)
{
grib_context_log(c, GRIB_LOG_ERROR,
"grib_accessor_data_jpeg2000_packing: Jasper JPEG support not enabled.");
"grib_accessor_data_jpeg2000_packing: JasPer JPEG support not enabled.");
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
int grib_jasper_encode(grib_context* c, j2k_encode_helper* helper)
{
grib_context_log(c, GRIB_LOG_ERROR,
"grib_accessor_data_jpeg2000_packing: Jasper JPEG support not enabled.");
"grib_accessor_data_jpeg2000_packing: JasPer JPEG support not enabled.");
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}

View File

@ -82,6 +82,7 @@ void grib_oarray_delete(grib_context* c, grib_oarray* v)
grib_context_free(c, v);
}
#if 0
void grib_oarray_delete_content(grib_context* c, grib_oarray* v)
{
int i;
@ -90,12 +91,14 @@ void grib_oarray_delete_content(grib_context* c, grib_oarray* v)
if (!c)
c = grib_context_get_default();
for (i = 0; i < v->n; i++) {
if (v->v[i])
if (v->v[i]) {
grib_context_free(c, v->v[i]);
v->v[i] = 0;
}
}
v->n = 0;
}
#endif
void** grib_oarray_get_array(grib_context* c, grib_oarray* v)
{

View File

@ -382,8 +382,9 @@ void grib_trie_with_rank_delete_container(grib_trie_with_rank* t)
GRIB_MUTEX_UNLOCK(&mutex);
}
/*
static void grib_trie_with_rank_delete_list(grib_context* c,grib_trie_with_rank_list *list) {
#if 0
static void grib_trie_with_rank_delete_list(grib_context* c,grib_trie_with_rank_list *list)
{
grib_trie_with_rank_list* next=list;
grib_trie_with_rank_list* p;
while (next) {
@ -393,7 +394,6 @@ static void grib_trie_with_rank_delete_list(grib_context* c,grib_trie_with_rank_
grib_context_free( c, p );
}
}
*/
void grib_trie_with_rank_delete(grib_trie_with_rank* t)
{
@ -434,7 +434,6 @@ void grib_trie_with_rank_clear(grib_trie_with_rank* t)
}
}
/*
static void grib_trie_with_rank_insert_in_list(grib_trie_with_rank* t,void* data) {
if (t->list==NULL) {
t->list=grib_context_malloc_clear(t->context,sizeof(grib_trie_with_rank_list));
@ -448,7 +447,7 @@ static void grib_trie_with_rank_insert_in_list(grib_trie_with_rank* t,void* data
t->last_list->rank++;
}
}
*/
#endif
int grib_trie_with_rank_insert(grib_trie_with_rank* t, const char* key, void* data)
{

View File

@ -16,6 +16,7 @@ list(APPEND test_bins
read_any
julian
grib_indexing
grib_fieldset
grib_multi_from_message
grib_read_index
unit_tests
@ -215,6 +216,7 @@ if( HAVE_BUILD_TOOLS )
grib_nearest_test
pseudo_budg
grib_gridType
grib_fieldset
grib_octahedral
grib_grid_mercator
grib_global

View File

@ -57,5 +57,14 @@ for f in $files; do
rm -f $temp
done
# ECC-989: Valgrind error: setting 'unpack=1' before setting unexpandedDescriptors
# ---------------------------------------------------------------------------------
f="$ECCODES_SAMPLES_PATH/BUFR4.tmpl"
cat > $fRules <<EOF
set unpack=1;
set unexpandedDescriptors={4025};
EOF
${tools_dir}/codes_bufr_filter $fRules $f
rm -f $fRules $fLog $temp

View File

@ -173,9 +173,16 @@ ${tools_dir}/bufr_set -s ident=' AB CD ' $f $fBufrTmp
result=`${tools_dir}/bufr_get -p ident $fBufrTmp`
[ "$result" = "AB CD" ]
# ${tools_dir}/bufr_compare $f $fBufrTmp
#-----------------------------------------------------------
# ECC-1359: string that can be converted to an integer
# ----------------------------------------------------------
${tools_dir}/bufr_set -s messageLength:s=333 $ECCODES_SAMPLES_PATH/BUFR4_local.tmpl $fBufrTmp
result=`${tools_dir}/bufr_get -p messageLength $fBufrTmp`
[ "$result" = "333" ]
# Clean up
rm -f $fLog
rm -f $fBufrTmp

View File

@ -113,6 +113,24 @@ ${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=1 $temp $tem
${tools_dir}/grib_compare -b totalLength,numberOfSection $temp $temp1
grib_check_key_equals $temp1 localUsePresent 1
# Check local ECMWF chemicals/aerosols
# ------------------------------------
${tools_dir}/grib_set -s paramId=217232 $sample2 $temp
${tools_dir}/grib_dump -O -p constituentType $temp > $temp1
grep -q "Biomass burning volatile organic compounds .*grib2/tables/local/ecmf/1/4.230.table" $temp1
${tools_dir}/grib_set -s paramId=219231 $sample2 $temp
${tools_dir}/grib_dump -O -p constituentType $temp > $temp1
grep -q "Anthropogenic volatile organic compounds .*grib2/tables/local/ecmf/1/4.230.table" $temp1
${tools_dir}/grib_set -s paramId=211248 $sample2 $temp
${tools_dir}/grib_dump -O -p aerosolType $temp > $temp1
grep -q "Nitrate Coarse Mode .*grib2/tables/local/ecmf/1/4.233.table" $temp1
${tools_dir}/grib_set -s paramId=215189 $sample2 $temp
${tools_dir}/grib_dump -O -p aerosolType $temp > $temp1
grep -q "Nitrate Fine Mode .*grib2/tables/local/ecmf/1/4.233.table" $temp1
grib_check_key_equals $temp aerosolTypeName "Nitrate Fine Mode"
# Clean up
rm -f $tempSample
rm -f $temp $temp1
rm -f $tempSample $temp $temp1

View File

@ -21,16 +21,6 @@ outfile2=temp.$label.2
rm -f $outfile1 $outfile2
# Use the sample file with CCSDS packing
# ---------------------------------------
sample_ccsds=$ECCODES_SAMPLES_PATH/ccsds_grib2.tmpl
${tools_dir}/grib_filter -o $outfile1 - $sample_ccsds << EOF
set values = { 55.0161, 99.7008 };
write;
EOF
grib_check_key_equals $outfile1 packingType grid_ccsds
stats=`${tools_dir}/grib_get -M -F%.4f -p min,max $outfile1`
[ "$stats" = "55.0161 99.7008" ]
# ECC-1263
# ---------
@ -111,5 +101,12 @@ ${tools_dir}/grib_compare -b $BLACKLIST $infile $outfile1
${tools_dir}/grib_compare -c data:n $outfile1 $outfile2
# ECC-1362
# ---------
infile=${data_dir}/ccsds_szip.grib2
res=`${tools_dir}/grib_get '-F%.3f' -p min,max,avg $infile`
[ "$res" = "-180.000 180.000 -0.044" ]
# Clean up
rm -f $outfile1 $outfile2

View File

@ -14,6 +14,8 @@
label="grib_dump_samples_test"
temp=${label}".temp"
sample_ccsds="$ECCODES_SAMPLES_PATH/ccsds_grib2.tmpl"
# Test selected sample GRIB files
samples="
GRIB1.tmpl
@ -25,9 +27,10 @@ samples="
regular_ll_sfc_grib1.tmpl
regular_ll_sfc_grib2.tmpl
"
for file in $samples; do
sf="$ECCODES_SAMPLES_PATH/$file"
${tools_dir}/grib_dump -O $sf >/dev/null
for sfile in $samples; do
sample="$ECCODES_SAMPLES_PATH/$sfile"
${tools_dir}/grib_dump -O $sample >/dev/null
done
# Test grib_dump with -t option
@ -37,5 +40,16 @@ grep -q "codetable (int) typeOfSecondFixedSurface" $temp
grep -q "ieeefloat (double) referenceValue" $temp
grep -q "unsigned (int) numberOfSection" $temp
# Extra tests for CCSDS
if [ $HAVE_AEC -eq 1 ]; then
${tools_dir}/grib_dump -O $sample_ccsds >/dev/null
rm -f $temp
echo 'set values = { 55.0161, 66.666, 99.7008 };write;' |\
${tools_dir}/grib_filter -o $temp - $sample_ccsds
grib_check_key_equals $temp packingType,numberOfValues 'grid_ccsds 3'
stats=`${tools_dir}/grib_get -M -F%.4f -p min,max $temp`
[ "$stats" = "55.0161 99.7008" ]
${tools_dir}/grib_dump -O $temp
fi
rm -f $temp

View File

@ -54,7 +54,6 @@ static int encode_file(char* input_file, char* output_file)
grib_handle* source_handle = NULL;
const void* buffer = NULL;
int err = 0;
size_t str_len = 0;
FILE* in = fopen(input_file, "rb");
FILE* out = fopen(output_file, "wb");
@ -89,7 +88,7 @@ static int encode_file(char* input_file, char* output_file)
GRIB_CHECK(grib_set_long(clone_handle, "bitsPerValue", 16), 0);
/*GRIB_CHECK(grib_set_string(clone_handle, "packingType", "grid_ccsds", &str_len), 0);*/
GRIB_CHECK(grib_set_string(clone_handle, "packingType", "grid_simple", &str_len), 0);
/*GRIB_CHECK(grib_set_string(clone_handle, "packingType", "grid_simple", &str_len), 0);*/
GRIB_CHECK(grib_set_double_array(clone_handle, "values", values, values_len), 0);
@ -118,7 +117,7 @@ void do_stuff(void* arg)
int i;
for (i = 0; i < FILES_PER_ITERATION; i++) {
sprintf(output_file, "temp.grib_encode_pthreads.out_%d-%d.grib", (int)number, i);
sprintf(output_file, "temp.grib_encode_pthreads_test.out_%d-%d.grib", (int)number, i);
encode_file(INPUT_FILE, output_file);
}
}

View File

@ -10,8 +10,29 @@
. ./include.sh
input=$ECCODES_SAMPLES_PATH/gg_sfc_grib2.tmpl
label="grib_encode_pthreads_test"
${test_dir}/grib_encode_pthreads $input
# Simple packing
# --------------
${test_dir}/grib_encode_pthreads $ECCODES_SAMPLES_PATH/GRIB2.tmpl
for f in temp.$label.out_*.grib; do
${tools_dir}/grib_get -p min,max,avg $f > $f.simple.txt
done
rm -f temp.grib_encode_pthreads.out_*.grib
rm -f temp.$label.out_*.grib
if [ $HAVE_AEC -eq 1 ]; then
# CCSDS packing
# --------------
${test_dir}/grib_encode_pthreads $ECCODES_SAMPLES_PATH/ccsds_grib2.tmpl
for f in temp.$label.out_*.grib; do
${tools_dir}/grib_get -p min,max,avg $f > $f.ccsds.txt
diff $f.simple.txt $f.ccsds.txt
rm $f.simple.txt $f.ccsds.txt
done
fi
# Clean up
for f in temp.$label.out_*.grib; do
rm -f $f.simple.txt $f.ccsds.txt temp.$label.out_*.grib
done

80
tests/grib_fieldset.c Normal file
View File

@ -0,0 +1,80 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "grib_api.h"
static void usage(const char* prog)
{
fprintf(stderr, "Usage: %s order_by grib_file grib_file ...\n", prog);
exit(1);
}
int main(int argc, char** argv)
{
int err = 0;
long step;
char** filenames;
size_t nkeys, nfiles, i=0;
char* keys[] = { "step:i", "date", "paramId", "levelType" };
grib_fieldset* set = NULL;
grib_handle* h = NULL;
char param[20] = {0,};
char typeOfLevel[50] = {0,};
char date[10] = {0,};
size_t lenDate = 10, lenParam = 20, lenLevel = 50;
char* order_by = NULL;
if (argc != 3) usage(argv[0]);
nkeys = sizeof(keys) / sizeof(*keys);
order_by = argv[1];
nfiles = argc - 2;
filenames = (char**)malloc(sizeof(char*) * nfiles);
for (i = 0; i < nfiles; i++)
filenames[i] = (char*)strdup(argv[i + 2]);
set = grib_fieldset_new_from_files(0, filenames, nfiles, keys, nkeys, 0, 0, &err);
GRIB_CHECK(err, 0);
/* not yet implemented */
/* err=grib_fieldset_apply_where(set,"(centre=='ecmf') && number==1 || step==6 "); */
/* GRIB_CHECK(err,0); */
grib_fieldset_apply_order_by(set, order_by);
GRIB_CHECK(err, 0);
printf("Ordering by %s\n", order_by);
printf("\n%d fields in the fieldset\n", grib_fieldset_count(set));
printf("step,date,levelType,levelType\n");
while ((h = grib_fieldset_next_handle(set, &err)) != NULL) {
lenParam = sizeof(param);
lenDate = sizeof(date);
lenLevel = sizeof(typeOfLevel);
GRIB_CHECK(grib_get_long(h, "step", &step), 0);
GRIB_CHECK(grib_get_string(h, "date", date, &lenDate), 0);
GRIB_CHECK(grib_get_string(h, "paramId", param, &lenParam), 0);
GRIB_CHECK(grib_get_string(h, "levelType", typeOfLevel, &lenLevel), 0);
printf("%ld %s %s %s\n", step, date, typeOfLevel, param);
grib_handle_delete(h);
}
grib_fieldset_delete(set);
grib_handle_delete(h);
for (i = 0; i < nfiles; i++)
free(filenames[i]);
free(filenames);
return 0;
}

48
tests/grib_fieldset.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.sh
set -u
label="grib_fieldset_test"
temp=temp.$label.txt
tempRef=temp.$label.ref
input_grb=${data_dir}/high_level_api.grib2
$EXEC ${test_dir}/grib_fieldset 'step:i asc' $input_grb > $temp
cat > $tempRef <<EOF
Ordering by step:i asc
5 fields in the fieldset
step,date,levelType,levelType
0 20110225 sfc 151
6 20110225 sfc 151
12 20110225 sfc 151
18 20110225 sfc 151
24 20110225 sfc 151
EOF
diff $tempRef $temp
$EXEC ${test_dir}/grib_fieldset 'step:i desc' $input_grb > $temp
cat > $tempRef <<EOF
Ordering by step:i desc
5 fields in the fieldset
step,date,levelType,levelType
24 20110225 sfc 151
18 20110225 sfc 151
12 20110225 sfc 151
6 20110225 sfc 151
0 20110225 sfc 151
EOF
diff $tempRef $temp
# Clean up
rm -f $temp $tempRef

View File

@ -209,10 +209,12 @@ input="${data_dir}/reduced_gaussian_pressure_level.grib2"
grib_check_key_equals $input scaleFactorOfFirstFixedSurface 0
cat >$tempFilt <<EOF
set scaleFactorOfFirstFixedSurface = MISSING; # has to be uppercase
set scaledValueOfFirstFixedSurface = missing(); # has to have parens
write;
EOF
${tools_dir}/grib_filter -o $tempGrib $tempFilt $input
grib_check_key_equals $tempGrib scaleFactorOfFirstFixedSurface MISSING
grib_check_key_equals $tempGrib scaledValueOfFirstFixedSurface MISSING
# Clean up

View File

@ -94,8 +94,6 @@ diff $tempRef $tempOut
${tools_dir}/grib_index_build -N -k mars.levtype -o $tempIndex ${data_dir}/tigge_cf_ecmwf.grib2 |\
grep -q "mars.levtype = { sfc, pl, pv, pt }"
#${tools_dir}/grib_index_build -N -k mars.levtype:i -o $tempIndex ${data_dir}/tigge_cf_ecmwf.grib2 |\
# grep -q "mars.levtype = { 103, 1, 106, 100, 101, 8, 109, 107 }"
echo "grib_compare with index files..."
# ------------------------------------

View File

@ -18,7 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "eccodes.h"
int grib_fieldset_apply_where(grib_fieldset* set, const char* where_string); /*experimental*/
@ -75,8 +75,8 @@ int main(int argc, char** argv)
CODES_CHECK(err, 0);
/* grib_fieldset_apply_where not fully implemented*/
err=grib_fieldset_apply_where(set, "(centre=='ecmf') && number==1 || step==6");
CODES_CHECK(err, 0);
err = grib_fieldset_apply_where(set, "(centre=='ecmf') && number==1 || step==6");
assert(err == CODES_NOT_IMPLEMENTED);
printf("ordering by %s\n", order_by);
printf("%d fields in the fieldset\n", codes_fieldset_count(set));

View File

@ -24790,6 +24790,9 @@ typedef enum {
VALUES_BEFORE_PACKING_TYPE
} PackingStage;
#define EPSILON 1e-5
int main(int argc, char** argv)
{
size_t values_len = sizeof(values)/sizeof(values[0]);
@ -24799,6 +24802,7 @@ int main(int argc, char** argv)
PackingStage packing_stage;
char* packing_type;
char* outfile_name;
int check = 1;
if (argc != 4) usage(argv[0]);
@ -24816,6 +24820,10 @@ int main(int argc, char** argv)
h = codes_grib_handle_new_from_samples(0, sample_filename);
assert(h);
if (strcmp(packing_type, "grid_second_order")==0 && packing_stage == VALUES_BEFORE_PACKING_TYPE) {
check = 0; /* TDOD */
}
CODES_CHECK(codes_set_long(h, "bitsPerValue", 16), 0);
if (packing_stage == PACKING_TYPE_BEFORE_VALUES) {
printf("Set packingType to %s\n", packing_type);
@ -24831,7 +24839,25 @@ int main(int argc, char** argv)
}
CODES_CHECK(codes_write_message(h, outfile_name, "w"), 0);
codes_handle_delete(h);
printf("%s checks on decoded values '%s' (%s) ...\n",
(check?"Doing":"Skipping"), packing_type, argv[2]);
if (check) {
size_t i = 0;
double* vals = (double*)malloc(sizeof(double) * values_len);
GRIB_CHECK(grib_get_double_array(h, "values", vals, &values_len), 0);
for (i = 0; i < values_len; i++) {
const double diff = fabs(values[i] - vals[i]);
if (diff > EPSILON) {
fprintf(stderr, "Unpacked value different at i=%lu: original=%.7f decoded=%.7f\n",
i, values[i], vals[i]);
return 1;
}
}
free(vals);
}
codes_handle_delete(h);
printf("All done\n");
return 0;
}

View File

@ -33,14 +33,6 @@ $EXEC ${test_dir}/grib_packing_order grid_simple values_before_packing_type $tem
grib_check_key_equals $temp_simple1 packingType grid_simple
${tools_dir}/grib_compare $temp_simple1 $temp_simple2
# Second order Packing: TODO
# ---------------------------
$EXEC ${test_dir}/grib_packing_order grid_second_order packing_type_before_values $temp_second1
$EXEC ${test_dir}/grib_packing_order grid_second_order values_before_packing_type $temp_second2
grib_check_key_equals $temp_second1 packingType grid_second_order
#${tools_dir}/grib_compare $temp_second1 $temp_second2
${tools_dir}/grib_compare -c data:n $temp_simple1 $temp_second1
# $temp_second2 is still not correct
# PNG Packing
# -------------
@ -79,16 +71,29 @@ fi
# IEEE
# ------------
#tests/grib_packing_order grid_ieee values_before_packing_type x2 # Does not work
$EXEC ${test_dir}/grib_packing_order grid_ieee packing_type_before_values $temp_ieee1
$EXEC ${test_dir}/grib_packing_order grid_ieee values_before_packing_type $temp_ieee2
if [ $HAVE_EXTRA_TESTS -eq 1 ]; then
#tests/grib_packing_order grid_ieee values_before_packing_type x2 # Does not work
$EXEC ${test_dir}/grib_packing_order grid_ieee packing_type_before_values $temp_ieee1
$EXEC ${test_dir}/grib_packing_order grid_ieee values_before_packing_type $temp_ieee2
${tools_dir}/grib_ls -n statistics $temp_ieee1 $temp_ieee2
# TODO
# ${tools_dir}/grib_compare $temp_ieee1 $temp_ieee2
${tools_dir}/grib_ls -n statistics $temp_ieee1 $temp_ieee2
# TODO
# ${tools_dir}/grib_compare $temp_ieee1 $temp_ieee2
# No point comparing with grid_simple as grid_ieee will be closer to the actual values
# and less lossy
fi
# Second order Packing: TODO
# ---------------------------
$EXEC ${test_dir}/grib_packing_order grid_second_order packing_type_before_values $temp_second1
$EXEC ${test_dir}/grib_packing_order grid_second_order values_before_packing_type $temp_second2
grib_check_key_equals $temp_second1 packingType grid_second_order
#${tools_dir}/grib_compare $temp_second1 $temp_second2
${tools_dir}/grib_compare -c data:n $temp_simple1 $temp_second1
# $temp_second2 is still not correct
# No point comparing with grid_simple as grid_ieee will be closer to the actual values
# and less lossy
# Clean up
rm -f $temp_simple1 $temp_simple2

View File

@ -18,7 +18,7 @@ temp=temp.grib_set.out
rm -f $outfile
${tools_dir}/grib_set -v -p levtype,centre,levtype:l,centre:l -s levtype=pl,centre=80 $infile $outfile >$REDIRECT
${tools_dir}/grib_set -v -p levtype,centre,levtype,centre:l -s levtype=pl,centre=80 $infile $outfile >$REDIRECT
levtype=`${tools_dir}/grib_get -p levtype $outfile`
[ $levtype = "pl" ]
@ -36,7 +36,7 @@ outfile=${data_dir}/set.grib2
rm -f $outfile
${tools_dir}/grib_set -v -p levtype:l,centre:s -s typeOfLevel=isobaricInhPa,centre:s=cnmc $infile $outfile >$REDIRECT
${tools_dir}/grib_set -v -p levtype:s,centre:s -s typeOfLevel=isobaricInhPa,centre:s=cnmc $infile $outfile >$REDIRECT
levtype=`${tools_dir}/grib_get -p levtype $outfile`
[ $levtype = "pl" ]
@ -44,9 +44,6 @@ levtype=`${tools_dir}/grib_get -p levtype $outfile`
centre=`${tools_dir}/grib_get -p centre $outfile`
[ $centre = "cnmc" ]
#levtype=`${tools_dir}/grib_get -p levtype:l $outfile`
#[ $levtype -eq 100 ]
centre=`${tools_dir}/grib_get -p centre:l $outfile`
[ $centre -eq 80 ]
@ -106,12 +103,38 @@ set -e
# offsetValuesBy
# ------------------
input=${data_dir}/reduced_latlon_surface.grib2
${tools_dir}/grib_set -s offsetValuesBy=0.5 $input $temp
${tools_dir}/grib_set -s offsetValuesBy=0.5 $input $outfile
max=`${tools_dir}/grib_get -F%.3f -p max $input`
[ "$max" = "12.597" ]
max=`${tools_dir}/grib_get -F%.3f -p max $temp`
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
[ "$max" = "13.097" ]
# ECC-1359: string that can be converted to an integer
# ---------------------------------------------------
${tools_dir}/grib_set -s month:s=6 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
grib_check_key_equals $outfile month 6
# Now try an illegal value: a string that cannot be converted to an integer
set +e
${tools_dir}/grib_set -s month=BAD $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile 2> $temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "String cannot be converted to an integer" $temp
# ECC-1363: Does not fail for invalid value for key of type 'double'
# ------------------------------------------------------------------
${tools_dir}/grib_set -s angleOfRotation:s=10.66 $ECCODES_SAMPLES_PATH/rotated_ll_sfc_grib2.tmpl $outfile
grib_check_key_equals $outfile angleOfRotation 10.66
# Now try an illegal value: a string that cannot be converted to an integer
set +e
${tools_dir}/grib_set -s angleOfRotation=BAD $ECCODES_SAMPLES_PATH/rotated_ll_sfc_grib2.tmpl $outfile 2>$temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "String cannot be converted to a double" $temp
# Clean up
rm -f $outfile $temp

View File

@ -1,6 +1,24 @@
set -ea
# For CMake
# Unset any environment variable that could interfere with tests
unset ECCODES_EXTRA_DEFINITION_PATH
unset ECCODES_LOG_STREAM
unset ECCODES_FAIL_IF_LOG_MESSAGE
unset ECCODES_DEBUG
unset ECCODES_GRIB_WRITE_ON_FAIL
unset ECCODES_GRIB_DATA_QUALITY_CHECKS
unset ECCODES_GRIB_KEEP_MATRIX
unset ECCODES_GRIB_NO_SPD
unset ECCODES_GRIB_NO_BIG_GROUP_SPLIT
unset ECCODES_GRIB_IEEE_PACKING
unset ECCODES_GRIBEX_MODE_ON
unset ECCODES_BUFRDC_MODE_ON
unset ECCODES_BUFR_SET_TO_MISSING_IF_OUT_OF_RANGE
unset ECCODES_BUFR_MULTI_ELEMENT_CONSTANT_ARRAYS
unset ECCODES_FILE_POOL_MAX_OPENED_FILES
unset ECCODES_IO_BUFFER_SIZE
set -x
echo "Script: $0"

2641
tests/keys

File diff suppressed because it is too large Load Diff

View File

@ -1472,7 +1472,8 @@ static void test_concept_condition_strings()
{
int err = 0;
char result[1024] = {0,};
grib_handle* h = grib_handle_new_from_samples(0, "GRIB2");
grib_context* context = NULL;
grib_handle* h = grib_handle_new_from_samples(context, "GRIB2");
printf("Testing: test_concept_condition_strings...\n");
@ -1508,6 +1509,8 @@ static void test_trimming()
char* pD = d;
char* pE = e;
printf("Testing: test_trimming...\n");
lrtrim(&pA, 0, 1); /*right only*/
assert( strcmp(pA, " Standing")==0 );
@ -1524,6 +1527,18 @@ static void test_trimming()
assert( strcmp(pE, "Apostle In Triumph")==0 );
}
static void test_gribex_mode()
{
grib_context* c = grib_context_get_default();
printf("Testing: test_gribex_mode...\n");
assert( grib_get_gribex_mode(c) == 0 ); /* default is OFF */
grib_gribex_mode_on(c);
assert( grib_get_gribex_mode(c) == 1 );
grib_gribex_mode_off(c);
assert( grib_get_gribex_mode(c) == 0 );
}
int main(int argc, char** argv)
{
/*printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version());*/
@ -1532,6 +1547,7 @@ int main(int argc, char** argv)
test_get_git_sha1();
test_get_build_date();
test_gribex_mode();
test_concept_condition_strings();

View File

@ -20,6 +20,9 @@ extern int optind;
static void usage_and_exit(const char* progname)
{
printf("\nUsage: %s [-v] [-d] [-s]\n", progname);
printf("\t-v\tPrint only the version of ecCodes\n");
printf("\t-d\tPrint only the definitions path\n");
printf("\t-s\tPrint only the samples path\n");
exit(1);
}
@ -37,14 +40,14 @@ static void print_debug_info(grib_context* context)
#ifdef HAVE_AEC
aec = 1;
#endif
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1=%s", grib_get_git_sha1());
grib_context_log(context, GRIB_LOG_DEBUG, "Build date=%s", codes_get_build_date());
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1: %s", grib_get_git_sha1());
grib_context_log(context, GRIB_LOG_DEBUG, "Build date: %s", codes_get_build_date());
grib_context_log(context, GRIB_LOG_DEBUG, "Features:");
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_AEC=%d", aec);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_JPEG=%d", HAVE_JPEG);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_LIBJASPER=%d", HAVE_LIBJASPER);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_LIBOPENJPEG=%d", HAVE_JPEG);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_LIBPNG=%d", HAVE_LIBPNG);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_AEC=%d", aec);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_ECCODES_THREADS=%d", GRIB_PTHREADS);
#ifdef GRIB_OMP_THREADS
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_ECCODES_OMP_THREADS=%d", GRIB_OMP_THREADS);
@ -90,8 +93,7 @@ int main(int argc, char* argv[])
if (print_flags == INFO_PRINT_ALL) {
print_debug_info(context);
printf("\n");
printf("%s Version %d.%d.%d",
grib_get_package_name(), major, minor, revision);
printf("%s Version %d.%d.%d", grib_get_package_name(), major, minor, revision);
if (ECCODES_MAJOR_VERSION < 1)
printf(" PRE-RELEASE");

View File

@ -31,7 +31,9 @@ static grib_options_help grib_options_help_list[] = {
"\n\t\tAll the keys in this list are skipped in the comparison. Bit-by-bit compare on.\n" },
{ "B:", "'order by' directive",
"\n\t\tOrder by. The output will be ordered according to the 'order by' directive."
"\n\t\tExample: \"step:i asc, centre desc\" (step numeric ascending and centre descending)\n" },
"\n\t\tExample: \"step:i asc, centre desc\" (step numeric ascending and centre descending)"
"\n\t\tDefault sort mode is 'asc'\n"
},
{ "c:", "key[:i|d|s|n],key[:i|d|s|n],...",
"\n\t\tOnly the listed keys or namespaces (:n) are compared. The optional letter after the colon is used "
"\n\t\tto force the type in the comparison: i->integer, d->float, s->string, n->namespace."