ECC-150 set double array and string in compressed data

This commit is contained in:
Enrico Fucile 2015-09-15 14:06:49 +01:00
parent e18c120f21
commit b78c5b13b2
5 changed files with 117 additions and 40 deletions

View File

@ -408,7 +408,7 @@ static void decode_string_array(grib_context* c,unsigned char* data,long* pos, i
*err=check_end_data(c,self,modifiedWidth);
if (*err) return ;
grib_decode_string(data,pos,modifiedWidth/8,sval);
clean_string(sval,modifiedWidth/8);
/* clean_string(sval,modifiedWidth/8); */
*err=check_end_data(c,self,6);
if (*err) return ;
width=grib_decode_unsigned_long(data,pos,6);
@ -419,7 +419,7 @@ static void decode_string_array(grib_context* c,unsigned char* data,long* pos, i
for (j=0;j<self->numberOfSubsets;j++) {
sval=(char*)grib_context_malloc_clear(c,width+1);
grib_decode_string(data,pos,width,sval);
clean_string(sval,width);
/* clean_string(sval,width); */
grib_sarray_push(c,self->stringValues,sval);
}
} else {
@ -487,7 +487,7 @@ static int encode_string_array(grib_context* c,grib_buffer* buff,long* pos, int
n=stringValues->n;
end=n+1;
} else {
end=start+n+1;
end=start+n;
}
modifiedWidth= self->expanded->v[i]->width;
@ -504,7 +504,7 @@ static int encode_string_array(grib_context* c,grib_buffer* buff,long* pos, int
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6);
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+width*n);
for (j=start;j<end;j++) {
grib_encode_string(buff->data,pos,width,stringValues->v[j]);
grib_encode_string(buff->data,pos,width/8,stringValues->v[j]);
}
}
return err;
@ -669,7 +669,7 @@ static char* decode_string_value(grib_context* c,unsigned char* data,long* pos,
sval=(char*)grib_context_malloc_clear(c,len+1);
grib_decode_string(data,pos,len,sval);
clean_string(sval,len);
/* clean_string(sval,len); */
return sval;
}

View File

@ -22,7 +22,7 @@
SUPER = grib_accessor_class_gen
IMPLEMENTS = init;dump
IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double
IMPLEMENTS = pack_long; pack_double
IMPLEMENTS = pack_long; pack_double ; pack_string_array; pack_string
IMPLEMENTS = value_count; destroy; get_native_type;
MEMBERS = long index
MEMBERS = int type
@ -51,6 +51,8 @@ or edit "accessor.class" and rerun ./make_class.pl
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 pack_string(grib_accessor*, const char*, size_t *len);
static int pack_string_array(grib_accessor*, const char**, 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_string (grib_accessor*, char*, size_t *len);
@ -101,9 +103,9 @@ static grib_accessor_class _grib_accessor_class_bufr_data_element = {
&unpack_long, /* grib_unpack procedures long */
&pack_double, /* grib_pack procedures double */
&unpack_double, /* grib_unpack procedures double */
0, /* grib_pack procedures string */
&pack_string, /* grib_pack 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 */
0, /* grib_pack procedures bytes */
0, /* grib_unpack procedures bytes */
@ -133,8 +135,6 @@ static void init_class(grib_accessor_class* c)
c->sub_section = (*(c->super))->sub_section;
c->pack_missing = (*(c->super))->pack_missing;
c->is_missing = (*(c->super))->is_missing;
c->pack_string = (*(c->super))->pack_string;
c->pack_string_array = (*(c->super))->pack_string_array;
c->pack_bytes = (*(c->super))->pack_bytes;
c->unpack_bytes = (*(c->super))->unpack_bytes;
c->pack_expression = (*(c->super))->pack_expression;
@ -247,13 +247,18 @@ static int unpack_string_array (grib_accessor* a, char** val, size_t *len)
return ret;
}
static int pack_string_array(grib_accessor*a , const char** v, size_t *len){
return GRIB_NOT_IMPLEMENTED;
}
static int unpack_string (grib_accessor* a, char* val, size_t *len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
char* str=NULL;
char* p=0;
size_t slen=0;
const char* sval[100]={0,};
char sval[100]={0,};
double dval=0;
size_t dlen=1;
@ -264,7 +269,7 @@ static int unpack_string (grib_accessor* a, char* val, size_t *len)
unpack_double(a,&dval,&dlen);
sprintf(sval,"%g",dval);
slen=strlen(sval);
if (len < slen) return GRIB_ARRAY_TOO_SMALL;
if (*len < slen) return GRIB_ARRAY_TOO_SMALL;
strcpy(val,sval);
return GRIB_SUCCESS;
}
@ -301,6 +306,33 @@ static int unpack_string (grib_accessor* a, char* val, size_t *len)
return ret;
}
static int pack_string(grib_accessor* a, const char* val, size_t *len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret=0,i,idx;
long count=0;
grib_context* c=a->parent->h->context;
if (self->compressedData) {
count=self->numberOfSubsets;
idx=(int)self->numericValues->v[self->index]->v[0]/1000-1;
for (i=0;i<count;i++) {
grib_context_free(c,self->stringValues->v[idx]);
self->stringValues->v[idx]=grib_context_strdup(c,val);
idx++;
}
*len=count;
} else {
idx=(int)self->numericValues->v[self->subsetNumber]->v[self->index]/1000-1;
grib_context_free(c,self->stringValues->v[idx]);
self->stringValues->v[idx]=grib_context_strdup(c,val);
*len=1;
}
return ret;
}
static int unpack_long (grib_accessor* a, long* val, size_t *len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
@ -353,16 +385,16 @@ 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;
long count=1,n;
if (self->compressedData) {
for (i=0;i<count;i++) {
self->numericValues->v[self->index]->v[i]=val[i];
}
count=self->numberOfSubsets;
grib_darray_delete(a->parent->h->context,self->numericValues->v[self->index]);
self->numericValues->v[self->index]=grib_darray_new(a->parent->h->context,count,1);
for (i=0;i<count;i++)
grib_darray_push(a->parent->h->context,self->numericValues->v[self->index],val[i]);
*len=count;
} else {
self->numericValues->v[self->subsetNumber]->v[self->index]=val[0];
@ -376,15 +408,14 @@ 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;
long count=1;
if (self->compressedData) {
count=self->numberOfSubsets;
grib_darray_delete(a->parent->h->context,self->numericValues->v[self->index]);
for (i=0;i<count;i++) {
self->numericValues->v[self->index]->v[i] = val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i];
grib_darray_push(a->parent->h->context,self->numericValues->v[self->index], val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i]);
}
*len=count;
} else {

View File

@ -56,7 +56,7 @@ typedef struct grib_accessor_unexpanded_descriptors {
/* Members defined in long */
/* Members defined in unexpanded_descriptors */
const char* numberOfUnexpandedDescriptors;
const char* createNewData;
const char* createNewData;
} grib_accessor_unexpanded_descriptors;
extern grib_accessor_class* grib_accessor_class_long;
@ -246,6 +246,7 @@ static int pack_long (grib_accessor* a, const long* val, size_t *len)
Assert(expanded!=NULL);
grib_accessor_class_expanded_descriptors_set_do_expand(expanded,1);
grib_set_long(a->parent->h,"unpack",3);
grib_set_long(a->parent->h,"unpack",1);
return ret;
}

View File

@ -65,7 +65,7 @@ int grib_encode_string(const unsigned char* bitStream, long *bitOffset, size_t n
}
for (i=0;i<numberOfCharacters;i++) {
c=(*s)>>remainder;
c=((*s)>>remainder) & ~mask[remainder];
*p |= c;
p++;
*p = ((*s)<<remainderComplement) & mask[remainder];

View File

@ -734,6 +734,8 @@ rm -f ${f}.ref ${f}.log
cat > $fRules <<EOF
set unpack=1;
print "[stringValues!1]";
print "====";
print "[stationOrSiteName!1]";
EOF
f="synop_multi_subset.bufr"
@ -743,18 +745,32 @@ ${tools_dir}/bufr_filter $fRules $f 2>> $fLog 1>> $fLog
${tools_dir}/bufr_filter $fRules $f 2>> ${f}.log 1>> ${f}.log
cat > ${f}.ref <<EOF
TROMSO-HOLT
PASVIK
KVITHAMAR
FROSTA
FURUNESET
LOKEN I VOLBU
APELSVOLL
KISE
FAVANG
SAERHEIM
LANDVIK
SANDE-GALLEBERG
TROMSO-HOLT
PASVIK
KVITHAMAR
FROSTA
FURUNESET
LOKEN I VOLBU
APELSVOLL
KISE
FAVANG
SAERHEIM
LANDVIK
SANDE-GALLEBERG
====
TROMSO-HOLT
PASVIK
KVITHAMAR
FROSTA
FURUNESET
LOKEN I VOLBU
APELSVOLL
KISE
FAVANG
SAERHEIM
LANDVIK
SANDE-GALLEBERG
EOF
@ -888,3 +904,32 @@ ${tools_dir}/bufr_compare ${f}.out $f 2>> $fLog 1>> $fLog
rm -f ${f}.out
#-----------------------------------------------------------
# Test: set keys in data section
#-----------------------------------------------------------
f="syno_1.bufr"
fout="311001.bufr"
echo "Test: set keys in data section" >> $fLog
echo "file: $f" >> $fLog
cat >$fRules <<EOF
set masterTablesVersionNumber=20;
set localTablesVersionNumber=0;
set compressedData=1;
set numberOfSubsets=10;
set unexpandedDescriptors={311001};
set windSpeed={1,2,3,4,5,6,7,8,9,10};
set windDirection={3,4,5,6,7,8,9,10,11};
set aircraftFlightNumber="1234";
set pack=1;
write;
EOF
${tools_dir}/bufr_filter $fRules -o ${fout} $f 2>> $fLog 1>> $fLog
${tools_dir}/bufr_compare $fout ${fout}.ref 2>> $fLog 1>> $fLog
rm -f $fRules ${fout}