ECC-616: BUFR operator 203YYY: implement encoding (Part 1)

This commit is contained in:
Shahram Najm 2018-04-06 13:52:39 +01:00
parent 9927ba9ce9
commit 5f7c5fca36
12 changed files with 48 additions and 0 deletions

View File

@ -23,6 +23,9 @@ transient inputShortDelayedDescriptorReplicationFactor={-1} : hidden;
transient inputDataPresentIndicator={-1} : hidden;
# For operator 203YYY: Table B override
transient overriddenReferenceValues={0} : hidden;
transient extractSubset=-1 : hidden;
transient extractSubsetList={-1} : hidden;
transient extractSubsetIntervalStart=-1 : hidden;

View File

@ -310,6 +310,26 @@ static void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array
}
self->tableb_override=NULL;
}
/* Operator 203YYY: Copy contents of linked list to the transient array key */
static int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array *self)
{
int err = GRIB_SUCCESS;
size_t size = 0;
long* refVals = NULL;
grib_iarray* refValArray = grib_iarray_new(h->context, 10, 10);
bufr_tableb_override* p = self->tableb_override;
while (p) {
grib_iarray_push(refValArray, p->new_ref_val);
p = p->next;
}
size = grib_iarray_used_size(refValArray);
if (size > 0) {
refVals = grib_iarray_get_array(refValArray);
err=grib_set_long_array(h, "overriddenReferenceValues", refVals, size);
}
grib_iarray_delete(refValArray);
return err;
}
/*
static void tableB_override_dump(grib_accessor_bufr_data_array *self)
{
@ -2519,6 +2539,11 @@ static int process_elements(grib_accessor* a,int flag,long onlySubset,long start
grib_context_log(c, GRIB_LOG_DEBUG,"Operator 203YYY: Y=255, definition of new reference values is concluded");
self->change_ref_value_operand = 255;
/*if (c->debug) tableB_override_dump(self);*/
if (iss == 0) {
/*Write out the contents of the TableB overridden reference values to the transient array key*/
err = tableB_override_set_key(h, self);
if (err) return err;
}
} else if (descriptors[i]->Y == 0) {
grib_context_log(c, GRIB_LOG_DEBUG,"Operator 203YYY: Y=0, clearing override of table B");
tableB_override_clear(c, self);

View File

@ -618,6 +618,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -508,6 +508,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
{
size_t size=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
fprintf(f,"print \"%s=[%s]\";\n", print_key, print_key);
}
@ -528,6 +529,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -535,6 +535,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
{
size_t size=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
fprintf(f," call codes_get(ibufr, '%s', iValues)\n",print_key);
}
@ -554,6 +555,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -547,6 +547,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
{
size_t size=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
fprintf(f," iVals = codes_get_array(ibufr, '%s')\n",print_key);
}
@ -566,6 +567,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -675,6 +675,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
int cols=9,icount=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
fprintf(f," free(ivalues); ivalues = NULL;\n");
fprintf(f," ivalues = (long*)malloc(%lu*sizeof(long));\n", (unsigned long)size);
@ -710,6 +711,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -640,6 +640,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
int cols=9,icount=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
val=(long*)grib_context_malloc_clear(h->context,sizeof(long)*size);
grib_get_long_array(h,key,val,&size);
@ -671,6 +672,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -734,6 +734,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
int cols=9,icount=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
fprintf(f," if(allocated(ivalues)) deallocate(ivalues)\n");
fprintf(f," allocate(ivalues(%lu))\n", (unsigned long)size);
@ -769,6 +770,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -668,6 +668,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
int cols=9,icount=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
fprintf(f," ivalues = (");
@ -701,6 +702,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -658,6 +658,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
int cols=9,icount=0;
if (grib_get_size(h,key,&size)==GRIB_NOT_FOUND) return;
if (size==0) return;
val=(long*)grib_context_malloc_clear(h->context,sizeof(long)*size);
grib_get_long_array(h,key,val,&size);
@ -689,6 +690,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso
_dump_long_array(h,self->dumper.out,"delayedDescriptorReplicationFactor","inputDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"shortDelayedDescriptorReplicationFactor","inputShortDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"extendedDelayedDescriptorReplicationFactor","inputExtendedDelayedDescriptorReplicationFactor");
_dump_long_array(h,self->dumper.out,"overriddenReferenceValues","overriddenReferenceValues");
grib_dump_accessors_block(d,block);
depth-=2;
} else if (!grib_inline_strcmp(a->name,"groupNumber")) {

View File

@ -35,6 +35,7 @@ cat > $tempRules <<EOF
set unpack=1;
print "h1=[heightOfStationGroundAboveMeanSeaLevel]";
print "h2=[heightOfBarometerAboveMeanSeaLevel]";
print "rv=[overriddenReferenceValues]";
EOF
${tools_dir}/codes_bufr_filter $tempRules $input > $tempOut
@ -62,8 +63,10 @@ h2=11 -1e+100 -1e+100 -1e+100 -1e+100 -1e+100 -1e+100 -1e+100
-1e+100 -1e+100 -1e+100 -1e+100 -1e+100 -387 -1e+100 -1e+100
-1e+100 -1e+100 -1e+100 -1e+100 -1e+100 938 -1e+100 -1e+100
-1e+100 -1e+100
rv=-5000 -5000
EOF
diff $tempRef $tempOut
rm -f $tempRules $tempRef $tempOut