Modernisation: Merge accessor classes

This commit is contained in:
Eugen Betke 2024-08-12 01:54:29 +02:00
parent db8d72582e
commit 26f586f7c1
506 changed files with 13844 additions and 15125 deletions

View File

@ -41,7 +41,7 @@ codetable[2] instrument "grib2/tables/local/ecmf/obstat.5.0.table";
codetable[2] dataStream "grib2/tables/local/ecmf/obstat.6.0.table";
# include "grib2/template.4.horizontal.def"
# include "grib2/templates/template.4.horizontal.def"
codetable[2] observationDiagnostic "grib2/tables/local/ecmf/obstat.9.0.table";

View File

@ -3,4 +3,4 @@
#
# This is deprecated and only included for backward compatibility, use template 4.33
#
include "grib2/template.4.33.def"
include "grib2/templates/template.4.33.def"

View File

@ -3,4 +3,4 @@
#
# This is deprecated and only included for backward compatibility, use template 4.34
#
include "grib2/template.4.34.def"
include "grib2/templates/template.4.34.def"

View File

@ -2,9 +2,9 @@
# TEMPLATE 4.65533, Individual member for large ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time
include "grib2/template.4.parameter.def"
include "grib2/template.4.generating_process.def"
include "grib2/template.4.forecast_time.def"
include "grib2/template.4.point_in_time.def"
include "grib2/template.4.horizontal.def"
include "grib2/template.4.leps.def"
include "grib2/templates/template.4.parameter.def"
include "grib2/templates/template.4.generating_process.def"
include "grib2/templates/template.4.forecast_time.def"
include "grib2/templates/template.4.point_in_time.def"
include "grib2/templates/template.4.horizontal.def"
include "grib2/templates/template.4.leps.def"

View File

@ -2,9 +2,9 @@
# TEMPLATE 4.65534, Individual member for large ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval
include "grib2/template.4.parameter.def"
include "grib2/template.4.generating_process.def"
include "grib2/template.4.forecast_time.def"
include "grib2/template.4.horizontal.def"
include "grib2/template.4.leps.def"
include "grib2/template.4.statistical.def"
include "grib2/templates/template.4.parameter.def"
include "grib2/templates/template.4.generating_process.def"
include "grib2/templates/template.4.forecast_time.def"
include "grib2/templates/template.4.horizontal.def"
include "grib2/templates/template.4.leps.def"
include "grib2/templates/template.4.statistical.def"

View File

@ -3,8 +3,8 @@
# TEMPLATE 3.32769 - Rotate Latitude/Longitude (Arakawa Non-E Staggered grid)
# See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp3-32769.shtml
include "grib2/template.3.shape_of_the_earth.def";
include "grib2/template.3.grid.def";
include "grib2/templates/template.3.shape_of_the_earth.def";
include "grib2/templates/template.3.grid.def";
meta latitudeOfFirstGridPointInDegrees scale(La1,one,grib2divider,truncateDegrees) : dump;
meta longitudeOfFirstGridPointInDegrees scale(Lo1,one,grib2divider,truncateDegrees) : dump;

View File

@ -115,12 +115,6 @@
parameterCategory = 128 ;
parameterNumber = 25 ;
}
#Lake cover
'Lake cover' = {
discipline = 192 ;
parameterCategory = 128 ;
parameterNumber = 26 ;
}
#Snow albedo
'Snow albedo' = {
localTablesVersion = 1 ;

View File

@ -115,12 +115,6 @@
parameterCategory = 128 ;
parameterNumber = 25 ;
}
#Lake cover
'26' = {
discipline = 192 ;
parameterCategory = 128 ;
parameterNumber = 26 ;
}
#Snow albedo
'32' = {
localTablesVersion = 1 ;

View File

@ -115,12 +115,6 @@
parameterCategory = 128 ;
parameterNumber = 25 ;
}
#Lake cover
'cl' = {
discipline = 192 ;
parameterCategory = 128 ;
parameterNumber = 26 ;
}
#Snow albedo
'asn' = {
localTablesVersion = 1 ;

View File

@ -115,12 +115,6 @@
parameterCategory = 128 ;
parameterNumber = 25 ;
}
#Lake cover
'(0 - 1)' = {
discipline = 192 ;
parameterCategory = 128 ;
parameterNumber = 26 ;
}
#Snow albedo
'(0 - 1)' = {
localTablesVersion = 1 ;

View File

@ -181,6 +181,12 @@
parameterCategory = 2 ;
parameterNumber = 45 ;
}
#Lake cover
'Lake cover' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Low vegetation cover
'Low vegetation cover' = {
discipline = 2 ;
@ -5416,12 +5422,6 @@
parameterCategory = 0 ;
parameterNumber = 12 ;
}
#Water fraction
'Water fraction' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Days since last observation
'Days since last observation' = {
discipline = 0 ;

View File

@ -181,6 +181,12 @@
parameterCategory = 2 ;
parameterNumber = 45 ;
}
#Lake cover
'26' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Low vegetation cover
'27' = {
discipline = 2 ;
@ -5416,12 +5422,6 @@
parameterCategory = 0 ;
parameterNumber = 12 ;
}
#Water fraction
'240016' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Days since last observation
'240017' = {
discipline = 0 ;

View File

@ -115,7 +115,7 @@ alias calendarIdPresent = false;
if ( ((section1Length > 21) or setCalendarId > 0) and deleteCalendarId == 0) {
alias calendarIdPresent = present;
codetable[2] calendarIdentificationTemplateNumber ('1.5.table',masterDir,localDir) : dump,string_type,no_fail;
template calendarIdentification "grib2/template.1.[calendarIdentificationTemplateNumber:l].def";
template calendarIdentification "grib2/templates/template.1.[calendarIdentificationTemplateNumber:l].def";
}
constant conceptsMasterDir="grib2" : hidden;

View File

@ -38,7 +38,7 @@ alias isRotatedGrid = false;
if (gridDefinitionTemplateNumber >= 32768) {
template gridDefinitionSection "grib2/local/[centreForLocal]/template.3.[gridDefinitionTemplateNumber:l].def";
} else {
template gridDefinitionSection "grib2/template.3.[gridDefinitionTemplateNumber:l].def";
template gridDefinitionSection "grib2/templates/template.3.[gridDefinitionTemplateNumber:l].def";
}
if(PLPresent){

View File

@ -68,13 +68,15 @@ transient genVertHeightCoords = 0;
if (productDefinitionTemplateNumber >= 32768) {
template productDefinition "grib2/local/[centreForLocal]/template.4.[productDefinitionTemplateNumber:l].def";
} else {
template productDefinition "grib2/template.4.[productDefinitionTemplateNumber:l].def";
template productDefinition "grib2/templates/template.4.[productDefinitionTemplateNumber:l].def";
}
if (defined(marsStream) && defined(marsType)) {
template_nofail marsKeywords1 "mars/grib.[marsStream:s].[marsType:s].def";
}
concept productDefinitionTemplateName(unknown, "productDefinitionTemplateConcept.def", conceptsDir2,conceptsDir1): no_copy;
template parameters "grib2/parameters.def";
# Hook for local extras

View File

@ -51,7 +51,7 @@ concept packingType (unknown) {
"grid_run_length" = { dataRepresentationTemplateNumber = 200; }
} : dump;
template dataRepresentation "grib2/template.5.[dataRepresentationTemplateNumber:l].def";
template dataRepresentation "grib2/templates/template.5.[dataRepresentationTemplateNumber:l].def";
alias ls.packingType=packingType;
alias dataRepresentation=packingType;

View File

@ -13,7 +13,7 @@ unsigned[1] numberOfSection = 7:read_only;
# Template number given in octets 10-11 of Section 5
position offsetBeforeData;
#if (changed(dataRepresentationTemplateNumber)) {
template dataValues "grib2/template.7.[dataRepresentationTemplateNumber:l].def";
template dataValues "grib2/templates/template.7.[dataRepresentationTemplateNumber:l].def";
#}
meta changeDecimalPrecision decimal_precision(bitsPerValue,decimalScaleFactor,changingPrecision,values) : edition_specific;

View File

@ -181,6 +181,12 @@
parameterCategory = 2 ;
parameterNumber = 45 ;
}
#Lake cover
'cl' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Low vegetation cover
'cvl' = {
discipline = 2 ;
@ -5416,12 +5422,6 @@
parameterCategory = 0 ;
parameterNumber = 12 ;
}
#Water fraction
'fldfrc' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Days since last observation
'dslr' = {
discipline = 0 ;

View File

@ -181,6 +181,12 @@
parameterCategory = 2 ;
parameterNumber = 45 ;
}
#Lake cover
'(0 - 1)' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Low vegetation cover
'(0 - 1)' = {
discipline = 2 ;
@ -5416,12 +5422,6 @@
parameterCategory = 0 ;
parameterNumber = 12 ;
}
#Water fraction
'(0 - 1)' = {
discipline = 1 ;
parameterCategory = 2 ;
parameterNumber = 2 ;
}
#Days since last observation
'Integer' = {
discipline = 0 ;

View File

@ -2765,6 +2765,12 @@
call grib_skip_read_only(iterid, status)
end subroutine codes_skip_read_only
!> Set debug mode
subroutine codes_set_debug(mode)
integer(kind=kindOfInt), intent(in) :: mode
call grib_set_debug(mode)
end subroutine codes_set_debug
!> Set the definition path
!>
!> In case of error, if the status parameter (optional) is not given, the program will

View File

@ -79,7 +79,7 @@ integer, external :: grib_f_set_int, grib_f_set_int_array, &
integer, external :: grib_f_get_message_size, grib_f_copy_message, grib_f_count_in_file
integer, external :: grib_f_write, grib_f_multi_write, grib_f_multi_append
integer, external :: grib_f_clone, grib_f_copy_namespace
external :: grib_f_check
external :: grib_f_check , grib_f_set_debug
integer, external :: grib_f_util_sections_copy
integer, external :: grib_f_set_definitions_path, grib_f_set_samples_path
integer, external :: grib_f_julian_to_datetime, grib_f_datetime_to_julian, grib_f_copy_key

View File

@ -3177,6 +3177,13 @@
end if
end subroutine grib_skip_read_only
!> Set debug mode
subroutine grib_set_debug(mode)
integer(kind=kindOfInt), intent(in) :: mode
call grib_f_set_debug(mode)
end subroutine grib_set_debug
!> Set the definition path
!>
!> In case of error, if the status parameter (optional) is not given, the program will

View File

@ -975,8 +975,9 @@ int grib_f_close_file_(int* fid)
/*****************************************************************************/
static int file_count=0;
void grib_f_write_on_fail(int* gid) {
grib_context* c=grib_context_get_default();
void grib_f_write_on_fail(int* gid)
{
grib_context* c = grib_context_get_default();
if (c->write_on_fail) {
char filename[100]={0,};
grib_handle* h=NULL;
@ -993,7 +994,8 @@ void grib_f_write_on_fail(int* gid) {
if (h) grib_write_message(h,filename,"w");
}
}
void grib_f_write_on_fail_(int* gid) {
void grib_f_write_on_fail_(int* gid)
{
grib_f_write_on_fail(gid);
}
/*****************************************************************************/
@ -2890,6 +2892,13 @@ int codes_f_bufr_multi_element_constant_arrays_off_(void)
return GRIB_SUCCESS;
}
/*****************************************************************************/
void grib_f_set_debug_(int mode)
{
grib_context* c = grib_context_get_default();
grib_context_set_debug(c, mode);
}
/*****************************************************************************/
int grib_f_set_definitions_path_(char* path, int len)
{

View File

@ -309,6 +309,7 @@ int grib_f_multi_append__(int *ingid, int *sec, int *mgid);
int codes_f_bufr_keys_iterator_new_(int* gid,int* iterid);
int grib_f_read_file_(int* fid, void* buffer, size_t* nbytes);
int codes_f_bufr_keys_iterator_delete_(int* iterid);
void grib_f_set_debug_(int mode);
int grib_f_set_definitions_path_(char* path, int len);
int grib_f_read_any_from_file_(int* fid, void* buffer, size_t* nbytes);
int any_f_new_from_file_(int* fid, int* gid);

View File

@ -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

View File

@ -16,132 +16,99 @@
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) {}
grib_accessor() :
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;
// private:
// TODO(maee): make members 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_;
};

View File

@ -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;

View File

@ -16,15 +16,12 @@
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;
};
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_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{}; }
public:
long* v_;
long pack_index_;
int number_of_elements_;
};

View File

@ -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;

View File

@ -16,14 +16,11 @@
class grib_accessor_abstract_vector_t : public grib_accessor_double_t
{
public:
/* Members defined in abstract_vector */
double* v;
int number_of_elements;
};
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_abstract_vector_t() :
grib_accessor_double_t() { class_name_ = "abstract_vector"; }
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; }
public:
double* v_;
int number_of_elements_;
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;

View File

@ -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_;
};

View File

@ -11,18 +11,18 @@
#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)
{
long slen = 0;
long off = 0;
grib_handle* hand = grib_handle_of_accessor(a);
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);
long slen = 0;
long off = 0;
grib_handle* hand = grib_handle_of_accessor(a);
grib_get_long_internal(hand, self->offsetbsec_, &off);
grib_get_long_internal(hand, self->sLength_, &slen);
if (slen == 0) {
grib_accessor* seclen;
@ -30,68 +30,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, self->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);
a->length_ = off + (slen - a->offset_);
if (a->length < 0) {
if (a->length_ < 0) {
/* Assume reparsing */
/*Assert(hand->loader != 0);*/
a->length = 0;
a->length_ = 0;
}
Assert(a->length >= 0);
Assert(a->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(this);
}
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 +106,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 +115,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 +127,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;
}

View File

@ -16,27 +16,24 @@
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;
};
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_bitmap_t() :
grib_accessor_bytes_t() { class_name_ = "bitmap"; }
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;
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;
// TODO(maee): make members private
public:
const char* tableReference_;
const char* missing_value_;
const char* offsetbsec_;
const char* sLength_;
};

View File

@ -11,55 +11,52 @@
#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;
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 +68,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 +164,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 +172,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;
}

View File

@ -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_;
};

View File

@ -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;
}

View File

@ -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_;
};

View File

@ -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);
}

View File

@ -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;
};

View File

@ -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;

View File

@ -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

View File

@ -15,75 +15,72 @@
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;
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_;
};
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);
grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor*);
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor*);
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor*);
void accessor_bufr_data_array_set_unpackMode(grib_accessor*, int unpackMode);

View File

@ -10,10 +10,10 @@
#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;
@ -28,34 +28,34 @@ 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 = (grib_accessor_bufr_data_element_t*)the_clone;
self = (grib_accessor_bufr_data_element_t*)this;
the_clone->flags_ = flags_;
the_clone->parent_ = NULL;
the_clone->h_ = s->h;
elementAccessor->index_ = self->index_;
elementAccessor->type_ = self->type_;
elementAccessor->numberOfSubsets_ = self->numberOfSubsets_;
elementAccessor->subsetNumber_ = self->subsetNumber_;
elementAccessor->compressedData_ = self->compressedData_;
elementAccessor->descriptors_ = self->descriptors_;
elementAccessor->numericValues_ = self->numericValues_;
elementAccessor->stringValues_ = self->stringValues_;
elementAccessor->elementsDescriptorsIndex_ = self->elementsDescriptorsIndex_;
elementAccessor->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++;
}
@ -66,149 +66,153 @@ grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor
void accessor_bufr_data_element_set_index(grib_accessor* a, long index)
{
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->index = index;
self->index_ = index;
}
void accessor_bufr_data_element_set_type(grib_accessor* a, int type)
{
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->type = type;
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;
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;
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;
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;
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;
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;
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;
self->elementsDescriptorsIndex_ = elementsDescriptorsIndex;
}
void grib_accessor_class_bufr_data_element_t::init(grib_accessor* a, const long len, grib_arguments* params)
void grib_accessor_bufr_data_element_t::init(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;
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 grib_accessor_class_bufr_data_element_t::dump(grib_accessor* a, grib_dumper* dumper)
void grib_accessor_bufr_data_element_t::dump(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 +220,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 +244,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 +290,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 +471,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 +495,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 +545,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 +573,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 +595,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 +610,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;

View File

@ -16,39 +16,36 @@
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;
public:
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_;
};

View File

@ -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,36 +39,44 @@ 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_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;
@ -76,33 +84,37 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
grib_trie* dictionary = NULL;
FILE* f = NULL;
grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = a->context;
grib_context* c = a->context_;
*err = GRIB_SUCCESS;
len = 1024;
if (self->masterDir != NULL)
grib_get_string(h, self->masterDir, masterDir, &len);
if (self->masterDir_ != NULL)
grib_get_string(h, self->masterDir_, masterDir, &len);
len = 1024;
if (self->localDir != NULL)
grib_get_string(h, self->localDir, localDir, &len);
if (self->localDir_ != NULL)
grib_get_string(h, self->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, self->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, self->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, self->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 +124,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", self->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 +134,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", self->dictionary_, filename);
}
f = codes_fopen(filename, "r");
@ -282,7 +294,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i
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) {
@ -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;
}

View File

@ -16,21 +16,22 @@
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;
// TODO(maee): make members private
// private:
public:
const char* dictionary_;
const char* masterDir_;
const char* localDir_;
};
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);

View File

@ -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;
}
@ -53,11 +51,10 @@ static void fill_in(double a[], long length)
static int select_area(grib_accessor* a)
{
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(a);
grib_context* c = h->context;
double* lat = NULL;
double* lon = NULL;
@ -66,13 +63,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, self->numberOfSubsets_, &numberOfSubsets);
if (ret) return ret;
subsets = grib_iarray_new(c, numberOfSubsets, 10);
@ -81,10 +82,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, self->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, self->extractAreaLatitudeRank_, &latRank);
if (ret) return ret;
snprintf(latstr, sizeof(latstr), "#%ld#latitude", latRank);
}
@ -141,13 +142,13 @@ static int select_area(grib_accessor* a)
}
}
ret = grib_get_double(h, self->extractAreaWestLongitude, &lonWest);
ret = grib_get_double(h, self->extractAreaWestLongitude_, &lonWest);
if (ret) return ret;
ret = grib_get_double(h, self->extractAreaEastLongitude, &lonEast);
ret = grib_get_double(h, self->extractAreaEastLongitude_, &lonEast);
if (ret) return ret;
ret = grib_get_double(h, self->extractAreaNorthLatitude, &latNorth);
ret = grib_get_double(h, self->extractAreaNorthLatitude_, &latNorth);
if (ret) return ret;
ret = grib_get_double(h, self->extractAreaSouthLatitude, &latSouth);
ret = grib_get_double(h, self->extractAreaSouthLatitude_, &latSouth);
if (ret) return ret;
for (i = 0; i < numberOfSubsets; i++) {
@ -159,16 +160,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, self->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, self->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, self->doExtractSubsets_, 1);
if (ret) return ret;
}
@ -180,11 +181,11 @@ 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(this);
}

View File

@ -16,25 +16,22 @@
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;
public:
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_;
};

View File

@ -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;
@ -108,16 +108,22 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed,
static int select_datetime(grib_accessor* a)
{
grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a;
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_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 +142,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, self->numberOfSubsets_, &numberOfSubsets);
if (ret) return ret;
subsets = grib_iarray_new(c, numberOfSubsets, 10);
@ -316,11 +322,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, self->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, self->doExtractSubsets_, 1);
if (ret) return ret;
}
@ -337,11 +343,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(this);
}

View File

@ -16,18 +16,15 @@
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;
public:
const char* doExtractSubsets_;
const char* numberOfSubsets_;
const char* extractSubsetList_;
};

View File

@ -11,51 +11,52 @@
#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)
{
const grib_handle* h = grib_handle_of_accessor(a);
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
const grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
if (self->packAccessor)
if (self->packAccessor_)
return;
self->numericValuesAccessor = grib_find_accessor(h, self->numericValues);
self->packAccessor = grib_find_accessor(h, self->pack);
self->numericValuesAccessor_ = grib_find_accessor(h, self->numericValues_);
self->packAccessor_ = grib_find_accessor(h, self->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(this);
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;
}

View File

@ -16,19 +16,16 @@
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;
public:
const char* numericValues_;
const char* pack_;
grib_accessor* numericValuesAccessor_;
grib_accessor* packAccessor_;
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -11,29 +11,27 @@
#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;
}
@ -55,21 +53,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, self->numberOfSubsets_, &numberOfSubsets);
if (ret)
return ret;
ret = grib_get_long(h, self->simpleThinningStart, &start);
ret = grib_get_long(h, self->simpleThinningStart_, &start);
if (ret)
return ret;
ret = grib_get_long(h, self->simpleThinningSkip, &skip);
ret = grib_get_long(h, self->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, self->simpleThinningMissingRadius_, &radius);
if (ret)
return ret;
@ -82,7 +80,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, self->extractSubsetList_, subsets_ar, nsubsets);
grib_context_free(c, subsets_ar);
if (ret)
return ret;
@ -91,7 +89,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, self->doExtractSubsets_, 1);
if (ret)
return ret;
}
@ -104,15 +102,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(this);
if (err)
return err;
return grib_set_long(a->parent->h, self->doExtractSubsets, 1);
return grib_set_long(parent_->h, doExtractSubsets_, 1);
}

View File

@ -16,21 +16,18 @@
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;
public:
const char* doExtractSubsets_;
const char* numberOfSubsets_;
const char* extractSubsetList_;
const char* simpleThinningStart_;
const char* simpleThinningMissingRadius_;
const char* simpleThinningSkip_;
};

View File

@ -12,45 +12,43 @@
#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_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 (!self->dataAccessor_) {
self->dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName_);
}
return self->dataAccessor;
return self->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_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 = get_accessor(this);
if (!data)
return GRIB_NOT_FOUND;
@ -75,18 +73,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(this);
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);
}

View File

@ -16,20 +16,17 @@
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;
public:
const char* dataAccessorName_;
grib_accessor* dataAccessor_;
};

View File

@ -11,43 +11,41 @@
#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_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 (!self->expandedDescriptorsAccessor_) {
self->expandedDescriptorsAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors_);
}
return self->expandedDescriptorsAccessor;
return self->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(this);
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 +60,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 +68,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(this);
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 +95,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(this);
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);
}

View File

@ -16,19 +16,16 @@
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;
public:
const char* expandedDescriptors_;
grib_accessor* expandedDescriptorsAccessor_;
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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", &paramId);
if (err) snprintf(val, 1024, "%s", "unknown");
else snprintf(val, 1024, "p%ld", paramId);
err = grib_get_long(h, "paramId", &paramId);
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;
}

View File

@ -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;
public:
/* Members defined in cf_var_name */
const char* defaultKey_;
};

View File

@ -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;

View File

@ -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_;
};

View File

@ -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;

View File

@ -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_;
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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) {

View File

@ -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_;
};

View File

@ -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)
@ -33,7 +31,7 @@ static int test_bit(long a, long b)
static int grib_get_codeflag(grib_accessor* a, 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 +41,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(a), NULL, self->tablename_, fname, 1);
if (err) {
strncpy(fname, self->tablename, sizeof(fname) - 1);
strncpy(fname, self->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(a->context_, fname)) == NULL) {
grib_context_log(a->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(a->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 +68,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, self->length_ * 8 - atol(num)) > 0) == atol(bval)) {
size_t linelen = strlen(line);
codename[j++] = '(';
codename[j++] = num[0];
@ -99,24 +97,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(this, v, flagname);
grib_dump_bits(dumper, a, flagname);
grib_dump_bits(dumper, this, flagname);
}

View File

@ -16,16 +16,13 @@
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;
public:
const char* tablename_;
};

View File

@ -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;
}
}
@ -167,40 +166,52 @@ static void dump_codetable(grib_codetable* atable)
static grib_codetable* load_table(grib_accessor* a)
{
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 = ((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,
};
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 (self->masterDir_ != NULL)
grib_get_string(h, self->masterDir_, masterDir, &len);
len = 1024;
if (self->localDir != NULL)
grib_get_string(h, self->localDir, localDir, &len);
if (self->localDir_ != NULL)
grib_get_string(h, self->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, self->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, self->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, self->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,9 +243,9 @@ 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 (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) {
Assert(self->vvalue_ != NULL);
size = self->vvalue_->length * 8;
}
else {
size = ((grib_accessor*)self)->byte_count() * 8;
@ -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(this); /* 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(this); /* 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(this); /* 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(this); /* 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;
}

View File

@ -15,27 +15,25 @@
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;
public:
grib_codetable* table_;
const char* tablename_;
const char* masterDir_;
const char* localDir_;
int table_loaded_;
};

View File

@ -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;
}

View File

@ -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_;
};

View File

@ -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;
}

View File

@ -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_;
};

View File

@ -11,9 +11,8 @@
#include "grib_accessor_class_concept.h"
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
@ -33,15 +32,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);
}
/* Return 1 (=True) or 0 (=False) */
@ -137,7 +136,7 @@ static const char* concept_evaluate(grib_accessor* a)
grib_concept_value* c = action_concept_get_concept(a);
grib_handle* h = grib_handle_of_accessor(a);
// 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;
@ -255,7 +254,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);
@ -270,7 +269,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,
@ -348,12 +349,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;
@ -363,16 +364,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);
}
@ -380,10 +381,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
@ -393,20 +394,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;
}
@ -416,14 +417,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;
}
@ -441,9 +442,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;
}
@ -452,73 +453,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;
@ -529,7 +530,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;
@ -542,10 +543,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;
@ -554,8 +555,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;
}

View File

@ -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;
};

View File

@ -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;
}

View File

@ -10,12 +10,11 @@
#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;
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;

View File

@ -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_;
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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,23 @@ 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)
{
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;
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
size_t i = 0;
size_t j = 0;
@ -254,17 +247,17 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
double missing_value = 0;
int err = a->value_count(&nn);
n_vals = 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(a), self->bitmap_))
return grib_get_array<T>(grib_handle_of_accessor(a), self->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(a), self->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(a), self->missing_value_, &missing_value)) != GRIB_SUCCESS)
return err;
if (*len < n_vals) {
@ -280,21 +273,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(a), self->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(a->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(a), self->coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) {
grib_context_free(a->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(a->context_, GRIB_LOG_DEBUG,
"grib_accessor_data_apply_bitmap: %s : creating %s, %d values",
__func__, a->name_, n_vals);
for (i = 0; i < n_vals; i++) {
if (val[i] == 0) {
@ -303,11 +296,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(a->context_, coded_vals);
grib_context_log(a->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);
a->name_, __func__, coded_n_vals, n_vals);
return GRIB_ARRAY_TOO_SMALL;
}
@ -316,28 +309,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(a->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>(this, 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>(this, 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 +341,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 +354,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;
}

View File

@ -15,28 +15,25 @@
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;
public:
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_;
};

View File

@ -11,53 +11,48 @@
#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)
{
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(a), self->numberOfPoints_, &numberOfPoints);
if (ret)
return ret;
@ -66,7 +61,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(a), self->values_, &valuesSize);
if (ret)
return ret;
@ -75,31 +70,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(a->context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)",
numberOfPoints, numberOfPoints, self->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(a->context_, sizeof(double) * numberOfPoints);
ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->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(a), self->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(a), self->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(a), self->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(a->context_, sizeof(long) * plSize);
ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl_, pl, &plSize);
if (ret)
return ret;
@ -116,7 +111,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
}
}
grib_context_free(a->context, pl);
grib_context_free(a->context_, pl);
}
else {
for (j = 0; j < numberOfRows; j++) {
@ -133,52 +128,52 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
}
}
grib_context_free(a->context, values);
grib_context_free(a->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>(this, 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>(this, 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 +181,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 +205,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 +216,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 +250,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 +266,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;
}

View File

@ -15,26 +15,23 @@
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;
public:
const char* values_;
const char* numberOfRows_;
const char* numberOfColumns_;
const char* numberOfPoints_;
const char* pl_;
};

View File

@ -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;
}

View File

@ -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_;
};

Some files were not shown because too many files have changed in this diff Show More