mirror of https://github.com/ecmwf/eccodes.git
ECC-856: BUFR - length of string attribute not correct if used with subset section
This commit is contained in:
parent
8d725958aa
commit
0cbfa864a5
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "eccodes.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main(int argc,char* argv[])
|
||||
{
|
||||
|
@ -65,22 +66,27 @@ int main(int argc,char* argv[])
|
|||
|
||||
printf(" subsetNumber=%d",i);
|
||||
/* 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);
|
||||
|
||||
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",longVal);
|
||||
|
||||
sprintf(key,"/subsetNumber=%d/stationOrSiteName->units",i);
|
||||
CODES_CHECK(codes_get_length(h,key,&stringLen), 0);
|
||||
assert(stringLen == 10); /* should be "CCITT IA5" */
|
||||
|
||||
sprintf(key,"/subsetNumber=%d/stationOrSiteName",i);
|
||||
stringLen=100;
|
||||
CODES_CHECK(codes_get_string(h,key,stringVal,&stringLen),0);
|
||||
CODES_CHECK(codes_get_length(h,key,&stringLen), 0);
|
||||
CODES_CHECK(codes_get_string(h,key,stringVal,&stringLen), 0);
|
||||
assert(stringLen > 0 && stringLen < 17);
|
||||
printf(" stationOrSiteName=\"%s\"",stringVal);
|
||||
|
||||
sprintf(key,"/subsetNumber=%d/airTemperature",i);
|
||||
CODES_CHECK(codes_get_double(h,key,&doubleVal),0);
|
||||
printf(" airTemperature=%g\n",doubleVal);
|
||||
|
||||
assert(doubleVal > 265 && doubleVal < 278);
|
||||
}
|
||||
|
||||
/* delete handle */
|
||||
|
|
|
@ -1157,10 +1157,21 @@ int _grib_get_string_length(grib_accessor* a, size_t* size)
|
|||
|
||||
int grib_get_string_length(grib_handle* h, const char* name,size_t* size)
|
||||
{
|
||||
grib_accessor* a = grib_find_accessor(h, name);
|
||||
if(!a) return GRIB_NOT_FOUND;
|
||||
grib_accessor* a = NULL;
|
||||
grib_accessors_list* al=NULL;
|
||||
int ret=0;
|
||||
|
||||
return _grib_get_string_length(a,size);
|
||||
if (name[0] == '/' ) {
|
||||
al=grib_find_accessors_list(h,name);
|
||||
if (!al) return GRIB_NOT_FOUND;
|
||||
ret=_grib_get_string_length(al->accessor,size);
|
||||
grib_context_free(h->context,al);
|
||||
return ret;
|
||||
} else {
|
||||
a = grib_find_accessor(h, name);
|
||||
if(!a) return GRIB_NOT_FOUND;
|
||||
return _grib_get_string_length(a,size);
|
||||
}
|
||||
}
|
||||
|
||||
int _grib_get_size(grib_handle* h, grib_accessor* a,size_t* size)
|
||||
|
|
Loading…
Reference in New Issue