mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'develop' of github.com:ecmwf/eccodes into develop
This commit is contained in:
commit
fd6da74ebd
|
@ -30,14 +30,13 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
|||
|
||||
int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags)
|
||||
{
|
||||
int ret = 0;
|
||||
long type1 = 0;
|
||||
long type2 = 0;
|
||||
int type_mismatch = 0;
|
||||
grib_accessor_class* c1 = NULL;
|
||||
grib_accessor* a1 = this;
|
||||
int ret = 0;
|
||||
long type1 = 0;
|
||||
long type2 = 0;
|
||||
int type_mismatch = 0;
|
||||
grib_accessor* a1 = this;
|
||||
|
||||
if ((compare_flags & GRIB_COMPARE_NAMES) && grib_inline_strcmp(a1->name, a2->name))
|
||||
if ((compare_flags & GRIB_COMPARE_NAMES) && grib_inline_strcmp(a1->name_, a2->name_))
|
||||
return GRIB_NAME_MISMATCH;
|
||||
|
||||
if (compare_flags & GRIB_COMPARE_TYPES) {
|
||||
|
@ -48,8 +47,7 @@ int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags)
|
|||
}
|
||||
|
||||
// ret = GRIB_UNABLE_TO_COMPARE_ACCESSORS;
|
||||
c1 = a1->cclass;
|
||||
ret = c1->compare(a1, a2);
|
||||
ret = compare(a2);
|
||||
|
||||
if (ret == GRIB_VALUE_MISMATCH && type_mismatch)
|
||||
ret = GRIB_TYPE_AND_VALUE_MISMATCH;
|
||||
|
@ -59,13 +57,13 @@ int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags)
|
|||
|
||||
int grib_accessor::add_attribute(grib_accessor* attr, int nest_if_clash)
|
||||
{
|
||||
int id = 0;
|
||||
int idx = 0;
|
||||
int id = 0;
|
||||
int idx = 0;
|
||||
grib_accessor* pSame = NULL;
|
||||
grib_accessor* pAloc = this;
|
||||
|
||||
if (this->has_attributes()) {
|
||||
pSame = this->get_attribute_index(attr->name, &id);
|
||||
pSame = this->get_attribute_index(attr->name_, &id);
|
||||
}
|
||||
|
||||
if (pSame) {
|
||||
|
@ -75,27 +73,27 @@ int grib_accessor::add_attribute(grib_accessor* attr, int nest_if_clash)
|
|||
}
|
||||
|
||||
for (id = 0; id < MAX_ACCESSOR_ATTRIBUTES; id++) {
|
||||
if (pAloc->attributes[id] == NULL) {
|
||||
if (pAloc->attributes_[id] == NULL) {
|
||||
// attr->parent=a->parent;
|
||||
pAloc->attributes[id] = attr;
|
||||
attr->parent_as_attribute = pAloc;
|
||||
if (pAloc->same)
|
||||
attr->same = pAloc->same->get_attribute_index(attr->name, &idx);
|
||||
pAloc->attributes_[id] = attr;
|
||||
attr->parent_as_attribute_ = pAloc;
|
||||
if (pAloc->same_)
|
||||
attr->same_ = pAloc->same_->get_attribute_index(attr->name_, &idx);
|
||||
|
||||
grib_context_log(this->context, GRIB_LOG_DEBUG, "added attribute %s->%s", this->name, attr->name);
|
||||
grib_context_log(this->context_, GRIB_LOG_DEBUG, "added attribute %s->%s", this->name_, attr->name_);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
}
|
||||
return GRIB_TOO_MANY_ATTRIBUTES;
|
||||
}
|
||||
|
||||
grib_accessor* grib_accessor::get_attribute_index(const char* name, int* index)
|
||||
grib_accessor* grib_accessor::get_attribute_index(const char* name_, int* index)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < MAX_ACCESSOR_ATTRIBUTES && this->attributes[i]) {
|
||||
if (!grib_inline_strcmp(this->attributes[i]->name, name)) {
|
||||
while (i < MAX_ACCESSOR_ATTRIBUTES && this->attributes_[i]) {
|
||||
if (!grib_inline_strcmp(this->attributes_[i]->name_, name_)) {
|
||||
*index = i;
|
||||
return this->attributes[i];
|
||||
return this->attributes_[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -104,29 +102,29 @@ grib_accessor* grib_accessor::get_attribute_index(const char* name, int* index)
|
|||
|
||||
int grib_accessor::has_attributes()
|
||||
{
|
||||
return this->attributes[0] ? 1 : 0;
|
||||
return this->attributes_[0] ? 1 : 0;
|
||||
}
|
||||
|
||||
grib_accessor* grib_accessor::get_attribute(const char* name)
|
||||
grib_accessor* grib_accessor::get_attribute(const char* name_)
|
||||
{
|
||||
int index = 0;
|
||||
const char* p = 0;
|
||||
char* basename = NULL;
|
||||
const char* attribute_name = NULL;
|
||||
grib_accessor* acc = NULL;
|
||||
p = name;
|
||||
p = name_;
|
||||
while (*(p + 1) != '\0' && (*p != '-' || *(p + 1) != '>'))
|
||||
p++;
|
||||
if (*(p + 1) == '\0') {
|
||||
return this->get_attribute_index(name, &index);
|
||||
return this->get_attribute_index(name_, &index);
|
||||
}
|
||||
else {
|
||||
size_t size = p - name;
|
||||
size_t size = p - name_;
|
||||
attribute_name = p + 2;
|
||||
basename = (char*)grib_context_malloc_clear(this->context, size + 1);
|
||||
basename = (char*)memcpy(basename, name, size);
|
||||
basename = (char*)grib_context_malloc_clear(this->context_, size + 1);
|
||||
basename = (char*)memcpy(basename, name_, size);
|
||||
acc = this->get_attribute_index(basename, &index);
|
||||
grib_context_free(this->context, basename);
|
||||
grib_context_free(this->context_, basename);
|
||||
if (acc)
|
||||
return acc->get_attribute(attribute_name);
|
||||
else
|
||||
|
|
|
@ -17,131 +17,95 @@ class grib_accessor
|
|||
{
|
||||
public:
|
||||
grib_accessor() :
|
||||
name(nullptr), name_space(nullptr), context(nullptr), h(nullptr), creator(nullptr),
|
||||
length(0), offset(0), parent(nullptr), next_(nullptr), previous_(nullptr), cclass(nullptr),
|
||||
flags(0), sub_section(nullptr), dirty(0), same(nullptr), loop(0), vvalue(nullptr),
|
||||
set(nullptr), parent_as_attribute(nullptr) {}
|
||||
context_(nullptr), name_(nullptr), class_name_(nullptr), name_space_(nullptr), h_(nullptr), creator_(nullptr), length_(0), offset_(0), parent_(nullptr), next_(nullptr), previous_(nullptr), flags_(0), sub_section_(nullptr), dirty_(0), same_(nullptr), loop_(0), vvalue_(nullptr), set_(nullptr), parent_as_attribute_(nullptr) {}
|
||||
|
||||
grib_accessor(const char* name) :
|
||||
context_(nullptr), name_(name), class_name_(nullptr), name_space_(nullptr), h_(nullptr), creator_(nullptr), length_(0), offset_(0), parent_(nullptr), next_(nullptr), previous_(nullptr), flags_(0), sub_section_(nullptr), dirty_(0), same_(nullptr), loop_(0), vvalue_(nullptr), set_(nullptr), parent_as_attribute_(nullptr) {}
|
||||
virtual ~grib_accessor() {}
|
||||
|
||||
virtual void init_accessor(const long, grib_arguments*) = 0;
|
||||
virtual void dump(grib_dumper* f) = 0;
|
||||
virtual int pack_missing() = 0;
|
||||
//virtual int grib_pack_zero(grib_accessor* a) = 0;
|
||||
virtual int is_missing_internal() = 0;
|
||||
virtual int pack_double(const double* v, size_t* len) = 0;
|
||||
virtual int pack_float(const float* v, size_t* len) = 0;
|
||||
virtual int pack_expression(grib_expression* e) = 0;
|
||||
virtual int pack_string(const char* v, size_t* len) = 0;
|
||||
virtual int pack_string_array(const char** v, size_t* len) = 0;
|
||||
virtual int pack_long(const long* v, size_t* len) = 0;
|
||||
virtual int pack_bytes(const unsigned char* v, size_t* len) = 0;
|
||||
virtual int unpack_bytes(unsigned char* v, size_t* len) = 0;
|
||||
virtual int unpack_double_subarray(double* v, size_t start, size_t len) = 0;
|
||||
virtual int unpack_double(double* v, size_t* len) = 0;
|
||||
virtual int unpack_float(float* v, size_t* len) = 0;
|
||||
virtual int unpack_double_element(size_t i, double* v) = 0;
|
||||
virtual int unpack_float_element(size_t i, float* v) = 0;
|
||||
virtual void dump(grib_dumper* f) = 0;
|
||||
virtual int pack_missing() = 0;
|
||||
// virtual int grib_pack_zero(grib_accessor* a) = 0;
|
||||
virtual int is_missing_internal() = 0;
|
||||
virtual int pack_double(const double* v, size_t* len) = 0;
|
||||
virtual int pack_float(const float* v, size_t* len) = 0;
|
||||
virtual int pack_expression(grib_expression* e) = 0;
|
||||
virtual int pack_string(const char* v, size_t* len) = 0;
|
||||
virtual int pack_string_array(const char** v, size_t* len) = 0;
|
||||
virtual int pack_long(const long* v, size_t* len) = 0;
|
||||
virtual int pack_bytes(const unsigned char* v, size_t* len) = 0;
|
||||
virtual int unpack_bytes(unsigned char* v, size_t* len) = 0;
|
||||
virtual int unpack_double_subarray(double* v, size_t start, size_t len) = 0;
|
||||
virtual int unpack_double(double* v, size_t* len) = 0;
|
||||
virtual int unpack_float(float* v, size_t* len) = 0;
|
||||
virtual int unpack_double_element(size_t i, double* v) = 0;
|
||||
virtual int unpack_float_element(size_t i, float* v) = 0;
|
||||
virtual int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) = 0;
|
||||
virtual int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) = 0;
|
||||
virtual int unpack_string(char* v, size_t* len) = 0;
|
||||
virtual int unpack_string_array(char** v, size_t* len) = 0;
|
||||
virtual int unpack_long(long* v, size_t* len) = 0;
|
||||
virtual long get_native_type() = 0;
|
||||
virtual long get_next_position_offset() = 0;
|
||||
virtual long string_length() = 0;
|
||||
virtual long byte_offset() = 0;
|
||||
virtual long byte_count() = 0;
|
||||
virtual int value_count(long* count) = 0;
|
||||
virtual int notify_change(grib_accessor* changed) = 0;
|
||||
virtual grib_accessor* clone(grib_section* s, int* err) = 0;
|
||||
virtual void update_size(size_t len) = 0;
|
||||
virtual int nearest_smaller_value(double val, double* nearest) = 0;
|
||||
virtual size_t preferred_size(int from_handle) = 0;
|
||||
virtual grib_accessor* next_accessor() = 0;
|
||||
virtual void resize(size_t new_size) = 0;
|
||||
virtual void destroy(grib_context* ct) = 0;
|
||||
|
||||
virtual int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) = 0;
|
||||
virtual int unpack_string(char* v, size_t* len) = 0;
|
||||
virtual int unpack_string_array(char** v, size_t* len) = 0;
|
||||
virtual int unpack_long(long* v, size_t* len) = 0;
|
||||
virtual long get_native_type() = 0;
|
||||
virtual long get_next_position_offset() = 0;
|
||||
virtual size_t string_length() = 0;
|
||||
virtual long byte_offset() = 0;
|
||||
virtual long byte_count() = 0;
|
||||
virtual int value_count(long* count) = 0;
|
||||
virtual int notify_change(grib_accessor* changed) = 0;
|
||||
virtual grib_accessor* clone(grib_section* s, int* err) = 0;
|
||||
virtual void update_size(size_t len) = 0;
|
||||
virtual int nearest_smaller_value(double val, double* nearest) = 0;
|
||||
virtual size_t preferred_size(int from_handle) = 0;
|
||||
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);
|
||||
virtual grib_accessor* get_attribute_index(const char* name, int* index);
|
||||
virtual int has_attributes();
|
||||
virtual grib_accessor* get_attribute(const char* name);
|
||||
virtual void init(const long, grib_arguments*) = 0;
|
||||
virtual void post_init() = 0;
|
||||
virtual grib_section* sub_section() = 0;
|
||||
virtual grib_accessor* create_empty_accessor() = 0;
|
||||
virtual int is_missing() = 0;
|
||||
virtual long next_offset() = 0;
|
||||
virtual grib_accessor* next(grib_accessor*, int) = 0;
|
||||
virtual int clear() = 0;
|
||||
virtual grib_accessor* make_clone(grib_section*, int*) = 0;
|
||||
|
||||
|
||||
const char* name; /** < name of the accessor */
|
||||
const char* name_space; /** < namespace to which the accessor belongs */
|
||||
grib_context* context;
|
||||
grib_handle* h;
|
||||
grib_action* creator; /** < action that created the accessor */
|
||||
long length; /** < byte length of the accessor */
|
||||
long offset; /** < offset of the data in the buffer */
|
||||
grib_section* parent; /** < section to which the accessor is attached */
|
||||
grib_accessor* next_; /** < next accessor in list */
|
||||
grib_accessor* previous_; /** < next accessor in list */
|
||||
grib_accessor_class* cclass; /** < behaviour of the accessor */
|
||||
unsigned long flags; /** < Various flags */
|
||||
grib_section* sub_section;
|
||||
|
||||
const char* all_names[MAX_ACCESSOR_NAMES]= {0,}; /** < name of the accessor */
|
||||
const char* all_name_spaces[MAX_ACCESSOR_NAMES] = {0,}; /** < namespace to which the accessor belongs */
|
||||
int dirty;
|
||||
|
||||
grib_accessor* same; /** < accessors with the same name */
|
||||
long loop; /** < used in lists */
|
||||
grib_virtual_value* vvalue; /** < virtual value used when transient flag on **/
|
||||
const char* set;
|
||||
grib_accessor* attributes[MAX_ACCESSOR_ATTRIBUTES] = {0,}; /** < attributes are accessors */
|
||||
grib_accessor* parent_as_attribute;
|
||||
};
|
||||
|
||||
|
||||
class grib_accessor_class
|
||||
{
|
||||
public:
|
||||
const char* name;
|
||||
// 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) */
|
||||
const char* name_space_; /** < namespace to which the accessor belongs */
|
||||
grib_handle* h_;
|
||||
grib_action* creator_; /** < action that created the accessor */
|
||||
long length_; /** < byte length of the accessor */
|
||||
long offset_; /** < offset of the data in the buffer */
|
||||
grib_section* parent_; /** < section to which the accessor is attached */
|
||||
grib_accessor* next_; /** < next accessor in list */
|
||||
grib_accessor* previous_; /** < next accessor in list */
|
||||
unsigned long flags_; /** < Various flags */
|
||||
grib_section* sub_section_;
|
||||
|
||||
grib_accessor_class(const char* name) : name(name){}
|
||||
virtual ~grib_accessor_class(){}
|
||||
const char* all_names_[MAX_ACCESSOR_NAMES] = {
|
||||
0,
|
||||
}; /** < name of the accessor */
|
||||
const char* all_name_spaces_[MAX_ACCESSOR_NAMES] = {
|
||||
0,
|
||||
}; /** < namespace to which the accessor belongs */
|
||||
int dirty_;
|
||||
|
||||
virtual grib_accessor* create_empty_accessor() = 0;
|
||||
virtual grib_section* sub_section(grib_accessor* a) = 0;
|
||||
virtual int get_native_type(grib_accessor*) = 0;
|
||||
virtual int pack_missing(grib_accessor*) = 0;
|
||||
virtual int is_missing(grib_accessor*) = 0;
|
||||
virtual int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) = 0;
|
||||
virtual int pack_double(grib_accessor*, const double* val, size_t* len) = 0;
|
||||
virtual int pack_float(grib_accessor*, const float* val, size_t* len) = 0;
|
||||
virtual int pack_long(grib_accessor*, const long* val, size_t* len) = 0;
|
||||
virtual int pack_string(grib_accessor*, const char*, size_t* len) = 0;
|
||||
virtual int pack_string_array(grib_accessor*, const char**, size_t* len) = 0;
|
||||
virtual int pack_expression(grib_accessor*, grib_expression*) = 0;
|
||||
virtual int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) = 0;
|
||||
virtual int unpack_double(grib_accessor*, double* val, size_t* len) = 0;
|
||||
virtual int unpack_float(grib_accessor*, float* val, size_t* len) = 0;
|
||||
virtual int unpack_long(grib_accessor*, long* val, size_t* len) = 0;
|
||||
virtual int unpack_string(grib_accessor*, char*, size_t* len) = 0;
|
||||
virtual int unpack_string_array(grib_accessor*, char**, size_t* len) = 0;
|
||||
virtual size_t string_length(grib_accessor*) = 0;
|
||||
virtual long byte_count(grib_accessor*) = 0;
|
||||
virtual long byte_offset(grib_accessor*) = 0;
|
||||
virtual long next_offset(grib_accessor*) = 0;
|
||||
virtual int value_count(grib_accessor*, long*) = 0;
|
||||
virtual void destroy(grib_context*, grib_accessor*) = 0;
|
||||
virtual void dump(grib_accessor*, grib_dumper*) = 0;
|
||||
virtual void init(grib_accessor*, const long, grib_arguments*) = 0;
|
||||
virtual void post_init(grib_accessor*) = 0;
|
||||
virtual int notify_change(grib_accessor*, grib_accessor*) = 0;
|
||||
virtual void update_size(grib_accessor*, size_t) = 0;
|
||||
virtual size_t preferred_size(grib_accessor*, int) = 0;
|
||||
virtual void resize(grib_accessor*,size_t) = 0;
|
||||
virtual int nearest_smaller_value (grib_accessor*, double, double*) = 0;
|
||||
virtual grib_accessor* next(grib_accessor*, int) = 0;
|
||||
virtual int compare(grib_accessor*, grib_accessor*) = 0;
|
||||
virtual int unpack_double_element(grib_accessor*, size_t i, double* val) = 0;
|
||||
virtual int unpack_float_element(grib_accessor*, size_t i, float* val) = 0;
|
||||
virtual int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) = 0;
|
||||
virtual int unpack_float_element_set(grib_accessor*, const size_t* index_array, size_t len, float* val_array) = 0;
|
||||
virtual int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) = 0;
|
||||
virtual int clear(grib_accessor*) = 0;
|
||||
virtual grib_accessor* make_clone(grib_accessor*, grib_section*, int*) = 0;
|
||||
grib_accessor* same_; /** < accessors with the same name */
|
||||
long loop_; /** < used in lists */
|
||||
grib_virtual_value* vvalue_; /** < virtual value used when transient flag on **/
|
||||
const char* set_;
|
||||
grib_accessor* attributes_[MAX_ACCESSOR_ATTRIBUTES] = {
|
||||
0,
|
||||
}; /** < attributes are accessors */
|
||||
grib_accessor* parent_as_attribute_;
|
||||
};
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
|
||||
#include "grib_accessor_class_abstract_long_vector.h"
|
||||
|
||||
grib_accessor_class_abstract_long_vector_t _grib_accessor_class_abstract_long_vector{"abstract_long_vector"};
|
||||
grib_accessor_class* grib_accessor_class_abstract_long_vector = &_grib_accessor_class_abstract_long_vector;
|
||||
grib_accessor_abstract_long_vector_t _grib_accessor_abstract_long_vector{};
|
||||
grib_accessor* grib_accessor_abstract_long_vector = &_grib_accessor_abstract_long_vector;
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
class grib_accessor_abstract_long_vector_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in abstract_long_vector */
|
||||
long* v;
|
||||
long pack_index;
|
||||
int number_of_elements;
|
||||
};
|
||||
grib_accessor_abstract_long_vector_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "abstract_long_vector"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; }
|
||||
|
||||
class grib_accessor_class_abstract_long_vector_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_abstract_long_vector_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
//grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; }
|
||||
// TODO(maee): make private
|
||||
long* v_;
|
||||
long pack_index_;
|
||||
int number_of_elements_;
|
||||
};
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
|
||||
#include "grib_accessor_class_abstract_vector.h"
|
||||
|
||||
grib_accessor_class_abstract_vector_t _grib_accessor_class_abstract_vector{"abstract_vector"};
|
||||
grib_accessor_class* grib_accessor_class_abstract_vector = &_grib_accessor_class_abstract_vector;
|
||||
grib_accessor_abstract_vector_t _grib_accessor_abstract_vector{};
|
||||
grib_accessor* grib_accessor_abstract_vector = &_grib_accessor_abstract_vector;
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
class grib_accessor_abstract_vector_t : public grib_accessor_double_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in abstract_vector */
|
||||
double* v;
|
||||
int number_of_elements;
|
||||
};
|
||||
grib_accessor_abstract_vector_t() :
|
||||
grib_accessor_double_t() { class_name_ = "abstract_vector"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; }
|
||||
|
||||
class grib_accessor_class_abstract_vector_t : public grib_accessor_class_double_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_abstract_vector_t(const char* name) : grib_accessor_class_double_t(name) {}
|
||||
// grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; }
|
||||
// TODO(maee): make private
|
||||
double* v_;
|
||||
int number_of_elements_;
|
||||
};
|
||||
|
|
|
@ -11,101 +11,101 @@
|
|||
|
||||
#include "grib_accessor_class_ascii.h"
|
||||
|
||||
grib_accessor_class_ascii_t _grib_accessor_class_ascii{ "ascii" };
|
||||
grib_accessor_class* grib_accessor_class_ascii = &_grib_accessor_class_ascii;
|
||||
grib_accessor_ascii_t _grib_accessor_ascii{};
|
||||
grib_accessor* grib_accessor_ascii = &_grib_accessor_ascii;
|
||||
|
||||
|
||||
void grib_accessor_class_ascii_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_ascii_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
a->length = len;
|
||||
Assert(a->length >= 0);
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
length_ = len;
|
||||
Assert(length_ >= 0);
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_ascii_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t grib_accessor_class_ascii_t::string_length(grib_accessor* a)
|
||||
size_t grib_accessor_ascii_t::string_length()
|
||||
{
|
||||
return a->length;
|
||||
return length_;
|
||||
}
|
||||
|
||||
void grib_accessor_class_ascii_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_ascii_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_string(dumper, a, NULL);
|
||||
grib_dump_string(dumper, this, NULL);
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_ascii_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_STRING;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
int grib_accessor_ascii_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
const size_t alen = a->length;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
const size_t alen = length_;
|
||||
|
||||
if (*len < (alen + 1)) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, alen + 1, *len);
|
||||
class_name_, name_, alen + 1, *len);
|
||||
*len = alen + 1;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
for (i = 0; i < alen; i++)
|
||||
val[i] = hand->buffer->data[a->offset + i];
|
||||
val[i] = hand->buffer->data[offset_ + i];
|
||||
val[i] = 0;
|
||||
*len = i;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::pack_string(grib_accessor* a, const char* val, size_t* len)
|
||||
int grib_accessor_ascii_t::pack_string(const char* val, size_t* len)
|
||||
{
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
const size_t alen = a->length;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
const size_t alen = length_;
|
||||
if (len[0] > (alen + 1)) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"pack_string: Wrong size (%zu) for %s, it contains %ld values",
|
||||
len[0], a->name, a->length + 1);
|
||||
len[0], name_, length_ + 1);
|
||||
len[0] = 0;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < alen; i++) {
|
||||
if (i < len[0])
|
||||
hand->buffer->data[a->offset + i] = val[i];
|
||||
hand->buffer->data[offset_ + i] = val[i];
|
||||
else
|
||||
hand->buffer->data[a->offset + i] = 0;
|
||||
hand->buffer->data[offset_ + i] = 0;
|
||||
}
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::pack_long(grib_accessor* a, const long* v, size_t* len)
|
||||
int grib_accessor_ascii_t::pack_long(const long* v, size_t* len)
|
||||
{
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", a->name);
|
||||
grib_context_log(this->context_, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", name_);
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::pack_double(grib_accessor* a, const double* v, size_t* len)
|
||||
int grib_accessor_ascii_t::pack_double(const double* v, size_t* len)
|
||||
{
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", a->name);
|
||||
grib_context_log(this->context_, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", name_);
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* len)
|
||||
int grib_accessor_ascii_t::unpack_long(long* v, size_t* len)
|
||||
{
|
||||
char val[1024] = {0,};
|
||||
char val[1024] = {
|
||||
0,
|
||||
};
|
||||
size_t l = sizeof(val);
|
||||
size_t i = 0;
|
||||
char* last = NULL;
|
||||
int err = a->unpack_string(val, &l);
|
||||
int err = unpack_string(val, &l);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -122,48 +122,48 @@ int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t*
|
|||
|
||||
*v = strtol(val, &last, 10);
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
|
||||
grib_context_log(this->context_, GRIB_LOG_DEBUG, " Casting string %s to long", name_);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size_t* len)
|
||||
int grib_accessor_ascii_t::unpack_double(double* v, size_t* len)
|
||||
{
|
||||
char val[1024];
|
||||
size_t l = sizeof(val);
|
||||
char* last = NULL;
|
||||
|
||||
int err = a->unpack_string(val, &l);
|
||||
int err = unpack_string(val, &l);
|
||||
if (err) return err;
|
||||
|
||||
*v = strtod(val, &last);
|
||||
|
||||
if (*last == 0) {
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
|
||||
grib_context_log(this->context_, GRIB_LOG_DEBUG, " Casting string %s to long", name_);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", a->name);
|
||||
grib_context_log(this->context_, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", name_);
|
||||
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b)
|
||||
int grib_accessor_ascii_t::compare(grib_accessor* b)
|
||||
{
|
||||
int retval = 0;
|
||||
char* aval = 0;
|
||||
char* bval = 0;
|
||||
int err = 0;
|
||||
|
||||
size_t alen = a->length + 1;
|
||||
size_t blen = b->length + 1;
|
||||
size_t alen = length_ + 1;
|
||||
size_t blen = b->length_ + 1;
|
||||
|
||||
if (alen != blen)
|
||||
return GRIB_COUNT_MISMATCH;
|
||||
|
||||
aval = (char*)grib_context_malloc(a->context, alen * sizeof(char));
|
||||
bval = (char*)grib_context_malloc(b->context, blen * sizeof(char));
|
||||
aval = (char*)grib_context_malloc(context_, alen * sizeof(char));
|
||||
bval = (char*)grib_context_malloc(b->context_, blen * sizeof(char));
|
||||
|
||||
err = a->unpack_string(aval, &alen);
|
||||
err = unpack_string(aval, &alen);
|
||||
if (err) return err;
|
||||
err = b->unpack_string(bval, &blen);
|
||||
if (err) return err;
|
||||
|
@ -172,8 +172,8 @@ int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b)
|
|||
if (!STR_EQUAL(aval, bval))
|
||||
retval = GRIB_STRING_VALUE_MISMATCH;
|
||||
|
||||
grib_context_free(a->context, aval);
|
||||
grib_context_free(b->context, bval);
|
||||
grib_context_free(context_, aval);
|
||||
grib_context_free(b->context_, bval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -16,24 +16,19 @@
|
|||
class grib_accessor_ascii_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in ascii */
|
||||
};
|
||||
|
||||
class grib_accessor_class_ascii_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_ascii_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_ascii_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "ascii"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_ascii_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int pack_string(grib_accessor*, const char*, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
size_t string_length(grib_accessor*) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*, grib_accessor*) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int pack_string(const char*, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
size_t string_length() override;
|
||||
int value_count(long*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*) override;
|
||||
};
|
||||
|
|
|
@ -11,37 +11,34 @@
|
|||
|
||||
#include "grib_accessor_class_bit.h"
|
||||
|
||||
grib_accessor_class_bit_t _grib_accessor_class_bit{ "bit" };
|
||||
grib_accessor_class* grib_accessor_class_bit = &_grib_accessor_class_bit;
|
||||
grib_accessor_bit_t _grib_accessor_bit{};
|
||||
grib_accessor* grib_accessor_bit = &_grib_accessor_bit;
|
||||
|
||||
|
||||
void grib_accessor_class_bit_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bit_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, len, arg);
|
||||
grib_accessor_bit_t* self = (grib_accessor_bit_t*)a;
|
||||
a->length = 0;
|
||||
self->owner = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0);
|
||||
self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1);
|
||||
grib_accessor_long_t::init(len, arg);
|
||||
length_ = 0;
|
||||
owner_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 0);
|
||||
bit_index_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 1);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bit_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bit_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bit_t* self = (grib_accessor_bit_t*)a;
|
||||
int ret = 0;
|
||||
long data = 0;
|
||||
int ret = 0;
|
||||
long data = 0;
|
||||
|
||||
if (*len < 1) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: unpack_long: Wrong size for %s, it contains %d values ", a->name, 1);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bit_t: unpack_long: Wrong size for %s, it contains %d values ", name_, 1);
|
||||
*len = 1;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->owner, &data)) != GRIB_SUCCESS) {
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), owner_, &data)) != GRIB_SUCCESS) {
|
||||
*len = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (data & (1 << self->bit_index))
|
||||
if (data & (1 << bit_index_))
|
||||
*val = 1;
|
||||
else
|
||||
*val = 0;
|
||||
|
@ -50,32 +47,30 @@ int grib_accessor_class_bit_t::unpack_long(grib_accessor* a, long* val, size_t*
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bit_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bit_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bit_t* self = (grib_accessor_bit_t*)a;
|
||||
|
||||
if (*len < 1) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: pack_long: At least one value to pack for %s", a->name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bit_t: pack_long: At least one value to pack for %s", name_);
|
||||
*len = 1;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner);
|
||||
grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(this), owner_);
|
||||
if (!owner) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: Cannot get the owner %s for computing the bit value of %s",
|
||||
self->owner, a->name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bit_t: Cannot get the owner %s for computing the bit value of %s",
|
||||
owner_, name_);
|
||||
*len = 0;
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data;
|
||||
unsigned char* mdata = grib_handle_of_accessor(this)->buffer->data;
|
||||
mdata += owner->byte_offset();
|
||||
/* Note: In the definitions, flagbit numbers go from 7 to 0 (the bit_index), while WMO convention is from 1 to 8 */
|
||||
if (a->context->debug) {
|
||||
if (context_->debug) {
|
||||
/* Print bit positions from 1 (MSB) */
|
||||
fprintf(stderr, "ECCODES DEBUG Setting bit %d in %s to %d\n", 8 - self->bit_index, owner->name, (*val > 0));
|
||||
fprintf(stderr, "ECCODES DEBUG Setting bit %d in %s to %d\n", 8 - bit_index_, owner->name_, (*val > 0));
|
||||
}
|
||||
grib_set_bit(mdata, 7 - self->bit_index, *val > 0);
|
||||
grib_set_bit(mdata, 7 - bit_index_, *val > 0);
|
||||
|
||||
*len = 1;
|
||||
return GRIB_SUCCESS;
|
||||
|
|
|
@ -16,17 +16,14 @@
|
|||
class grib_accessor_bit_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bit */
|
||||
const char* owner;
|
||||
int bit_index;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bit_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bit_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_bit_t() :
|
||||
grib_accessor_long_t() { class_name_ = "bit"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bit_t{}; }
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* owner_;
|
||||
int bit_index_;
|
||||
};
|
||||
|
|
|
@ -11,18 +11,17 @@
|
|||
|
||||
#include "grib_accessor_class_bitmap.h"
|
||||
|
||||
grib_accessor_class_bitmap_t _grib_accessor_class_bitmap{ "bitmap" };
|
||||
grib_accessor_class* grib_accessor_class_bitmap = &_grib_accessor_class_bitmap;
|
||||
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()
|
||||
{
|
||||
long slen = 0;
|
||||
long off = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
long slen = 0;
|
||||
long off = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a;
|
||||
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,68 +29,67 @@ 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);
|
||||
grib_get_block_length(seclen->parent_, &size);
|
||||
slen = size;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("compute_size off=%ld slen=%ld a->offset=%ld\n", (long)off,(long)slen,(long)a->offset);
|
||||
// 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_class_bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bitmap_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_bytes_t::init(a, len, arg);
|
||||
grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
int n = 0;
|
||||
grib_accessor_bytes_t::init(len, arg);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
int n = 0;
|
||||
|
||||
self->tableReference = grib_arguments_get_name(hand, arg, n++);
|
||||
self->missing_value = grib_arguments_get_name(hand, arg, n++);
|
||||
self->offsetbsec = grib_arguments_get_name(hand, arg, n++);
|
||||
self->sLength = grib_arguments_get_name(hand, arg, n++);
|
||||
tableReference_ = grib_arguments_get_name(hand, arg, n++);
|
||||
missing_value_ = grib_arguments_get_name(hand, arg, n++);
|
||||
offsetbsec_ = grib_arguments_get_name(hand, arg, n++);
|
||||
sLength_ = grib_arguments_get_name(hand, arg, n++);
|
||||
|
||||
compute_size(a);
|
||||
compute_size();
|
||||
}
|
||||
|
||||
long grib_accessor_class_bitmap_t::next_offset(grib_accessor* a)
|
||||
long grib_accessor_bitmap_t::next_offset()
|
||||
{
|
||||
return a->byte_offset() + a->byte_count();
|
||||
return byte_offset() + byte_count();
|
||||
}
|
||||
|
||||
void grib_accessor_class_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_bitmap_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
long len = 0;
|
||||
char label[1024];
|
||||
|
||||
a->value_count(&len);
|
||||
value_count(&len);
|
||||
snprintf(label, sizeof(label), "Bitmap of %ld values", len);
|
||||
grib_dump_bytes(dumper, a, label);
|
||||
grib_dump_bytes(dumper, this, label);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bitmap_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
long pos = a->offset * 8;
|
||||
long tlen = 0;
|
||||
const grib_handle* hand = grib_handle_of_accessor(a);
|
||||
long pos = offset_ * 8;
|
||||
long tlen = 0;
|
||||
const grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
int err = a->value_count(&tlen);
|
||||
int err = value_count(&tlen);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (*len < tlen) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", name_, tlen);
|
||||
*len = tlen;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
@ -107,7 +105,7 @@ template <typename T>
|
|||
static int unpack(grib_accessor* a, T* val, size_t* len)
|
||||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
|
||||
long pos = a->offset * 8;
|
||||
long pos = a->offset_ * 8;
|
||||
long tlen;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
|
||||
|
@ -116,7 +114,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return err;
|
||||
|
||||
if (*len < tlen) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
|
||||
grib_context_log(a->context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name_, tlen);
|
||||
*len = tlen;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
@ -128,62 +126,61 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_bitmap_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(a, val, len);
|
||||
return unpack<double>(this, val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_bitmap_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(a, val, len);
|
||||
return unpack<float>(this, val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_bitmap_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
long pos = a->offset * 8;
|
||||
long pos = offset_ * 8;
|
||||
|
||||
pos += idx;
|
||||
*val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, 1);
|
||||
*val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, &pos, 1);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
int grib_accessor_class_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_bitmap_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
unpack_double_element(a, index_array[i], val_array + i);
|
||||
unpack_double_element(index_array[i], val_array + i);
|
||||
}
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
void grib_accessor_class_bitmap_t::update_size(grib_accessor* a, size_t s)
|
||||
void grib_accessor_bitmap_t::update_size(size_t s)
|
||||
{
|
||||
a->length = s;
|
||||
length_ = s;
|
||||
}
|
||||
|
||||
size_t grib_accessor_class_bitmap_t::string_length(grib_accessor* a)
|
||||
size_t grib_accessor_bitmap_t::string_length()
|
||||
{
|
||||
return a->length;
|
||||
return length_;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bitmap_t::unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
int grib_accessor_bitmap_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
const size_t l = a->length;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
const size_t l = length_;
|
||||
|
||||
if (*len < l) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
class_name_, name_, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
for (long i = 0; i < a->length; i++) {
|
||||
val[i] = hand->buffer->data[a->offset + i];
|
||||
for (long i = 0; i < length_; i++) {
|
||||
val[i] = hand->buffer->data[offset_ + i];
|
||||
}
|
||||
|
||||
*len = a->length;
|
||||
*len = length_;
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -16,27 +16,28 @@
|
|||
class grib_accessor_bitmap_t : public grib_accessor_bytes_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bitmap */
|
||||
const char* tableReference;
|
||||
const char* missing_value;
|
||||
const char* offsetbsec;
|
||||
const char* sLength;
|
||||
};
|
||||
grib_accessor_bitmap_t() :
|
||||
grib_accessor_bytes_t() { class_name_ = "bitmap"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bitmap_t{}; }
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
size_t string_length() override;
|
||||
long next_offset() override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
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;
|
||||
|
||||
class grib_accessor_class_bitmap_t : public grib_accessor_class_bytes_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bitmap_t(const char* name) : grib_accessor_class_bytes_t(name) {}
|
||||
//grib_accessor* create_empty_accessor() override { return new grib_accessor_bitmap_t{}; }
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
size_t string_length(grib_accessor*) override;
|
||||
long next_offset(grib_accessor*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
void update_size(grib_accessor*, size_t) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
protected:
|
||||
const char* missing_value_;
|
||||
|
||||
private:
|
||||
const char* tableReference_;
|
||||
const char* offsetbsec_;
|
||||
const char* sLength_;
|
||||
|
||||
void compute_size();
|
||||
};
|
||||
|
|
|
@ -11,55 +11,53 @@
|
|||
|
||||
#include "grib_accessor_class_bits.h"
|
||||
|
||||
grib_accessor_class_bits_t _grib_accessor_class_bits{ "bits" };
|
||||
grib_accessor_class* grib_accessor_class_bits = &_grib_accessor_class_bits;
|
||||
grib_accessor_bits_t _grib_accessor_bits{};
|
||||
grib_accessor* grib_accessor_bits = &_grib_accessor_bits;
|
||||
|
||||
|
||||
void grib_accessor_class_bits_t::init(grib_accessor* a, const long l, grib_arguments* c)
|
||||
void grib_accessor_bits_t::init(const long l, grib_arguments* c)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, l, c);
|
||||
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_expression* e = NULL;
|
||||
int n = 0;
|
||||
grib_accessor_gen_t::init(l, c);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
grib_expression* e = NULL;
|
||||
int n = 0;
|
||||
referenceValue_ = 0;
|
||||
|
||||
self->argument = grib_arguments_get_name(hand, c, n++);
|
||||
self->start = grib_arguments_get_long(hand, c, n++);
|
||||
self->len = grib_arguments_get_long(hand, c, n++);
|
||||
e = grib_arguments_get_expression(hand, c, n++);
|
||||
argument_ = grib_arguments_get_name(hand, c, n++);
|
||||
start_ = grib_arguments_get_long(hand, c, n++);
|
||||
len_ = grib_arguments_get_long(hand, c, n++);
|
||||
e = grib_arguments_get_expression(hand, c, n++);
|
||||
if (e) {
|
||||
grib_expression_evaluate_double(hand, e, &(self->referenceValue));
|
||||
self->referenceValuePresent = 1;
|
||||
grib_expression_evaluate_double(hand, e, &(referenceValue_));
|
||||
referenceValuePresent_ = 1;
|
||||
}
|
||||
else {
|
||||
self->referenceValuePresent = 0;
|
||||
referenceValuePresent_ = 0;
|
||||
}
|
||||
self->scale = 1;
|
||||
if (self->referenceValuePresent) {
|
||||
self->scale = grib_arguments_get_double(hand, c, n++);
|
||||
scale_ = 1;
|
||||
if (referenceValuePresent_) {
|
||||
scale_ = grib_arguments_get_double(hand, c, n++);
|
||||
}
|
||||
|
||||
Assert(self->len <= sizeof(long) * 8);
|
||||
Assert(len_ <= sizeof(long) * 8);
|
||||
|
||||
a->length = 0;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bits_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
|
||||
grib_accessor* x = NULL;
|
||||
unsigned char* p = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_accessor* x = NULL;
|
||||
unsigned char* p = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
long start, length;
|
||||
int ret = 0;
|
||||
|
||||
if (*len < 1)
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
|
||||
start = self->start;
|
||||
length = self->len;
|
||||
start = start_;
|
||||
length = len_;
|
||||
|
||||
x = grib_find_accessor(grib_handle_of_accessor(a), self->argument);
|
||||
x = grib_find_accessor(grib_handle_of_accessor(this), argument_);
|
||||
if (!x)
|
||||
return GRIB_NOT_FOUND;
|
||||
|
||||
|
@ -71,96 +69,93 @@ int grib_accessor_class_bits_t::unpack_long(grib_accessor* a, long* val, size_t*
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_bits_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
|
||||
grib_accessor* x = NULL;
|
||||
unsigned char* p = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_accessor* x = NULL;
|
||||
unsigned char* p = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
long start, length;
|
||||
int ret = 0;
|
||||
|
||||
if (*len < 1)
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
|
||||
start = self->start;
|
||||
length = self->len;
|
||||
start = start_;
|
||||
length = len_;
|
||||
|
||||
x = grib_find_accessor(grib_handle_of_accessor(a), self->argument);
|
||||
x = grib_find_accessor(grib_handle_of_accessor(this), argument_);
|
||||
if (!x)
|
||||
return GRIB_NOT_FOUND;
|
||||
|
||||
p = h->buffer->data + x->byte_offset();
|
||||
*val = grib_decode_unsigned_long(p, &start, length);
|
||||
|
||||
*val = ((long)*val + self->referenceValue) / self->scale;
|
||||
*val = ((long)*val + referenceValue_) / scale_;
|
||||
|
||||
*len = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_bits_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
|
||||
grib_accessor* x = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
unsigned char* p = NULL;
|
||||
grib_accessor* x = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
unsigned char* p = NULL;
|
||||
long start, length, lval;
|
||||
|
||||
if (*len != 1)
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
|
||||
start = self->start;
|
||||
length = self->len;
|
||||
start = start_;
|
||||
length = len_;
|
||||
|
||||
x = grib_find_accessor(grib_handle_of_accessor(a), self->argument);
|
||||
x = grib_find_accessor(grib_handle_of_accessor(this), argument_);
|
||||
if (!x)
|
||||
return GRIB_NOT_FOUND;
|
||||
|
||||
p = h->buffer->data + x->byte_offset();
|
||||
lval = round(*val * self->scale) - self->referenceValue;
|
||||
lval = round(*val * scale_) - referenceValue_;
|
||||
return grib_encode_unsigned_longb(p, lval, &start, length);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bits_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
|
||||
grib_accessor* x = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
unsigned char* p = NULL;
|
||||
grib_accessor* x = NULL;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
unsigned char* p = NULL;
|
||||
long start, length, maxval;
|
||||
|
||||
if (*len != 1)
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
|
||||
if (get_native_type(a) == GRIB_TYPE_DOUBLE) {
|
||||
if (get_native_type() == GRIB_TYPE_DOUBLE) {
|
||||
/* ECC-402 */
|
||||
const double dVal = (double)(*val);
|
||||
return pack_double(a, &dVal, len);
|
||||
return pack_double(&dVal, len);
|
||||
}
|
||||
|
||||
start = self->start;
|
||||
length = self->len;
|
||||
start = start_;
|
||||
length = len_;
|
||||
|
||||
x = grib_find_accessor(grib_handle_of_accessor(a), self->argument);
|
||||
x = grib_find_accessor(grib_handle_of_accessor(this), argument_);
|
||||
if (!x)
|
||||
return GRIB_NOT_FOUND;
|
||||
|
||||
/* Check the input value */
|
||||
if (*val < 0) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "key=%s: value cannot be negative", a->name);
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "key=%s: value cannot be negative", name_);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
const long numbits = (x->length) * 8;
|
||||
const long numbits = (x->length_) * 8;
|
||||
if (start + length > numbits) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR,
|
||||
"grib_accessor_class_bits::pack_long: key=%s (x=%s): "
|
||||
"grib_accessor_bits::pack_long: key=%s (x=%s): "
|
||||
"Invalid start/length. x->length=%ld, start=%ld, length=%ld",
|
||||
a->name, x->name, numbits, start, length);
|
||||
name_, x->name_, numbits, start, length);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +165,7 @@ int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, siz
|
|||
if (*val > maxval) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR,
|
||||
"key=%s: Trying to encode value of %ld but the maximum allowable value is %ld (number of bits=%ld)",
|
||||
a->name, *val, maxval, length);
|
||||
name_, *val, maxval, length);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
|
||||
|
@ -178,64 +173,63 @@ int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, siz
|
|||
return grib_encode_unsigned_longb(p, *val, &start, length);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bits_t::get_native_type()
|
||||
{
|
||||
int type = GRIB_TYPE_BYTES;
|
||||
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
|
||||
int type = GRIB_TYPE_BYTES;
|
||||
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE)
|
||||
type = GRIB_TYPE_STRING;
|
||||
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE)
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE)
|
||||
type = GRIB_TYPE_LONG;
|
||||
|
||||
if (self->referenceValuePresent)
|
||||
if (referenceValuePresent_)
|
||||
type = GRIB_TYPE_DOUBLE;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||
int grib_accessor_bits_t::unpack_string(char* v, size_t* len)
|
||||
{
|
||||
int ret = 0;
|
||||
double dval = 0;
|
||||
long lval = 0;
|
||||
size_t llen = 1;
|
||||
|
||||
switch (get_native_type(a)) {
|
||||
switch (get_native_type()) {
|
||||
case GRIB_TYPE_LONG:
|
||||
ret = unpack_long(a, &lval, &llen);
|
||||
ret = unpack_long(&lval, &llen);
|
||||
snprintf(v, 64, "%ld", lval);
|
||||
*len = strlen(v);
|
||||
break;
|
||||
|
||||
case GRIB_TYPE_DOUBLE:
|
||||
ret = unpack_double(a, &dval, &llen);
|
||||
ret = unpack_double(&dval, &llen);
|
||||
snprintf(v, 64, "%g", dval);
|
||||
*len = strlen(v);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = grib_accessor_class_gen_t::unpack_string(a, v, len);
|
||||
ret = grib_accessor_gen_t::unpack_string(v, len);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
long grib_accessor_class_bits_t::byte_count(grib_accessor* a)
|
||||
long grib_accessor_bits_t::byte_count()
|
||||
{
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length);
|
||||
return a->length;
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "byte_count of %s = %ld", name_, length_);
|
||||
return length_;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len)
|
||||
int grib_accessor_bits_t::unpack_bytes(unsigned char* buffer, size_t* len)
|
||||
{
|
||||
if (*len < a->length) {
|
||||
*len = a->length;
|
||||
if (*len < length_) {
|
||||
*len = length_;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
*len = a->length;
|
||||
*len = length_;
|
||||
|
||||
memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len);
|
||||
memcpy(buffer, grib_handle_of_accessor(this)->buffer->data + offset_, *len);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -16,27 +16,24 @@
|
|||
class grib_accessor_bits_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bits */
|
||||
const char* argument;
|
||||
long start;
|
||||
long len;
|
||||
double referenceValue;
|
||||
double referenceValuePresent;
|
||||
double scale;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bits_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bits_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bits_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bits"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bits_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
long byte_count(grib_accessor*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_bytes(unsigned char*, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
long byte_count() override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* argument_;
|
||||
long start_;
|
||||
long len_;
|
||||
double referenceValue_;
|
||||
double referenceValuePresent_;
|
||||
double scale_;
|
||||
};
|
||||
|
|
|
@ -11,63 +11,57 @@
|
|||
|
||||
#include "grib_accessor_class_bits_per_value.h"
|
||||
|
||||
grib_accessor_class_bits_per_value_t _grib_accessor_class_bits_per_value{ "bits_per_value" };
|
||||
grib_accessor_class* grib_accessor_class_bits_per_value = &_grib_accessor_class_bits_per_value;
|
||||
grib_accessor_bits_per_value_t _grib_accessor_bits_per_value{};
|
||||
grib_accessor* grib_accessor_bits_per_value = &_grib_accessor_bits_per_value;
|
||||
|
||||
|
||||
void grib_accessor_class_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* args)
|
||||
void grib_accessor_bits_per_value_t::init(const long l, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, l, args);
|
||||
int n = 0;
|
||||
grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a;
|
||||
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
a->length = 0;
|
||||
grib_accessor_long_t::init(l, args);
|
||||
int n = 0;
|
||||
values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
bits_per_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bits_per_value_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a;
|
||||
int ret = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
int ret = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
|
||||
if ((ret = grib_get_long_internal(h, self->bits_per_value, val)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(h, bits_per_value_, val)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
*len = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bits_per_value_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a;
|
||||
|
||||
double* values = NULL;
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_context* c = context_;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
values = (double*)grib_context_malloc(c, size * sizeof(double));
|
||||
if (!values)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) {
|
||||
if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = grib_set_long_internal(h, self->bits_per_value, *val)) != GRIB_SUCCESS) {
|
||||
if ((ret = grib_set_long_internal(h, bits_per_value_, *val)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) {
|
||||
if ((ret = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -16,17 +16,14 @@
|
|||
class grib_accessor_bits_per_value_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bits_per_value */
|
||||
const char* values;
|
||||
const char* bits_per_value;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bits_per_value_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bits_per_value_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_bits_per_value_t() :
|
||||
grib_accessor_long_t() { class_name_ = "bits_per_value"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bits_per_value_t{}; }
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* values_;
|
||||
const char* bits_per_value_;
|
||||
};
|
||||
|
|
|
@ -11,37 +11,36 @@
|
|||
|
||||
#include "grib_accessor_class_blob.h"
|
||||
|
||||
grib_accessor_class_blob_t _grib_accessor_class_blob{ "blob" };
|
||||
grib_accessor_class* grib_accessor_class_blob = &_grib_accessor_class_blob;
|
||||
grib_accessor_blob_t _grib_accessor_blob{};
|
||||
grib_accessor* grib_accessor_blob = &_grib_accessor_blob;
|
||||
|
||||
|
||||
void grib_accessor_class_blob_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_blob_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
grib_get_long_internal(grib_handle_of_accessor(a),
|
||||
grib_arguments_get_name(a->parent->h, arg, 0), &a->length);
|
||||
Assert(a->length >= 0);
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
grib_get_long_internal(grib_handle_of_accessor(this),
|
||||
grib_arguments_get_name(parent_->h, arg, 0), &length_);
|
||||
Assert(length_ >= 0);
|
||||
}
|
||||
|
||||
int grib_accessor_class_blob_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_blob_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_BYTES;
|
||||
}
|
||||
|
||||
int grib_accessor_class_blob_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len)
|
||||
int grib_accessor_blob_t::unpack_bytes(unsigned char* buffer, size_t* len)
|
||||
{
|
||||
if (*len < (size_t)a->length) {
|
||||
*len = a->length;
|
||||
if (*len < (size_t)length_) {
|
||||
*len = length_;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
*len = a->length;
|
||||
*len = length_;
|
||||
|
||||
memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len);
|
||||
memcpy(buffer, grib_handle_of_accessor(this)->buffer->data + offset_, *len);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
void grib_accessor_class_blob_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_blob_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_bytes(dumper, a, NULL);
|
||||
grib_dump_bytes(dumper, this, NULL);
|
||||
}
|
||||
|
|
|
@ -16,16 +16,11 @@
|
|||
class grib_accessor_blob_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in blob */
|
||||
};
|
||||
|
||||
class grib_accessor_class_blob_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_blob_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_blob_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "blob"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_blob_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int unpack_bytes(unsigned char*, size_t* len) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
};
|
||||
|
|
|
@ -11,35 +11,32 @@
|
|||
|
||||
#include "grib_accessor_class_budgdate.h"
|
||||
|
||||
grib_accessor_class_budgdate_t _grib_accessor_class_budgdate{ "budgdate" };
|
||||
grib_accessor_class* grib_accessor_class_budgdate = &_grib_accessor_class_budgdate;
|
||||
grib_accessor_budgdate_t _grib_accessor_budgdate{};
|
||||
grib_accessor* grib_accessor_budgdate = &_grib_accessor_budgdate;
|
||||
|
||||
|
||||
void grib_accessor_class_budgdate_t::init(grib_accessor* a, const long l, grib_arguments* c)
|
||||
void grib_accessor_budgdate_t::init(const long l, grib_arguments* c)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, l, c);
|
||||
grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a;
|
||||
int n = 0;
|
||||
grib_accessor_long_t::init(l, c);
|
||||
int n = 0;
|
||||
|
||||
self->year = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
self->month = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
year_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
|
||||
month_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
|
||||
day_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
|
||||
}
|
||||
|
||||
int grib_accessor_class_budgdate_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_budgdate_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
int ret = 0;
|
||||
grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a;
|
||||
int ret = 0;
|
||||
|
||||
long year = 0;
|
||||
long month = 0;
|
||||
long day = 0;
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), day_, &day)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), month_, &month)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), year_, &year)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (*len < 1)
|
||||
|
@ -51,11 +48,10 @@ int grib_accessor_class_budgdate_t::unpack_long(grib_accessor* a, long* val, siz
|
|||
}
|
||||
|
||||
/* TODO: Check for a valid date */
|
||||
int grib_accessor_class_budgdate_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_budgdate_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
int ret = 0;
|
||||
long v = val[0];
|
||||
grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a;
|
||||
int ret = 0;
|
||||
long v = val[0];
|
||||
|
||||
long year = 0;
|
||||
long month = 0;
|
||||
|
@ -74,11 +70,11 @@ int grib_accessor_class_budgdate_t::pack_long(grib_accessor* a, const long* val,
|
|||
|
||||
Assert(year < 255);
|
||||
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), day_, day)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), month_, month)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), year_, year)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -16,18 +16,15 @@
|
|||
class grib_accessor_budgdate_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in budgdate */
|
||||
const char* year;
|
||||
const char* month;
|
||||
const char* day;
|
||||
};
|
||||
|
||||
class grib_accessor_class_budgdate_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_budgdate_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_budgdate_t() :
|
||||
grib_accessor_long_t() { class_name_ = "budgdate"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_budgdate_t{}; }
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* year_;
|
||||
const char* month_;
|
||||
const char* day_;
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -11,79 +11,135 @@
|
|||
#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
|
||||
{
|
||||
public:
|
||||
const char* bufrDataEncodedName;
|
||||
const char* numberOfSubsetsName;
|
||||
const char* expandedDescriptorsName;
|
||||
const char* flagsName;
|
||||
const char* unitsName;
|
||||
const char* elementsDescriptorsIndexName;
|
||||
const char* compressedDataName;
|
||||
bufr_descriptors_array* expanded;
|
||||
grib_accessor* expandedAccessor;
|
||||
int* canBeMissing;
|
||||
long numberOfSubsets;
|
||||
long compressedData;
|
||||
grib_vdarray* numericValues;
|
||||
grib_vsarray* stringValues;
|
||||
grib_viarray* elementsDescriptorsIndex;
|
||||
int do_decode;
|
||||
int bitmapStartElementsDescriptorsIndex;
|
||||
int bitmapCurrentElementsDescriptorsIndex;
|
||||
int bitmapSize;
|
||||
int bitmapStart;
|
||||
int bitmapCurrent;
|
||||
grib_accessors_list* dataAccessors;
|
||||
int unpackMode;
|
||||
int bitsToEndData;
|
||||
grib_section* dataKeys;
|
||||
double* inputBitmap;
|
||||
int nInputBitmap;
|
||||
int iInputBitmap;
|
||||
long* inputReplications;
|
||||
int nInputReplications;
|
||||
int iInputReplications;
|
||||
long* inputExtendedReplications;
|
||||
int nInputExtendedReplications;
|
||||
int iInputExtendedReplications;
|
||||
long* inputShortReplications;
|
||||
int nInputShortReplications;
|
||||
int iInputShortReplications;
|
||||
grib_iarray* iss_list;
|
||||
grib_trie_with_rank* dataAccessorsTrie;
|
||||
grib_sarray* tempStrings;
|
||||
grib_vdarray* tempDoubleValues;
|
||||
int change_ref_value_operand;
|
||||
size_t refValListSize;
|
||||
long* refValList;
|
||||
long refValIndex;
|
||||
bufr_tableb_override* tableb_override;
|
||||
int set_to_missing_if_out_of_range;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_data_array_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_data_array_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bufr_data_array_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_data_array"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_data_array_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
long byte_count(grib_accessor*) override;
|
||||
long byte_offset(grib_accessor*) override;
|
||||
long next_offset(grib_accessor*) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
long byte_count() override;
|
||||
long byte_offset() override;
|
||||
long next_offset() override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
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_;
|
||||
const char* flagsName_;
|
||||
const char* unitsName_;
|
||||
const char* elementsDescriptorsIndexName_;
|
||||
const char* compressedDataName_;
|
||||
bufr_descriptors_array* expanded_;
|
||||
grib_accessor_expanded_descriptors_t* expandedAccessor_;
|
||||
int* canBeMissing_;
|
||||
long numberOfSubsets_;
|
||||
long compressedData_;
|
||||
grib_vdarray* numericValues_;
|
||||
grib_vsarray* stringValues_;
|
||||
grib_viarray* elementsDescriptorsIndex_;
|
||||
int do_decode_;
|
||||
int bitmapStartElementsDescriptorsIndex_;
|
||||
int bitmapCurrentElementsDescriptorsIndex_;
|
||||
int bitmapSize_;
|
||||
int bitmapStart_;
|
||||
int bitmapCurrent_;
|
||||
grib_accessors_list* dataAccessors_;
|
||||
int unpackMode_;
|
||||
int bitsToEndData_;
|
||||
grib_section* dataKeys_;
|
||||
double* inputBitmap_;
|
||||
int nInputBitmap_;
|
||||
int iInputBitmap_;
|
||||
long* inputReplications_;
|
||||
int nInputReplications_;
|
||||
int iInputReplications_;
|
||||
long* inputExtendedReplications_;
|
||||
int nInputExtendedReplications_;
|
||||
int iInputExtendedReplications_;
|
||||
long* inputShortReplications_;
|
||||
int nInputShortReplications_;
|
||||
int iInputShortReplications_;
|
||||
grib_iarray* iss_list_;
|
||||
grib_trie_with_rank* dataAccessorsTrie_;
|
||||
grib_sarray* tempStrings_;
|
||||
grib_vdarray* tempDoubleValues_;
|
||||
int change_ref_value_operand_;
|
||||
size_t refValListSize_;
|
||||
long* refValList_;
|
||||
long refValIndex_;
|
||||
bufr_tableb_override* tableb_override_;
|
||||
int set_to_missing_if_out_of_range_;
|
||||
|
||||
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*);
|
||||
};
|
||||
|
||||
grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a);
|
||||
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a);
|
||||
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a);
|
||||
void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode);
|
||||
|
||||
|
|
|
@ -10,15 +10,14 @@
|
|||
|
||||
#include "grib_accessor_class_bufr_data_element.h"
|
||||
|
||||
grib_accessor_class_bufr_data_element_t _grib_accessor_class_bufr_data_element{ "bufr_data_element" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_data_element = &_grib_accessor_class_bufr_data_element;
|
||||
grib_accessor_bufr_data_element_t _grib_accessor_bufr_data_element{};
|
||||
grib_accessor* grib_accessor_bufr_data_element = &_grib_accessor_bufr_data_element;
|
||||
|
||||
grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor* a, grib_section* s, int* err)
|
||||
grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, int* err)
|
||||
{
|
||||
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 = {
|
||||
|
@ -28,34 +27,33 @@ grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor
|
|||
creator.name_space = (char*)"";
|
||||
creator.set = 0;
|
||||
creator.name = (char*)"unknown";
|
||||
if (strcmp(a->cclass->name, "bufr_data_element")) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL, "wrong accessor type: '%s' should be '%s'", a->cclass->name, "bufr_data_element");
|
||||
if (strcmp(class_name_, "bufr_data_element")) {
|
||||
grib_context_log(context_, GRIB_LOG_FATAL, "wrong accessor type: '%s' should be '%s'", class_name_, "bufr_data_element");
|
||||
}
|
||||
*err = 0;
|
||||
|
||||
the_clone = grib_accessor_factory(s, &creator, 0, NULL);
|
||||
copied_name = grib_context_strdup(a->context, a->name);
|
||||
the_clone->name = copied_name;
|
||||
elementAccessor = (grib_accessor_bufr_data_element_t*)the_clone;
|
||||
self = (grib_accessor_bufr_data_element_t*)a;
|
||||
the_clone->flags = a->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->cname = copied_name; /* ECC-765 */
|
||||
the_clone = grib_accessor_factory(s, &creator, 0, NULL);
|
||||
copied_name = grib_context_strdup(context_, name_);
|
||||
the_clone->name_ = copied_name;
|
||||
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_ = 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;
|
||||
while (a->attributes[i]) {
|
||||
attribute = a->attributes[i]->clone(s, err);
|
||||
/* attribute->parent=a->parent; */
|
||||
while (attributes_[i]) {
|
||||
attribute = attributes_[i]->clone(s, err);
|
||||
/* attribute->parent=parent_ ; */
|
||||
the_clone->add_attribute(attribute, 0);
|
||||
i++;
|
||||
}
|
||||
|
@ -63,152 +61,102 @@ grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor
|
|||
return the_clone;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_index(grib_accessor* a, long index)
|
||||
void grib_accessor_bufr_data_element_t::init(const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
self->index = index;
|
||||
grib_accessor_gen_t::init(len, params);
|
||||
length_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_BUFR_DATA;
|
||||
/* flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; */
|
||||
index_ = 0;
|
||||
type_ = 0;
|
||||
compressedData_ = 0;
|
||||
subsetNumber_ = 0;
|
||||
numberOfSubsets_ = 0;
|
||||
descriptors_ = NULL;
|
||||
numericValues_ = NULL;
|
||||
stringValues_ = NULL;
|
||||
elementsDescriptorsIndex_ = NULL;
|
||||
cname_ = NULL;
|
||||
}
|
||||
|
||||
void accessor_bufr_data_element_set_type(grib_accessor* a, int type)
|
||||
void grib_accessor_bufr_data_element_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
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_class_bufr_data_element_t::init(grib_accessor* a, const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, params);
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_BUFR_DATA;
|
||||
/* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */
|
||||
self->cname = NULL;
|
||||
}
|
||||
|
||||
void grib_accessor_class_bufr_data_element_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
{
|
||||
int type = get_native_type(a);
|
||||
int type = get_native_type();
|
||||
|
||||
switch (type) {
|
||||
case GRIB_TYPE_LONG:
|
||||
grib_dump_long(dumper, a, NULL);
|
||||
grib_dump_long(dumper, this, NULL);
|
||||
break;
|
||||
case GRIB_TYPE_DOUBLE:
|
||||
grib_dump_values(dumper, a);
|
||||
grib_dump_values(dumper, this);
|
||||
break;
|
||||
case GRIB_TYPE_STRING:
|
||||
grib_dump_string_array(dumper, a, NULL);
|
||||
grib_dump_string_array(dumper, this, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::unpack_string_array(grib_accessor* a, char** val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::unpack_string_array(char** val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
|
||||
int ret = 0, idx = 0;
|
||||
size_t count = 0, i = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->compressedData) {
|
||||
DEBUG_ASSERT(self->index < self->numericValues->n);
|
||||
idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets;
|
||||
DEBUG_ASSERT(idx < self->stringValues->n);
|
||||
count = grib_sarray_used_size(self->stringValues->v[idx]);
|
||||
if (compressedData_) {
|
||||
DEBUG_ASSERT(index_ < numericValues_->n);
|
||||
idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_;
|
||||
DEBUG_ASSERT(idx < stringValues_->n);
|
||||
count = grib_sarray_used_size(stringValues_->v[idx]);
|
||||
for (i = 0; i < count; i++) {
|
||||
val[i] = grib_context_strdup(c, self->stringValues->v[idx]->v[i]);
|
||||
val[i] = grib_context_strdup(c, stringValues_->v[idx]->v[i]);
|
||||
}
|
||||
*len = count;
|
||||
}
|
||||
else {
|
||||
DEBUG_ASSERT(self->subsetNumber < self->numericValues->n);
|
||||
DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n);
|
||||
idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1;
|
||||
val[0] = grib_context_strdup(c, self->stringValues->v[idx]->v[0]);
|
||||
DEBUG_ASSERT(subsetNumber_ < numericValues_->n);
|
||||
DEBUG_ASSERT(index_ < numericValues_->v[subsetNumber_]->n);
|
||||
idx = (int)numericValues_->v[subsetNumber_]->v[index_] / 1000 - 1;
|
||||
val[0] = grib_context_strdup(c, stringValues_->v[idx]->v[0]);
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::pack_string_array(grib_accessor* a, const char** v, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::pack_string_array(const char** v, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
|
||||
int ret = GRIB_SUCCESS, idx = 0;
|
||||
size_t i = 0;
|
||||
char* s = NULL;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->compressedData) {
|
||||
idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets;
|
||||
if (*len != 1 && *len != (size_t)self->numberOfSubsets) {
|
||||
if (compressedData_) {
|
||||
idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_;
|
||||
if (*len != 1 && *len != (size_t)numberOfSubsets_) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld strings provided but expected %ld (=number of subsets)",
|
||||
self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[idx]]->shortName, *len, self->numberOfSubsets);
|
||||
descriptors_->v[elementsDescriptorsIndex_->v[0]->v[idx]]->shortName, *len, numberOfSubsets_);
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
grib_sarray_delete_content(c, self->stringValues->v[idx]); /* ECC-1172 */
|
||||
grib_sarray_delete(c, self->stringValues->v[idx]);
|
||||
self->stringValues->v[idx] = grib_sarray_new(c, *len, 1);
|
||||
grib_sarray_delete_content(c, stringValues_->v[idx]); /* ECC-1172 */
|
||||
grib_sarray_delete(c, stringValues_->v[idx]);
|
||||
stringValues_->v[idx] = grib_sarray_new(c, *len, 1);
|
||||
for (i = 0; i < *len; i++) {
|
||||
s = grib_context_strdup(c, v[i]);
|
||||
grib_sarray_push(c, self->stringValues->v[idx], s);
|
||||
grib_sarray_push(c, stringValues_->v[idx], s);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// ECC-1623
|
||||
if (*len != (size_t)self->numberOfSubsets) {
|
||||
if (*len != (size_t)numberOfSubsets_) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR,
|
||||
"Number of values mismatch for '%s': %zu strings provided but expected %ld (=number of subsets)",
|
||||
a->name, *len, self->numberOfSubsets);
|
||||
name_, *len, numberOfSubsets_);
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
}
|
||||
for (i = 0; i < *len; i++) {
|
||||
// idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1;
|
||||
idx = (int)self->numericValues->v[i]->v[self->index] / 1000 - 1;
|
||||
self->stringValues->v[idx]->v[0] = strdup(v[i]);
|
||||
// idx = (int)numericValues->v[subsetNumber]->v[index_ ] / 1000 - 1;
|
||||
idx = (int)numericValues_->v[i]->v[index_] / 1000 - 1;
|
||||
stringValues_->v[idx]->v[0] = strdup(v[i]);
|
||||
}
|
||||
*len = 1;
|
||||
}
|
||||
|
@ -216,20 +164,21 @@ int grib_accessor_class_bufr_data_element_t::pack_string_array(grib_accessor* a,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
char* str = NULL;
|
||||
char* p = 0;
|
||||
size_t slen = 0;
|
||||
double dval = 0;
|
||||
size_t dlen = 1;
|
||||
char* str = NULL;
|
||||
char* p = 0;
|
||||
size_t slen = 0;
|
||||
double dval = 0;
|
||||
size_t dlen = 1;
|
||||
int idx = 0, err = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->type != BUFR_DESCRIPTOR_TYPE_STRING) {
|
||||
char sval[32] = {0,};
|
||||
err = unpack_double(a, &dval, &dlen);
|
||||
if (type_ != BUFR_DESCRIPTOR_TYPE_STRING) {
|
||||
char sval[32] = {
|
||||
0,
|
||||
};
|
||||
err = unpack_double(&dval, &dlen);
|
||||
if (err) return err;
|
||||
snprintf(sval, sizeof(sval), "%g", dval);
|
||||
slen = strlen(sval);
|
||||
|
@ -239,20 +188,20 @@ int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, cha
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
if (self->compressedData) {
|
||||
DEBUG_ASSERT(self->index < self->numericValues->n);
|
||||
idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets;
|
||||
if (compressedData_) {
|
||||
DEBUG_ASSERT(index_ < numericValues_->n);
|
||||
idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_;
|
||||
if (idx < 0)
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]);
|
||||
str = grib_context_strdup(c, stringValues_->v[idx]->v[0]);
|
||||
}
|
||||
else {
|
||||
DEBUG_ASSERT(self->subsetNumber < self->numericValues->n);
|
||||
idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1;
|
||||
DEBUG_ASSERT(subsetNumber_ < numericValues_->n);
|
||||
idx = (int)numericValues_->v[subsetNumber_]->v[index_] / 1000 - 1;
|
||||
if (idx < 0)
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
DEBUG_ASSERT(idx < self->stringValues->n);
|
||||
str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]);
|
||||
DEBUG_ASSERT(idx < stringValues_->n);
|
||||
str = grib_context_strdup(c, stringValues_->v[idx]->v[0]);
|
||||
}
|
||||
|
||||
if (str == NULL || strlen(str) == 0) {
|
||||
|
@ -285,188 +234,180 @@ int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, cha
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::pack_string(grib_accessor* a, const char* val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::pack_string(const char* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
|
||||
int ret = GRIB_SUCCESS, idx = 0;
|
||||
char* s = NULL;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->compressedData) {
|
||||
idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets;
|
||||
if (compressedData_) {
|
||||
idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_;
|
||||
}
|
||||
else {
|
||||
idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1;
|
||||
idx = (int)numericValues_->v[subsetNumber_]->v[index_] / 1000 - 1;
|
||||
}
|
||||
grib_sarray_delete_content(c, self->stringValues->v[idx]); /* ECC-1172 */
|
||||
grib_sarray_delete(c, self->stringValues->v[idx]);
|
||||
self->stringValues->v[idx] = grib_sarray_new(c, 1, 1);
|
||||
s = grib_context_strdup(c, val);
|
||||
grib_sarray_push(c, self->stringValues->v[idx], s);
|
||||
grib_sarray_delete_content(c, stringValues_->v[idx]); /* ECC-1172 */
|
||||
grib_sarray_delete(c, stringValues_->v[idx]);
|
||||
stringValues_->v[idx] = grib_sarray_new(c, 1, 1);
|
||||
s = grib_context_strdup(c, val);
|
||||
grib_sarray_push(c, stringValues_->v[idx], s);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int ret = GRIB_SUCCESS;
|
||||
int ret = GRIB_SUCCESS;
|
||||
long count = 0, i = 0;
|
||||
|
||||
value_count(a, &count);
|
||||
value_count(&count);
|
||||
|
||||
if (*len < (size_t)count)
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
if (self->compressedData) {
|
||||
if (compressedData_) {
|
||||
for (i = 0; i < count; i++) {
|
||||
DEBUG_ASSERT(self->index < self->numericValues->n);
|
||||
DEBUG_ASSERT(i < self->numericValues->v[self->index]->n);
|
||||
val[i] = self->numericValues->v[self->index]->v[i] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->index]->v[i];
|
||||
DEBUG_ASSERT(index_ < numericValues_->n);
|
||||
DEBUG_ASSERT(i < numericValues_->v[index_]->n);
|
||||
val[i] = numericValues_->v[index_]->v[i] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)numericValues_->v[index_]->v[i];
|
||||
}
|
||||
*len = count;
|
||||
}
|
||||
else {
|
||||
DEBUG_ASSERT(self->subsetNumber < self->numericValues->n);
|
||||
DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n);
|
||||
val[0] = self->numericValues->v[self->subsetNumber]->v[self->index] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->subsetNumber]->v[self->index];
|
||||
DEBUG_ASSERT(subsetNumber_ < numericValues_->n);
|
||||
DEBUG_ASSERT(index_ < numericValues_->v[subsetNumber_]->n);
|
||||
val[0] = numericValues_->v[subsetNumber_]->v[index_] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)numericValues_->v[subsetNumber_]->v[index_];
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int ret = GRIB_SUCCESS;
|
||||
int ret = GRIB_SUCCESS;
|
||||
long count = 0, i = 0;
|
||||
|
||||
value_count(a, &count);
|
||||
value_count(&count);
|
||||
|
||||
if (*len < (size_t)count)
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
if (self->compressedData) {
|
||||
if (compressedData_) {
|
||||
for (i = 0; i < count; i++) {
|
||||
DEBUG_ASSERT(self->index < self->numericValues->n);
|
||||
DEBUG_ASSERT(i < self->numericValues->v[self->index]->n);
|
||||
val[i] = self->numericValues->v[self->index]->v[i];
|
||||
DEBUG_ASSERT(index_ < numericValues_->n);
|
||||
DEBUG_ASSERT(i < numericValues_->v[index_]->n);
|
||||
val[i] = numericValues_->v[index_]->v[i];
|
||||
}
|
||||
*len = count;
|
||||
}
|
||||
else {
|
||||
DEBUG_ASSERT(self->subsetNumber < self->numericValues->n);
|
||||
DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n);
|
||||
val[0] = self->numericValues->v[self->subsetNumber]->v[self->index];
|
||||
DEBUG_ASSERT(subsetNumber_ < numericValues_->n);
|
||||
DEBUG_ASSERT(index_ < numericValues_->v[subsetNumber_]->n);
|
||||
val[0] = numericValues_->v[subsetNumber_]->v[index_];
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int ret = GRIB_SUCCESS;
|
||||
int ret = GRIB_SUCCESS;
|
||||
size_t count = 1, i = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->compressedData) {
|
||||
if (compressedData_) {
|
||||
count = *len;
|
||||
if (count != 1 && count != (size_t)self->numberOfSubsets) {
|
||||
if (count != 1 && count != (size_t)numberOfSubsets_) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld doubles provided but expected %ld (=number of subsets)",
|
||||
self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets);
|
||||
descriptors_->v[elementsDescriptorsIndex_->v[0]->v[index_]]->shortName, count, numberOfSubsets_);
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
grib_darray_delete(a->context, self->numericValues->v[self->index]);
|
||||
self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1);
|
||||
grib_darray_delete(context_, numericValues_->v[index_]);
|
||||
numericValues_->v[index_] = grib_darray_new(context_, count, 1);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
grib_darray_push(a->context, self->numericValues->v[self->index], val[i]);
|
||||
grib_darray_push(context_, numericValues_->v[index_], val[i]);
|
||||
|
||||
*len = count;
|
||||
}
|
||||
else {
|
||||
self->numericValues->v[self->subsetNumber]->v[self->index] = val[0];
|
||||
*len = 1;
|
||||
numericValues_->v[subsetNumber_]->v[index_] = val[0];
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bufr_data_element_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
size_t count = 1, i = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->compressedData) {
|
||||
if (compressedData_) {
|
||||
count = *len;
|
||||
if (count != 1 && count != (size_t)self->numberOfSubsets) {
|
||||
if (count != 1 && count != (size_t)numberOfSubsets_) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %zu integers provided but expected %ld (=number of subsets)",
|
||||
self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets);
|
||||
descriptors_->v[elementsDescriptorsIndex_->v[0]->v[index_]]->shortName, count, numberOfSubsets_);
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
grib_darray_delete(a->context, self->numericValues->v[self->index]);
|
||||
self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1);
|
||||
grib_darray_delete(context_, numericValues_->v[index_]);
|
||||
numericValues_->v[index_] = grib_darray_new(context_, count, 1);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
grib_darray_push(a->context, self->numericValues->v[self->index], val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i]);
|
||||
grib_darray_push(context_, numericValues_->v[index_], val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i]);
|
||||
}
|
||||
*len = count;
|
||||
}
|
||||
else {
|
||||
self->numericValues->v[self->subsetNumber]->v[self->index] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0];
|
||||
*len = 1;
|
||||
numericValues_->v[subsetNumber_]->v[index_] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0];
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_bufr_data_element_t::value_count(long* count)
|
||||
{
|
||||
int ret = 0, type = 0, idx = 0;
|
||||
size_t size = 0;
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
size_t size = 0;
|
||||
|
||||
if (!self->compressedData) {
|
||||
if (!compressedData_) {
|
||||
*count = 1;
|
||||
return 0;
|
||||
}
|
||||
type = get_native_type(a);
|
||||
type = get_native_type();
|
||||
|
||||
if (type == GRIB_TYPE_STRING) {
|
||||
DEBUG_ASSERT(self->index < self->numericValues->n);
|
||||
idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets;
|
||||
size = grib_sarray_used_size(self->stringValues->v[idx]);
|
||||
DEBUG_ASSERT(index_ < numericValues_->n);
|
||||
idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_;
|
||||
size = grib_sarray_used_size(stringValues_->v[idx]);
|
||||
}
|
||||
else {
|
||||
DEBUG_ASSERT(self->index < self->numericValues->n);
|
||||
size = grib_darray_used_size(self->numericValues->v[self->index]);
|
||||
DEBUG_ASSERT(index_ < numericValues_->n);
|
||||
size = grib_darray_used_size(numericValues_->v[index_]);
|
||||
}
|
||||
|
||||
*count = size == 1 ? 1 : self->numberOfSubsets;
|
||||
*count = size == 1 ? 1 : numberOfSubsets_;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_bufr_data_element_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
/* ECC-415 */
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int ret = GRIB_SUCCESS;
|
||||
long count = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
long count = 0;
|
||||
|
||||
value_count(a, &count);
|
||||
value_count(&count);
|
||||
if (idx >= (size_t)count) {
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
if (self->compressedData) {
|
||||
*val = self->numericValues->v[self->index]->v[idx];
|
||||
if (compressedData_) {
|
||||
*val = numericValues_->v[index_]->v[idx];
|
||||
}
|
||||
else {
|
||||
ret = GRIB_NOT_IMPLEMENTED;
|
||||
|
@ -474,12 +415,10 @@ int grib_accessor_class_bufr_data_element_t::unpack_double_element(grib_accessor
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bufr_data_element_t::get_native_type()
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int ret = GRIB_TYPE_DOUBLE;
|
||||
DEBUG_ASSERT(self);
|
||||
switch (self->type) {
|
||||
int ret = GRIB_TYPE_DOUBLE;
|
||||
switch (type_) {
|
||||
case BUFR_DESCRIPTOR_TYPE_STRING:
|
||||
ret = GRIB_TYPE_STRING;
|
||||
break;
|
||||
|
@ -500,50 +439,49 @@ int grib_accessor_class_bufr_data_element_t::get_native_type(grib_accessor* a)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void grib_accessor_class_bufr_data_element_t::destroy(grib_context* ct, grib_accessor* a)
|
||||
void grib_accessor_bufr_data_element_t::destroy(grib_context* ct)
|
||||
{
|
||||
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
|
||||
int i = 0;
|
||||
if (self->cname)
|
||||
grib_context_free(ct, self->cname); /* ECC-765 */
|
||||
while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) {
|
||||
/*grib_context_log(ct,GRIB_LOG_DEBUG,"deleting attribute %s->%s",a->name,a->attributes[i]->name);*/
|
||||
/*printf("bufr_data_element destroy %s %p\n", a->attributes[i]->name, (void*)a->attributes[i]);*/
|
||||
a->attributes[i]->destroy(ct);
|
||||
a->attributes[i] = NULL;
|
||||
int i = 0;
|
||||
if (cname_)
|
||||
grib_context_free(ct, cname_); /* ECC-765 */
|
||||
while (i < MAX_ACCESSOR_ATTRIBUTES && attributes_[i]) {
|
||||
/*grib_context_log(ct,GRIB_LOG_DEBUG,"deleting attribute %s->%s",a->name,attributes_ [i]->name);*/
|
||||
/*printf("bufr_data_element destroy %s %p\n", a->attributes_[i]->name, (void*)attributes_ [i]);*/
|
||||
attributes_[i]->destroy(ct);
|
||||
attributes_[i] = NULL;
|
||||
i++;
|
||||
}
|
||||
grib_accessor_class_gen_t::destroy(ct, a);
|
||||
grib_accessor_gen_t::destroy(ct);
|
||||
}
|
||||
|
||||
#define MAX_STRING_SIZE 4096
|
||||
/* Return 1 if BUFR element(s) is/are missing, 0 otherwise. In case of decoding errors, also return 0 */
|
||||
int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a)
|
||||
int grib_accessor_bufr_data_element_t::is_missing()
|
||||
{
|
||||
const int ktype = get_native_type(a);
|
||||
const int ktype = get_native_type();
|
||||
int err = 0, result = 1; /* default: assume all are missing */
|
||||
long count = 0;
|
||||
size_t i = 0, size = 1, size2 = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (ktype == GRIB_TYPE_LONG) {
|
||||
long* values = NULL;
|
||||
long value = 0;
|
||||
|
||||
value_count(a, &count);
|
||||
value_count(&count);
|
||||
size = size2 = count;
|
||||
if (size > 1) {
|
||||
values = (long*)grib_context_malloc_clear(c, sizeof(long) * size);
|
||||
err = a->unpack_long(values, &size2);
|
||||
err = unpack_long(values, &size2);
|
||||
}
|
||||
else {
|
||||
err = a->unpack_long(&value, &size2);
|
||||
err = unpack_long(&value, &size2);
|
||||
}
|
||||
if (err) return 0; /* TODO: no way of propagating the error up */
|
||||
Assert(size2 == size);
|
||||
if (size > 1) {
|
||||
for (i = 0; i < size; i++) {
|
||||
if (!grib_is_missing_long(a, values[i])) {
|
||||
if (!grib_is_missing_long(this, values[i])) {
|
||||
result = 0; /* at least one not missing */
|
||||
break;
|
||||
}
|
||||
|
@ -551,27 +489,27 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a)
|
|||
grib_context_free(c, values);
|
||||
}
|
||||
else {
|
||||
result = grib_is_missing_long(a, value);
|
||||
result = grib_is_missing_long(this, value);
|
||||
}
|
||||
}
|
||||
else if (ktype == GRIB_TYPE_DOUBLE) {
|
||||
double value = 0;
|
||||
double* values = NULL;
|
||||
|
||||
value_count(a, &count);
|
||||
value_count(&count);
|
||||
size = size2 = count;
|
||||
if (size > 1) {
|
||||
values = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
|
||||
err = a->unpack_double(values, &size2);
|
||||
err = unpack_double(values, &size2);
|
||||
}
|
||||
else {
|
||||
err = a->unpack_double(&value, &size2);
|
||||
err = unpack_double(&value, &size2);
|
||||
}
|
||||
if (err) return 0; /* TODO: no way of propagating the error up */
|
||||
Assert(size2 == size);
|
||||
if (size > 1) {
|
||||
for (i = 0; i < size; ++i) {
|
||||
if (!grib_is_missing_double(a, values[i])) {
|
||||
if (!grib_is_missing_double(this, values[i])) {
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -579,19 +517,19 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a)
|
|||
grib_context_free(c, values);
|
||||
}
|
||||
else {
|
||||
result = grib_is_missing_double(a, value);
|
||||
result = grib_is_missing_double(this, value);
|
||||
}
|
||||
}
|
||||
else if (ktype == GRIB_TYPE_STRING) {
|
||||
char** values = NULL;
|
||||
value_count(a, &count);
|
||||
value_count(&count);
|
||||
size = count;
|
||||
if (size > 1) {
|
||||
values = (char**)grib_context_malloc_clear(a->context, size * sizeof(char*));
|
||||
err = a->unpack_string_array(values, &size);
|
||||
values = (char**)grib_context_malloc_clear(context_, size * sizeof(char*));
|
||||
err = unpack_string_array(values, &size);
|
||||
if (err) return 0; /* TODO: no way of propagating the error up */
|
||||
for (i = 0; i < size; i++) {
|
||||
if (!grib_is_missing_string(a, (unsigned char*)values[i], size)) {
|
||||
if (!grib_is_missing_string(this, (unsigned char*)values[i], size)) {
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -601,11 +539,13 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a)
|
|||
grib_context_free(c, values);
|
||||
}
|
||||
else {
|
||||
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
|
||||
char value[MAX_STRING_SIZE] = {
|
||||
0,
|
||||
}; /* See ECC-710 */
|
||||
size = MAX_STRING_SIZE;
|
||||
err = a->unpack_string(value, &size);
|
||||
err = unpack_string(value, &size);
|
||||
if (err) return 0; /* TODO: no way of propagating the error up */
|
||||
result = grib_is_missing_string(a, (unsigned char*)value, size);
|
||||
result = grib_is_missing_string(this, (unsigned char*)value, size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -614,26 +554,26 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a)
|
|||
return result;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_data_element_t::pack_missing(grib_accessor* a)
|
||||
int grib_accessor_bufr_data_element_t::pack_missing()
|
||||
{
|
||||
int ktype = GRIB_TYPE_UNDEFINED;
|
||||
int err = 0;
|
||||
size_t size = 1;
|
||||
const int can_be_missing = (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING);
|
||||
const int can_be_missing = (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING);
|
||||
if (!can_be_missing)
|
||||
return GRIB_VALUE_CANNOT_BE_MISSING;
|
||||
|
||||
ktype = get_native_type(a);
|
||||
ktype = get_native_type();
|
||||
if (ktype == GRIB_TYPE_LONG) {
|
||||
long missing = GRIB_MISSING_LONG;
|
||||
err = pack_long(a, &missing, &size);
|
||||
err = pack_long(&missing, &size);
|
||||
}
|
||||
else if (ktype == GRIB_TYPE_DOUBLE) {
|
||||
double missing = GRIB_MISSING_DOUBLE;
|
||||
err = pack_double(a, &missing, &size);
|
||||
err = pack_double(&missing, &size);
|
||||
}
|
||||
else if (ktype == GRIB_TYPE_STRING) {
|
||||
err = pack_string(a, "", &size);
|
||||
err = pack_string("", &size);
|
||||
}
|
||||
else {
|
||||
err = GRIB_INVALID_TYPE;
|
||||
|
|
|
@ -16,39 +16,46 @@
|
|||
class grib_accessor_bufr_data_element_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_data_element */
|
||||
long index;
|
||||
int type;
|
||||
long compressedData;
|
||||
long subsetNumber;
|
||||
long numberOfSubsets;
|
||||
bufr_descriptors_array* descriptors;
|
||||
grib_vdarray* numericValues;
|
||||
grib_vsarray* stringValues;
|
||||
grib_viarray* elementsDescriptorsIndex;
|
||||
char* cname;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_data_element_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_data_element_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bufr_data_element_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_data_element"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_data_element_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_missing(grib_accessor*) override;
|
||||
int is_missing(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int pack_string(grib_accessor*, const char*, size_t* len) override;
|
||||
int pack_string_array(grib_accessor*, const char**, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
int unpack_string_array(grib_accessor*, char**, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override;
|
||||
long get_native_type() override;
|
||||
int pack_missing() override;
|
||||
int is_missing() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int pack_string(const char*, size_t* len) override;
|
||||
int pack_string_array(const char**, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
int unpack_string_array(char**, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
int unpack_double_element(size_t i, double* val) override;
|
||||
grib_accessor* make_clone(grib_section*, int*) override;
|
||||
|
||||
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_;
|
||||
long subsetNumber_;
|
||||
long numberOfSubsets_;
|
||||
bufr_descriptors_array* descriptors_;
|
||||
grib_vdarray* numericValues_;
|
||||
grib_vsarray* stringValues_;
|
||||
grib_viarray* elementsDescriptorsIndex_;
|
||||
char* cname_;
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ static omp_nest_lock_t mutex1;
|
|||
|
||||
static void init_mutex()
|
||||
{
|
||||
GRIB_OMP_CRITICAL(lock_grib_accessor_class_bufr_elements_table_c)
|
||||
GRIB_OMP_CRITICAL(lock_grib_accessor_bufr_elements_table_c)
|
||||
{
|
||||
if (once == 0) {
|
||||
omp_init_nest_lock(&mutex1);
|
||||
|
@ -39,70 +39,81 @@ static void init_mutex()
|
|||
}
|
||||
#endif
|
||||
|
||||
grib_accessor_bufr_elements_table_t _grib_accessor_bufr_elements_table{};
|
||||
grib_accessor* grib_accessor_bufr_elements_table = &_grib_accessor_bufr_elements_table;
|
||||
|
||||
grib_accessor_class_bufr_elements_table_t _grib_accessor_class_bufr_elements_table{ "bufr_elements_table" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_elements_table = &_grib_accessor_class_bufr_elements_table;
|
||||
|
||||
|
||||
void grib_accessor_class_bufr_elements_table_t::init(grib_accessor* a, const long len, grib_arguments* params)
|
||||
void grib_accessor_bufr_elements_table_t::init(const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, params);
|
||||
int n = 0;
|
||||
grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a;
|
||||
grib_accessor_gen_t::init(len, params);
|
||||
int n = 0;
|
||||
|
||||
self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a), params, n++);
|
||||
self->masterDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
|
||||
self->localDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
|
||||
dictionary_ = grib_arguments_get_string(grib_handle_of_accessor(this), params, n++);
|
||||
masterDir_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++);
|
||||
localDir_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++);
|
||||
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
length_ = 0;
|
||||
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,};
|
||||
char masterDir[1024] = {0,};
|
||||
char localDir[1024] = {0,};
|
||||
char dictName[1024] = {0,};
|
||||
char masterRecomposed[1024] = {0,}; //e.g. bufr/tables/0/wmo/36/element.table
|
||||
char localRecomposed[1024] = {0,}; //e.g. bufr/tables/0/local/0/98/0/element.table
|
||||
char* filename = NULL;
|
||||
char line[1024] = {
|
||||
0,
|
||||
};
|
||||
char masterDir[1024] = {
|
||||
0,
|
||||
};
|
||||
char localDir[1024] = {
|
||||
0,
|
||||
};
|
||||
char dictName[1024] = {
|
||||
0,
|
||||
};
|
||||
char masterRecomposed[1024] = {
|
||||
0,
|
||||
}; // e.g. bufr/tables/0/wmo/36/element.table
|
||||
char localRecomposed[1024] = {
|
||||
0,
|
||||
}; // e.g. bufr/tables/0/local/0/98/0/element.table
|
||||
char* localFilename = 0;
|
||||
char** list = 0;
|
||||
char** cached_list = 0;
|
||||
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);
|
||||
|
||||
if (*masterDir != 0) {
|
||||
char name[4096] = {0,};
|
||||
snprintf(name, 4096, "%s/%s", masterDir, self->dictionary);
|
||||
char name[4096] = {
|
||||
0,
|
||||
};
|
||||
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);
|
||||
char localName[2048] = {
|
||||
0,
|
||||
};
|
||||
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);
|
||||
|
@ -112,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;
|
||||
|
@ -122,11 +133,11 @@ static grib_trie* load_bufr_elements_table(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",a->dictionary_ );*/
|
||||
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");
|
||||
|
@ -217,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;
|
||||
|
||||
|
@ -276,13 +287,14 @@ 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;
|
||||
|
||||
if (!a)
|
||||
return NULL;
|
||||
|
||||
c = a->context;
|
||||
c = a->context_;
|
||||
DEBUG_ASSERT(c);
|
||||
v = (bufr_descriptor*)grib_context_malloc_clear(c, sizeof(bufr_descriptor));
|
||||
if (!v) {
|
||||
|
@ -298,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;
|
||||
|
@ -314,28 +326,28 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i
|
|||
return v;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_elements_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
||||
int grib_accessor_bufr_elements_table_t::unpack_string(char* buffer, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_elements_table_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_bufr_elements_table_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_elements_table_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bufr_elements_table_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_STRING;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_elements_table_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bufr_elements_table_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_elements_table_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_bufr_elements_table_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -16,21 +16,26 @@
|
|||
class grib_accessor_bufr_elements_table_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_elements_table */
|
||||
const char* dictionary;
|
||||
const char* masterDir;
|
||||
const char* localDir;
|
||||
grib_accessor_bufr_elements_table_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_elements_table"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_elements_table_t{}; }
|
||||
long get_native_type() override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_elements_table_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_elements_table_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_elements_table_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
};
|
||||
int bufr_descriptor_is_marker(bufr_descriptor* d);
|
||||
bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err);
|
||||
|
|
|
@ -11,33 +11,31 @@
|
|||
|
||||
#include "grib_accessor_class_bufr_extract_area_subsets.h"
|
||||
|
||||
grib_accessor_class_bufr_extract_area_subsets_t _grib_accessor_class_bufr_extract_area_subsets{ "bufr_extract_area_subsets" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_extract_area_subsets = &_grib_accessor_class_bufr_extract_area_subsets;
|
||||
grib_accessor_bufr_extract_area_subsets_t _grib_accessor_bufr_extract_area_subsets{};
|
||||
grib_accessor* grib_accessor_bufr_extract_area_subsets = &_grib_accessor_bufr_extract_area_subsets;
|
||||
|
||||
|
||||
void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bufr_extract_area_subsets_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
int n = 0;
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
int n = 0;
|
||||
|
||||
a->length = 0;
|
||||
self->doExtractSubsets = grib_arguments_get_name(h, arg, n++);
|
||||
self->numberOfSubsets = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractSubsetList = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractAreaWestLongitude = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractAreaEastLongitude = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractAreaNorthLatitude = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractAreaSouthLatitude = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractAreaLongitudeRank = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractAreaLatitudeRank = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractedAreaNumberOfSubsets = grib_arguments_get_name(h, arg, n++);
|
||||
length_ = 0;
|
||||
doExtractSubsets_ = grib_arguments_get_name(h, arg, n++);
|
||||
numberOfSubsets_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractSubsetList_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractAreaWestLongitude_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractAreaEastLongitude_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractAreaNorthLatitude_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractAreaSouthLatitude_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractAreaLongitudeRank_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractAreaLatitudeRank_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractedAreaNumberOfSubsets_ = grib_arguments_get_name(h, arg, n++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_extract_area_subsets_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bufr_extract_area_subsets_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
@ -50,14 +48,12 @@ 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_context* c = h->context;
|
||||
int ret = 0;
|
||||
long compressed = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_context* c = h->context;
|
||||
|
||||
double* lat = NULL;
|
||||
double* lon = NULL;
|
||||
|
@ -66,13 +62,17 @@ static int select_area(grib_accessor* a)
|
|||
long numberOfSubsets, i, latRank, lonRank;
|
||||
grib_iarray* subsets = NULL;
|
||||
size_t nsubsets = 0;
|
||||
char latstr[32] = {0,};
|
||||
char lonstr[32] = {0,};
|
||||
char latstr[32] = {
|
||||
0,
|
||||
};
|
||||
char lonstr[32] = {
|
||||
0,
|
||||
};
|
||||
|
||||
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);
|
||||
|
@ -81,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);
|
||||
}
|
||||
|
@ -141,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++) {
|
||||
|
@ -159,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;
|
||||
}
|
||||
|
||||
|
@ -180,11 +180,9 @@ static int select_area(grib_accessor* a)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_extract_area_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
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(a);
|
||||
return select_area();
|
||||
}
|
||||
|
|
|
@ -16,25 +16,24 @@
|
|||
class grib_accessor_bufr_extract_area_subsets_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_extract_area_subsets */
|
||||
const char* doExtractSubsets;
|
||||
const char* numberOfSubsets;
|
||||
const char* extractSubsetList;
|
||||
const char* extractAreaWestLongitude;
|
||||
const char* extractAreaEastLongitude;
|
||||
const char* extractAreaNorthLatitude;
|
||||
const char* extractAreaSouthLatitude;
|
||||
const char* extractAreaLongitudeRank;
|
||||
const char* extractAreaLatitudeRank;
|
||||
const char* extractedAreaNumberOfSubsets;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_extract_area_subsets_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_extract_area_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bufr_extract_area_subsets_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_extract_area_subsets"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_area_subsets_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* doExtractSubsets_;
|
||||
const char* numberOfSubsets_;
|
||||
const char* extractSubsetList_;
|
||||
const char* extractAreaWestLongitude_;
|
||||
const char* extractAreaEastLongitude_;
|
||||
const char* extractAreaNorthLatitude_;
|
||||
const char* extractAreaSouthLatitude_;
|
||||
const char* extractAreaLongitudeRank_;
|
||||
const char* extractAreaLatitudeRank_;
|
||||
const char* extractedAreaNumberOfSubsets_;
|
||||
|
||||
int select_area();
|
||||
};
|
||||
|
|
|
@ -10,25 +10,23 @@
|
|||
|
||||
#include "grib_accessor_class_bufr_extract_datetime_subsets.h"
|
||||
|
||||
grib_accessor_class_bufr_extract_datetime_subsets_t _grib_accessor_class_bufr_extract_datetime_subsets{ "bufr_extract_datetime_subsets" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_extract_datetime_subsets = &_grib_accessor_class_bufr_extract_datetime_subsets;
|
||||
grib_accessor_bufr_extract_datetime_subsets_t _grib_accessor_bufr_extract_datetime_subsets{};
|
||||
grib_accessor* grib_accessor_bufr_extract_datetime_subsets = &_grib_accessor_bufr_extract_datetime_subsets;
|
||||
|
||||
|
||||
void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bufr_extract_datetime_subsets_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
int n = 0;
|
||||
grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a;
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
int n = 0;
|
||||
|
||||
a->length = 0;
|
||||
self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
|
||||
self->numberOfSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
|
||||
self->extractSubsetList = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
|
||||
length_ = 0;
|
||||
doExtractSubsets_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++);
|
||||
numberOfSubsets_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++);
|
||||
extractSubsetList_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_extract_datetime_subsets_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bufr_extract_datetime_subsets_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
@ -87,7 +85,9 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed,
|
|||
}
|
||||
else {
|
||||
/* uncompressed */
|
||||
char keystr[32] = {0,};
|
||||
char keystr[32] = {
|
||||
0,
|
||||
};
|
||||
size_t values_len = 0;
|
||||
for (i = 0; i < numberOfSubsets; ++i) {
|
||||
long lVal = 0;
|
||||
|
@ -106,18 +106,23 @@ 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()
|
||||
{
|
||||
int ret = 0;
|
||||
long compressed = 0;
|
||||
grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a;
|
||||
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;
|
||||
char start_str[80] = {0,},
|
||||
end_str[80] = {0,},
|
||||
datetime_str[80] = {0,};
|
||||
char start_str[80] = {
|
||||
0,
|
||||
},
|
||||
end_str[80] = {
|
||||
0,
|
||||
},
|
||||
datetime_str[80] = {
|
||||
0,
|
||||
};
|
||||
long yearRank, monthRank, dayRank, hourRank, minuteRank, secondRank;
|
||||
long yearStart, monthStart, dayStart, hourStart, minuteStart, secondStart;
|
||||
long yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd;
|
||||
|
@ -136,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);
|
||||
|
@ -316,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;
|
||||
}
|
||||
|
||||
|
@ -337,11 +342,11 @@ cleanup:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_extract_datetime_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bufr_extract_datetime_subsets_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
/*grib_accessor_bufr_extract_datetime_subsets_t *self =(grib_accessor_bufr_extract_datetime_subsets_t*)a;*/
|
||||
|
||||
if (*len == 0)
|
||||
return GRIB_SUCCESS;
|
||||
return select_datetime(a);
|
||||
return select_datetime();
|
||||
}
|
||||
|
|
|
@ -16,18 +16,17 @@
|
|||
class grib_accessor_bufr_extract_datetime_subsets_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_extract_datetime_subsets */
|
||||
const char* doExtractSubsets;
|
||||
const char* numberOfSubsets;
|
||||
const char* extractSubsetList;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_extract_datetime_subsets_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_extract_datetime_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bufr_extract_datetime_subsets_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_extract_datetime_subsets"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_datetime_subsets_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* doExtractSubsets_;
|
||||
const char* numberOfSubsets_;
|
||||
const char* extractSubsetList_;
|
||||
|
||||
int select_datetime();
|
||||
};
|
||||
|
|
|
@ -11,51 +11,50 @@
|
|||
|
||||
#include "grib_accessor_class_bufr_extract_subsets.h"
|
||||
|
||||
grib_accessor_class_bufr_extract_subsets_t _grib_accessor_class_bufr_extract_subsets{ "bufr_extract_subsets" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_extract_subsets = &_grib_accessor_class_bufr_extract_subsets;
|
||||
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()
|
||||
{
|
||||
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
|
||||
const grib_handle* h = grib_handle_of_accessor(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_class_bufr_extract_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bufr_extract_subsets_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
int n = 0;
|
||||
|
||||
a->length = 0;
|
||||
self->numericValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
|
||||
self->pack = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
length_ = 0;
|
||||
numericValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++);
|
||||
pack_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++);
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
|
||||
numericValuesAccessor_ = NULL;
|
||||
packAccessor_ = NULL;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_extract_subsets_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bufr_extract_subsets_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_extract_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bufr_extract_subsets_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
|
||||
size_t l = 1;
|
||||
long v[1];
|
||||
|
||||
get_accessors(a);
|
||||
get_accessors();
|
||||
|
||||
v[0] = 1;
|
||||
int err = self->packAccessor->pack_long(v, &l);
|
||||
v[0] = 1;
|
||||
int err = packAccessor_->pack_long(v, &l);
|
||||
if (err) {
|
||||
if (err == GRIB_ENCODING_ERROR)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?");
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?");
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,19 +16,18 @@
|
|||
class grib_accessor_bufr_extract_subsets_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_extract_subsets */
|
||||
const char* numericValues;
|
||||
const char* pack;
|
||||
grib_accessor* numericValuesAccessor;
|
||||
grib_accessor* packAccessor;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_extract_subsets_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_extract_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bufr_extract_subsets_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_extract_subsets"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_subsets_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* numericValues_;
|
||||
const char* pack_;
|
||||
grib_accessor* numericValuesAccessor_;
|
||||
grib_accessor* packAccessor_;
|
||||
|
||||
void get_accessors();
|
||||
};
|
||||
|
|
|
@ -10,20 +10,19 @@
|
|||
|
||||
#include "grib_accessor_class_bufr_group.h"
|
||||
|
||||
grib_accessor_class_bufr_group_t _grib_accessor_class_bufr_group{ "bufr_group" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_group = &_grib_accessor_class_bufr_group;
|
||||
grib_accessor_bufr_group_t _grib_accessor_bufr_group{};
|
||||
grib_accessor* grib_accessor_bufr_group = &_grib_accessor_bufr_group;
|
||||
|
||||
|
||||
void grib_accessor_class_bufr_group_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_bufr_group_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_section(dumper, a, a->sub_section->block);
|
||||
grib_dump_section(dumper, this, sub_section_->block);
|
||||
}
|
||||
|
||||
grib_accessor* grib_accessor_class_bufr_group_t::next(grib_accessor* a, int explore)
|
||||
grib_accessor* grib_accessor_bufr_group_t::next(grib_accessor* a, int explore)
|
||||
{
|
||||
grib_accessor* next = NULL;
|
||||
if (explore) {
|
||||
next = a->sub_section->block->first;
|
||||
next = a->sub_section_->block->first;
|
||||
if (!next)
|
||||
next = a->next_;
|
||||
}
|
||||
|
@ -31,8 +30,8 @@ grib_accessor* grib_accessor_class_bufr_group_t::next(grib_accessor* a, int expl
|
|||
next = a->next_;
|
||||
}
|
||||
if (!next) {
|
||||
if (a->parent->owner)
|
||||
next = a->parent->owner->cclass->next(a->parent->owner, 0);
|
||||
if (a->parent_->owner)
|
||||
next = a->parent_->owner->next(a->parent_->owner, 0);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
|
|
@ -16,14 +16,9 @@
|
|||
class grib_accessor_bufr_group_t : public grib_accessor_variable_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_group */
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_group_t : public grib_accessor_class_variable_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_group_t(const char* name) : grib_accessor_class_variable_t(name) {}
|
||||
grib_accessor_bufr_group_t() :
|
||||
grib_accessor_variable_t() { class_name_ = "bufr_group"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_group_t{}; }
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
grib_accessor* next(grib_accessor* a, int explore) override;
|
||||
void dump(grib_dumper*) override;
|
||||
grib_accessor* next(grib_accessor*, int explore) override;
|
||||
};
|
||||
|
|
|
@ -11,39 +11,35 @@
|
|||
|
||||
#include "grib_accessor_class_bufr_simple_thinning.h"
|
||||
|
||||
grib_accessor_class_bufr_simple_thinning_t _grib_accessor_class_bufr_simple_thinning{ "bufr_simple_thinning" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_class_bufr_simple_thinning;
|
||||
grib_accessor_bufr_simple_thinning_t _grib_accessor_bufr_simple_thinning{};
|
||||
grib_accessor* grib_accessor_bufr_simple_thinning = &_grib_accessor_bufr_simple_thinning;
|
||||
|
||||
|
||||
void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bufr_simple_thinning_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
int n = 0;
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
int n = 0;
|
||||
|
||||
a->length = 0;
|
||||
self->doExtractSubsets = grib_arguments_get_name(h, arg, n++);
|
||||
self->numberOfSubsets = grib_arguments_get_name(h, arg, n++);
|
||||
self->extractSubsetList = grib_arguments_get_name(h, arg, n++);
|
||||
self->simpleThinningStart = grib_arguments_get_name(h, arg, n++);
|
||||
self->simpleThinningMissingRadius = grib_arguments_get_name(h, arg, n++);
|
||||
self->simpleThinningSkip = grib_arguments_get_name(h, arg, n++);
|
||||
length_ = 0;
|
||||
doExtractSubsets_ = grib_arguments_get_name(h, arg, n++);
|
||||
numberOfSubsets_ = grib_arguments_get_name(h, arg, n++);
|
||||
extractSubsetList_ = grib_arguments_get_name(h, arg, n++);
|
||||
simpleThinningStart_ = grib_arguments_get_name(h, arg, n++);
|
||||
simpleThinningMissingRadius_ = grib_arguments_get_name(h, arg, n++);
|
||||
simpleThinningSkip_ = grib_arguments_get_name(h, arg, n++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_simple_thinning_t::get_native_type(grib_accessor* a)
|
||||
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;
|
||||
|
@ -55,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;
|
||||
|
||||
|
@ -82,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;
|
||||
|
@ -91,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;
|
||||
}
|
||||
|
@ -104,15 +100,13 @@ static int apply_thinning(grib_accessor* a)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_simple_thinning_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_bufr_simple_thinning_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a;
|
||||
|
||||
if (*len == 0)
|
||||
return GRIB_SUCCESS;
|
||||
int err = apply_thinning(a);
|
||||
int err = apply_thinning();
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return grib_set_long(a->parent->h, self->doExtractSubsets, 1);
|
||||
return grib_set_long(parent_->h, doExtractSubsets_, 1);
|
||||
}
|
||||
|
|
|
@ -16,21 +16,20 @@
|
|||
class grib_accessor_bufr_simple_thinning_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_simple_thinning */
|
||||
const char* doExtractSubsets;
|
||||
const char* numberOfSubsets;
|
||||
const char* extractSubsetList;
|
||||
const char* simpleThinningStart;
|
||||
const char* simpleThinningMissingRadius;
|
||||
const char* simpleThinningSkip;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_simple_thinning_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_simple_thinning_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bufr_simple_thinning_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bufr_simple_thinning"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_simple_thinning_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* doExtractSubsets_;
|
||||
const char* numberOfSubsets_;
|
||||
const char* extractSubsetList_;
|
||||
const char* simpleThinningStart_;
|
||||
const char* simpleThinningMissingRadius_;
|
||||
const char* simpleThinningSkip_;
|
||||
|
||||
int apply_thinning();
|
||||
};
|
||||
|
|
|
@ -12,49 +12,46 @@
|
|||
#include "grib_accessor_class_bufr_string_values.h"
|
||||
#include "grib_accessor_class_bufr_data_array.h"
|
||||
|
||||
grib_accessor_class_bufr_string_values_t _grib_accessor_class_bufr_string_values{ "bufr_string_values" };
|
||||
grib_accessor_class* grib_accessor_class_bufr_string_values = &_grib_accessor_class_bufr_string_values;
|
||||
grib_accessor_bufr_string_values_t _grib_accessor_bufr_string_values{};
|
||||
grib_accessor* grib_accessor_bufr_string_values = &_grib_accessor_bufr_string_values;
|
||||
|
||||
|
||||
void grib_accessor_class_bufr_string_values_t::init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
void grib_accessor_bufr_string_values_t::init(const long len, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_ascii_t::init(a, len, args);
|
||||
grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a;
|
||||
int n = 0;
|
||||
self->dataAccessorName = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->dataAccessor = NULL;
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
grib_accessor_ascii_t::init(len, args);
|
||||
int n = 0;
|
||||
dataAccessorName_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
dataAccessor_ = NULL;
|
||||
length_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
void grib_accessor_class_bufr_string_values_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_bufr_string_values_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_string_array(dumper, a, NULL);
|
||||
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_class_bufr_string_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len)
|
||||
int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len)
|
||||
{
|
||||
grib_accessor* data = 0;
|
||||
grib_context* c = a->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(a);
|
||||
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);
|
||||
|
||||
|
@ -75,18 +72,18 @@ int grib_accessor_class_bufr_string_values_t::unpack_string_array(grib_accessor*
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_string_values_t::unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
int grib_accessor_bufr_string_values_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufr_string_values_t::value_count(grib_accessor* a, long* rlen)
|
||||
int grib_accessor_bufr_string_values_t::value_count(long* rlen)
|
||||
{
|
||||
grib_accessor* descriptors = get_accessor(a);
|
||||
grib_accessor* descriptors = get_accessor();
|
||||
return descriptors->value_count(rlen);
|
||||
}
|
||||
|
||||
void grib_accessor_class_bufr_string_values_t::destroy(grib_context* c, grib_accessor* a)
|
||||
void grib_accessor_bufr_string_values_t::destroy(grib_context* c)
|
||||
{
|
||||
grib_accessor_class_ascii_t::destroy(c, a);
|
||||
grib_accessor_ascii_t::destroy(c);
|
||||
}
|
||||
|
|
|
@ -16,20 +16,19 @@
|
|||
class grib_accessor_bufr_string_values_t : public grib_accessor_ascii_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufr_string_values */
|
||||
const char* dataAccessorName;
|
||||
grib_accessor* dataAccessor;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufr_string_values_t : public grib_accessor_class_ascii_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufr_string_values_t(const char* name) : grib_accessor_class_ascii_t(name) {}
|
||||
grib_accessor_bufr_string_values_t() :
|
||||
grib_accessor_ascii_t() { class_name_ = "bufr_string_values"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_string_values_t{}; }
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
int unpack_string_array(grib_accessor*, char**, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
int unpack_string_array(char**, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* dataAccessorName_;
|
||||
grib_accessor* dataAccessor_;
|
||||
|
||||
grib_accessor* get_accessor();
|
||||
};
|
||||
|
|
|
@ -11,43 +11,40 @@
|
|||
|
||||
#include "grib_accessor_class_bufrdc_expanded_descriptors.h"
|
||||
|
||||
grib_accessor_class_bufrdc_expanded_descriptors_t _grib_accessor_class_bufrdc_expanded_descriptors{ "bufrdc_expanded_descriptors" };
|
||||
grib_accessor_class* grib_accessor_class_bufrdc_expanded_descriptors = &_grib_accessor_class_bufrdc_expanded_descriptors;
|
||||
grib_accessor_bufrdc_expanded_descriptors_t _grib_accessor_bufrdc_expanded_descriptors{};
|
||||
grib_accessor* grib_accessor_bufrdc_expanded_descriptors = &_grib_accessor_bufrdc_expanded_descriptors;
|
||||
|
||||
|
||||
void grib_accessor_class_bufrdc_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
void grib_accessor_bufrdc_expanded_descriptors_t::init(const long len, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, len, args);
|
||||
grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a;
|
||||
int n = 0;
|
||||
self->expandedDescriptors = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->expandedDescriptorsAccessor = 0;
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
grib_accessor_long_t::init(len, args);
|
||||
int n = 0;
|
||||
expandedDescriptors_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
expandedDescriptorsAccessor_ = 0;
|
||||
length_ = 0;
|
||||
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_class_bufrdc_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_bufrdc_expanded_descriptors_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor* descriptors = 0;
|
||||
size_t rlen = 0, l;
|
||||
long lenall = 0;
|
||||
size_t i = 0;
|
||||
long* v = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
descriptors = get_accessor(a);
|
||||
descriptors = get_accessor();
|
||||
if (!descriptors) return GRIB_NOT_FOUND;
|
||||
|
||||
a->value_count(&lenall);
|
||||
value_count(&lenall);
|
||||
v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall);
|
||||
l = lenall;
|
||||
descriptors->unpack_long(v, &l);
|
||||
|
@ -62,7 +59,7 @@ int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_long(grib_accessor
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len)
|
||||
int grib_accessor_bufrdc_expanded_descriptors_t::unpack_string_array(char** buffer, size_t* len)
|
||||
{
|
||||
int err = 0;
|
||||
grib_accessor* descriptors = 0;
|
||||
|
@ -70,13 +67,15 @@ int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_
|
|||
long lenall = 0;
|
||||
size_t i = 0;
|
||||
long* v = 0;
|
||||
char buf[25] = {0,};
|
||||
grib_context* c = a->context;
|
||||
char buf[25] = {
|
||||
0,
|
||||
};
|
||||
grib_context* c = context_;
|
||||
|
||||
descriptors = get_accessor(a);
|
||||
descriptors = get_accessor();
|
||||
if (!descriptors) return GRIB_NOT_FOUND;
|
||||
|
||||
err = a->value_count(&lenall);
|
||||
err = value_count(&lenall);
|
||||
if (err) return err;
|
||||
l = lenall;
|
||||
if (l > *len) return GRIB_ARRAY_TOO_SMALL;
|
||||
|
@ -95,14 +94,14 @@ int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bufrdc_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen)
|
||||
int grib_accessor_bufrdc_expanded_descriptors_t::value_count(long* rlen)
|
||||
{
|
||||
grib_accessor* descriptors = get_accessor(a);
|
||||
grib_accessor* descriptors = get_accessor();
|
||||
|
||||
return descriptors->value_count(rlen);
|
||||
}
|
||||
|
||||
void grib_accessor_class_bufrdc_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a)
|
||||
void grib_accessor_bufrdc_expanded_descriptors_t::destroy(grib_context* c)
|
||||
{
|
||||
grib_accessor_class_long_t::destroy(c, a);
|
||||
grib_accessor_long_t::destroy(c);
|
||||
}
|
||||
|
|
|
@ -16,19 +16,18 @@
|
|||
class grib_accessor_bufrdc_expanded_descriptors_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bufrdc_expanded_descriptors */
|
||||
const char* expandedDescriptors;
|
||||
grib_accessor* expandedDescriptorsAccessor;
|
||||
};
|
||||
|
||||
class grib_accessor_class_bufrdc_expanded_descriptors_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bufrdc_expanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_bufrdc_expanded_descriptors_t() :
|
||||
grib_accessor_long_t() { class_name_ = "bufrdc_expanded_descriptors"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufrdc_expanded_descriptors_t{}; }
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string_array(grib_accessor*, char**, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string_array(char**, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* expandedDescriptors_;
|
||||
grib_accessor* expandedDescriptorsAccessor_;
|
||||
|
||||
grib_accessor* get_accessor();
|
||||
};
|
||||
|
|
|
@ -10,28 +10,27 @@
|
|||
|
||||
#include "grib_accessor_class_bytes.h"
|
||||
|
||||
grib_accessor_class_bytes_t _grib_accessor_class_bytes{ "bytes" };
|
||||
grib_accessor_class* grib_accessor_class_bytes = &_grib_accessor_class_bytes;
|
||||
grib_accessor_bytes_t _grib_accessor_bytes{};
|
||||
grib_accessor* grib_accessor_bytes = &_grib_accessor_bytes;
|
||||
|
||||
|
||||
void grib_accessor_class_bytes_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_bytes_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, arg);
|
||||
grib_accessor_gen_t::init(len, arg);
|
||||
/*grib_accessor_signed* self = (grib_accessor_signed*)a; */
|
||||
a->length = len;
|
||||
Assert(a->length >= 0);
|
||||
length_ = len;
|
||||
Assert(length_ >= 0);
|
||||
}
|
||||
|
||||
int grib_accessor_class_bytes_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_bytes_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_BYTES;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bytes_t::compare(grib_accessor* a, grib_accessor* b)
|
||||
int grib_accessor_bytes_t::compare(grib_accessor* b)
|
||||
{
|
||||
int retval = GRIB_SUCCESS;
|
||||
|
||||
size_t alen = (size_t)a->byte_count();
|
||||
size_t alen = (size_t)byte_count();
|
||||
size_t blen = (size_t)b->byte_count();
|
||||
if (alen != blen)
|
||||
return GRIB_COUNT_MISMATCH;
|
||||
|
@ -39,12 +38,12 @@ int grib_accessor_class_bytes_t::compare(grib_accessor* a, grib_accessor* b)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||
int grib_accessor_bytes_t::unpack_string(char* v, size_t* len)
|
||||
{
|
||||
unsigned char* p = NULL;
|
||||
char* s = v;
|
||||
long i = 0;
|
||||
const long length = a->byte_count();
|
||||
const long length = byte_count();
|
||||
const long slength = 2 * length;
|
||||
|
||||
if (*len < (size_t)slength) {
|
||||
|
@ -52,7 +51,7 @@ int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t
|
|||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset();
|
||||
p = grib_handle_of_accessor(this)->buffer->data + byte_offset();
|
||||
for (i = 0; i < length; i++) {
|
||||
snprintf(s, INT_MAX, "%02x", *(p++));
|
||||
s += 2;
|
||||
|
@ -63,15 +62,15 @@ int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val, size_t* len)
|
||||
int grib_accessor_bytes_t::pack_string(const char* val, size_t* len)
|
||||
{
|
||||
/* The string representation (val) of the byte array will have two chars
|
||||
* per byte e.g. 4C5B means the 2 bytes 0114 and 0133 in octal
|
||||
* so has to be twice the length of the byte array
|
||||
*/
|
||||
int err = 0;
|
||||
grib_context* c = a->context;
|
||||
size_t nbytes = a->length;
|
||||
grib_context* c = context_;
|
||||
size_t nbytes = length_;
|
||||
const size_t expected_blen = nbytes;
|
||||
const size_t expected_slen = 2 * expected_blen;
|
||||
unsigned char* bytearray = NULL;
|
||||
|
@ -80,7 +79,7 @@ int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val,
|
|||
if (slen != expected_slen || *len != expected_slen) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR,
|
||||
"%s: Key %s is %lu bytes. Expected a string with %lu characters (actual length=%zu)",
|
||||
__func__, a->name, expected_blen, expected_slen, *len);
|
||||
__func__, name_, expected_blen, expected_slen, *len);
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
}
|
||||
|
||||
|
@ -99,7 +98,7 @@ int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val,
|
|||
}
|
||||
|
||||
/* Forward to base class to pack the byte array */
|
||||
err = grib_accessor_class_gen_t::pack_bytes(a, bytearray, &nbytes);
|
||||
err = grib_accessor_gen_t::pack_bytes(bytearray, &nbytes);
|
||||
grib_context_free(c, bytearray);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -16,17 +16,12 @@
|
|||
class grib_accessor_bytes_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in bytes */
|
||||
};
|
||||
|
||||
class grib_accessor_class_bytes_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_bytes_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_bytes_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "bytes"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_bytes_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_string(grib_accessor*, const char*, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*, grib_accessor*) override;
|
||||
long get_native_type() override;
|
||||
int pack_string(const char*, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*) override;
|
||||
};
|
||||
|
|
|
@ -10,40 +10,38 @@
|
|||
|
||||
#include "grib_accessor_class_cf_var_name.h"
|
||||
|
||||
grib_accessor_class_cf_var_name_t _grib_accessor_class_cf_var_name{ "cf_var_name" };
|
||||
grib_accessor_class* grib_accessor_class_cf_var_name = &_grib_accessor_class_cf_var_name;
|
||||
grib_accessor_cf_var_name_t _grib_accessor_cf_var_name{};
|
||||
grib_accessor* grib_accessor_cf_var_name = &_grib_accessor_cf_var_name;
|
||||
|
||||
|
||||
void grib_accessor_class_cf_var_name_t::init(grib_accessor* a, const long l, grib_arguments* arg)
|
||||
void grib_accessor_cf_var_name_t::init(const long l, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_ascii_t::init(a, l, arg);
|
||||
|
||||
grib_accessor_cf_var_name_t* self = (grib_accessor_cf_var_name_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
|
||||
self->defaultKey = grib_arguments_get_name(h, arg, 0);
|
||||
grib_accessor_ascii_t::init(l, arg);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
defaultKey_ = grib_arguments_get_name(h, arg, 0);
|
||||
}
|
||||
|
||||
int grib_accessor_class_cf_var_name_t::unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
int grib_accessor_cf_var_name_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
grib_accessor_cf_var_name_t* self = (grib_accessor_cf_var_name_t*)a;
|
||||
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
char defaultKey[256] = {0,};
|
||||
size_t size = sizeof(defaultKey) / sizeof(*defaultKey);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
char defaultKey[256] = {
|
||||
0,
|
||||
};
|
||||
size_t size = sizeof(defaultKey) / sizeof(*defaultKey);
|
||||
char* pDefaultKey = defaultKey;
|
||||
|
||||
int err = grib_get_string(h, self->defaultKey, defaultKey, &size);
|
||||
int err = grib_get_string(h, defaultKey_, defaultKey, &size);
|
||||
if (err) return err;
|
||||
Assert(size > 0);
|
||||
Assert(strlen(defaultKey) > 0);
|
||||
|
||||
if ( STR_EQUAL(defaultKey, "~") || isdigit(defaultKey[0]) ) {
|
||||
if (STR_EQUAL(defaultKey, "~") || isdigit(defaultKey[0])) {
|
||||
// NetCDF variables cannot start with a digit
|
||||
long paramId = 0;
|
||||
err = grib_get_long(h, "paramId", ¶mId);
|
||||
if (err) snprintf(val, 1024, "%s", "unknown");
|
||||
else snprintf(val, 1024, "p%ld", paramId);
|
||||
err = grib_get_long(h, "paramId", ¶mId);
|
||||
if (err)
|
||||
snprintf(val, 1024, "%s", "unknown");
|
||||
else
|
||||
snprintf(val, 1024, "p%ld", paramId);
|
||||
}
|
||||
else {
|
||||
snprintf(val, 1024, "%s", pDefaultKey);
|
||||
|
@ -53,7 +51,7 @@ int grib_accessor_class_cf_var_name_t::unpack_string(grib_accessor* a, char* val
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
size_t grib_accessor_class_cf_var_name_t::string_length(grib_accessor* a)
|
||||
size_t grib_accessor_cf_var_name_t::string_length()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
|
|
|
@ -15,16 +15,14 @@
|
|||
class grib_accessor_cf_var_name_t : public grib_accessor_ascii_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in cf_var_name */
|
||||
const char* defaultKey;
|
||||
};
|
||||
|
||||
class grib_accessor_class_cf_var_name_t : public grib_accessor_class_ascii_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_cf_var_name_t(const char* name) : grib_accessor_class_ascii_t(name) {}
|
||||
grib_accessor_cf_var_name_t() :
|
||||
grib_accessor_ascii_t() { class_name_ = "cf_var_name"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_cf_var_name_t{}; }
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
size_t string_length(grib_accessor*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
size_t string_length() override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
/* Members defined in cf_var_name */
|
||||
const char* defaultKey_;
|
||||
};
|
||||
|
|
|
@ -10,32 +10,28 @@
|
|||
|
||||
#include "grib_accessor_class_change_alternative_row_scanning.h"
|
||||
|
||||
grib_accessor_class_change_alternative_row_scanning_t _grib_accessor_class_change_alternative_row_scanning{ "change_alternative_row_scanning" };
|
||||
grib_accessor_class* grib_accessor_class_change_alternative_row_scanning = &_grib_accessor_class_change_alternative_row_scanning;
|
||||
grib_accessor_change_alternative_row_scanning_t _grib_accessor_change_alternative_row_scanning{};
|
||||
grib_accessor* grib_accessor_change_alternative_row_scanning = &_grib_accessor_change_alternative_row_scanning;
|
||||
|
||||
|
||||
void grib_accessor_class_change_alternative_row_scanning_t::init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
void grib_accessor_change_alternative_row_scanning_t::init(const long len, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, args);
|
||||
grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a;
|
||||
|
||||
grib_accessor_gen_t::init(len, args);
|
||||
int n = 0;
|
||||
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->Ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->Nj = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->alternativeRowScanning = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
a->length = 0;
|
||||
values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
Ni_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
Nj_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
alternativeRowScanning_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_change_alternative_row_scanning_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a;
|
||||
|
||||
int err = 0;
|
||||
const grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
const grib_context* c = context_;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning;
|
||||
size_t size = 0;
|
||||
double* values = NULL;
|
||||
|
@ -45,23 +41,23 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access
|
|||
return 0;
|
||||
|
||||
/* Make sure Ni / Nj are not missing */
|
||||
if (grib_is_missing(h, self->Ni, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Ni);
|
||||
if (grib_is_missing(h, Ni_, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", Ni_);
|
||||
return GRIB_WRONG_GRID;
|
||||
}
|
||||
if (grib_is_missing(h, self->Nj, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Nj);
|
||||
if (grib_is_missing(h, Nj_, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", Nj_);
|
||||
return GRIB_WRONG_GRID;
|
||||
}
|
||||
|
||||
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->alternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, alternativeRowScanning_, &alternativeRowScanning)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_size(h, values_, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (size > (size_t)(Ni * Nj)) {
|
||||
|
@ -73,7 +69,7 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access
|
|||
if (!values)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) {
|
||||
if ((err = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return err;
|
||||
}
|
||||
|
@ -93,12 +89,12 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access
|
|||
}
|
||||
}
|
||||
alternativeRowScanning = !alternativeRowScanning;
|
||||
if ((err = grib_set_long_internal(h, self->alternativeRowScanning, alternativeRowScanning)) != GRIB_SUCCESS) {
|
||||
if ((err = grib_set_long_internal(h, alternativeRowScanning_, alternativeRowScanning)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) {
|
||||
if ((err = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return err;
|
||||
}
|
||||
|
@ -108,12 +104,12 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_change_alternative_row_scanning_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_change_alternative_row_scanning_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
||||
int grib_accessor_class_change_alternative_row_scanning_t::unpack_long(grib_accessor* a, long* v, size_t* len)
|
||||
int grib_accessor_change_alternative_row_scanning_t::unpack_long(long* v, size_t* len)
|
||||
{
|
||||
/* Decoding this accessor doesn't make sense so we return a dummy value */
|
||||
*v = -1;
|
||||
|
|
|
@ -16,20 +16,17 @@
|
|||
class grib_accessor_change_alternative_row_scanning_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in change_alternative_row_scanning */
|
||||
const char* values;
|
||||
const char* Ni;
|
||||
const char* Nj;
|
||||
const char* alternativeRowScanning;
|
||||
};
|
||||
|
||||
class grib_accessor_class_change_alternative_row_scanning_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_change_alternative_row_scanning_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_change_alternative_row_scanning_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "change_alternative_row_scanning"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_change_alternative_row_scanning_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* values_;
|
||||
const char* Ni_;
|
||||
const char* Nj_;
|
||||
const char* alternativeRowScanning_;
|
||||
};
|
||||
|
|
|
@ -10,75 +10,72 @@
|
|||
|
||||
#include "grib_accessor_class_change_scanning_direction.h"
|
||||
|
||||
grib_accessor_class_change_scanning_direction_t _grib_accessor_class_change_scanning_direction{ "change_scanning_direction" };
|
||||
grib_accessor_class* grib_accessor_class_change_scanning_direction = &_grib_accessor_class_change_scanning_direction;
|
||||
grib_accessor_change_scanning_direction_t _grib_accessor_change_scanning_direction{};
|
||||
grib_accessor* grib_accessor_change_scanning_direction = &_grib_accessor_change_scanning_direction;
|
||||
|
||||
|
||||
void grib_accessor_class_change_scanning_direction_t::init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
void grib_accessor_change_scanning_direction_t::init(const long len, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, args);
|
||||
grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_accessor_gen_t::init(len, args);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
int n = 0;
|
||||
|
||||
int n = 0;
|
||||
self->values = grib_arguments_get_name(h, args, n++);
|
||||
self->Ni = grib_arguments_get_name(h, args, n++);
|
||||
self->Nj = grib_arguments_get_name(h, args, n++);
|
||||
self->i_scans_negatively = grib_arguments_get_name(h, args, n++);
|
||||
self->j_scans_positively = grib_arguments_get_name(h, args, n++);
|
||||
self->first = grib_arguments_get_name(h, args, n++);
|
||||
self->last = grib_arguments_get_name(h, args, n++);
|
||||
self->axis = grib_arguments_get_name(h, args, n++);
|
||||
values_ = grib_arguments_get_name(h, args, n++);
|
||||
Ni_ = grib_arguments_get_name(h, args, n++);
|
||||
Nj_ = grib_arguments_get_name(h, args, n++);
|
||||
i_scans_negatively_ = grib_arguments_get_name(h, args, n++);
|
||||
j_scans_positively_ = grib_arguments_get_name(h, args, n++);
|
||||
first_ = grib_arguments_get_name(h, args, n++);
|
||||
last_ = grib_arguments_get_name(h, args, n++);
|
||||
axis_ = grib_arguments_get_name(h, args, n++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
a->length = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_change_scanning_direction_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
int err = 0;
|
||||
long i, j, jr, theEnd, Ni, Nj, k, kp;
|
||||
double tmp;
|
||||
long iScansNegatively = 0;
|
||||
long jScansPositively = 0;
|
||||
double first = 0;
|
||||
double last = 0;
|
||||
size_t size = 0;
|
||||
double* values = NULL;
|
||||
grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a;
|
||||
const grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
long iScansNegatively = 0;
|
||||
long jScansPositively = 0;
|
||||
double first = 0;
|
||||
double last = 0;
|
||||
size_t size = 0;
|
||||
double* values = NULL;
|
||||
const grib_context* c = context_;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
if (*val == 0)
|
||||
return GRIB_SUCCESS;
|
||||
|
||||
/* Make sure Ni / Nj are not missing */
|
||||
if (grib_is_missing(h, self->Ni, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, self->Ni);
|
||||
if (grib_is_missing(h, Ni_, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, Ni_);
|
||||
return GRIB_WRONG_GRID;
|
||||
}
|
||||
if (grib_is_missing(h, self->Nj, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, self->Nj);
|
||||
if (grib_is_missing(h, Nj_, &err) && !err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, Nj_);
|
||||
return GRIB_WRONG_GRID;
|
||||
}
|
||||
|
||||
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->i_scans_negatively, &iScansNegatively)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, i_scans_negatively_, &iScansNegatively)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_long_internal(h, self->j_scans_positively, &jScansPositively)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(h, j_scans_positively_, &jScansPositively)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_double_internal(h, self->first, &first)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, first_, &first)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_get_double_internal(h, self->last, &last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(h, last_, &last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_size(h, values_, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (size > Ni * Nj) {
|
||||
|
@ -90,15 +87,15 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a,
|
|||
if (!values)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) {
|
||||
if ((err = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return err;
|
||||
}
|
||||
|
||||
Assert(self->axis);
|
||||
Assert(strcmp(self->axis, "x") == 0 || strcmp(self->axis, "y") == 0);
|
||||
Assert(axis_);
|
||||
Assert(strcmp(axis_, "x") == 0 || strcmp(axis_, "y") == 0);
|
||||
|
||||
if (self->axis[0] == 'x') {
|
||||
if (axis_[0] == 'x') {
|
||||
theEnd = Ni / 2;
|
||||
for (j = 0; j < Nj; j++) {
|
||||
jr = Ni * j;
|
||||
|
@ -111,7 +108,7 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a,
|
|||
}
|
||||
}
|
||||
iScansNegatively = !iScansNegatively;
|
||||
if ((err = grib_set_long_internal(h, self->i_scans_negatively, iScansNegatively)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(h, i_scans_negatively_, iScansNegatively)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
}
|
||||
else {
|
||||
|
@ -128,19 +125,19 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a,
|
|||
}
|
||||
}
|
||||
jScansPositively = !jScansPositively;
|
||||
if ((err = grib_set_long_internal(h, self->j_scans_positively, jScansPositively)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(h, j_scans_positively_, jScansPositively)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) {
|
||||
if ((err = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) {
|
||||
grib_context_free(c, values);
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = grib_set_double_internal(h, self->first, last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_internal(h, first_, last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_set_double_internal(h, self->last, first)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_internal(h, last_, first)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
grib_context_free(c, values);
|
||||
|
@ -148,12 +145,12 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a,
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_change_scanning_direction_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_change_scanning_direction_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
||||
int grib_accessor_class_change_scanning_direction_t::unpack_long(grib_accessor* a, long* v, size_t* len)
|
||||
int grib_accessor_change_scanning_direction_t::unpack_long(long* v, size_t* len)
|
||||
{
|
||||
/* ECC-976: decoding this accessor doesn't make sense so we return a dummy value */
|
||||
*v = -1;
|
||||
|
|
|
@ -16,24 +16,21 @@
|
|||
class grib_accessor_change_scanning_direction_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in change_scanning_direction */
|
||||
const char* values;
|
||||
const char* Ni;
|
||||
const char* Nj;
|
||||
const char* i_scans_negatively;
|
||||
const char* j_scans_positively;
|
||||
const char* first;
|
||||
const char* last;
|
||||
const char* axis;
|
||||
};
|
||||
|
||||
class grib_accessor_class_change_scanning_direction_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_change_scanning_direction_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_change_scanning_direction_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "change_scanning_direction"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_change_scanning_direction_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* values_;
|
||||
const char* Ni_;
|
||||
const char* Nj_;
|
||||
const char* i_scans_negatively_;
|
||||
const char* j_scans_positively_;
|
||||
const char* first_;
|
||||
const char* last_;
|
||||
const char* axis_;
|
||||
};
|
||||
|
|
|
@ -10,22 +10,21 @@
|
|||
|
||||
#include "grib_accessor_class_check_internal_version.h"
|
||||
|
||||
grib_accessor_class_check_internal_version_t _grib_accessor_class_check_internal_version{ "check_internal_version" };
|
||||
grib_accessor_class* grib_accessor_class_check_internal_version = &_grib_accessor_class_check_internal_version;
|
||||
|
||||
grib_accessor_check_internal_version_t _grib_accessor_check_internal_version{};
|
||||
grib_accessor* grib_accessor_check_internal_version = &_grib_accessor_check_internal_version;
|
||||
|
||||
/* This is the internal engine version number */
|
||||
/* We check this against the version number found in the definitions boot.def file */
|
||||
/* See the key "internalVersion" */
|
||||
#define LATEST_ENGINE_VERSION 30
|
||||
|
||||
void grib_accessor_class_check_internal_version_t::init(grib_accessor* a, const long l, grib_arguments* args)
|
||||
void grib_accessor_check_internal_version_t::init(const long l, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_ascii_t::init(a, l, args);
|
||||
grib_accessor_ascii_t::init(l, args);
|
||||
/* Check version of definition files is compatible with the engine */
|
||||
int err = 0;
|
||||
long defs_file_version = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
const char* s_defn_version = grib_arguments_get_name(h, args, 0);
|
||||
Assert(s_defn_version);
|
||||
|
||||
|
@ -41,13 +40,13 @@ void grib_accessor_class_check_internal_version_t::init(grib_accessor* a, const
|
|||
}
|
||||
}
|
||||
|
||||
int grib_accessor_class_check_internal_version_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_check_internal_version_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t grib_accessor_class_check_internal_version_t::string_length(grib_accessor* a)
|
||||
size_t grib_accessor_check_internal_version_t::string_length()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
|
|
@ -16,15 +16,10 @@
|
|||
class grib_accessor_check_internal_version_t : public grib_accessor_ascii_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in check_internal_version */
|
||||
};
|
||||
|
||||
class grib_accessor_class_check_internal_version_t : public grib_accessor_class_ascii_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_check_internal_version_t(const char* name) : grib_accessor_class_ascii_t(name) {}
|
||||
grib_accessor_check_internal_version_t() :
|
||||
grib_accessor_ascii_t() { class_name_ = "check_internal_version"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_check_internal_version_t{}; }
|
||||
size_t string_length(grib_accessor*) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
size_t string_length() override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
};
|
||||
|
|
|
@ -11,51 +11,47 @@
|
|||
#include "grib_accessor_class_closest_date.h"
|
||||
#include <float.h>
|
||||
|
||||
grib_accessor_class_closest_date_t _grib_accessor_class_closest_date{ "closest_date" };
|
||||
grib_accessor_class* grib_accessor_class_closest_date = &_grib_accessor_class_closest_date;
|
||||
grib_accessor_closest_date_t _grib_accessor_closest_date{};
|
||||
grib_accessor* grib_accessor_closest_date = &_grib_accessor_closest_date;
|
||||
|
||||
|
||||
void grib_accessor_class_closest_date_t::init(grib_accessor* a, const long l, grib_arguments* c)
|
||||
void grib_accessor_closest_date_t::init(const long l, grib_arguments* c)
|
||||
{
|
||||
grib_accessor_class_double_t::init(a, l, c);
|
||||
grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
int n = 0;
|
||||
grib_accessor_double_t::init(l, c);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
int n = 0;
|
||||
|
||||
self->dateLocal = grib_arguments_get_name(h, c, n++);
|
||||
self->timeLocal = grib_arguments_get_name(h, c, n++);
|
||||
self->numForecasts = grib_arguments_get_name(h, c, n++);
|
||||
self->year = grib_arguments_get_name(h, c, n++);
|
||||
self->month = grib_arguments_get_name(h, c, n++);
|
||||
self->day = grib_arguments_get_name(h, c, n++);
|
||||
self->hour = grib_arguments_get_name(h, c, n++);
|
||||
self->minute = grib_arguments_get_name(h, c, n++);
|
||||
self->second = grib_arguments_get_name(h, c, n++);
|
||||
dateLocal_ = grib_arguments_get_name(h, c, n++);
|
||||
timeLocal_ = grib_arguments_get_name(h, c, n++);
|
||||
numForecasts_ = grib_arguments_get_name(h, c, n++);
|
||||
year_ = grib_arguments_get_name(h, c, n++);
|
||||
month_ = grib_arguments_get_name(h, c, n++);
|
||||
day_ = grib_arguments_get_name(h, c, n++);
|
||||
hour_ = grib_arguments_get_name(h, c, n++);
|
||||
minute_ = grib_arguments_get_name(h, c, n++);
|
||||
second_ = grib_arguments_get_name(h, c, n++);
|
||||
|
||||
a->length = 0;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
void grib_accessor_class_closest_date_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_closest_date_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_string(dumper, a, NULL);
|
||||
grib_dump_string(dumper, this, NULL);
|
||||
}
|
||||
|
||||
int grib_accessor_class_closest_date_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_closest_date_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
int ret = 0;
|
||||
double v = 0;
|
||||
|
||||
ret = unpack_double(a, &v, len);
|
||||
ret = unpack_double(&v, len);
|
||||
*val = (long)v;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Sets val to the 'index' of the closes date */
|
||||
int grib_accessor_class_closest_date_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_closest_date_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
const grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a;
|
||||
|
||||
int err = 0;
|
||||
long num_forecasts = 0; /* numberOfForecastsUsedInLocalTime */
|
||||
/* These relate to the date and time in Section 1 */
|
||||
|
@ -68,56 +64,56 @@ int grib_accessor_class_closest_date_t::unpack_double(grib_accessor* a, double*
|
|||
/* These relate to the forecast dates and times in Section 4 */
|
||||
long *yearArray, *monthArray, *dayArray, *hourArray, *minuteArray, *secondArray;
|
||||
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
const grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
const grib_context* c = context_;
|
||||
*val = -1; /* initialise to an invalid index */
|
||||
|
||||
if ((err = grib_get_long_internal(h, self->numForecasts, &num_forecasts)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_internal(h, numForecasts_, &num_forecasts)) != GRIB_SUCCESS) return err;
|
||||
Assert(num_forecasts > 1);
|
||||
|
||||
if ((err = grib_get_long(h, self->dateLocal, &ymdLocal)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long(h, dateLocal_, &ymdLocal)) != GRIB_SUCCESS) return err;
|
||||
yearLocal = ymdLocal / 10000;
|
||||
ymdLocal %= 10000;
|
||||
monthLocal = ymdLocal / 100;
|
||||
ymdLocal %= 100;
|
||||
dayLocal = ymdLocal;
|
||||
|
||||
if ((err = grib_get_long(h, self->timeLocal, &hmsLocal)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long(h, timeLocal_, &hmsLocal)) != GRIB_SUCCESS) return err;
|
||||
hourLocal = hmsLocal / 100;
|
||||
hmsLocal %= 100;
|
||||
minuteLocal = hmsLocal / 100;
|
||||
hmsLocal %= 100;
|
||||
secondLocal = hmsLocal;
|
||||
|
||||
if ((err = grib_get_size(h, self->year, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_size(h, year_, &size)) != GRIB_SUCCESS) return err;
|
||||
Assert(size == (size_t)num_forecasts);
|
||||
yearArray = (long*)grib_context_malloc_clear(c, size * sizeof(long));
|
||||
if ((err = grib_get_long_array_internal(h, self->year, yearArray, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_array_internal(h, year_, yearArray, &size)) != GRIB_SUCCESS) return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->month, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_size(h, month_, &size)) != GRIB_SUCCESS) return err;
|
||||
Assert(size == (size_t)num_forecasts);
|
||||
monthArray = (long*)grib_context_malloc_clear(c, size * sizeof(long));
|
||||
if ((err = grib_get_long_array_internal(h, self->month, monthArray, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_array_internal(h, month_, monthArray, &size)) != GRIB_SUCCESS) return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->day, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_size(h, day_, &size)) != GRIB_SUCCESS) return err;
|
||||
Assert(size == (size_t)num_forecasts);
|
||||
dayArray = (long*)grib_context_malloc_clear(c, size * sizeof(long));
|
||||
if ((err = grib_get_long_array_internal(h, self->day, dayArray, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_array_internal(h, day_, dayArray, &size)) != GRIB_SUCCESS) return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->hour, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_size(h, hour_, &size)) != GRIB_SUCCESS) return err;
|
||||
Assert(size == (size_t)num_forecasts);
|
||||
hourArray = (long*)grib_context_malloc_clear(c, size * sizeof(long));
|
||||
if ((err = grib_get_long_array_internal(h, self->hour, hourArray, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_array_internal(h, hour_, hourArray, &size)) != GRIB_SUCCESS) return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->minute, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_size(h, minute_, &size)) != GRIB_SUCCESS) return err;
|
||||
Assert(size == (size_t)num_forecasts);
|
||||
minuteArray = (long*)grib_context_malloc_clear(c, size * sizeof(long));
|
||||
if ((err = grib_get_long_array_internal(h, self->minute, minuteArray, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_array_internal(h, minute_, minuteArray, &size)) != GRIB_SUCCESS) return err;
|
||||
|
||||
if ((err = grib_get_size(h, self->second, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_size(h, second_, &size)) != GRIB_SUCCESS) return err;
|
||||
Assert(size == (size_t)num_forecasts);
|
||||
secondArray = (long*)grib_context_malloc_clear(c, size * sizeof(long));
|
||||
if ((err = grib_get_long_array_internal(h, self->second, secondArray, &size)) != GRIB_SUCCESS) return err;
|
||||
if ((err = grib_get_long_array_internal(h, second_, secondArray, &size)) != GRIB_SUCCESS) return err;
|
||||
|
||||
grib_datetime_to_julian(yearLocal, monthLocal, dayLocal, hourLocal, minuteLocal, secondLocal, &jLocal);
|
||||
for (i = 0; i < size; ++i) {
|
||||
|
|
|
@ -16,25 +16,22 @@
|
|||
class grib_accessor_closest_date_t : public grib_accessor_double_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in closest_date */
|
||||
const char *dateLocal;
|
||||
const char *timeLocal;
|
||||
const char *numForecasts;
|
||||
const char *year;
|
||||
const char *month;
|
||||
const char *day;
|
||||
const char *hour;
|
||||
const char *minute;
|
||||
const char *second;
|
||||
};
|
||||
|
||||
class grib_accessor_class_closest_date_t : public grib_accessor_class_double_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_closest_date_t(const char* name) : grib_accessor_class_double_t(name) {}
|
||||
grib_accessor_closest_date_t() :
|
||||
grib_accessor_double_t() { class_name_ = "closest_date"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_closest_date_t{}; }
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* dateLocal_;
|
||||
const char* timeLocal_;
|
||||
const char* numForecasts_;
|
||||
const char* year_;
|
||||
const char* month_;
|
||||
const char* day_;
|
||||
const char* hour_;
|
||||
const char* minute_;
|
||||
const char* second_;
|
||||
};
|
||||
|
|
|
@ -11,17 +11,15 @@
|
|||
|
||||
#include "grib_accessor_class_codeflag.h"
|
||||
|
||||
grib_accessor_class_codeflag_t _grib_accessor_class_codeflag{ "codeflag" };
|
||||
grib_accessor_class* grib_accessor_class_codeflag = &_grib_accessor_class_codeflag;
|
||||
grib_accessor_codeflag_t _grib_accessor_codeflag{};
|
||||
grib_accessor* grib_accessor_codeflag = &_grib_accessor_codeflag;
|
||||
|
||||
|
||||
void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* param)
|
||||
void grib_accessor_codeflag_t::init(const long len, grib_arguments* param)
|
||||
{
|
||||
grib_accessor_class_unsigned_t::init(a, len, param);
|
||||
grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a;
|
||||
a->length = len;
|
||||
self->tablename = grib_arguments_get_string(grib_handle_of_accessor(a), param, 0);
|
||||
Assert(a->length >= 0);
|
||||
grib_accessor_unsigned_t::init(len, param);
|
||||
length_ = len;
|
||||
tablename_ = grib_arguments_get_string(grib_handle_of_accessor(this), param, 0);
|
||||
Assert(length_ >= 0);
|
||||
}
|
||||
|
||||
static int test_bit(long a, long b)
|
||||
|
@ -30,10 +28,9 @@ 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;
|
||||
FILE* f = NULL;
|
||||
char fname[1024];
|
||||
char bval[50];
|
||||
char num[50];
|
||||
|
@ -43,26 +40,26 @@ 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;
|
||||
}
|
||||
|
||||
// strcpy(codename, self->tablename);
|
||||
// strcpy(codename, tablename_ );
|
||||
// strcat(codename,": ");
|
||||
// j = strlen(codename);
|
||||
|
||||
|
@ -70,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, a->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];
|
||||
|
@ -99,24 +96,27 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codeflag_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_codeflag_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void grib_accessor_class_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_codeflag_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a;
|
||||
long v = 0;
|
||||
char flagname[1024] = {0,};
|
||||
char fname[1024] = {0,};
|
||||
long v = 0;
|
||||
char flagname[1024] = {
|
||||
0,
|
||||
};
|
||||
char fname[1024] = {
|
||||
0,
|
||||
};
|
||||
|
||||
size_t llen = 1;
|
||||
|
||||
grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1);
|
||||
a->unpack_long(&v, &llen);
|
||||
grib_get_codeflag(a, v, flagname);
|
||||
grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1);
|
||||
unpack_long(&v, &llen);
|
||||
grib_get_codeflag(v, flagname);
|
||||
|
||||
grib_dump_bits(dumper, a, flagname);
|
||||
grib_dump_bits(dumper, this, flagname);
|
||||
}
|
||||
|
|
|
@ -16,16 +16,15 @@
|
|||
class grib_accessor_codeflag_t : public grib_accessor_unsigned_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in codeflag */
|
||||
const char* tablename;
|
||||
};
|
||||
|
||||
class grib_accessor_class_codeflag_t : public grib_accessor_class_unsigned_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_codeflag_t(const char* name) : grib_accessor_class_unsigned_t(name) {}
|
||||
grib_accessor_codeflag_t() :
|
||||
grib_accessor_unsigned_t() { class_name_ = "codeflag"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_codeflag_t{}; }
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int value_count(long*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* tablename_;
|
||||
|
||||
int grib_get_codeflag(long code, char* codename);
|
||||
};
|
||||
|
|
|
@ -11,10 +11,8 @@
|
|||
#include "grib_accessor_class_codetable.h"
|
||||
#include <cctype>
|
||||
|
||||
|
||||
grib_accessor_class_codetable_t _grib_accessor_class_codetable("codetable");
|
||||
grib_accessor_class* grib_accessor_class_codetable = &_grib_accessor_class_codetable;
|
||||
|
||||
grib_accessor_codetable_t _grib_accessor_codetable{};
|
||||
grib_accessor* grib_accessor_codetable = &_grib_accessor_codetable;
|
||||
|
||||
#if GRIB_PTHREADS
|
||||
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
|
@ -34,7 +32,7 @@ static omp_nest_lock_t mutex1;
|
|||
|
||||
static void init_mutex()
|
||||
{
|
||||
GRIB_OMP_CRITICAL(lock_grib_accessor_class_codetable_c)
|
||||
GRIB_OMP_CRITICAL(lock_grib_accessor_codetable_c)
|
||||
{
|
||||
if (once == 0) {
|
||||
omp_init_nest_lock(&mutex1);
|
||||
|
@ -46,16 +44,17 @@ static void init_mutex()
|
|||
|
||||
static int grib_load_codetable(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_codetable* t);
|
||||
|
||||
void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, grib_arguments* params)
|
||||
void grib_accessor_codetable_t::init(const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_class_unsigned_t::init(a, len, params);
|
||||
grib_accessor_unsigned_t::init(len, params);
|
||||
|
||||
int n = 0;
|
||||
long new_len = len;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
grib_action* act = (grib_action*)(a->creator);
|
||||
DEBUG_ASSERT(len == self->nbytes);
|
||||
int n = 0;
|
||||
long new_len = len;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
grib_action* act = (grib_action*)(creator_);
|
||||
DEBUG_ASSERT(len == nbytes_);
|
||||
table_ = NULL;
|
||||
table_loaded_ = 0;
|
||||
|
||||
if (new_len == 0) {
|
||||
/* ECC-485: When the codetable length is 0, it means we are passing
|
||||
|
@ -64,33 +63,33 @@ void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, gri
|
|||
*/
|
||||
new_len = grib_arguments_get_long(hand, params, n++);
|
||||
if (new_len <= 0) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL, "%s: codetable length must be a positive integer", a->name);
|
||||
grib_context_log(context_, GRIB_LOG_FATAL, "%s: codetable length must be a positive integer", name_);
|
||||
}
|
||||
self->nbytes = new_len;
|
||||
nbytes_ = new_len;
|
||||
}
|
||||
|
||||
self->tablename = grib_arguments_get_string(hand, params, n++);
|
||||
if (self->tablename == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL, "%s: codetable table is invalid", a->name);
|
||||
tablename_ = grib_arguments_get_string(hand, params, n++);
|
||||
if (tablename_ == NULL) {
|
||||
grib_context_log(context_, GRIB_LOG_FATAL, "%s: codetable table is invalid", name_);
|
||||
}
|
||||
self->masterDir = grib_arguments_get_name(hand, params, n++); /* can be NULL */
|
||||
self->localDir = grib_arguments_get_name(hand, params, n++); /* can be NULL */
|
||||
masterDir_ = grib_arguments_get_name(hand, params, n++); /* can be NULL */
|
||||
localDir_ = grib_arguments_get_name(hand, params, n++); /* can be NULL */
|
||||
|
||||
/*if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
|
||||
printf("-------- %s type string (%ld)\n",a->name,a->flags);*/
|
||||
/*if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE)
|
||||
printf("-------- %s type string (%ld)\n",a->name,flags_ );*/
|
||||
#ifdef DEBUG
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL, "codetable '%s' has flag can_be_missing!", a->name);
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) {
|
||||
grib_context_log(context_, GRIB_LOG_FATAL, "codetable '%s' has flag can_be_missing!", name_);
|
||||
Assert(!"codetable with can_be_missing?");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
a->length = 0;
|
||||
if (!a->vvalue)
|
||||
a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value));
|
||||
a->vvalue->type = a->get_native_type();
|
||||
a->vvalue->length = new_len;
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
length_ = 0;
|
||||
if (!vvalue_)
|
||||
vvalue_ = (grib_virtual_value*)grib_context_malloc_clear(context_, sizeof(grib_virtual_value));
|
||||
vvalue_->type = get_native_type();
|
||||
vvalue_->length = new_len;
|
||||
if (act->default_value != NULL) {
|
||||
const char* p = 0;
|
||||
size_t s_len = 1;
|
||||
|
@ -103,29 +102,29 @@ void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, gri
|
|||
switch (type) {
|
||||
case GRIB_TYPE_DOUBLE:
|
||||
grib_expression_evaluate_double(hand, expression, &d);
|
||||
a->pack_double(&d, &s_len);
|
||||
pack_double(&d, &s_len);
|
||||
break;
|
||||
|
||||
case GRIB_TYPE_LONG:
|
||||
grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l);
|
||||
a->pack_long(&l, &s_len);
|
||||
grib_expression_evaluate_long(grib_handle_of_accessor(this), expression, &l);
|
||||
pack_long(&l, &s_len);
|
||||
break;
|
||||
|
||||
default:
|
||||
s_len = sizeof(tmp);
|
||||
p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret);
|
||||
p = grib_expression_evaluate_string(grib_handle_of_accessor(this), expression, tmp, &s_len, &ret);
|
||||
if (ret != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL,
|
||||
"Unable to evaluate %s as string", a->name);
|
||||
grib_context_log(context_, GRIB_LOG_FATAL,
|
||||
"Unable to evaluate %s as string", name_);
|
||||
}
|
||||
s_len = strlen(p) + 1;
|
||||
pack_string(a, p, &s_len);
|
||||
pack_string(p, &s_len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
a->length = new_len;
|
||||
length_ = new_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,43 +163,55 @@ 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_context* c = h->context;
|
||||
grib_codetable* t = NULL;
|
||||
grib_codetable* next = NULL;
|
||||
char* filename = 0;
|
||||
char recomposed[1024] = {0,};
|
||||
char localRecomposed[1024] = {0,};
|
||||
size_t size = 0;
|
||||
grib_handle* h = parent_->h;
|
||||
grib_context* c = h->context;
|
||||
grib_codetable* t = NULL;
|
||||
grib_codetable* next = NULL;
|
||||
char* filename = 0;
|
||||
char recomposed[1024] = {
|
||||
0,
|
||||
};
|
||||
char localRecomposed[1024] = {
|
||||
0,
|
||||
};
|
||||
char* localFilename = 0;
|
||||
char masterDir[1024] = {0,};
|
||||
char localDir[1024] = {0,};
|
||||
char masterDir[1024] = {
|
||||
0,
|
||||
};
|
||||
char localDir[1024] = {
|
||||
0,
|
||||
};
|
||||
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);
|
||||
char name[2048] = {
|
||||
0,
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
if (*localDir != 0) {
|
||||
char localName[2048] = {0,};
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename);
|
||||
char localName[2048] = {
|
||||
0,
|
||||
};
|
||||
snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_);
|
||||
grib_recompose_name(h, NULL, localName, localRecomposed, 0);
|
||||
localFilename = grib_context_full_defs_path(c, localRecomposed);
|
||||
}
|
||||
|
@ -208,7 +219,7 @@ static grib_codetable* load_table(grib_accessor* a)
|
|||
GRIB_MUTEX_INIT_ONCE(&once, &init_mutex);
|
||||
GRIB_MUTEX_LOCK(&mutex1); /* GRIB-930 */
|
||||
|
||||
/*printf("DBG %s: Look in cache: f=%s lf=%s (recomposed=%s)\n", self->att.name, filename, localFilename,recomposed);*/
|
||||
/*printf("DBG %s: Look in cache: f=%s lf=%s (recomposed=%s)\n", att_ .name, filename, localFilename,recomposed);*/
|
||||
if (filename == NULL && localFilename == NULL) {
|
||||
t = NULL;
|
||||
goto the_end;
|
||||
|
@ -232,12 +243,12 @@ static grib_codetable* load_table(grib_accessor* a)
|
|||
next = next->next;
|
||||
}
|
||||
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
Assert(a->vvalue != NULL);
|
||||
size = a->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 */
|
||||
|
@ -294,8 +305,12 @@ static int grib_load_codetable(grib_context* c, const char* filename,
|
|||
while (fgets(line, sizeof(line) - 1, f)) {
|
||||
char* p = line;
|
||||
int code = 0;
|
||||
char abbreviation[1024] = {0,};
|
||||
char title[1024] = {0,};
|
||||
char abbreviation[1024] = {
|
||||
0,
|
||||
};
|
||||
char title[1024] = {
|
||||
0,
|
||||
};
|
||||
char* pAbbrev = abbreviation;
|
||||
char* pTitle = title;
|
||||
char* units = 0;
|
||||
|
@ -421,34 +436,34 @@ void grib_codetable_delete(grib_context* c)
|
|||
|
||||
int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, code_table_entry** entries, size_t* num_entries)
|
||||
{
|
||||
long lvalue = 0;
|
||||
size_t size = 1;
|
||||
int err = 0;
|
||||
long lvalue = 0;
|
||||
size_t size = 1;
|
||||
int err = 0;
|
||||
grib_context* c = h->context;
|
||||
|
||||
grib_accessor* aa = grib_find_accessor(h, key);
|
||||
if (!aa) return GRIB_NOT_FOUND;
|
||||
|
||||
if (!STR_EQUAL(aa->cclass->name, "codetable")) {
|
||||
return GRIB_INVALID_ARGUMENT; // key is not a codetable
|
||||
if (!STR_EQUAL(aa->class_name_, "codetable")) {
|
||||
return GRIB_INVALID_ARGUMENT; // key is not a codetable
|
||||
}
|
||||
|
||||
const grib_accessor_codetable_t* ca = (const grib_accessor_codetable_t*)aa; // could be dynamic_cast
|
||||
const grib_accessor_codetable_t* ca = (const grib_accessor_codetable_t*)aa; // could be dynamic_cast
|
||||
|
||||
// Decode the key itself. This will either fetch it from the cache or place it there
|
||||
if ((err = aa->unpack_long(&lvalue, &size)) != GRIB_SUCCESS) {
|
||||
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
|
||||
grib_codetable* cached_table = c->codetable; // Access the codetable cache
|
||||
while (cached_table) {
|
||||
if (STR_EQUAL(table->recomposed_name[0], cached_table->recomposed_name[0])) {
|
||||
// Found a cache entry that matches the recomposed name of ours
|
||||
*num_entries = cached_table->size;
|
||||
*entries = (code_table_entry*)calloc(cached_table->size, sizeof(code_table_entry));
|
||||
*entries = (code_table_entry*)calloc(cached_table->size, sizeof(code_table_entry));
|
||||
if (!*entries) {
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -466,9 +481,9 @@ int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, c
|
|||
int codes_codetable_check_code_figure(const grib_handle* h, const char* key, long code_figure)
|
||||
{
|
||||
code_table_entry* entries = NULL;
|
||||
size_t num_entries = 0;
|
||||
int err = 0;
|
||||
err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries);
|
||||
size_t num_entries = 0;
|
||||
int err = 0;
|
||||
err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries);
|
||||
if (err) return err;
|
||||
|
||||
if (code_figure < 0 || (size_t)code_figure >= num_entries) {
|
||||
|
@ -488,13 +503,13 @@ cleanup:
|
|||
int codes_codetable_check_abbreviation(const grib_handle* h, const char* key, const char* abbreviation)
|
||||
{
|
||||
code_table_entry* entries = NULL;
|
||||
size_t num_entries = 0;
|
||||
int err = 0;
|
||||
err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries);
|
||||
size_t num_entries = 0;
|
||||
int err = 0;
|
||||
err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries);
|
||||
if (err) return err;
|
||||
|
||||
bool found = false;
|
||||
for (size_t i=0; i<num_entries; ++i) {
|
||||
for (size_t i = 0; i < num_entries; ++i) {
|
||||
const char* abbrev = entries[i].abbreviation;
|
||||
if (abbrev && STR_EQUAL(abbrev, abbreviation)) {
|
||||
found = true;
|
||||
|
@ -507,26 +522,25 @@ int codes_codetable_check_abbreviation(const grib_handle* h, const char* key, co
|
|||
return err;
|
||||
}
|
||||
|
||||
void grib_accessor_class_codetable_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_codetable_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
char comment[2048];
|
||||
grib_codetable* table;
|
||||
|
||||
size_t llen = 1;
|
||||
long value;
|
||||
|
||||
if (!self->table_loaded) {
|
||||
self->table = load_table(a); /* may return NULL */
|
||||
self->table_loaded = 1;
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
table = self->table;
|
||||
table = table_;
|
||||
|
||||
a->unpack_long(&value, &llen);
|
||||
unpack_long(&value, &llen);
|
||||
|
||||
if (value == GRIB_MISSING_LONG) {
|
||||
if (a->length < 4) {
|
||||
value = (1L << a->length) - 1;
|
||||
if (length_ < 4) {
|
||||
value = (1L << length_) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,13 +576,12 @@ void grib_accessor_class_codetable_t::dump(grib_accessor* a, grib_dumper* dumper
|
|||
}
|
||||
strcat(comment, ") ");
|
||||
|
||||
grib_dump_long(dumper, a, comment);
|
||||
grib_dump_long(dumper, this, comment);
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
||||
int grib_accessor_codetable_t::unpack_string(char* buffer, size_t* len)
|
||||
{
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
grib_codetable* table = NULL;
|
||||
grib_codetable* table = NULL;
|
||||
|
||||
size_t size = 1;
|
||||
long value;
|
||||
|
@ -576,14 +589,14 @@ int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffe
|
|||
char tmp[1024];
|
||||
size_t l = 0;
|
||||
|
||||
if ((err = a->unpack_long(&value, &size)) != GRIB_SUCCESS)
|
||||
if ((err = unpack_long(&value, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (!self->table_loaded) {
|
||||
self->table = load_table(a); /* may return NULL */
|
||||
self->table_loaded = 1;
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
table = self->table;
|
||||
table = table_;
|
||||
|
||||
if (table && (value >= 0) && (value < table->size) && table->entries[value].abbreviation) {
|
||||
strcpy(tmp, table->entries[value].abbreviation);
|
||||
|
@ -595,10 +608,10 @@ int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffe
|
|||
l = strlen(tmp) + 1;
|
||||
|
||||
if (*len < l) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
const char* cclass_name = class_name_;
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
cclass_name, name_, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
@ -609,7 +622,7 @@ int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffe
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_codetable_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
|
@ -632,36 +645,35 @@ bool strings_equal(const char* s1, const char* s2, bool case_sensitive)
|
|||
return (strcmp_nocase(s1, s2) == 0);
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* buffer, size_t* len)
|
||||
int grib_accessor_codetable_t::pack_string(const char* buffer, size_t* len)
|
||||
{
|
||||
long lValue = 0;
|
||||
Assert(buffer);
|
||||
if (is_number(buffer) && string_to_long(buffer, &lValue, 1) == GRIB_SUCCESS) {
|
||||
// ECC-1654: If value is a pure number, just pack as long
|
||||
size_t l = 1;
|
||||
return a->pack_long(&lValue, &l);
|
||||
return pack_long(&lValue, &l);
|
||||
}
|
||||
|
||||
if (STR_EQUAL_NOCASE(buffer, "missing")) {
|
||||
return pack_missing(a);
|
||||
return pack_missing();
|
||||
}
|
||||
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
grib_codetable* table = NULL;
|
||||
long i = 0;
|
||||
size_t size = 1;
|
||||
long i = 0;
|
||||
size_t size = 1;
|
||||
|
||||
if (!self->table_loaded) {
|
||||
self->table = load_table(a); /* may return NULL */
|
||||
self->table_loaded = 1;
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
table = self->table;
|
||||
table = table_;
|
||||
|
||||
if (!table)
|
||||
return GRIB_ENCODING_ERROR;
|
||||
|
||||
if (a->set) {
|
||||
int err = grib_set_string(grib_handle_of_accessor(a), a->set, buffer, len);
|
||||
if (set_) {
|
||||
int err = grib_set_string(grib_handle_of_accessor(this), set_, buffer, len);
|
||||
if (err != 0)
|
||||
return err;
|
||||
}
|
||||
|
@ -669,48 +681,50 @@ int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* b
|
|||
// If the key has the "lowercase" flag set, then the string comparison
|
||||
// should ignore the case
|
||||
bool case_sensitive = true;
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_LOWERCASE) case_sensitive = false;
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_LOWERCASE) case_sensitive = false;
|
||||
|
||||
for (i = 0; i < table->size; i++) {
|
||||
if (table->entries[i].abbreviation) {
|
||||
if (strings_equal(table->entries[i].abbreviation, buffer, case_sensitive)) {
|
||||
return a->pack_long(&i, &size);
|
||||
return pack_long(&i, &size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_NO_FAIL) {
|
||||
grib_action* act = (grib_action*)(a->creator);
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_NO_FAIL) {
|
||||
grib_action* act = (grib_action*)(creator_);
|
||||
if (act->default_value != NULL) {
|
||||
const char* p = 0;
|
||||
size_t s_len = 1;
|
||||
long l = 0;
|
||||
int ret = 0;
|
||||
double d = 0;
|
||||
char tmp[1024] = {0,};
|
||||
grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(a), act->default_value, 0);
|
||||
int type = grib_expression_native_type(grib_handle_of_accessor(a), expression);
|
||||
const char* p = 0;
|
||||
size_t s_len = 1;
|
||||
long l = 0;
|
||||
int ret = 0;
|
||||
double d = 0;
|
||||
char tmp[1024] = {
|
||||
0,
|
||||
};
|
||||
grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(this), act->default_value, 0);
|
||||
int type = grib_expression_native_type(grib_handle_of_accessor(this), expression);
|
||||
switch (type) {
|
||||
case GRIB_TYPE_DOUBLE:
|
||||
grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d);
|
||||
a->pack_double(&d, &s_len);
|
||||
grib_expression_evaluate_double(grib_handle_of_accessor(this), expression, &d);
|
||||
pack_double(&d, &s_len);
|
||||
break;
|
||||
|
||||
case GRIB_TYPE_LONG:
|
||||
grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l);
|
||||
a->pack_long(&l, &s_len);
|
||||
grib_expression_evaluate_long(grib_handle_of_accessor(this), expression, &l);
|
||||
pack_long(&l, &s_len);
|
||||
break;
|
||||
|
||||
default:
|
||||
s_len = sizeof(tmp);
|
||||
p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret);
|
||||
p = grib_expression_evaluate_string(grib_handle_of_accessor(this), expression, tmp, &s_len, &ret);
|
||||
if (ret != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s: Unable to evaluate default value of %s as string expression", __func__, a->name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Unable to evaluate default value of %s as string expression", __func__, name_);
|
||||
return ret;
|
||||
}
|
||||
s_len = strlen(p) + 1;
|
||||
pack_string(a, p, &s_len);
|
||||
pack_string(p, &s_len);
|
||||
break;
|
||||
}
|
||||
return GRIB_SUCCESS;
|
||||
|
@ -721,10 +735,10 @@ int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* b
|
|||
for (i = 0; i < table->size; i++) {
|
||||
if (table->entries[i].abbreviation) {
|
||||
if (strcmp_nocase(table->entries[i].abbreviation, buffer) == 0) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: No such code table entry: '%s' "
|
||||
"(Did you mean '%s'?)",
|
||||
a->name, buffer, table->entries[i].abbreviation);
|
||||
name_, buffer, table->entries[i].abbreviation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -732,124 +746,122 @@ int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* b
|
|||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::pack_expression(grib_accessor* a, grib_expression* e)
|
||||
int grib_accessor_codetable_t::pack_expression(grib_expression* e)
|
||||
{
|
||||
const char* cval = NULL;
|
||||
int ret = 0;
|
||||
long lval = 0;
|
||||
size_t len = 1;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
if (strcmp(e->cclass->name, "long") == 0) {
|
||||
grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */
|
||||
//if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %ld\n", a->name,lval);
|
||||
ret = a->pack_long(&lval, &len);
|
||||
// if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_codetable::pack_expression %s %ld\n", name_ ,lval);
|
||||
ret = pack_long(&lval, &len);
|
||||
}
|
||||
else {
|
||||
char tmp[1024];
|
||||
len = sizeof(tmp);
|
||||
cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret);
|
||||
if (ret != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"grib_accessor_codetable.%s: Unable to evaluate string %s to be set in %s",
|
||||
__func__, grib_expression_get_name(e), a->name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"grib_accessor_codetable.%s: Unable to evaluate string %s to be set in %s",
|
||||
__func__, grib_expression_get_name(e), name_);
|
||||
return ret;
|
||||
}
|
||||
len = strlen(cval) + 1;
|
||||
//if (hand->context->debug)
|
||||
// printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval);
|
||||
ret = a->pack_string(cval, &len);
|
||||
// if (hand->context->debug)
|
||||
// printf("ECCODES DEBUG grib_accessor_codetable::pack_expression %s %s\n", name_ , cval);
|
||||
ret = pack_string(cval, &len);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void grib_accessor_class_codetable_t::destroy(grib_context* context, grib_accessor* a)
|
||||
void grib_accessor_codetable_t::destroy(grib_context* context)
|
||||
{
|
||||
if (a->vvalue != NULL) {
|
||||
grib_context_free(context, a->vvalue);
|
||||
a->vvalue = NULL;
|
||||
if (vvalue_ != NULL) {
|
||||
grib_context_free(context, vvalue_);
|
||||
vvalue_ = NULL;
|
||||
}
|
||||
grib_accessor_class_unsigned_t::destroy(context, a);
|
||||
grib_accessor_unsigned_t::destroy(context);
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_codetable_t::get_native_type()
|
||||
{
|
||||
int type = GRIB_TYPE_LONG;
|
||||
/*printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n",
|
||||
a->name,a->flags,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
|
||||
a->name,flags_ ,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE)
|
||||
type = GRIB_TYPE_STRING;
|
||||
return type;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_codetable_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
long rlen = 0, i = 0;
|
||||
long pos = a->offset * 8;
|
||||
long pos = offset_ * 8;
|
||||
grib_handle* hand = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
int err = a->value_count(&rlen);
|
||||
int err = value_count(&rlen);
|
||||
Assert(!err);
|
||||
Assert(rlen == 1);
|
||||
}
|
||||
#endif
|
||||
rlen = 1; /* ECC-480 Performance: avoid func call overhead of grib_value_count */
|
||||
|
||||
if (!self->table_loaded) {
|
||||
self->table = load_table(a); /* may return NULL */
|
||||
self->table_loaded = 1;
|
||||
if (!table_loaded_) {
|
||||
table_ = load_table(); /* may return NULL */
|
||||
table_loaded_ = 1;
|
||||
}
|
||||
|
||||
if (*len < rlen) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%lu) for %s, it contains %ld values",
|
||||
*len, a->name, rlen);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size (%lu) for %s, it contains %ld values",
|
||||
*len, name_, rlen);
|
||||
*len = 0;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
*val = a->vvalue->lval;
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
|
||||
*val = vvalue_->lval;
|
||||
*len = 1;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
/* ECC-480 Performance: inline the grib_handle_of_accessor here to reduce func call overhead */
|
||||
if (a->parent == NULL)
|
||||
hand = a->h;
|
||||
if (parent_ == NULL)
|
||||
hand = h_;
|
||||
else
|
||||
hand = a->parent->h;
|
||||
hand = parent_->h;
|
||||
|
||||
for (i = 0; i < rlen; i++) {
|
||||
val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, self->nbytes * 8);
|
||||
val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, nbytes_ * 8);
|
||||
}
|
||||
|
||||
*len = rlen;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_t::pack_missing(grib_accessor* a)
|
||||
int grib_accessor_codetable_t::pack_missing()
|
||||
{
|
||||
// Many of the code tables do have a 'Missing' entry (all bits = 1)
|
||||
// So it is more user-friendly to allow setting codetable keys to
|
||||
// missing. For tables that do not have such an entry, an error is issued
|
||||
grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
|
||||
const long nbytes = a->length;
|
||||
const long nbits = nbytes*8;
|
||||
const long maxVal = (1<<nbits) - 1;
|
||||
const long nbytes = length_;
|
||||
const long nbits = nbytes * 8;
|
||||
const long maxVal = (1 << nbits) - 1;
|
||||
|
||||
int err = codes_codetable_check_code_figure(h, a->name, maxVal);
|
||||
int err = codes_codetable_check_code_figure(h, name_, maxVal);
|
||||
if (!err) {
|
||||
size_t l = 1;
|
||||
return a->pack_long(&maxVal, &l);
|
||||
return pack_long(&maxVal, &l);
|
||||
}
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "There is no 'missing' entry in Code Table %s (%s)",
|
||||
self->tablename, grib_get_error_message(err));
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "There is no 'missing' entry in Code Table %s (%s)",
|
||||
tablename_, grib_get_error_message(err));
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -15,27 +15,29 @@
|
|||
|
||||
class grib_accessor_codetable_t : public grib_accessor_unsigned_t
|
||||
{
|
||||
public:
|
||||
const char* tablename;
|
||||
const char* masterDir;
|
||||
const char* localDir;
|
||||
grib_codetable* table;
|
||||
int table_loaded;
|
||||
};
|
||||
|
||||
class grib_accessor_class_codetable_t : public grib_accessor_class_unsigned_t
|
||||
{
|
||||
public:
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_t{}; }
|
||||
grib_accessor_class_codetable_t(const char* name) : grib_accessor_class_unsigned_t(name) {}
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_missing(grib_accessor*) override;
|
||||
int pack_string(grib_accessor*, const char*, size_t* len) override;
|
||||
int pack_expression(grib_accessor*, grib_expression*) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
grib_accessor_codetable_t() :
|
||||
grib_accessor_unsigned_t() { class_name_ = "codetable"; }
|
||||
long get_native_type() override;
|
||||
int pack_missing() override;
|
||||
int pack_string(const char*, size_t* len) override;
|
||||
int pack_expression(grib_expression*) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
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();
|
||||
};
|
||||
|
|
|
@ -12,40 +12,38 @@
|
|||
#include "grib_accessor_class_codetable_title.h"
|
||||
#include "grib_accessor_class_codetable.h"
|
||||
|
||||
grib_accessor_class_codetable_title_t _grib_accessor_class_codetable_title{ "codetable_title" };
|
||||
grib_accessor_class* grib_accessor_class_codetable_title = &_grib_accessor_class_codetable_title;
|
||||
grib_accessor_codetable_title_t _grib_accessor_codetable_title{};
|
||||
grib_accessor* grib_accessor_codetable_title = &_grib_accessor_codetable_title;
|
||||
|
||||
void grib_accessor_class_codetable_title_t::init(grib_accessor* a, const long len, grib_arguments* params)
|
||||
void grib_accessor_codetable_title_t::init(const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, params);
|
||||
grib_accessor_codetable_title_t* self = (grib_accessor_codetable_title_t*)a;
|
||||
int n = 0;
|
||||
self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
grib_accessor_gen_t::init(len, params);
|
||||
int n = 0;
|
||||
codetable_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++);
|
||||
length_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_title_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_codetable_title_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_STRING;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_title_t::unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
||||
int grib_accessor_codetable_title_t::unpack_string(char* buffer, size_t* len)
|
||||
{
|
||||
grib_accessor_codetable_title_t* self = (grib_accessor_codetable_title_t*)a;
|
||||
grib_codetable* table = NULL;
|
||||
|
||||
size_t size = 1;
|
||||
long value;
|
||||
int err = GRIB_SUCCESS;
|
||||
char tmp[1024];
|
||||
size_t l = 1024;
|
||||
grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable);
|
||||
size_t l = 1024;
|
||||
grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(this), codetable_);
|
||||
|
||||
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);
|
||||
|
@ -57,10 +55,10 @@ int grib_accessor_class_codetable_title_t::unpack_string(grib_accessor* a, char*
|
|||
l = strlen(tmp) + 1;
|
||||
|
||||
if (*len < l) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
const char* cclass_name = class_name_;
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
cclass_name, name_, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
|
|
@ -16,16 +16,13 @@
|
|||
class grib_accessor_codetable_title_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in codetable_title */
|
||||
const char* codetable;
|
||||
};
|
||||
|
||||
class grib_accessor_class_codetable_title_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_codetable_title_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_codetable_title_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "codetable_title"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_title_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* codetable_;
|
||||
};
|
||||
|
|
|
@ -12,41 +12,39 @@
|
|||
#include "grib_accessor_class_codetable_units.h"
|
||||
#include "grib_accessor_class_codetable.h"
|
||||
|
||||
grib_accessor_class_codetable_units_t _grib_accessor_class_codetable_units{ "codetable_units" };
|
||||
grib_accessor_class* grib_accessor_class_codetable_units = &_grib_accessor_class_codetable_units;
|
||||
grib_accessor_codetable_units_t _grib_accessor_codetable_units{};
|
||||
grib_accessor* grib_accessor_codetable_units = &_grib_accessor_codetable_units;
|
||||
|
||||
void grib_accessor_class_codetable_units_t::init(grib_accessor* a, const long len, grib_arguments* params)
|
||||
void grib_accessor_codetable_units_t::init(const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, params);
|
||||
grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a;
|
||||
grib_accessor_gen_t::init(len, params);
|
||||
|
||||
int n = 0;
|
||||
self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
int n = 0;
|
||||
codetable_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++);
|
||||
length_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_units_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_codetable_units_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_STRING;
|
||||
}
|
||||
|
||||
int grib_accessor_class_codetable_units_t::unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
||||
int grib_accessor_codetable_units_t::unpack_string(char* buffer, size_t* len)
|
||||
{
|
||||
grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a;
|
||||
grib_codetable* table = NULL;
|
||||
grib_codetable* table = NULL;
|
||||
|
||||
size_t size = 1;
|
||||
long value;
|
||||
int err = GRIB_SUCCESS;
|
||||
char tmp[1024];
|
||||
size_t l = sizeof(tmp);
|
||||
grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable);
|
||||
size_t l = sizeof(tmp);
|
||||
grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(this), codetable_);
|
||||
|
||||
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);
|
||||
|
@ -58,10 +56,10 @@ int grib_accessor_class_codetable_units_t::unpack_string(grib_accessor* a, char*
|
|||
l = strlen(tmp) + 1;
|
||||
|
||||
if (*len < l) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
const char* cclass_name = class_name_;
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
cclass_name, name_, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
|
|
@ -16,16 +16,13 @@
|
|||
class grib_accessor_codetable_units_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in codetable_units */
|
||||
const char* codetable;
|
||||
};
|
||||
|
||||
class grib_accessor_class_codetable_units_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_codetable_units_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_codetable_units_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "codetable_units"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_units_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
long get_native_type() override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* codetable_;
|
||||
};
|
||||
|
|
|
@ -10,14 +10,12 @@
|
|||
*/
|
||||
|
||||
#include "grib_accessor_class_concept.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
grib_accessor_class_concept_t _grib_accessor_class_concept{ "concept" };
|
||||
grib_accessor_class* grib_accessor_class_concept = &_grib_accessor_class_concept;
|
||||
|
||||
grib_accessor_concept_t _grib_accessor_concept{};
|
||||
grib_accessor* grib_accessor_concept = &_grib_accessor_concept;
|
||||
|
||||
#define MAX_CONCEPT_STRING_LENGTH 255
|
||||
|
||||
|
@ -37,15 +35,15 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
|||
return (*a == 0 && *b == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
void grib_accessor_class_concept_t::init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
void grib_accessor_concept_t::init(const long len, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, len, args);
|
||||
a->length = 0;
|
||||
grib_accessor_gen_t::init(len, args);
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
void grib_accessor_class_concept_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_concept_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_string(dumper, a, NULL);
|
||||
grib_dump_string(dumper, this, NULL);
|
||||
}
|
||||
|
||||
// See ECC-1905
|
||||
|
@ -166,8 +164,8 @@ static const char* concept_evaluate(grib_accessor* a)
|
|||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
|
||||
std::unordered_map<std::string_view, long> memo; // See ECC-1905
|
||||
|
||||
//fprintf(stderr, "DEBUG: concept_evaluate: %s %s\n", a->name, c->name);
|
||||
|
||||
// fprintf(stderr, "DEBUG: concept_evaluate: %s %s\n", name_ , c->name);
|
||||
while (c) {
|
||||
grib_concept_condition* e = c->conditions;
|
||||
int cnt = 0;
|
||||
|
@ -285,7 +283,7 @@ static int grib_concept_apply(grib_accessor* a, const char* name)
|
|||
grib_concept_value* c = NULL;
|
||||
grib_concept_value* concepts = action_concept_get_concept(a);
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_action* act = a->creator;
|
||||
grib_action* act = a->creator_;
|
||||
int nofail = action_concept_get_nofail(a);
|
||||
|
||||
DEBUG_ASSERT(concepts);
|
||||
|
@ -300,7 +298,9 @@ static int grib_concept_apply(grib_accessor* a, const char* name)
|
|||
if (err) {
|
||||
size_t i = 0, concept_count = 0;
|
||||
long dummy = 0, editionNumber = 0;
|
||||
char centre_s[32] = {0,};
|
||||
char centre_s[32] = {
|
||||
0,
|
||||
};
|
||||
size_t centre_len = sizeof(centre_s);
|
||||
char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = {
|
||||
NULL,
|
||||
|
@ -378,12 +378,12 @@ static int grib_concept_apply(grib_accessor* a, const char* name)
|
|||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_concept_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
int grib_accessor_concept_t::pack_long(const long* val, size_t* len)
|
||||
{
|
||||
char buf[80];
|
||||
size_t s;
|
||||
|
@ -393,16 +393,16 @@ int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val,
|
|||
// return GRIB_NOT_IMPLEMENTED;
|
||||
|
||||
// ECC-1806: GRIB: Change of paramId in conversion from GRIB1 to GRIB2
|
||||
if (STR_EQUAL(a->name, "paramId")) {
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
if (STR_EQUAL(name_, "paramId")) {
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
long edition = 0;
|
||||
if (grib_get_long(h, "edition", &edition) == GRIB_SUCCESS && edition == 2) {
|
||||
long newParamId = 0;
|
||||
if (grib_get_long(h, "paramIdForConversion", &newParamId) == GRIB_SUCCESS && newParamId > 0) {
|
||||
if (a->context->debug) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
if (context_->debug) {
|
||||
const char* cclass_name = class_name_;
|
||||
fprintf(stderr, "ECCODES DEBUG %s::%s: Changing %s from %ld to %ld\n",
|
||||
cclass_name, __func__, a->name, *val, newParamId);
|
||||
cclass_name, __func__, name_, *val, newParamId);
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%ld", newParamId);
|
||||
}
|
||||
|
@ -410,10 +410,10 @@ int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val,
|
|||
}
|
||||
|
||||
s = strlen(buf) + 1;
|
||||
return pack_string(a, buf, &s);
|
||||
return pack_string(buf, &s);
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_concept_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
/*
|
||||
* If we want to have a condition which contains tests for paramId as well
|
||||
|
@ -423,20 +423,20 @@ int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val,
|
|||
*/
|
||||
/*return GRIB_NOT_IMPLEMENTED*/
|
||||
int ret = 0;
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) {
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE) {
|
||||
long lval = 0;
|
||||
ret = unpack_long(a, &lval, len);
|
||||
ret = unpack_long(&lval, len);
|
||||
if (ret == GRIB_SUCCESS) {
|
||||
*val = lval;
|
||||
}
|
||||
}
|
||||
else if (a->flags & GRIB_ACCESSOR_FLAG_DOUBLE_TYPE) {
|
||||
const char* p = concept_evaluate(a);
|
||||
else if (flags_ & GRIB_ACCESSOR_FLAG_DOUBLE_TYPE) {
|
||||
const char* p = concept_evaluate(this);
|
||||
|
||||
if (!p) {
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
if (a->creator->defaultkey)
|
||||
return grib_get_double_internal(h, a->creator->defaultkey, val);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
if (creator_->defaultkey)
|
||||
return grib_get_double_internal(h, creator_->defaultkey, val);
|
||||
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
@ -446,14 +446,14 @@ int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_concept_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
const char* p = concept_evaluate(a);
|
||||
const char* p = concept_evaluate(this);
|
||||
|
||||
if (!p) {
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
if (a->creator->defaultkey)
|
||||
return grib_get_long_internal(h, a->creator->defaultkey, val);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
if (creator_->defaultkey)
|
||||
return grib_get_long_internal(h, creator_->defaultkey, val);
|
||||
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
@ -471,9 +471,9 @@ int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size
|
|||
if (endptr == p || *endptr != '\0') {
|
||||
/* Failed to convert string into integer */
|
||||
int type = GRIB_TYPE_UNDEFINED;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack %s as long", a->name);
|
||||
if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type));
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Cannot unpack %s as long", name_);
|
||||
if (grib_get_native_type(grib_handle_of_accessor(this), name_, &type) == GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type));
|
||||
}
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
@ -482,73 +482,73 @@ int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_concept_t::get_native_type()
|
||||
{
|
||||
int type = GRIB_TYPE_STRING;
|
||||
if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE)
|
||||
if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE)
|
||||
type = GRIB_TYPE_LONG;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
void grib_accessor_class_concept_t::destroy(grib_context* c, grib_accessor* a)
|
||||
void grib_accessor_concept_t::destroy(grib_context* c)
|
||||
{
|
||||
// grib_accessor_concept_t *self = (grib_accessor_concept_t*)a;
|
||||
// grib_context_free(c,self->cval);
|
||||
grib_accessor_class_gen_t::destroy(c, a);
|
||||
// grib_context_free(c,cval_ );
|
||||
grib_accessor_gen_t::destroy(c);
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
int grib_accessor_concept_t::unpack_string(char* val, size_t* len)
|
||||
{
|
||||
size_t slen;
|
||||
const char* p = concept_evaluate(a);
|
||||
const char* p = concept_evaluate(this);
|
||||
|
||||
if (!p) {
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
if (a->creator->defaultkey)
|
||||
return grib_get_string_internal(h, a->creator->defaultkey, val, len);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
if (creator_->defaultkey)
|
||||
return grib_get_string_internal(h, creator_->defaultkey, val, len);
|
||||
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
slen = strlen(p) + 1;
|
||||
if (*len < slen) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"Concept unpack_string. Buffer too small for %s, value='%s' which requires %lu bytes (len=%lu)",
|
||||
a->name, p, slen, *len);
|
||||
name_, p, slen, *len);
|
||||
*len = slen;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
strcpy(val, p); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */
|
||||
*len = slen;
|
||||
|
||||
// if (a->context->debug==1) {
|
||||
// if (context_ ->debug==1) {
|
||||
// int err = 0;
|
||||
// char result[1024] = {0,};
|
||||
// err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result);
|
||||
// if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result);
|
||||
// err = get_concept_condition_string(grib_handle_of_accessor(this), name_ , val, result);
|
||||
// if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", name_ , val, result);
|
||||
// }
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::pack_string(grib_accessor* a, const char* val, size_t* len)
|
||||
int grib_accessor_concept_t::pack_string(const char* val, size_t* len)
|
||||
{
|
||||
return grib_concept_apply(a, val);
|
||||
return grib_concept_apply(this, val);
|
||||
}
|
||||
|
||||
size_t grib_accessor_class_concept_t::string_length(grib_accessor* a)
|
||||
size_t grib_accessor_concept_t::string_length()
|
||||
{
|
||||
return MAX_CONCEPT_STRING_LENGTH;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_concept_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b)
|
||||
int grib_accessor_concept_t::compare(grib_accessor* b)
|
||||
{
|
||||
int retval = 0;
|
||||
char* aval = 0;
|
||||
|
@ -559,7 +559,7 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b)
|
|||
int err = 0;
|
||||
long count = 0;
|
||||
|
||||
err = a->value_count(&count);
|
||||
err = value_count(&count);
|
||||
if (err) return err;
|
||||
alen = count;
|
||||
|
||||
|
@ -572,10 +572,10 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b)
|
|||
alen = MAX_CONCEPT_STRING_LENGTH;
|
||||
blen = MAX_CONCEPT_STRING_LENGTH;
|
||||
|
||||
aval = (char*)grib_context_malloc(a->context, alen * sizeof(char));
|
||||
bval = (char*)grib_context_malloc(b->context, blen * sizeof(char));
|
||||
aval = (char*)grib_context_malloc(context_, alen * sizeof(char));
|
||||
bval = (char*)grib_context_malloc(b->context_, blen * sizeof(char));
|
||||
|
||||
err = a->unpack_string(aval, &alen);
|
||||
err = unpack_string(aval, &alen);
|
||||
if (err) return err;
|
||||
err = b->unpack_string(bval, &blen);
|
||||
if (err) return err;
|
||||
|
@ -584,8 +584,8 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b)
|
|||
if (!aval || !bval || grib_inline_strcmp(aval, bval))
|
||||
retval = GRIB_STRING_VALUE_MISMATCH;
|
||||
|
||||
grib_context_free(a->context, aval);
|
||||
grib_context_free(b->context, bval);
|
||||
grib_context_free(context_, aval);
|
||||
grib_context_free(b->context_, bval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -16,25 +16,20 @@
|
|||
class grib_accessor_concept_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in concept */
|
||||
};
|
||||
|
||||
class grib_accessor_class_concept_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_concept_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_concept_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "concept"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_concept_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int pack_long(grib_accessor*, const long* val, size_t* len) override;
|
||||
int pack_string(grib_accessor*, const char*, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int unpack_string(grib_accessor*, char*, size_t* len) override;
|
||||
size_t string_length(grib_accessor*) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*, grib_accessor*) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int pack_long(const long* val, size_t* len) override;
|
||||
int pack_string(const char*, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int unpack_string(char*, size_t* len) override;
|
||||
size_t string_length() override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*) override;
|
||||
};
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
|
||||
#include "grib_accessor_class_constant.h"
|
||||
|
||||
grib_accessor_class_constant_t _grib_accessor_class_constant{"constant"};
|
||||
grib_accessor_class* grib_accessor_class_constant = &_grib_accessor_class_constant;
|
||||
grib_accessor_constant_t _grib_accessor_constant{};
|
||||
grib_accessor* grib_accessor_constant = &_grib_accessor_constant;
|
||||
|
||||
void grib_accessor_class_constant_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_constant_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_variable_t::init(a, len, arg);
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
grib_accessor_variable_t::init(len, arg);
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
#include "grib_accessor_class_variable.h"
|
||||
|
||||
class grib_accessor_constant_t : public grib_accessor_variable_t {};
|
||||
|
||||
class grib_accessor_class_constant_t : public grib_accessor_class_variable_t
|
||||
class grib_accessor_constant_t : public grib_accessor_variable_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_constant_t(const char* name) : grib_accessor_class_variable_t(name) {}
|
||||
grib_accessor_constant_t() :
|
||||
grib_accessor_variable_t() { class_name_ = "constant"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_constant_t{}; }
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
};
|
||||
|
|
|
@ -11,20 +11,19 @@
|
|||
|
||||
#include "grib_accessor_class_count_file.h"
|
||||
|
||||
grib_accessor_class_count_file_t _grib_accessor_class_count_file{ "count_file" };
|
||||
grib_accessor_class* grib_accessor_class_count_file = &_grib_accessor_class_count_file;
|
||||
grib_accessor_count_file_t _grib_accessor_count_file{};
|
||||
grib_accessor* grib_accessor_count_file = &_grib_accessor_count_file;
|
||||
|
||||
|
||||
void grib_accessor_class_count_file_t::init(grib_accessor* a, const long l, grib_arguments* c)
|
||||
void grib_accessor_count_file_t::init(const long l, grib_arguments* c)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, l, c);
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
a->length = 0;
|
||||
grib_accessor_long_t::init(l, c);
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_count_file_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_count_file_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
*val = grib_context_get_handle_file_count(a->context);
|
||||
*val = grib_context_get_handle_file_count(context_);
|
||||
*len = 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,14 +16,9 @@
|
|||
class grib_accessor_count_file_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in count_file */
|
||||
};
|
||||
|
||||
class grib_accessor_class_count_file_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_count_file_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_count_file_t() :
|
||||
grib_accessor_long_t() { class_name_ = "count_file"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_count_file_t{}; }
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
};
|
||||
|
|
|
@ -11,9 +11,8 @@
|
|||
|
||||
#include "grib_accessor_class_count_missing.h"
|
||||
|
||||
grib_accessor_class_count_missing_t _grib_accessor_class_count_missing{ "count_missing" };
|
||||
grib_accessor_class* grib_accessor_class_count_missing = &_grib_accessor_class_count_missing;
|
||||
|
||||
grib_accessor_count_missing_t _grib_accessor_count_missing{};
|
||||
grib_accessor* grib_accessor_count_missing = &_grib_accessor_count_missing;
|
||||
|
||||
static const unsigned char bitsoff[] = {
|
||||
8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, 7,
|
||||
|
@ -34,25 +33,24 @@ static const unsigned char bitsoff[] = {
|
|||
0
|
||||
};
|
||||
|
||||
void grib_accessor_class_count_missing_t::init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||
void grib_accessor_count_missing_t::init(const long len, grib_arguments* arg)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, len, arg);
|
||||
int n = 0;
|
||||
grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
self->bitmap = grib_arguments_get_name(h, arg, n++);
|
||||
self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++);
|
||||
self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++);
|
||||
self->missingValueManagementUsed = grib_arguments_get_name(h, arg, n++); /* Can be NULL */
|
||||
grib_accessor_long_t::init(len, arg);
|
||||
int n = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
length_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
bitmap_ = grib_arguments_get_name(h, arg, n++);
|
||||
unusedBitsInBitmap_ = grib_arguments_get_name(h, arg, n++);
|
||||
numberOfDataPoints_ = grib_arguments_get_name(h, arg, n++);
|
||||
missingValueManagementUsed_ = grib_arguments_get_name(h, arg, n++); /* Can be NULL */
|
||||
}
|
||||
|
||||
static const int used[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
|
||||
|
||||
static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing)
|
||||
{
|
||||
int err = 0;
|
||||
int err = 0;
|
||||
long count_of_missing = 0;
|
||||
size_t vsize = 0, ii = 0;
|
||||
double* values = NULL;
|
||||
|
@ -74,24 +72,23 @@ static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing)
|
|||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_count_missing_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a;
|
||||
unsigned char* p;
|
||||
int i;
|
||||
long size = 0;
|
||||
long offset = 0;
|
||||
long unusedBitsInBitmap = 0;
|
||||
long numberOfDataPoints = 0;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_accessor* bitmap = grib_find_accessor(h, self->bitmap);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
grib_accessor* bitmap = grib_find_accessor(h, bitmap_);
|
||||
|
||||
*val = 0; /* By default assume none are missing */
|
||||
*len = 1;
|
||||
if (!bitmap) {
|
||||
long mvmu = 0;
|
||||
if (self->missingValueManagementUsed &&
|
||||
grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0) {
|
||||
if (missingValueManagementUsed_ &&
|
||||
grib_get_long(h, missingValueManagementUsed_, &mvmu) == GRIB_SUCCESS && mvmu != 0) {
|
||||
/* ECC-523: No bitmap. Missing values are encoded in the Data Section.
|
||||
* So we must decode all the data values and count how many are missing
|
||||
*/
|
||||
|
@ -105,15 +102,15 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val
|
|||
|
||||
size = bitmap->byte_count();
|
||||
offset = bitmap->byte_offset();
|
||||
if (grib_get_long(h, self->unusedBitsInBitmap, &unusedBitsInBitmap) != GRIB_SUCCESS) {
|
||||
if (grib_get_long(h, self->numberOfDataPoints, &numberOfDataPoints) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to count missing values");
|
||||
if (grib_get_long(h, unusedBitsInBitmap_, &unusedBitsInBitmap) != GRIB_SUCCESS) {
|
||||
if (grib_get_long(h, numberOfDataPoints_, &numberOfDataPoints) != GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Unable to count missing values");
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
unusedBitsInBitmap = size * 8 - numberOfDataPoints;
|
||||
if (unusedBitsInBitmap < 0) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!");
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size * 8, numberOfDataPoints);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!");
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size * 8, numberOfDataPoints);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +128,7 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_count_missing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_count_missing_t::value_count(long* count)
|
||||
{
|
||||
*count = 1;
|
||||
return 0;
|
||||
|
|
|
@ -16,19 +16,16 @@
|
|||
class grib_accessor_count_missing_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in count_missing */
|
||||
const char* bitmap;
|
||||
const char* unusedBitsInBitmap;
|
||||
const char* numberOfDataPoints;
|
||||
const char* missingValueManagementUsed;
|
||||
};
|
||||
|
||||
class grib_accessor_class_count_missing_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_count_missing_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_count_missing_t() :
|
||||
grib_accessor_long_t() { class_name_ = "count_missing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_count_missing_t{}; }
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* bitmap_;
|
||||
const char* unusedBitsInBitmap_;
|
||||
const char* numberOfDataPoints_;
|
||||
const char* missingValueManagementUsed_;
|
||||
};
|
||||
|
|
|
@ -11,20 +11,19 @@
|
|||
|
||||
#include "grib_accessor_class_count_total.h"
|
||||
|
||||
grib_accessor_class_count_total_t _grib_accessor_class_count_total{ "count_total" };
|
||||
grib_accessor_class* grib_accessor_class_count_total = &_grib_accessor_class_count_total;
|
||||
grib_accessor_count_total_t _grib_accessor_count_total{};
|
||||
grib_accessor* grib_accessor_count_total = &_grib_accessor_count_total;
|
||||
|
||||
|
||||
void grib_accessor_class_count_total_t::init(grib_accessor* a, const long l, grib_arguments* c)
|
||||
void grib_accessor_count_total_t::init(const long l, grib_arguments* c)
|
||||
{
|
||||
grib_accessor_class_long_t::init(a, l, c);
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
a->length = 0;
|
||||
grib_accessor_long_t::init(l, c);
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
int grib_accessor_class_count_total_t::unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
int grib_accessor_count_total_t::unpack_long(long* val, size_t* len)
|
||||
{
|
||||
*val = grib_context_get_handle_total_count(a->context);
|
||||
*val = grib_context_get_handle_total_count(context_);
|
||||
*len = 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,14 +16,9 @@
|
|||
class grib_accessor_count_total_t : public grib_accessor_long_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in count_total */
|
||||
};
|
||||
|
||||
class grib_accessor_class_count_total_t : public grib_accessor_class_long_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_count_total_t(const char* name) : grib_accessor_class_long_t(name) {}
|
||||
grib_accessor_count_total_t() :
|
||||
grib_accessor_long_t() { class_name_ = "count_total"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_count_total_t{}; }
|
||||
int unpack_long(grib_accessor*, long* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_long(long* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
};
|
||||
|
|
|
@ -11,68 +11,64 @@
|
|||
|
||||
#include "grib_accessor_class_data_apply_bitmap.h"
|
||||
|
||||
grib_accessor_class_data_apply_bitmap_t _grib_accessor_class_data_apply_bitmap{ "data_apply_bitmap" };
|
||||
grib_accessor_class* grib_accessor_class_data_apply_bitmap = &_grib_accessor_class_data_apply_bitmap;
|
||||
grib_accessor_data_apply_bitmap_t _grib_accessor_data_apply_bitmap{};
|
||||
grib_accessor* grib_accessor_data_apply_bitmap = &_grib_accessor_data_apply_bitmap;
|
||||
|
||||
|
||||
void grib_accessor_class_data_apply_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_apply_bitmap_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, v, args);
|
||||
grib_accessor_gen_t::init(v, args);
|
||||
int n = 0;
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
|
||||
self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->number_of_data_points = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
coded_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
bitmap_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
missing_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
binary_scale_factor_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
number_of_data_points_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
number_of_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
|
||||
a->length = 0;
|
||||
length_ = 0;
|
||||
}
|
||||
void grib_accessor_class_data_apply_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_data_apply_bitmap_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_values(dumper, a);
|
||||
grib_dump_values(dumper, this);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_apply_bitmap_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
size_t len = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
int ret = GRIB_SUCCESS;
|
||||
|
||||
if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap))
|
||||
ret = grib_get_size(grib_handle_of_accessor(a), self->bitmap, &len);
|
||||
if (grib_find_accessor(grib_handle_of_accessor(this), bitmap_))
|
||||
ret = grib_get_size(grib_handle_of_accessor(this), bitmap_, &len);
|
||||
else
|
||||
ret = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len);
|
||||
ret = grib_get_size(grib_handle_of_accessor(this), coded_values_, &len);
|
||||
|
||||
*count = len;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_apply_bitmap_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
size_t i = 0, cidx = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
size_t i = 0, cidx = 0;
|
||||
double missing_value = 0;
|
||||
double* bvals = NULL;
|
||||
size_t n_vals = 0;
|
||||
long nn = 0;
|
||||
|
||||
int err = a->value_count(&nn);
|
||||
n_vals = nn;
|
||||
int err = value_count(&nn);
|
||||
n_vals = nn;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_internal(gh, self->coded_values, idx, val);
|
||||
if (!grib_find_accessor(gh, bitmap_))
|
||||
return grib_get_double_element_internal(gh, coded_values_, idx, val);
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_double_element_internal(gh, self->bitmap, idx, val)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_element_internal(gh, bitmap_, idx, val)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*val == 0) {
|
||||
|
@ -80,11 +76,11 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double));
|
||||
bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double));
|
||||
if (bvals == NULL)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx = 0;
|
||||
|
@ -92,15 +88,14 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor
|
|||
cidx += bvals[i];
|
||||
}
|
||||
|
||||
grib_context_free(a->context, bvals);
|
||||
grib_context_free(context_, bvals);
|
||||
|
||||
return grib_get_double_element_internal(gh, self->coded_values, cidx, val);
|
||||
return grib_get_double_element_internal(gh, coded_values_, cidx, val);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_apply_bitmap_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
int err = 0, all_missing = 1;
|
||||
size_t cidx = 0; /* index into the coded_values array */
|
||||
size_t* cidx_array = NULL; /* array of indexes into the coded_values */
|
||||
|
@ -110,17 +105,17 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce
|
|||
size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0;
|
||||
long nn = 0;
|
||||
|
||||
err = a->value_count(&nn);
|
||||
err = value_count(&nn);
|
||||
n_vals = nn;
|
||||
if (err) return err;
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_set_internal(gh, self->coded_values, index_array, len, val_array);
|
||||
if (!grib_find_accessor(gh, bitmap_))
|
||||
return grib_get_double_element_set_internal(gh, coded_values_, index_array, len, val_array);
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
err = grib_get_double_element_set_internal(gh, self->bitmap, index_array, len, val_array);
|
||||
err = grib_get_double_element_set_internal(gh, bitmap_, index_array, len, val_array);
|
||||
if (err) return err;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (val_array[i] == 0) {
|
||||
|
@ -139,14 +134,14 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce
|
|||
/* At this point val_array contains entries which are either missing_value or 1 */
|
||||
/* Now we need to dig into the codes values with index array of count_1s */
|
||||
|
||||
bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double));
|
||||
bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double));
|
||||
if (!bvals) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx_array = (size_t*)grib_context_malloc(a->context, count_1s * sizeof(size_t));
|
||||
cval_array = (double*)grib_context_malloc(a->context, count_1s * sizeof(double));
|
||||
cidx_array = (size_t*)grib_context_malloc(context_, count_1s * sizeof(size_t));
|
||||
cval_array = (double*)grib_context_malloc(context_, count_1s * sizeof(double));
|
||||
|
||||
ci = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
|
@ -160,7 +155,7 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce
|
|||
cidx_array[ci++] = cidx;
|
||||
}
|
||||
}
|
||||
err = grib_get_double_element_set_internal(gh, self->coded_values, cidx_array, count_1s, cval_array);
|
||||
err = grib_get_double_element_set_internal(gh, coded_values_, cidx_array, count_1s, cval_array);
|
||||
if (err) return err;
|
||||
|
||||
/* Transfer from cval_array to our result val_array */
|
||||
|
@ -171,48 +166,47 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context, bvals);
|
||||
grib_context_free(a->context, cidx_array);
|
||||
grib_context_free(a->context, cval_array);
|
||||
grib_context_free(context_, bvals);
|
||||
grib_context_free(context_, cidx_array);
|
||||
grib_context_free(context_, cval_array);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_apply_bitmap_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
int err = 0;
|
||||
size_t bmaplen = *len;
|
||||
long coded_n_vals = 0;
|
||||
double* coded_vals = NULL;
|
||||
long i = 0;
|
||||
long j = 0;
|
||||
double missing_value = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_context* ctxt = a->context;
|
||||
int err = 0;
|
||||
size_t bmaplen = *len;
|
||||
long coded_n_vals = 0;
|
||||
double* coded_vals = NULL;
|
||||
long i = 0;
|
||||
long j = 0;
|
||||
double missing_value = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
grib_context* ctxt = context_;
|
||||
|
||||
if (*len == 0)
|
||||
return GRIB_NO_VALUES;
|
||||
|
||||
if (!grib_find_accessor(hand, self->bitmap)) {
|
||||
/*printf("SETTING TOTAL number_of_data_points %s %ld\n",self->number_of_data_points,*len);*/
|
||||
if (self->number_of_data_points)
|
||||
grib_set_long_internal(hand, self->number_of_data_points, *len);
|
||||
if (!grib_find_accessor(hand, bitmap_)) {
|
||||
/*printf("SETTING TOTAL number_of_data_points %s %ld\n",number_of_data_points_ ,*len);*/
|
||||
if (number_of_data_points_)
|
||||
grib_set_long_internal(hand, number_of_data_points_, *len);
|
||||
|
||||
err = grib_set_double_array_internal(hand, self->coded_values, val, *len);
|
||||
err = grib_set_double_array_internal(hand, coded_values_, val, *len);
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = grib_get_double_internal(hand, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(hand, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_set_double_array_internal(hand, self->bitmap, val, bmaplen)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_array_internal(hand, bitmap_, val, bmaplen)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
coded_n_vals = *len;
|
||||
|
||||
if (coded_n_vals < 1) {
|
||||
err = grib_set_double_array_internal(hand, self->coded_values, NULL, 0);
|
||||
err = grib_set_double_array_internal(hand, coded_values_, NULL, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -226,24 +220,22 @@ int grib_accessor_class_data_apply_bitmap_t::pack_double(grib_accessor* a, const
|
|||
}
|
||||
}
|
||||
|
||||
err = grib_set_double_array_internal(hand, self->coded_values, coded_vals, j);
|
||||
err = grib_set_double_array_internal(hand, coded_values_, coded_vals, j);
|
||||
grib_context_free(ctxt, coded_vals);
|
||||
if (j == 0) {
|
||||
if (self->number_of_values)
|
||||
err = grib_set_long_internal(hand, self->number_of_values, 0);
|
||||
if (self->binary_scale_factor)
|
||||
err = grib_set_long_internal(hand, self->binary_scale_factor, 0);
|
||||
if (number_of_values_)
|
||||
err = grib_set_long_internal(hand, number_of_values_, 0);
|
||||
if (binary_scale_factor_)
|
||||
err = grib_set_long_internal(hand, binary_scale_factor_, 0);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
|
@ -253,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);
|
||||
n_vals = 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) {
|
||||
|
@ -280,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_accessor_class_data_apply_bitmap: %s : creating %s, %d values",
|
||||
__func__, a->name, n_vals);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"grib_accessor_data_apply_bitmap: %s : creating %s, %d values",
|
||||
__func__, name_, n_vals);
|
||||
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
if (val[i] == 0) {
|
||||
|
@ -303,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_accessor_class_data_apply_bitmap [%s]:"
|
||||
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;
|
||||
}
|
||||
|
@ -316,28 +308,28 @@ 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_class_data_apply_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_apply_bitmap_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(a, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_data_apply_bitmap_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(a, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_data_apply_bitmap_t::get_native_type()
|
||||
{
|
||||
// grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
|
||||
// return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
|
||||
// return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(this),coded_values_ ));
|
||||
return GRIB_TYPE_DOUBLE;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_accessor* b)
|
||||
int grib_accessor_data_apply_bitmap_t::compare(grib_accessor* b)
|
||||
{
|
||||
int retval = GRIB_SUCCESS;
|
||||
double* aval = 0;
|
||||
|
@ -348,7 +340,7 @@ int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_acce
|
|||
int err = 0;
|
||||
long count = 0;
|
||||
|
||||
err = a->value_count(&count);
|
||||
err = value_count(&count);
|
||||
if (err)
|
||||
return err;
|
||||
alen = count;
|
||||
|
@ -361,18 +353,18 @@ int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_acce
|
|||
if (alen != blen)
|
||||
return GRIB_COUNT_MISMATCH;
|
||||
|
||||
aval = (double*)grib_context_malloc(a->context, alen * sizeof(double));
|
||||
bval = (double*)grib_context_malloc(b->context, blen * sizeof(double));
|
||||
aval = (double*)grib_context_malloc(context_, alen * sizeof(double));
|
||||
bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double));
|
||||
|
||||
a->unpack_double(aval, &alen);
|
||||
unpack_double(aval, &alen);
|
||||
b->unpack_double(bval, &blen);
|
||||
retval = GRIB_SUCCESS;
|
||||
for (size_t i = 0; i < alen && retval == GRIB_SUCCESS; ++i) {
|
||||
if (aval[i] != bval[i]) retval = GRIB_DOUBLE_VALUE_MISMATCH;
|
||||
}
|
||||
|
||||
grib_context_free(a->context, aval);
|
||||
grib_context_free(b->context, bval);
|
||||
grib_context_free(context_, aval);
|
||||
grib_context_free(b->context_, bval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -15,28 +15,27 @@
|
|||
class grib_accessor_data_apply_bitmap_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_apply_bitmap */
|
||||
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;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_apply_bitmap_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_apply_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_data_apply_bitmap_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "data_apply_bitmap"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_bitmap_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*, grib_accessor*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
int compare(grib_accessor*) 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;
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
|
@ -11,53 +11,47 @@
|
|||
|
||||
#include "grib_accessor_class_data_apply_boustrophedonic.h"
|
||||
|
||||
grib_accessor_class_data_apply_boustrophedonic_t _grib_accessor_class_data_apply_boustrophedonic{ "data_apply_boustrophedonic" };
|
||||
grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic = &_grib_accessor_class_data_apply_boustrophedonic;
|
||||
grib_accessor_data_apply_boustrophedonic_t _grib_accessor_data_apply_boustrophedonic{};
|
||||
grib_accessor* grib_accessor_data_apply_boustrophedonic = &_grib_accessor_data_apply_boustrophedonic;
|
||||
|
||||
|
||||
void grib_accessor_class_data_apply_boustrophedonic_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_apply_boustrophedonic_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, v, args);
|
||||
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
|
||||
grib_accessor_gen_t::init(v, args);
|
||||
|
||||
int n = 0;
|
||||
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->numberOfRows = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->numberOfColumns = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->pl = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
int n = 0;
|
||||
values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
numberOfRows_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
numberOfColumns_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
numberOfPoints_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
pl_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++);
|
||||
|
||||
a->length = 0;
|
||||
length_ = 0;
|
||||
}
|
||||
void grib_accessor_class_data_apply_boustrophedonic_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_data_apply_boustrophedonic_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_values(dumper, a);
|
||||
grib_dump_values(dumper, this);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_t::value_count(grib_accessor* a, long* numberOfPoints)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::value_count(long* numberOfPoints)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
|
||||
|
||||
*numberOfPoints = 0;
|
||||
return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints);
|
||||
return grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, 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;
|
||||
double* pvalues = 0;
|
||||
T* pval = 0;
|
||||
size_t valuesSize = 0;
|
||||
size_t plSize = 0;
|
||||
long* pl = 0;
|
||||
double* values = 0;
|
||||
double* pvalues = 0;
|
||||
T* pval = 0;
|
||||
size_t valuesSize = 0;
|
||||
long i, j;
|
||||
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;
|
||||
|
||||
|
@ -66,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;
|
||||
|
||||
|
@ -75,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)",
|
||||
self->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;
|
||||
|
||||
|
@ -116,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++) {
|
||||
|
@ -133,52 +127,52 @@ 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_class_data_apply_boustrophedonic_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(a, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(a, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
size_t size;
|
||||
double* values;
|
||||
|
||||
/* GRIB-564: The index idx relates to codedValues NOT values! */
|
||||
int err = grib_get_size(a->parent->h, "codedValues", &size);
|
||||
int err = grib_get_size(parent_->h, "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
if (idx > size)
|
||||
return GRIB_INVALID_NEAREST;
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->parent->h->context, size * sizeof(double));
|
||||
err = grib_get_double_array(a->parent->h, "codedValues", values, &size);
|
||||
values = (double*)grib_context_malloc_clear(parent_->h->context, size * sizeof(double));
|
||||
err = grib_get_double_array(parent_->h, "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->parent->h->context, values);
|
||||
grib_context_free(parent_->h->context, values);
|
||||
return err;
|
||||
}
|
||||
*val = values[idx];
|
||||
grib_context_free(a->parent->h->context, values);
|
||||
grib_context_free(parent_->h->context, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
size_t size = 0, i = 0;
|
||||
double* values;
|
||||
int err = 0;
|
||||
|
||||
/* GRIB-564: The indexes in index_array relate to codedValues NOT values! */
|
||||
err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -186,23 +180,21 @@ int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element_set(
|
|||
if (index_array[i] > size) return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size);
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
val_array[i] = values[index_array[i]];
|
||||
}
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_apply_boustrophedonic_t::pack_double(const double* 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;
|
||||
|
@ -212,7 +204,7 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor*
|
|||
long i, j;
|
||||
long numberOfPoints, numberOfRows, numberOfColumns;
|
||||
|
||||
int ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints);
|
||||
int ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &numberOfPoints);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -223,23 +215,23 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor*
|
|||
|
||||
valuesSize = numberOfPoints;
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfPoints);
|
||||
values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints);
|
||||
|
||||
pvalues = values;
|
||||
pval = (double*)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;
|
||||
|
||||
|
@ -257,7 +249,7 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor*
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context, pl);
|
||||
grib_context_free(context_, pl);
|
||||
}
|
||||
else {
|
||||
for (j = 0; j < numberOfRows; j++) {
|
||||
|
@ -273,16 +265,16 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor*
|
|||
}
|
||||
}
|
||||
}
|
||||
ret = grib_set_double_array_internal(grib_handle_of_accessor(a), self->values, values, valuesSize);
|
||||
ret = grib_set_double_array_internal(grib_handle_of_accessor(this), values_, values, valuesSize);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_data_apply_boustrophedonic_t::get_native_type()
|
||||
{
|
||||
return GRIB_TYPE_DOUBLE;
|
||||
}
|
||||
|
|
|
@ -15,26 +15,25 @@
|
|||
class grib_accessor_data_apply_boustrophedonic_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_apply_boustrophedonic */
|
||||
const char* values;
|
||||
const char* numberOfRows;
|
||||
const char* numberOfColumns;
|
||||
const char* numberOfPoints;
|
||||
const char* pl;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_apply_boustrophedonic_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_apply_boustrophedonic_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_data_apply_boustrophedonic_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "data_apply_boustrophedonic"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_boustrophedonic_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) 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;
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
|
@ -10,54 +10,49 @@
|
|||
|
||||
#include "grib_accessor_class_data_apply_boustrophedonic_bitmap.h"
|
||||
|
||||
grib_accessor_class_data_apply_boustrophedonic_bitmap_t _grib_accessor_class_data_apply_boustrophedonic_bitmap{ "data_apply_boustrophedonic_bitmap" };
|
||||
grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic_bitmap = &_grib_accessor_class_data_apply_boustrophedonic_bitmap;
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t _grib_accessor_data_apply_boustrophedonic_bitmap{};
|
||||
grib_accessor* grib_accessor_data_apply_boustrophedonic_bitmap = &_grib_accessor_data_apply_boustrophedonic_bitmap;
|
||||
|
||||
|
||||
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_apply_boustrophedonic_bitmap_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_gen_t::init(a, v, args);
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_accessor_gen_t::init(v, args);
|
||||
int n = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
|
||||
int n = 0;
|
||||
self->coded_values = grib_arguments_get_name(gh, args, n++);
|
||||
self->bitmap = grib_arguments_get_name(gh, args, n++);
|
||||
self->missing_value = grib_arguments_get_name(gh, args, n++);
|
||||
self->binary_scale_factor = grib_arguments_get_name(gh, args, n++);
|
||||
coded_values_ = grib_arguments_get_name(gh, args, n++);
|
||||
bitmap_ = grib_arguments_get_name(gh, args, n++);
|
||||
missing_value_ = grib_arguments_get_name(gh, args, n++);
|
||||
binary_scale_factor_ = grib_arguments_get_name(gh, args, n++);
|
||||
|
||||
self->numberOfRows = grib_arguments_get_name(gh, args, n++);
|
||||
self->numberOfColumns = grib_arguments_get_name(gh, args, n++);
|
||||
self->numberOfPoints = grib_arguments_get_name(gh, args, n++);
|
||||
numberOfRows_ = grib_arguments_get_name(gh, args, n++);
|
||||
numberOfColumns_ = grib_arguments_get_name(gh, args, n++);
|
||||
numberOfPoints_ = grib_arguments_get_name(gh, args, n++);
|
||||
|
||||
a->length = 0;
|
||||
length_ = 0;
|
||||
}
|
||||
|
||||
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper)
|
||||
void grib_accessor_data_apply_boustrophedonic_bitmap_t::dump(grib_dumper* dumper)
|
||||
{
|
||||
grib_dump_values(dumper, a);
|
||||
grib_dump_values(dumper, this);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_apply_boustrophedonic_bitmap_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
size_t len = 0;
|
||||
int ret = 0;
|
||||
|
||||
/* This accessor is for data with a bitmap after all */
|
||||
Assert(grib_find_accessor(gh, self->bitmap));
|
||||
Assert(grib_find_accessor(gh, bitmap_));
|
||||
|
||||
ret = grib_get_size(gh, self->bitmap, &len);
|
||||
ret = grib_get_size(gh, bitmap_, &len);
|
||||
*count = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_apply_boustrophedonic_bitmap_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
|
||||
size_t i = 0, j = 0, n_vals = 0, irow = 0;
|
||||
long nn = 0;
|
||||
|
@ -67,29 +62,29 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_
|
|||
double missing_value = 0;
|
||||
long numberOfPoints, numberOfRows, numberOfColumns;
|
||||
|
||||
err = a->value_count(&nn);
|
||||
err = value_count(&nn);
|
||||
n_vals = nn;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = grib_get_long_internal(gh, self->numberOfRows, &numberOfRows);
|
||||
err = grib_get_long_internal(gh, numberOfRows_, &numberOfRows);
|
||||
if (err)
|
||||
return err;
|
||||
err = grib_get_long_internal(gh, self->numberOfColumns, &numberOfColumns);
|
||||
err = grib_get_long_internal(gh, numberOfColumns_, &numberOfColumns);
|
||||
if (err)
|
||||
return err;
|
||||
err = grib_get_long_internal(gh, self->numberOfPoints, &numberOfPoints);
|
||||
err = grib_get_long_internal(gh, numberOfPoints_, &numberOfPoints);
|
||||
if (err)
|
||||
return err;
|
||||
Assert(nn == numberOfPoints);
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_array_internal(gh, self->coded_values, val, len);
|
||||
if (!grib_find_accessor(gh, bitmap_))
|
||||
return grib_get_double_array_internal(gh, coded_values_, val, len);
|
||||
|
||||
if ((err = grib_get_size(gh, self->coded_values, &coded_n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_size(gh, coded_values_, &coded_n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*len < n_vals) {
|
||||
|
@ -105,21 +100,21 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, val, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, bitmap_, val, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
coded_vals = (double*)grib_context_malloc(a->context, coded_n_vals * sizeof(double));
|
||||
coded_vals = (double*)grib_context_malloc(context_, coded_n_vals * sizeof(double));
|
||||
if (coded_vals == NULL)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->coded_values, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) {
|
||||
grib_context_free(a->context, coded_vals);
|
||||
if ((err = grib_get_double_array_internal(gh, 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_accessor_class_data_apply_boustrophedonic_bitmap: unpack_double : creating %s, %d values",
|
||||
a->name, n_vals);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"grib_accessor_data_apply_boustrophedonic_bitmap: unpack_double : creating %s, %d values",
|
||||
name_, n_vals);
|
||||
|
||||
/* Boustrophedonic ordering (See GRIB-472):
|
||||
* Values on even rank lines (the initial line scanned having rank 1) are swapped
|
||||
|
@ -147,11 +142,11 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_
|
|||
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_accessor_class_data_apply_boustrophedonic_bitmap [%s]:"
|
||||
grib_context_free(context_, coded_vals);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"grib_accessor_data_apply_boustrophedonic_bitmap [%s]:"
|
||||
" unpack_double : number of coded values does not match bitmap %ld %ld",
|
||||
a->name, coded_n_vals, n_vals);
|
||||
name_, coded_n_vals, n_vals);
|
||||
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
@ -160,14 +155,13 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_
|
|||
|
||||
*len = n_vals;
|
||||
|
||||
grib_context_free(a->context, coded_vals);
|
||||
grib_context_free(context_, coded_vals);
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_apply_boustrophedonic_bitmap_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
int err = 0, i = 0;
|
||||
size_t cidx = 0;
|
||||
double missing_value = 0;
|
||||
|
@ -175,18 +169,18 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
size_t n_vals = 0;
|
||||
long nn = 0;
|
||||
|
||||
err = a->value_count(&nn);
|
||||
err = value_count(&nn);
|
||||
n_vals = nn;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_internal(gh, self->coded_values, idx, val);
|
||||
if (!grib_find_accessor(gh, bitmap_))
|
||||
return grib_get_double_element_internal(gh, coded_values_, idx, val);
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_double_element_internal(gh, self->bitmap, idx, val)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_element_internal(gh, bitmap_, idx, val)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*val == 0) {
|
||||
|
@ -194,11 +188,11 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double));
|
||||
bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double));
|
||||
if (bvals == NULL)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx = 0;
|
||||
|
@ -206,15 +200,14 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
cidx += bvals[i];
|
||||
}
|
||||
|
||||
grib_context_free(a->context, bvals);
|
||||
grib_context_free(context_, bvals);
|
||||
|
||||
return grib_get_double_element_internal(gh, self->coded_values, cidx, val);
|
||||
return grib_get_double_element_internal(gh, coded_values_, cidx, val);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
int err = 0, all_missing = 1;
|
||||
size_t cidx = 0; /* index into the coded_values array */
|
||||
size_t* cidx_array = NULL; /* array of indexes into the coded_values */
|
||||
|
@ -224,17 +217,17 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0;
|
||||
long nn = 0;
|
||||
|
||||
err = a->value_count(&nn);
|
||||
err = value_count(&nn);
|
||||
n_vals = nn;
|
||||
if (err) return err;
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_set_internal(gh, self->coded_values, index_array, len, val_array);
|
||||
if (!grib_find_accessor(gh, bitmap_))
|
||||
return grib_get_double_element_set_internal(gh, coded_values_, index_array, len, val_array);
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
err = grib_get_double_element_set_internal(gh, self->bitmap, index_array, len, val_array);
|
||||
err = grib_get_double_element_set_internal(gh, bitmap_, index_array, len, val_array);
|
||||
if (err) return err;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (val_array[i] == 0) {
|
||||
|
@ -253,14 +246,14 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
/* At this point val_array contains entries which are either missing_value or 1 */
|
||||
/* Now we need to dig into the codes values with index array of count_1s */
|
||||
|
||||
bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double));
|
||||
bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double));
|
||||
if (!bvals) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx_array = (size_t*)grib_context_malloc(a->context, count_1s * sizeof(size_t));
|
||||
cval_array = (double*)grib_context_malloc(a->context, count_1s * sizeof(double));
|
||||
cidx_array = (size_t*)grib_context_malloc(context_, count_1s * sizeof(size_t));
|
||||
cval_array = (double*)grib_context_malloc(context_, count_1s * sizeof(double));
|
||||
|
||||
ci = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
|
@ -274,7 +267,7 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
cidx_array[ci++] = cidx;
|
||||
}
|
||||
}
|
||||
err = grib_get_double_element_set_internal(gh, self->coded_values, cidx_array, count_1s, cval_array);
|
||||
err = grib_get_double_element_set_internal(gh, coded_values_, cidx_array, count_1s, cval_array);
|
||||
if (err) return err;
|
||||
|
||||
/* Transfer from cval_array to our result val_array */
|
||||
|
@ -285,18 +278,16 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
|
|||
}
|
||||
}
|
||||
|
||||
grib_context_free(a->context, bvals);
|
||||
grib_context_free(a->context, cidx_array);
|
||||
grib_context_free(a->context, cval_array);
|
||||
grib_context_free(context_, bvals);
|
||||
grib_context_free(context_, cidx_array);
|
||||
grib_context_free(context_, cval_array);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_apply_boustrophedonic_bitmap_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
int err = 0;
|
||||
size_t bmaplen = *len;
|
||||
size_t irow = 0;
|
||||
|
@ -311,30 +302,30 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac
|
|||
if (*len == 0)
|
||||
return GRIB_NO_VALUES;
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap)) {
|
||||
err = grib_set_double_array_internal(gh, self->coded_values, val, *len);
|
||||
/*printf("SETTING TOTAL number_of_data_points %s %ld\n",self->number_of_data_points,*len);*/
|
||||
/*if(self->number_of_data_points)
|
||||
grib_set_long_internal(gh,self->number_of_data_points,*len);*/
|
||||
if (!grib_find_accessor(gh, bitmap_)) {
|
||||
err = grib_set_double_array_internal(gh, coded_values_, val, *len);
|
||||
/*printf("SETTING TOTAL number_of_data_points %s %ld\n",number_of_data_points_ ,*len);*/
|
||||
/*if(number_of_data_points_ )
|
||||
grib_set_long_internal(gh,number_of_data_points_ ,*len);*/
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
err = grib_get_long_internal(gh, self->numberOfRows, &numberOfRows);
|
||||
err = grib_get_long_internal(gh, numberOfRows_, &numberOfRows);
|
||||
if (err)
|
||||
return err;
|
||||
err = grib_get_long_internal(gh, self->numberOfColumns, &numberOfColumns);
|
||||
err = grib_get_long_internal(gh, numberOfColumns_, &numberOfColumns);
|
||||
if (err)
|
||||
return err;
|
||||
err = grib_get_long_internal(gh, self->numberOfPoints, &numberOfPoints);
|
||||
err = grib_get_long_internal(gh, numberOfPoints_, &numberOfPoints);
|
||||
if (err)
|
||||
return err;
|
||||
Assert(numberOfPoints == bmaplen);
|
||||
|
||||
/* Create a copy of the incoming 'val' array because we're going to change it */
|
||||
values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfPoints);
|
||||
values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints);
|
||||
if (!values)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
for (i = 0; i < numberOfPoints; ++i) {
|
||||
|
@ -356,19 +347,19 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac
|
|||
}
|
||||
}
|
||||
/* Now set the bitmap based on the array with the boustrophedonic ordering */
|
||||
if ((err = grib_set_double_array_internal(gh, self->bitmap, values, bmaplen)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_array_internal(gh, bitmap_, values, bmaplen)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
|
||||
coded_n_vals = *len;
|
||||
|
||||
if (coded_n_vals < 1) {
|
||||
err = grib_set_double_array_internal(gh, self->coded_values, NULL, 0);
|
||||
err = grib_set_double_array_internal(gh, coded_values_, NULL, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
coded_vals = (double*)grib_context_malloc_clear(a->context, coded_n_vals * sizeof(double));
|
||||
coded_vals = (double*)grib_context_malloc_clear(context_, coded_n_vals * sizeof(double));
|
||||
if (!coded_vals)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -380,23 +371,23 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac
|
|||
}
|
||||
}
|
||||
|
||||
err = grib_set_double_array_internal(gh, self->coded_values, coded_vals, j);
|
||||
err = grib_set_double_array_internal(gh, coded_values_, coded_vals, j);
|
||||
if (j == 0) {
|
||||
/*if (self->number_of_values)
|
||||
err=grib_set_long_internal(gh,self->number_of_values,0);*/
|
||||
if (self->binary_scale_factor)
|
||||
err = grib_set_long_internal(gh, self->binary_scale_factor, 0);
|
||||
/*if (number_of_values_ )
|
||||
err=grib_set_long_internal(gh,number_of_values_ ,0);*/
|
||||
if (binary_scale_factor_)
|
||||
err = grib_set_long_internal(gh, binary_scale_factor_, 0);
|
||||
}
|
||||
|
||||
grib_context_free(a->context, coded_vals);
|
||||
grib_context_free(context_, coded_vals);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::get_native_type(grib_accessor* a)
|
||||
long grib_accessor_data_apply_boustrophedonic_bitmap_t::get_native_type()
|
||||
{
|
||||
// grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
|
||||
// return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
|
||||
// return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(this),coded_values_ ));
|
||||
|
||||
return GRIB_TYPE_DOUBLE;
|
||||
}
|
||||
|
|
|
@ -15,27 +15,24 @@
|
|||
class grib_accessor_data_apply_boustrophedonic_bitmap_t : public grib_accessor_gen_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_apply_boustrophedonic_bitmap */
|
||||
const char* coded_values;
|
||||
const char* bitmap;
|
||||
const char* missing_value;
|
||||
const char* binary_scale_factor;
|
||||
const char* numberOfRows;
|
||||
const char* numberOfColumns;
|
||||
const char* numberOfPoints;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_apply_boustrophedonic_bitmap_t : public grib_accessor_class_gen_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_apply_boustrophedonic_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {}
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap_t() :
|
||||
grib_accessor_gen_t() { class_name_ = "data_apply_boustrophedonic_bitmap"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_boustrophedonic_bitmap_t{}; }
|
||||
int get_native_type(grib_accessor*) override;
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void dump(grib_accessor*, grib_dumper*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
long get_native_type() override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void dump(grib_dumper*) override;
|
||||
void init(const long, grib_arguments*) 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;
|
||||
|
||||
private:
|
||||
const char* coded_values_;
|
||||
const char* bitmap_;
|
||||
const char* missing_value_;
|
||||
const char* binary_scale_factor_;
|
||||
const char* numberOfRows_;
|
||||
const char* numberOfColumns_;
|
||||
const char* numberOfPoints_;
|
||||
};
|
||||
|
|
|
@ -18,37 +18,32 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
grib_accessor_data_ccsds_packing_t _grib_accessor_data_ccsds_packing{};
|
||||
grib_accessor* grib_accessor_data_ccsds_packing = &_grib_accessor_data_ccsds_packing;
|
||||
|
||||
grib_accessor_class_data_ccsds_packing_t _grib_accessor_class_data_ccsds_packing{ "data_ccsds_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_ccsds_packing = &_grib_accessor_class_data_ccsds_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_ccsds_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_ccsds_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_values_t::init(a, v, args);
|
||||
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
grib_accessor_values_t::init(v, args);
|
||||
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
number_of_values_ = grib_arguments_get_name(h, args, carg_++);
|
||||
reference_value_ = grib_arguments_get_name(h, args, carg_++);
|
||||
binary_scale_factor_ = grib_arguments_get_name(h, args, carg_++);
|
||||
decimal_scale_factor_ = grib_arguments_get_name(h, args, carg_++);
|
||||
optimize_scaling_factor_ = grib_arguments_get_name(h, args, carg_++);
|
||||
bits_per_value_ = grib_arguments_get_name(h, args, carg_++);
|
||||
number_of_data_points_ = grib_arguments_get_name(h, args, carg_++);
|
||||
ccsds_flags_ = grib_arguments_get_name(h, args, carg_++);
|
||||
ccsds_block_size_ = grib_arguments_get_name(h, args, carg_++);
|
||||
ccsds_rsi_ = grib_arguments_get_name(h, args, carg_++);
|
||||
|
||||
self->number_of_values = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->reference_value = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->binary_scale_factor = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->decimal_scale_factor = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->optimize_scaling_factor = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->bits_per_value = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->number_of_data_points = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->ccsds_flags = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->ccsds_block_size = grib_arguments_get_name(h, args, self->carg++);
|
||||
self->ccsds_rsi = grib_arguments_get_name(h, args, self->carg++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_ccsds_packing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_ccsds_packing_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
*count = 0;
|
||||
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, count);
|
||||
return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, count);
|
||||
}
|
||||
|
||||
#if defined(HAVE_LIBAEC) || defined(HAVE_AEC)
|
||||
|
@ -91,13 +86,10 @@ static void print_aec_stream_info(struct aec_stream* strm, const char* func)
|
|||
}
|
||||
|
||||
#define MAX_BITS_PER_VALUE 32
|
||||
|
||||
int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
int err = GRIB_SUCCESS;
|
||||
size_t buflen = 0, i = 0;
|
||||
bool is_constant_field = false;
|
||||
|
@ -121,34 +113,34 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
|
||||
struct aec_stream strm;
|
||||
|
||||
self->dirty = 1;
|
||||
dirty_ = 1;
|
||||
|
||||
n_vals = *len;
|
||||
|
||||
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;
|
||||
|
||||
// if ((err = grib_get_long_internal(gh, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS)
|
||||
// if ((err = grib_get_long_internal(gh, optimize_scaling_factor_ , &optimize_scaling_factor)) != GRIB_SUCCESS)
|
||||
// return err;
|
||||
|
||||
if ((err = grib_get_long_internal(hand, self->ccsds_flags, &ccsds_flags)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(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);
|
||||
|
||||
// Special case
|
||||
if (*len == 0) {
|
||||
grib_buffer_replace(a, NULL, 0, 1, 1);
|
||||
grib_buffer_replace(this, NULL, 0, 1, 1);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -176,31 +168,31 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
}
|
||||
|
||||
if (is_constant_field) {
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
for (i = 1; i < n_vals; i++) {
|
||||
Assert(val[i] == val[0]);
|
||||
}
|
||||
#endif
|
||||
if (grib_get_nearest_smaller_value(hand, self->reference_value, val[0], &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
#endif
|
||||
if (grib_get_nearest_smaller_value(hand, reference_value_, val[0], &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, reference_value_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
if ((err = grib_set_double_internal(hand, self->reference_value, reference_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_internal(hand, reference_value_, reference_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_set_long_internal(hand, self->number_of_values, n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(hand, number_of_values_, n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
bits_per_value = 0; // ECC-1387
|
||||
if ((err = grib_set_long_internal(hand, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(hand, bits_per_value_, bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
grib_buffer_replace(a, NULL, 0, 1, 1);
|
||||
grib_buffer_replace(this, NULL, 0, 1, 1);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
if ((err = grib_get_long_internal(hand, self->number_of_data_points, &number_of_data_points)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(hand, number_of_data_points_, &number_of_data_points)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (bits_per_value == 0 || (binary_scale_factor == 0 && decimal_scale_factor != 0)) {
|
||||
|
@ -208,14 +200,14 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
min *= d;
|
||||
max *= d;
|
||||
|
||||
if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
if (grib_get_nearest_smaller_value(hand, reference_value_, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, reference_value_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
if (reference_value > min) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s %s: reference_value=%g min_value=%g diff=%g", cclass_name, __func__, reference_value, min, reference_value - min);
|
||||
DEBUG_ASSERT(reference_value <= min);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
|
@ -253,9 +245,9 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
range = (max - min);
|
||||
}
|
||||
|
||||
if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
if (grib_get_nearest_smaller_value(hand, reference_value_, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, reference_value_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
d = codes_power<double>(decimal_scale_factor, 10);
|
||||
|
@ -270,7 +262,7 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
if (nbytes == 3)
|
||||
nbytes = 4;
|
||||
|
||||
encoded = reinterpret_cast<unsigned char*>(grib_context_buffer_malloc_clear(a->context, nbytes * n_vals));
|
||||
encoded = reinterpret_cast<unsigned char*>(grib_context_buffer_malloc_clear(context_, nbytes * n_vals));
|
||||
|
||||
if (!encoded) {
|
||||
err = GRIB_OUT_OF_MEMORY;
|
||||
|
@ -312,40 +304,40 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
}
|
||||
break;
|
||||
default:
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s pack_double: packing %s, bitsPerValue=%ld (max %ld)",
|
||||
cclass_name, a->name, bits_per_value, MAX_BITS_PER_VALUE);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s pack_double: packing %s, bitsPerValue=%ld (max %ld)",
|
||||
cclass_name, name_, bits_per_value, MAX_BITS_PER_VALUE);
|
||||
err = GRIB_INVALID_BPV;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "%s pack_double: packing %s, %zu values", cclass_name, a->name, n_vals);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "%s pack_double: packing %s, %zu values", cclass_name, name_, n_vals);
|
||||
|
||||
// ECC-1431: GRIB2: CCSDS encoding failure AEC_STREAM_ERROR
|
||||
buflen = (nbytes * n_vals) * 67 / 64 + 256;
|
||||
buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen);
|
||||
buf = (unsigned char*)grib_context_buffer_malloc_clear(context_, buflen);
|
||||
|
||||
if (!buf) {
|
||||
err = GRIB_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = grib_set_double_internal(hand, self->reference_value, reference_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_internal(hand, reference_value_, reference_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
{
|
||||
// Make sure we can decode it again
|
||||
double ref = 1e-100;
|
||||
grib_get_double_internal(hand, self->reference_value, &ref);
|
||||
grib_get_double_internal(hand, reference_value_, &ref);
|
||||
if (ref != reference_value) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)",
|
||||
cclass_name, __func__, self->reference_value, ref, reference_value);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)",
|
||||
cclass_name, __func__, reference_value_, ref, reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = grib_set_long_internal(hand, self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(hand, binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_set_long_internal(hand, self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(hand, decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
strm.flags = ccsds_flags;
|
||||
|
@ -364,35 +356,34 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons
|
|||
if (hand->context->debug) print_aec_stream_info(&strm, "pack_double");
|
||||
|
||||
if ((err = aec_buffer_encode(&strm)) != AEC_OK) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: aec_buffer_encode error %d (%s)",
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_encode error %d (%s)",
|
||||
cclass_name, __func__, err, aec_get_error_message(err));
|
||||
err = GRIB_ENCODING_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
buflen = strm.total_out;
|
||||
grib_buffer_replace(a, buf, buflen, 1, 1);
|
||||
grib_buffer_replace(this, buf, buflen, 1, 1);
|
||||
|
||||
cleanup:
|
||||
grib_context_buffer_free(a->context, buf);
|
||||
grib_context_buffer_free(a->context, encoded);
|
||||
grib_context_buffer_free(context_, buf);
|
||||
grib_context_buffer_free(context_, encoded);
|
||||
|
||||
if (err == GRIB_SUCCESS)
|
||||
err = grib_set_long_internal(hand, self->number_of_values, *len);
|
||||
err = grib_set_long_internal(hand, number_of_values_, *len);
|
||||
|
||||
if (err == GRIB_SUCCESS)
|
||||
err = grib_set_long_internal(hand, self->bits_per_value, strm.bits_per_sample);
|
||||
err = grib_set_long_internal(hand, bits_per_value_, strm.bits_per_sample);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->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;
|
||||
|
@ -416,28 +407,28 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
long ccsds_rsi;
|
||||
size_t nbytes;
|
||||
|
||||
self->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);
|
||||
|
@ -457,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 = a->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;
|
||||
|
@ -473,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;
|
||||
|
@ -484,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;
|
||||
|
@ -511,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;
|
||||
}
|
||||
|
@ -520,35 +511,33 @@ 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_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(a, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(a, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
// The index idx relates to codedValues NOT values!
|
||||
const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
int err = 0;
|
||||
size_t size = 0;
|
||||
long bits_per_value = 0;
|
||||
double reference_value = 0;
|
||||
double* values = NULL;
|
||||
|
||||
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;
|
||||
|
||||
// Special case of constant field
|
||||
|
@ -561,30 +550,29 @@ int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accesso
|
|||
if (err) return err;
|
||||
if (idx > size) return GRIB_INVALID_ARGUMENT;
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(hand, "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
*val = values[idx];
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
size_t size = 0, i = 0;
|
||||
double* values = NULL;
|
||||
int err = 0;
|
||||
long bits_per_value = 0;
|
||||
double reference_value = 0;
|
||||
|
||||
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;
|
||||
|
||||
// Special case of constant field
|
||||
|
@ -596,7 +584,7 @@ int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_acc
|
|||
}
|
||||
|
||||
// GRIB-564: The indexes in index_array relate to codedValues NOT values!
|
||||
err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -604,17 +592,17 @@ int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_acc
|
|||
if (index_array[i] > size) return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size);
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
val_array[i] = values[index_array[i]];
|
||||
}
|
||||
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -626,29 +614,29 @@ static void print_error_feature_not_enabled(grib_context* c)
|
|||
"CCSDS support not enabled. "
|
||||
"Please rebuild with -DENABLE_AEC=ON (Adaptive Entropy Coding library)");
|
||||
}
|
||||
int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
print_error_feature_not_enabled(a->context);
|
||||
print_error_feature_not_enabled(context_);
|
||||
return GRIB_FUNCTIONALITY_NOT_ENABLED;
|
||||
}
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
print_error_feature_not_enabled(a->context);
|
||||
print_error_feature_not_enabled(context_);
|
||||
return GRIB_FUNCTIONALITY_NOT_ENABLED;
|
||||
}
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
print_error_feature_not_enabled(a->context);
|
||||
print_error_feature_not_enabled(context_);
|
||||
return GRIB_FUNCTIONALITY_NOT_ENABLED;
|
||||
}
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
print_error_feature_not_enabled(a->context);
|
||||
print_error_feature_not_enabled(context_);
|
||||
return GRIB_FUNCTIONALITY_NOT_ENABLED;
|
||||
}
|
||||
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_ccsds_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
print_error_feature_not_enabled(a->context);
|
||||
print_error_feature_not_enabled(context_);
|
||||
return GRIB_FUNCTIONALITY_NOT_ENABLED;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,30 +16,28 @@
|
|||
class grib_accessor_data_ccsds_packing_t : public grib_accessor_values_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_ccsds_packing */
|
||||
const char* number_of_values;
|
||||
const char* reference_value;
|
||||
const char* binary_scale_factor;
|
||||
const char* decimal_scale_factor;
|
||||
const char* optimize_scaling_factor;
|
||||
const char* bits_per_value;
|
||||
const char* number_of_data_points;
|
||||
const char* ccsds_flags;
|
||||
const char* ccsds_block_size;
|
||||
const char* ccsds_rsi;
|
||||
};
|
||||
|
||||
|
||||
class grib_accessor_class_data_ccsds_packing_t : public grib_accessor_class_values_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_ccsds_packing_t(const char* name) : grib_accessor_class_values_t(name) {}
|
||||
grib_accessor_data_ccsds_packing_t() :
|
||||
grib_accessor_values_t() { class_name_ = "data_ccsds_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_ccsds_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) 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;
|
||||
|
||||
private:
|
||||
const char* number_of_values_;
|
||||
const char* reference_value_;
|
||||
const char* binary_scale_factor_;
|
||||
const char* decimal_scale_factor_;
|
||||
const char* optimize_scaling_factor_;
|
||||
const char* bits_per_value_;
|
||||
const char* number_of_data_points_;
|
||||
const char* ccsds_flags_;
|
||||
const char* ccsds_block_size_;
|
||||
const char* ccsds_rsi_;
|
||||
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -11,53 +11,50 @@
|
|||
|
||||
#include "grib_accessor_class_data_complex_packing.h"
|
||||
|
||||
grib_accessor_class_data_complex_packing_t _grib_accessor_class_data_complex_packing{ "data_complex_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_complex_packing = &_grib_accessor_class_data_complex_packing;
|
||||
grib_accessor_data_complex_packing_t _grib_accessor_data_complex_packing{};
|
||||
grib_accessor* grib_accessor_data_complex_packing = &_grib_accessor_data_complex_packing;
|
||||
|
||||
void grib_accessor_class_data_complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_complex_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_simple_packing_t::init(a, v, args);
|
||||
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_accessor_data_simple_packing_t::init(v, args);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
|
||||
self->GRIBEX_sh_bug_present = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->laplacianOperatorIsSet = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->laplacianOperator = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->sub_j = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->sub_k = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->sub_m = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->pen_j = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->pen_k = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->pen_m = grib_arguments_get_name(gh, args, self->carg++);
|
||||
GRIBEX_sh_bug_present_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
ieee_floats_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
laplacianOperatorIsSet_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
laplacianOperator_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
sub_j_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
sub_k_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
sub_m_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
pen_j_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
pen_k_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
pen_m_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_complex_packing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_complex_packing_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
|
||||
|
||||
int ret = GRIB_SUCCESS;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
long pen_j = 0;
|
||||
long pen_k = 0;
|
||||
long pen_m = 0;
|
||||
*count = 0;
|
||||
|
||||
if (a->length == 0)
|
||||
if (length_ == 0)
|
||||
return 0;
|
||||
|
||||
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;
|
||||
|
||||
if (pen_j != pen_k || pen_j != pen_m) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Invalid pentagonal resolution parameters");
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld", pen_j, pen_k, pen_m);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Invalid pentagonal resolution parameters");
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld", pen_j, pen_k, pen_m);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
*count = (pen_j + 1) * (pen_j + 2);
|
||||
|
@ -169,11 +166,10 @@ double calculate_pfactor(const grib_context* ctx, const double* spectralField, l
|
|||
return pFactor;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_complex_packing_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
size_t i = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
|
@ -228,42 +224,42 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
if (*len == 0)
|
||||
return GRIB_NO_VALUES;
|
||||
|
||||
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_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->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, optimize_scaling_factor_, &optimize_scaling_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;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->ieee_floats, &ieee_floats)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, ieee_floats_, &ieee_floats)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet, &laplacianOperatorIsSet)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(gh, laplacianOperatorIsSet_, &laplacianOperatorIsSet)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &laplacianOperator)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(gh, laplacianOperator_, &laplacianOperator)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
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;
|
||||
|
||||
self->dirty = 1;
|
||||
dirty_ = 1;
|
||||
|
||||
switch (ieee_floats) {
|
||||
case 0:
|
||||
|
@ -283,20 +279,20 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
}
|
||||
|
||||
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_ENCODING_ERROR;
|
||||
}
|
||||
|
||||
n_vals = (pen_j + 1) * (pen_j + 2);
|
||||
|
||||
if (*len != n_vals) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong number of values, expected %ld - got %zu",
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s: Wrong number of values, expected %ld - got %zu",
|
||||
cclass_name, n_vals, *len);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
/* Data Quality checks */
|
||||
if (a->context->grib_data_quality_checks) {
|
||||
if (context_->grib_data_quality_checks) {
|
||||
/* First value is the field's average */
|
||||
double min_val = val[0];
|
||||
double max_val = min_val;
|
||||
|
@ -308,7 +304,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
double* values;
|
||||
d = codes_power<double>(decimal_scale_factor, 10);
|
||||
if (d) {
|
||||
values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * n_vals);
|
||||
values = (double*)grib_context_malloc_clear(context_, sizeof(double) * n_vals);
|
||||
for (i = 0; i < n_vals; i++)
|
||||
values[i] = val[i] * d;
|
||||
}
|
||||
|
@ -316,20 +312,20 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
values = (double*)val;
|
||||
}
|
||||
buflen = n_vals * bytes;
|
||||
buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen);
|
||||
grib_ieee_encode_array(a->context, values, n_vals, bytes, buf);
|
||||
buf = (unsigned char*)grib_context_malloc_clear(context_, buflen);
|
||||
grib_ieee_encode_array(context_, values, n_vals, bytes, buf);
|
||||
if (d)
|
||||
grib_context_free(a->context, values);
|
||||
grib_buffer_replace(a, buf, buflen, 1, 1);
|
||||
grib_context_free(a->context, buf);
|
||||
grib_context_free(context_, values);
|
||||
grib_buffer_replace(this, buf, buflen, 1, 1);
|
||||
grib_context_free(context_, buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!laplacianOperatorIsSet) {
|
||||
laplacianOperator = calculate_pfactor(a->context, val, pen_j, sub_j);
|
||||
if ((ret = grib_set_double_internal(gh, self->laplacianOperator, laplacianOperator)) != GRIB_SUCCESS)
|
||||
laplacianOperator = calculate_pfactor(context_, val, pen_j, sub_j);
|
||||
if ((ret = grib_set_double_internal(gh, laplacianOperator_, laplacianOperator)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
grib_get_double_internal(gh, self->laplacianOperator, &laplacianOperator);
|
||||
grib_get_double_internal(gh, laplacianOperator_, &laplacianOperator);
|
||||
}
|
||||
|
||||
hsize = bytes * (sub_k + 1) * (sub_k + 2);
|
||||
|
@ -337,7 +333,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
|
||||
buflen = hsize + lsize;
|
||||
|
||||
buf = (unsigned char*)grib_context_malloc(a->context, buflen);
|
||||
buf = (unsigned char*)grib_context_malloc(context_, buflen);
|
||||
hres = buf;
|
||||
lres = buf + hsize;
|
||||
|
||||
|
@ -346,7 +342,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
lpos = 0;
|
||||
hpos = 0;
|
||||
|
||||
scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double));
|
||||
scals = (double*)grib_context_malloc(context_, maxv * sizeof(double));
|
||||
if (!scals) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
scals[0] = 0;
|
||||
|
@ -396,23 +392,23 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
}
|
||||
|
||||
if (optimize_scaling_factor) {
|
||||
ret = grib_optimize_decimal_factor(a, self->reference_value,
|
||||
ret = grib_optimize_decimal_factor(this, reference_value_,
|
||||
max, min, bits_per_value, 0, 1,
|
||||
&decimal_scale_factor,
|
||||
&binary_scale_factor,
|
||||
&reference_value);
|
||||
if (ret != GRIB_SUCCESS) {
|
||||
grib_context_log(gh->context, GRIB_LOG_ERROR,
|
||||
"%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, min, self->reference_value);
|
||||
"%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, min, reference_value_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
d = codes_power<double>(+decimal_scale_factor, 10);
|
||||
}
|
||||
else {
|
||||
d = codes_power<double>(+decimal_scale_factor, 10);
|
||||
if (grib_get_nearest_smaller_value(gh, self->reference_value, d * min, &reference_value) != GRIB_SUCCESS) {
|
||||
if (grib_get_nearest_smaller_value(gh, reference_value_, d * min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(gh->context, GRIB_LOG_ERROR,
|
||||
"%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, self->reference_value);
|
||||
"%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, reference_value_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
binary_scale_factor = grib_get_binary_scale_fact(d * max, reference_value, bits_per_value, &ret);
|
||||
|
@ -423,7 +419,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
}
|
||||
else {
|
||||
if (ret != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Cannot compute binary_scale_factor", cclass_name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s: Cannot compute binary_scale_factor", cclass_name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -467,13 +463,13 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
for (lcount = hcount; lcount < maxv; lcount++) {
|
||||
current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5);
|
||||
if (current_val < 0)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: negative coput before packing (%g)", cclass_name, current_val);
|
||||
grib_encode_unsigned_longb(lres, current_val, &lpos, bits_per_value);
|
||||
|
||||
current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5);
|
||||
if (current_val < 0)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: negative coput before packing (%g)", cclass_name, current_val);
|
||||
grib_encode_unsigned_longb(lres, current_val, &lpos, bits_per_value);
|
||||
lup++;
|
||||
|
@ -483,13 +479,13 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
for (lcount = hcount; lcount < maxv; lcount++) {
|
||||
current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5);
|
||||
if (current_val < 0)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: negative coput before packing (%g)", cclass_name, current_val);
|
||||
grib_encode_unsigned_long(lres, current_val, &lpos, bits_per_value);
|
||||
|
||||
current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5);
|
||||
if (current_val < 0)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: negative coput before packing (%g)", cclass_name, current_val);
|
||||
grib_encode_unsigned_long(lres, current_val, &lpos, bits_per_value);
|
||||
lup++;
|
||||
|
@ -503,47 +499,46 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co
|
|||
}
|
||||
|
||||
if (((hpos / 8) != hsize) && ((lpos / 8) != lsize)) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"%s: Mismatch in packing between high resolution and low resolution part", cclass_name);
|
||||
grib_context_free(a->context, buf);
|
||||
grib_context_free(a->context, scals);
|
||||
grib_context_free(context_, buf);
|
||||
grib_context_free(context_, scals);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
buflen = ((hpos + lpos) / 8);
|
||||
|
||||
if ((ret = grib_set_double_internal(gh, self->reference_value, reference_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_double_internal(gh, reference_value_, reference_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
{
|
||||
// Make sure we can decode it again
|
||||
double ref = 1e-100;
|
||||
grib_get_double_internal(gh, self->reference_value, &ref);
|
||||
grib_get_double_internal(gh, reference_value_, &ref);
|
||||
if (ref != reference_value) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)",
|
||||
cclass_name, __func__, self->reference_value, ref, reference_value);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)",
|
||||
cclass_name, __func__, reference_value_, ref, reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = grib_set_long_internal(gh, self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(gh, binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_set_long_internal(gh, self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(gh, decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
grib_buffer_replace(a, buf, buflen, 1, 1);
|
||||
grib_context_free(a->context, buf);
|
||||
grib_context_free(a->context, scals);
|
||||
grib_buffer_replace(this, buf, buflen, 1, 1);
|
||||
grib_context_free(context_, buf);
|
||||
grib_context_free(context_, scals);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
size_t i = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
|
@ -589,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;
|
||||
|
||||
|
@ -598,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;
|
||||
|
||||
self->dirty = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
switch (ieee_floats) {
|
||||
case 0:
|
||||
|
@ -655,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;
|
||||
}
|
||||
|
||||
|
@ -663,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;
|
||||
|
||||
|
@ -671,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;
|
||||
|
@ -679,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;
|
||||
|
@ -694,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;
|
||||
}
|
||||
|
@ -753,25 +748,25 @@ 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_class_data_complex_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_complex_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack_real<double>(a, val, len);
|
||||
return unpack_real<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_complex_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_data_complex_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
// TODO(maee): See ECC-1579
|
||||
// Investigate why results are not bit-identical
|
||||
|
@ -779,18 +774,18 @@ int grib_accessor_class_data_complex_packing_t::unpack_float(grib_accessor* a, f
|
|||
// return unpack<float>(a, val, len);
|
||||
|
||||
size_t size = *len;
|
||||
double* val8 = (double*)grib_context_malloc(a->context, size * (sizeof(double)));
|
||||
double* val8 = (double*)grib_context_malloc(context_, size * (sizeof(double)));
|
||||
if (!val8) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
int err = unpack_real<double>(a, val8, len);
|
||||
int err = unpack_real<double>(val8, len);
|
||||
if (err) {
|
||||
grib_context_free(a->context, val8);
|
||||
grib_context_free(context_, val8);
|
||||
return err;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
val[i] = val8[i];
|
||||
grib_context_free(a->context, val8);
|
||||
grib_context_free(context_, val8);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -20,27 +20,28 @@ typedef double (*decode_float_proc)(unsigned long);
|
|||
class grib_accessor_data_complex_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_complex_packing */
|
||||
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;
|
||||
};
|
||||
grib_accessor_data_complex_packing_t() :
|
||||
grib_accessor_data_simple_packing_t() { class_name_ = "data_complex_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_complex_packing_t{}; }
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
class grib_accessor_class_data_complex_packing_t : public grib_accessor_class_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_complex_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
|
||||
// grib_accessor* create_empty_accessor() override { return new grib_accessor_data_complex_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
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* pen_j_;
|
||||
const char* pen_k_;
|
||||
const char* pen_m_;
|
||||
|
||||
template <typename T> int unpack_real(T* val, size_t* len);
|
||||
};
|
||||
|
|
|
@ -10,32 +10,29 @@
|
|||
|
||||
#include "grib_accessor_class_data_dummy_field.h"
|
||||
|
||||
grib_accessor_class_data_dummy_field_t _grib_accessor_class_data_dummy_field{ "data_dummy_field" };
|
||||
grib_accessor_class* grib_accessor_class_data_dummy_field = &_grib_accessor_class_data_dummy_field;
|
||||
grib_accessor_data_dummy_field_t _grib_accessor_data_dummy_field{};
|
||||
grib_accessor* grib_accessor_data_dummy_field = &_grib_accessor_data_dummy_field;
|
||||
|
||||
|
||||
void grib_accessor_class_data_dummy_field_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_dummy_field_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_g1simple_packing_t::init(a, v, args);
|
||||
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
|
||||
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
grib_accessor_data_g1simple_packing_t::init(v, args);
|
||||
missing_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
numberOfPoints_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
bitmap_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_dummy_field_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
|
||||
size_t i = 0, n_vals = 0;
|
||||
long numberOfPoints;
|
||||
double missing_value = 0;
|
||||
int err = 0;
|
||||
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &numberOfPoints)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
n_vals = numberOfPoints;
|
||||
|
||||
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) {
|
||||
|
@ -46,8 +43,8 @@ int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, doub
|
|||
for (i = 0; i < n_vals; i++)
|
||||
val[i] = missing_value;
|
||||
|
||||
if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) {
|
||||
if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->bitmap, val, n_vals)) != GRIB_SUCCESS)
|
||||
if (grib_find_accessor(grib_handle_of_accessor(this), bitmap_)) {
|
||||
if ((err = grib_set_double_array_internal(grib_handle_of_accessor(this), bitmap_, val, n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -55,10 +52,8 @@ int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, doub
|
|||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_dummy_field_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
|
||||
|
||||
size_t n_vals = *len;
|
||||
int err = 0;
|
||||
long bits_per_value = 0;
|
||||
|
@ -69,36 +64,35 @@ int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const
|
|||
if (*len == 0)
|
||||
return GRIB_NO_VALUES;
|
||||
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
buflen = (1 + ((bits_per_value * n_vals) / 8)) * sizeof(unsigned char);
|
||||
|
||||
buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen);
|
||||
buf = (unsigned char*)grib_context_malloc_clear(context_, buflen);
|
||||
if (!buf)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
half_byte = (buflen * 8) - ((*len) * bits_per_value);
|
||||
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte)) != GRIB_SUCCESS) {
|
||||
grib_context_free(a->context, buf);
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, half_byte)) != GRIB_SUCCESS) {
|
||||
grib_context_free(context_, buf);
|
||||
return err;
|
||||
}
|
||||
grib_buffer_replace(a, buf, buflen, 1, 1);
|
||||
grib_buffer_replace(this, buf, buflen, 1, 1);
|
||||
|
||||
grib_context_free(a->context, buf);
|
||||
grib_context_free(context_, buf);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_dummy_field_t::value_count(grib_accessor* a, long* numberOfPoints)
|
||||
int grib_accessor_data_dummy_field_t::value_count(long* numberOfPoints)
|
||||
{
|
||||
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
|
||||
int err = 0;
|
||||
int err = 0;
|
||||
*numberOfPoints = 0;
|
||||
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints)) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to get count of %s (%s)", a->name, grib_get_error_message(err));
|
||||
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, numberOfPoints)) != GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Unable to get count of %s (%s)", name_, grib_get_error_message(err));
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -15,19 +15,16 @@
|
|||
class grib_accessor_data_dummy_field_t : public grib_accessor_data_g1simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_dummy_field */
|
||||
const char* missing_value;
|
||||
const char* numberOfPoints;
|
||||
const char* bitmap;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_dummy_field_t : public grib_accessor_class_data_g1simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_dummy_field_t(const char* name) : grib_accessor_class_data_g1simple_packing_t(name) {}
|
||||
grib_accessor_data_dummy_field_t() :
|
||||
grib_accessor_data_g1simple_packing_t() { class_name_ = "data_dummy_field"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_dummy_field_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* missing_value_;
|
||||
const char* numberOfPoints_;
|
||||
const char* bitmap_;
|
||||
};
|
||||
|
|
|
@ -10,28 +10,23 @@
|
|||
|
||||
#include "grib_accessor_class_data_g1complex_packing.h"
|
||||
|
||||
grib_accessor_class_data_g1complex_packing_t _grib_accessor_class_data_g1complex_packing{ "data_g1complex_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1complex_packing = &_grib_accessor_class_data_g1complex_packing;
|
||||
grib_accessor_data_g1complex_packing_t _grib_accessor_data_g1complex_packing{};
|
||||
grib_accessor* grib_accessor_data_g1complex_packing = &_grib_accessor_data_g1complex_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g1complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1complex_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_complex_packing_t::init(a, v, args);
|
||||
grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a;
|
||||
|
||||
self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->N = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->edition = 1;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
grib_accessor_data_complex_packing_t::init(v, args);
|
||||
half_byte_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
N_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
packingType_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
ieee_packing_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
edition_ = 1;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_g1complex_packing_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a;
|
||||
|
||||
int ret = GRIB_SUCCESS;
|
||||
long seclen = 0;
|
||||
long sub_j = 0;
|
||||
|
@ -46,17 +41,17 @@ int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a,
|
|||
return GRIB_NO_VALUES;
|
||||
|
||||
// /* TODO: spectral_ieee does not work */
|
||||
// if (c->ieee_packing && self->ieee_packing) {
|
||||
// grib_handle* h = grib_handle_of_accessor(a);
|
||||
// grib_context* c = a->context;
|
||||
// if (c->ieee_packing && ieee_packing_ ) {
|
||||
// grib_handle* h = grib_handle_of_accessor(this);
|
||||
// grib_context* c = context_ ;
|
||||
// char* packingType_s = NULL;
|
||||
// char* ieee_packing_s = NULL;
|
||||
// long precision = c->ieee_packing == 32 ? 1 : 2;
|
||||
// size_t lenstr = strlen(self->ieee_packing);
|
||||
// size_t lenstr = strlen(ieee_packing_ );
|
||||
|
||||
// packingType_s = grib_context_strdup(c, self->packingType);
|
||||
// ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
|
||||
// precision_s = grib_context_strdup(c, self->precision);
|
||||
// packingType_s = grib_context_strdup(c, packingType_ );
|
||||
// ieee_packing_s = grib_context_strdup(c, ieee_packing_ );
|
||||
// precision_s = grib_context_strdup(c, precision_ );
|
||||
|
||||
// grib_set_string(h, packingType_s, ieee_packing_s, &lenstr);
|
||||
// grib_set_long(h, precision_s, precision);
|
||||
|
@ -67,47 +62,47 @@ int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a,
|
|||
// return grib_set_double_array(h, "values", val, *len);
|
||||
// }
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_j_, &sub_j)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_k, &sub_k)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_k_, &sub_k)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_m, &sub_m)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_m_, &sub_m)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
self->dirty = 1;
|
||||
dirty_ = 1;
|
||||
|
||||
Assert((sub_j == sub_k) && (sub_m == sub_j));
|
||||
|
||||
ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len);
|
||||
ret = grib_accessor_data_complex_packing_t::pack_double(val, len);
|
||||
|
||||
if (ret == GRIB_SUCCESS) {
|
||||
n = a->offset + 4 * ((sub_k + 1) * (sub_k + 2));
|
||||
n = offset_ + 4 * ((sub_k + 1) * (sub_k + 2));
|
||||
|
||||
/* Octet number starts from beginning of message but shouldn't */
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), N_, n)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
// ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection);
|
||||
// ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetsection_ , &offsetsection);
|
||||
// if (ret != GRIB_SUCCESS)
|
||||
// return ret;
|
||||
// if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n - offsetsection)) != GRIB_SUCCESS)
|
||||
// if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), N_ , n - offsetsection)) != GRIB_SUCCESS)
|
||||
// return ret;
|
||||
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value);
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen);
|
||||
ret = grib_get_long_internal(grib_handle_of_accessor(this), seclen_, &seclen);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
buflen = 32 * (sub_k + 1) * (sub_k + 2) + (*len - (sub_k + 1) * (sub_k + 2)) * bits_per_value + 18 * 8;
|
||||
half_byte = seclen * 8 - buflen;
|
||||
if (a->context->debug == -1) {
|
||||
if (context_->debug == -1) {
|
||||
fprintf(stderr, "ECCODES DEBUG: half_byte=%ld\n", half_byte);
|
||||
}
|
||||
|
||||
ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte);
|
||||
ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, half_byte);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -15,19 +15,16 @@
|
|||
class grib_accessor_data_g1complex_packing_t : public grib_accessor_data_complex_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1complex_packing */
|
||||
const char* N;
|
||||
const char* half_byte;
|
||||
const char* packingType;
|
||||
const char* ieee_packing;
|
||||
const char* precision;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1complex_packing_t : public grib_accessor_class_data_complex_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1complex_packing_t(const char* name) : grib_accessor_class_data_complex_packing_t(name) {}
|
||||
grib_accessor_data_g1complex_packing_t() :
|
||||
grib_accessor_data_complex_packing_t() { class_name_ = "data_g1complex_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1complex_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* N_;
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
const char* precision_;
|
||||
};
|
||||
|
|
|
@ -11,55 +11,51 @@
|
|||
#include "grib_accessor_class_data_g1second_order_constant_width_packing.h"
|
||||
#include "grib_scaling.h"
|
||||
|
||||
grib_accessor_class_data_g1second_order_constant_width_packing_t _grib_accessor_class_data_g1second_order_constant_width_packing{ "data_g1second_order_constant_width_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1second_order_constant_width_packing = &_grib_accessor_class_data_g1second_order_constant_width_packing;
|
||||
grib_accessor_data_g1second_order_constant_width_packing_t _grib_accessor_data_g1second_order_constant_width_packing{};
|
||||
grib_accessor* grib_accessor_data_g1second_order_constant_width_packing = &_grib_accessor_data_g1second_order_constant_width_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1second_order_constant_width_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_simple_packing_t::init(a, v, args);
|
||||
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_accessor_data_simple_packing_t::init(v, args);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
self->half_byte = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->packingType = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->ieee_packing = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->precision = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->widthOfFirstOrderValues = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->N1 = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->N2 = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->numberOfGroups = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->numberOfSecondOrderPackedValues = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->extraValues = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->Ni = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->Nj = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->pl = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->jPointsAreConsecutive = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->bitmap = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->groupWidth = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->edition = 1;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
half_byte_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
packingType_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
ieee_packing_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
precision_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
widthOfFirstOrderValues_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
N1_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
N2_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
numberOfGroups_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
numberOfSecondOrderPackedValues_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
extraValues_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
Ni_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
Nj_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
pl_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
jPointsAreConsecutive_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
bitmap_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
groupWidth_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
edition_ = 1;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_constant_width_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
|
||||
int grib_accessor_data_g1second_order_constant_width_packing_t::value_count(long* numberOfSecondOrderPackedValues)
|
||||
{
|
||||
int err = 0;
|
||||
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
|
||||
int err = 0;
|
||||
*numberOfSecondOrderPackedValues = 0;
|
||||
|
||||
err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues);
|
||||
err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_, numberOfSecondOrderPackedValues);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_float(grib_accessor*, float* val, size_t* len)
|
||||
int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_double(double* values, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
|
||||
int ret = 0;
|
||||
long numberOfGroups, numberOfSecondOrderPackedValues;
|
||||
long groupWidth = 0;
|
||||
|
@ -69,68 +65,68 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
|
|||
long pos = 0;
|
||||
long widthOfFirstOrderValues = 0;
|
||||
long jPointsAreConsecutive;
|
||||
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;
|
||||
long decimal_scale_factor;
|
||||
double s, d;
|
||||
long* secondaryBitmap;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
buf += a->byte_offset();
|
||||
if ((ret = grib_get_long_internal(hand, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
buf += byte_offset();
|
||||
if ((ret = grib_get_long_internal(hand, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(hand, self->jPointsAreConsecutive, &jPointsAreConsecutive)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (jPointsAreConsecutive) {
|
||||
if ((ret = grib_get_long_internal(hand, self->Ni, &numberPerRow)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, Ni_, &numberPerRow)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
if ((ret = grib_get_long_internal(hand, self->Nj, &numberPerRow)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, Nj_, &numberPerRow)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(hand, self->widthOfFirstOrderValues, &widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(hand, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(hand, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(hand, self->numberOfSecondOrderPackedValues,
|
||||
if ((ret = grib_get_long_internal(hand, numberOfSecondOrderPackedValues_,
|
||||
&numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (*len < numberOfSecondOrderPackedValues)
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
if ((ret = grib_get_long_internal(hand, self->groupWidth, &groupWidth)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(hand, groupWidth_, &groupWidth)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
secondaryBitmap = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfSecondOrderPackedValues);
|
||||
secondaryBitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfSecondOrderPackedValues);
|
||||
if (!secondaryBitmap)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
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);
|
||||
if (!firstOrderValues)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
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);
|
||||
if (!X)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -173,23 +169,23 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
|
|||
}
|
||||
|
||||
*len = numberOfSecondOrderPackedValues;
|
||||
grib_context_free(a->context, secondaryBitmap);
|
||||
grib_context_free(a->context, firstOrderValues);
|
||||
grib_context_free(a->context, X);
|
||||
grib_context_free(context_, secondaryBitmap);
|
||||
grib_context_free(context_, firstOrderValues);
|
||||
grib_context_free(context_, X);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_constant_width_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||
int grib_accessor_data_g1second_order_constant_width_packing_t::pack_double(const double* cval, size_t* len)
|
||||
{
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s: Not implemented", cclass_name, __func__);
|
||||
const char* cclass_name = class_name_;
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s: %s: Not implemented", cclass_name, __func__);
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
size_t size = 0;
|
||||
double* values = NULL;
|
||||
int err = 0;
|
||||
|
@ -202,20 +198,20 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
|
|||
if (idx > size)
|
||||
return GRIB_INVALID_ARGUMENT;
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(hand, "values", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
*val = values[idx];
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
size_t size = 0, i = 0;
|
||||
double* values = NULL;
|
||||
int err = 0;
|
||||
|
@ -229,15 +225,15 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
|
|||
if (index_array[i] > size) return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(hand, "values", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
val_array[i] = values[index_array[i]];
|
||||
}
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -15,35 +15,32 @@
|
|||
class grib_accessor_data_g1second_order_constant_width_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1second_order_constant_width_packing */
|
||||
const char* half_byte;
|
||||
const char* packingType;
|
||||
const char* ieee_packing;
|
||||
const char* precision;
|
||||
const char* widthOfFirstOrderValues;
|
||||
const char* N1;
|
||||
const char* N2;
|
||||
const char* numberOfGroups;
|
||||
const char* numberOfSecondOrderPackedValues;
|
||||
const char* extraValues;
|
||||
const char* pl;
|
||||
const char* Ni;
|
||||
const char* Nj;
|
||||
const char* jPointsAreConsecutive;
|
||||
const char* bitmap;
|
||||
const char* groupWidth;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1second_order_constant_width_packing_t : public grib_accessor_class_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1second_order_constant_width_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
|
||||
grib_accessor_data_g1second_order_constant_width_packing_t() :
|
||||
grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_constant_width_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_constant_width_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) 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;
|
||||
|
||||
private:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
const char* precision_;
|
||||
const char* widthOfFirstOrderValues_;
|
||||
const char* N1_;
|
||||
const char* N2_;
|
||||
const char* numberOfGroups_;
|
||||
const char* numberOfSecondOrderPackedValues_;
|
||||
const char* extraValues_;
|
||||
const char* pl_;
|
||||
const char* Ni_;
|
||||
const char* Nj_;
|
||||
const char* jPointsAreConsecutive_;
|
||||
const char* bitmap_;
|
||||
const char* groupWidth_;
|
||||
};
|
||||
|
|
|
@ -12,9 +12,8 @@
|
|||
#include "grib_accessor_class_data_g1second_order_general_extended_packing.h"
|
||||
#include "grib_scaling.h"
|
||||
|
||||
grib_accessor_class_data_g1second_order_general_extended_packing_t _grib_accessor_class_data_g1second_order_general_extended_packing{ "data_g1second_order_general_extended_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1second_order_general_extended_packing = &_grib_accessor_class_data_g1second_order_general_extended_packing;
|
||||
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t _grib_accessor_data_g1second_order_general_extended_packing{};
|
||||
grib_accessor* grib_accessor_data_g1second_order_general_extended_packing = &_grib_accessor_data_g1second_order_general_extended_packing;
|
||||
|
||||
#define MAX_NUMBER_OF_GROUPS 65534
|
||||
#define EFDEBUG 0
|
||||
|
@ -49,54 +48,52 @@ long number_of_bits(grib_handle* h, unsigned long x)
|
|||
if (i >= count) {
|
||||
/*grib_dump_content(h, stdout,"debug", ~0, NULL);*/
|
||||
grib_context_log(h->context, GRIB_LOG_FATAL,
|
||||
"grib_accessor_class_data_g1second_order_general_extended_packing: Number out of range: %ld", x);
|
||||
"grib_accessor_data_g1second_order_general_extended_packing: Number out of range: %ld", x);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1second_order_general_extended_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_simple_packing_t::init(a, v, args);
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
|
||||
grib_handle* handle = grib_handle_of_accessor(a);
|
||||
grib_accessor_data_simple_packing_t::init(v, args);
|
||||
grib_handle* handle = grib_handle_of_accessor(this);
|
||||
|
||||
self->half_byte = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->packingType = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->ieee_packing = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->precision = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->widthOfFirstOrderValues = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->firstOrderValues = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->N1 = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->N2 = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->numberOfGroups = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->codedNumberOfGroups = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->numberOfSecondOrderPackedValues = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->extraValues = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->groupWidths = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->widthOfWidths = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->groupLengths = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->widthOfLengths = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->NL = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->SPD = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->widthOfSPD = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->orderOfSPD = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->numberOfPoints = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->dataFlag = grib_arguments_get_name(handle, args, self->carg++);
|
||||
self->edition = 1;
|
||||
self->dirty = 1;
|
||||
self->dvalues = NULL;
|
||||
self->fvalues = NULL;
|
||||
self->double_dirty = self->float_dirty = 1;
|
||||
self->size = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
half_byte_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
packingType_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
ieee_packing_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
precision_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
widthOfFirstOrderValues_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
firstOrderValues_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
N1_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
N2_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
numberOfGroups_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
codedNumberOfGroups_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
numberOfSecondOrderPackedValues_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
extraValues_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
groupWidths_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
widthOfWidths_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
groupLengths_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
widthOfLengths_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
NL_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
SPD_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
widthOfSPD_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
orderOfSPD_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
numberOfPoints_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
dataFlag_ = grib_arguments_get_name(handle, args, carg_++);
|
||||
edition_ = 1;
|
||||
dirty_ = 1;
|
||||
dvalues_ = NULL;
|
||||
fvalues_ = NULL;
|
||||
double_dirty_ = float_dirty_ = 1;
|
||||
size_ = 0;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
|
||||
long numberOfCodedValues = 0;
|
||||
long numberOfGroups = 0;
|
||||
long numberOfCodedValues = 0;
|
||||
long numberOfGroups = 0;
|
||||
size_t ngroups;
|
||||
long* groupLengths;
|
||||
long orderOfSPD = 0;
|
||||
|
@ -105,62 +102,62 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_co
|
|||
|
||||
*count = 0;
|
||||
|
||||
err = grib_get_long(grib_handle_of_accessor(a), self->numberOfGroups, &numberOfGroups);
|
||||
err = grib_get_long(grib_handle_of_accessor(this), numberOfGroups_, &numberOfGroups);
|
||||
if (err)
|
||||
return err;
|
||||
if (numberOfGroups == 0)
|
||||
return 0;
|
||||
|
||||
groupLengths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups);
|
||||
groupLengths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
ngroups = numberOfGroups;
|
||||
err = grib_get_long_array(grib_handle_of_accessor(a), self->groupLengths, groupLengths, &ngroups);
|
||||
err = grib_get_long_array(grib_handle_of_accessor(this), groupLengths_, groupLengths, &ngroups);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
for (i = 0; i < numberOfGroups; i++)
|
||||
numberOfCodedValues += groupLengths[i];
|
||||
|
||||
grib_context_free(a->context, groupLengths);
|
||||
grib_context_free(context_, groupLengths);
|
||||
|
||||
err = grib_get_long(grib_handle_of_accessor(a), self->orderOfSPD, &orderOfSPD);
|
||||
err = grib_get_long(grib_handle_of_accessor(this), orderOfSPD_, &orderOfSPD);
|
||||
|
||||
*count = numberOfCodedValues + orderOfSPD;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
size_t size;
|
||||
double* values;
|
||||
int err = 0;
|
||||
|
||||
/* GRIB-564: The index idx relates to codedValues NOT values! */
|
||||
err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
if (idx >= size)
|
||||
return GRIB_INVALID_ARGUMENT;
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size);
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
*val = values[idx];
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
size_t size = 0, i = 0;
|
||||
double* values;
|
||||
int err = 0;
|
||||
|
||||
/* GRIB-564: The indexes in index_array relate to codedValues NOT values! */
|
||||
err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -168,28 +165,27 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_d
|
|||
if (index_array[i] > size) return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size);
|
||||
values = (double*)grib_context_malloc_clear(context_, size * sizeof(double));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
val_array[i] = values[index_array[i]];
|
||||
}
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::unpack(double* dvalues, float* fvalues, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
long numberOfGroups, numberOfSecondOrderPackedValues;
|
||||
long* firstOrderValues = 0;
|
||||
long* X = 0;
|
||||
long pos = 0;
|
||||
grib_handle* handle = grib_handle_of_accessor(a);
|
||||
grib_handle* handle = grib_handle_of_accessor(this);
|
||||
unsigned char* buf = (unsigned char*)handle->buffer->data;
|
||||
long i, n;
|
||||
double reference_value;
|
||||
|
@ -207,33 +203,33 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g
|
|||
Assert(!(dvalues && fvalues));
|
||||
|
||||
if (dvalues) {
|
||||
if (!self->double_dirty) {
|
||||
if (*len < self->size) {
|
||||
if (!double_dirty_) {
|
||||
if (*len < size_) {
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
for (k = 0; k < self->size; k++)
|
||||
dvalues[k] = self->dvalues[k];
|
||||
*len = self->size;
|
||||
for (k = 0; k < size_; k++)
|
||||
dvalues[k] = dvalues_[k];
|
||||
*len = size_;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
self->double_dirty = 0;
|
||||
double_dirty_ = 0;
|
||||
}
|
||||
|
||||
if (fvalues) {
|
||||
if (!self->float_dirty) {
|
||||
if (*len < self->size) {
|
||||
if (!float_dirty_) {
|
||||
if (*len < size_) {
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
for (k = 0; k < self->size; k++)
|
||||
fvalues[k] = self->fvalues[k];
|
||||
*len = self->size;
|
||||
for (k = 0; k < size_; k++)
|
||||
fvalues[k] = fvalues_[k];
|
||||
*len = size_;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
self->float_dirty = 0;
|
||||
float_dirty_ = 0;
|
||||
}
|
||||
|
||||
buf += a->byte_offset();
|
||||
ret = a->value_count(&numberOfValues);
|
||||
buf += byte_offset();
|
||||
ret = value_count(&numberOfValues);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -241,51 +237,51 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g
|
|||
if (*len < (size_t)numberOfValues)
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
ngroups = numberOfGroups;
|
||||
groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups);
|
||||
ret = grib_get_long_array(handle, self->groupWidths, groupWidths, &ngroups);
|
||||
groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
ret = grib_get_long_array(handle, groupWidths_, groupWidths, &ngroups);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
groupLengths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups);
|
||||
ret = grib_get_long_array(handle, self->groupLengths, groupLengths, &ngroups);
|
||||
groupLengths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
ret = grib_get_long_array(handle, groupLengths_, groupLengths, &ngroups);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups);
|
||||
ret = grib_get_long_array(handle, self->firstOrderValues, firstOrderValues, &ngroups);
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
ret = grib_get_long_array(handle, firstOrderValues_, firstOrderValues, &ngroups);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_double_internal(handle, self->reference_value, &reference_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_double_internal(handle, reference_value_, &reference_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->numberOfSecondOrderPackedValues,
|
||||
if ((ret = grib_get_long_internal(handle, numberOfSecondOrderPackedValues_,
|
||||
&numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->orderOfSPD, &orderOfSPD)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, orderOfSPD_, &orderOfSPD)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (orderOfSPD) {
|
||||
size_t nSPD = orderOfSPD + 1;
|
||||
SPD = (long*)grib_context_malloc_clear(a->context, sizeof(long) * nSPD);
|
||||
ret = grib_get_long_array(handle, self->SPD, SPD, &nSPD);
|
||||
SPD = (long*)grib_context_malloc_clear(context_, sizeof(long) * nSPD);
|
||||
ret = grib_get_long_array(handle, SPD_, SPD, &nSPD);
|
||||
bias = SPD[orderOfSPD];
|
||||
if (ret != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
||||
X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues);
|
||||
X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues);
|
||||
|
||||
n = orderOfSPD;
|
||||
for (i = 0; i < numberOfGroups; i++) {
|
||||
|
@ -351,64 +347,64 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g
|
|||
}
|
||||
|
||||
if (dvalues) { // double-precision
|
||||
if (self->dvalues) {
|
||||
if (numberOfValues != self->size) {
|
||||
grib_context_free(a->context, self->dvalues);
|
||||
self->dvalues = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfValues);
|
||||
if (dvalues_) {
|
||||
if (numberOfValues != size_) {
|
||||
grib_context_free(context_, dvalues_);
|
||||
dvalues_ = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfValues);
|
||||
}
|
||||
}
|
||||
else {
|
||||
self->dvalues = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfValues);
|
||||
dvalues_ = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfValues);
|
||||
}
|
||||
|
||||
double s = codes_power<double>(binary_scale_factor, 2);
|
||||
double d = codes_power<double>(-decimal_scale_factor, 10);
|
||||
for (i = 0; i < numberOfValues; i++) {
|
||||
dvalues[i] = (double)(((X[i] * s) + reference_value) * d);
|
||||
self->dvalues[i] = dvalues[i];
|
||||
dvalues[i] = (double)(((X[i] * s) + reference_value) * d);
|
||||
dvalues_[i] = dvalues[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// single-precision
|
||||
if (self->fvalues) {
|
||||
if (numberOfValues != self->size) {
|
||||
grib_context_free(a->context, self->fvalues);
|
||||
self->fvalues = (float*)grib_context_malloc_clear(a->context, sizeof(float) * numberOfValues);
|
||||
if (fvalues_) {
|
||||
if (numberOfValues != size_) {
|
||||
grib_context_free(context_, fvalues_);
|
||||
fvalues_ = (float*)grib_context_malloc_clear(context_, sizeof(float) * numberOfValues);
|
||||
}
|
||||
}
|
||||
else {
|
||||
self->fvalues = (float*)grib_context_malloc_clear(a->context, sizeof(float) * numberOfValues);
|
||||
fvalues_ = (float*)grib_context_malloc_clear(context_, sizeof(float) * numberOfValues);
|
||||
}
|
||||
|
||||
float s = codes_power<float>(binary_scale_factor, 2);
|
||||
float d = codes_power<float>(-decimal_scale_factor, 10);
|
||||
for (i = 0; i < numberOfValues; i++) {
|
||||
fvalues[i] = (float)(((X[i] * s) + reference_value) * d);
|
||||
self->fvalues[i] = fvalues[i];
|
||||
fvalues[i] = (float)(((X[i] * s) + reference_value) * d);
|
||||
fvalues_[i] = fvalues[i];
|
||||
}
|
||||
}
|
||||
|
||||
*len = numberOfValues;
|
||||
self->size = numberOfValues;
|
||||
*len = numberOfValues;
|
||||
size_ = numberOfValues;
|
||||
|
||||
grib_context_free(a->context, X);
|
||||
grib_context_free(a->context, groupWidths);
|
||||
grib_context_free(a->context, groupLengths);
|
||||
grib_context_free(a->context, firstOrderValues);
|
||||
grib_context_free(context_, X);
|
||||
grib_context_free(context_, groupWidths);
|
||||
grib_context_free(context_, groupLengths);
|
||||
grib_context_free(context_, firstOrderValues);
|
||||
if (orderOfSPD)
|
||||
grib_context_free(a->context, SPD);
|
||||
grib_context_free(context_, SPD);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_float(float* values, size_t* len)
|
||||
{
|
||||
return unpack(a, NULL, values, len);
|
||||
return unpack(NULL, values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_double(double* values, size_t* len)
|
||||
{
|
||||
return unpack(a, values, NULL, len);
|
||||
return unpack(values, NULL, len);
|
||||
}
|
||||
|
||||
static void grib_split_long_groups(grib_handle* hand, grib_context* c, long* numberOfGroups, long* lengthOfSecondOrderValues,
|
||||
|
@ -543,13 +539,12 @@ static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, lo
|
|||
}
|
||||
|
||||
// For the old implementation of pack_double, see
|
||||
// src/deprecated/grib_accessor_class_data_g1second_order_general_extended_packing.pack_double.cc
|
||||
// src/deprecated/grib_accessor_data_g1second_order_general_extended_packing.pack_double.cc
|
||||
// See ECC-441 and ECC-261
|
||||
int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_extended_packing_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
|
||||
int ret = 0;
|
||||
int grib2 = 0;
|
||||
int ret = 0;
|
||||
int grib2 = 0;
|
||||
long bits_per_value, orderOfSPD, binary_scale_factor;
|
||||
long numberOfValues;
|
||||
double max, min;
|
||||
|
@ -587,10 +582,10 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
int computeGroupA = 1;
|
||||
long dataHeadersLength, widthsLength, lengthsLength, firstOrderValuesLength;
|
||||
long decimal_scale_factor;
|
||||
grib_handle* handle = grib_handle_of_accessor(a);
|
||||
grib_handle* handle = grib_handle_of_accessor(this);
|
||||
long optimize_scaling_factor = 0;
|
||||
|
||||
self->double_dirty = 1;
|
||||
double_dirty_ = 1;
|
||||
|
||||
numberOfValues = *len;
|
||||
|
||||
|
@ -606,16 +601,16 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
}
|
||||
|
||||
/* ECC-1219: packingType conversion from grid_ieee to grid_second_order */
|
||||
if ((ret = get_bits_per_value(handle, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((ret = get_bits_per_value(handle, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, optimize_scaling_factor_, &optimize_scaling_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (optimize_scaling_factor) {
|
||||
const int compat_gribex = handle->context->gribex_mode_on && self->edition == 1;
|
||||
const int compat_gribex = handle->context->gribex_mode_on && edition_ == 1;
|
||||
const int compat_32bit = 1;
|
||||
if ((ret = grib_optimize_decimal_factor(a, self->reference_value,
|
||||
if ((ret = grib_optimize_decimal_factor(this, reference_value_,
|
||||
max, min, bits_per_value,
|
||||
compat_gribex, compat_32bit,
|
||||
&decimal_scale_factor, &binary_scale_factor, &reference_value)) != GRIB_SUCCESS)
|
||||
|
@ -626,26 +621,26 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
/*min = min * decimal;*/
|
||||
/*max = max * decimal;*/
|
||||
|
||||
if ((ret = grib_set_long_internal(handle, self->decimal_scale_factor, decimal_scale_factor)) !=
|
||||
if ((ret = grib_set_long_internal(handle, decimal_scale_factor_, decimal_scale_factor)) !=
|
||||
GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
/* For constant fields set decimal scale factor to 0 (See GRIB-165) */
|
||||
if (min == max) {
|
||||
grib_set_long_internal(handle, self->decimal_scale_factor, 0);
|
||||
grib_set_long_internal(handle, decimal_scale_factor_, 0);
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
decimal = codes_power<double>(decimal_scale_factor, 10);
|
||||
min = min * decimal;
|
||||
max = max * decimal;
|
||||
|
||||
if (grib_get_nearest_smaller_value(handle, self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"Unable to find nearest_smaller_value of %g for %s", min, self->reference_value);
|
||||
if (grib_get_nearest_smaller_value(handle, reference_value_, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(context_, GRIB_LOG_ERROR,
|
||||
"Unable to find nearest_smaller_value of %g for %s", min, reference_value_);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &ret);
|
||||
|
@ -654,31 +649,31 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
divisor = codes_power<double>(-binary_scale_factor, 2);
|
||||
}
|
||||
|
||||
if ((ret = grib_set_long_internal(handle, self->binary_scale_factor, binary_scale_factor)) !=
|
||||
if ((ret = grib_set_long_internal(handle, binary_scale_factor_, binary_scale_factor)) !=
|
||||
GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_set_double_internal(handle, self->reference_value, reference_value)) !=
|
||||
if ((ret = grib_set_double_internal(handle, reference_value_, reference_value)) !=
|
||||
GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->offsetdata, &offsetBeforeData)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, offsetdata_, &offsetBeforeData)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->offsetsection, &offsetSection4)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, offsetsection_, &offsetSection4)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->orderOfSPD, &orderOfSPD)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(handle, orderOfSPD_, &orderOfSPD)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues);
|
||||
X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues);
|
||||
for (i = 0; i < numberOfValues; i++) {
|
||||
X[i] = (((val[i] * decimal) - reference_value) * divisor) + 0.5;
|
||||
}
|
||||
|
||||
groupLengths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues);
|
||||
groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues);
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues);
|
||||
groupLengths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues);
|
||||
groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues);
|
||||
firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues);
|
||||
|
||||
/* spatial differencing */
|
||||
switch (orderOfSPD) {
|
||||
|
@ -955,7 +950,7 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
Focus on groups which have been shrank as left groups of an A group taking
|
||||
some of their elements.
|
||||
*/
|
||||
offsets = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups);
|
||||
offsets = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups);
|
||||
offsets[0] = orderOfSPD;
|
||||
for (i = 1; i < numberOfGroups; i++)
|
||||
offsets[i] = offsets[i - 1] + groupLengths[i - 1];
|
||||
|
@ -1017,7 +1012,7 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
}
|
||||
}
|
||||
}
|
||||
grib_context_free(a->context, offsets);
|
||||
grib_context_free(context_, offsets);
|
||||
}
|
||||
|
||||
maxWidth = groupWidths[0];
|
||||
|
@ -1030,7 +1025,7 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
}
|
||||
|
||||
if (maxWidth < 0 || maxLength < 0) {
|
||||
grib_context_log(a->parent->h->context, GRIB_LOG_ERROR, "Cannot compute parameters for second order packing.");
|
||||
grib_context_log(parent_->h->context, GRIB_LOG_ERROR, "Cannot compute parameters for second order packing.");
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
widthOfWidths = number_of_bits(handle, maxWidth);
|
||||
|
@ -1041,8 +1036,8 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
lengthOfSecondOrderValues += groupLengths[i] * groupWidths[i];
|
||||
}
|
||||
|
||||
if (!a->context->no_big_group_split) {
|
||||
grib_split_long_groups(handle, a->context, &numberOfGroups, &lengthOfSecondOrderValues,
|
||||
if (!context_->no_big_group_split) {
|
||||
grib_split_long_groups(handle, context_, &numberOfGroups, &lengthOfSecondOrderValues,
|
||||
groupLengths, &widthOfLengths, groupWidths, widthOfWidths,
|
||||
firstOrderValues, widthOfFirstOrderValues);
|
||||
}
|
||||
|
@ -1058,12 +1053,12 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
|
||||
/* writing SPD */
|
||||
if (orderOfSPD) {
|
||||
if ((ret = grib_set_long_internal(handle, self->widthOfSPD, widthOfSPD)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, widthOfSPD_, widthOfSPD)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* end writing SPD */
|
||||
if ((ret = grib_set_long_internal(handle, self->widthOfFirstOrderValues, widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, widthOfFirstOrderValues_, widthOfFirstOrderValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
dataHeadersLength = 25;
|
||||
|
@ -1081,9 +1076,9 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
N2 = N2 > 65535 ? 65535 : N2;
|
||||
N1 = N1 > 65535 ? 65535 : N1;
|
||||
|
||||
grib_set_long(handle, self->NL, NL);
|
||||
grib_set_long(handle, self->N1, N1);
|
||||
grib_set_long(handle, self->N2, N2);
|
||||
grib_set_long(handle, NL_, NL);
|
||||
grib_set_long(handle, N1_, N1);
|
||||
grib_set_long(handle, N2_, N2);
|
||||
|
||||
if (numberOfGroups > 65535) {
|
||||
extraValues = numberOfGroups / 65536;
|
||||
|
@ -1096,34 +1091,34 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
|
||||
/* if no extraValues key present it is a GRIB2*/
|
||||
grib2 = 0;
|
||||
if ((ret = grib_set_long(handle, self->extraValues, extraValues)) != GRIB_SUCCESS) {
|
||||
if ((ret = grib_set_long(handle, extraValues_, extraValues)) != GRIB_SUCCESS) {
|
||||
codedNumberOfGroups = numberOfGroups;
|
||||
grib2 = 1;
|
||||
}
|
||||
|
||||
if ((ret = grib_set_long_internal(handle, self->codedNumberOfGroups, codedNumberOfGroups)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, codedNumberOfGroups_, codedNumberOfGroups)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
numberOfSecondOrderPackedValues = numberOfValues - orderOfSPD;
|
||||
if (!grib2 && numberOfSecondOrderPackedValues > 65535)
|
||||
numberOfSecondOrderPackedValues = 65535;
|
||||
|
||||
if ((ret = grib_set_long_internal(handle, self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, numberOfSecondOrderPackedValues_, numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (grib2) {
|
||||
if ((ret = grib_set_long_internal(handle, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, bits_per_value_, bits_per_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
if ((ret = grib_set_long_internal(handle, self->bits_per_value, 0)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, bits_per_value_, 0)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = grib_set_long_internal(handle, self->widthOfWidths, widthOfWidths)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, widthOfWidths_, widthOfWidths)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_set_long_internal(handle, self->widthOfLengths, widthOfLengths)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, widthOfLengths_, widthOfLengths)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
lengthOfSecondOrderValues = 0;
|
||||
|
@ -1137,10 +1132,10 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
/* padding section 4 to an even number of octets */
|
||||
size = ((size + offsetBeforeData - offsetSection4) % 2) ? size + 1 : size;
|
||||
half_byte = 8 * size - sizebits;
|
||||
if ((ret = grib_set_long_internal(handle, self->half_byte, half_byte)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(handle, half_byte_, half_byte)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
buffer = (unsigned char*)grib_context_malloc_clear(a->context, size);
|
||||
buffer = (unsigned char*)grib_context_malloc_clear(context_, size);
|
||||
|
||||
pos = 0;
|
||||
if (orderOfSPD) {
|
||||
|
@ -1152,20 +1147,20 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
for (i = 0; i < orderOfSPD; i++)
|
||||
SPD[i] = X[i];
|
||||
SPD[orderOfSPD] = bias;
|
||||
ret = grib_set_long_array_internal(handle, self->SPD, SPD, nSPD);
|
||||
ret = grib_set_long_array_internal(handle, SPD_, SPD, nSPD);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = grib_set_long_array_internal(handle, self->groupWidths, groupWidths, (size_t)numberOfGroups);
|
||||
ret = grib_set_long_array_internal(handle, groupWidths_, groupWidths, (size_t)numberOfGroups);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = grib_set_long_array_internal(handle, self->groupLengths, groupLengths, (size_t)numberOfGroups);
|
||||
ret = grib_set_long_array_internal(handle, groupLengths_, groupLengths, (size_t)numberOfGroups);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = grib_set_long_array_internal(handle, self->firstOrderValues, firstOrderValues, (size_t)numberOfGroups);
|
||||
ret = grib_set_long_array_internal(handle, firstOrderValues_, firstOrderValues, (size_t)numberOfGroups);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -1193,31 +1188,30 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou
|
|||
}
|
||||
|
||||
/* ECC-259: Set correct number of values */
|
||||
ret = grib_set_long_internal(a->parent->h, self->number_of_values, *len);
|
||||
ret = grib_set_long_internal(parent_->h, number_of_values_, *len);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = grib_buffer_replace(a, buffer, size, 1, 1);
|
||||
ret = grib_buffer_replace(this, buffer, size, 1, 1);
|
||||
if (ret) return ret;
|
||||
|
||||
grib_context_free(a->context, buffer);
|
||||
grib_context_free(a->context, X);
|
||||
grib_context_free(a->context, groupLengths);
|
||||
grib_context_free(a->context, groupWidths);
|
||||
grib_context_free(a->context, firstOrderValues);
|
||||
grib_context_free(context_, buffer);
|
||||
grib_context_free(context_, X);
|
||||
grib_context_free(context_, groupLengths);
|
||||
grib_context_free(context_, groupWidths);
|
||||
grib_context_free(context_, firstOrderValues);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
void grib_accessor_class_data_g1second_order_general_extended_packing_t::destroy(grib_context* context, grib_accessor* a)
|
||||
void grib_accessor_data_g1second_order_general_extended_packing_t::destroy(grib_context* context)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
|
||||
if (self->dvalues != NULL) {
|
||||
grib_context_free(context, self->dvalues);
|
||||
self->dvalues = NULL;
|
||||
if (dvalues_ != NULL) {
|
||||
grib_context_free(context, dvalues_);
|
||||
dvalues_ = NULL;
|
||||
}
|
||||
if (self->fvalues != NULL) {
|
||||
grib_context_free(context, self->fvalues);
|
||||
self->fvalues = NULL;
|
||||
if (fvalues_ != NULL) {
|
||||
grib_context_free(context, fvalues_);
|
||||
fvalues_ = NULL;
|
||||
}
|
||||
grib_accessor_class_data_simple_packing_t::destroy(context, a);
|
||||
grib_accessor_data_simple_packing_t::destroy(context);
|
||||
}
|
||||
|
|
|
@ -15,50 +15,47 @@
|
|||
class grib_accessor_data_g1second_order_general_extended_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1second_order_general_extended_packing */
|
||||
const char* half_byte;
|
||||
const char* packingType;
|
||||
const char* ieee_packing;
|
||||
const char* precision;
|
||||
const char* widthOfFirstOrderValues;
|
||||
const char* firstOrderValues;
|
||||
const char* N1;
|
||||
const char* N2;
|
||||
const char* numberOfGroups;
|
||||
const char* codedNumberOfGroups;
|
||||
const char* numberOfSecondOrderPackedValues;
|
||||
const char* extraValues;
|
||||
const char* groupWidths;
|
||||
const char* widthOfWidths;
|
||||
const char* groupLengths;
|
||||
const char* widthOfLengths;
|
||||
const char* NL;
|
||||
const char* SPD;
|
||||
const char* widthOfSPD;
|
||||
const char* orderOfSPD;
|
||||
const char* numberOfPoints;
|
||||
const char* dataFlag;
|
||||
double* dvalues;
|
||||
float* fvalues;
|
||||
int double_dirty;
|
||||
int float_dirty;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1second_order_general_extended_packing_t : public grib_accessor_class_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1second_order_general_extended_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
|
||||
grib_accessor_data_g1second_order_general_extended_packing_t() :
|
||||
grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_general_extended_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_general_extended_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void destroy(grib_context*, grib_accessor*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void destroy(grib_context*) override;
|
||||
void init(const long, grib_arguments*) 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;
|
||||
|
||||
private:
|
||||
int unpack(grib_accessor* a, double*, float*, size_t*);
|
||||
int unpack(double*, float*, size_t*);
|
||||
|
||||
private:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
const char* precision_;
|
||||
const char* widthOfFirstOrderValues_;
|
||||
const char* firstOrderValues_;
|
||||
const char* N1_;
|
||||
const char* N2_;
|
||||
const char* numberOfGroups_;
|
||||
const char* codedNumberOfGroups_;
|
||||
const char* numberOfSecondOrderPackedValues_;
|
||||
const char* extraValues_;
|
||||
const char* groupWidths_;
|
||||
const char* widthOfWidths_;
|
||||
const char* groupLengths_;
|
||||
const char* widthOfLengths_;
|
||||
const char* NL_;
|
||||
const char* SPD_;
|
||||
const char* widthOfSPD_;
|
||||
const char* orderOfSPD_;
|
||||
const char* numberOfPoints_;
|
||||
const char* dataFlag_;
|
||||
double* dvalues_;
|
||||
float* fvalues_;
|
||||
int double_dirty_;
|
||||
int float_dirty_;
|
||||
size_t size_;
|
||||
};
|
||||
|
|
|
@ -10,51 +10,47 @@
|
|||
|
||||
#include "grib_accessor_class_data_g1second_order_general_packing.h"
|
||||
|
||||
grib_accessor_class_data_g1second_order_general_packing_t _grib_accessor_class_data_g1second_order_general_packing{ "data_g1second_order_general_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1second_order_general_packing = &_grib_accessor_class_data_g1second_order_general_packing;
|
||||
grib_accessor_data_g1second_order_general_packing_t _grib_accessor_data_g1second_order_general_packing{};
|
||||
grib_accessor* grib_accessor_data_g1second_order_general_packing = &_grib_accessor_data_g1second_order_general_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g1second_order_general_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1second_order_general_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_simple_packing_t::init(a, v, args);
|
||||
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_accessor_data_simple_packing_t::init(v, args);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
self->half_byte = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->packingType = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->ieee_packing = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->precision = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->widthOfFirstOrderValues = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->N1 = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->N2 = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->numberOfGroups = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->numberOfSecondOrderPackedValues = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->extraValues = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->Ni = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->Nj = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->pl = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->jPointsAreConsecutive = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->bitmap = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->groupWidths = grib_arguments_get_name(hand, args, self->carg++);
|
||||
self->edition = 1;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
half_byte_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
packingType_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
ieee_packing_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
precision_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
widthOfFirstOrderValues_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
N1_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
N2_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
numberOfGroups_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
numberOfSecondOrderPackedValues_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
extraValues_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
Ni_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
Nj_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
pl_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
jPointsAreConsecutive_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
bitmap_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
groupWidths_ = grib_arguments_get_name(hand, args, carg_++);
|
||||
edition_ = 1;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
|
||||
int grib_accessor_data_g1second_order_general_packing_t::value_count(long* numberOfSecondOrderPackedValues)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
|
||||
*numberOfSecondOrderPackedValues = 0;
|
||||
|
||||
int err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues);
|
||||
int err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_, numberOfSecondOrderPackedValues);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
|
||||
int ret = 0;
|
||||
long numberOfGroups, numberOfSecondOrderPackedValues;
|
||||
long* groupWidths = 0;
|
||||
|
@ -62,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;
|
||||
|
@ -72,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;
|
||||
|
@ -146,30 +142,30 @@ 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_class_data_g1second_order_general_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_packing_t::unpack_float(float* values, size_t* len)
|
||||
{
|
||||
return unpack_real<float>(a, values, len);
|
||||
return unpack_real<float>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_packing_t::unpack_double(double* values, size_t* len)
|
||||
{
|
||||
return unpack_real<double>(a, values, len);
|
||||
return unpack_real<double>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_general_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||
int grib_accessor_data_g1second_order_general_packing_t::pack_double(const double* cval, size_t* len)
|
||||
{
|
||||
/* return GRIB_NOT_IMPLEMENTED; */
|
||||
char type[] = "grid_second_order";
|
||||
size_t size = strlen(type);
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
grib_handle* hand = grib_handle_of_accessor(this);
|
||||
|
||||
int err = grib_set_string(hand, "packingType", type, &size);
|
||||
if (err)
|
||||
|
|
|
@ -16,33 +16,32 @@
|
|||
class grib_accessor_data_g1second_order_general_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1second_order_general_packing */
|
||||
const char* half_byte;
|
||||
const char* packingType;
|
||||
const char* ieee_packing;
|
||||
const char* precision;
|
||||
const char* widthOfFirstOrderValues;
|
||||
const char* N1;
|
||||
const char* N2;
|
||||
const char* numberOfGroups;
|
||||
const char* numberOfSecondOrderPackedValues;
|
||||
const char* extraValues;
|
||||
const char* pl;
|
||||
const char* Ni;
|
||||
const char* Nj;
|
||||
const char* jPointsAreConsecutive;
|
||||
const char* bitmap;
|
||||
const char* groupWidths;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1second_order_general_packing_t : public grib_accessor_class_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1second_order_general_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
|
||||
grib_accessor_data_g1second_order_general_packing_t() :
|
||||
grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_general_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_general_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
const char* precision_;
|
||||
const char* widthOfFirstOrderValues_;
|
||||
const char* N1_;
|
||||
const char* N2_;
|
||||
const char* numberOfGroups_;
|
||||
const char* numberOfSecondOrderPackedValues_;
|
||||
const char* extraValues_;
|
||||
const char* pl_;
|
||||
const char* Ni_;
|
||||
const char* Nj_;
|
||||
const char* jPointsAreConsecutive_;
|
||||
const char* bitmap_;
|
||||
const char* groupWidths_;
|
||||
|
||||
template <typename T> int unpack_real(T* values, size_t* len);
|
||||
};
|
||||
|
|
|
@ -10,58 +10,54 @@
|
|||
|
||||
#include "grib_accessor_class_data_g1second_order_row_by_row_packing.h"
|
||||
|
||||
grib_accessor_class_data_g1second_order_row_by_row_packing_t _grib_accessor_class_data_g1second_order_row_by_row_packing{ "data_g1second_order_row_by_row_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1second_order_row_by_row_packing = &_grib_accessor_class_data_g1second_order_row_by_row_packing;
|
||||
grib_accessor_data_g1second_order_row_by_row_packing_t _grib_accessor_data_g1second_order_row_by_row_packing{};
|
||||
grib_accessor* grib_accessor_data_g1second_order_row_by_row_packing = &_grib_accessor_data_g1second_order_row_by_row_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g1second_order_row_by_row_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1second_order_row_by_row_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_simple_packing_t::init(a, v, args);
|
||||
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_accessor_data_simple_packing_t::init(v, args);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
|
||||
self->half_byte = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->packingType = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->ieee_packing = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->precision = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->widthOfFirstOrderValues = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->N1 = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->N2 = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->numberOfGroups = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->numberOfSecondOrderPackedValues = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->extraValues = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->Ni = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->Nj = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->pl = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->jPointsAreConsecutive = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->groupWidths = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->bitmap = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->edition = 1;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
half_byte_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
packingType_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
ieee_packing_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
precision_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
widthOfFirstOrderValues_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
N1_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
N2_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
numberOfGroups_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
numberOfSecondOrderPackedValues_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
extraValues_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
Ni_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
Nj_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
pl_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
jPointsAreConsecutive_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
groupWidths_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
bitmap_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
edition_ = 1;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::value_count(long* count)
|
||||
{
|
||||
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);
|
||||
long n = 0, i = 0;
|
||||
long numberOfRows = 0;
|
||||
long numberOfRows = 0;
|
||||
long jPointsAreConsecutive = 0;
|
||||
long Ni = 0, Nj = 0;
|
||||
int bitmapPresent = 0;
|
||||
size_t plSize = 0;
|
||||
long* pl = 0;
|
||||
int ret = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_context* c = context_;
|
||||
|
||||
if (self->bitmap)
|
||||
if (bitmap_)
|
||||
bitmapPresent = 1;
|
||||
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 ((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;
|
||||
|
@ -71,10 +67,10 @@ int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(gr
|
|||
}
|
||||
|
||||
plSize = 0;
|
||||
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;
|
||||
}
|
||||
ret = 0;
|
||||
|
@ -92,13 +88,13 @@ int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(gr
|
|||
else {
|
||||
numberOfPoints = Ni * Nj;
|
||||
}
|
||||
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);
|
||||
for (i = 0; i < numberOfPoints; i++)
|
||||
n += *(bitmap++);
|
||||
|
||||
grib_context_free(a->context, pbitmap);
|
||||
grib_context_free(context_, pbitmap);
|
||||
}
|
||||
else {
|
||||
if (plSize) {
|
||||
|
@ -117,12 +113,10 @@ int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(gr
|
|||
}
|
||||
|
||||
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);
|
||||
int ret = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
int ret = 0;
|
||||
long numberOfGroups, numberOfSecondOrderPackedValues;
|
||||
long* groupWidths = 0;
|
||||
long* firstOrderValues = 0;
|
||||
|
@ -143,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;
|
||||
|
@ -172,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) {
|
||||
|
@ -184,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++) {
|
||||
|
@ -203,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) {
|
||||
|
@ -216,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);
|
||||
|
||||
|
@ -248,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++) {
|
||||
|
@ -273,31 +267,31 @@ 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_class_data_g1second_order_row_by_row_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_float(float* values, size_t* len)
|
||||
{
|
||||
return unpack_real<float>(a, values, len);
|
||||
return unpack_real<float>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len)
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_double(double* values, size_t* len)
|
||||
{
|
||||
return unpack_real<double>(a, values, len);
|
||||
return unpack_real<double>(values, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||
int grib_accessor_data_g1second_order_row_by_row_packing_t::pack_double(const double* cval, size_t* len)
|
||||
{
|
||||
int err = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
char type[] = "grid_second_order";
|
||||
size_t size = strlen(type);
|
||||
|
||||
|
|
|
@ -16,33 +16,32 @@
|
|||
class grib_accessor_data_g1second_order_row_by_row_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1second_order_row_by_row_packing */
|
||||
const char* half_byte;
|
||||
const char* packingType;
|
||||
const char* ieee_packing;
|
||||
const char* precision;
|
||||
const char* widthOfFirstOrderValues;
|
||||
const char* N1;
|
||||
const char* N2;
|
||||
const char* numberOfGroups;
|
||||
const char* numberOfSecondOrderPackedValues;
|
||||
const char* extraValues;
|
||||
const char* pl;
|
||||
const char* Ni;
|
||||
const char* Nj;
|
||||
const char* jPointsAreConsecutive;
|
||||
const char* bitmap;
|
||||
const char* groupWidths;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1second_order_row_by_row_packing_t : public grib_accessor_class_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1second_order_row_by_row_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
|
||||
grib_accessor_data_g1second_order_row_by_row_packing_t() :
|
||||
grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_row_by_row_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_row_by_row_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
const char* precision_;
|
||||
const char* widthOfFirstOrderValues_;
|
||||
const char* N1_;
|
||||
const char* N2_;
|
||||
const char* numberOfGroups_;
|
||||
const char* numberOfSecondOrderPackedValues_;
|
||||
const char* extraValues_;
|
||||
const char* pl_;
|
||||
const char* Ni_;
|
||||
const char* Nj_;
|
||||
const char* jPointsAreConsecutive_;
|
||||
const char* bitmap_;
|
||||
const char* groupWidths_;
|
||||
|
||||
template <typename T> int unpack_real(T* values, size_t* len);
|
||||
};
|
||||
|
|
|
@ -10,30 +10,27 @@
|
|||
|
||||
#include "grib_accessor_class_data_g1secondary_bitmap.h"
|
||||
|
||||
grib_accessor_class_data_g1secondary_bitmap_t _grib_accessor_class_data_g1secondary_bitmap{ "data_g1secondary_bitmap" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1secondary_bitmap = &_grib_accessor_class_data_g1secondary_bitmap;
|
||||
grib_accessor_data_g1secondary_bitmap_t _grib_accessor_data_g1secondary_bitmap{};
|
||||
grib_accessor* grib_accessor_data_g1secondary_bitmap = &_grib_accessor_data_g1secondary_bitmap;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g1secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1secondary_bitmap_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_secondary_bitmap_t::init(a, v, args);
|
||||
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
|
||||
self->number_of_ones = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
|
||||
grib_accessor_data_secondary_bitmap_t::init(v, args);
|
||||
number_of_ones_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 4);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_g1secondary_bitmap_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
|
||||
size_t len = 0;
|
||||
int err = 0;
|
||||
int err = 0;
|
||||
long expand_by;
|
||||
*count = 0;
|
||||
|
||||
err = grib_get_long_internal(grib_handle_of_accessor(a), self->expand_by, &expand_by);
|
||||
err = grib_get_long_internal(grib_handle_of_accessor(this), expand_by_, &expand_by);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &len);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), primary_bitmap_, &len);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -41,10 +38,8 @@ int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a,
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_g1secondary_bitmap_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
|
||||
|
||||
int err = 0;
|
||||
long primary_len = 0;
|
||||
long secondary_len = 0;
|
||||
|
@ -62,12 +57,12 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a,
|
|||
if (*len == 0)
|
||||
return GRIB_NO_VALUES;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(this), expand_by_, &expand_by)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if (expand_by <= 0)
|
||||
return GRIB_ENCODING_ERROR;
|
||||
|
||||
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 % expand_by) {
|
||||
|
@ -76,14 +71,14 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a,
|
|||
}
|
||||
|
||||
primary_len = *len / expand_by;
|
||||
primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double));
|
||||
primary_bitmap = (double*)grib_context_malloc_clear(context_, primary_len * sizeof(double));
|
||||
if (!primary_bitmap)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
secondary_len = *len;
|
||||
secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double));
|
||||
secondary_bitmap = (double*)grib_context_malloc_clear(context_, secondary_len * sizeof(double));
|
||||
if (!secondary_bitmap) {
|
||||
grib_context_free(a->context, primary_bitmap);
|
||||
grib_context_free(context_, primary_bitmap);
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -115,15 +110,15 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a,
|
|||
/*printf("QQQQQQQ %ld %ld second=%ld\n",primary_len,on,m);*/
|
||||
Assert(k == primary_len);
|
||||
|
||||
err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k);
|
||||
err = grib_set_double_array_internal(grib_handle_of_accessor(this), primary_bitmap_, primary_bitmap, k);
|
||||
if (err == GRIB_SUCCESS)
|
||||
err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m);
|
||||
err = grib_set_double_array_internal(grib_handle_of_accessor(this), secondary_bitmap_, secondary_bitmap, m);
|
||||
|
||||
grib_context_free(a->context, primary_bitmap);
|
||||
grib_context_free(a->context, secondary_bitmap);
|
||||
grib_context_free(context_, primary_bitmap);
|
||||
grib_context_free(context_, secondary_bitmap);
|
||||
|
||||
if (err == GRIB_SUCCESS)
|
||||
err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_ones, on);
|
||||
err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_ones_, on);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -15,16 +15,13 @@
|
|||
class grib_accessor_data_g1secondary_bitmap_t : public grib_accessor_data_secondary_bitmap_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1secondary_bitmap */
|
||||
const char* number_of_ones;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1secondary_bitmap_t : public grib_accessor_class_data_secondary_bitmap_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1secondary_bitmap_t(const char* name) : grib_accessor_class_data_secondary_bitmap_t(name) {}
|
||||
grib_accessor_data_g1secondary_bitmap_t() :
|
||||
grib_accessor_data_secondary_bitmap_t() { class_name_ = "data_g1secondary_bitmap"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1secondary_bitmap_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
private:
|
||||
const char* number_of_ones_;
|
||||
};
|
||||
|
|
|
@ -10,32 +10,29 @@
|
|||
|
||||
#include "grib_accessor_class_data_g1shsimple_packing.h"
|
||||
|
||||
grib_accessor_class_data_g1shsimple_packing_t _grib_accessor_class_data_g1shsimple_packing{ "data_g1shsimple_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1shsimple_packing = &_grib_accessor_class_data_g1shsimple_packing;
|
||||
grib_accessor_data_g1shsimple_packing_t _grib_accessor_data_g1shsimple_packing{};
|
||||
grib_accessor* grib_accessor_data_g1shsimple_packing = &_grib_accessor_data_g1shsimple_packing;
|
||||
|
||||
|
||||
int grib_accessor_class_data_g1shsimple_packing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_g1shsimple_packing_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a;
|
||||
size_t len = 0;
|
||||
int err = 0;
|
||||
size_t len = 0;
|
||||
int err = 0;
|
||||
|
||||
err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), coded_values_, &len);
|
||||
len += 1;
|
||||
|
||||
*count = len;
|
||||
return err;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_g1shsimple_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a;
|
||||
int err = GRIB_SUCCESS;
|
||||
int err = GRIB_SUCCESS;
|
||||
|
||||
size_t coded_n_vals = 0;
|
||||
size_t n_vals = 0;
|
||||
|
||||
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;
|
||||
|
||||
n_vals = coded_n_vals + 1;
|
||||
|
@ -45,17 +42,17 @@ int grib_accessor_class_data_g1shsimple_packing_t::unpack_double(grib_accessor*
|
|||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(grib_handle_of_accessor(this), real_part_, val)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
val++;
|
||||
|
||||
if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &coded_n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(grib_handle_of_accessor(this), coded_values_, val, &coded_n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"grib_accessor_data_g1shsimple_packing_t_bitmap : unpack_double : creating %s, %d values",
|
||||
a->name, n_vals);
|
||||
name_, n_vals);
|
||||
|
||||
*len = n_vals;
|
||||
|
||||
|
|
|
@ -15,14 +15,9 @@
|
|||
class grib_accessor_data_g1shsimple_packing_t : public grib_accessor_data_shsimple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1shsimple_packing */
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1shsimple_packing_t : public grib_accessor_class_data_shsimple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1shsimple_packing_t(const char* name) : grib_accessor_class_data_shsimple_packing_t(name) {}
|
||||
grib_accessor_data_g1shsimple_packing_t() :
|
||||
grib_accessor_data_shsimple_packing_t() { class_name_ = "data_g1shsimple_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1shsimple_packing_t{}; }
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
};
|
||||
|
|
|
@ -11,39 +11,34 @@
|
|||
#include "grib_accessor_class_data_g1simple_packing.h"
|
||||
#include "grib_scaling.h"
|
||||
|
||||
grib_accessor_class_data_g1simple_packing_t _grib_accessor_class_data_g1simple_packing{ "data_g1simple_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g1simple_packing = &_grib_accessor_class_data_g1simple_packing;
|
||||
grib_accessor_data_g1simple_packing_t _grib_accessor_data_g1simple_packing{};
|
||||
grib_accessor* grib_accessor_data_g1simple_packing = &_grib_accessor_data_g1simple_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g1simple_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_data_simple_packing_t::init(a, v, args);
|
||||
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
|
||||
grib_accessor_data_simple_packing_t::init(v, args);
|
||||
|
||||
self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
|
||||
self->edition = 1;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
half_byte_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
packingType_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
ieee_packing_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++);
|
||||
edition_ = 1;
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, long* number_of_values)
|
||||
int grib_accessor_data_g1simple_packing_t::value_count(long* number_of_values)
|
||||
{
|
||||
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
|
||||
*number_of_values = 0;
|
||||
|
||||
/* Special case for when values are cleared */
|
||||
/*if(a->length == 0)
|
||||
/*if(length_ == 0)
|
||||
return 0;*/
|
||||
|
||||
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values);
|
||||
return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, number_of_values);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||
int grib_accessor_data_g1simple_packing_t::pack_double(const double* cval, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
|
||||
|
||||
size_t n_vals = *len;
|
||||
long half_byte = 0;
|
||||
int ret = 0;
|
||||
|
@ -60,8 +55,8 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c
|
|||
double divisor = 1;
|
||||
int i;
|
||||
long off = 0;
|
||||
grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_context* c = context_;
|
||||
grib_handle* h = grib_handle_of_accessor(this);
|
||||
char* ieee_packing_s = NULL;
|
||||
char* packingType_s = NULL;
|
||||
char* precision_s = NULL;
|
||||
|
@ -73,14 +68,14 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c
|
|||
int err = 0;
|
||||
|
||||
if (*len != 0) {
|
||||
if (self->units_factor &&
|
||||
(grib_get_double_internal(grib_handle_of_accessor(a), self->units_factor, &units_factor) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(grib_handle_of_accessor(a), self->units_factor, 1.0);
|
||||
if (units_factor_ &&
|
||||
(grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(grib_handle_of_accessor(this), units_factor_, 1.0);
|
||||
}
|
||||
|
||||
if (self->units_bias &&
|
||||
(grib_get_double_internal(grib_handle_of_accessor(a), self->units_bias, &units_bias) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(grib_handle_of_accessor(a), self->units_bias, 0.0);
|
||||
if (units_bias_ &&
|
||||
(grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias) == GRIB_SUCCESS)) {
|
||||
grib_set_double_internal(grib_handle_of_accessor(this), units_bias_, 0.0);
|
||||
}
|
||||
|
||||
if (units_factor != 1.0) {
|
||||
|
@ -101,15 +96,15 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c
|
|||
}
|
||||
}
|
||||
|
||||
if (c->ieee_packing && self->ieee_packing) {
|
||||
if (c->ieee_packing && ieee_packing_) {
|
||||
long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */
|
||||
size_t lenstr = strlen(self->ieee_packing);
|
||||
size_t lenstr = strlen(ieee_packing_);
|
||||
if ((ret = codes_check_grib_ieee_packing_value(c->ieee_packing)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
packingType_s = grib_context_strdup(c, self->packingType);
|
||||
ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
|
||||
precision_s = grib_context_strdup(c, self->precision);
|
||||
packingType_s = grib_context_strdup(c, packingType_);
|
||||
ieee_packing_s = grib_context_strdup(c, ieee_packing_);
|
||||
precision_s = grib_context_strdup(c, precision_);
|
||||
precision = c->ieee_packing == 32 ? 1 : 2;
|
||||
|
||||
if ((ret = grib_set_string(h, packingType_s, ieee_packing_s, &lenstr)) != GRIB_SUCCESS)
|
||||
|
@ -124,62 +119,62 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c
|
|||
}
|
||||
}
|
||||
|
||||
ret = grib_accessor_class_data_simple_packing_t::pack_double(a, val, len);
|
||||
ret = grib_accessor_data_simple_packing_t::pack_double(val, len);
|
||||
switch (ret) {
|
||||
case GRIB_CONSTANT_FIELD:
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), "constantFieldHalfByte", &constantFieldHalfByte);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), "constantFieldHalfByte", &constantFieldHalfByte);
|
||||
if (ret)
|
||||
constantFieldHalfByte = 0;
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, constantFieldHalfByte)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, constantFieldHalfByte)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
ret = grib_buffer_replace(a, NULL, 0, 1, 1);
|
||||
ret = grib_buffer_replace(this, NULL, 0, 1, 1);
|
||||
if (ret != GRIB_SUCCESS) return ret;
|
||||
return GRIB_SUCCESS;
|
||||
|
||||
case GRIB_NO_VALUES:
|
||||
ret = grib_get_long(grib_handle_of_accessor(a), "constantFieldHalfByte", &constantFieldHalfByte);
|
||||
ret = grib_get_long(grib_handle_of_accessor(this), "constantFieldHalfByte", &constantFieldHalfByte);
|
||||
if (ret)
|
||||
constantFieldHalfByte = 0;
|
||||
/* TODO move to def file */
|
||||
grib_get_double(grib_handle_of_accessor(a), "missingValue", &missingValue);
|
||||
if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->reference_value, missingValue)) !=
|
||||
grib_get_double(grib_handle_of_accessor(this), "missingValue", &missingValue);
|
||||
if ((err = grib_set_double_internal(grib_handle_of_accessor(this), reference_value_, missingValue)) !=
|
||||
GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, constantFieldHalfByte)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, constantFieldHalfByte)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
ret = grib_buffer_replace(a, NULL, 0, 1, 1);
|
||||
ret = grib_buffer_replace(this, NULL, 0, 1, 1);
|
||||
if (ret != GRIB_SUCCESS) return ret;
|
||||
return GRIB_SUCCESS;
|
||||
|
||||
case GRIB_INVALID_BPV:
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to compute packing parameters. Invalid bits per value");
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "Unable to compute packing parameters. Invalid bits per value");
|
||||
return ret;
|
||||
case GRIB_SUCCESS:
|
||||
break;
|
||||
default:
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "GRIB1 simple packing: unable to set values (%s)", grib_get_error_message(ret));
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "GRIB1 simple packing: unable to set values (%s)", grib_get_error_message(ret));
|
||||
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->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->bits_per_value, &bits_per_value)) !=
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) !=
|
||||
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_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetdata_, &offsetdata)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetsection_, &offsetsection)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
decimal = codes_power<double>(decimal_scale_factor, 10);
|
||||
|
@ -189,32 +184,32 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c
|
|||
if ((buflen + (offsetdata - offsetsection)) % 2) {
|
||||
buflen++;
|
||||
/*
|
||||
a->length++;
|
||||
grib_handle_of_accessor(a)->buffer->ulength++;
|
||||
length_ ++;
|
||||
grib_handle_of_accessor(this)->buffer->ulength++;
|
||||
*/
|
||||
}
|
||||
half_byte = (buflen * 8) - ((*len) * bits_per_value);
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"HALF byte: buflen=%d bits_per_value=%ld len=%d half_byte=%ld\n",
|
||||
buflen, bits_per_value, *len, half_byte);
|
||||
|
||||
Assert(half_byte <= 0x0f);
|
||||
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, half_byte)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen);
|
||||
buf = (unsigned char*)grib_context_buffer_malloc_clear(context_, buflen);
|
||||
encoded = buf;
|
||||
|
||||
grib_encode_double_array(n_vals, val, bits_per_value, reference_value, decimal, divisor, encoded, &off);
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG,
|
||||
"grib_accessor_data_g1simple_packing_t : pack_double : packing %s, %d values", a->name, n_vals);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"grib_accessor_data_g1simple_packing_t : pack_double : packing %s, %d values", name_, n_vals);
|
||||
|
||||
ret = grib_buffer_replace(a, buf, buflen, 1, 1);
|
||||
ret = grib_buffer_replace(this, buf, buflen, 1, 1);
|
||||
if (ret != GRIB_SUCCESS) return ret;
|
||||
|
||||
grib_context_buffer_free(a->context, buf);
|
||||
grib_context_buffer_free(context_, buf);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -15,19 +15,16 @@
|
|||
class grib_accessor_data_g1simple_packing_t : public grib_accessor_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g1simple_packing */
|
||||
const char* half_byte;
|
||||
const char* packingType;
|
||||
const char* ieee_packing;
|
||||
const char* precision;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g1simple_packing_t : public grib_accessor_class_data_simple_packing_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g1simple_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
|
||||
grib_accessor_data_g1simple_packing_t() :
|
||||
grib_accessor_data_simple_packing_t() { class_name_ = "data_g1simple_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1simple_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) override;
|
||||
|
||||
protected:
|
||||
const char* half_byte_;
|
||||
const char* packingType_;
|
||||
const char* ieee_packing_;
|
||||
const char* precision_;
|
||||
};
|
||||
|
|
|
@ -10,39 +10,37 @@
|
|||
|
||||
#include "grib_accessor_class_data_g22order_packing.h"
|
||||
|
||||
grib_accessor_class_data_g22order_packing_t _grib_accessor_class_data_g22order_packing{ "data_g22order_packing" };
|
||||
grib_accessor_class* grib_accessor_class_data_g22order_packing = &_grib_accessor_class_data_g22order_packing;
|
||||
grib_accessor_data_g22order_packing_t _grib_accessor_data_g22order_packing{};
|
||||
grib_accessor* grib_accessor_data_g22order_packing = &_grib_accessor_data_g22order_packing;
|
||||
|
||||
|
||||
void grib_accessor_class_data_g22order_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
void grib_accessor_data_g22order_packing_t::init(const long v, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_class_values_t::init(a, v, args);
|
||||
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
grib_accessor_values_t::init(v, args);
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
|
||||
self->numberOfValues = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->reference_value = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->optimize_scale_factor = grib_arguments_get_name(gh, args, self->carg++);
|
||||
numberOfValues_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
bits_per_value_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
reference_value_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
binary_scale_factor_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
decimal_scale_factor_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
optimize_scale_factor_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
|
||||
self->typeOfOriginalFieldValues = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->groupSplittingMethodUsed = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->missingValueManagementUsed = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->primaryMissingValueSubstitute = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->secondaryMissingValueSubstitute = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->numberOfGroupsOfDataValues = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->referenceForGroupWidths = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->numberOfBitsUsedForTheGroupWidths = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->referenceForGroupLengths = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->lengthIncrementForTheGroupLengths = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->trueLengthOfLastGroup = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->numberOfBitsUsedForTheScaledGroupLengths = grib_arguments_get_name(gh, args, self->carg++);
|
||||
typeOfOriginalFieldValues_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
groupSplittingMethodUsed_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
missingValueManagementUsed_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
primaryMissingValueSubstitute_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
secondaryMissingValueSubstitute_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
numberOfGroupsOfDataValues_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
referenceForGroupWidths_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
numberOfBitsUsedForTheGroupWidths_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
referenceForGroupLengths_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
lengthIncrementForTheGroupLengths_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
trueLengthOfLastGroup_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
numberOfBitsUsedForTheScaledGroupLengths_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
|
||||
self->orderOfSpatialDifferencing = grib_arguments_get_name(gh, args, self->carg++);
|
||||
self->numberOfOctetsExtraDescriptors = grib_arguments_get_name(gh, args, self->carg++);
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
orderOfSpatialDifferencing_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
numberOfOctetsExtraDescriptors_ = grib_arguments_get_name(gh, args, carg_++);
|
||||
flags_ |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
}
|
||||
|
||||
#define ONES (~(int)0)
|
||||
|
@ -87,7 +85,7 @@ void add_many_bitstream(bitstream_context* ctx, grib_accessor* a, int* t, int n,
|
|||
const int max_numbits = 25;
|
||||
|
||||
if (n_bits > max_numbits) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits);
|
||||
grib_context_log(a->context_, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits);
|
||||
}
|
||||
jmask = (1 << n_bits) - 1;
|
||||
|
||||
|
@ -114,7 +112,7 @@ void add_bitstream(bitstream_context* ctx, grib_accessor* a, int t, int n_bits)
|
|||
n_bits = 16;
|
||||
}
|
||||
if (n_bits > max_numbits) {
|
||||
grib_context_log(a->context, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits);
|
||||
grib_context_log(a->context_, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits);
|
||||
}
|
||||
jmask = (1 << n_bits) - 1;
|
||||
ctx->rbits += n_bits;
|
||||
|
@ -256,9 +254,9 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max)
|
|||
// }
|
||||
|
||||
// if (i == nn) { /* all defined values, no need for bms */
|
||||
// bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, 6));
|
||||
// bms = reinterpret_cast<unsigned char*>(grib_context_malloc(context_ , 6));
|
||||
// if (bms == NULL)
|
||||
// grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
// grib_context_log(context_ , GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
// uint_char(6, bms); // length of section 6
|
||||
// bms[4] = 6; // section 6
|
||||
// bms[5] = 255; // no bitmap
|
||||
|
@ -266,9 +264,9 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max)
|
|||
// }
|
||||
|
||||
// bms_size = 6 + (nn + 7) / 8;
|
||||
// bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, bms_size));
|
||||
// bms = reinterpret_cast<unsigned char*>(grib_context_malloc(context_ , bms_size));
|
||||
// if (bms == NULL)
|
||||
// grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
// grib_context_log(context_ , GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
|
||||
// uint_char(bms_size, bms); // length of section 6
|
||||
// bms[4] = 6; // section 6
|
||||
|
@ -774,11 +772,10 @@ static void merge_j(struct section* h, int ref_bits, int width_bits, int has_und
|
|||
}
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
int grib_accessor_data_g22order_packing_t::pack_double(const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_handle* gh = grib_handle_of_accessor(this);
|
||||
const char* cclass_name = class_name_;
|
||||
|
||||
int err = 0;
|
||||
|
||||
|
@ -810,33 +807,33 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
if (*len == 0)
|
||||
return GRIB_NO_VALUES;
|
||||
|
||||
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_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->optimize_scale_factor, &optimize_scale_factor)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, optimize_scale_factor_, &optimize_scale_factor)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
int use_scale = !optimize_scale_factor;
|
||||
|
||||
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->typeOfOriginalFieldValues, &typeOfOriginalFieldValues)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long_internal(gh, typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != 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->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->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_long_internal(gh, "bitmapPresent", &bitmap_present)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
@ -863,37 +860,37 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
size_t packing_type_len = strlen(packing_type);
|
||||
grib_set_string_internal(gh, "packingType", packing_type, &packing_type_len);
|
||||
|
||||
if ((err = grib_set_double_internal(gh, self->reference_value, grib_ieee_to_long(0.0))) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_internal(gh, reference_value_, grib_ieee_to_long(0.0))) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->binary_scale_factor, 0)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, binary_scale_factor_, 0)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->decimal_scale_factor, 0)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, decimal_scale_factor_, 0)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->bits_per_value, 8)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, bits_per_value_, 8)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->typeOfOriginalFieldValues, 0)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, typeOfOriginalFieldValues_, 0)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->groupSplittingMethodUsed, 1)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, groupSplittingMethodUsed_, 1)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->missingValueManagementUsed, 1)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, missingValueManagementUsed_, 1)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->primaryMissingValueSubstitute, grib_ieee_to_long(static_cast<float>(9.999e20)))) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, primaryMissingValueSubstitute_, grib_ieee_to_long(static_cast<float>(9.999e20)))) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->secondaryMissingValueSubstitute, 0xFFFFFFFF)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, secondaryMissingValueSubstitute_, 0xFFFFFFFF)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfGroupsOfDataValues, 1)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfGroupsOfDataValues_, 1)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->referenceForGroupWidths, grib_ieee_to_long(0.0))) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, referenceForGroupWidths_, grib_ieee_to_long(0.0))) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, 8)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, 8)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->referenceForGroupLengths, *len)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, referenceForGroupLengths_, *len)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->lengthIncrementForTheGroupLengths, 1)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, lengthIncrementForTheGroupLengths_, 1)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->trueLengthOfLastGroup, *len)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, trueLengthOfLastGroup_, *len)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, 8)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, 8)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
// Section 6
|
||||
|
@ -902,14 +899,14 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
// Section 7
|
||||
constexpr size_t sec7_size = 3;
|
||||
unsigned char empty_sec7[sec7_size] = { 255, 0, 0 }; // group reference, group width, group length
|
||||
grib_buffer_replace(a, empty_sec7, sec7_size, 1, 1);
|
||||
grib_buffer_replace(this, empty_sec7, sec7_size, 1, 1);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
size_t ndata = *len;
|
||||
double* data = reinterpret_cast<double*>(grib_context_malloc_clear(a->context, ndata * sizeof(double)));
|
||||
double* data = reinterpret_cast<double*>(grib_context_malloc_clear(context_, ndata * sizeof(double)));
|
||||
if (data == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, ndata * sizeof(double));
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, ndata * sizeof(double));
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(data, val, sizeof(*data) * ndata);
|
||||
|
@ -927,13 +924,13 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
nndata = use_bitmap ? ndef : ndata;
|
||||
has_undef = use_bitmap ? 0 : ndata != ndef;
|
||||
|
||||
v = reinterpret_cast<int*>(grib_context_malloc(a->context, nndata * sizeof(int)));
|
||||
v = reinterpret_cast<int*>(grib_context_malloc(context_, nndata * sizeof(int)));
|
||||
if (v == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, nndata * sizeof(int));
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, nndata * sizeof(int));
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
if (min_max_array(data, ndata, &mn, &mx) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: failed to get min max of data", cclass_name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: failed to get min max of data", cclass_name);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
min_val = mn;
|
||||
|
@ -1090,7 +1087,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: 2: vmx %d vmn %d nbits %d", vmx, vmn,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: 2: vmx %d vmn %d nbits %d", vmx, vmn,
|
||||
find_nbits(vmx - vmn + has_undef));
|
||||
#endif
|
||||
|
||||
|
@ -1110,9 +1107,9 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
}
|
||||
}
|
||||
|
||||
list = reinterpret_cast<section*>(grib_context_malloc_clear(a->context, nstruct * sizeof(section)));
|
||||
list = reinterpret_cast<section*>(grib_context_malloc_clear(context_, nstruct * sizeof(section)));
|
||||
if (list == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory allocation of list failed", cclass_name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: memory allocation of list failed", cclass_name);
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1139,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
start.tail = &list[0];
|
||||
|
||||
if (nstruct != ii + 1) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: nstruct=%zu wanted %zu", cclass_name, nstruct, ii + 1);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: nstruct=%zu wanted %zu", cclass_name, nstruct, ii + 1);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
for (i = 1; i < nstruct; i++) {
|
||||
|
@ -1160,7 +1157,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
LEN_SEC_MAX);
|
||||
#ifdef DEBUG
|
||||
j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef);
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", k, j);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", k, j);
|
||||
#endif
|
||||
k = 2 * k + 1 + has_undef;
|
||||
}
|
||||
|
@ -1168,16 +1165,16 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
// try making segment sizes larger
|
||||
// 12/2015 need to segment size less 25 bits, bitstream software limitation
|
||||
|
||||
list_backup = reinterpret_cast<section*>(grib_context_malloc(a->context, nstruct * sizeof(section)));
|
||||
list_backup = reinterpret_cast<section*>(grib_context_malloc(context_, nstruct * sizeof(section)));
|
||||
if (list_backup == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory allocation of list_backup failed", cclass_name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: memory allocation of list_backup failed", cclass_name);
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef);
|
||||
j0 = j + 1;
|
||||
#ifdef DEBUG
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: complex start inc segments size0 %d segsize %d", j, LEN_SEC_MAX);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex start inc segments size0 %d segsize %d", j, LEN_SEC_MAX);
|
||||
#endif
|
||||
while (j < j0 && LEN_BITS < 25) {
|
||||
j0 = j;
|
||||
|
@ -1188,7 +1185,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
LEN_SEC_MAX);
|
||||
j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef);
|
||||
#ifdef DEBUG
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG,
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG,
|
||||
"COMPLEX: complex inc segments size size0 %d size1 %d segsize %d "
|
||||
"LEN_BITS=%d",
|
||||
j0, j, LEN_SEC_MAX, LEN_BITS);
|
||||
|
@ -1199,19 +1196,19 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
LEN_SEC_MAX = (LEN_SEC_MAX - 1) / 2;
|
||||
}
|
||||
}
|
||||
grib_context_free(a->context, list_backup);
|
||||
grib_context_free(context_, list_backup);
|
||||
|
||||
exchange(start.tail, v, has_undef, LEN_SEC_MAX);
|
||||
#ifdef DEBUG
|
||||
j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef);
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: exchange %d bytes", j);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: exchange %d bytes", j);
|
||||
#endif
|
||||
|
||||
merge_j(start.tail, vbits, LEN_BITS + est_group_width, has_undef, vmx,
|
||||
LEN_SEC_MAX);
|
||||
#ifdef DEBUG
|
||||
j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef);
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", vmx, j);
|
||||
grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", vmx, j);
|
||||
#endif
|
||||
|
||||
// finished making segments
|
||||
|
@ -1243,14 +1240,14 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
s = s->tail;
|
||||
}
|
||||
|
||||
lens = reinterpret_cast<int*>(grib_context_malloc(a->context, ngroups * sizeof(int)));
|
||||
widths = reinterpret_cast<int*>(grib_context_malloc(a->context, ngroups * sizeof(int)));
|
||||
refs = reinterpret_cast<int*>(grib_context_malloc(a->context, ngroups * sizeof(int)));
|
||||
itmp = reinterpret_cast<int*>(grib_context_malloc(a->context, ngroups * sizeof(int)));
|
||||
itmp2 = reinterpret_cast<int*>(grib_context_malloc(a->context, ngroups * sizeof(int)));
|
||||
lens = reinterpret_cast<int*>(grib_context_malloc(context_, ngroups * sizeof(int)));
|
||||
widths = reinterpret_cast<int*>(grib_context_malloc(context_, ngroups * sizeof(int)));
|
||||
refs = reinterpret_cast<int*>(grib_context_malloc(context_, ngroups * sizeof(int)));
|
||||
itmp = reinterpret_cast<int*>(grib_context_malloc(context_, ngroups * sizeof(int)));
|
||||
itmp2 = reinterpret_cast<int*>(grib_context_malloc(context_, ngroups * sizeof(int)));
|
||||
|
||||
if (lens == NULL || widths == NULL || refs == NULL || itmp == NULL || itmp2 == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory alloc of lens/widths/refs/itmp/itmp2 failed", cclass_name);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: memory alloc of lens/widths/refs/itmp/itmp2 failed", cclass_name);
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -1310,38 +1307,38 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
bits_per_value = find_nbits(grefmx + has_undef);
|
||||
numberOfBitsUsedForTheGroupWidths = find_nbits(gwidmx - gwidmn + has_undef);
|
||||
|
||||
if ((err = grib_set_long_internal(gh, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, bits_per_value_, bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_double_internal(gh, self->reference_value, static_cast<double>(ref))) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_double_internal(gh, reference_value_, static_cast<double>(ref))) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->binary_scale_factor, binary_scale)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, binary_scale_factor_, binary_scale)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->decimal_scale_factor, -dec_scale)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, decimal_scale_factor_, -dec_scale)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->typeOfOriginalFieldValues, 0)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, typeOfOriginalFieldValues_, 0)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->groupSplittingMethodUsed, 1)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, groupSplittingMethodUsed_, 1)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->missingValueManagementUsed, has_undef)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, missingValueManagementUsed_, has_undef)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->primaryMissingValueSubstitute, grib_ieee_to_long(static_cast<float>(9.999e20)))) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, primaryMissingValueSubstitute_, grib_ieee_to_long(static_cast<float>(9.999e20)))) != GRIB_SUCCESS)
|
||||
return err;
|
||||
// if ((err = grib_set_long_internal(gh, self->secondaryMissingValueSubstitute, 0xFFFFFFFF)) != GRIB_SUCCESS) return err;
|
||||
// if ((err = grib_set_long_internal(gh, secondaryMissingValueSubstitute_ , 0xFFFFFFFF)) != GRIB_SUCCESS) return err;
|
||||
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfGroupsOfDataValues, ngroups)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfGroupsOfDataValues_, ngroups)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->referenceForGroupWidths, gwidmn)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, referenceForGroupWidths_, gwidmn)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, find_nbits(gwidmx - gwidmn + has_undef))) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, find_nbits(gwidmx - gwidmn + has_undef))) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->referenceForGroupLengths, glenmn)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, referenceForGroupLengths_, glenmn)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->lengthIncrementForTheGroupLengths, 1)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, lengthIncrementForTheGroupLengths_, 1)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->trueLengthOfLastGroup, len_last)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, trueLengthOfLastGroup_, len_last)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
numberOfBitsUsedForTheScaledGroupLengths = find_nbits(glenmx - glenmn);
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
size_sec7 = 5;
|
||||
|
@ -1353,9 +1350,9 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
size_sec7 += 3 * numberOfOctetsExtraDescriptors;
|
||||
}
|
||||
if (orderOfSpatialDifferencing > 0) {
|
||||
if ((err = grib_set_long_internal(gh, self->orderOfSpatialDifferencing, orderOfSpatialDifferencing)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, orderOfSpatialDifferencing_, orderOfSpatialDifferencing)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfOctetsExtraDescriptors, numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfOctetsExtraDescriptors_, numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -1383,9 +1380,9 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
}
|
||||
size_sec7 += (k >> 3) + ((k & 7) ? 1 : 0);
|
||||
|
||||
unsigned char* sec7 = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, size_sec7));
|
||||
unsigned char* sec7 = reinterpret_cast<unsigned char*>(grib_context_malloc(context_, size_sec7));
|
||||
if (sec7 == NULL) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Unable to allocate %d bytes", cclass_name, size_sec7);
|
||||
grib_context_log(context_, GRIB_LOG_ERROR, "%s: Unable to allocate %d bytes", cclass_name, size_sec7);
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -1393,32 +1390,32 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
|
||||
bitstream_context ctx;
|
||||
init_bitstream(&ctx, sec7);
|
||||
add_bitstream(&ctx, a, size_sec7 >> 16, 16);
|
||||
add_bitstream(&ctx, a, size_sec7, 16);
|
||||
add_bitstream(&ctx, a, 7, 8);
|
||||
add_bitstream(&ctx, this, size_sec7 >> 16, 16);
|
||||
add_bitstream(&ctx, this, size_sec7, 16);
|
||||
add_bitstream(&ctx, this, 7, 8);
|
||||
|
||||
// write extra octets
|
||||
if (orderOfSpatialDifferencing == 1 || orderOfSpatialDifferencing == 2) {
|
||||
add_bitstream(&ctx, a, extra_0, 8 * numberOfOctetsExtraDescriptors);
|
||||
if (orderOfSpatialDifferencing == 2) add_bitstream(&ctx, a, extra_1, 8 * numberOfOctetsExtraDescriptors);
|
||||
add_bitstream(&ctx, this, extra_0, 8 * numberOfOctetsExtraDescriptors);
|
||||
if (orderOfSpatialDifferencing == 2) add_bitstream(&ctx, this, extra_1, 8 * numberOfOctetsExtraDescriptors);
|
||||
k = vmn;
|
||||
if (k < 0) {
|
||||
k = -vmn | (1 << (8 * numberOfOctetsExtraDescriptors - 1));
|
||||
}
|
||||
add_bitstream(&ctx, a, k, 8 * numberOfOctetsExtraDescriptors);
|
||||
add_bitstream(&ctx, this, k, 8 * numberOfOctetsExtraDescriptors);
|
||||
finish_bitstream(&ctx);
|
||||
}
|
||||
|
||||
// write the group reference values
|
||||
add_many_bitstream(&ctx, a, refs, ngroups, bits_per_value);
|
||||
add_many_bitstream(&ctx, this, refs, ngroups, bits_per_value);
|
||||
finish_bitstream(&ctx);
|
||||
|
||||
// write the group widths
|
||||
add_many_bitstream(&ctx, a, itmp, ngroups, numberOfBitsUsedForTheGroupWidths);
|
||||
add_many_bitstream(&ctx, this, itmp, ngroups, numberOfBitsUsedForTheGroupWidths);
|
||||
finish_bitstream(&ctx);
|
||||
|
||||
// write the group lengths
|
||||
add_many_bitstream(&ctx, a, itmp2, ngroups, numberOfBitsUsedForTheScaledGroupLengths);
|
||||
add_many_bitstream(&ctx, this, itmp2, ngroups, numberOfBitsUsedForTheScaledGroupLengths);
|
||||
finish_bitstream(&ctx);
|
||||
|
||||
s = start.tail;
|
||||
|
@ -1438,38 +1435,37 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
|
|||
}
|
||||
for (i = 0; i < ngroups; i++) {
|
||||
if (widths[i]) {
|
||||
add_many_bitstream(&ctx, a, v + itmp[i], lens[i], widths[i]);
|
||||
add_many_bitstream(&ctx, this, v + itmp[i], lens[i], widths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
finish_bitstream(&ctx);
|
||||
|
||||
grib_buffer_replace(a, sec7 + 5, size_sec7 - 5, 1, 1);
|
||||
grib_buffer_replace(this, sec7 + 5, size_sec7 - 5, 1, 1);
|
||||
|
||||
grib_context_free(a->context, sec7);
|
||||
grib_context_free(a->context, list);
|
||||
grib_context_free(a->context, v);
|
||||
grib_context_free(a->context, lens);
|
||||
grib_context_free(a->context, widths);
|
||||
grib_context_free(a->context, refs);
|
||||
grib_context_free(a->context, itmp);
|
||||
grib_context_free(a->context, itmp2);
|
||||
grib_context_free(a->context, data);
|
||||
grib_context_free(context_, sec7);
|
||||
grib_context_free(context_, list);
|
||||
grib_context_free(context_, v);
|
||||
grib_context_free(context_, lens);
|
||||
grib_context_free(context_, widths);
|
||||
grib_context_free(context_, refs);
|
||||
grib_context_free(context_, itmp);
|
||||
grib_context_free(context_, itmp2);
|
||||
grib_context_free(context_, data);
|
||||
|
||||
// ECC-259: Set correct number of values
|
||||
if ((err = grib_set_long_internal(gh, self->numberOfValues, *len)) != GRIB_SUCCESS)
|
||||
if ((err = grib_set_long_internal(gh, numberOfValues_, *len)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
|
||||
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
|
||||
const char* cclass_name = a->cclass->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;
|
||||
|
@ -1514,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;
|
||||
|
||||
self->dirty = 0;
|
||||
dirty_ = 0;
|
||||
|
||||
if (bits_per_value == 0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
|
@ -1574,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);
|
||||
|
||||
|
@ -1691,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;
|
||||
}
|
||||
|
@ -1702,8 +1698,8 @@ 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);
|
||||
// de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias);
|
||||
post_process(context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras);
|
||||
// de_spatial_difference (context_ , sec_val, n_vals, orderOfSpatialDifferencing, bias);
|
||||
}
|
||||
|
||||
binary_s = (T)codes_power<T>(binary_scale_factor, 2);
|
||||
|
@ -1718,49 +1714,49 @@ 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_class_data_g22order_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
int grib_accessor_data_g22order_packing_t::unpack_double(double* val, size_t* len)
|
||||
{
|
||||
return unpack<double>(a, val, len);
|
||||
return unpack<double>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g22order_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len)
|
||||
int grib_accessor_data_g22order_packing_t::unpack_float(float* val, size_t* len)
|
||||
{
|
||||
return unpack<float>(a, val, len);
|
||||
return unpack<float>(val, len);
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g22order_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
||||
int grib_accessor_data_g22order_packing_t::unpack_double_element(size_t idx, double* val)
|
||||
{
|
||||
size_t size = 0;
|
||||
double* values = NULL;
|
||||
int err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
|
||||
int err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
if (idx > size)
|
||||
return GRIB_INVALID_ARGUMENT;
|
||||
|
||||
values = reinterpret_cast<double*>(grib_context_malloc_clear(a->context, size * sizeof(double)));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size);
|
||||
values = reinterpret_cast<double*>(grib_context_malloc_clear(context_, size * sizeof(double)));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
*val = values[idx];
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g22order_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
int grib_accessor_data_g22order_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
size_t size = 0, i = 0;
|
||||
double* values;
|
||||
int err = 0;
|
||||
|
||||
// GRIB-564: The indexes in index_array relate to codedValues NOT values!
|
||||
err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
|
||||
err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -1768,22 +1764,21 @@ int grib_accessor_class_data_g22order_packing_t::unpack_double_element_set(grib_
|
|||
if (index_array[i] > size) return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
values = reinterpret_cast<double*>(grib_context_malloc_clear(a->context, size * sizeof(double)));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size);
|
||||
values = reinterpret_cast<double*>(grib_context_malloc_clear(context_, size * sizeof(double)));
|
||||
err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size);
|
||||
if (err) {
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return err;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
val_array[i] = values[index_array[i]];
|
||||
}
|
||||
grib_context_free(a->context, values);
|
||||
grib_context_free(context_, values);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_accessor_class_data_g22order_packing_t::value_count(grib_accessor* a, long* count)
|
||||
int grib_accessor_data_g22order_packing_t::value_count(long* count)
|
||||
{
|
||||
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
|
||||
*count = 0;
|
||||
return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, count);
|
||||
return grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, count);
|
||||
}
|
||||
|
|
|
@ -16,39 +16,38 @@
|
|||
class grib_accessor_data_g22order_packing_t : public grib_accessor_values_t
|
||||
{
|
||||
public:
|
||||
/* Members defined in data_g22order_packing */
|
||||
const char* numberOfValues;
|
||||
const char* bits_per_value;
|
||||
const char* reference_value;
|
||||
const char* binary_scale_factor;
|
||||
const char* decimal_scale_factor;
|
||||
const char* optimize_scale_factor;
|
||||
const char* typeOfOriginalFieldValues;
|
||||
const char* groupSplittingMethodUsed;
|
||||
const char* missingValueManagementUsed;
|
||||
const char* primaryMissingValueSubstitute;
|
||||
const char* secondaryMissingValueSubstitute;
|
||||
const char* numberOfGroupsOfDataValues;
|
||||
const char* referenceForGroupWidths;
|
||||
const char* numberOfBitsUsedForTheGroupWidths;
|
||||
const char* referenceForGroupLengths;
|
||||
const char* lengthIncrementForTheGroupLengths;
|
||||
const char* trueLengthOfLastGroup;
|
||||
const char* numberOfBitsUsedForTheScaledGroupLengths;
|
||||
const char* orderOfSpatialDifferencing;
|
||||
const char* numberOfOctetsExtraDescriptors;
|
||||
};
|
||||
|
||||
class grib_accessor_class_data_g22order_packing_t : public grib_accessor_class_values_t
|
||||
{
|
||||
public:
|
||||
grib_accessor_class_data_g22order_packing_t(const char* name) : grib_accessor_class_values_t(name) {}
|
||||
grib_accessor_data_g22order_packing_t() :
|
||||
grib_accessor_values_t() { class_name_ = "data_g22order_packing"; }
|
||||
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g22order_packing_t{}; }
|
||||
int pack_double(grib_accessor*, const double* val, size_t* len) override;
|
||||
int unpack_double(grib_accessor*, double* val, size_t* len) override;
|
||||
int unpack_float(grib_accessor*, float* val, size_t* len) override;
|
||||
int value_count(grib_accessor*, long*) override;
|
||||
void init(grib_accessor*, const long, grib_arguments*) override;
|
||||
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
|
||||
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
|
||||
int pack_double(const double* val, size_t* len) override;
|
||||
int unpack_double(double* val, size_t* len) override;
|
||||
int unpack_float(float* val, size_t* len) override;
|
||||
int value_count(long*) override;
|
||||
void init(const long, grib_arguments*) 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;
|
||||
|
||||
private:
|
||||
const char* numberOfValues_;
|
||||
const char* bits_per_value_;
|
||||
const char* reference_value_;
|
||||
const char* binary_scale_factor_;
|
||||
const char* decimal_scale_factor_;
|
||||
const char* optimize_scale_factor_;
|
||||
const char* typeOfOriginalFieldValues_;
|
||||
const char* groupSplittingMethodUsed_;
|
||||
const char* missingValueManagementUsed_;
|
||||
const char* primaryMissingValueSubstitute_;
|
||||
const char* secondaryMissingValueSubstitute_;
|
||||
const char* numberOfGroupsOfDataValues_;
|
||||
const char* referenceForGroupWidths_;
|
||||
const char* numberOfBitsUsedForTheGroupWidths_;
|
||||
const char* referenceForGroupLengths_;
|
||||
const char* lengthIncrementForTheGroupLengths_;
|
||||
const char* trueLengthOfLastGroup_;
|
||||
const char* numberOfBitsUsedForTheScaledGroupLengths_;
|
||||
const char* orderOfSpatialDifferencing_;
|
||||
const char* numberOfOctetsExtraDescriptors_;
|
||||
|
||||
template <typename T> int unpack(T* val, size_t* len);
|
||||
};
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue