ECC-1126: Simplify keys

This commit is contained in:
Shahram Najm 2020-06-27 12:52:54 +01:00
parent 15f2b7eb76
commit f78f19c2e5
8 changed files with 36 additions and 102 deletions

View File

@ -82,9 +82,8 @@ if (section2Present && bufrHeaderCentre==98 && section2Length==52) {
} else {
meta ls.localLatitude bits(keyData,72,25,-9000000,100000) : dump,no_copy;
meta ls.localLongitude bits(keyData,40,26,-18000000,100000) : dump,no_copy;
meta identTrimmed trim(keyMore,1,1): no_copy, hidden;
meta mars.ident sprintf("%s", identTrimmed) : string_type, no_copy;
alias ls.ident=identTrimmed : dump,string_type,no_copy;
meta ident trim(keyMore,1,1): dump, no_copy; # remove whitespaces left and right
alias mars.ident = ident : string_type, no_copy;
}
}

View File

@ -16,7 +16,7 @@
CLASS = accessor
SUPER = grib_accessor_class_ascii
IMPLEMENTS = unpack_string;pack_string
IMPLEMENTS = init
IMPLEMENTS = init; string_length
MEMBERS= const char* input
MEMBERS= int trim_left
MEMBERS= int trim_right
@ -36,6 +36,7 @@ or edit "accessor.class" and rerun ./make_class.pl
static int pack_string(grib_accessor*, const char*, size_t* len);
static int unpack_string(grib_accessor*, char*, size_t* len);
static size_t string_length(grib_accessor*);
static void init(grib_accessor*, const long, grib_arguments*);
static void init_class(grib_accessor_class*);
@ -63,7 +64,7 @@ static grib_accessor_class _grib_accessor_class_trim = {
0, /* free mem */
0, /* describes himself */
0, /* get length of section */
0, /* get length of string */
&string_length, /* get length of string */
0, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
@ -103,7 +104,6 @@ static void init_class(grib_accessor_class* c)
{
c->dump = (*(c->super))->dump;
c->next_offset = (*(c->super))->next_offset;
c->string_length = (*(c->super))->string_length;
c->value_count = (*(c->super))->value_count;
c->byte_count = (*(c->super))->byte_count;
c->byte_offset = (*(c->super))->byte_offset;
@ -193,3 +193,8 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
return grib_pack_string(inputAccesstor, pBuf, len);
}
static size_t string_length(grib_accessor* a)
{
return 1024;
}

View File

@ -547,12 +547,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
(void)err; /* TODO */
}
#define MAX_STRING_SIZE 4096
static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
{
grib_dumper_bufr_decode_C* self = (grib_dumper_bufr_decode_C*)d;
char* value = NULL;
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
size_t size = MAX_STRING_SIZE;
char* p = NULL;
size_t size = 0;
grib_context* c = a->context;
int r = 0, err = 0;
grib_handle* h = grib_handle_of_accessor(a);
@ -560,16 +561,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0)
return;
_grib_get_string_length(a, &size);
if (size == 0)
return;
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
return;
}
self->empty = 0;
err = grib_unpack_string(a, value, &size);
@ -613,7 +604,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
depth -= 2;
}
grib_context_free(c, value);
(void)err; /* TODO */
}

View File

@ -460,31 +460,21 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
(void)err; /* TODO */
}
#define MAX_STRING_SIZE 4096
static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
{
grib_dumper_bufr_decode_filter* self = (grib_dumper_bufr_decode_filter*)d;
char* value = NULL;
char* p = NULL;
size_t size = 0;
grib_context* c = a->context;
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
size_t size = MAX_STRING_SIZE;
char* p = NULL;
grib_context* c = a->context;
int r =0, err = 0;
grib_handle* h = grib_handle_of_accessor(a);
if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0)
return;
_grib_get_string_length(a, &size);
if (size == 0)
return;
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
return;
}
else
self->begin = 0;
self->begin = 0;
self->empty = 0;
@ -492,7 +482,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
p = value;
r = compute_bufr_key_rank(h, self->keys, a->name);
if (grib_is_missing_string(a, (unsigned char*)value, size)) {
grib_context_free(c, value);
return;
}
@ -528,7 +517,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
depth -= 2;
}
grib_context_free(c, value);
(void)err; /* TODO */
}

View File

@ -489,29 +489,20 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
(void)err; /* TODO */
}
#define MAX_STRING_SIZE 4096
static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
{
grib_dumper_bufr_decode_fortran* self = (grib_dumper_bufr_decode_fortran*)d;
char* value = NULL;
char* p = NULL;
size_t size = 0;
grib_context* c = a->context;
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
size_t size = MAX_STRING_SIZE;
char* p = NULL;
grib_context* c = a->context;
int r = 0, err = 0;
grib_handle* h = grib_handle_of_accessor(a);
if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0)
return;
_grib_get_string_length(a, &size);
if (size == 0)
return;
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
return;
}
self->empty = 0;
err = grib_unpack_string(a, value, &size);
@ -556,7 +547,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
depth -= 2;
}
grib_context_free(c, value);
(void)err; /* TODO */
}

View File

@ -502,12 +502,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
(void)err; /* TODO */
}
#define MAX_STRING_SIZE 4096
static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
{
grib_dumper_bufr_decode_python* self = (grib_dumper_bufr_decode_python*)d;
char* value = NULL;
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
char* p = NULL;
size_t size = 0;
size_t size = MAX_STRING_SIZE;
grib_context* c = a->context;
int r = 0, err = 0;
grib_handle* h = grib_handle_of_accessor(a);
@ -515,16 +516,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0)
return;
_grib_get_string_length(a, &size);
if (size == 0)
return;
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
return;
}
self->empty = 0;
err = grib_unpack_string(a, value, &size);
@ -567,7 +558,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
depth -= 2;
}
grib_context_free(c, value);
(void)err; /* TODO */
}

View File

@ -628,49 +628,31 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
(void)err; /* TODO */
}
#define MAX_STRING_SIZE 4096
static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
{
grib_dumper_bufr_simple* self = (grib_dumper_bufr_simple*)d;
char* value = NULL;
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
char* p = NULL;
size_t size = 0;
size_t size = MAX_STRING_SIZE;
grib_context* c = a->context;
int r = 0;
int is_missing = 0;
int err = 0;
grib_handle* h = grib_handle_of_accessor(a);
const char* acc_name = a->name;
_grib_get_string_length(a, &size);
if (size == 0)
return;
if ( strcmp(acc_name,"ident")==0 )
puts("");
if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) {
/* ECC-356: Solution for the special local section key 'keyMore' and its alias 'ident' */
int skip = 1;
if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) {
/* We've come across a key which is hidden */
if (strcmp(a->name, "keyMore") == 0 && grib_is_defined(h, "ls.ident")) {
grib_accessor* acc = NULL;
skip = 0;
acc_name = "ident";
acc = grib_find_accessor(h, "identTrimmed");
if (acc) a = acc;
}
}
if (skip)
return;
}
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
return;
}
self->empty = 0;
err = grib_unpack_string(a, value, &size);
Assert(size < MAX_STRING_SIZE);
p = value;
r = compute_bufr_key_rank(h, self->keys, acc_name);
if (grib_is_missing_string(a, (unsigned char*)value, size)) {
@ -711,7 +693,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
grib_context_free(c, prefix);
}
grib_context_free(c, value);
(void)err; /* TODO */
}

View File

@ -450,23 +450,14 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
{
grib_dumper_json* self = (grib_dumper_json*)d;
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
size_t size = MAX_STRING_SIZE;
char* p = NULL;
size_t size = MAX_STRING_SIZE;
int is_missing = 0;
int err = 0;
const char* acc_name = a->name;
if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) {
/* ECC-356: Solution for the special local section key 'keyMore' and its alias 'ident' */
int skip = 1;
if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) {
if (strcmp(a->name, "identTrimmed") == 0) {
skip = 0;
acc_name = "ident";
}
}
if (skip)
return;
return;
}
/* ECC-710: It is MUCH slower determining the string length here