This commit is contained in:
Enrico Fucile 2015-10-28 16:07:41 +00:00
parent bd4385fce0
commit 384164a9ca
5 changed files with 59 additions and 27 deletions

View File

@ -32,7 +32,9 @@ int main(int argc,char* argv[])
long numberOfSubsets=0; long numberOfSubsets=0;
long longVal; long longVal;
/*double doubleVal;*/ double doubleVal;
size_t stringLen;
char stringVal[100]={0,};
int i,err=0; int i,err=0;
int cnt=0; int cnt=0;
char* infile = "../../data/bufr/synop_multi_subset.bufr"; char* infile = "../../data/bufr/synop_multi_subset.bufr";
@ -67,13 +69,22 @@ int main(int argc,char* argv[])
sprintf(key,"/subsetNumber=%d/blockNumber",i); sprintf(key,"/subsetNumber=%d/blockNumber",i);
printf(" subsetNumber=%ld",i); printf(" subsetNumber=%ld",i);
/* read and print some data values */ /* read and print some data values */
CODES_CHECK(codes_get_long(h,key,&longVal),0); CODES_CHECK(codes_get_long(h,key,&longVal),0);
printf(" blockNumber=%ld",longVal); printf(" blockNumber=%ld",longVal);
sprintf(key,"/subsetNumber=%d/stationNumber",i); sprintf(key,"/subsetNumber=%d/stationNumber",i);
CODES_CHECK(codes_get_long(h,key,&longVal),0); CODES_CHECK(codes_get_long(h,key,&longVal),0);
printf(" stationNumber=%ld\n",longVal); printf(" stationNumber=%ld",longVal);
sprintf(key,"/subsetNumber=%d/stationOrSiteName",i);
stringLen=100;
CODES_CHECK(codes_get_string(h,key,stringVal,&stringLen),0);
printf(" stationOrSiteName=\"%s\"",stringVal);
sprintf(key,"/subsetNumber=%d/airTemperature",i);
CODES_CHECK(codes_get_double(h,key,&doubleVal),0);
printf(" airTemperature=%g\n",doubleVal);
} }

View File

@ -22,18 +22,18 @@ fRef=${label}.ref
cat > $fRef <<EOF cat > $fRef <<EOF
message: 0 message: 0
numberOfSubsets: 12 numberOfSubsets: 12
subsetNumber=1 blockNumber=1 stationNumber=27 subsetNumber=1 blockNumber=1 stationNumber=27 stationOrSiteName="TROMSO-HOLT" airTemperature=276.45
subsetNumber=2 blockNumber=1 stationNumber=84 subsetNumber=2 blockNumber=1 stationNumber=84 stationOrSiteName="PASVIK" airTemperature=266.55
subsetNumber=3 blockNumber=1 stationNumber=270 subsetNumber=3 blockNumber=1 stationNumber=270 stationOrSiteName="KVITHAMAR" airTemperature=275.25
subsetNumber=4 blockNumber=1 stationNumber=272 subsetNumber=4 blockNumber=1 stationNumber=272 stationOrSiteName="FROSTA" airTemperature=276.25
subsetNumber=5 blockNumber=1 stationNumber=308 subsetNumber=5 blockNumber=1 stationNumber=308 stationOrSiteName="FURUNESET" airTemperature=276.85
subsetNumber=6 blockNumber=1 stationNumber=371 subsetNumber=6 blockNumber=1 stationNumber=371 stationOrSiteName="LOKEN I VOLBU" airTemperature=265.35
subsetNumber=7 blockNumber=1 stationNumber=381 subsetNumber=7 blockNumber=1 stationNumber=381 stationOrSiteName="APELSVOLL" airTemperature=270.15
subsetNumber=8 blockNumber=1 stationNumber=382 subsetNumber=8 blockNumber=1 stationNumber=382 stationOrSiteName="KISE" airTemperature=270.45
subsetNumber=9 blockNumber=1 stationNumber=387 subsetNumber=9 blockNumber=1 stationNumber=387 stationOrSiteName="FAVANG" airTemperature=267.55
subsetNumber=10 blockNumber=1 stationNumber=413 subsetNumber=10 blockNumber=1 stationNumber=413 stationOrSiteName="SAERHEIM" airTemperature=277.45
subsetNumber=11 blockNumber=1 stationNumber=464 subsetNumber=11 blockNumber=1 stationNumber=464 stationOrSiteName="LANDVIK" airTemperature=275.95
subsetNumber=12 blockNumber=1 stationNumber=485 subsetNumber=12 blockNumber=1 stationNumber=485 stationOrSiteName="SANDE-GALLEBERG" airTemperature=275.45
EOF EOF
#We check "synop_multi_subset.bufr". The path is #We check "synop_multi_subset.bufr". The path is

View File

@ -870,7 +870,7 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
err=encode_string_array(c,buff,pos,i,self,self->stringValues->v[idx]); err=encode_string_array(c,buff,pos,i,self,self->stringValues->v[idx]);
} else { } else {
idx=((int)self->numericValues->v[0]->v[elementIndex]/1000-1)/self->numberOfSubsets; 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[subsetIndex]); err=encode_string_value(c,buff,pos,i,self,self->stringValues->v[subsetIndex]->v[idx]);
} }
} else { } else {
/* numeric or codetable or flagtable */ /* numeric or codetable or flagtable */

View File

@ -335,7 +335,7 @@ static int unpack_string (grib_accessor* a, char* val, size_t *len)
str=grib_context_strdup(c,self->stringValues->v[idx]->v[0]); str=grib_context_strdup(c,self->stringValues->v[idx]->v[0]);
} else { } else {
idx=((int)self->numericValues->v[self->subsetNumber]->v[self->index]/1000-1)/self->numberOfSubsets; 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]); str=grib_context_strdup(c,self->stringValues->v[self->subsetNumber]->v[idx]);
} }
if (str==0 || strlen(str)==0) { if (str==0 || strlen(str)==0) {

View File

@ -828,13 +828,22 @@ int grib_get_double_internal(grib_handle* h, const char* name, double* val)
int grib_get_double(grib_handle* h, const char* name, double* val) int grib_get_double(grib_handle* h, const char* name, double* val)
{ {
grib_accessor* act = grib_find_accessor(h, name); size_t length = 1;
size_t l = 1; grib_accessor* a = NULL;
grib_accessors_list* al=NULL;
int ret=0;
if(act) if (name[0] == '/' ) {
return grib_unpack_double(act, val, &l); al=grib_find_accessors_list(h,name);
if (!al) return GRIB_NOT_FOUND;
return GRIB_NOT_FOUND; ret=grib_unpack_double(al->accessor, val , &length);
grib_context_free(h->context,al);
} else {
a=grib_find_accessor(h, name);
if(!a) return GRIB_NOT_FOUND;
ret=grib_unpack_double(a, val , &length);
}
return ret;
} }
int grib_get_double_element_internal(grib_handle* h, const char* name, int i,double* val) int grib_get_double_element_internal(grib_handle* h, const char* name, int i,double* val)
@ -924,10 +933,22 @@ int grib_get_string_internal(grib_handle* h, const char* name, char* val, size_t
int grib_get_string(grib_handle* h, const char* name, char* val, size_t *length) int grib_get_string(grib_handle* h, const char* name, char* val, size_t *length)
{ {
grib_accessor* act = grib_find_accessor(h, name); size_t len = 1;
if(act) grib_accessor* a = NULL;
return grib_unpack_string(act, val, length); grib_accessors_list* al=NULL;
return GRIB_NOT_FOUND; int ret=0;
if (name[0] == '/' ) {
al=grib_find_accessors_list(h,name);
if (!al) return GRIB_NOT_FOUND;
ret=grib_unpack_string(al->accessor, val, length);
grib_context_free(h->context,al);
return ret;
} else {
a=grib_find_accessor(h, name);
if(!a) return GRIB_NOT_FOUND;
return grib_unpack_string(a, val , length);
}
} }