mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'feature/modernisation_merge_accessor_classes' of github.com:ecmwf/eccodes into feature/modernisation_merge_accessor_classes
This commit is contained in:
commit
7ee915b8c3
|
@ -60,7 +60,6 @@ public:
|
|||
virtual grib_accessor* next_accessor() = 0;
|
||||
virtual void resize(size_t new_size) = 0;
|
||||
virtual void destroy(grib_context* ct) = 0;
|
||||
|
||||
virtual int compare_accessors(grib_accessor* a2, int compare_flags);
|
||||
virtual int compare(grib_accessor*) = 0;
|
||||
virtual int add_attribute(grib_accessor* attr, int nest_if_clash);
|
||||
|
@ -78,8 +77,7 @@ public:
|
|||
virtual grib_accessor* make_clone(grib_section*, int*) = 0;
|
||||
|
||||
public:
|
||||
// private:
|
||||
// TODO(maee): make members private
|
||||
// TODO(maee): make private
|
||||
grib_context* context_;
|
||||
const char* name_; /** < name of the accessor */
|
||||
const char* class_name_; /** < name of the class (Artifact from C version of ecCodes) */
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; }
|
||||
|
||||
public:
|
||||
// TODO(maee): make private
|
||||
long* v_;
|
||||
long pack_index_;
|
||||
int number_of_elements_;
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; }
|
||||
|
||||
public:
|
||||
// TODO(maee): make private
|
||||
double* v_;
|
||||
int number_of_elements_;
|
||||
};
|
||||
|
|
|
@ -14,15 +14,14 @@
|
|||
grib_accessor_bitmap_t _grib_accessor_bitmap{};
|
||||
grib_accessor* grib_accessor_bitmap = &_grib_accessor_bitmap;
|
||||
|
||||
static void compute_size(grib_accessor* a)
|
||||
void grib_accessor_bitmap_t::compute_size()
|
||||
{
|
||||
grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a;
|
||||
long slen = 0;
|
||||
long off = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
grib_get_long_internal(hand, self->offsetbsec_, &off);
|
||||
grib_get_long_internal(hand, self->sLength_, &slen);
|
||||
grib_get_long_internal(hand, offsetbsec_, &off);
|
||||
grib_get_long_internal(hand, sLength_, &slen);
|
||||
|
||||
if (slen == 0) {
|
||||
grib_accessor* seclen;
|
||||
|
@ -30,7 +29,7 @@ static void compute_size(grib_accessor* a)
|
|||
/* Assume reparsing */
|
||||
Assert(hand->loader != 0);
|
||||
if (hand->loader != 0) {
|
||||
seclen = grib_find_accessor(hand, self->sLength_);
|
||||
seclen = grib_find_accessor(hand, sLength_);
|
||||
Assert(seclen);
|
||||
grib_get_block_length(seclen->parent_, &size);
|
||||
slen = size;
|
||||
|
@ -39,15 +38,15 @@ static void compute_size(grib_accessor* a)
|
|||
|
||||
// printf("compute_size off=%ld slen=%ld a->offset_=%ld\n", (long)off,(long)slen,(long)offset_ );
|
||||
|
||||
a->length_ = off + (slen - a->offset_);
|
||||
length_ = off + (slen - offset_);
|
||||
|
||||
if (a->length_ < 0) {
|
||||
if (length_ < 0) {
|
||||
/* Assume reparsing */
|
||||
/*Assert(hand->loader != 0);*/
|
||||
a->length_ = 0;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
Assert(a->length_ >= 0);
|
||||
Assert(length_ >= 0);
|
||||
}
|
||||
|
||||
void grib_accessor_bitmap_t::init(const long len, grib_arguments* arg)
|
||||
|
@ -61,7 +60,7 @@ void grib_accessor_bitmap_t::init(const long len, grib_arguments* arg)
|
|||
offsetbsec_ = grib_arguments_get_name(hand, arg, n++);
|
||||
sLength_ = grib_arguments_get_name(hand, arg, n++);
|
||||
|
||||
compute_size(this);
|
||||
compute_size();
|
||||
}
|
||||
|
||||
long grib_accessor_bitmap_t::next_offset()
|
||||
|
|
|
@ -30,10 +30,14 @@ public:
|
|||
void update_size(size_t) override;
|
||||
int unpack_double_element(size_t i, double* val) override;
|
||||
int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override;
|
||||
// TODO(maee): make members private
|
||||
public:
|
||||
const char* tableReference_;
|
||||
|
||||
protected:
|
||||
const char* missing_value_;
|
||||
|
||||
private:
|
||||
const char* tableReference_;
|
||||
const char* offsetbsec_;
|
||||
const char* sLength_;
|
||||
|
||||
void compute_size();
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -11,6 +11,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "grib_accessor_class_gen.h"
|
||||
#include "grib_accessor_class_expanded_descriptors.h"
|
||||
|
||||
typedef struct bitmap_s
|
||||
{
|
||||
grib_accessors_list* cursor;
|
||||
grib_accessors_list* referredElement;
|
||||
grib_accessors_list* referredElementStart;
|
||||
} bitmap_s;
|
||||
|
||||
|
||||
class grib_accessor_bufr_data_array_t;
|
||||
|
||||
typedef int (*codec_element_proc)(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
|
||||
|
||||
typedef int (*codec_replication_proc)(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
|
||||
|
||||
|
||||
class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t
|
||||
{
|
||||
|
@ -30,7 +46,12 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
void accessor_bufr_data_array_set_unpackMode(int);
|
||||
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors();
|
||||
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie();
|
||||
grib_vsarray* accessor_bufr_data_array_get_stringValues();
|
||||
|
||||
private:
|
||||
const char* bufrDataEncodedName_;
|
||||
const char* numberOfSubsetsName_;
|
||||
const char* expandedDescriptorsName_;
|
||||
|
@ -39,7 +60,7 @@ public:
|
|||
const char* elementsDescriptorsIndexName_;
|
||||
const char* compressedDataName_;
|
||||
bufr_descriptors_array* expanded_;
|
||||
grib_accessor* expandedAccessor_;
|
||||
grib_accessor_expanded_descriptors_t* expandedAccessor_;
|
||||
int* canBeMissing_;
|
||||
long numberOfSubsets_;
|
||||
long compressedData_;
|
||||
|
@ -78,9 +99,47 @@ public:
|
|||
long refValIndex_;
|
||||
bufr_tableb_override* tableb_override_;
|
||||
int set_to_missing_if_out_of_range_;
|
||||
};
|
||||
|
||||
grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor*);
|
||||
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor*);
|
||||
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor*);
|
||||
void accessor_bufr_data_array_set_unpackMode(grib_accessor*, int unpackMode);
|
||||
void restart_bitmap();
|
||||
void cancel_bitmap();
|
||||
int is_bitmap_start_defined();
|
||||
size_t get_length();
|
||||
void tableB_override_store_ref_val(grib_context*, int, long);
|
||||
int tableB_override_get_ref_val(int, long*);
|
||||
void tableB_override_clear(grib_context*);
|
||||
int tableB_override_set_key(grib_handle*);
|
||||
int get_descriptors();
|
||||
int decode_string_array(grib_context*, unsigned char*, long*, bufr_descriptor*);
|
||||
int encode_string_array(grib_context*, grib_buffer*, long*, bufr_descriptor*, grib_sarray*);
|
||||
int encode_double_array(grib_context*, grib_buffer*, long*, bufr_descriptor*, grib_darray*);
|
||||
int encode_double_value(grib_context*, grib_buffer*, long*, bufr_descriptor*, double);
|
||||
char* decode_string_value(grib_context*, unsigned char*, long*, bufr_descriptor*, int*);
|
||||
double decode_double_value(grib_context*, unsigned char*, long*, bufr_descriptor*, int, int*);
|
||||
int encode_new_bitmap(grib_context*, grib_buffer*, long*, int);
|
||||
grib_darray* doubleValues = NULL;
|
||||
int encode_overridden_reference_value(grib_context*, grib_buffer*, long*, bufr_descriptor*);
|
||||
int build_bitmap(unsigned char*, long*, int, grib_iarray*, int);
|
||||
int consume_bitmap(int);
|
||||
int build_bitmap_new_data(unsigned char*, long*, int, grib_iarray*, int);
|
||||
int get_next_bitmap_descriptor_index_new_bitmap(grib_iarray*, int);
|
||||
int get_next_bitmap_descriptor_index(grib_iarray*, grib_darray*);
|
||||
void push_zero_element(grib_darray*);
|
||||
grib_accessor* create_attribute_variable(const char*, grib_section*, int, char*, double, long, unsigned long);
|
||||
grib_accessor* create_accessor_from_descriptor(grib_accessor*, grib_section*, long, long, int, int, int, int);
|
||||
grib_iarray* set_subset_list( grib_context*, long, long, long, const long*, size_t);
|
||||
void print_bitmap_debug_info(grib_context*, bitmap_s*, grib_accessors_list*, int);
|
||||
int create_keys(long, long, long);
|
||||
void set_input_replications(grib_handle*);
|
||||
void set_input_bitmap(grib_handle*);
|
||||
int process_elements(int, long, long, long);
|
||||
void self_clear();
|
||||
grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, int canBeMissing, int*);
|
||||
|
||||
friend int check_end_data(grib_context*, bufr_descriptor*, grib_accessor_bufr_data_array_t*, int);
|
||||
friend int decode_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
|
||||
friend int decode_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
|
||||
friend int encode_new_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
|
||||
friend int encode_new_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
|
||||
friend int encode_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
|
||||
friend int encode_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
|
||||
};
|
||||
|
|
|
@ -18,7 +18,6 @@ grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, in
|
|||
grib_accessor* the_clone = NULL;
|
||||
grib_accessor* attribute = NULL;
|
||||
grib_accessor_bufr_data_element_t* elementAccessor;
|
||||
grib_accessor_bufr_data_element_t* self;
|
||||
char* copied_name = NULL;
|
||||
int i;
|
||||
grib_action creator = {
|
||||
|
@ -36,20 +35,19 @@ grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, in
|
|||
the_clone = grib_accessor_factory(s, &creator, 0, NULL);
|
||||
copied_name = grib_context_strdup(context_, name_);
|
||||
the_clone->name_ = copied_name;
|
||||
elementAccessor = (grib_accessor_bufr_data_element_t*)the_clone;
|
||||
self = (grib_accessor_bufr_data_element_t*)this;
|
||||
elementAccessor = dynamic_cast<grib_accessor_bufr_data_element_t*>(the_clone);
|
||||
the_clone->flags_ = flags_;
|
||||
the_clone->parent_ = NULL;
|
||||
the_clone->h_ = s->h;
|
||||
elementAccessor->index_ = self->index_;
|
||||
elementAccessor->type_ = self->type_;
|
||||
elementAccessor->numberOfSubsets_ = self->numberOfSubsets_;
|
||||
elementAccessor->subsetNumber_ = self->subsetNumber_;
|
||||
elementAccessor->compressedData_ = self->compressedData_;
|
||||
elementAccessor->descriptors_ = self->descriptors_;
|
||||
elementAccessor->numericValues_ = self->numericValues_;
|
||||
elementAccessor->stringValues_ = self->stringValues_;
|
||||
elementAccessor->elementsDescriptorsIndex_ = self->elementsDescriptorsIndex_;
|
||||
elementAccessor->index_ = index_;
|
||||
elementAccessor->type_ = type_;
|
||||
elementAccessor->numberOfSubsets_ = numberOfSubsets_;
|
||||
elementAccessor->subsetNumber_ = subsetNumber_;
|
||||
elementAccessor->compressedData_ = compressedData_;
|
||||
elementAccessor->descriptors_ = descriptors_;
|
||||
elementAccessor->numericValues_ = numericValues_;
|
||||
elementAccessor->stringValues_ = stringValues_;
|
||||
elementAccessor->elementsDescriptorsIndex_ = elementsDescriptorsIndex_;
|
||||
elementAccessor->cname_ = copied_name; /* ECC-765 */
|
||||
|
||||
i = 0;
|
||||
|
@ -63,60 +61,6 @@ grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, in
|
|||
return the_clone;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_index(grib_accessor* a, long index)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->index_ = index;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_type(grib_accessor* a, int type)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->type_ = type;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->numberOfSubsets_ = numberOfSubsets;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->subsetNumber_ = subsetNumber;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->compressedData_ = compressedData;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->descriptors_ = descriptors;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->numericValues_ = numericValues;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->stringValues_ = stringValues;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->elementsDescriptorsIndex_ = elementsDescriptorsIndex;
|
||||
}
|
||||
|
||||
void grib_accessor_bufr_data_element_t::init(const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_gen_t::init(len, params);
|
||||
|
|
|
@ -37,7 +37,17 @@ public:
|
|||
int unpack_double_element(size_t i, double* val) override;
|
||||
grib_accessor* make_clone(grib_section*, int*) override;
|
||||
|
||||
public:
|
||||
void index(long index) { index_ = index; }
|
||||
void type(int type) { type_ = type; }
|
||||
void numberOfSubsets(long numberOfSubsets) { numberOfSubsets_ = numberOfSubsets; }
|
||||
void subsetNumber(long subsetNumber) { subsetNumber_ = subsetNumber; }
|
||||
void compressedData(int compressedData) { compressedData_ = compressedData; }
|
||||
void descriptors(bufr_descriptors_array* descriptors) { descriptors_ = descriptors; }
|
||||
void numericValues(grib_vdarray* numericValues) { numericValues_ = numericValues; }
|
||||
void stringValues(grib_vsarray* stringValues) { stringValues_ = stringValues; }
|
||||
void elementsDescriptorsIndex(grib_viarray* elementsDescriptorsIndex) { elementsDescriptorsIndex_ = elementsDescriptorsIndex; }
|
||||
|
||||
private:
|
||||
long index_;
|
||||
int type_;
|
||||
long compressedData_;
|
||||
|
|
|
@ -55,9 +55,8 @@ void grib_accessor_bufr_elements_table_t::init(const long len, grib_arguments* p
|
|||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
|
||||
grib_trie* grib_accessor_bufr_elements_table_t::load_bufr_elements_table(int* err)
|
||||
{
|
||||
grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a;
|
||||
char* filename = NULL;
|
||||
char line[1024] = {
|
||||
0,
|
||||
|
@ -83,17 +82,17 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
|
|||
size_t len = 1024;
|
||||
grib_trie* dictionary = NULL;
|
||||
FILE* f = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_context* c = a->context_;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_context* c = context_;
|
||||
|
||||
*err = GRIB_SUCCESS;
|
||||
|
||||
len = 1024;
|
||||
if (self->masterDir_ != NULL)
|
||||
grib_get_string(h, self->masterDir_, masterDir, &len);
|
||||
if (masterDir_ != NULL)
|
||||
grib_get_string(h, masterDir_, masterDir, &len);
|
||||
len = 1024;
|
||||
if (self->localDir_ != NULL)
|
||||
grib_get_string(h, self->localDir_, localDir, &len);
|
||||
if (localDir_ != NULL)
|
||||
grib_get_string(h, localDir_, localDir, &len);
|
||||
|
||||
GRIB_MUTEX_INIT_ONCE(&once, &init_mutex);
|
||||
GRIB_MUTEX_LOCK(&mutex1);
|
||||
|
@ -102,19 +101,19 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
|
|||
char name[4096] = {
|
||||
0,
|
||||
};
|
||||
snprintf(name, 4096, "%s/%s", masterDir, self->dictionary_);
|
||||
snprintf(name, 4096, "%s/%s", masterDir, dictionary_);
|
||||
grib_recompose_name(h, NULL, name, masterRecomposed, 0);
|
||||
filename = grib_context_full_defs_path(c, masterRecomposed);
|
||||
}
|
||||
else {
|
||||
filename = grib_context_full_defs_path(c, self->dictionary_);
|
||||
filename = grib_context_full_defs_path(c, dictionary_);
|
||||
}
|
||||
|
||||
if (*localDir != 0) {
|
||||
char localName[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(localName, 2048, "%s/%s", localDir, self->dictionary_);
|
||||
snprintf(localName, 2048, "%s/%s", localDir, dictionary_);
|
||||
grib_recompose_name(h, NULL, localName, localRecomposed, 0);
|
||||
localFilename = grib_context_full_defs_path(c, localRecomposed);
|
||||
snprintf(dictName, 1024, "%s:%s", localFilename, filename);
|
||||
|
@ -124,7 +123,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
|
|||
}
|
||||
|
||||
if (!filename) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", self->dictionary_);
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", dictionary_);
|
||||
if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "master path=%s", masterRecomposed);
|
||||
if (strlen(localRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "local path=%s", localRecomposed);
|
||||
*err = GRIB_FILE_NOT_FOUND;
|
||||
|
@ -138,7 +137,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
|
|||
goto the_end;
|
||||
}
|
||||
else {
|
||||
grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename);
|
||||
grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", dictionary_, filename);
|
||||
}
|
||||
|
||||
f = codes_fopen(filename, "r");
|
||||
|
@ -229,14 +228,14 @@ static long atol_fast(const char* input)
|
|||
return atol(input);
|
||||
}
|
||||
|
||||
static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v)
|
||||
int grib_accessor_bufr_elements_table_t::bufr_get_from_table(bufr_descriptor* v)
|
||||
{
|
||||
int ret = 0;
|
||||
char** list = 0;
|
||||
char code[7] = { 0 };
|
||||
const size_t codeLen = sizeof(code);
|
||||
|
||||
grib_trie* table = load_bufr_elements_table(a, &ret);
|
||||
grib_trie* table = load_bufr_elements_table(&ret);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -288,6 +287,7 @@ int bufr_descriptor_is_marker(bufr_descriptor* d)
|
|||
|
||||
bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err)
|
||||
{
|
||||
grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a;
|
||||
grib_context* c;
|
||||
bufr_descriptor* v = NULL;
|
||||
|
||||
|
@ -310,7 +310,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i
|
|||
|
||||
switch (v->F) {
|
||||
case 0:
|
||||
*err = bufr_get_from_table(a, v);
|
||||
*err = self->bufr_get_from_table(v);
|
||||
break;
|
||||
case 1:
|
||||
v->type = BUFR_DESCRIPTOR_TYPE_REPLICATION;
|
||||
|
|
|
@ -25,12 +25,16 @@ public:
|
|||
int unpack_string(char*, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
// TODO(maee): make members private
|
||||
// private:
|
||||
public:
|
||||
|
||||
private:
|
||||
const char* dictionary_;
|
||||
const char* masterDir_;
|
||||
const char* localDir_;
|
||||
|
||||
grib_trie* load_bufr_elements_table(int* err);
|
||||
int bufr_get_from_table(bufr_descriptor* v);
|
||||
|
||||
friend bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err);
|
||||
};
|
||||
|
||||
int bufr_descriptor_is_marker(bufr_descriptor* d);
|
||||
|
|
|
@ -48,12 +48,11 @@ static void fill_in(double a[], long length)
|
|||
a[i] = a[0];
|
||||
}
|
||||
|
||||
static int select_area(grib_accessor* a)
|
||||
int grib_accessor_bufr_extract_area_subsets_t::select_area()
|
||||
{
|
||||
grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a;
|
||||
int ret = 0;
|
||||
long compressed = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_context* c = h->context;
|
||||
|
||||
double* lat = NULL;
|
||||
|
@ -73,7 +72,7 @@ static int select_area(grib_accessor* a)
|
|||
ret = grib_get_long(h, "compressedData", &compressed);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets);
|
||||
ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets);
|
||||
if (ret) return ret;
|
||||
|
||||
subsets = grib_iarray_new(c, numberOfSubsets, 10);
|
||||
|
@ -82,10 +81,10 @@ static int select_area(grib_accessor* a)
|
|||
if (ret) return ret;
|
||||
|
||||
if (compressed) {
|
||||
ret = grib_get_long(h, self->extractAreaLongitudeRank_, &lonRank);
|
||||
ret = grib_get_long(h, extractAreaLongitudeRank_, &lonRank);
|
||||
if (ret) return ret;
|
||||
snprintf(lonstr, sizeof(lonstr), "#%ld#longitude", lonRank);
|
||||
ret = grib_get_long(h, self->extractAreaLatitudeRank_, &latRank);
|
||||
ret = grib_get_long(h, extractAreaLatitudeRank_, &latRank);
|
||||
if (ret) return ret;
|
||||
snprintf(latstr, sizeof(latstr), "#%ld#latitude", latRank);
|
||||
}
|
||||
|
@ -142,13 +141,13 @@ static int select_area(grib_accessor* a)
|
|||
}
|
||||
}
|
||||
|
||||
ret = grib_get_double(h, self->extractAreaWestLongitude_, &lonWest);
|
||||
ret = grib_get_double(h, extractAreaWestLongitude_, &lonWest);
|
||||
if (ret) return ret;
|
||||
ret = grib_get_double(h, self->extractAreaEastLongitude_, &lonEast);
|
||||
ret = grib_get_double(h, extractAreaEastLongitude_, &lonEast);
|
||||
if (ret) return ret;
|
||||
ret = grib_get_double(h, self->extractAreaNorthLatitude_, &latNorth);
|
||||
ret = grib_get_double(h, extractAreaNorthLatitude_, &latNorth);
|
||||
if (ret) return ret;
|
||||
ret = grib_get_double(h, self->extractAreaSouthLatitude_, &latSouth);
|
||||
ret = grib_get_double(h, extractAreaSouthLatitude_, &latSouth);
|
||||
if (ret) return ret;
|
||||
|
||||
for (i = 0; i < numberOfSubsets; i++) {
|
||||
|
@ -160,16 +159,16 @@ static int select_area(grib_accessor* a)
|
|||
}
|
||||
|
||||
nsubsets = grib_iarray_used_size(subsets);
|
||||
ret = grib_set_long(h, self->extractedAreaNumberOfSubsets_, nsubsets);
|
||||
ret = grib_set_long(h, extractedAreaNumberOfSubsets_, nsubsets);
|
||||
if (ret) return ret;
|
||||
|
||||
if (nsubsets != 0) {
|
||||
long* subsets_ar = grib_iarray_get_array(subsets);
|
||||
ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets);
|
||||
ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets);
|
||||
grib_context_free(c, subsets_ar);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = grib_set_long(h, self->doExtractSubsets_, 1);
|
||||
ret = grib_set_long(h, doExtractSubsets_, 1);
|
||||
if (ret) return ret;
|
||||
}
|
||||
|
||||
|
@ -183,9 +182,7 @@ static int select_area(grib_accessor* a)
|
|||
|
||||
int grib_accessor_bufr_extract_area_subsets_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
/*grib_accessor_bufr_extract_area_subsets_t *self =(grib_accessor_bufr_extract_area_subsets_t*)a;*/
|
||||
|
||||
if (*len == 0)
|
||||
return GRIB_SUCCESS;
|
||||
return select_area(this);
|
||||
return select_area();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* doExtractSubsets_;
|
||||
const char* numberOfSubsets_;
|
||||
const char* extractSubsetList_;
|
||||
|
@ -34,4 +34,6 @@ public:
|
|||
const char* extractAreaLongitudeRank_;
|
||||
const char* extractAreaLatitudeRank_;
|
||||
const char* extractedAreaNumberOfSubsets_;
|
||||
|
||||
int select_area();
|
||||
};
|
||||
|
|
|
@ -106,12 +106,11 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int select_datetime(grib_accessor* a)
|
||||
int grib_accessor_bufr_extract_datetime_subsets_t::select_datetime()
|
||||
{
|
||||
grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a;
|
||||
int ret = 0;
|
||||
long compressed = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_context* c = h->context;
|
||||
size_t n;
|
||||
double julianStart = 0, julianEnd = 0, julianDT = 0;
|
||||
|
@ -142,7 +141,7 @@ static int select_datetime(grib_accessor* a)
|
|||
ret = grib_get_long(h, "compressedData", &compressed);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets);
|
||||
ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets);
|
||||
if (ret) return ret;
|
||||
|
||||
subsets = grib_iarray_new(c, numberOfSubsets, 10);
|
||||
|
@ -322,11 +321,11 @@ static int select_datetime(grib_accessor* a)
|
|||
|
||||
if (nsubsets != 0) {
|
||||
long* subsets_ar = grib_iarray_get_array(subsets);
|
||||
ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets);
|
||||
ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets);
|
||||
grib_context_free(c, subsets_ar);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = grib_set_long(h, self->doExtractSubsets_, 1);
|
||||
ret = grib_set_long(h, doExtractSubsets_, 1);
|
||||
if (ret) return ret;
|
||||
}
|
||||
|
||||
|
@ -349,5 +348,5 @@ int grib_accessor_bufr_extract_datetime_subsets_t::pack_long(const long* val, si
|
|||
|
||||
if (*len == 0)
|
||||
return GRIB_SUCCESS;
|
||||
return select_datetime(this);
|
||||
return select_datetime();
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ public:
|
|||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* doExtractSubsets_;
|
||||
const char* numberOfSubsets_;
|
||||
const char* extractSubsetList_;
|
||||
|
||||
int select_datetime();
|
||||
};
|
||||
|
|
|
@ -14,15 +14,14 @@
|
|||
grib_accessor_bufr_extract_subsets_t _grib_accessor_bufr_extract_subsets{};
|
||||
grib_accessor* grib_accessor_bufr_extract_subsets = &_grib_accessor_bufr_extract_subsets;
|
||||
|
||||
void get_accessors(grib_accessor* a)
|
||||
void grib_accessor_bufr_extract_subsets_t::get_accessors()
|
||||
{
|
||||
const grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
|
||||
const grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
if (self->packAccessor_)
|
||||
if (packAccessor_)
|
||||
return;
|
||||
self->numericValuesAccessor_ = grib_find_accessor(h, self->numericValues_);
|
||||
self->packAccessor_ = grib_find_accessor(h, self->pack_);
|
||||
numericValuesAccessor_ = grib_find_accessor(h, numericValues_);
|
||||
packAccessor_ = grib_find_accessor(h, pack_);
|
||||
}
|
||||
|
||||
void grib_accessor_bufr_extract_subsets_t::init(const long len, grib_arguments* arg)
|
||||
|
@ -49,7 +48,7 @@ int grib_accessor_bufr_extract_subsets_t::pack_long(const long* val, size_t* len
|
|||
size_t l = 1;
|
||||
long v[1];
|
||||
|
||||
get_accessors(this);
|
||||
get_accessors();
|
||||
|
||||
v[0] = 1;
|
||||
int err = packAccessor_->pack_long(v, &l);
|
||||
|
|
|
@ -23,9 +23,11 @@ public:
|
|||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* numericValues_;
|
||||
const char* pack_;
|
||||
grib_accessor* numericValuesAccessor_;
|
||||
grib_accessor* packAccessor_;
|
||||
|
||||
void get_accessors();
|
||||
};
|
||||
|
|
|
@ -36,12 +36,10 @@ long grib_accessor_bufr_simple_thinning_t::get_native_type()
|
|||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
||||
static int apply_thinning(grib_accessor* a)
|
||||
int grib_accessor_bufr_simple_thinning_t::apply_thinning()
|
||||
{
|
||||
const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a;
|
||||
|
||||
long skip;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_context* c = h->context;
|
||||
long compressed = 0, nsubsets;
|
||||
grib_iarray* subsets;
|
||||
|
@ -53,21 +51,21 @@ static int apply_thinning(grib_accessor* a)
|
|||
return ret;
|
||||
if (compressed) {
|
||||
long numberOfSubsets = 0;
|
||||
ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets);
|
||||
ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = grib_get_long(h, self->simpleThinningStart_, &start);
|
||||
ret = grib_get_long(h, simpleThinningStart_, &start);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = grib_get_long(h, self->simpleThinningSkip_, &skip);
|
||||
ret = grib_get_long(h, simpleThinningSkip_, &skip);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (skip <= 0)
|
||||
return GRIB_INVALID_KEY_VALUE;
|
||||
|
||||
ret = grib_get_long(h, self->simpleThinningMissingRadius_, &radius);
|
||||
ret = grib_get_long(h, simpleThinningMissingRadius_, &radius);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -80,7 +78,7 @@ static int apply_thinning(grib_accessor* a)
|
|||
|
||||
if (nsubsets != 0) {
|
||||
subsets_ar = grib_iarray_get_array(subsets);
|
||||
ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets);
|
||||
ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets);
|
||||
grib_context_free(c, subsets_ar);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -89,7 +87,7 @@ static int apply_thinning(grib_accessor* a)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = grib_set_long(h, self->doExtractSubsets_, 1);
|
||||
ret = grib_set_long(h, doExtractSubsets_, 1);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
@ -106,7 +104,7 @@ int grib_accessor_bufr_simple_thinning_t::pack_long(const long* val, size_t* len
|
|||
{
|
||||
if (*len == 0)
|
||||
return GRIB_SUCCESS;
|
||||
int err = apply_thinning(this);
|
||||
int err = apply_thinning();
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
|
|
@ -23,11 +23,13 @@ public:
|
|||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* doExtractSubsets_;
|
||||
const char* numberOfSubsets_;
|
||||
const char* extractSubsetList_;
|
||||
const char* simpleThinningStart_;
|
||||
const char* simpleThinningMissingRadius_;
|
||||
const char* simpleThinningSkip_;
|
||||
|
||||
int apply_thinning();
|
||||
};
|
||||
|
|
|
@ -30,29 +30,28 @@ void grib_accessor_bufr_string_values_t::dump(grib_dumper* dumper)
|
|||
grib_dump_string_array(dumper, this, NULL);
|
||||
}
|
||||
|
||||
static grib_accessor* get_accessor(grib_accessor* a)
|
||||
grib_accessor* grib_accessor_bufr_string_values_t::get_accessor()
|
||||
{
|
||||
grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a;
|
||||
if (!self->dataAccessor_) {
|
||||
self->dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName_);
|
||||
if (!dataAccessor_) {
|
||||
dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(this), dataAccessorName_);
|
||||
}
|
||||
return self->dataAccessor_;
|
||||
return dataAccessor_;
|
||||
}
|
||||
|
||||
int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len)
|
||||
{
|
||||
grib_accessor* data = 0;
|
||||
grib_context* c = context_;
|
||||
grib_vsarray* stringValues = NULL;
|
||||
size_t l = 0, tl;
|
||||
grib_accessor_bufr_data_array_t* data = 0;
|
||||
grib_context* c = context_;
|
||||
grib_vsarray* stringValues = NULL;
|
||||
size_t l = 0, tl;
|
||||
size_t i, j, n = 0;
|
||||
char** b = buffer;
|
||||
|
||||
data = get_accessor(this);
|
||||
data = dynamic_cast<grib_accessor_bufr_data_array_t*>(get_accessor());
|
||||
if (!data)
|
||||
return GRIB_NOT_FOUND;
|
||||
|
||||
stringValues = accessor_bufr_data_array_get_stringValues(data);
|
||||
stringValues = data->accessor_bufr_data_array_get_stringValues();
|
||||
|
||||
n = grib_vsarray_used_size(stringValues);
|
||||
|
||||
|
@ -80,7 +79,7 @@ int grib_accessor_bufr_string_values_t::unpack_string(char* val, size_t* len)
|
|||
|
||||
int grib_accessor_bufr_string_values_t::value_count(long* rlen)
|
||||
{
|
||||
grib_accessor* descriptors = get_accessor(this);
|
||||
grib_accessor* descriptors = get_accessor();
|
||||
return descriptors->value_count(rlen);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* dataAccessorName_;
|
||||
grib_accessor* dataAccessor_;
|
||||
|
||||
grib_accessor* get_accessor();
|
||||
};
|
||||
|
|
|
@ -24,13 +24,12 @@ void grib_accessor_bufrdc_expanded_descriptors_t::init(const long len, grib_argu
|
|||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
static grib_accessor* get_accessor(grib_accessor* a)
|
||||
grib_accessor* grib_accessor_bufrdc_expanded_descriptors_t::get_accessor()
|
||||
{
|
||||
grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a;
|
||||
if (!self->expandedDescriptorsAccessor_) {
|
||||
self->expandedDescriptorsAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors_);
|
||||
if (!expandedDescriptorsAccessor_) {
|
||||
expandedDescriptorsAccessor_ = grib_find_accessor(grib_handle_of_accessor(this), expandedDescriptors_);
|
||||
}
|
||||
return self->expandedDescriptorsAccessor_;
|
||||
return expandedDescriptorsAccessor_;
|
||||
}
|
||||
|
||||
int grib_accessor_bufrdc_expanded_descriptors_t::unpack_long(long* val, size_t* len)
|
||||
|
@ -42,7 +41,7 @@ int grib_accessor_bufrdc_expanded_descriptors_t::unpack_long(long* val, size_t*
|
|||
long* v = 0;
|
||||
grib_context* c = context_;
|
||||
|
||||
descriptors = get_accessor(this);
|
||||
descriptors = get_accessor();
|
||||
if (!descriptors) return GRIB_NOT_FOUND;
|
||||
|
||||
value_count(&lenall);
|
||||
|
@ -73,7 +72,7 @@ int grib_accessor_bufrdc_expanded_descriptors_t::unpack_string_array(char** buff
|
|||
};
|
||||
grib_context* c = context_;
|
||||
|
||||
descriptors = get_accessor(this);
|
||||
descriptors = get_accessor();
|
||||
if (!descriptors) return GRIB_NOT_FOUND;
|
||||
|
||||
err = value_count(&lenall);
|
||||
|
@ -97,7 +96,7 @@ int grib_accessor_bufrdc_expanded_descriptors_t::unpack_string_array(char** buff
|
|||
|
||||
int grib_accessor_bufrdc_expanded_descriptors_t::value_count(long* rlen)
|
||||
{
|
||||
grib_accessor* descriptors = get_accessor(this);
|
||||
grib_accessor* descriptors = get_accessor();
|
||||
|
||||
return descriptors->value_count(rlen);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@ public:
|
|||
void destroy(grib_context*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* expandedDescriptors_;
|
||||
grib_accessor* expandedDescriptorsAccessor_;
|
||||
|
||||
grib_accessor* get_accessor();
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
size_t string_length() override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
/* Members defined in cf_var_name */
|
||||
const char* defaultKey_;
|
||||
};
|
||||
|
|
|
@ -28,9 +28,8 @@ static int test_bit(long a, long b)
|
|||
return a & (1 << b);
|
||||
}
|
||||
|
||||
static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
|
||||
int grib_accessor_codeflag_t::grib_get_codeflag(long code, char* codename)
|
||||
{
|
||||
const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a;
|
||||
FILE* f = NULL;
|
||||
char fname[1024];
|
||||
char bval[50];
|
||||
|
@ -41,21 +40,21 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
|
|||
int j = 0;
|
||||
int err = 0;
|
||||
|
||||
err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename_, fname, 1);
|
||||
err = grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1);
|
||||
if (err) {
|
||||
strncpy(fname, self->tablename_, sizeof(fname) - 1);
|
||||
strncpy(fname, tablename_, sizeof(fname) - 1);
|
||||
fname[sizeof(fname) - 1] = '\0';
|
||||
}
|
||||
|
||||
if ((filename = grib_context_full_defs_path(a->context_, fname)) == NULL) {
|
||||
grib_context_log(a->context_, GRIB_LOG_WARNING, "Cannot open flag table %s", filename);
|
||||
if ((filename = grib_context_full_defs_path(context_, fname)) == NULL) {
|
||||
grib_context_log(context_, GRIB_LOG_WARNING, "Cannot open flag table %s", filename);
|
||||
strcpy(codename, "Cannot open flag table");
|
||||
return GRIB_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
f = codes_fopen(filename, "r");
|
||||
if (!f) {
|
||||
grib_context_log(a->context_, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename);
|
||||
grib_context_log(context_, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename);
|
||||
strcpy(codename, "Cannot open flag table");
|
||||
return GRIB_FILE_NOT_FOUND;
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
|
|||
sscanf(line, "%49s %49s", num, bval);
|
||||
|
||||
if (num[0] != '#') {
|
||||
if ((test_bit(code, self->length_ * 8 - atol(num)) > 0) == atol(bval)) {
|
||||
if ((test_bit(code, length_ * 8 - atol(num)) > 0) == atol(bval)) {
|
||||
size_t linelen = strlen(line);
|
||||
codename[j++] = '(';
|
||||
codename[j++] = num[0];
|
||||
|
@ -117,7 +116,7 @@ void grib_accessor_codeflag_t::dump(grib_dumper* dumper)
|
|||
|
||||
grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1);
|
||||
unpack_long(&v, &llen);
|
||||
grib_get_codeflag(this, v, flagname);
|
||||
grib_get_codeflag(v, flagname);
|
||||
|
||||
grib_dump_bits(dumper, this, flagname);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* tablename_;
|
||||
|
||||
int grib_get_codeflag(long code, char* codename);
|
||||
};
|
||||
|
|
|
@ -163,11 +163,11 @@ static void dump_codetable(grib_codetable* atable)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
static grib_codetable* load_table(grib_accessor* a)
|
||||
|
||||
grib_codetable* grib_accessor_codetable_t::load_table()
|
||||
{
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
size_t size = 0;
|
||||
grib_handle* h = ((grib_accessor*)self)->parent_->h;
|
||||
grib_handle* h = parent_->h;
|
||||
grib_context* c = h->context;
|
||||
grib_codetable* t = NULL;
|
||||
grib_codetable* next = NULL;
|
||||
|
@ -187,23 +187,23 @@ static grib_codetable* load_table(grib_accessor* a)
|
|||
};
|
||||
size_t len = 1024;
|
||||
|
||||
if (self->masterDir_ != NULL)
|
||||
grib_get_string(h, self->masterDir_, masterDir, &len);
|
||||
if (masterDir_ != NULL)
|
||||
grib_get_string(h, masterDir_, masterDir, &len);
|
||||
|
||||
len = 1024;
|
||||
if (self->localDir_ != NULL)
|
||||
grib_get_string(h, self->localDir_, localDir, &len);
|
||||
if (localDir_ != NULL)
|
||||
grib_get_string(h, localDir_, localDir, &len);
|
||||
|
||||
if (*masterDir != 0) {
|
||||
char name[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_);
|
||||
snprintf(name, sizeof(name), "%s/%s", masterDir, tablename_);
|
||||
grib_recompose_name(h, NULL, name, recomposed, 0);
|
||||
filename = grib_context_full_defs_path(c, recomposed);
|
||||
}
|
||||
else {
|
||||
grib_recompose_name(h, NULL, self->tablename_, recomposed, 0);
|
||||
grib_recompose_name(h, NULL, tablename_, recomposed, 0);
|
||||
filename = grib_context_full_defs_path(c, recomposed);
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ static grib_codetable* load_table(grib_accessor* a)
|
|||
char localName[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_);
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_);
|
||||
grib_recompose_name(h, NULL, localName, localRecomposed, 0);
|
||||
localFilename = grib_context_full_defs_path(c, localRecomposed);
|
||||
}
|
||||
|
@ -243,12 +243,12 @@ static grib_codetable* load_table(grib_accessor* a)
|
|||
next = next->next;
|
||||
}
|
||||
|
||||
if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
Assert(self->vvalue_ != NULL);
|
||||
size = self->vvalue_->length * 8;
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
Assert(vvalue_ != NULL);
|
||||
size = vvalue_->length * 8;
|
||||
}
|
||||
else {
|
||||
size = ((grib_accessor*)self)->byte_count() * 8;
|
||||
size = byte_count() * 8;
|
||||
}
|
||||
|
||||
size = (1ULL << size); /* 2^size - 64bits */
|
||||
|
@ -455,7 +455,7 @@ int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, c
|
|||
return err;
|
||||
}
|
||||
|
||||
const grib_codetable* table = ca->table_;
|
||||
const grib_codetable* table = ca->table();
|
||||
if (!table) return GRIB_INTERNAL_ERROR;
|
||||
|
||||
grib_codetable* cached_table = c->codetable; // Access the codetable cache
|
||||
|
@ -531,7 +531,7 @@ void grib_accessor_codetable_t::dump(grib_dumper* dumper)
|
|||
long value;
|
||||
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(this); /* may return NULL */
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
table = table_;
|
||||
|
@ -593,7 +593,7 @@ int grib_accessor_codetable_t::unpack_string(char* buffer, size_t* len)
|
|||
return err;
|
||||
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(this); /* may return NULL */
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
table = table_;
|
||||
|
@ -664,7 +664,7 @@ int grib_accessor_codetable_t::pack_string(const char* buffer, size_t* len)
|
|||
size_t size = 1;
|
||||
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(this); /* may return NULL */
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
table = table_;
|
||||
|
@ -812,7 +812,7 @@ int grib_accessor_codetable_t::unpack_long(long* val, size_t* len)
|
|||
rlen = 1; /* ECC-480 Performance: avoid func call overhead of grib_value_count */
|
||||
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(this); /* may return NULL */
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,14 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
grib_codetable* table() const { return table_; }
|
||||
|
||||
private:
|
||||
grib_codetable* table_;
|
||||
const char* tablename_;
|
||||
const char* masterDir_;
|
||||
const char* localDir_;
|
||||
int table_loaded_;
|
||||
|
||||
grib_codetable* load_table();
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ int grib_accessor_codetable_title_t::unpack_string(char* buffer, size_t* len)
|
|||
if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
table = ca->table_;
|
||||
table = ca->table();
|
||||
|
||||
if (table && (value >= 0) && (value < table->size) && table->entries[value].title) {
|
||||
strcpy(tmp, table->entries[value].title);
|
||||
|
|
|
@ -44,7 +44,7 @@ int grib_accessor_codetable_units_t::unpack_string(char* buffer, size_t* len)
|
|||
if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
table = ca->table_;
|
||||
table = ca->table();
|
||||
|
||||
if (table && (value >= 0) && (value < table->size) && table->entries[value].units) {
|
||||
strcpy(tmp, table->entries[value].units);
|
||||
|
|
|
@ -17,4 +17,5 @@ public:
|
|||
grib_accessor_variable_t() { class_name_ = "constant"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_constant_t{}; }
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
};
|
||||
|
|
|
@ -232,10 +232,9 @@ int grib_accessor_data_apply_bitmap_t::pack_double(const double* val, size_t* le
|
|||
return err;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack(grib_accessor* a, T* val, size_t* len)
|
||||
template <typename T>
|
||||
int grib_accessor_data_apply_bitmap_t::unpack(T* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
|
||||
size_t i = 0;
|
||||
|
@ -246,18 +245,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
T* coded_vals = NULL;
|
||||
double missing_value = 0;
|
||||
|
||||
int err = a->value_count(&nn);
|
||||
int err = value_count(&nn);
|
||||
n_vals = nn;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap_))
|
||||
return grib_get_array<T>(grib_handle_of_accessor(a), self->coded_values_, val, len);
|
||||
if (!grib_find_accessor(grib_handle_of_accessor(this), bitmap_))
|
||||
return grib_get_array<T>(grib_handle_of_accessor(this), coded_values_, val, len);
|
||||
|
||||
if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values_, &coded_n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_size(grib_handle_of_accessor(this), coded_values_, &coded_n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*len < n_vals) {
|
||||
|
@ -273,21 +272,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
if ((err = grib_get_array_internal<T>(grib_handle_of_accessor(a), self->bitmap_, val, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_array_internal<T>(grib_handle_of_accessor(this), bitmap_, val, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
coded_vals = (T*)grib_context_malloc(a->context_, coded_n_vals * sizeof(T));
|
||||
coded_vals = (T*)grib_context_malloc(context_, coded_n_vals * sizeof(T));
|
||||
if (coded_vals == NULL)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_array<T>(grib_handle_of_accessor(a), self->coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) {
|
||||
grib_context_free(a->context_, coded_vals);
|
||||
if ((err = grib_get_array<T>(grib_handle_of_accessor(this), coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) {
|
||||
grib_context_free(context_, coded_vals);
|
||||
return err;
|
||||
}
|
||||
|
||||
grib_context_log(a->context_, GRIB_LOG_DEBUG,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"grib_accessor_data_apply_bitmap: %s : creating %s, %d values",
|
||||
__func__, a->name_, n_vals);
|
||||
__func__, name_, n_vals);
|
||||
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
if (val[i] == 0) {
|
||||
|
@ -296,11 +295,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
else {
|
||||
val[i] = coded_vals[j++];
|
||||
if (j > coded_n_vals) {
|
||||
grib_context_free(a->context_, coded_vals);
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_free(context_, coded_vals);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"grib_accessor_data_apply_bitmap [%s]:"
|
||||
" %s : number of coded values does not match bitmap %ld %ld",
|
||||
a->name_, __func__, coded_n_vals, n_vals);
|
||||
name_, __func__, coded_n_vals, n_vals);
|
||||
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
@ -309,18 +308,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
|
||||
*len = n_vals;
|
||||
|
||||
grib_context_free(a->context_, coded_vals);
|
||||
grib_context_free(context_, coded_vals);
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_data_apply_bitmap_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(this, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_apply_bitmap_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(this, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
long grib_accessor_data_apply_bitmap_t::get_native_type()
|
||||
|
|
|
@ -29,11 +29,13 @@ public:
|
|||
int unpack_double_element(size_t i, double* val) override;
|
||||
int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* coded_values_;
|
||||
const char* bitmap_;
|
||||
const char* missing_value_;
|
||||
const char* number_of_data_points_;
|
||||
const char* number_of_values_;
|
||||
const char* binary_scale_factor_;
|
||||
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -39,9 +39,8 @@ int grib_accessor_data_apply_boustrophedonic_t::value_count(long* numberOfPoints
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack(grib_accessor* a, T* val, size_t* len)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack(T* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
|
||||
size_t plSize = 0;
|
||||
long* pl = 0;
|
||||
double* values = 0;
|
||||
|
@ -52,7 +51,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
int ret;
|
||||
long numberOfPoints, numberOfRows, numberOfColumns;
|
||||
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints_, &numberOfPoints);
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &numberOfPoints);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -61,7 +60,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
ret = grib_get_size(grib_handle_of_accessor(a), self->values_, &valuesSize);
|
||||
ret = grib_get_size(grib_handle_of_accessor(this), values_, &valuesSize);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -70,31 +69,31 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return 0;
|
||||
|
||||
if (valuesSize != numberOfPoints) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)",
|
||||
numberOfPoints, numberOfPoints, self->values_, (long)valuesSize);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)",
|
||||
numberOfPoints, numberOfPoints, values_, (long)valuesSize);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context_, sizeof(double) * numberOfPoints);
|
||||
ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values_, values, &valuesSize);
|
||||
values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints);
|
||||
ret = grib_get_double_array_internal(grib_handle_of_accessor(this), values_, values, &valuesSize);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
pvalues = values;
|
||||
pval = val;
|
||||
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfRows_, &numberOfRows);
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfRows_, &numberOfRows);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfColumns_, &numberOfColumns);
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfColumns_, &numberOfColumns);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (grib_get_size(grib_handle_of_accessor(a), self->pl_, &plSize) == GRIB_SUCCESS) {
|
||||
if (grib_get_size(grib_handle_of_accessor(this), pl_, &plSize) == GRIB_SUCCESS) {
|
||||
Assert(plSize == numberOfRows);
|
||||
pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize);
|
||||
ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl_, pl, &plSize);
|
||||
pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize);
|
||||
ret = grib_get_long_array_internal(grib_handle_of_accessor(this), pl_, pl, &plSize);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -111,7 +110,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context_, pl);
|
||||
grib_context_free(context_, pl);
|
||||
}
|
||||
else {
|
||||
for (j = 0; j < numberOfRows; j++) {
|
||||
|
@ -128,19 +127,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context_, values);
|
||||
grib_context_free(context_, values);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(this, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(this, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element(size_t idx, double* val)
|
||||
|
|
|
@ -28,10 +28,12 @@ public:
|
|||
int unpack_double_element(size_t i, double* val) override;
|
||||
int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* values_;
|
||||
const char* numberOfRows_;
|
||||
const char* numberOfColumns_;
|
||||
const char* numberOfPoints_;
|
||||
const char* pl_;
|
||||
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -379,12 +379,11 @@ cleanup:
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack(grib_accessor* a, T* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack(T* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->class_name_;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
int err = GRIB_SUCCESS, i = 0;
|
||||
size_t buflen = 0;
|
||||
|
@ -408,28 +407,28 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
long ccsds_rsi;
|
||||
size_t nbytes;
|
||||
|
||||
a->dirty_ = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
if ((err = a->value_count(&nn)) != GRIB_SUCCESS)
|
||||
if ((err = value_count(&nn)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
n_vals = nn;
|
||||
|
||||
if ((err = grib_get_long_internal(hand, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(hand, self->reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(hand, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(hand, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
// ECC-477: Don't call grib_get_long_internal to suppress error message being output
|
||||
if ((err = grib_get_long(hand, self->ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(hand, ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(hand, self->ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(hand, ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(hand, self->ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(hand, ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
modify_aec_flags(&ccsds_flags);
|
||||
|
@ -449,9 +448,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
bscale = codes_power<T>(binary_scale_factor, 2);
|
||||
dscale = codes_power<T>(-decimal_scale_factor, 10);
|
||||
|
||||
buflen = self->byte_count();
|
||||
buflen = byte_count();
|
||||
buf = (unsigned char*)hand->buffer->data;
|
||||
buf += a->byte_offset();
|
||||
buf += byte_offset();
|
||||
strm.flags = ccsds_flags;
|
||||
strm.bits_per_sample = bits_per_value;
|
||||
strm.block_size = ccsds_block_size;
|
||||
|
@ -465,7 +464,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
nbytes = 4;
|
||||
|
||||
size = n_vals * nbytes;
|
||||
decoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context_, size);
|
||||
decoded = (unsigned char*)grib_context_buffer_malloc_clear(context_, size);
|
||||
if (!decoded) {
|
||||
err = GRIB_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
|
@ -476,7 +475,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
if (hand->context->debug) print_aec_stream_info(&strm, "unpack_*");
|
||||
|
||||
if ((err = aec_buffer_decode(&strm)) != AEC_OK) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)",
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)",
|
||||
cclass_name, __func__, err, aec_get_error_message(err));
|
||||
err = GRIB_DECODING_ERROR;
|
||||
goto cleanup;
|
||||
|
@ -503,8 +502,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bitsPerValue=%ld (max %ld)",
|
||||
cclass_name, __func__, a->name_, bits_per_value, MAX_BITS_PER_VALUE);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bitsPerValue=%ld (max %ld)",
|
||||
cclass_name, __func__, name_, bits_per_value, MAX_BITS_PER_VALUE);
|
||||
err = GRIB_INVALID_BPV;
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -512,18 +511,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
*len = n_vals;
|
||||
|
||||
cleanup:
|
||||
grib_context_buffer_free(a->context_, decoded);
|
||||
grib_context_buffer_free(context_, decoded);
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(this, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(this, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
int unpack_double_element(size_t i, double* val) override;
|
||||
int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* number_of_values_;
|
||||
const char* reference_value_;
|
||||
const char* binary_scale_factor_;
|
||||
|
@ -38,4 +38,6 @@ public:
|
|||
const char* ccsds_flags_;
|
||||
const char* ccsds_block_size_;
|
||||
const char* ccsds_rsi_;
|
||||
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -534,12 +534,11 @@ int grib_accessor_data_complex_packing_t::pack_double(const double* val, size_t*
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
||||
int grib_accessor_data_complex_packing_t::unpack_real(T* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->class_name_;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
size_t i = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
|
@ -585,7 +584,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
|
||||
decode_float_proc decode_float = NULL;
|
||||
|
||||
err = a->value_count(&n_vals);
|
||||
err = value_count(&n_vals);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -594,44 +593,44 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->offsetdata_, &offsetdata)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, offsetdata_, &offsetdata)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_double_internal(gh, self->reference_value_, &tmp)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(gh, reference_value_, &tmp)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
reference_value = tmp;
|
||||
if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
/* ECC-774: don't use grib_get_long_internal */
|
||||
if ((ret = grib_get_long(gh, self->ieee_floats_, &ieee_floats)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long(gh, ieee_floats_, &ieee_floats)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &tmp)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(gh, laplacianOperator_, &tmp)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
laplacianOperator = tmp;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->sub_j_, &sub_j)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, sub_j_, &sub_j)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->sub_k_, &sub_k)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, sub_k_, &sub_k)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->sub_m_, &sub_m)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, sub_m_, &sub_m)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->pen_j_, &pen_j)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, pen_j_, &pen_j)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->pen_k_, &pen_k)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, pen_k_, &pen_k)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->pen_m_, &pen_m)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, pen_m_, &pen_m)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
a->dirty_ = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
switch (ieee_floats) {
|
||||
case 0:
|
||||
|
@ -651,7 +650,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
}
|
||||
|
||||
if (sub_j != sub_k || sub_j != sub_m || pen_j != pen_k || pen_j != pen_m) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
|
@ -659,7 +658,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
|
||||
maxv = pen_j + 1;
|
||||
|
||||
buf += a->byte_offset();
|
||||
buf += byte_offset();
|
||||
hres = buf;
|
||||
lres = buf;
|
||||
|
||||
|
@ -667,7 +666,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
n_vals = (pen_j + 1) * (pen_j + 2);
|
||||
d = codes_power<T>(-decimal_scale_factor, 10);
|
||||
|
||||
grib_ieee_decode_array<T>(a->context_, buf, n_vals, bytes, val);
|
||||
grib_ieee_decode_array<T>(context_, buf, n_vals, bytes, val);
|
||||
if (d) {
|
||||
for (i = 0; i < n_vals; i++)
|
||||
val[i] *= d;
|
||||
|
@ -675,13 +674,13 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
packed_offset = a->byte_offset() + bytes * (sub_k + 1) * (sub_k + 2);
|
||||
packed_offset = byte_offset() + bytes * (sub_k + 1) * (sub_k + 2);
|
||||
lpos = 8 * (packed_offset - offsetdata);
|
||||
|
||||
s = codes_power<T>(binary_scale_factor, 2);
|
||||
d = codes_power<T>(-decimal_scale_factor, 10);
|
||||
|
||||
scals = (T*)grib_context_malloc(a->context_, maxv * sizeof(T));
|
||||
scals = (T*)grib_context_malloc(context_, maxv * sizeof(T));
|
||||
if (!scals) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
scals[0] = 0;
|
||||
|
@ -690,7 +689,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
if (operat != 0)
|
||||
scals[i] = (1.0 / operat);
|
||||
else {
|
||||
grib_context_log(a->context_, GRIB_LOG_WARNING,
|
||||
grib_context_log(context_, GRIB_LOG_WARNING,
|
||||
"%s: Problem with operator div by zero at index %d of %d", cclass_name, i, maxv);
|
||||
scals[i] = 0;
|
||||
}
|
||||
|
@ -749,22 +748,22 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len)
|
|||
|
||||
//Assert(*len >= i);
|
||||
if (*len < i) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "%s::%s: Invalid values *len=%zu and i=%zu.",
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s::%s: Invalid values *len=%zu and i=%zu.",
|
||||
cclass_name, __func__, *len, i);
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "Make sure your array is large enough.");
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Make sure your array is large enough.");
|
||||
ret = GRIB_ARRAY_TOO_SMALL;
|
||||
} else {
|
||||
*len = i;
|
||||
}
|
||||
|
||||
grib_context_free(a->context_, scals);
|
||||
grib_context_free(context_, scals);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_data_complex_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack_real<double>(this, val, len);
|
||||
return unpack_real<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_complex_packing_t::unpack_float(float* val, size_t* len)
|
||||
|
@ -778,7 +777,7 @@ int grib_accessor_data_complex_packing_t::unpack_float(float* val, size_t* len)
|
|||
double* val8 = (double*)grib_context_malloc(context_, size * (sizeof(double)));
|
||||
if (!val8) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
int err = unpack_real<double>(this, val8, len);
|
||||
int err = unpack_real<double>(val8, len);
|
||||
if (err) {
|
||||
grib_context_free(context_, val8);
|
||||
return err;
|
||||
|
|
|
@ -29,15 +29,19 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
const char* sub_j_;
|
||||
const char* sub_k_;
|
||||
const char* sub_m_;
|
||||
|
||||
private:
|
||||
const char* GRIBEX_sh_bug_present_;
|
||||
const char* ieee_floats_;
|
||||
const char* laplacianOperatorIsSet_;
|
||||
const char* laplacianOperator_;
|
||||
const char* sub_j_;
|
||||
const char* sub_k_;
|
||||
const char* sub_m_;
|
||||
const char* pen_j_;
|
||||
const char* pen_k_;
|
||||
const char* pen_m_;
|
||||
|
||||
template <typename T> int unpack_real(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -48,9 +48,8 @@ int grib_accessor_data_g1second_order_general_packing_t::value_count(long* numbe
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_packing_t::unpack_real(T* values, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
int ret = 0;
|
||||
long numberOfGroups, numberOfSecondOrderPackedValues;
|
||||
|
@ -59,7 +58,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
long* X = 0;
|
||||
long pos = 0;
|
||||
long widthOfFirstOrderValues = 0;
|
||||
unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data;
|
||||
unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data;
|
||||
long i, n;
|
||||
double reference_value;
|
||||
long binary_scale_factor;
|
||||
|
@ -69,44 +68,44 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
long groupLength, j;
|
||||
size_t groupWidthsSize;
|
||||
|
||||
buf += a->byte_offset();
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
buf += byte_offset();
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues_,
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_,
|
||||
&numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (*len < (size_t)numberOfSecondOrderPackedValues)
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups);
|
||||
groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
groupWidthsSize = numberOfGroups;
|
||||
if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(this), groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
secondaryBitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1));
|
||||
secondaryBitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1));
|
||||
secondaryBitmap[numberOfSecondOrderPackedValues] = 1;
|
||||
grib_decode_long_array(buf, &pos, 1, numberOfSecondOrderPackedValues, secondaryBitmap);
|
||||
pos = 8 * ((pos + 7) / 8);
|
||||
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups);
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues);
|
||||
pos = 8 * ((pos + 7) / 8);
|
||||
|
||||
X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfSecondOrderPackedValues);
|
||||
X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfSecondOrderPackedValues);
|
||||
|
||||
n = 0;
|
||||
i = -1;
|
||||
|
@ -143,22 +142,22 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
}
|
||||
|
||||
*len = numberOfSecondOrderPackedValues;
|
||||
grib_context_free(a->context_, secondaryBitmap);
|
||||
grib_context_free(a->context_, firstOrderValues);
|
||||
grib_context_free(a->context_, X);
|
||||
grib_context_free(a->context_, groupWidths);
|
||||
grib_context_free(context_, secondaryBitmap);
|
||||
grib_context_free(context_, firstOrderValues);
|
||||
grib_context_free(context_, X);
|
||||
grib_context_free(context_, groupWidths);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_data_g1second_order_general_packing_t::unpack_float(float* values, size_t* len)
|
||||
{
|
||||
return unpack_real<float>(this, values, len);
|
||||
return unpack_real<float>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_g1second_order_general_packing_t::unpack_double(double* values, size_t* len)
|
||||
{
|
||||
return unpack_real<double>(this, values, len);
|
||||
return unpack_real<double>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_g1second_order_general_packing_t::pack_double(const double* cval, size_t* len)
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
|
@ -42,4 +42,6 @@ public:
|
|||
const char* jPointsAreConsecutive_;
|
||||
const char* bitmap_;
|
||||
const char* groupWidths_;
|
||||
|
||||
template <typename T> int unpack_real(T* values, size_t* len);
|
||||
};
|
||||
|
|
|
@ -113,10 +113,9 @@ int grib_accessor_data_g1second_order_row_by_row_packing_t::value_count(long* co
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_real(T* values, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
int ret = 0;
|
||||
long numberOfGroups, numberOfSecondOrderPackedValues;
|
||||
long* groupWidths = 0;
|
||||
|
@ -138,25 +137,25 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
size_t plSize = 0;
|
||||
long* pl = 0;
|
||||
|
||||
buf += a->byte_offset();
|
||||
if ((ret = grib_get_long_internal(gh, self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
buf += byte_offset();
|
||||
if ((ret = grib_get_long_internal(gh, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (self->bitmap_)
|
||||
if (bitmap_)
|
||||
bitmapPresent = 1;
|
||||
ret = grib_get_size(gh, self->pl_, &plSize);
|
||||
ret = grib_get_size(gh, pl_, &plSize);
|
||||
if (ret == GRIB_SUCCESS) {
|
||||
pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize);
|
||||
if ((ret = grib_get_long_array(gh, self->pl_, pl, &plSize)) != GRIB_SUCCESS)
|
||||
pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize);
|
||||
if ((ret = grib_get_long_array(gh, pl_, pl, &plSize)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->Ni_, &Ni)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, Ni_, &Ni)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(gh, self->Nj_, &Nj)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, Nj_, &Nj)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if (jPointsAreConsecutive) {
|
||||
numberOfRows = Ni;
|
||||
|
@ -167,7 +166,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
numberOfColumns = Ni;
|
||||
}
|
||||
|
||||
numbersPerRow = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfRows);
|
||||
numbersPerRow = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfRows);
|
||||
if (!numbersPerRow)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
if (bitmapPresent) {
|
||||
|
@ -179,9 +178,9 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
for (i = 0; i < numberOfRows; i++)
|
||||
numberOfPoints += pl[i];
|
||||
}
|
||||
bitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfPoints);
|
||||
bitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfPoints);
|
||||
pbitmap = bitmap;
|
||||
grib_get_long_array(gh, self->bitmap_, bitmap, &numberOfPoints);
|
||||
grib_get_long_array(gh, bitmap_, bitmap, &numberOfPoints);
|
||||
if (plSize && pl) {
|
||||
for (i = 0; i < numberOfRows; i++) {
|
||||
for (j = 0; j < pl[i]; j++) {
|
||||
|
@ -198,7 +197,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context_, pbitmap);
|
||||
grib_context_free(context_, pbitmap);
|
||||
}
|
||||
else {
|
||||
if (plSize && pl) {
|
||||
|
@ -211,28 +210,28 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
}
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->numberOfSecondOrderPackedValues_,
|
||||
if ((ret = grib_get_long_internal(gh, numberOfSecondOrderPackedValues_,
|
||||
&numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups);
|
||||
groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
groupWidthsSize = numberOfGroups;
|
||||
if ((ret = grib_get_long_array_internal(gh, self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_array_internal(gh, groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups);
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues);
|
||||
pos = 8 * ((pos + 7) / 8);
|
||||
|
||||
|
@ -243,7 +242,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
if (*len < (size_t)n)
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * n);
|
||||
X = (long*)grib_context_malloc_clear(context_, sizeof(long) * n);
|
||||
n = 0;
|
||||
k = 0;
|
||||
for (i = 0; i < numberOfGroups; i++) {
|
||||
|
@ -268,25 +267,25 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len)
|
|||
for (i = 0; i < n; i++) {
|
||||
values[i] = (T)(((X[i] * s) + reference_value) * d);
|
||||
}
|
||||
grib_context_free(a->context_, firstOrderValues);
|
||||
grib_context_free(a->context_, X);
|
||||
grib_context_free(a->context_, groupWidths);
|
||||
grib_context_free(context_, firstOrderValues);
|
||||
grib_context_free(context_, X);
|
||||
grib_context_free(context_, groupWidths);
|
||||
if (plSize)
|
||||
grib_context_free(a->context_, pl);
|
||||
grib_context_free(context_, pl);
|
||||
if (numbersPerRow)
|
||||
grib_context_free(a->context_, numbersPerRow);
|
||||
grib_context_free(context_, numbersPerRow);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_float(float* values, size_t* len)
|
||||
{
|
||||
return unpack_real<float>(this, values, len);
|
||||
return unpack_real<float>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_double(double* values, size_t* len)
|
||||
{
|
||||
return unpack_real<double>(this, values, len);
|
||||
return unpack_real<double>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::pack_double(const double* cval, size_t* len)
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
|
@ -42,4 +42,6 @@ public:
|
|||
const char* jPointsAreConsecutive_;
|
||||
const char* bitmap_;
|
||||
const char* groupWidths_;
|
||||
|
||||
template <typename T> int unpack_real(T* values, size_t* len);
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
|
|
|
@ -1461,12 +1461,11 @@ int grib_accessor_data_g22order_packing_t::pack_double(const double* val, size_t
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack(grib_accessor* a, T* val, size_t* len)
|
||||
int grib_accessor_data_g22order_packing_t::unpack(T* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
|
||||
const char* cclass_name = a->class_name_;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = class_name_;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
|
@ -1511,57 +1510,57 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
long numberOfOctetsExtraDescriptors = 0;
|
||||
double missingValue = 0;
|
||||
|
||||
err = a->value_count(&n_vals);
|
||||
err = value_count(&n_vals);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (*len < static_cast<size_t>(n_vals))
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
// Don't call grib_get_long_internal to suppress error message being output
|
||||
if ((err = grib_get_long(gh, self->groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(gh, groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(gh, "missingValue", &missingValue)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
a->dirty_ = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
if (bits_per_value == 0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
|
@ -1571,11 +1570,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
sec_val = (long*)grib_context_malloc(a->context_, (n_vals) * sizeof(long));
|
||||
sec_val = (long*)grib_context_malloc(context_, (n_vals) * sizeof(long));
|
||||
if (!sec_val) return GRIB_OUT_OF_MEMORY;
|
||||
memset(sec_val, 0, (n_vals) * sizeof(long)); // See SUP-718
|
||||
|
||||
buf_ref = buf + a->offset_;
|
||||
buf_ref = buf + offset_;
|
||||
|
||||
ref_p = (numberOfGroupsOfDataValues * bits_per_value);
|
||||
|
||||
|
@ -1688,7 +1687,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
// For Complex packing, order == 0
|
||||
// For Complex packing and spatial differencing, order == 1 or 2 (code table 5.6)
|
||||
if (orderOfSpatialDifferencing != 1 && orderOfSpatialDifferencing != 2) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unpacking: Unsupported order of spatial differencing %ld", cclass_name, orderOfSpatialDifferencing);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
@ -1699,7 +1698,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
|
||||
bias = grib_decode_signed_longb(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8);
|
||||
|
||||
post_process(a->context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras);
|
||||
post_process(context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras);
|
||||
// de_spatial_difference (context_ , sec_val, n_vals, orderOfSpatialDifferencing, bias);
|
||||
}
|
||||
|
||||
|
@ -1715,18 +1714,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context_, sec_val);
|
||||
grib_context_free(context_, sec_val);
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_data_g22order_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(this, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_g22order_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(this, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_g22order_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
int unpack_double_element(size_t i, double* val) override;
|
||||
int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* numberOfValues_;
|
||||
const char* bits_per_value_;
|
||||
const char* reference_value_;
|
||||
|
@ -48,4 +48,6 @@ public:
|
|||
const char* numberOfBitsUsedForTheScaledGroupLengths_;
|
||||
const char* orderOfSpatialDifferencing_;
|
||||
const char* numberOfOctetsExtraDescriptors_;
|
||||
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
grib_accessor_data_g2bifourier_packing_t _grib_accessor_data_g2bifourier_packing{};
|
||||
grib_accessor* grib_accessor_data_g2bifourier_packing = &_grib_accessor_data_g2bifourier_packing;
|
||||
|
||||
typedef unsigned long (*encode_float_proc)(double);
|
||||
typedef double (*decode_float_proc)(unsigned long);
|
||||
|
||||
void grib_accessor_data_g2bifourier_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_data_simple_packing_t::init(v, args);
|
||||
|
@ -145,29 +142,6 @@ static void diamond(long ni, long nj, long itrunc[], long jtrunc[])
|
|||
insub = insub || (i == 0) || (j == 0); \
|
||||
} while (0)
|
||||
|
||||
typedef struct bif_trunc_t
|
||||
{
|
||||
long bits_per_value;
|
||||
long decimal_scale_factor;
|
||||
long binary_scale_factor;
|
||||
long ieee_floats;
|
||||
long laplacianOperatorIsSet;
|
||||
double laplacianOperator;
|
||||
double reference_value;
|
||||
long sub_i, sub_j, bif_i, bif_j;
|
||||
long biFourierTruncationType;
|
||||
long biFourierSubTruncationType;
|
||||
long keepaxes;
|
||||
long maketemplate;
|
||||
decode_float_proc decode_float;
|
||||
encode_float_proc encode_float;
|
||||
int bytes;
|
||||
long* itruncation_bif;
|
||||
long* jtruncation_bif;
|
||||
long* itruncation_sub;
|
||||
long* jtruncation_sub;
|
||||
size_t n_vals_bif, n_vals_sub;
|
||||
} bif_trunc_t;
|
||||
|
||||
/*
|
||||
* Total number of coefficients
|
||||
|
@ -354,45 +328,44 @@ static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a)
|
|||
grib_context_free(gh->context, bt);
|
||||
}
|
||||
|
||||
static bif_trunc_t* new_bif_trunc(grib_accessor* a)
|
||||
bif_trunc_t* grib_accessor_data_g2bifourier_packing_t::new_bif_trunc()
|
||||
{
|
||||
int ret;
|
||||
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
|
||||
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
bif_trunc_t* bt = (bif_trunc_t*)grib_context_malloc(gh->context, sizeof(bif_trunc_t));
|
||||
|
||||
memset(bt, 0, sizeof(bif_trunc_t));
|
||||
|
||||
if ((ret = grib_get_double_internal(gh, self->reference_value_, &bt->reference_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(gh, reference_value_, &bt->reference_value)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(gh, laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->sub_i_, &bt->sub_i)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, sub_i_, &bt->sub_i)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->sub_j_, &bt->sub_j)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, sub_j_, &bt->sub_j)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->bif_i_, &bt->bif_i)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, bif_i_, &bt->bif_i)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->bif_j_, &bt->bif_j)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, bif_j_, &bt->bif_j)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
if ((ret = grib_get_long_internal(gh, self->biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
|
||||
switch (bt->ieee_floats) {
|
||||
|
@ -461,7 +434,7 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a)
|
|||
|
||||
cleanup:
|
||||
|
||||
free_bif_trunc(bt, a);
|
||||
free_bif_trunc(bt, this);
|
||||
if (ret) fprintf(stderr, "ERROR: new_bif_trunc: %s\n", grib_get_error_message(ret));
|
||||
|
||||
return NULL;
|
||||
|
@ -495,7 +468,7 @@ int grib_accessor_data_g2bifourier_packing_t::unpack_double(double* val, size_t*
|
|||
if ((ret = value_count(&count)) != GRIB_SUCCESS)
|
||||
goto cleanup;
|
||||
|
||||
bt = new_bif_trunc(this);
|
||||
bt = new_bif_trunc();
|
||||
|
||||
if (bt == NULL) {
|
||||
ret = GRIB_INTERNAL_ERROR;
|
||||
|
@ -594,7 +567,7 @@ int grib_accessor_data_g2bifourier_packing_t::pack_double(const double* val, siz
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
bt = new_bif_trunc(this);
|
||||
bt = new_bif_trunc();
|
||||
|
||||
if (bt == NULL) {
|
||||
long makeTemplate = 0;
|
||||
|
|
|
@ -12,6 +12,35 @@
|
|||
|
||||
#include "grib_accessor_class_data_simple_packing.h"
|
||||
|
||||
typedef unsigned long (*encode_float_proc)(double);
|
||||
typedef double (*decode_float_proc)(unsigned long);
|
||||
|
||||
|
||||
typedef struct bif_trunc_t
|
||||
{
|
||||
long bits_per_value;
|
||||
long decimal_scale_factor;
|
||||
long binary_scale_factor;
|
||||
long ieee_floats;
|
||||
long laplacianOperatorIsSet;
|
||||
double laplacianOperator;
|
||||
double reference_value;
|
||||
long sub_i, sub_j, bif_i, bif_j;
|
||||
long biFourierTruncationType;
|
||||
long biFourierSubTruncationType;
|
||||
long keepaxes;
|
||||
long maketemplate;
|
||||
decode_float_proc decode_float;
|
||||
encode_float_proc encode_float;
|
||||
int bytes;
|
||||
long* itruncation_bif;
|
||||
long* jtruncation_bif;
|
||||
long* itruncation_sub;
|
||||
long* jtruncation_sub;
|
||||
size_t n_vals_bif, n_vals_sub;
|
||||
} bif_trunc_t;
|
||||
|
||||
|
||||
class grib_accessor_data_g2bifourier_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
|
@ -23,7 +52,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* ieee_floats_;
|
||||
const char* laplacianOperatorIsSet_;
|
||||
const char* laplacianOperator_;
|
||||
|
@ -37,4 +66,6 @@ public:
|
|||
const char* biFourierMakeTemplate_;
|
||||
const char* totalNumberOfValuesInUnpackedSubset_;
|
||||
const char* numberOfValues_;
|
||||
|
||||
bif_trunc_t* new_bif_trunc();
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* number_of_values_;
|
||||
const char* bits_per_value_;
|
||||
const char* max_level_value_;
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
const char* primary_bitmap_;
|
||||
const char* secondary_bitmap_;
|
||||
const char* missing_value_;
|
||||
|
|
|
@ -199,6 +199,7 @@ int grib_accessor_data_sh_unpacked_t::unpack_double(double* val, size_t* len)
|
|||
if (sub_k >= 0) {
|
||||
for (hcount = 0; hcount < sub_k + 1; hcount++) {
|
||||
val[i++] = decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes));
|
||||
val[i++] = decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes));
|
||||
|
||||
if (GRIBEX_sh_bug_present && hcount == sub_k) {
|
||||
/* bug in ecmwf data, last row (K+1)is scaled but should not */
|
||||
|
|
|
@ -23,9 +23,7 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
const char* coded_values_;
|
||||
const char* real_part_;
|
||||
// TODO(maee): dirty_ shadowed by the derived class
|
||||
// int dirty_;
|
||||
};
|
||||
|
|
|
@ -159,14 +159,13 @@ int grib_accessor_data_simple_packing_t::unpack_double_element_set(const size_t*
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static int unpack(grib_accessor* a, T* val, size_t* len)
|
||||
int grib_accessor_data_simple_packing_t::unpack(T* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a;
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
|
||||
const char* cclass_name = a->class_name_;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data;
|
||||
const char* cclass_name = class_name_;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data;
|
||||
|
||||
size_t i = 0;
|
||||
int err = 0;
|
||||
|
@ -184,7 +183,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
double units_factor = 1.0;
|
||||
double units_bias = 0.0;
|
||||
|
||||
err = a->value_count(&count);
|
||||
err = value_count(&count);
|
||||
if (err)
|
||||
return err;
|
||||
n_vals = count;
|
||||
|
@ -194,7 +193,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
/*
|
||||
|
@ -205,14 +204,14 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_INVALID_BPV;
|
||||
}
|
||||
|
||||
if (self->units_factor_ &&
|
||||
(grib_get_double_internal(gh, self->units_factor_, &units_factor) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(gh, self->units_factor_, 1.0);
|
||||
if (units_factor_ &&
|
||||
(grib_get_double_internal(gh, units_factor_, &units_factor) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(gh, units_factor_, 1.0);
|
||||
}
|
||||
|
||||
if (self->units_bias_ &&
|
||||
(grib_get_double_internal(gh, self->units_bias_, &units_bias) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(gh, self->units_bias_, 0.0);
|
||||
if (units_bias_ &&
|
||||
(grib_get_double_internal(gh, units_bias_, &units_bias) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(gh, units_bias_, 0.0);
|
||||
}
|
||||
|
||||
if (n_vals == 0) {
|
||||
|
@ -220,15 +219,15 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
a->dirty_ = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
/* Special case */
|
||||
|
@ -243,23 +242,23 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
s = codes_power<T>(binary_scale_factor, 2);
|
||||
d = codes_power<T>(-decimal_scale_factor, 10);
|
||||
|
||||
grib_context_log(a->context_, GRIB_LOG_DEBUG,
|
||||
"%s %s: Creating %s, %zu values", cclass_name, __func__, a->name_, n_vals);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"%s %s: Creating %s, %zu values", cclass_name, __func__, name_, n_vals);
|
||||
|
||||
offsetBeforeData = a->byte_offset();
|
||||
offsetBeforeData = byte_offset();
|
||||
buf += offsetBeforeData;
|
||||
|
||||
/*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */
|
||||
|
||||
/* ECC-941 */
|
||||
if (!a->context_->ieee_packing) {
|
||||
if (!context_->ieee_packing) {
|
||||
/* Must turn off this check when the environment variable ECCODES_GRIB_IEEE_PACKING is on */
|
||||
long offsetAfterData = 0;
|
||||
err = grib_get_long(gh, "offsetAfterData", &offsetAfterData);
|
||||
if (!err && offsetAfterData > offsetBeforeData) {
|
||||
const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/
|
||||
if (offsetBeforeData + valuesSize > offsetAfterData) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Data section size mismatch: "
|
||||
"offset before data=%ld, offset after data=%ld (num values=%zu, bits per value=%ld)",
|
||||
cclass_name, offsetBeforeData, offsetAfterData, n_vals, bits_per_value);
|
||||
|
@ -275,7 +274,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
// }
|
||||
}
|
||||
|
||||
grib_context_log(a->context_, GRIB_LOG_DEBUG,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"%s %s: calling outline function: bpv: %ld, rv: %g, bsf: %ld, dsf: %ld",
|
||||
cclass_name, __func__, bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor);
|
||||
grib_decode_array<T>(buf, &pos, bits_per_value, reference_value, s, d, n_vals, val);
|
||||
|
@ -304,19 +303,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
|
||||
int grib_accessor_data_simple_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(this, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_data_simple_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(this, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals)
|
||||
int grib_accessor_data_simple_packing_t::_unpack_double(double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals)
|
||||
{
|
||||
grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->class_name_;
|
||||
grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)this;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
size_t i = 0;
|
||||
int err = 0;
|
||||
|
@ -362,7 +361,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
a->dirty_ = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
@ -385,23 +384,23 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c
|
|||
s = codes_power<double>(binary_scale_factor, 2);
|
||||
d = codes_power<double>(-decimal_scale_factor, 10);
|
||||
|
||||
grib_context_log(a->context_, GRIB_LOG_DEBUG,
|
||||
"%s %s: Creating %s, %zu values", cclass_name, __func__, a->name_, n_vals);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"%s %s: Creating %s, %zu values", cclass_name, __func__, name_, n_vals);
|
||||
|
||||
offsetBeforeData = a->byte_offset();
|
||||
offsetBeforeData = byte_offset();
|
||||
buf += offsetBeforeData;
|
||||
|
||||
/*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */
|
||||
|
||||
/* ECC-941 */
|
||||
if (!a->context_->ieee_packing) {
|
||||
if (!context_->ieee_packing) {
|
||||
/* Must turn off this check when the environment variable ECCODES_GRIB_IEEE_PACKING is on */
|
||||
long offsetAfterData = 0;
|
||||
err = grib_get_long(gh, "offsetAfterData", &offsetAfterData);
|
||||
if (!err && offsetAfterData > offsetBeforeData) {
|
||||
const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/
|
||||
if (offsetBeforeData + valuesSize > offsetAfterData) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"Data section size mismatch: offset before data=%ld, offset after data=%ld (num values=%ld, bits per value=%ld)",
|
||||
offsetBeforeData, offsetAfterData, n_vals, bits_per_value);
|
||||
return GRIB_DECODING_ERROR;
|
||||
|
@ -417,7 +416,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c
|
|||
// }
|
||||
}
|
||||
|
||||
grib_context_log(a->context_, GRIB_LOG_DEBUG,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"unpack_double: calling outline function : bpv %d, rv : %g, sf : %d, dsf : %d ",
|
||||
bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor);
|
||||
grib_decode_array<double>(buf, &pos, bits_per_value, reference_value, s, d, n_vals, val);
|
||||
|
@ -454,7 +453,7 @@ int grib_accessor_data_simple_packing_t::unpack_double_subarray(double* val, siz
|
|||
|
||||
buf += (start * bits_per_value) / 8;
|
||||
pos = start * bits_per_value % 8;
|
||||
return _unpack_double(this, val, plen, buf, pos, nvals);
|
||||
return _unpack_double(val, plen, buf, pos, nvals);
|
||||
}
|
||||
|
||||
int grib_accessor_data_simple_packing_t::pack_double(const double* val, size_t* len)
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override;
|
||||
int unpack_double_subarray(double* val, size_t start, size_t len) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
int edition_;
|
||||
const char* units_factor_;
|
||||
const char* units_bias_;
|
||||
|
@ -39,4 +39,8 @@ public:
|
|||
const char* binary_scale_factor_;
|
||||
const char* decimal_scale_factor_;
|
||||
const char* optimize_scaling_factor_;
|
||||
|
||||
private:
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
int _unpack_double(double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals);
|
||||
};
|
||||
|
|
|
@ -29,10 +29,8 @@ void grib_accessor_dictionary_t::init(const long len, grib_arguments* params)
|
|||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
static grib_trie* load_dictionary(grib_accessor* a, int* err)
|
||||
grib_trie* grib_accessor_dictionary_t::load_dictionary(int* err)
|
||||
{
|
||||
grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a;
|
||||
|
||||
char* filename = NULL;
|
||||
char line[1024] = {
|
||||
0,
|
||||
|
@ -55,17 +53,17 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err)
|
|||
grib_trie* dictionary = NULL;
|
||||
FILE* f = NULL;
|
||||
int i = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_context* c = a->context_;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_context* c = context_;
|
||||
|
||||
*err = GRIB_SUCCESS;
|
||||
|
||||
len = 1024;
|
||||
if (self->masterDir_ != NULL)
|
||||
grib_get_string(h, self->masterDir_, masterDir, &len);
|
||||
if (masterDir_ != NULL)
|
||||
grib_get_string(h, masterDir_, masterDir, &len);
|
||||
len = 1024;
|
||||
if (self->localDir_ != NULL)
|
||||
grib_get_string(h, self->localDir_, localDir, &len);
|
||||
if (localDir_ != NULL)
|
||||
grib_get_string(h, localDir_, localDir, &len);
|
||||
|
||||
if (*masterDir != 0) {
|
||||
char name[2048] = {
|
||||
|
@ -74,12 +72,12 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err)
|
|||
char recomposed[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(name, sizeof(name), "%s/%s", masterDir, self->dictionary_);
|
||||
snprintf(name, sizeof(name), "%s/%s", masterDir, dictionary_);
|
||||
grib_recompose_name(h, NULL, name, recomposed, 0);
|
||||
filename = grib_context_full_defs_path(c, recomposed);
|
||||
}
|
||||
else {
|
||||
filename = grib_context_full_defs_path(c, self->dictionary_);
|
||||
filename = grib_context_full_defs_path(c, dictionary_);
|
||||
}
|
||||
|
||||
if (*localDir != 0) {
|
||||
|
@ -89,7 +87,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err)
|
|||
char localRecomposed[1024] = {
|
||||
0,
|
||||
};
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, self->dictionary_);
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, dictionary_);
|
||||
grib_recompose_name(h, NULL, localName, localRecomposed, 0);
|
||||
localFilename = grib_context_full_defs_path(c, localRecomposed);
|
||||
snprintf(dictName, sizeof(dictName), "%s:%s", localFilename, filename);
|
||||
|
@ -99,7 +97,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err)
|
|||
}
|
||||
|
||||
if (!filename) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", self->dictionary_);
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", dictionary_);
|
||||
*err = GRIB_FILE_NOT_FOUND;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -108,11 +106,11 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err)
|
|||
}
|
||||
dictionary = (grib_trie*)grib_trie_get(c->lists, dictName);
|
||||
if (dictionary) {
|
||||
grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", self->dictionary_);
|
||||
grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", dictionary_);
|
||||
return dictionary;
|
||||
}
|
||||
else {
|
||||
grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename);
|
||||
grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", dictionary_, filename);
|
||||
}
|
||||
|
||||
f = codes_fopen(filename, "r");
|
||||
|
@ -192,7 +190,7 @@ int grib_accessor_dictionary_t::unpack_string(char* buffer, size_t* len)
|
|||
size_t rsize = 0;
|
||||
int i = 0;
|
||||
|
||||
grib_trie* dictionary = load_dictionary(this, &err);
|
||||
grib_trie* dictionary = load_dictionary(&err);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
|
|
@ -26,10 +26,12 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* dictionary_;
|
||||
const char* key_;
|
||||
long column_;
|
||||
const char* masterDir_;
|
||||
const char* localDir_;
|
||||
|
||||
grib_trie* load_dictionary(int* err);
|
||||
};
|
||||
|
|
|
@ -21,6 +21,6 @@ public:
|
|||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
grib_arguments* arg_;
|
||||
};
|
||||
|
|
|
@ -19,16 +19,6 @@ grib_accessor* grib_accessor_expanded_descriptors = &_grib_accessor_expanded_des
|
|||
#define DESC_SIZE_INIT 400 /* Initial size for grib_bufr_descriptors_array_new */
|
||||
#define DESC_SIZE_INCR 400 /* Increment size for grib_bufr_descriptors_array_new */
|
||||
|
||||
typedef struct change_coding_params
|
||||
{
|
||||
int associatedFieldWidth;
|
||||
int localDescriptorWidth;
|
||||
int extraWidth;
|
||||
int extraScale;
|
||||
int newStringWidth;
|
||||
double referenceFactor;
|
||||
} change_coding_params;
|
||||
|
||||
/* Handy macro to catch errors.
|
||||
* Arguments: array is a pointer to 'bufr_descriptors_array', result is pointer to 'bufr_descriptor' */
|
||||
#define DESCRIPTORS_POP_FRONT_OR_RETURN(array, result) \
|
||||
|
@ -49,7 +39,7 @@ void grib_accessor_expanded_descriptors_t::init(const long len, grib_arguments*
|
|||
expandedName_ = grib_arguments_get_name(hand, args, n++);
|
||||
rank_ = grib_arguments_get_long(hand, args, n++);
|
||||
if (rank_ != 0) {
|
||||
expandedAccessor_ = grib_find_accessor(hand, expandedName_);
|
||||
expandedAccessor_ = dynamic_cast<grib_accessor_expanded_descriptors_t*>(grib_find_accessor(hand, expandedName_));
|
||||
}
|
||||
else {
|
||||
expandedAccessor_ = 0;
|
||||
|
@ -98,10 +88,8 @@ static char* descriptor_type_name(int dtype)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err)
|
||||
void grib_accessor_expanded_descriptors_t::__expand(bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err)
|
||||
{
|
||||
grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a;
|
||||
|
||||
int k, j, i;
|
||||
size_t size = 0;
|
||||
long* v_array = NULL;
|
||||
|
@ -115,11 +103,11 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_
|
|||
bufr_descriptor* urc = NULL;
|
||||
size_t idx = 0;
|
||||
bufr_descriptor* u0 = NULL;
|
||||
grib_context* c = a->context_;
|
||||
grib_context* c = context_;
|
||||
bufr_descriptor* us = NULL;
|
||||
bufr_descriptors_array* inner_expanded = NULL;
|
||||
bufr_descriptors_array* inner_unexpanded = NULL;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
#if MYDEBUG
|
||||
int idepth;
|
||||
#endif
|
||||
|
@ -146,23 +134,23 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_
|
|||
printf("+++ pop %06ld [%s]\n", u->code, descriptor_type_name(u->type));
|
||||
#endif
|
||||
/*this is to get the sequence elements of the sequence unexpanded[i] */
|
||||
*err = grib_set_long(hand, self->sequence_, u->code);
|
||||
*err = grib_get_size(hand, self->sequence_, &size);
|
||||
*err = grib_set_long(hand, sequence_, u->code);
|
||||
*err = grib_get_size(hand, sequence_, &size);
|
||||
grib_bufr_descriptor_delete(u);
|
||||
if (*err)
|
||||
goto cleanup;
|
||||
v_array = (long*)grib_context_malloc_clear(c, sizeof(long) * size);
|
||||
*err = grib_get_long_array(hand, self->sequence_, v_array, &size);
|
||||
*err = grib_get_long_array(hand, sequence_, v_array, &size);
|
||||
if (*err)
|
||||
goto cleanup;
|
||||
|
||||
inner_unexpanded = grib_bufr_descriptors_array_new(c, DESC_SIZE_INIT, DESC_SIZE_INCR);
|
||||
for (i = 0; i < size; i++) {
|
||||
vv = grib_bufr_descriptor_new(self->tablesAccessor_, v_array[i], !SILENT, err);
|
||||
vv = grib_bufr_descriptor_new(tablesAccessor_, v_array[i], !SILENT, err);
|
||||
inner_unexpanded = grib_bufr_descriptors_array_push(inner_unexpanded, vv);
|
||||
}
|
||||
grib_context_free(c, v_array);
|
||||
inner_expanded = do_expand(a, inner_unexpanded, ccp, err);
|
||||
inner_expanded = do_expand(inner_unexpanded, ccp, err);
|
||||
if (*err)
|
||||
return;
|
||||
grib_bufr_descriptors_array_delete(inner_unexpanded);
|
||||
|
@ -212,7 +200,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_
|
|||
printf("+++ pop %06ld [%s]\n", u0->code, descriptor_type_name(u0->type));
|
||||
#endif
|
||||
}
|
||||
inner_expanded = do_expand(a, inner_unexpanded, ccp, err);
|
||||
inner_expanded = do_expand(inner_unexpanded, ccp, err);
|
||||
if (*err)
|
||||
return;
|
||||
grib_bufr_descriptors_array_delete(inner_unexpanded);
|
||||
|
@ -270,7 +258,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_
|
|||
for (i = 0; i < us->X; i++)
|
||||
grib_bufr_descriptor_delete(ur[i]);
|
||||
|
||||
inner_expanded = do_expand(a, inner_unexpanded, ccp, err);
|
||||
inner_expanded = do_expand(inner_unexpanded, ccp, err);
|
||||
if (*err)
|
||||
return;
|
||||
grib_bufr_descriptors_array_delete(inner_unexpanded);
|
||||
|
@ -290,7 +278,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_
|
|||
DESCRIPTORS_POP_FRONT_OR_RETURN(unexpanded, u);
|
||||
size = 1;
|
||||
if (ccp->associatedFieldWidth && u->X != 31) {
|
||||
bufr_descriptor* au = grib_bufr_descriptor_new(self->tablesAccessor_, 999999, !SILENT, err);
|
||||
bufr_descriptor* au = grib_bufr_descriptor_new(tablesAccessor_, 999999, !SILENT, err);
|
||||
au->width = ccp->associatedFieldWidth;
|
||||
grib_bufr_descriptor_set_scale(au, 0);
|
||||
strcpy(au->shortName, "associatedField");
|
||||
|
@ -416,10 +404,10 @@ cleanup:
|
|||
if (us) grib_bufr_descriptor_delete(us);
|
||||
}
|
||||
|
||||
static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err)
|
||||
bufr_descriptors_array* grib_accessor_expanded_descriptors_t::do_expand(bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err)
|
||||
{
|
||||
bufr_descriptors_array* expanded = NULL;
|
||||
grib_context* c = a->context_;
|
||||
bufr_descriptors_array* expanded = NULL;
|
||||
grib_context* c = context_;
|
||||
#if MYDEBUG
|
||||
int idepth;
|
||||
global_depth++;
|
||||
|
@ -445,7 +433,7 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra
|
|||
}
|
||||
#endif
|
||||
while (unexpanded->n) {
|
||||
__expand(a, unexpanded, expanded, ccp, err);
|
||||
__expand(unexpanded, expanded, ccp, err);
|
||||
if (*err) {
|
||||
grib_bufr_descriptors_array_delete(expanded);
|
||||
return NULL;
|
||||
|
@ -478,11 +466,10 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra
|
|||
return expanded;
|
||||
}
|
||||
|
||||
static int expand(grib_accessor* a)
|
||||
int grib_accessor_expanded_descriptors_t::expand()
|
||||
{
|
||||
grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a;
|
||||
int err = 0;
|
||||
size_t unexpandedSize = 0;
|
||||
int err = 0;
|
||||
size_t unexpandedSize = 0;
|
||||
/* grib_iarray* unexp=0; */
|
||||
int i;
|
||||
long* u = 0;
|
||||
|
@ -494,25 +481,25 @@ static int expand(grib_accessor* a)
|
|||
bufr_descriptors_array* unexpanded = NULL;
|
||||
bufr_descriptors_array* unexpanded_copy = NULL;
|
||||
bufr_descriptors_array* expanded = NULL;
|
||||
grib_context* c = a->context_;
|
||||
const grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_context* c = context_;
|
||||
const grib_handle* h = grib_handle_of_accessor(this);
|
||||
int operator206yyy_width = 0; /* width specified by operator 206YYY */
|
||||
|
||||
if (!self->do_expand_) {
|
||||
if (!do_expand_) {
|
||||
return err;
|
||||
}
|
||||
self->do_expand_ = 0;
|
||||
if (self->rank_ != 0) {
|
||||
err = expand(self->expandedAccessor_);
|
||||
self->expanded_ = ((grib_accessor_expanded_descriptors_t*)self->expandedAccessor_)->expanded_;
|
||||
do_expand_ = 0;
|
||||
if (rank_ != 0) {
|
||||
err = expandedAccessor_->expand();
|
||||
expanded_ = ((grib_accessor_expanded_descriptors_t*)expandedAccessor_)->expanded_;
|
||||
return err;
|
||||
}
|
||||
|
||||
err = grib_get_size(h, self->unexpandedDescriptors_, &unexpandedSize);
|
||||
err = grib_get_size(h, unexpandedDescriptors_, &unexpandedSize);
|
||||
if (err)
|
||||
return err;
|
||||
if (unexpandedSize == 0) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Unexpanded size is zero!", a->name_);
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Unexpanded size is zero!", name_);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
|
@ -521,7 +508,7 @@ static int expand(grib_accessor* a)
|
|||
err = GRIB_OUT_OF_MEMORY;
|
||||
return err;
|
||||
}
|
||||
err = grib_get_long_array(h, self->unexpandedDescriptors_, u, &unexpandedSize);
|
||||
err = grib_get_long_array(h, unexpandedDescriptors_, u, &unexpandedSize);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -541,14 +528,14 @@ static int expand(grib_accessor* a)
|
|||
snprintf(key, sizeof(key), "%ld_%ld_%ld_%ld_%ld", centre, masterTablesVersionNumber, localTablesVersionNumber, masterTablesNumber, u[0]);
|
||||
expanded = grib_context_expanded_descriptors_list_get(c, key, u, unexpandedSize);
|
||||
if (expanded) {
|
||||
self->expanded_ = expanded;
|
||||
expanded_ = expanded;
|
||||
grib_context_free(c, u);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
if (!self->tablesAccessor_) {
|
||||
self->tablesAccessor_ = grib_find_accessor(h, self->tablesAccessorName_);
|
||||
Assert(self->tablesAccessor_);
|
||||
if (!tablesAccessor_) {
|
||||
tablesAccessor_ = grib_find_accessor(h, tablesAccessorName_);
|
||||
Assert(tablesAccessor_);
|
||||
}
|
||||
|
||||
unexpanded = grib_bufr_descriptors_array_new(c, unexpandedSize, DESC_SIZE_INCR);
|
||||
|
@ -558,9 +545,9 @@ static int expand(grib_accessor* a)
|
|||
bufr_descriptor *aDescriptor1, *aDescriptor2;
|
||||
/* ECC-1274: clear error and only issue msg once */
|
||||
err = 0;
|
||||
aDescriptor1 = grib_bufr_descriptor_new(self->tablesAccessor_, u[i], SILENT, &err);
|
||||
aDescriptor1 = grib_bufr_descriptor_new(tablesAccessor_, u[i], SILENT, &err);
|
||||
err = 0;
|
||||
aDescriptor2 = grib_bufr_descriptor_new(self->tablesAccessor_, u[i], !SILENT, &err);
|
||||
aDescriptor2 = grib_bufr_descriptor_new(tablesAccessor_, u[i], !SILENT, &err);
|
||||
|
||||
/* ECC-433: Operator 206YYY */
|
||||
if (aDescriptor1->F == 2 && aDescriptor1->X == 6) {
|
||||
|
@ -591,30 +578,28 @@ static int expand(grib_accessor* a)
|
|||
ccp.referenceFactor = 1;
|
||||
ccp.associatedFieldWidth = 0;
|
||||
ccp.newStringWidth = 0;
|
||||
self->expanded_ = do_expand(a, unexpanded, &ccp, &err);
|
||||
expanded_ = do_expand(unexpanded, &ccp, &err);
|
||||
if (err) {
|
||||
grib_bufr_descriptors_array_delete(unexpanded);
|
||||
grib_bufr_descriptors_array_delete(unexpanded_copy);
|
||||
return err;
|
||||
}
|
||||
grib_context_expanded_descriptors_list_push(c, key, self->expanded_, unexpanded_copy);
|
||||
grib_context_expanded_descriptors_list_push(c, key, expanded_, unexpanded_copy);
|
||||
grib_bufr_descriptors_array_delete(unexpanded);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand)
|
||||
int grib_accessor_expanded_descriptors_t::grib_accessor_expanded_descriptors_set_do_expand(long do_expand)
|
||||
{
|
||||
grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a;
|
||||
self->do_expand_ = do_expand;
|
||||
do_expand_ = do_expand;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(grib_accessor* a, int* err)
|
||||
bufr_descriptors_array* grib_accessor_expanded_descriptors_t::grib_accessor_expanded_descriptors_get_expanded(int* err)
|
||||
{
|
||||
const grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a;
|
||||
*err = expand(a);
|
||||
return self->expanded_;
|
||||
*err = expand();
|
||||
return expanded_;
|
||||
}
|
||||
|
||||
int grib_accessor_expanded_descriptors_t::unpack_double(double* val, size_t* len)
|
||||
|
@ -633,7 +618,7 @@ int grib_accessor_expanded_descriptors_t::unpack_double(double* val, size_t* len
|
|||
grib_context_free(context_, lval);
|
||||
}
|
||||
else {
|
||||
ret = expand(this);
|
||||
ret = expand();
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -657,7 +642,7 @@ int grib_accessor_expanded_descriptors_t::unpack_long(long* val, size_t* len)
|
|||
size_t rlen = 0;
|
||||
size_t i = 0;
|
||||
|
||||
ret = expand(this);
|
||||
ret = expand();
|
||||
if (ret)
|
||||
return ret;
|
||||
if (!expanded_)
|
||||
|
@ -736,7 +721,7 @@ int grib_accessor_expanded_descriptors_t::value_count(long* rlen)
|
|||
int err = 0;
|
||||
*rlen = 0;
|
||||
|
||||
err = expand(this);
|
||||
err = expand();
|
||||
if (err) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s unable to compute size", name_);
|
||||
grib_bufr_descriptors_array_delete(expanded_);
|
||||
|
|
|
@ -12,6 +12,16 @@
|
|||
|
||||
#include "grib_accessor_class_long.h"
|
||||
|
||||
typedef struct change_coding_params
|
||||
{
|
||||
int associatedFieldWidth;
|
||||
int localDescriptorWidth;
|
||||
int extraWidth;
|
||||
int extraScale;
|
||||
int newStringWidth;
|
||||
double referenceFactor;
|
||||
} change_coding_params;
|
||||
|
||||
class grib_accessor_expanded_descriptors_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
|
@ -27,17 +37,21 @@ public:
|
|||
void destroy(grib_context*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
int grib_accessor_expanded_descriptors_set_do_expand(long do_expand);
|
||||
bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(int* err);
|
||||
|
||||
private:
|
||||
const char* unexpandedDescriptors_;
|
||||
const char* sequence_;
|
||||
const char* expandedName_;
|
||||
const char* tablesAccessorName_;
|
||||
bufr_descriptors_array* expanded_;
|
||||
int rank_;
|
||||
grib_accessor* expandedAccessor_;
|
||||
grib_accessor_expanded_descriptors_t* expandedAccessor_;
|
||||
int do_expand_;
|
||||
grib_accessor* tablesAccessor_;
|
||||
};
|
||||
|
||||
int grib_accessor_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand);
|
||||
bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(grib_accessor* a, int* err);
|
||||
int expand();
|
||||
void __expand(bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err);
|
||||
bufr_descriptors_array* do_expand(bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err);
|
||||
};
|
||||
|
|
|
@ -79,7 +79,7 @@ int grib_accessor_g1_message_length_t::pack_long(const long* val, size_t* len)
|
|||
/* Do not directly call pack_long on base class */
|
||||
/* because in this special case we want to skip the checks. */
|
||||
/* So we call the helper function which has an extra argument */
|
||||
return pack_long_unsigned_helper(this, val, len, /*check=*/0);
|
||||
return pack_long_unsigned_helper(val, len, /*check=*/0);
|
||||
}
|
||||
|
||||
if (!s4)
|
||||
|
@ -97,7 +97,7 @@ int grib_accessor_g1_message_length_t::pack_long(const long* val, size_t* len)
|
|||
|
||||
*len = 1;
|
||||
/* Do not do the length checks in this special case */
|
||||
if ((ret = pack_long_unsigned_helper(this, &tlen, len, /*check=*/0)) != GRIB_SUCCESS)
|
||||
if ((ret = pack_long_unsigned_helper(&tlen, len, /*check=*/0)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
// if((ret = super->pack_long(a,&tlen,len)) != GRIB_SUCCESS) return ret;
|
||||
|
|
|
@ -31,7 +31,7 @@ int grib_accessor_g1_section4_length_t::pack_long(const long* val, size_t* len)
|
|||
// Note: Do not directly call pack_long on base class
|
||||
// because in this special case we want to skip the checks.
|
||||
// So we call the helper function which has an extra argument
|
||||
return pack_long_unsigned_helper(this, val, len, /*check=*/0);
|
||||
return pack_long_unsigned_helper(val, len, /*check=*/0);
|
||||
}
|
||||
|
||||
int grib_accessor_g1_section4_length_t::unpack_long(long* val, size_t* len)
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
const char* century_;
|
||||
const char* year_;
|
||||
const char* month_;
|
||||
|
|
|
@ -18,7 +18,7 @@ int grib_accessor_g1fcperiod_t::unpack_string(char* val, size_t* len)
|
|||
long start = 0, theEnd = 0;
|
||||
char tmp[1024];
|
||||
const size_t tmpLen = sizeof(tmp);
|
||||
int err = grib_g1_step_get_steps(this, &start, &theEnd);
|
||||
int err = grib_g1_step_get_steps(&start, &theEnd);
|
||||
size_t l = 0;
|
||||
|
||||
if (err)
|
||||
|
|
|
@ -103,9 +103,8 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_g1forecastmonth_t::unpack_long_edition1(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a;
|
||||
int err = 0;
|
||||
|
||||
long verification_yearmonth = 0;
|
||||
|
@ -116,29 +115,29 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len)
|
|||
long check = 0;
|
||||
long fcmonth = 0;
|
||||
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a),
|
||||
self->verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this),
|
||||
verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->base_date_, &base_date)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), base_date_, &base_date)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->day_, &day)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), day_, &day)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->hour_, &hour)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), hour_, &hour)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->check_, &check)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), check_, &check)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = calculate_fcmonth(a, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS)
|
||||
if ((err = calculate_fcmonth(this, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
/* Verification - compare gribForecastMonth with fcmonth */
|
||||
fcmonth = *val;
|
||||
if (gribForecastMonth != 0 && gribForecastMonth != fcmonth) {
|
||||
if (check) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", self->fcmonth_,
|
||||
gribForecastMonth, base_date, self->verification_yearmonth_, fcmonth);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", fcmonth_,
|
||||
gribForecastMonth, base_date, verification_yearmonth_, fcmonth);
|
||||
Assert(gribForecastMonth == fcmonth);
|
||||
}
|
||||
else {
|
||||
|
@ -160,7 +159,7 @@ int grib_accessor_g1forecastmonth_t::unpack_long(long* val, size_t* len)
|
|||
return err;
|
||||
|
||||
if (edition == 1)
|
||||
return unpack_long_edition1(this, val, len);
|
||||
return unpack_long_edition1(val, len);
|
||||
if (edition == 2)
|
||||
return unpack_long_edition2(this, val, len);
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* verification_yearmonth_;
|
||||
const char* base_date_;
|
||||
const char* day_;
|
||||
const char* hour_;
|
||||
const char* fcmonth_;
|
||||
const char* check_;
|
||||
|
||||
int unpack_long_edition1(long* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -83,9 +83,8 @@ static const int u2s[] = {
|
|||
1800 /* (15) 30 minutes */
|
||||
};
|
||||
|
||||
int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd)
|
||||
int grib_accessor_g1step_range_t::grib_g1_step_get_steps(long* start, long* theEnd)
|
||||
{
|
||||
grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a;
|
||||
int err = 0;
|
||||
long p1 = 0, p2 = 0, unit = 0, timeRangeIndicator = 0, timeRangeIndicatorFromStepRange = 0;
|
||||
long step_unit = 1;
|
||||
|
@ -96,30 +95,30 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd)
|
|||
long newstart, newend;
|
||||
int factor = 1;
|
||||
long u2sf, u2sf_step_unit;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
if (self->step_unit_ != NULL)
|
||||
grib_get_long_internal(hand, self->step_unit_, &step_unit);
|
||||
if (step_unit_ != NULL)
|
||||
grib_get_long_internal(hand, step_unit_, &step_unit);
|
||||
|
||||
if (err != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
err = grib_get_long_internal(hand, self->unit_, &unit);
|
||||
err = grib_get_long_internal(hand, unit_, &unit);
|
||||
if (err)
|
||||
return err;
|
||||
if (unit == 254) {
|
||||
unit = 15; /* See ECC-316: WMO says 254 is for 'seconds' but we use 15! */
|
||||
}
|
||||
|
||||
err = grib_get_long_internal(hand, self->p1_, &p1);
|
||||
err = grib_get_long_internal(hand, p1_, &p1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = grib_get_long_internal(hand, self->p2_, &p2);
|
||||
err = grib_get_long_internal(hand, p2_, &p2);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = grib_get_long_internal(hand, self->timeRangeIndicator_, &timeRangeIndicator);
|
||||
err = grib_get_long_internal(hand, timeRangeIndicator_, &timeRangeIndicator);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -130,8 +129,8 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd)
|
|||
if (timeRangeIndicatorFromStepRange == 10)
|
||||
timeRangeIndicator = timeRangeIndicatorFromStepRange;
|
||||
|
||||
if (self->stepType_) {
|
||||
err = grib_get_string_internal(hand, self->stepType_, stepType, &stepTypeLen);
|
||||
if (stepType_) {
|
||||
err = grib_get_string_internal(hand, stepType_, stepType, &stepTypeLen);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
@ -196,7 +195,7 @@ int grib_accessor_g1step_range_t::unpack_string(char* val, size_t* len)
|
|||
size_t stepTypeLen = 20;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
if ((err = grib_g1_step_get_steps(this, &start, &theEnd)) != GRIB_SUCCESS) {
|
||||
if ((err = grib_g1_step_get_steps(&start, &theEnd)) != GRIB_SUCCESS) {
|
||||
size_t step_unit_string_len = 10;
|
||||
char step_unit_string[10];
|
||||
|
||||
|
|
|
@ -30,7 +30,10 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
int grib_g1_step_get_steps(long* start, long* theEnd);
|
||||
|
||||
private:
|
||||
const char* p1_;
|
||||
const char* p2_;
|
||||
const char* timeRangeIndicator_;
|
||||
|
|
|
@ -77,11 +77,10 @@ int grib_accessor_g2_mars_labeling_t::unpack_string(char* val, size_t* len)
|
|||
return grib_get_string(grib_handle_of_accessor(this), key, val, len);
|
||||
}
|
||||
|
||||
static int extra_set(grib_accessor* a, long val)
|
||||
int grib_accessor_g2_mars_labeling_t::extra_set(long val)
|
||||
{
|
||||
grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a;
|
||||
int ret = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
char stepType[30] = {
|
||||
0,
|
||||
};
|
||||
|
@ -108,7 +107,7 @@ static int extra_set(grib_accessor* a, long val)
|
|||
const int is_wave = grib_is_defined(hand, "waveDirectionNumber");
|
||||
const int is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval");
|
||||
|
||||
switch (self->index_) {
|
||||
switch (index_) {
|
||||
case 0:
|
||||
/* class */
|
||||
return ret;
|
||||
|
@ -162,7 +161,7 @@ static int extra_set(grib_accessor* a, long val)
|
|||
break;
|
||||
case 17: /* Ensemble mean (em) */
|
||||
derivedForecast = 0;
|
||||
grib_get_string(hand, self->stepType_, stepType, &stepTypelen);
|
||||
grib_get_string(hand, stepType_, stepType, &stepTypelen);
|
||||
if (!strcmp(stepType, "instant")) {
|
||||
productDefinitionTemplateNumberNew = 2;
|
||||
}
|
||||
|
@ -174,7 +173,7 @@ static int extra_set(grib_accessor* a, long val)
|
|||
break;
|
||||
case 18: /* Ensemble standard deviation (es) */
|
||||
derivedForecast = 4;
|
||||
grib_get_string(hand, self->stepType_, stepType, &stepTypelen);
|
||||
grib_get_string(hand, stepType_, stepType, &stepTypelen);
|
||||
if (!strcmp(stepType, "instant")) {
|
||||
productDefinitionTemplateNumberNew = 2;
|
||||
}
|
||||
|
@ -258,7 +257,7 @@ static int extra_set(grib_accessor* a, long val)
|
|||
typeOfGeneratingProcess = 255;
|
||||
break;
|
||||
default:
|
||||
grib_context_log(a->context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val);
|
||||
grib_context_log(context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val);
|
||||
/*return GRIB_ENCODING_ERROR;*/
|
||||
}
|
||||
break;
|
||||
|
@ -269,7 +268,7 @@ static int extra_set(grib_accessor* a, long val)
|
|||
case 1249: /* elda */
|
||||
case 1250: /* ewla */
|
||||
is_eps = 1; /* These streams are all for ensembles */
|
||||
grib_get_string(hand, self->stepType_, stepType, &stepTypelen);
|
||||
grib_get_string(hand, stepType_, stepType, &stepTypelen);
|
||||
is_instant = (strcmp(stepType, "instant") == 0);
|
||||
productDefinitionTemplateNumberNew = grib2_select_PDTN(
|
||||
is_eps, is_instant,
|
||||
|
@ -282,8 +281,8 @@ static int extra_set(grib_accessor* a, long val)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"invalid first argument of g2_mars_labeling in %s", a->name_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"invalid first argument of g2_mars_labeling in %s", name_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
@ -293,19 +292,19 @@ static int extra_set(grib_accessor* a, long val)
|
|||
}
|
||||
|
||||
if (productDefinitionTemplateNumberNew >= 0) {
|
||||
grib_get_long(hand, self->productDefinitionTemplateNumber_, &productDefinitionTemplateNumber);
|
||||
grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber);
|
||||
if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew)
|
||||
grib_set_long(hand, self->productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew);
|
||||
grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew);
|
||||
}
|
||||
|
||||
if (derivedForecast >= 0) {
|
||||
grib_set_long(hand, self->derivedForecast_, derivedForecast);
|
||||
grib_set_long(hand, derivedForecast_, derivedForecast);
|
||||
}
|
||||
|
||||
if (typeOfProcessedData > 0)
|
||||
grib_set_long(hand, self->typeOfProcessedData_, typeOfProcessedData);
|
||||
grib_set_long(hand, typeOfProcessedData_, typeOfProcessedData);
|
||||
if (typeOfGeneratingProcess > 0)
|
||||
grib_set_long(hand, self->typeOfGeneratingProcess_, typeOfGeneratingProcess);
|
||||
grib_set_long(hand, typeOfGeneratingProcess_, typeOfGeneratingProcess);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -340,7 +339,7 @@ int grib_accessor_g2_mars_labeling_t::pack_string(const char* val, size_t* len)
|
|||
if (ret)
|
||||
return ret; /* failed */
|
||||
|
||||
return extra_set(this, lval);
|
||||
return extra_set(lval);
|
||||
}
|
||||
|
||||
int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len)
|
||||
|
@ -368,7 +367,7 @@ int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len)
|
|||
if (ret)
|
||||
return ret; /* failed */
|
||||
|
||||
return extra_set(this, *val);
|
||||
return extra_set(*val);
|
||||
}
|
||||
|
||||
int grib_accessor_g2_mars_labeling_t::value_count(long* count)
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
int index_;
|
||||
const char* the_class_;
|
||||
const char* stream_;
|
||||
|
@ -38,4 +38,6 @@ public:
|
|||
const char* stepType_;
|
||||
const char* derivedForecast_;
|
||||
const char* typeOfGeneratingProcess_;
|
||||
|
||||
int extra_set(long val);
|
||||
};
|
||||
|
|
|
@ -96,10 +96,8 @@ static int convert_time_range_long_(
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_g2end_step_t::unpack_one_time_range_long_(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a;
|
||||
|
||||
int err = 0;
|
||||
long start_step_value;
|
||||
long step_units;
|
||||
|
@ -107,17 +105,17 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len)
|
|||
long time_range_value, typeOfTimeIncrement;
|
||||
int add_time_range = 1; /* whether we add lengthOfTimeRange */
|
||||
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value)))
|
||||
if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->step_units_, &step_units)))
|
||||
if ((err = grib_get_long_internal(h, step_units_, &step_units)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit)))
|
||||
if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->time_range_value_, &time_range_value)))
|
||||
if ((err = grib_get_long_internal(h, time_range_value_, &time_range_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement)))
|
||||
if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement)))
|
||||
return err;
|
||||
|
||||
err = convert_time_range_long_(h, step_units, time_range_unit, &time_range_value);
|
||||
|
@ -146,9 +144,8 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_g2end_step_t::unpack_one_time_range_double_(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a;
|
||||
int err = 0;
|
||||
double start_step_value;
|
||||
long start_step_unit;
|
||||
|
@ -158,19 +155,19 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t*
|
|||
long typeOfTimeIncrement;
|
||||
int add_time_range = 1; /* whether we add lengthOfTimeRange */
|
||||
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
if ((err = grib_get_double_internal(h, self->start_step_value_, &start_step_value)))
|
||||
if ((err = grib_get_double_internal(h, start_step_value_, &start_step_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->step_units_, &step_units)))
|
||||
if ((err = grib_get_long_internal(h, step_units_, &step_units)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit)))
|
||||
if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit)))
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->time_range_value_, &time_range_value)))
|
||||
if ((err = grib_get_double_internal(h, time_range_value_, &time_range_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement)))
|
||||
if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement)))
|
||||
return err;
|
||||
|
||||
eccodes::Step start_step{ start_step_value, start_step_unit };
|
||||
|
@ -199,11 +196,10 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t*
|
|||
}
|
||||
|
||||
#define MAX_NUM_TIME_RANGES 16 /* maximum number of time range specifications */
|
||||
static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_g2end_step_t::unpack_multiple_time_ranges_long_(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a;
|
||||
int i = 0, err = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
long numberOfTimeRanges = 0, step_units = 0, start_step_value = 0;
|
||||
|
||||
size_t count = 0;
|
||||
|
@ -217,11 +213,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t
|
|||
0,
|
||||
};
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value)))
|
||||
if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->step_units_, &step_units)))
|
||||
if ((err = grib_get_long_internal(h, step_units_, &step_units)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges)))
|
||||
if ((err = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges)))
|
||||
return err;
|
||||
if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!");
|
||||
|
@ -230,11 +226,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t
|
|||
|
||||
count = numberOfTimeRanges;
|
||||
/* Get the arrays for the N time ranges */
|
||||
if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count)))
|
||||
if ((err = grib_get_long_array(h, typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count)))
|
||||
return err;
|
||||
if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count)))
|
||||
if ((err = grib_get_long_array(h, time_range_unit_, arr_coded_unit, &count)))
|
||||
return err;
|
||||
if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count)))
|
||||
if ((err = grib_get_long_array(h, time_range_value_, arr_coded_time_range, &count)))
|
||||
return err;
|
||||
|
||||
/* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */
|
||||
|
@ -258,11 +254,10 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t
|
|||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_g2end_step_t::unpack_multiple_time_ranges_double_(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a;
|
||||
int i = 0, err = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
long numberOfTimeRanges = 0;
|
||||
long step_units = 0;
|
||||
long start_step_value = 0;
|
||||
|
@ -279,17 +274,17 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si
|
|||
0,
|
||||
};
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value)))
|
||||
if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit)))
|
||||
return err;
|
||||
|
||||
eccodes::Step start_step{ start_step_value, start_step_unit };
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->step_units_, &step_units)))
|
||||
if ((err = grib_get_long_internal(h, step_units_, &step_units)))
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges)))
|
||||
if ((err = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges)))
|
||||
return err;
|
||||
if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!");
|
||||
|
@ -298,11 +293,11 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si
|
|||
|
||||
count = numberOfTimeRanges;
|
||||
/* Get the arrays for the N time ranges */
|
||||
if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count)))
|
||||
if ((err = grib_get_long_array(h, typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count)))
|
||||
return err;
|
||||
if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count)))
|
||||
if ((err = grib_get_long_array(h, time_range_unit_, arr_coded_unit, &count)))
|
||||
return err;
|
||||
if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count)))
|
||||
if ((err = grib_get_long_array(h, time_range_value_, arr_coded_time_range, &count)))
|
||||
return err;
|
||||
|
||||
/* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */
|
||||
|
@ -355,10 +350,10 @@ int grib_accessor_g2end_step_t::unpack_long(long* val, size_t* len)
|
|||
|
||||
try {
|
||||
if (numberOfTimeRanges == 1) {
|
||||
ret = unpack_one_time_range_long_(this, val, len);
|
||||
ret = unpack_one_time_range_long_(val, len);
|
||||
}
|
||||
else {
|
||||
ret = unpack_multiple_time_ranges_long_(this, val, len);
|
||||
ret = unpack_multiple_time_ranges_long_(val, len);
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
@ -397,10 +392,10 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len)
|
|||
|
||||
try {
|
||||
if (numberOfTimeRanges == 1) {
|
||||
ret = unpack_one_time_range_double_(this, val, len);
|
||||
ret = unpack_one_time_range_double_(val, len);
|
||||
}
|
||||
else {
|
||||
ret = unpack_multiple_time_ranges_double_(this, val, len);
|
||||
ret = unpack_multiple_time_ranges_double_(val, len);
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
@ -411,10 +406,9 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit)
|
||||
int grib_accessor_g2end_step_t::pack_long_(const long end_step_value, const long end_step_unit)
|
||||
{
|
||||
grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
int err = 0;
|
||||
|
||||
long year;
|
||||
|
@ -436,34 +430,34 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en
|
|||
long typeOfTimeIncrement;
|
||||
|
||||
double dend, dstep;
|
||||
const int show_units_for_hours = a->context_->grib_hourly_steps_with_units;
|
||||
const int show_units_for_hours = context_->grib_hourly_steps_with_units;
|
||||
|
||||
eccodes::Step end_step{ end_step_value, end_step_unit };
|
||||
|
||||
/*point in time */
|
||||
if (self->year_ == NULL) {
|
||||
if (year_ == NULL) {
|
||||
if ((err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
err = grib_set_long_internal(h, self->start_step_value_, end_step.value<long>());
|
||||
err = grib_set_long_internal(h, start_step_value_, end_step.value<long>());
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit)))
|
||||
if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->year_, &year)))
|
||||
if ((err = grib_get_long_internal(h, year_, &year)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->month_, &month)))
|
||||
if ((err = grib_get_long_internal(h, month_, &month)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->day_, &day)))
|
||||
if ((err = grib_get_long_internal(h, day_, &day)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->hour_, &hour)))
|
||||
if ((err = grib_get_long_internal(h, hour_, &hour)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->minute_, &minute)))
|
||||
if ((err = grib_get_long_internal(h, minute_, &minute)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->second_, &second)))
|
||||
if ((err = grib_get_long_internal(h, second_, &second)))
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value)))
|
||||
if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value)))
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit)))
|
||||
return err;
|
||||
|
@ -478,7 +472,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en
|
|||
return GRIB_WRONG_STEP_UNIT;
|
||||
}
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement)))
|
||||
if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement)))
|
||||
return err;
|
||||
|
||||
eccodes::Step start_step{ start_step_value, start_step_unit };
|
||||
|
@ -496,7 +490,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en
|
|||
grib_context_log(h->context, GRIB_LOG_ERROR,
|
||||
"%s:%s: Date/Time is not valid! "
|
||||
"year=%ld month=%ld day=%ld hour=%ld minute=%ld second=%ld",
|
||||
a->class_name_, __func__, year, month, day, hour, minute, second);
|
||||
class_name_, __func__, year, month, day, hour, minute, second);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
|
@ -513,17 +507,17 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en
|
|||
if (err != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_set_long_internal(h, self->year_of_end_of_interval_, year_of_end_of_interval)))
|
||||
if ((err = grib_set_long_internal(h, year_of_end_of_interval_, year_of_end_of_interval)))
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(h, self->month_of_end_of_interval_, month_of_end_of_interval)))
|
||||
if ((err = grib_set_long_internal(h, month_of_end_of_interval_, month_of_end_of_interval)))
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(h, self->day_of_end_of_interval_, day_of_end_of_interval)))
|
||||
if ((err = grib_set_long_internal(h, day_of_end_of_interval_, day_of_end_of_interval)))
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(h, self->hour_of_end_of_interval_, hour_of_end_of_interval)))
|
||||
if ((err = grib_set_long_internal(h, hour_of_end_of_interval_, hour_of_end_of_interval)))
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(h, self->minute_of_end_of_interval_, minute_of_end_of_interval)))
|
||||
if ((err = grib_set_long_internal(h, minute_of_end_of_interval_, minute_of_end_of_interval)))
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(h, self->second_of_end_of_interval_, second_of_end_of_interval)))
|
||||
if ((err = grib_set_long_internal(h, second_of_end_of_interval_, second_of_end_of_interval)))
|
||||
return err;
|
||||
|
||||
const char* forecast_time_value_key = "forecastTime";
|
||||
|
@ -538,13 +532,13 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en
|
|||
time_range_opt = eccodes::Step{ time_range.value<long>(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } };
|
||||
}
|
||||
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value_, time_range_opt.value<long>())) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_value_, time_range_opt.value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_unit_, time_range_opt.unit().value<long>())) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_unit_, time_range_opt.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_value_key, forecast_time_opt.value<long>())) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_value_key, forecast_time_opt.value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_unit_key, forecast_time_opt.unit().value<long>())) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_unit_key, forecast_time_opt.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
|
@ -614,7 +608,7 @@ int grib_accessor_g2end_step_t::pack_long(const long* val, size_t* len)
|
|||
else {
|
||||
end_step_unit = force_step_units;
|
||||
}
|
||||
ret = pack_long_(this, *val, end_step_unit);
|
||||
ret = pack_long_(*val, end_step_unit);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::pack_long: %s", e.what());
|
||||
|
@ -638,7 +632,7 @@ int grib_accessor_g2end_step_t::pack_string(const char* val, size_t* len)
|
|||
if ((ret = grib_set_long_internal(h, "endStepUnit", end_step.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = pack_long_(this, end_step.value<long>(), end_step.unit().value<long>())) != GRIB_SUCCESS)
|
||||
if ((ret = pack_long_(end_step.value<long>(), end_step.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* start_step_value_;
|
||||
const char* step_units_;
|
||||
const char* year_;
|
||||
|
@ -47,4 +47,10 @@ public:
|
|||
const char* time_range_value_;
|
||||
const char* typeOfTimeIncrement_;
|
||||
const char* numberOfTimeRanges_;
|
||||
|
||||
int unpack_one_time_range_long_(long* val, size_t* len);
|
||||
int unpack_one_time_range_double_(double* val, size_t* len);
|
||||
int unpack_multiple_time_ranges_long_(long* val, size_t* len);
|
||||
int unpack_multiple_time_ranges_double_(double* val, size_t* len);
|
||||
int pack_long_(const long end_step_value, const long end_step_unit);
|
||||
};
|
||||
|
|
|
@ -69,10 +69,6 @@ public:
|
|||
grib_accessor* make_clone(grib_section*, int*) override;
|
||||
grib_accessor* next_accessor() override; // TODO: Implement
|
||||
|
||||
|
||||
template <typename T>
|
||||
int unpack_helper(grib_accessor* a, T* v, size_t* len);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
|
@ -86,6 +82,9 @@ private:
|
|||
UNPACK_STRING,
|
||||
};
|
||||
std::bitset<8> is_overridden_ = 0b11111111;
|
||||
|
||||
template <typename T>
|
||||
int unpack_helper(grib_accessor* a, T* v, size_t* len);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ public:
|
|||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
// TODO(maee): shadows name_?
|
||||
const char* envvar_;
|
||||
char* value_;
|
||||
const char* default_value_;
|
||||
|
|
|
@ -64,16 +64,15 @@ int grib_accessor_hash_array_t::unpack_double(double* val, size_t* len)
|
|||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err)
|
||||
grib_hash_array_value* grib_accessor_hash_array_t::find_hash_value(int* err)
|
||||
{
|
||||
grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a;
|
||||
grib_hash_array_value* ha_ret = 0;
|
||||
grib_hash_array_value* ha = NULL;
|
||||
|
||||
ha = get_hash_array(grib_handle_of_accessor(a), self->creator_);
|
||||
ha = get_hash_array(grib_handle_of_accessor(this), creator_);
|
||||
if (!ha) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"unable to get hash value for %s", self->creator_->name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"unable to get hash value for %s", creator_->name);
|
||||
*err = GRIB_HASH_ARRAY_NO_MATCH;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -81,27 +80,27 @@ static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err)
|
|||
*err = GRIB_SUCCESS;
|
||||
|
||||
Assert(ha != NULL);
|
||||
if (!self->key_) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"unable to get hash value for %s, set before getting", self->creator_->name);
|
||||
if (!key_) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"unable to get hash value for %s, set before getting", creator_->name);
|
||||
*err = GRIB_HASH_ARRAY_NO_MATCH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key_);
|
||||
ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, key_);
|
||||
if (!ha_ret)
|
||||
ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, "default");
|
||||
|
||||
if (!ha_ret) {
|
||||
*err = GRIB_HASH_ARRAY_NO_MATCH;
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"hash_array: no match for %s=%s",
|
||||
self->creator_->name, self->key_);
|
||||
const char* full_path = get_hash_array_full_path(self->creator_);
|
||||
creator_->name, key_);
|
||||
const char* full_path = get_hash_array_full_path(creator_);
|
||||
if (full_path) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path);
|
||||
}
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'");
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'");
|
||||
return NULL;
|
||||
}
|
||||
return ha_ret;
|
||||
|
@ -114,7 +113,7 @@ int grib_accessor_hash_array_t::unpack_long(long* val, size_t* len)
|
|||
size_t i = 0;
|
||||
|
||||
if (!ha_) {
|
||||
ha = find_hash_value(this, &err);
|
||||
ha = find_hash_value(&err);
|
||||
if (err)
|
||||
return err;
|
||||
ha_ = ha;
|
||||
|
@ -169,7 +168,7 @@ int grib_accessor_hash_array_t::value_count(long* count)
|
|||
grib_hash_array_value* ha = 0;
|
||||
|
||||
if (!ha_) {
|
||||
ha = find_hash_value(this, &err);
|
||||
ha = find_hash_value(&err);
|
||||
if (err)
|
||||
return err;
|
||||
ha_ = ha;
|
||||
|
|
|
@ -33,7 +33,9 @@ public:
|
|||
void init(const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
char* key_;
|
||||
grib_hash_array_value* ha_;
|
||||
|
||||
grib_hash_array_value* find_hash_value(int* err);
|
||||
};
|
||||
|
|
|
@ -21,8 +21,10 @@ public:
|
|||
void init(const long l, grib_arguments* args) override;
|
||||
void dump(grib_dumper* dumper) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
grib_arguments* args_;
|
||||
|
||||
friend grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error);
|
||||
};
|
||||
|
||||
// grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error)
|
||||
|
|
|
@ -41,7 +41,7 @@ void grib_accessor_md5_t::init(const long len, grib_arguments* arg)
|
|||
}
|
||||
}
|
||||
}
|
||||
// TODO(maee): Is this necessary?
|
||||
|
||||
grib_accessor::length_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC;
|
||||
|
|
|
@ -21,8 +21,10 @@ public:
|
|||
void init(const long l, grib_arguments* args) override;
|
||||
void dump(grib_dumper* dumper) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
grib_arguments* args_;
|
||||
|
||||
friend grib_nearest* grib_nearest_new(const grib_handle* ch, int* error);
|
||||
};
|
||||
|
||||
// grib_nearest* grib_nearest_new(const grib_handle* ch, int* error);
|
||||
|
|
|
@ -122,15 +122,14 @@ int grib_accessor_number_of_points_gaussian_t::unpack_long(long* val, size_t* le
|
|||
return err;
|
||||
|
||||
if (support_legacy == 1)
|
||||
return unpack_long_with_legacy_support(this, val, len);
|
||||
return unpack_long_with_legacy_support(val, len);
|
||||
else
|
||||
return unpack_long_new(this, val, len);
|
||||
return unpack_long_new(val, len);
|
||||
}
|
||||
|
||||
/* New algorithm */
|
||||
static int unpack_long_new(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_number_of_points_gaussian_t::unpack_long_new(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a;
|
||||
int err = GRIB_SUCCESS;
|
||||
int is_global = 0;
|
||||
long ni = 0, nj = 0, plpresent = 0, order = 0;
|
||||
|
@ -142,17 +141,17 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len)
|
|||
long ilon_first = 0, ilon_last = 0;
|
||||
double angular_precision = 1.0 / 1000000.0;
|
||||
long angleSubdivisions = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
grib_context* c = a->context_;
|
||||
grib_context* c = context_;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->ni_, &ni)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, ni_, &ni)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, nj_, &nj)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (nj == 0)
|
||||
|
@ -169,23 +168,23 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len)
|
|||
// double lon_first_row = 0, lon_last_row = 0;
|
||||
|
||||
/*reduced*/
|
||||
if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, order_, &order)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lat_first_, &lat_first)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lon_first_, &lon_first)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lat_last_, &lat_last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lon_last_, &lon_last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize);
|
||||
plsave = pl;
|
||||
grib_get_long_array_internal(h, self->pl_, pl, &plsize);
|
||||
grib_get_long_array_internal(h, pl_, pl, &plsize);
|
||||
|
||||
if (lon_last < 0)
|
||||
lon_last += 360;
|
||||
|
@ -237,9 +236,8 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len)
|
|||
}
|
||||
|
||||
/* With Legacy support */
|
||||
static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_number_of_points_gaussian_t::unpack_long_with_legacy_support(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a;
|
||||
int err = GRIB_SUCCESS;
|
||||
int is_global = 0;
|
||||
long ni = 0, nj = 0, plpresent = 0, order = 0;
|
||||
|
@ -251,18 +249,18 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t*
|
|||
long ilon_first = 0, ilon_last = 0;
|
||||
double angular_precision = 1.0 / 1000000.0;
|
||||
long angleSubdivisions = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
size_t numDataValues = 0;
|
||||
|
||||
grib_context* c = a->context_;
|
||||
grib_context* c = context_;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->ni_, &ni)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, ni_, &ni)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, nj_, &nj)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (nj == 0)
|
||||
|
@ -279,23 +277,23 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t*
|
|||
// double lon_first_row = 0, lon_last_row = 0;
|
||||
|
||||
/*reduced*/
|
||||
if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, order_, &order)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lat_first_, &lat_first)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lon_first_, &lon_first)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lat_last_, &lat_last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, lon_last_, &lon_last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize);
|
||||
plsave = pl;
|
||||
grib_get_long_array_internal(h, self->pl_, pl, &plsize);
|
||||
grib_get_long_array_internal(h, pl_, pl, &plsize);
|
||||
|
||||
if (lon_last < 0)
|
||||
lon_last += 360;
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* ni_;
|
||||
const char* nj_;
|
||||
const char* plpresent_;
|
||||
|
@ -33,4 +33,7 @@ public:
|
|||
const char* lat_last_;
|
||||
const char* lon_last_;
|
||||
const char* support_legacy_;
|
||||
|
||||
int unpack_long_new(long* val, size_t* len);
|
||||
int unpack_long_with_legacy_support(long* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -96,7 +96,6 @@ grib_accessor* grib_accessor_section_t::next(grib_accessor* a, int explore)
|
|||
}
|
||||
if (!next) {
|
||||
if (a->parent_->owner)
|
||||
// TODO(maee): check the owner of the parent
|
||||
next = a->parent_->owner->next(a->parent_->owner, 0);
|
||||
}
|
||||
return next;
|
||||
|
|
|
@ -18,24 +18,23 @@ long grib_accessor_signed_bits_t::byte_count()
|
|||
return length_;
|
||||
}
|
||||
|
||||
static long compute_byte_count(grib_accessor* a)
|
||||
long grib_accessor_signed_bits_t::compute_byte_count()
|
||||
{
|
||||
grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a;
|
||||
long numberOfBits;
|
||||
long numberOfElements;
|
||||
int ret = 0;
|
||||
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits);
|
||||
if (ret) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", a->name_, self->numberOfBits_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", name_, numberOfBits_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements);
|
||||
if (ret) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", a->name_, self->numberOfElements_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", name_, numberOfElements_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -48,7 +47,7 @@ void grib_accessor_signed_bits_t::init(const long len, grib_arguments* args)
|
|||
int n = 0;
|
||||
numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
length_ = compute_byte_count(this);
|
||||
length_ = compute_byte_count();
|
||||
}
|
||||
|
||||
int grib_accessor_signed_bits_t::unpack_long(long* val, size_t* len)
|
||||
|
|
|
@ -28,7 +28,9 @@ public:
|
|||
void init(const long, grib_arguments*) override;
|
||||
void update_size(size_t) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* numberOfBits_;
|
||||
const char* numberOfElements_;
|
||||
|
||||
long compute_byte_count();
|
||||
};
|
||||
|
|
|
@ -65,11 +65,10 @@ void grib_accessor_smart_table_t::init(const long len, grib_arguments* params)
|
|||
table_ = NULL;
|
||||
}
|
||||
|
||||
grib_smart_table* load_table(grib_accessor* a)
|
||||
grib_smart_table* grib_accessor_smart_table_t::load_table()
|
||||
{
|
||||
grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a;
|
||||
size_t size = 0;
|
||||
grib_handle* h = ((grib_accessor*)self)->parent_->h;
|
||||
grib_handle* h = this->parent_->h;
|
||||
grib_context* c = h->context;
|
||||
grib_smart_table* t = NULL;
|
||||
grib_smart_table* next = NULL;
|
||||
|
@ -96,30 +95,30 @@ grib_smart_table* load_table(grib_accessor* a)
|
|||
};
|
||||
size_t len = 1024;
|
||||
|
||||
if (self->masterDir_ != NULL) {
|
||||
grib_get_string(h, self->masterDir_, masterDir, &len);
|
||||
if (masterDir_ != NULL) {
|
||||
grib_get_string(h, masterDir_, masterDir, &len);
|
||||
}
|
||||
|
||||
len = 1024;
|
||||
if (self->localDir_ != NULL) {
|
||||
grib_get_string(h, self->localDir_, localDir, &len);
|
||||
if (localDir_ != NULL) {
|
||||
grib_get_string(h, localDir_, localDir, &len);
|
||||
}
|
||||
|
||||
len = 1024;
|
||||
if (self->extraDir_ != NULL && self->extraTable_ != NULL) {
|
||||
grib_get_string(h, self->extraDir_, extraDir, &len);
|
||||
if (extraDir_ != NULL && extraTable_ != NULL) {
|
||||
grib_get_string(h, extraDir_, extraDir, &len);
|
||||
}
|
||||
|
||||
if (*masterDir != 0) {
|
||||
char name[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_);
|
||||
snprintf(name, sizeof(name), "%s/%s", masterDir, tablename_);
|
||||
grib_recompose_name(h, NULL, name, recomposed, 0);
|
||||
filename = grib_context_full_defs_path(c, recomposed);
|
||||
}
|
||||
else {
|
||||
grib_recompose_name(h, NULL, self->tablename_, recomposed, 0);
|
||||
grib_recompose_name(h, NULL, tablename_, recomposed, 0);
|
||||
filename = grib_context_full_defs_path(c, recomposed);
|
||||
}
|
||||
|
||||
|
@ -127,7 +126,7 @@ grib_smart_table* load_table(grib_accessor* a)
|
|||
char localName[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_);
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_);
|
||||
grib_recompose_name(h, NULL, localName, localRecomposed, 0);
|
||||
localFilename = grib_context_full_defs_path(c, localRecomposed);
|
||||
}
|
||||
|
@ -136,7 +135,7 @@ grib_smart_table* load_table(grib_accessor* a)
|
|||
char extraTable[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, self->extraTable_);
|
||||
snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, extraTable_);
|
||||
grib_recompose_name(h, NULL, extraTable, extraRecomposed, 0);
|
||||
extraFilename = grib_context_full_defs_path(c, extraRecomposed);
|
||||
}
|
||||
|
@ -155,7 +154,7 @@ grib_smart_table* load_table(grib_accessor* a)
|
|||
// Note: widthOfCode_ is chosen so that 2^width is bigger than the maximum descriptor code,
|
||||
// which for BUFR4 is the Table C operator 243255
|
||||
//
|
||||
size = (1ULL << self->widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number)
|
||||
size = (1ULL << widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number)
|
||||
|
||||
t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table));
|
||||
t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry));
|
||||
|
@ -317,7 +316,7 @@ int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len)
|
|||
return err;
|
||||
|
||||
if (!table_)
|
||||
table_ = load_table(this);
|
||||
table_ = load_table();
|
||||
table = table_;
|
||||
|
||||
if (table && (value >= 0) && (value < table->numberOfEntries) && table->entries[value].abbreviation) {
|
||||
|
@ -341,9 +340,8 @@ int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
static int get_table_codes(grib_accessor* a)
|
||||
int grib_accessor_smart_table_t::get_table_codes()
|
||||
{
|
||||
grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a;
|
||||
size_t size = 0;
|
||||
long* v = 0;
|
||||
int err = 0;
|
||||
|
@ -352,43 +350,43 @@ static int get_table_codes(grib_accessor* a)
|
|||
|
||||
int table_size;
|
||||
|
||||
if (!a->dirty_)
|
||||
if (!dirty_)
|
||||
return 0;
|
||||
|
||||
table_size = (1 << self->widthOfCode_); // 2 ^ widthOfCode_
|
||||
table_size = (1 << widthOfCode_); // 2 ^ widthOfCode_
|
||||
|
||||
if (!self->table_)
|
||||
self->table_ = load_table(a);
|
||||
if (!table_)
|
||||
table_ = load_table();
|
||||
|
||||
err = grib_get_size(grib_handle_of_accessor(a), self->values_, &size);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), values_, &size);
|
||||
if (err) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"unable to get size of %s", a->name_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"unable to get size of %s", name_);
|
||||
return err;
|
||||
}
|
||||
|
||||
v = (long*)grib_context_malloc_clear(a->context_, size * sizeof(long));
|
||||
v = (long*)grib_context_malloc_clear(context_, size * sizeof(long));
|
||||
|
||||
grib_get_long_array(grib_handle_of_accessor(a), self->values_, v, &size);
|
||||
grib_get_long_array(grib_handle_of_accessor(this), values_, v, &size);
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (v[i] < table_size)
|
||||
count++;
|
||||
}
|
||||
if (self->tableCodes_)
|
||||
grib_context_free(a->context_, self->tableCodes_);
|
||||
self->tableCodes_ = (long*)grib_context_malloc_clear(a->context_, count * sizeof(long));
|
||||
if (tableCodes_)
|
||||
grib_context_free(context_, tableCodes_);
|
||||
tableCodes_ = (long*)grib_context_malloc_clear(context_, count * sizeof(long));
|
||||
j = 0;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (v[i] < table_size)
|
||||
self->tableCodes_[j++] = v[i];
|
||||
tableCodes_[j++] = v[i];
|
||||
}
|
||||
|
||||
grib_context_free(a->context_, v);
|
||||
grib_context_free(context_, v);
|
||||
|
||||
self->tableCodesSize_ = count;
|
||||
a->dirty_ = 0;
|
||||
tableCodesSize_ = count;
|
||||
dirty_ = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -400,7 +398,7 @@ int grib_accessor_smart_table_t::value_count(long* count)
|
|||
|
||||
if (!values_)
|
||||
return 0;
|
||||
err = get_table_codes(this);
|
||||
err = get_table_codes();
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -438,7 +436,7 @@ int grib_accessor_smart_table_t::unpack_long(long* val, size_t* len)
|
|||
if (!values_)
|
||||
return 0;
|
||||
|
||||
err = get_table_codes(this);
|
||||
err = get_table_codes();
|
||||
if (err)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -27,7 +27,10 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
grib_smart_table* table() const { return table_; }
|
||||
|
||||
private:
|
||||
grib_smart_table* table_;
|
||||
const char* values_;
|
||||
const char* tablename_;
|
||||
const char* masterDir_;
|
||||
|
@ -37,7 +40,7 @@ public:
|
|||
int widthOfCode_;
|
||||
long* tableCodes_;
|
||||
size_t tableCodesSize_;
|
||||
grib_smart_table* table_;
|
||||
// TODO(maee): dirty_ shadowed by the derived class
|
||||
// int dirty_;
|
||||
|
||||
grib_smart_table* load_table();
|
||||
int get_table_codes();
|
||||
};
|
||||
|
|
|
@ -77,7 +77,7 @@ int grib_accessor_smart_table_column_t::unpack_string_array(char** buffer, size_
|
|||
if ((err = ((grib_accessor*)tableAccessor)->unpack_long(code, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
table = tableAccessor->table_;
|
||||
table = tableAccessor->table();
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (table && (code[i] >= 0) &&
|
||||
|
@ -132,7 +132,7 @@ int grib_accessor_smart_table_column_t::unpack_long(long* val, size_t* len)
|
|||
return err;
|
||||
}
|
||||
|
||||
table = tableAccessor->table_;
|
||||
table = tableAccessor->table();
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (table && (code[i] >= 0) &&
|
||||
|
|
|
@ -18,23 +18,22 @@ long grib_accessor_spd_t::byte_count()
|
|||
return length_;
|
||||
}
|
||||
|
||||
static long compute_byte_count(grib_accessor* a)
|
||||
long grib_accessor_spd_t::compute_byte_count()
|
||||
{
|
||||
grib_accessor_spd_t* self = (grib_accessor_spd_t*)a;
|
||||
long numberOfBits = 0;
|
||||
long numberOfElements = 0;
|
||||
|
||||
int ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits);
|
||||
int ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits);
|
||||
if (ret) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", a->name_, self->numberOfBits_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", name_, numberOfBits_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements);
|
||||
if (ret) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", a->name_, self->numberOfElements_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", name_, numberOfElements_);
|
||||
return 0;
|
||||
}
|
||||
numberOfElements++;
|
||||
|
@ -48,7 +47,7 @@ void grib_accessor_spd_t::init(const long len, grib_arguments* args)
|
|||
int n = 0;
|
||||
numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
length_ = compute_byte_count(this);
|
||||
length_ = compute_byte_count();
|
||||
}
|
||||
|
||||
int grib_accessor_spd_t::unpack_long(long* val, size_t* len)
|
||||
|
@ -109,7 +108,7 @@ int grib_accessor_spd_t::pack_long(const long* val, size_t* len)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
buflen = compute_byte_count(this);
|
||||
buflen = compute_byte_count();
|
||||
buf = (unsigned char*)grib_context_malloc_clear(context_, buflen);
|
||||
|
||||
for (i = 0; i < rlen - 1; i++) {
|
||||
|
|
|
@ -28,7 +28,9 @@ public:
|
|||
void init(const long, grib_arguments*) override;
|
||||
void update_size(size_t) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* numberOfBits_;
|
||||
const char* numberOfElements_;
|
||||
|
||||
long compute_byte_count();
|
||||
};
|
||||
|
|
|
@ -92,19 +92,18 @@ int grib_accessor_step_in_units_t::unpack_double(double* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
static int pack_long_new_(grib_accessor* a, const long start_step_value, const long start_step_unit, const long force_step_units)
|
||||
int grib_accessor_step_in_units_t::pack_long_new_(const long start_step_value, const long start_step_unit, const long force_step_units)
|
||||
{
|
||||
const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
int err = 0;
|
||||
long forecast_time_unit;
|
||||
long start_step_value_old;
|
||||
long start_step_unit_old;
|
||||
size_t len = 0;
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = a->unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS)
|
||||
if ((err = unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit_old)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
@ -113,7 +112,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l
|
|||
eccodes::Step forecast_time(start_step_value, start_step_unit);
|
||||
eccodes::Step time_range_new{};
|
||||
|
||||
auto time_range_opt = get_step(h, self->time_range_value_, self->time_range_unit_);
|
||||
auto time_range_opt = get_step(h, time_range_value_, time_range_unit_);
|
||||
|
||||
if (time_range_opt) {
|
||||
auto time_range = time_range_opt.value();
|
||||
|
@ -121,11 +120,11 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l
|
|||
if (time_range.value<long>() < 0)
|
||||
time_range = eccodes::Step{ 0l, time_range.unit() };
|
||||
auto [sa, sb] = find_common_units(forecast_time.optimize_unit(), time_range.optimize_unit());
|
||||
if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, sa)) != GRIB_SUCCESS)
|
||||
if ((err = set_step(h, forecast_time_value_, forecast_time_unit_, sa)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = set_step(h, self->time_range_value_, self->time_range_unit_, sb)) != GRIB_SUCCESS)
|
||||
if ((err = set_step(h, time_range_value_, time_range_unit_, sb)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
@ -136,7 +135,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l
|
|||
|
||||
if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, forecast_time)) != GRIB_SUCCESS)
|
||||
if ((err = set_step(h, forecast_time_value_, forecast_time_unit_, forecast_time)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
|
@ -169,7 +168,7 @@ int grib_accessor_step_in_units_t::pack_long(const long* val, size_t* len)
|
|||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
ret = pack_long_new_(this, *val, start_step_unit, force_step_units);
|
||||
ret = pack_long_new_(*val, start_step_unit, force_step_units);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -185,7 +184,7 @@ int grib_accessor_step_in_units_t::pack_string(const char* val, size_t* len)
|
|||
|
||||
try {
|
||||
eccodes::Step step = step_from_string(val, eccodes::Unit{ force_step_units });
|
||||
if ((ret = pack_long_new_(this, step.value<long>(), step.unit().value<long>(), force_step_units)) != GRIB_SUCCESS)
|
||||
if ((ret = pack_long_new_(step.value<long>(), step.unit().value<long>(), force_step_units)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
|
|
@ -28,10 +28,12 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* forecast_time_value_;
|
||||
const char* forecast_time_unit_;
|
||||
const char* step_units_;
|
||||
const char* time_range_unit_;
|
||||
const char* time_range_value_;
|
||||
|
||||
int pack_long_new_(const long start_step_value, const long start_step_unit, const long force_step_units);
|
||||
};
|
||||
|
|
|
@ -22,38 +22,37 @@ void grib_accessor_suppressed_t::init(const long l, grib_arguments* c)
|
|||
length_ = 0;
|
||||
}
|
||||
|
||||
static void log_message(grib_accessor* a)
|
||||
void grib_accessor_suppressed_t::log_message()
|
||||
{
|
||||
grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a;
|
||||
int i = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"key '%s' is unavailable in this version.", a->name_);
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"key '%s' is unavailable in this version.", name_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"Please use the following key(s):");
|
||||
while (grib_arguments_get_name(hand, self->args_, i)) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "\t- %s",
|
||||
grib_arguments_get_name(hand, self->args_, i));
|
||||
while (grib_arguments_get_name(hand, args_, i)) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "\t- %s",
|
||||
grib_arguments_get_name(hand, args_, i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int grib_accessor_suppressed_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
log_message(this);
|
||||
log_message();
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
int grib_accessor_suppressed_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
log_message(this);
|
||||
log_message();
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
int grib_accessor_suppressed_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
log_message(this);
|
||||
log_message();
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
grib_arguments* args_;
|
||||
|
||||
void log_message();
|
||||
};
|
||||
|
|
|
@ -29,9 +29,11 @@ public:
|
|||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
const char* key_;
|
||||
long start_;
|
||||
size_t length_;
|
||||
|
||||
private:
|
||||
long scale_;
|
||||
};
|
||||
|
|
|
@ -70,7 +70,7 @@ int grib_accessor_unexpanded_descriptors_t::pack_long(const long* val, size_t* l
|
|||
long pos = 0;
|
||||
unsigned long f, x, y;
|
||||
unsigned char* buf = NULL;
|
||||
grib_accessor* expanded = NULL;
|
||||
grib_accessor_expanded_descriptors_t* expanded = NULL;
|
||||
size_t buflen = *len * 2;
|
||||
size_t i = 0, length = *len;
|
||||
long createNewData = 1;
|
||||
|
@ -96,9 +96,9 @@ int grib_accessor_unexpanded_descriptors_t::pack_long(const long* val, size_t* l
|
|||
if (createNewData == 0)
|
||||
return ret;
|
||||
|
||||
expanded = grib_find_accessor(hand, "expandedCodes");
|
||||
expanded = dynamic_cast<grib_accessor_expanded_descriptors_t*>(grib_find_accessor(hand, "expandedCodes"));
|
||||
Assert(expanded != NULL);
|
||||
ret = grib_accessor_expanded_descriptors_set_do_expand(expanded, 1);
|
||||
ret = expanded->grib_accessor_expanded_descriptors_set_do_expand(1);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
*/
|
||||
|
||||
#include "grib_accessor_class_unpack_bufr_values.h"
|
||||
#include "grib_accessor_class_bufr_data_array.h"
|
||||
|
||||
grib_accessor_unpack_bufr_values_t _grib_accessor_unpack_bufr_values{};
|
||||
grib_accessor* grib_accessor_unpack_bufr_values = &_grib_accessor_unpack_bufr_values;
|
||||
|
@ -19,7 +18,7 @@ void grib_accessor_unpack_bufr_values_t::init(const long len, grib_arguments* pa
|
|||
grib_accessor_gen_t::init(len, params);
|
||||
char* key;
|
||||
key = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), params, 0);
|
||||
data_accessor_ = grib_find_accessor(grib_handle_of_accessor(this), key);
|
||||
data_accessor_ = dynamic_cast<grib_accessor_bufr_data_array_t*>(grib_find_accessor(grib_handle_of_accessor(this), key));
|
||||
|
||||
length_ = 0;
|
||||
}
|
||||
|
@ -89,7 +88,7 @@ int grib_accessor_unpack_bufr_values_t::pack_long(const long* val, size_t* len)
|
|||
if (*val == 3)
|
||||
unpackMode = CODES_BUFR_NEW_DATA;
|
||||
|
||||
accessor_bufr_data_array_set_unpackMode(data_accessor_, unpackMode);
|
||||
data_accessor_->accessor_bufr_data_array_set_unpackMode(unpackMode);
|
||||
|
||||
return data_accessor_->unpack_double(0, 0);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "grib_accessor_class_gen.h"
|
||||
#include "grib_accessor_class_bufr_data_array.h"
|
||||
|
||||
class grib_accessor_unpack_bufr_values_t : public grib_accessor_gen_t
|
||||
{
|
||||
|
@ -32,5 +33,5 @@ public:
|
|||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
grib_accessor* data_accessor_;
|
||||
grib_accessor_bufr_data_array_t* data_accessor_;
|
||||
};
|
||||
|
|
|
@ -61,10 +61,8 @@ int value_is_missing(long val)
|
|||
return (val == GRIB_MISSING_LONG || val == all_ones);
|
||||
}
|
||||
|
||||
int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, int check)
|
||||
int grib_accessor_unsigned_t::pack_long_unsigned_helper(const long* val, size_t* len, int check)
|
||||
{
|
||||
grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a;
|
||||
|
||||
int ret = 0;
|
||||
long off = 0;
|
||||
long rlen = 0;
|
||||
|
@ -74,28 +72,28 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in
|
|||
unsigned long i = 0;
|
||||
unsigned long missing = 0;
|
||||
|
||||
int err = a->value_count(&rlen);
|
||||
int err = value_count(&rlen);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) {
|
||||
Assert(self->nbytes_ <= 4);
|
||||
missing = ones[self->nbytes_];
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) {
|
||||
Assert(nbytes_ <= 4);
|
||||
missing = ones[nbytes_];
|
||||
}
|
||||
|
||||
if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
self->vvalue_->lval = val[0];
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
vvalue_->lval = val[0];
|
||||
|
||||
if (missing && val[0] == GRIB_MISSING_LONG)
|
||||
self->vvalue_->missing = 1;
|
||||
vvalue_->missing = 1;
|
||||
else
|
||||
self->vvalue_->missing = 0;
|
||||
vvalue_->missing = 0;
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
if (*len < 1) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name_, 1);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1);
|
||||
len[0] = 0;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
@ -110,51 +108,51 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in
|
|||
/* Check if value fits into number of bits */
|
||||
if (check) {
|
||||
if (val[0] < 0) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", a->name_, val[0]);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", name_, val[0]);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
/* See GRIB-23 and GRIB-262 */
|
||||
if (!value_is_missing(v)) {
|
||||
const long nbits = self->nbytes_ * 8;
|
||||
const long nbits = nbytes_ * 8;
|
||||
if (nbits < 33) {
|
||||
unsigned long maxval = (1UL << nbits) - 1;
|
||||
if (maxval > 0 && v > maxval) { /* See ECC-1002 */
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"Key \"%s\": Trying to encode value of %ld but the maximum allowable value is %lu (number of bits=%ld)",
|
||||
a->name_, v, maxval, nbits);
|
||||
name_, v, maxval, nbits);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
off = a->offset_ * 8;
|
||||
ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, v, &off, self->nbytes_ * 8);
|
||||
off = offset_ * 8;
|
||||
ret = grib_encode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, v, &off, nbytes_ * 8);
|
||||
if (ret == GRIB_SUCCESS)
|
||||
len[0] = 1;
|
||||
if (*len > 1)
|
||||
grib_context_log(a->context_, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value", *len, a->name_);
|
||||
grib_context_log(context_, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value", *len, name_);
|
||||
len[0] = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* TODO: We assume that there are no missing values if there are more that 1 value */
|
||||
buflen = *len * self->nbytes_;
|
||||
buflen = *len * nbytes_;
|
||||
|
||||
buf = (unsigned char*)grib_context_malloc(a->context_, buflen);
|
||||
buf = (unsigned char*)grib_context_malloc(context_, buflen);
|
||||
|
||||
for (i = 0; i < *len; i++)
|
||||
grib_encode_unsigned_long(buf, val[i], &off, self->nbytes_ * 8);
|
||||
grib_encode_unsigned_long(buf, val[i], &off, nbytes_ * 8);
|
||||
|
||||
ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent_->h, self->arg_, 0), *len);
|
||||
ret = grib_set_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), *len);
|
||||
|
||||
if (ret == GRIB_SUCCESS)
|
||||
grib_buffer_replace(a, buf, buflen, 1, 1);
|
||||
grib_buffer_replace(this, buf, buflen, 1, 1);
|
||||
else
|
||||
*len = 0;
|
||||
|
||||
grib_context_free(a->context_, buf);
|
||||
grib_context_free(context_, buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -204,7 +202,7 @@ int grib_accessor_unsigned_t::unpack_long(long* val, size_t* len)
|
|||
int grib_accessor_unsigned_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
/* See GRIB-262 as example of why we do the checks */
|
||||
return pack_long_unsigned_helper(this, val, len, /*check=*/1);
|
||||
return pack_long_unsigned_helper(val, len, /*check=*/1);
|
||||
}
|
||||
|
||||
long grib_accessor_unsigned_t::byte_count()
|
||||
|
|
|
@ -30,8 +30,12 @@ public:
|
|||
int is_missing() override;
|
||||
void destroy(grib_context* context) override;
|
||||
|
||||
// TODO(maee): make members private
|
||||
public:
|
||||
protected:
|
||||
long nbytes_;
|
||||
|
||||
int pack_long_unsigned_helper(const long* val, size_t* len, int check);
|
||||
|
||||
private:
|
||||
grib_arguments* arg_;
|
||||
|
||||
};
|
||||
|
|
|
@ -13,24 +13,23 @@
|
|||
grib_accessor_unsigned_bits_t _grib_accessor_unsigned_bits{};
|
||||
grib_accessor* grib_accessor_unsigned_bits = &_grib_accessor_unsigned_bits;
|
||||
|
||||
static long compute_byte_count(grib_accessor* a)
|
||||
long grib_accessor_unsigned_bits_t::compute_byte_count()
|
||||
{
|
||||
grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a;
|
||||
long numberOfBits;
|
||||
long numberOfElements;
|
||||
int ret = 0;
|
||||
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits);
|
||||
if (ret) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", a->name_, self->numberOfBits_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", name_, numberOfBits_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements);
|
||||
if (ret) {
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", a->name_, self->numberOfElements_);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s unable to get %s to compute size", name_, numberOfElements_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -43,7 +42,7 @@ void grib_accessor_unsigned_bits_t::init(const long len, grib_arguments* args)
|
|||
int n = 0;
|
||||
numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
length_ = compute_byte_count(this);
|
||||
length_ = compute_byte_count();
|
||||
}
|
||||
|
||||
int grib_accessor_unsigned_bits_t::unpack_long(long* val, size_t* len)
|
||||
|
@ -112,7 +111,7 @@ int grib_accessor_unsigned_bits_t::pack_long(const long* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
buflen = compute_byte_count(this);
|
||||
buflen = compute_byte_count();
|
||||
buf = (unsigned char*)grib_context_malloc_clear(context_, buflen + sizeof(long));
|
||||
|
||||
for (i = 0; i < *len; i++)
|
||||
|
|
|
@ -28,7 +28,9 @@ public:
|
|||
void init(const long, grib_arguments*) override;
|
||||
void update_size(size_t) override;
|
||||
|
||||
public:
|
||||
private:
|
||||
const char* numberOfBits_;
|
||||
const char* numberOfElements_;
|
||||
|
||||
long compute_byte_count();
|
||||
};
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue