ECC-158 part 1

This commit is contained in:
Enrico Fucile 2015-10-07 17:14:29 +01:00
parent b6b84114f0
commit 918a5d62b3
4 changed files with 88 additions and 70 deletions

View File

@ -43,7 +43,7 @@
MEMBERS = long numberOfSubsets
MEMBERS = long compressedData
MEMBERS = grib_vdarray* numericValues
MEMBERS = grib_sarray* stringValues
MEMBERS = grib_vsarray* stringValues
MEMBERS = grib_viarray* elementsDescriptorsIndex
MEMBERS = int do_decode
MEMBERS = int bitmapStartElementsDescriptorsIndex
@ -107,7 +107,7 @@ typedef struct grib_accessor_bufr_data_array {
long numberOfSubsets;
long compressedData;
grib_vdarray* numericValues;
grib_sarray* stringValues;
grib_vsarray* stringValues;
grib_viarray* elementsDescriptorsIndex;
int do_decode;
int bitmapStartElementsDescriptorsIndex;
@ -296,8 +296,8 @@ static void self_clear(grib_context* c,grib_accessor_bufr_data_array* self)
grib_vdarray_delete_content(c,self->numericValues);
grib_vdarray_delete(c,self->numericValues);
if(self->stringValues) {
/* grib_sarray_delete_content(c,self->stringValues); */
grib_sarray_delete(c,self->stringValues);
/* grib_vsarray_delete_content(c,self->stringValues); */
grib_vsarray_delete(c,self->stringValues);
}
grib_viarray_delete_content(c,self->elementsDescriptorsIndex);
grib_viarray_delete(c,self->elementsDescriptorsIndex);
@ -350,7 +350,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len)
return process_elements(a,PROCESS_ENCODE);
}
grib_sarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a)
grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a)
{
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
process_elements(a,PROCESS_DECODE);
@ -399,6 +399,7 @@ static void decode_string_array(grib_context* c,unsigned char* data,long* pos, i
char* sval=0;
int j,modifiedWidth,modifiedReference,width;
double modifiedFactor;
grib_sarray* sa=grib_sarray_new(c,self->numberOfSubsets,10);
modifiedWidth= self->expanded->v[i]->width;
modifiedReference= self->expanded->v[i]->reference;
@ -420,14 +421,14 @@ static void decode_string_array(grib_context* c,unsigned char* data,long* pos, i
sval=(char*)grib_context_malloc_clear(c,width+1);
grib_decode_string(data,pos,width,sval);
/* clean_string(sval,width); */
grib_sarray_push(c,self->stringValues,sval);
grib_sarray_push(c,sa,sval);
}
} else {
for (j=0;j<self->numberOfSubsets;j++) {
grib_sarray_push(c,self->stringValues,sval);
}
/* for (j=0;j<self->numberOfSubsets;j++) { */
grib_sarray_push(c,sa,sval);
/* } */
}
grib_vsarray_push(c,self->stringValues,sa);
}
static grib_darray* decode_double_array(grib_context* c,unsigned char* data,long* pos,int i,
@ -477,18 +478,15 @@ static grib_darray* decode_double_array(grib_context* c,unsigned char* data,long
}
static int encode_string_array(grib_context* c,grib_buffer* buff,long* pos, int i,
grib_accessor_bufr_data_array* self,grib_sarray* stringValues,int start,int n)
grib_accessor_bufr_data_array* self,grib_sarray* stringValues)
{
char* sval=0;
int err=0,end;
int err=0,end,start;
int j,modifiedWidth,modifiedReference,width;
double modifiedFactor;
if (n==start && start==0) {
n=stringValues->n;
end=n+1;
} else {
end=start+n;
}
start=0;
end=grib_sarray_used_size(stringValues);
modifiedWidth= self->expanded->v[i]->width;
modifiedReference= self->expanded->v[i]->reference;
@ -496,13 +494,13 @@ static int encode_string_array(grib_context* c,grib_buffer* buff,long* pos, int
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+modifiedWidth);
grib_encode_string(buff->data,pos,modifiedWidth/8,stringValues->v[0]);
width= n > 1 ? modifiedWidth : 0;
width= end > 1 ? modifiedWidth : 0;
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6);
grib_encode_unsigned_longb(buff->data,width/8,pos,6);
if (width) {
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6);
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+width*n);
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+width*end);
for (j=start;j<end;j++) {
grib_encode_string(buff->data,pos,width/8,stringValues->v[j]);
}
@ -705,7 +703,7 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
grib_accessor* a=(grib_accessor*)self;
grib_darray* dar=0;
grib_sarray* sar=0;
int index=0,ii;
int index=0,ii,stringValuesLen;
char* csval=0;
double cdval=0,x;
int err=0;
@ -716,7 +714,7 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
/* string */
if (self->compressedData) {
decode_string_array(c,data,pos,i,self,&err);
index=grib_sarray_used_size(self->stringValues)/self->numberOfSubsets;
index=grib_vsarray_used_size(self->stringValues);
dar=grib_darray_new(c,self->numberOfSubsets,10);
index=self->numberOfSubsets*(index-1);
for (ii=1;ii<=self->numberOfSubsets;ii++) {
@ -728,8 +726,13 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
csval=decode_string_value(c,data,pos,i,self,&err);
grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \t %s = %s",
self->expanded->v[i]->shortName,csval);
grib_sarray_push(c,self->stringValues,csval);
index=grib_sarray_used_size(self->stringValues);
sar=grib_sarray_push(c,sar,csval);
grib_vsarray_push(c,self->stringValues,sar);
stringValuesLen=grib_vsarray_used_size(self->stringValues);
index=0;
for (ii=0;ii<stringValuesLen;ii++) {
index+=grib_sarray_used_size(self->stringValues->v[ii]);
}
cdval=index*1000+self->expanded->v[i]->width / 8;
grib_darray_push(c,dval,cdval);
}
@ -807,7 +810,7 @@ static int encode_new_element(grib_context* c,grib_accessor_bufr_data_array* sel
if (self->compressedData) {
grib_sarray* stringValues=grib_sarray_new(c,1,1);
grib_sarray_push(c,stringValues,csval);
err=encode_string_array(c,buff,pos,i,self,stringValues,0,0);
err=encode_string_array(c,buff,pos,i,self,stringValues);
grib_sarray_delete_content(c,stringValues);
grib_sarray_delete(c,stringValues);
} else {
@ -868,11 +871,11 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
/* grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data encoding: \t %s = %s",
self->expanded->v[i]->shortName,csval); */
if (self->compressedData) {
idx=(int)self->numericValues->v[elementIndex]->v[0]/1000-1;
err=encode_string_array(c,buff,pos,i,self,self->stringValues,idx,self->numberOfSubsets);
idx=((int)self->numericValues->v[elementIndex]->v[0]/1000-1)/self->numberOfSubsets;
err=encode_string_array(c,buff,pos,i,self,self->stringValues->v[idx]);
} else {
idx=(int)self->numericValues->v[self->subsetNumber]->v[elementIndex]/1000-1;
err=encode_string_value(c,buff,pos,i,self,self->stringValues->v[idx]);
idx=((int)self->numericValues->v[0]->v[elementIndex]/1000-1)/self->numberOfSubsets;
err=encode_string_value(c,buff,pos,i,self,self->stringValues->v[idx]->v[self->subsetNumber]);
}
} else {
/* numeric or codetable or flagtable */
@ -1541,13 +1544,13 @@ static int process_elements(grib_accessor* a,int flag)
if (do_clean==1 && self->numericValues) {
grib_vdarray_delete_content(c,self->numericValues);
grib_vdarray_delete(c,self->numericValues);
grib_sarray_delete_content(c,self->stringValues);
grib_sarray_delete(c,self->stringValues);
grib_vsarray_delete_content(c,self->stringValues);
grib_vsarray_delete(c,self->stringValues);
}
if (flag!=PROCESS_ENCODE) {
self->numericValues=grib_vdarray_new(c,100,100);
self->stringValues=grib_sarray_new(c,10,10);
self->stringValues=grib_vsarray_new(c,10,10);
if (self->elementsDescriptorsIndex) grib_viarray_delete(c,self->elementsDescriptorsIndex);
self->elementsDescriptorsIndex=grib_viarray_new(c,100,100);

View File

@ -31,7 +31,7 @@
MEMBERS = long numberOfSubsets
MEMBERS = bufr_descriptors_array* descriptors
MEMBERS = grib_vdarray* numericValues
MEMBERS = grib_sarray* stringValues
MEMBERS = grib_vsarray* stringValues
MEMBERS = grib_viarray* elementsDescriptorsIndex
END_CLASS_DEF
@ -74,7 +74,7 @@ typedef struct grib_accessor_bufr_data_element {
long numberOfSubsets;
bufr_descriptors_array* descriptors;
grib_vdarray* numericValues;
grib_sarray* stringValues;
grib_vsarray* stringValues;
grib_viarray* elementsDescriptorsIndex;
} grib_accessor_bufr_data_element;
@ -187,7 +187,7 @@ void accessor_bufr_data_element_set_numericValues(grib_accessor* a,grib_vdarray*
self->numericValues=numericValues;
}
void accessor_bufr_data_element_set_stringValues(grib_accessor* a,grib_sarray* stringValues) {
void accessor_bufr_data_element_set_stringValues(grib_accessor* a,grib_vsarray* stringValues) {
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
self->stringValues=stringValues;
}
@ -228,19 +228,18 @@ static int unpack_string_array (grib_accessor* a, char** val, size_t *len)
long count=0;
grib_context* c=a->parent->h->context;
value_count(a,&count);
if (*len<count) return GRIB_ARRAY_TOO_SMALL;
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)/self->numberOfSubsets;
count=grib_sarray_used_size(self->stringValues->v[idx]);
for (i=0;i<count;i++) {
val[i]=grib_context_strdup(c,self->stringValues->v[idx++]);
val[i]=grib_context_strdup(c,self->stringValues->v[idx]->v[i]);
}
*len=count;
} else {
idx=(int)self->numericValues->v[self->subsetNumber]->v[self->index]/1000-1;
val[0]=grib_context_strdup(c,self->stringValues->v[idx]);
val[0]=grib_context_strdup(c,self->stringValues->v[idx]->v[0]);
*len=1;
}
@ -249,7 +248,23 @@ static int unpack_string_array (grib_accessor* a, char** val, size_t *len)
static int pack_string_array(grib_accessor*a , const char** v, size_t *len){
return GRIB_NOT_IMPLEMENTED;
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret=0,i,idx;
long count=0;
char* s=NULL;
grib_context* c=a->parent->h->context;
count=self->numberOfSubsets;
idx=((int)self->numericValues->v[self->index]->v[0]/1000-1)/self->numberOfSubsets;
grib_sarray_delete(c,self->stringValues->v[idx]);
self->stringValues->v[idx]=grib_sarray_new(c,self->numberOfSubsets,1);
for (i=0;i<self->numberOfSubsets;i++) {
s=grib_context_strdup(c,v[i]);
grib_sarray_push(c,self->stringValues->v[idx],s);
}
return ret;
}
static int unpack_string (grib_accessor* a, char* val, size_t *len)
@ -275,11 +290,11 @@ static int unpack_string (grib_accessor* a, char* val, size_t *len)
}
if (self->compressedData) {
idx=(int)self->numericValues->v[self->index]->v[0]/1000-1;
str=grib_context_strdup(c,self->stringValues->v[idx]);
idx=((int)self->numericValues->v[self->index]->v[0]/1000-1)/self->numberOfSubsets;
str=grib_context_strdup(c,self->stringValues->v[idx]->v[0]);
} else {
idx=(int)self->numericValues->v[self->subsetNumber]->v[self->index]/1000-1;
str=grib_context_strdup(c,self->stringValues->v[idx]);
idx=((int)self->numericValues->v[self->subsetNumber]->v[self->index]/1000-1)/self->numberOfSubsets;
str=grib_context_strdup(c,self->stringValues->v[idx]->v[0]);
}
if (str==0 || strlen(str)==0) {
@ -312,23 +327,15 @@ static int pack_string(grib_accessor* a, const char* val, size_t *len)
int ret=0,i,idx;
long count=0;
char* s=NULL;
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;
}
count=self->numberOfSubsets;
idx=((int)self->numericValues->v[self->index]->v[0]/1000-1)/self->numberOfSubsets;
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);
return ret;
}

View File

@ -168,24 +168,32 @@ static int unpack_string_array (grib_accessor* a, char** buffer, size_t *len)
{
grib_accessor* data=0;
grib_context* c=a->parent->h->context;
grib_sarray* stringValues=NULL;
long l=0;
size_t size,i;
grib_vsarray* stringValues=NULL;
long l=0,n=0,tl;
size_t size,i,j;
char buf[25]={0,};
long* v=0;
char** b=buffer;
data=get_accessor(a);
if (!data) return GRIB_NOT_FOUND;
stringValues=accessor_bufr_data_array_get_stringValues(data);
l=grib_sarray_used_size(stringValues);
if (l>*len) return GRIB_ARRAY_TOO_SMALL;
n=grib_vsarray_used_size(stringValues);
for (i=0;i<l;i++) {
buffer[i]=grib_context_strdup(c,stringValues->v[i]);
tl=0;
for (j=0;j<n;j++) {
l=grib_sarray_used_size(stringValues->v[j]);
tl+=l;
if (tl>*len) return GRIB_ARRAY_TOO_SMALL;
for (i=0;i<l;i++) {
*(b++)=grib_context_strdup(c,stringValues->v[j]->v[i]);
}
}
*len=l;
*len=tl;
return GRIB_SUCCESS;
}

View File

@ -266,7 +266,7 @@ size_t grib_viarray_used_size(grib_viarray *v);
/* grib_accessor_class_bufr_data.c */
/* grib_accessor_class_bufr_data_array.c */
grib_sarray *accessor_bufr_data_array_get_stringValues(grib_accessor *a);
grib_vsarray *accessor_bufr_data_array_get_stringValues(grib_accessor *a);
grib_accessors_list *accessor_bufr_data_array_get_dataAccessors(grib_accessor *a);
void accessor_bufr_data_array_set_unpackMode(grib_accessor *a, int unpackMode);
@ -278,7 +278,7 @@ void accessor_bufr_data_element_set_subsetNumber(grib_accessor *a, long subsetNu
void accessor_bufr_data_element_set_compressedData(grib_accessor *a, int compressedData);
void accessor_bufr_data_element_set_descriptors(grib_accessor *a, bufr_descriptors_array *descriptors);
void accessor_bufr_data_element_set_numericValues(grib_accessor *a, grib_vdarray *numericValues);
void accessor_bufr_data_element_set_stringValues(grib_accessor *a, grib_sarray *stringValues);
void accessor_bufr_data_element_set_stringValues(grib_accessor *a, grib_vsarray *stringValues);
void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor *a, grib_viarray *elementsDescriptorsIndex);
/* grib_accessor_class_bufr_elements_table.c */