fix for flat format

This commit is contained in:
Enrico Fucile 2015-02-25 11:50:02 +00:00
parent b23406949e
commit d0e609065c
5 changed files with 36 additions and 58 deletions

View File

@ -53,6 +53,7 @@
MEMBERS = int bitmapStart MEMBERS = int bitmapStart
MEMBERS = int bitmapCurrent MEMBERS = int bitmapCurrent
MEMBERS = grib_accessors_list* dataAccessors MEMBERS = grib_accessors_list* dataAccessors
MEMBERS = int unpackMode
END_CLASS_DEF END_CLASS_DEF
@ -115,6 +116,7 @@ typedef struct grib_accessor_bufr_data_array {
int bitmapStart; int bitmapStart;
int bitmapCurrent; int bitmapCurrent;
grib_accessors_list* dataAccessors; grib_accessors_list* dataAccessors;
int unpackMode;
} grib_accessor_bufr_data_array; } grib_accessor_bufr_data_array;
extern grib_accessor_class* grib_accessor_class_gen; extern grib_accessor_class* grib_accessor_class_gen;
@ -246,6 +248,7 @@ static void init(grib_accessor* a,const long v, grib_arguments* params)
a->parent->h->unpacked=0; a->parent->h->unpacked=0;
a->length = init_length(a); a->length = init_length(a);
self->unpackMode=CODES_BUFR_UNPACK_STRUCTURE;
/* Assert(a->length>=0); */ /* Assert(a->length>=0); */
} }
@ -307,6 +310,11 @@ grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a
return self->dataAccessors; return self->dataAccessors;
} }
void accessor_bufr_data_array_set_unpackMode(grib_accessor* a,int unpackMode) {
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
self->unpackMode=unpackMode;
}
static int get_descriptors(grib_accessor* a) { static int get_descriptors(grib_accessor* a) {
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
int ret=0,i,numberOfDescriptors; int ret=0,i,numberOfDescriptors;
@ -827,7 +835,8 @@ static int create_keys(grib_accessor* a) {
descriptor=self->expanded->v[idx]; descriptor=self->expanded->v[idx];
elementFromBitmap=NULL; elementFromBitmap=NULL;
if (descriptor->F==0 && IS_QUALIFIER(descriptor->X)) { if (descriptor->F==0 && IS_QUALIFIER(descriptor->X)
&& self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE) {
int sidx=significanceQualifierIndex(descriptor->X,descriptor->Y); int sidx=significanceQualifierIndex(descriptor->X,descriptor->Y);
groupNumber++; groupNumber++;
@ -922,7 +931,8 @@ static int create_keys(grib_accessor* a) {
} }
elementAccessor=create_accessor_from_descriptor(a,section,ide,iss,dump); elementAccessor=create_accessor_from_descriptor(a,section,ide,iss,dump);
if (elementFromBitmap) grib_accessor_add_attribute(elementFromBitmap,elementAccessor); if (elementFromBitmap && self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE)
grib_accessor_add_attribute(elementFromBitmap,elementAccessor);
else if (elementAccessor) { else if (elementAccessor) {
grib_push_accessor(elementAccessor,section->block); grib_push_accessor(elementAccessor,section->block);
grib_accessors_list_push(self->dataAccessors,elementAccessor); grib_accessors_list_push(self->dataAccessors,elementAccessor);

View File

@ -136,47 +136,6 @@ static void init_class(grib_accessor_class* c)
/* END_CLASS_IMP */ /* END_CLASS_IMP */
/*TODO move all those typedef in a unique .h file*/
typedef struct grib_accessor_bufr_compressed_data {
grib_accessor att;
/* Members defined in gen */
/* Members defined in bufr_compressed_data */
const char* offsetSection4Name;
const char* offsetBeforeDataName;
const char* offsetEndSection4Name;
const char* section4LengthName;
const char* numberOfSubsetsName;
const char* subsetNumberName;
const char* expandedDescriptorsName;
const char* elementsName;
const char* abbreviationName;
const char* typeName;
const char* nameName;
const char* unitName;
const char* referenceName;
const char* scaleName;
const char* widthName;
const char* codeFlags;
long* code;
long* expandedDescriptors;
char** abbreviation;
int* index;
grib_trie* abbreviationTrie;
char** type;
char** names;
char** units;
long* reference;
long* scale;
long* width;
long numberOfElements;
long numberOfSubsets;
size_t numberOfDescriptors;
double* values;
int* is_constant;
double* constant;
int dirty;
} grib_accessor_bufr_compressed_data;
static void init(grib_accessor* a, const long len, grib_arguments* params) { static void init(grib_accessor* a, const long len, grib_arguments* params) {
char* key; char* key;
@ -241,9 +200,14 @@ static int get_native_type(grib_accessor* a){
static int pack_long (grib_accessor* a, const long* val, size_t *len) static int pack_long (grib_accessor* a, const long* val, size_t *len)
{ {
int unpackMode=CODES_BUFR_UNPACK_STRUCTURE;
grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a;
grib_accessor* data=(grib_accessor*)self->data_accessor; grib_accessor* data=(grib_accessor*)self->data_accessor;
if (*val==2) unpackMode=CODES_BUFR_UNPACK_FLAT;
accessor_bufr_data_array_set_unpackMode(data,unpackMode);
return grib_unpack_double(data,0,0); return grib_unpack_double(data,0,0);
} }

View File

@ -199,6 +199,9 @@ extern "C" {
#define CODES_GRIB 1 #define CODES_GRIB 1
#define CODES_BUFR 2 #define CODES_BUFR 2
#define CODES_BUFR_UNPACK_STRUCTURE 0
#define CODES_BUFR_UNPACK_FLAT 1
#define MAX_SMART_TABLE_COLUMNS 20 #define MAX_SMART_TABLE_COLUMNS 20
#define MAX_CODETABLE_ENTRIES 65536 #define MAX_CODETABLE_ENTRIES 65536

View File

@ -263,6 +263,7 @@ size_t grib_viarray_used_size(grib_viarray *v);
/* grib_accessor_class_bufr_data_array.c */ /* grib_accessor_class_bufr_data_array.c */
grib_accessors_list *accessor_bufr_data_array_get_dataAccessors(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);
/* grib_accessor_class_bufr_data_element.c */ /* grib_accessor_class_bufr_data_element.c */
void accessor_bufr_data_element_set_index(grib_accessor *a, long index); void accessor_bufr_data_element_set_index(grib_accessor *a, long index);

View File

@ -161,9 +161,23 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
grib_set_flag(h,options->print_keys[i].name,GRIB_ACCESSOR_FLAG_DUMP); grib_set_flag(h,options->print_keys[i].name,GRIB_ACCESSOR_FLAG_DUMP);
if (json) { if (json) {
grib_set_long(h,"unpack",1);
if (options->handle_count>1) fprintf(stdout,",\n"); if (options->handle_count>1) fprintf(stdout,",\n");
/* fprintf(stdout,"\"message%d\" : ",options->handle_count); */ /* fprintf(stdout,"\"message%d\" : ",options->handle_count); */
switch (json_option[0]) {
case 'f':
grib_set_long(h,"unpack",2);
a=grib_find_accessor(h,"numericValues");
al=accessor_bufr_data_array_get_dataAccessors(a);
grib_dump_bufr_flat(al,h,stdout,options->dump_mode,options->dump_flags,0);
break;
case 's':
grib_set_long(h,"unpack",1);
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
break;
default :
printf("unknown json option %s\n",json_option);
exit(1);
}
} else { } else {
sprintf(tmp,"MESSAGE %d ( length=%ld )",options->handle_count,length); sprintf(tmp,"MESSAGE %d ( length=%ld )",options->handle_count,length);
if (!grib_options_on("C")) if (!grib_options_on("C"))
@ -174,20 +188,6 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
} }
} }
switch (json_option[0]) {
case 'f':
a=grib_find_accessor(h,"numericValues");
al=accessor_bufr_data_array_get_dataAccessors(a);
grib_dump_bufr_flat(al,h,stdout,options->dump_mode,options->dump_flags,0);
break;
case 's':
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
break;
default :
printf("unknown json option %s\n",json_option);
exit(1);
}
if (!strcmp(options->dump_mode,"default")) if (!strcmp(options->dump_mode,"default"))
printf("}\n"); printf("}\n");
return 0; return 0;