mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'develop' into feature/SUP-1862-high-level-python-bufr
Conflicts: examples/python/high_level_api.py python/eccodes/high_level/gribfile.py python/eccodes/high_level/gribmessage.py
This commit is contained in:
commit
1e5c817ead
|
@ -40,6 +40,7 @@ list( APPEND tests
|
||||||
grib_print_data
|
grib_print_data
|
||||||
grib_samples
|
grib_samples
|
||||||
grib_set_keys
|
grib_set_keys
|
||||||
|
grib_set_pv
|
||||||
grib_set_missing
|
grib_set_missing
|
||||||
binary_message
|
binary_message
|
||||||
grib_set_bitmap
|
grib_set_bitmap
|
||||||
|
|
|
@ -31,7 +31,7 @@ def example(input_filename, output_filename):
|
||||||
1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 0)
|
1, 1, 1, 1, 1, 1, 1, 1, 0)
|
||||||
codes_set(ibufr, 'inputDataPresentIndicator', ivalues)
|
codes_set_array(ibufr, 'inputDataPresentIndicator', ivalues)
|
||||||
codes_set(ibufr, 'edition', 3)
|
codes_set(ibufr, 'edition', 3)
|
||||||
codes_set(ibufr, 'masterTableNumber', 0)
|
codes_set(ibufr, 'masterTableNumber', 0)
|
||||||
codes_set(ibufr, 'bufrHeaderSubCentre', 0)
|
codes_set(ibufr, 'bufrHeaderSubCentre', 0)
|
||||||
|
@ -55,7 +55,7 @@ def example(input_filename, output_filename):
|
||||||
236000,101023,31031,1031,1032,8024,101001,225255,
|
236000,101023,31031,1031,1032,8024,101001,225255,
|
||||||
1063,2001,4001,4002,4003,4004,4005,5002,
|
1063,2001,4001,4002,4003,4004,4005,5002,
|
||||||
6002,7001,7006,11001,11016,11017,11002)
|
6002,7001,7006,11001,11016,11017,11002)
|
||||||
codes_set(ibufr, 'unexpandedDescriptors', ivalues)
|
codes_set_array(ibufr, 'unexpandedDescriptors', ivalues)
|
||||||
codes_set(ibufrin, 'unpack', 1)
|
codes_set(ibufrin, 'unpack', 1)
|
||||||
codes_bufr_copy_data(ibufrin, ibufr) # Copy data across
|
codes_bufr_copy_data(ibufrin, ibufr) # Copy data across
|
||||||
|
|
||||||
|
|
|
@ -63,23 +63,23 @@ def example(csvfile, input_filename, output_filename):
|
||||||
# to choose the template for the BUFR message
|
# to choose the template for the BUFR message
|
||||||
|
|
||||||
#unexpandedDescriptors = [301051,4006,7002,10004,12001,11001,11002,11031,11032,11033,20041]
|
#unexpandedDescriptors = [301051,4006,7002,10004,12001,11001,11002,11031,11032,11033,20041]
|
||||||
#codes_set(bufr, 'unexpandedDescriptors', unexpandedDescriptors)
|
#codes_set_array(bufr, 'unexpandedDescriptors', unexpandedDescriptors)
|
||||||
|
|
||||||
codes_set(bufr,'BufrTemplate','aircraftReportWithSecondsAndPressure')
|
codes_set(bufr,'BufrTemplate','aircraftReportWithSecondsAndPressure')
|
||||||
|
|
||||||
codes_set(bufr, 'year', years)
|
codes_set_array(bufr, 'year', years)
|
||||||
codes_set(bufr, 'month', months)
|
codes_set_array(bufr, 'month', months)
|
||||||
codes_set(bufr, 'day', days)
|
codes_set_array(bufr, 'day', days)
|
||||||
codes_set(bufr, 'hour', hours)
|
codes_set_array(bufr, 'hour', hours)
|
||||||
codes_set(bufr, 'minute', minutes)
|
codes_set_array(bufr, 'minute', minutes)
|
||||||
codes_set(bufr, 'second', seconds)
|
codes_set_array(bufr, 'second', seconds)
|
||||||
codes_set(bufr, 'latitude', latitudes)
|
codes_set_array(bufr, 'latitude', latitudes)
|
||||||
codes_set(bufr, 'longitude', longitudes)
|
codes_set_array(bufr, 'longitude', longitudes)
|
||||||
codes_set(bufr, 'height', altitudes)
|
codes_set_array(bufr, 'height', altitudes)
|
||||||
codes_set(bufr, 'nonCoordinatePressure', pressures)
|
codes_set_array(bufr, 'nonCoordinatePressure', pressures)
|
||||||
codes_set(bufr, 'windSpeed', windSpeeds)
|
codes_set_array(bufr, 'windSpeed', windSpeeds)
|
||||||
codes_set(bufr, 'windDirection', windDirections)
|
codes_set_array(bufr, 'windDirection', windDirections)
|
||||||
codes_set(bufr, 'airTemperature', temperatures)
|
codes_set_array(bufr, 'airTemperature', temperatures)
|
||||||
|
|
||||||
codes_set(bufr, 'pack', 1)
|
codes_set(bufr, 'pack', 1)
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ def example():
|
||||||
numberOfCoefficients = 2 * (numberOfLevels + 1)
|
numberOfCoefficients = 2 * (numberOfLevels + 1)
|
||||||
assert(len(pv) == numberOfCoefficients)
|
assert(len(pv) == numberOfCoefficients)
|
||||||
|
|
||||||
fout = open('out.pv.grib1', 'w')
|
fout = open('grib_set_pv.py.temp.grib', 'w')
|
||||||
gid = codes_grib_new_from_samples('reduced_gg_sfc_grib1')
|
gid = codes_grib_new_from_samples('reduced_gg_sfc_grib1')
|
||||||
|
|
||||||
codes_set(gid, 'typeOfLevel', 'hybrid')
|
codes_set(gid, 'typeOfLevel', 'hybrid')
|
||||||
codes_set(gid, 'level', 2)
|
codes_set(gid, 'level', 2)
|
||||||
codes_set(gid, 'PVPresent', 1)
|
codes_set(gid, 'PVPresent', 1)
|
||||||
codes_set(gid, 'pv', pv)
|
codes_set_array(gid, 'pv', pv)
|
||||||
|
|
||||||
codes_write(gid, fout)
|
codes_write(gid, fout)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./include.sh
|
||||||
|
|
||||||
|
OUTPUT=grib_set_pv.py.temp.grib
|
||||||
|
$PYTHON $examples_src/grib_set_pv.py
|
||||||
|
rm $OUTPUT
|
|
@ -238,7 +238,7 @@ class TestGribMessage(unittest.TestCase):
|
||||||
self.assertEqual(msg.size(), 160219)
|
self.assertEqual(msg.size(), 160219)
|
||||||
self.assertEqual(len(msg.keys()), len(msg))
|
self.assertEqual(len(msg.keys()), len(msg))
|
||||||
|
|
||||||
def test_missing_message_behavior(self):
|
def test_missing_message_behaviour(self):
|
||||||
"""Missing messages are detected properly."""
|
"""Missing messages are detected properly."""
|
||||||
with GribFile(TESTGRIB) as grib:
|
with GribFile(TESTGRIB) as grib:
|
||||||
msg = GribMessage(grib)
|
msg = GribMessage(grib)
|
||||||
|
|
|
@ -12,7 +12,8 @@ set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/memfs.c PROPERTIES OBJE
|
||||||
# "${PROJECT_SOURCE_DIR}/memfs.py" ${definition_files}"
|
# "${PROJECT_SOURCE_DIR}/memfs.py" ${definition_files}"
|
||||||
)
|
)
|
||||||
|
|
||||||
ecbuild_add_library(TARGET eccodes_memfs
|
if (HAVE_MEMFS)
|
||||||
CONDITION HAVE_MEMFS
|
ecbuild_add_library(TARGET eccodes_memfs
|
||||||
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/memfs.c
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/memfs.c
|
||||||
GENERATED ${CMAKE_CURRENT_BINARY_DIR}/memfs.c )
|
GENERATED ${CMAKE_CURRENT_BINARY_DIR}/memfs.c)
|
||||||
|
endif()
|
||||||
|
|
|
@ -34,7 +34,7 @@ class GribIndex(object):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, exception_type, exception_value, traceback):
|
||||||
"""Release GRIB message handle and inform file of release."""
|
"""Release GRIB message handle and inform file of release."""
|
||||||
while self.open_messages:
|
while self.open_messages:
|
||||||
self.open_messages[0].close()
|
self.open_messages[0].close()
|
||||||
|
@ -79,9 +79,9 @@ class GribIndex(object):
|
||||||
"""Return number of distinct values for index key."""
|
"""Return number of distinct values for index key."""
|
||||||
return eccodes.codes_index_get_size(self.iid, key)
|
return eccodes.codes_index_get_size(self.iid, key)
|
||||||
|
|
||||||
def values(self, key, type=str):
|
def values(self, key, ktype=str):
|
||||||
"""Return distinct values of index key."""
|
"""Return distinct values of index key."""
|
||||||
return eccodes.codes_index_get(self.iid, key, type)
|
return eccodes.codes_index_get(self.iid, key, ktype)
|
||||||
|
|
||||||
def add(self, filename):
|
def add(self, filename):
|
||||||
"""Add ``filename`` to the ``GribIndex``."""
|
"""Add ``filename`` to the ``GribIndex``."""
|
||||||
|
|
|
@ -1609,9 +1609,9 @@ def grib_set(msgid, key, value):
|
||||||
grib_set_double(msgid, key, value)
|
grib_set_double(msgid, key, value)
|
||||||
elif isinstance(value, str):
|
elif isinstance(value, str):
|
||||||
grib_set_string(msgid, key, value)
|
grib_set_string(msgid, key, value)
|
||||||
elif hasattr(value, "__iter__"):
|
#elif hasattr(value, "__iter__"):
|
||||||
# The value passed in is iterable; i.e. a list or array etc
|
# # The value passed in is iterable; i.e. a list or array etc
|
||||||
grib_set_array(msgid, key, value)
|
# grib_set_array(msgid, key, value)
|
||||||
else:
|
else:
|
||||||
raise errors.GribInternalError("Invalid type of value when setting key '%s'." % key)
|
raise errors.GribInternalError("Invalid type of value when setting key '%s'." % key)
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ if shared_libs == 'OFF':
|
||||||
if @HAVE_LIBPNG@:
|
if @HAVE_LIBPNG@:
|
||||||
add_attribute(libraries='png')
|
add_attribute(libraries='png')
|
||||||
|
|
||||||
|
if @HAVE_MEMFS@:
|
||||||
|
add_attribute(libraries='eccodes_memfs')
|
||||||
|
|
||||||
if @HAVE_AEC@:
|
if @HAVE_AEC@:
|
||||||
aec_dir = '@AEC_DIR@'
|
aec_dir = '@AEC_DIR@'
|
||||||
if aec_dir and aec_dir != 'system':
|
if aec_dir and aec_dir != 'system':
|
||||||
|
|
|
@ -222,12 +222,12 @@ void grib_push_accessor(grib_accessor* a, grib_block_of_accessors* l)
|
||||||
}
|
}
|
||||||
l->last = a;
|
l->last = a;
|
||||||
|
|
||||||
|
|
||||||
if (grib_handle_of_accessor(a)->use_trie) {
|
if (grib_handle_of_accessor(a)->use_trie) {
|
||||||
if (*(a->all_names[0]) != '_') {
|
if (*(a->all_names[0]) != '_') {
|
||||||
id=grib_hash_keys_get_id(a->context->keys,a->all_names[0]);
|
id=grib_hash_keys_get_id(a->context->keys,a->all_names[0]);
|
||||||
|
#ifdef DEBUG
|
||||||
|
Assert(id >=0 && id < ACCESSORS_ARRAY_SIZE);
|
||||||
|
#endif
|
||||||
a->same=grib_handle_of_accessor(a)->accessors[id];
|
a->same=grib_handle_of_accessor(a)->accessors[id];
|
||||||
link_same_attributes(a,a->same);
|
link_same_attributes(a,a->same);
|
||||||
grib_handle_of_accessor(a)->accessors[id]=a;
|
grib_handle_of_accessor(a)->accessors[id]=a;
|
||||||
|
|
|
@ -1539,7 +1539,7 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_acce
|
||||||
switch (self->expanded->v[idx]->F) {
|
switch (self->expanded->v[idx]->F) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
creator.name=grib_context_strdup(a->context,self->expanded->v[idx]->shortName);
|
creator.name=grib_context_strdup(a->context, self->expanded->v[idx]->shortName);
|
||||||
elementAccessor = grib_accessor_factory(section, &creator, 0, NULL);
|
elementAccessor = grib_accessor_factory(section, &creator, 0, NULL);
|
||||||
if (self->canBeMissing[idx]) elementAccessor->flags |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING;
|
if (self->canBeMissing[idx]) elementAccessor->flags |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING;
|
||||||
if (self->expanded->v[idx]->code == 31000 || self->expanded->v[idx]->code == 31001 || self->expanded->v[idx]->code == 31002 || self->expanded->v[idx]->code == 31031)
|
if (self->expanded->v[idx]->code == 31000 || self->expanded->v[idx]->code == 31001 || self->expanded->v[idx]->code == 31002 || self->expanded->v[idx]->code == 31031)
|
||||||
|
@ -1828,22 +1828,25 @@ static grib_accessor* accessor_or_attribute_with_same_name(grib_accessor* a,cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_key_rank(grib_trie* accessorsRank,grib_accessor* a) {
|
static int get_key_rank(grib_trie* accessorsRank,grib_accessor* a)
|
||||||
int* r=(int*)grib_trie_get(accessorsRank,a->name);
|
{
|
||||||
|
int* r=(int*)grib_trie_get(accessorsRank,a->name);
|
||||||
|
|
||||||
if (r) (*r)++;
|
if (r) (*r)++;
|
||||||
else {
|
else {
|
||||||
r=grib_context_malloc(a->context,sizeof(int));
|
r=grib_context_malloc(a->context,sizeof(int));
|
||||||
*r=1;
|
*r=1;
|
||||||
grib_trie_insert(accessorsRank,a->name,(void*)r);
|
grib_trie_insert(accessorsRank,a->name,(void*)r);
|
||||||
}
|
}
|
||||||
return *r;
|
return *r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void grib_data_accessors_trie_push(grib_trie* accessorsTrie,grib_accessor* a,int r) {
|
static void grib_data_accessors_trie_push(grib_trie* accessorsTrie, grib_accessor* a, int r)
|
||||||
char* name=grib_context_malloc_clear(a->context,strlen(a->name)+20);
|
{
|
||||||
sprintf(name,"#%d#%s",r,a->name);
|
char* name=grib_context_malloc_clear(a->context, strlen(a->name)+20);
|
||||||
grib_trie_insert(accessorsTrie,name,a);
|
sprintf(name,"#%d#%s", r, a->name);
|
||||||
|
grib_trie_insert(accessorsTrie, name, a);
|
||||||
|
grib_context_free(a->context, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_keys(grib_accessor* a,long onlySubset,long startSubset,long endSubset)
|
static int create_keys(grib_accessor* a,long onlySubset,long startSubset,long endSubset)
|
||||||
|
|
|
@ -278,12 +278,12 @@ static int pack_double(grib_accessor* a, const double* cval, size_t *len)
|
||||||
return GRIB_SUCCESS;
|
return GRIB_SUCCESS;
|
||||||
break;
|
break;
|
||||||
case GRIB_INVALID_BPV:
|
case GRIB_INVALID_BPV:
|
||||||
grib_context_log(a->context,GRIB_LOG_ERROR,"unable to compute packing parameters\n");
|
grib_context_log(a->context,GRIB_LOG_ERROR,"unable to compute packing parameters. Invalid bits per value\n");
|
||||||
return ret;
|
return ret;
|
||||||
case GRIB_SUCCESS:
|
case GRIB_SUCCESS:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
grib_context_log(a->context,GRIB_LOG_FATAL,"unable to compute packing parameters\n");
|
grib_context_log(a->context,GRIB_LOG_ERROR,"unable to compute packing parameters\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ extern "C" {
|
||||||
|
|
||||||
#define MAX_ACCESSOR_ATTRIBUTES 20
|
#define MAX_ACCESSOR_ATTRIBUTES 20
|
||||||
#define MAX_FILE_HANDLES_WITH_MULTI 10
|
#define MAX_FILE_HANDLES_WITH_MULTI 10
|
||||||
#define ACCESSORS_ARRAY_SIZE 20000
|
#define ACCESSORS_ARRAY_SIZE 5000
|
||||||
#define MAX_NUM_CONCEPTS 2000
|
#define MAX_NUM_CONCEPTS 2000
|
||||||
#define MAX_NUM_HASH_ARRAY 2000
|
#define MAX_NUM_HASH_ARRAY 2000
|
||||||
|
|
||||||
|
|
|
@ -199,9 +199,9 @@ static void dump_values(grib_dumper* d,grib_accessor* a)
|
||||||
grib_context_free(c,values);
|
grib_context_free(c,values);
|
||||||
|
|
||||||
if ((r=compute_bufr_key_rank(h,self->keys,a->name))!=0)
|
if ((r=compute_bufr_key_rank(h,self->keys,a->name))!=0)
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '#%d#%s', rvalues)\n",r,a->name);
|
fprintf(self->dumper.out," codes_set_array(ibufr, '#%d#%s', rvalues)\n",r,a->name);
|
||||||
else
|
else
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '%s', rvalues)\n",a->name);
|
fprintf(self->dumper.out," codes_set_array(ibufr, '%s', rvalues)\n",a->name);
|
||||||
} else {
|
} else {
|
||||||
r=compute_bufr_key_rank(h,self->keys,a->name);
|
r=compute_bufr_key_rank(h,self->keys,a->name);
|
||||||
if( !grib_is_missing_double(a,value) ) {
|
if( !grib_is_missing_double(a,value) ) {
|
||||||
|
@ -283,7 +283,7 @@ static void dump_values_attribute(grib_dumper* d,grib_accessor* a, const char* p
|
||||||
fprintf(self->dumper.out,",)\n");
|
fprintf(self->dumper.out,",)\n");
|
||||||
grib_context_free(c,values);
|
grib_context_free(c,values);
|
||||||
|
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '%s->%s' \n, rvalues)\n",prefix,a->name);
|
fprintf(self->dumper.out," codes_set_array(ibufr, '%s->%s' \n, rvalues)\n",prefix,a->name);
|
||||||
} else {
|
} else {
|
||||||
/* int r=compute_bufr_key_rank(h,self->keys,a->name); */
|
/* int r=compute_bufr_key_rank(h,self->keys,a->name); */
|
||||||
if( !grib_is_missing_double(a,value) ) {
|
if( !grib_is_missing_double(a,value) ) {
|
||||||
|
@ -372,9 +372,9 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
|
||||||
grib_context_free(a->context,values);
|
grib_context_free(a->context,values);
|
||||||
|
|
||||||
if ((r=compute_bufr_key_rank(h,self->keys,a->name))!=0)
|
if ((r=compute_bufr_key_rank(h,self->keys,a->name))!=0)
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '#%d#%s', ivalues)\n",r,a->name);
|
fprintf(self->dumper.out," codes_set_array(ibufr, '#%d#%s', ivalues)\n",r,a->name);
|
||||||
else
|
else
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '%s', ivalues)\n",a->name);
|
fprintf(self->dumper.out," codes_set_array(ibufr, '%s', ivalues)\n",a->name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
r=compute_bufr_key_rank(h,self->keys,a->name);
|
r=compute_bufr_key_rank(h,self->keys,a->name);
|
||||||
|
@ -447,7 +447,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
|
||||||
fprintf(self->dumper.out,",)\n");
|
fprintf(self->dumper.out,",)\n");
|
||||||
grib_context_free(a->context,values);
|
grib_context_free(a->context,values);
|
||||||
|
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '%s->%s' \n,ivalues)\n",prefix,a->name);
|
fprintf(self->dumper.out," codes_set_array(ibufr, '%s->%s' \n,ivalues)\n",prefix,a->name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* int r=compute_bufr_key_rank(h,self->keys,a->name); */
|
/* int r=compute_bufr_key_rank(h,self->keys,a->name); */
|
||||||
|
@ -559,9 +559,9 @@ static void dump_string_array(grib_dumper* d,grib_accessor* a,const char* commen
|
||||||
|
|
||||||
if (self->isLeaf==0) {
|
if (self->isLeaf==0) {
|
||||||
if ((r=compute_bufr_key_rank(h,self->keys,a->name))!=0)
|
if ((r=compute_bufr_key_rank(h,self->keys,a->name))!=0)
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '#%d#%s', svalues)\n",r,a->name);
|
fprintf(self->dumper.out," codes_set_string_array(ibufr, '#%d#%s', svalues)\n",r,a->name);
|
||||||
else
|
else
|
||||||
fprintf(self->dumper.out," codes_set(ibufr, '%s', svalues)\n",a->name);
|
fprintf(self->dumper.out," codes_set_string_array(ibufr, '%s', svalues)\n",a->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->isLeaf==0) {
|
if (self->isLeaf==0) {
|
||||||
|
@ -675,7 +675,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
|
||||||
fprintf(f,"%ld ,)\n",val[size-1]);
|
fprintf(f,"%ld ,)\n",val[size-1]);
|
||||||
|
|
||||||
grib_context_free(h->context,val);
|
grib_context_free(h->context,val);
|
||||||
fprintf(f," codes_set(ibufr, '%s', ivalues)\n",print_key);
|
fprintf(f," codes_set_array(ibufr, '%s', ivalues)\n",print_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block)
|
static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block)
|
||||||
|
|
|
@ -8124,7 +8124,7 @@ int grib_hash_keys_insert(grib_itrie* t,const char* key)
|
||||||
(*(t->count))++;
|
(*(t->count))++;
|
||||||
} else {
|
} else {
|
||||||
grib_context_log(t->context,GRIB_LOG_ERROR,
|
grib_context_log(t->context,GRIB_LOG_ERROR,
|
||||||
"grib_hash_keys_get_id: too many accessors, increase ACCESSORS_ARRAY_SIZE\n");
|
"grib_hash_keys_insert: too many accessors, increase ACCESSORS_ARRAY_SIZE\n");
|
||||||
Assert(*(t->count)+TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE);
|
Assert(*(t->count)+TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
119
src/grib_itrie.c
119
src/grib_itrie.c
|
@ -310,90 +310,91 @@ struct grib_itrie {
|
||||||
|
|
||||||
grib_itrie *grib_itrie_new(grib_context* c,int* count)
|
grib_itrie *grib_itrie_new(grib_context* c,int* count)
|
||||||
{
|
{
|
||||||
grib_itrie* t = (grib_itrie*)grib_context_malloc_clear(c,sizeof(grib_itrie));
|
grib_itrie* t = (grib_itrie*)grib_context_malloc_clear(c,sizeof(grib_itrie));
|
||||||
t->context = c;
|
t->context = c;
|
||||||
t->id=-1;
|
t->id=-1;
|
||||||
t->count=count;
|
t->count=count;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void grib_itrie_delete(grib_itrie *t) {
|
void grib_itrie_delete(grib_itrie *t)
|
||||||
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
{
|
||||||
GRIB_MUTEX_LOCK(&mutex)
|
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
||||||
|
GRIB_MUTEX_LOCK(&mutex)
|
||||||
|
|
||||||
if(t) {
|
if(t) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < SIZE; i++)
|
for(i = 0; i < SIZE; i++)
|
||||||
if (t->next[i])
|
if (t->next[i])
|
||||||
grib_itrie_delete(t->next[i]);
|
grib_itrie_delete(t->next[i]);
|
||||||
|
|
||||||
grib_context_free(t->context,t);
|
grib_context_free(t->context,t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
GRIB_MUTEX_UNLOCK(&mutex)
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_itrie_get_id(grib_itrie* t,const char* key)
|
int grib_itrie_get_id(grib_itrie* t,const char* key)
|
||||||
{
|
{
|
||||||
const char *k=key;
|
const char *k=key;
|
||||||
grib_itrie* last=t;
|
grib_itrie* last=t;
|
||||||
|
|
||||||
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
||||||
GRIB_MUTEX_LOCK(&mutex)
|
GRIB_MUTEX_LOCK(&mutex)
|
||||||
|
|
||||||
while(*k && t) t = t->next[mapping[(int)*k++]];
|
while(*k && t) t = t->next[mapping[(int)*k++]];
|
||||||
|
|
||||||
if(t != NULL && t->id != -1) {
|
if(t != NULL && t->id != -1) {
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
GRIB_MUTEX_UNLOCK(&mutex)
|
||||||
return t->id;
|
return t->id;
|
||||||
} else {
|
} else {
|
||||||
int ret=grib_itrie_insert(last,key);
|
int ret=grib_itrie_insert(last,key);
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
GRIB_MUTEX_UNLOCK(&mutex)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_itrie_insert(grib_itrie* t,const char* key)
|
int grib_itrie_insert(grib_itrie* t,const char* key)
|
||||||
{
|
{
|
||||||
const char *k = key;
|
const char *k = key;
|
||||||
grib_itrie *last = t;
|
grib_itrie *last = t;
|
||||||
int* count;
|
int* count;
|
||||||
|
|
||||||
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
||||||
|
|
||||||
GRIB_MUTEX_LOCK(&mutex)
|
GRIB_MUTEX_LOCK(&mutex)
|
||||||
|
|
||||||
count=t->count;
|
count=t->count;
|
||||||
|
|
||||||
while(*k && t) {
|
while(*k && t) {
|
||||||
last = t;
|
last = t;
|
||||||
t = t->next[mapping[(int)*k]];
|
t = t->next[mapping[(int)*k]];
|
||||||
if(t) k++;
|
if(t) k++;
|
||||||
}
|
|
||||||
|
|
||||||
if (*k!=0) {
|
|
||||||
t=last;
|
|
||||||
while(*k) {
|
|
||||||
int j = mapping[(int)*k++];
|
|
||||||
t->next[j] = grib_itrie_new(t->context,count);
|
|
||||||
t = t->next[j];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (*(t->count) < MAX_NUM_CONCEPTS) {
|
|
||||||
t->id=*(t->count);
|
|
||||||
(*(t->count))++;
|
|
||||||
} else {
|
|
||||||
grib_context_log(t->context,GRIB_LOG_ERROR,
|
|
||||||
"grib_itrie_get_id: too many accessors, increase MAX_NUM_CONCEPTS\n");
|
|
||||||
Assert(*(t->count) < MAX_NUM_CONCEPTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
if (*k!=0) {
|
||||||
|
t=last;
|
||||||
|
while(*k) {
|
||||||
|
int j = mapping[(int)*k++];
|
||||||
|
t->next[j] = grib_itrie_new(t->context,count);
|
||||||
|
t = t->next[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*(t->count) < MAX_NUM_CONCEPTS) {
|
||||||
|
t->id=*(t->count);
|
||||||
|
(*(t->count))++;
|
||||||
|
} else {
|
||||||
|
grib_context_log(t->context,GRIB_LOG_ERROR,
|
||||||
|
"grib_itrie_insert: too many accessors, increase MAX_NUM_CONCEPTS\n");
|
||||||
|
Assert(*(t->count) < MAX_NUM_CONCEPTS);
|
||||||
|
}
|
||||||
|
|
||||||
/*printf("grib_itrie_get_id: %s -> %d\n",key,t->id);*/
|
GRIB_MUTEX_UNLOCK(&mutex)
|
||||||
|
|
||||||
return t->id;
|
/*printf("grib_itrie_get_id: %s -> %d\n",key,t->id);*/
|
||||||
|
|
||||||
|
return t->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_itrie_get_size(grib_itrie* t) {return *(t->count);}
|
int grib_itrie_get_size(grib_itrie* t) {return *(t->count);}
|
||||||
|
|
|
@ -310,100 +310,102 @@ struct grib_itrie {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
grib_itrie *grib_hash_keys_new(grib_context* c,int* count) {
|
grib_itrie *grib_hash_keys_new(grib_context* c,int* count)
|
||||||
grib_itrie* t = (grib_itrie*)grib_context_malloc_clear(c,sizeof(grib_itrie));
|
{
|
||||||
t->context = c;
|
grib_itrie* t = (grib_itrie*)grib_context_malloc_clear(c,sizeof(grib_itrie));
|
||||||
t->id=-1;
|
t->context = c;
|
||||||
t->count=count;
|
t->id=-1;
|
||||||
return t;
|
t->count=count;
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void grib_hash_keys_delete(grib_itrie *t) {
|
void grib_hash_keys_delete(grib_itrie *t)
|
||||||
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
{
|
||||||
GRIB_MUTEX_LOCK(&mutex)
|
GRIB_MUTEX_INIT_ONCE(&once,&init);
|
||||||
|
GRIB_MUTEX_LOCK(&mutex);
|
||||||
|
|
||||||
if(t) {
|
if(t) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < SIZE; i++)
|
for(i = 0; i < SIZE; i++)
|
||||||
if (t->next[i])
|
if (t->next[i])
|
||||||
grib_hash_keys_delete(t->next[i]);
|
grib_hash_keys_delete(t->next[i]);
|
||||||
|
|
||||||
grib_context_free(t->context,t);
|
grib_context_free(t->context,t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
GRIB_MUTEX_UNLOCK(&mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_hash_keys_get_id(grib_itrie* t,const char* key)
|
int grib_hash_keys_get_id(grib_itrie* t,const char* key)
|
||||||
{
|
{
|
||||||
const char *k=key;
|
const char *k=key;
|
||||||
grib_itrie* last=t;
|
grib_itrie* last=t;
|
||||||
|
|
||||||
struct grib_keys_hash* hash=grib_keys_hash_get(key,strlen(key));
|
struct grib_keys_hash* hash=grib_keys_hash_get(key,strlen(key));
|
||||||
|
|
||||||
if (hash) {
|
if (hash) {
|
||||||
/* printf("%s found %s (%d)\n",key,hash->name,hash->id); */
|
/* printf("%s found %s (%d)\n",key,hash->name,hash->id); */
|
||||||
return hash->id;
|
return hash->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* printf("+++ \"%s\"\n",key); */
|
/* printf("+++ \"%s\"\n",key); */
|
||||||
|
|
||||||
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
GRIB_MUTEX_INIT_ONCE(&once,&init);
|
||||||
GRIB_MUTEX_LOCK(&mutex)
|
GRIB_MUTEX_LOCK(&mutex);
|
||||||
|
|
||||||
while(*k && t) t = t->next[mapping[(int)*k++]];
|
while(*k && t) t = t->next[mapping[(int)*k++]];
|
||||||
|
|
||||||
if(t != NULL && t->id != -1) {
|
if(t != NULL && t->id != -1) {
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
GRIB_MUTEX_UNLOCK(&mutex);
|
||||||
return t->id+TOTAL_KEYWORDS+1;
|
return t->id+TOTAL_KEYWORDS+1;
|
||||||
} else {
|
} else {
|
||||||
int ret=grib_hash_keys_insert(last,key);
|
int ret=grib_hash_keys_insert(last,key);
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
GRIB_MUTEX_UNLOCK(&mutex);
|
||||||
return ret+TOTAL_KEYWORDS+1;
|
return ret+TOTAL_KEYWORDS+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_hash_keys_insert(grib_itrie* t,const char* key)
|
int grib_hash_keys_insert(grib_itrie* t,const char* key)
|
||||||
{
|
{
|
||||||
const char *k = key;
|
const char *k = key;
|
||||||
grib_itrie *last = t;
|
grib_itrie *last = t;
|
||||||
int* count;
|
int* count;
|
||||||
|
|
||||||
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
GRIB_MUTEX_INIT_ONCE(&once,&init)
|
||||||
|
|
||||||
GRIB_MUTEX_LOCK(&mutex)
|
GRIB_MUTEX_LOCK(&mutex)
|
||||||
|
|
||||||
count=t->count;
|
count=t->count;
|
||||||
|
|
||||||
while(*k && t) {
|
while(*k && t) {
|
||||||
last = t;
|
last = t;
|
||||||
t = t->next[mapping[(int)*k]];
|
t = t->next[mapping[(int)*k]];
|
||||||
if(t) k++;
|
if(t) k++;
|
||||||
}
|
|
||||||
|
|
||||||
if (*k!=0) {
|
|
||||||
t=last;
|
|
||||||
while(*k) {
|
|
||||||
int j = mapping[(int)*k++];
|
|
||||||
t->next[j] = grib_hash_keys_new(t->context,count);
|
|
||||||
t = t->next[j];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (*(t->count)+TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE) {
|
|
||||||
t->id=*(t->count);
|
|
||||||
(*(t->count))++;
|
|
||||||
} else {
|
|
||||||
grib_context_log(t->context,GRIB_LOG_ERROR,
|
|
||||||
"grib_hash_keys_get_id: too many accessors, increase ACCESSORS_ARRAY_SIZE\n");
|
|
||||||
Assert(*(t->count)+TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
GRIB_MUTEX_UNLOCK(&mutex)
|
if (*k!=0) {
|
||||||
|
t=last;
|
||||||
|
while(*k) {
|
||||||
|
int j = mapping[(int)*k++];
|
||||||
|
t->next[j] = grib_hash_keys_new(t->context,count);
|
||||||
|
t = t->next[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*(t->count)+TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE) {
|
||||||
|
t->id=*(t->count);
|
||||||
|
(*(t->count))++;
|
||||||
|
} else {
|
||||||
|
grib_context_log(t->context,GRIB_LOG_ERROR,
|
||||||
|
"grib_hash_keys_insert: too many accessors, increase ACCESSORS_ARRAY_SIZE\n");
|
||||||
|
Assert(*(t->count)+TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
/*printf("grib_hash_keys_get_id: %s -> %d\n",key,t->id);*/
|
GRIB_MUTEX_UNLOCK(&mutex)
|
||||||
|
|
||||||
return t->id;
|
/*printf("grib_hash_keys_get_id: %s -> %d\n",key,t->id);*/
|
||||||
|
|
||||||
|
return t->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_hash_keys_get_size(grib_itrie* t) {return *(t->count);}
|
int grib_hash_keys_get_size(grib_itrie* t) {return *(t->count);}
|
||||||
|
|
|
@ -31,7 +31,6 @@ if [ $skip_test -eq 1 ]; then
|
||||||
fi
|
fi
|
||||||
echo "AEC feature was enabled."
|
echo "AEC feature was enabled."
|
||||||
|
|
||||||
BLACKLIST="totalLength,section5Length,section7Length,dataRepresentationTemplateNumber,typeOfPacking"
|
|
||||||
BLACKLIST="totalLength,section5Length,section7Length,dataRepresentationTemplateNumber"
|
BLACKLIST="totalLength,section5Length,section7Length,dataRepresentationTemplateNumber"
|
||||||
|
|
||||||
infile=${data_dir}/ccsds.grib2
|
infile=${data_dir}/ccsds.grib2
|
||||||
|
@ -72,6 +71,7 @@ res3=`${tools_dir}grib_get '-F%1.2f' -p min,max,avg $outfile2`
|
||||||
|
|
||||||
rm -f $outfile1 $outfile2 || true
|
rm -f $outfile1 $outfile2 || true
|
||||||
|
|
||||||
|
# ECC-297
|
||||||
infile=${data_dir}/tigge_ecmwf.grib2
|
infile=${data_dir}/tigge_ecmwf.grib2
|
||||||
outfile1=$infile.tmp_ccsds.1
|
outfile1=$infile.tmp_ccsds.1
|
||||||
outfile2=$infile.tmp_ccsds.2
|
outfile2=$infile.tmp_ccsds.2
|
||||||
|
|
Loading…
Reference in New Issue