ECC-147 and part ECC-133

This commit is contained in:
Enrico Fucile 2015-09-03 15:49:24 +01:00
parent a68262a9b3
commit fb7434b671
9 changed files with 100 additions and 21 deletions

View File

@ -22,6 +22,7 @@ meta numericValues bufr_data_array(offsetSection4,offsetBeforeData,offsetEndSect
meta stringValues bufr_string_values(numericValues); meta stringValues bufr_string_values(numericValues);
meta unpack unpack_bufr_values(numericValues) ; meta unpack unpack_bufr_values(numericValues) ;
meta pack pack_bufr_values(numericValues) ;
#when (changed(unexpandedDescriptors)) { #when (changed(unexpandedDescriptors)) {
# resize data section and unpack # resize data section and unpack

View File

@ -102,7 +102,7 @@ int main(int argc,char* argv[])
CODES_CHECK(codes_get_size(h,name,&klen),0); CODES_CHECK(codes_get_size(h,name,&klen),0);
/* not array */ /* not array */
if(klen ==1 || keyType == CODES_TYPE_STRING) if(klen ==1)
{ {
vlen=MAX_VAL_LEN; vlen=MAX_VAL_LEN;
bzero(value,vlen); bzero(value,vlen);

View File

@ -8,6 +8,7 @@
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. # virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
# #
set -x
. ./include.sh . ./include.sh

View File

@ -22,6 +22,7 @@
SUPER = grib_accessor_class_gen SUPER = grib_accessor_class_gen
IMPLEMENTS = init;dump IMPLEMENTS = init;dump
IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double
IMPLEMENTS = pack_long; pack_double
IMPLEMENTS = value_count; destroy; get_native_type; IMPLEMENTS = value_count; destroy; get_native_type;
MEMBERS = long index MEMBERS = long index
MEMBERS = int type MEMBERS = int type
@ -48,6 +49,8 @@ or edit "accessor.class" and rerun ./make_class.pl
*/ */
static int get_native_type(grib_accessor*); static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val,size_t *len);
static int pack_long(grib_accessor*, const long* val,size_t *len);
static int unpack_double(grib_accessor*, double* val,size_t *len); static int unpack_double(grib_accessor*, double* val,size_t *len);
static int unpack_long(grib_accessor*, long* val,size_t *len); static int unpack_long(grib_accessor*, long* val,size_t *len);
static int unpack_string (grib_accessor*, char*, size_t *len); static int unpack_string (grib_accessor*, char*, size_t *len);
@ -94,9 +97,9 @@ static grib_accessor_class _grib_accessor_class_bufr_data_element = {
0, /* get sub_section */ 0, /* get sub_section */
0, /* grib_pack procedures long */ 0, /* grib_pack procedures long */
0, /* grib_pack procedures long */ 0, /* grib_pack procedures long */
0, /* grib_pack procedures long */ &pack_long, /* grib_pack procedures long */
&unpack_long, /* grib_unpack procedures long */ &unpack_long, /* grib_unpack procedures long */
0, /* grib_pack procedures double */ &pack_double, /* grib_pack procedures double */
&unpack_double, /* grib_unpack procedures double */ &unpack_double, /* grib_unpack procedures double */
0, /* grib_pack procedures string */ 0, /* grib_pack procedures string */
&unpack_string, /* grib_unpack procedures string */ &unpack_string, /* grib_unpack procedures string */
@ -130,8 +133,6 @@ static void init_class(grib_accessor_class* c)
c->sub_section = (*(c->super))->sub_section; c->sub_section = (*(c->super))->sub_section;
c->pack_missing = (*(c->super))->pack_missing; c->pack_missing = (*(c->super))->pack_missing;
c->is_missing = (*(c->super))->is_missing; c->is_missing = (*(c->super))->is_missing;
c->pack_long = (*(c->super))->pack_long;
c->pack_double = (*(c->super))->pack_double;
c->pack_string = (*(c->super))->pack_string; c->pack_string = (*(c->super))->pack_string;
c->pack_string_array = (*(c->super))->pack_string_array; c->pack_string_array = (*(c->super))->pack_string_array;
c->pack_bytes = (*(c->super))->pack_bytes; c->pack_bytes = (*(c->super))->pack_bytes;
@ -199,7 +200,7 @@ void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a,gr
static void init(grib_accessor* a, const long len, grib_arguments* params) { static void init(grib_accessor* a, const long len, grib_arguments* params) {
a->length = 0; a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */
} }
static void dump(grib_accessor* a, grib_dumper* dumper) static void dump(grib_accessor* a, grib_dumper* dumper)
@ -252,10 +253,22 @@ static int unpack_string (grib_accessor* a, char* val, size_t *len)
char* str=NULL; char* str=NULL;
char* p=0; char* p=0;
size_t slen=0; size_t slen=0;
const char* sval[100]={0,};
double dval=0;
size_t dlen=1;
int ret=0,i,idx; int ret=0,i,idx;
grib_context* c=a->parent->h->context; grib_context* c=a->parent->h->context;
if (self->type != BUFR_DESCRIPTOR_TYPE_STRING) {
unpack_double(a,&dval,&dlen);
sprintf(sval,"%g",dval);
slen=strlen(sval);
if (len < slen) return GRIB_ARRAY_TOO_SMALL;
strcpy(val,sval);
return GRIB_SUCCESS;
}
if (self->compressedData) { if (self->compressedData) {
idx=(int)self->numericValues->v[self->index]->v[0]/1000-1; idx=(int)self->numericValues->v[self->index]->v[0]/1000-1;
str=grib_context_strdup(c,self->stringValues->v[idx]); str=grib_context_strdup(c,self->stringValues->v[idx]);
@ -336,6 +349,52 @@ static int unpack_double (grib_accessor* a, double* val, size_t *len)
return ret; return ret;
} }
static int pack_double(grib_accessor* a, const double* val, size_t *len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret=0,i;
long count=0;
value_count(a,&count);
if (*len<count) return GRIB_ARRAY_TOO_SMALL;
if (self->compressedData) {
for (i=0;i<count;i++) {
self->numericValues->v[self->index]->v[i]=val[i];
}
*len=count;
} else {
self->numericValues->v[self->subsetNumber]->v[self->index]=val[0];
*len=1;
}
return ret;
}
static int pack_long(grib_accessor* a, const long* val, size_t *len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret=0,i;
long count=0;
value_count(a,&count);
if (*len<count) return GRIB_ARRAY_TOO_SMALL;
if (self->compressedData) {
for (i=0;i<count;i++) {
self->numericValues->v[self->index]->v[i] = 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;
}
return ret;
}
static int value_count(grib_accessor* a,long* count) static int value_count(grib_accessor* a,long* count)
{ {
int ret=0,size,type,idx; int ret=0,size,type,idx;

View File

@ -16,7 +16,7 @@
START_CLASS_DEF START_CLASS_DEF
CLASS = accessor CLASS = accessor
SUPER = grib_accessor_class_variable SUPER = grib_accessor_class_variable
IMPLEMENTS = init;dump IMPLEMENTS = init;dump;next
END_CLASS_DEF END_CLASS_DEF
*/ */
@ -34,6 +34,7 @@ or edit "accessor.class" and rerun ./make_class.pl
static void dump(grib_accessor*, grib_dumper*); static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*,const long, grib_arguments* ); static void init(grib_accessor*,const long, grib_arguments* );
static void init_class(grib_accessor_class*); static void init_class(grib_accessor_class*);
static grib_accessor* next(grib_accessor*, int);
typedef struct grib_accessor_bufr_group { typedef struct grib_accessor_bufr_group {
grib_accessor att; grib_accessor att;
@ -82,7 +83,7 @@ static grib_accessor_class _grib_accessor_class_bufr_group = {
0, /* preferred_size */ 0, /* preferred_size */
0, /* resize */ 0, /* resize */
0, /* nearest_smaller_value */ 0, /* nearest_smaller_value */
0, /* next accessor */ &next, /* next accessor */
0, /* compare vs. another accessor */ 0, /* compare vs. another accessor */
0, /* unpack only ith value */ 0, /* unpack only ith value */
0, /* unpack a subarray */ 0, /* unpack a subarray */
@ -120,7 +121,6 @@ static void init_class(grib_accessor_class* c)
c->preferred_size = (*(c->super))->preferred_size; c->preferred_size = (*(c->super))->preferred_size;
c->resize = (*(c->super))->resize; c->resize = (*(c->super))->resize;
c->nearest_smaller_value = (*(c->super))->nearest_smaller_value; c->nearest_smaller_value = (*(c->super))->nearest_smaller_value;
c->next = (*(c->super))->next;
c->compare = (*(c->super))->compare; c->compare = (*(c->super))->compare;
c->unpack_double_element = (*(c->super))->unpack_double_element; c->unpack_double_element = (*(c->super))->unpack_double_element;
c->unpack_double_subarray = (*(c->super))->unpack_double_subarray; c->unpack_double_subarray = (*(c->super))->unpack_double_subarray;
@ -140,3 +140,18 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
grib_dump_section(dumper,a,a->sub_section->block); grib_dump_section(dumper,a,a->sub_section->block);
} }
static grib_accessor* next(grib_accessor* a,int explore) {
grib_accessor* next=NULL;
if (explore) {
next=a->sub_section->block->first;
if (!next) next=a->next;
} else {
next=a->next;
}
if (!next) {
if (a->parent->owner)
next=a->parent->owner->cclass->next(a->parent->owner,0);
}
return next;
}

View File

@ -43,6 +43,8 @@ or edit "accessor.class" and rerun ./make_class.pl
*/ */
static int pack_string(grib_accessor*, const char*, size_t *len);
static int pack_string_array(grib_accessor*, const char**, size_t *len);
static int unpack_string (grib_accessor*, char*, size_t *len); static int unpack_string (grib_accessor*, char*, size_t *len);
static int unpack_string_array (grib_accessor*, char**, size_t *len); static int unpack_string_array (grib_accessor*, char**, size_t *len);
static int value_count(grib_accessor*,long*); static int value_count(grib_accessor*,long*);
@ -85,9 +87,9 @@ static grib_accessor_class _grib_accessor_class_bufr_string_values = {
0, /* grib_unpack procedures long */ 0, /* grib_unpack procedures long */
0, /* grib_pack procedures double */ 0, /* grib_pack procedures double */
0, /* grib_unpack procedures double */ 0, /* grib_unpack procedures double */
0, /* grib_pack procedures string */ &pack_string, /* grib_pack procedures string */
&unpack_string, /* grib_unpack procedures string */ &unpack_string, /* grib_unpack procedures string */
0, /* grib_pack array procedures string */ &pack_string_array, /* grib_pack array procedures string */
&unpack_string_array, /* grib_unpack array procedures string */ &unpack_string_array, /* grib_unpack array procedures string */
0, /* grib_pack procedures bytes */ 0, /* grib_pack procedures bytes */
0, /* grib_unpack procedures bytes */ 0, /* grib_unpack procedures bytes */
@ -122,8 +124,6 @@ static void init_class(grib_accessor_class* c)
c->unpack_long = (*(c->super))->unpack_long; c->unpack_long = (*(c->super))->unpack_long;
c->pack_double = (*(c->super))->pack_double; c->pack_double = (*(c->super))->pack_double;
c->unpack_double = (*(c->super))->unpack_double; c->unpack_double = (*(c->super))->unpack_double;
c->pack_string = (*(c->super))->pack_string;
c->pack_string_array = (*(c->super))->pack_string_array;
c->pack_bytes = (*(c->super))->pack_bytes; c->pack_bytes = (*(c->super))->pack_bytes;
c->unpack_bytes = (*(c->super))->unpack_bytes; c->unpack_bytes = (*(c->super))->unpack_bytes;
c->pack_expression = (*(c->super))->pack_expression; c->pack_expression = (*(c->super))->pack_expression;

View File

@ -197,6 +197,9 @@ static int pack_long (grib_accessor* a, const long* val, size_t *len)
static int pack_double (grib_accessor* a, const double* val, size_t *len) static int pack_double (grib_accessor* a, const double* val, size_t *len)
{ {
return GRIB_NOT_IMPLEMENTED; grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a;
grib_accessor* data=(grib_accessor*)self->data_accessor;
return grib_pack_double(data,0,0);
} }

View File

@ -709,12 +709,12 @@ set -e
EOF EOF
chmod +x $testScript chmod +x $testScript
${tools_dir}/bufr_filter $fRulesReady $f 2>> $fLog 1> $testScript ${tools_dir}/bufr_filter $fRulesReady $f 2>> $fLog 1>> $testScript
./$testScript ./$testScript
rm -f new_*bufr #rm -f new_*bufr
rm -f $testScript #rm -f $testScript
#----------------------------------------------------------- #-----------------------------------------------------------
# Test: get string # Test: get string

View File

@ -1001,7 +1001,7 @@ static int compare_all_dump_keys(grib_handle* h1,grib_handle* h2,grib_runtime_op
{ {
grib_accessor* xa=grib_keys_iterator_get_accessor(iter); grib_accessor* xa=grib_keys_iterator_get_accessor(iter);
name=grib_keys_iterator_get_name(iter); name=grib_keys_iterator_get_name(iter);
/*printf("----- comparing %s\n",name);*/ printf("----- comparing %s\n",name);
if (blacklisted(name)) continue; if (blacklisted(name)) continue;
if (xa==NULL || ( xa->flags & GRIB_ACCESSOR_FLAG_DUMP )==0 ) continue; if (xa==NULL || ( xa->flags & GRIB_ACCESSOR_FLAG_DUMP )==0 ) continue;
@ -1108,10 +1108,10 @@ static int compare_handles(grib_handle* h1,grib_handle* h2,grib_runtime_options*
GRIB_CHECK_NOLINE(grib_get_message(h2,&msg2,&size2),0); GRIB_CHECK_NOLINE(grib_get_message(h2,&msg2,&size2),0);
if (size1==size2 && !(memcmp_ret=memcmp(msg1,msg2,size1))) { if (size1==size2 && !(memcmp_ret=memcmp(msg1,msg2,size1))) {
return 0; return 0;
} }
#if 0 #if 0
else if (options->mode == MODE_BUFR ) { else {
int lcount=count; int lcount=count,ii;
if (options->current_infile) lcount=options->current_infile->filter_handle_count; if (options->current_infile) lcount=options->current_infile->filter_handle_count;
if (size1 != size2) { if (size1 != size2) {
printf("#%d different size: %d!=%d\n",lcount,(int)size1,(int)size2); printf("#%d different size: %d!=%d\n",lcount,(int)size1,(int)size2);