added recursive delayed replication (passing 130 tests out of 132)

This commit is contained in:
Enrico Fucile 2014-10-21 09:58:21 +01:00
parent 63a6d347b7
commit ff9d348af2
1 changed files with 50 additions and 20 deletions

View File

@ -568,12 +568,18 @@ static void push_zero_element(grib_accessor_bufr_data_array* self,grib_darray* d
} }
} }
#define MAX_NESTED_REPLICATIONS 8
static int decode_elements(grib_accessor* a) { static int decode_elements(grib_accessor* a) {
int err=0; int err=0;
int associatedFieldWidth=0,localDescriptorWidth=0; int associatedFieldWidth=0,localDescriptorWidth=0;
int nn=0; long inr,innr,ir;
int numberOfElementsToRepeat=0,numberOfRepetitions=0; long n[MAX_NESTED_REPLICATIONS]={0,};
int startRepetition=0; long nn[MAX_NESTED_REPLICATIONS]={0,};
long numberOfElementsToRepeat[MAX_NESTED_REPLICATIONS]={0,};
long numberOfRepetitions[MAX_NESTED_REPLICATIONS]={0,};
long startRepetition[MAX_NESTED_REPLICATIONS]={0,};
long numberOfNestedRepetions=0;
unsigned char* data=0; unsigned char* data=0;
int i; int i;
grib_iarray* elementsDescriptorsIndex=0; grib_iarray* elementsDescriptorsIndex=0;
@ -636,8 +642,11 @@ static int decode_elements(grib_accessor* a) {
break; break;
case 1: case 1:
/* Delayed replication */ /* Delayed replication */
numberOfElementsToRepeat=descriptors[i]->X; inr=numberOfNestedRepetions;
nn=numberOfElementsToRepeat; numberOfNestedRepetions++;
Assert(numberOfNestedRepetions<=MAX_NESTED_REPLICATIONS);
numberOfElementsToRepeat[inr]=descriptors[i]->X;
n[inr]=numberOfElementsToRepeat[inr];
i++; i++;
if (self->compressedData) { if (self->compressedData) {
localReference=grib_decode_unsigned_long(data,&pos,descriptors[i]->width)+descriptors[i]->reference; localReference=grib_decode_unsigned_long(data,&pos,descriptors[i]->width)+descriptors[i]->reference;
@ -646,23 +655,24 @@ static int decode_elements(grib_accessor* a) {
/* delayed replication number is not constant. NOT IMPLEMENTED */ /* delayed replication number is not constant. NOT IMPLEMENTED */
Assert(0); Assert(0);
} else { } else {
numberOfRepetitions=localReference*descriptors[i]->factor; numberOfRepetitions[inr]=localReference*descriptors[i]->factor;
startRepetition=i; startRepetition[inr]=i;
} }
} else { } else {
numberOfRepetitions=grib_decode_unsigned_long(data,&pos,descriptors[i]->width)+ numberOfRepetitions[inr]=grib_decode_unsigned_long(data,&pos,descriptors[i]->width)+
descriptors[i]->reference*descriptors[i]->factor; descriptors[i]->reference*descriptors[i]->factor;
startRepetition=i; startRepetition[inr]=i;
} }
nn[inr]=numberOfRepetitions[inr];
grib_iarray_push(elementsDescriptorsIndex,i); grib_iarray_push(elementsDescriptorsIndex,i);
if (self->compressedData) { if (self->compressedData) {
dval=grib_darray_new(c,1,100); dval=grib_darray_new(c,1,100);
grib_darray_push(c,dval,(double)numberOfRepetitions); grib_darray_push(c,dval,(double)numberOfRepetitions[inr]);
grib_vdarray_push(c,self->numericValues,dval); grib_vdarray_push(c,self->numericValues,dval);
} else { } else {
grib_darray_push(c,dval,(double)numberOfRepetitions); grib_darray_push(c,dval,(double)numberOfRepetitions[inr]);
} }
if (numberOfRepetitions==0) i+=numberOfElementsToRepeat; if (numberOfRepetitions[inr]==0) i+=numberOfElementsToRepeat[inr];
continue; continue;
case 2: case 2:
/* Operator */ /* Operator */
@ -743,15 +753,35 @@ static int decode_elements(grib_accessor* a) {
} }
/* delayed repetition check */ /* delayed repetition check */
if (numberOfRepetitions) { innr=numberOfNestedRepetions-1;
if (nn>1) { for (ir=innr;ir>=0;ir--) {
nn--; if (nn[ir]) {
} else { if (n[ir]>1) {
nn=numberOfElementsToRepeat; n[ir]--;
numberOfRepetitions--; break;
if (numberOfRepetitions>0) i=startRepetition; } else {
n[ir]=numberOfElementsToRepeat[ir];
nn[ir]--;
if (nn[ir]) {
i=startRepetition[ir];
break;
} else {
if (ir>0) {
n[ir-1]-=numberOfElementsToRepeat[ir]+1;
i=startRepetition[ir-1];
} else {
i=startRepetition[ir]+numberOfElementsToRepeat[ir];
}
numberOfNestedRepetions--;
}
}
} else {
if (ir==0) {
i=startRepetition[ir]+numberOfElementsToRepeat[ir]+1;
numberOfNestedRepetions=0;
}
}
} }
}
} }
grib_viarray_push(c,self->elementsDescriptorsIndex,elementsDescriptorsIndex); grib_viarray_push(c,self->elementsDescriptorsIndex,elementsDescriptorsIndex);