ECC-218 part 1

This commit is contained in:
Enrico Fucile 2016-02-03 16:31:23 +00:00
parent 5d4726e82d
commit 10f245d4f4
14 changed files with 355 additions and 110 deletions

View File

@ -6,16 +6,16 @@ alias ls.rdbSubtype=rdbSubtype;
byte[13] keyData : hidden;
meta localYear bits(keyData,0,12) : long_type ;
meta localMonth bits(keyData,12,4) : long_type;
meta localDay bits(keyData,16,6) : long_type;
meta localHour bits(keyData,22,5) : long_type;
meta localMinute bits(keyData,27,6) : long_type;
meta localSecond bits(keyData,33,6) : long_type;
meta spare bits(keyData,39,1); # 40 bits = 10 bytes
meta localYear bits(keyData,0,12) : long_type,no_copy ;
meta localMonth bits(keyData,12,4) : long_type,no_copy;
meta localDay bits(keyData,16,6) : long_type,no_copy;
meta localHour bits(keyData,22,5) : long_type,no_copy;
meta localMinute bits(keyData,27,6) : long_type,no_copy;
meta localSecond bits(keyData,33,6) : long_type,no_copy;
meta spare bits(keyData,39,1) : no_copy; # 40 bits = 10 bytes
meta ls.typicalDate sprintf("%.4d%.2d%.2d",localYear,localMonth,localDay) : dump;
meta ls.typicalTime sprintf("%.2d%.2d%.2d",localHour,localMinute,localSecond) :dump;
meta ls.typicalDate sprintf("%.4d%.2d%.2d",localYear,localMonth,localDay) : dump,no_copy;
meta ls.typicalTime sprintf("%.2d%.2d%.2d",localHour,localMinute,localSecond) :dump,no_copy;
# isSatellite and other stuff moved to section 3
ascii[8] keyMore : hidden;
@ -28,33 +28,33 @@ alias rdb.messageLength=messageLength;
byte[3] rdbtime;
alias ls.rdbtimeYear = localYear;
alias ls.rdbtimeMonth = localMonth;
meta rdbtimeDay bits(rdbtime,0,6) : dump,long_type;
meta rdbtimeHour bits(rdbtime,6,5) : dump,long_type;
meta rdbtimeMinute bits(rdbtime,11,6) : dump,long_type;
meta rdbtimeSecond bits(rdbtime,17,6) : dump,long_type;
meta rdbtimeDay bits(rdbtime,0,6) : dump,long_type,no_copy;
meta rdbtimeHour bits(rdbtime,6,5) : dump,long_type,no_copy;
meta rdbtimeMinute bits(rdbtime,11,6) : dump,long_type,no_copy;
meta rdbtimeSecond bits(rdbtime,17,6) : dump,long_type,no_copy;
byte[3] rectime;
meta rectimeDay bits(rectime,0,6) : dump,long_type;
meta rectimeHour bits(rectime,6,5) : dump,long_type;
meta rectimeMinute bits(rectime,11,6) : dump,long_type;
meta rectimeSecond bits(rectime,17,6) : dump,long_type;
meta rectimeDay bits(rectime,0,6) : dump,long_type,no_copy;
meta rectimeHour bits(rectime,6,5) : dump,long_type,no_copy;
meta rectimeMinute bits(rectime,11,6) : dump,long_type,no_copy;
meta rectimeSecond bits(rectime,17,6) : dump,long_type,no_copy;
byte[1] corr1Data;
meta correction1 bits(corr1Data,0,6) : dump,long_type;
meta correction1Part bits(corr1Data,6,1) : dump,long_type;
meta correction1 bits(corr1Data,0,6) : dump,long_type,no_copy;
meta correction1Part bits(corr1Data,6,1) : dump,long_type,no_copy;
byte[1] corr2Data;
meta correction2 bits(corr2Data,0,6) : dump,long_type;
meta correction2Part bits(corr2Data,6,1) : dump,long_type;
meta correction2 bits(corr2Data,0,6) : dump,long_type,no_copy;
meta correction2Part bits(corr2Data,6,1) : dump,long_type,no_copy;
byte[1] corr3Data;
meta correction3 bits(corr3Data,0,6) : dump,long_type;
meta correction3Part bits(corr3Data,6,1) : dump,long_type;
meta correction3 bits(corr3Data,0,6) : dump,long_type,no_copy;
meta correction3Part bits(corr3Data,6,1) : dump,long_type,no_copy;
byte[1] corr4Data;
meta correction4 bits(corr4Data,0,6) : dump,long_type;
meta correction4Part bits(corr4Data,6,1) : dump,long_type;
meta correction4 bits(corr4Data,0,6) : dump,long_type,no_copy;
meta correction4Part bits(corr4Data,6,1) : dump,long_type,no_copy;
unsigned[1] qualityControl : dump,long_type;
alias qualityControl=qualityControl;
unsigned[3] spare;
unsigned[3] spare1;

View File

@ -8,7 +8,7 @@
#
section_length[3] section2Length ;
unsigned[1] reserved = 0;
unsigned[1] reservedSection2 = 0;
if(bufrHeaderCentre == 98) {
if (section2Length==52 or new() ) {
template rdb_key "bufr/rdb_key.def";

View File

@ -23,23 +23,22 @@ transient tableNumber=0;
#codetable[4] codeTablesMaster '[tablesMasterDir]/codetables/[tableNumber].table' : string_type,transient;
#codetable[4] codeTablesLocal '[tablesLocalDir]/codetables/[tableNumber].table' : string_type,transient;
hash_array sequences (defaultSequence,"sequence.def",tablesMasterDir,tablesLocalDir): long_type;
hash_array sequences (defaultSequence,"sequence.def",tablesMasterDir,tablesLocalDir): long_type,no_copy;
#smart_table codeFlags ("codeFlag.def",tablesMasterDir,tablesLocalDir,...);
position offsetSection3;
section_length[3] section3Length ;
unsigned[1] reserved = 0;
unsigned[1] reservedSection3 = 0;
unsigned[2] numberOfSubsets : dump;
alias ls.numberOfSubsets=numberOfSubsets;
if (section2Present && bufrHeaderCentre==98 && section2Length==52) {
concept isSatelliteType(zero) {
1 = {rdbType = 2; }
1 = {rdbType = 3; }
1 = {rdbType = 8; }
1 = {rdbType = 12; }
}
if ( rdbType == 2 || rdbType == 3 || rdbType == 8 || rdbType == 12 ) {
transient isSatelliteType=1;
} else {
transient isSatelliteType=0;
}
if (isSatelliteType || numberOfSubsets>1) {
constant isSatellite=1;
} else {
@ -47,60 +46,64 @@ if (section2Present && bufrHeaderCentre==98 && section2Length==52) {
}
alias rdb.isSatellite=isSatellite;
if (isSatellite) {
meta localLongitude1 bits(keyData,40,26,-18000000,100000) : dump;
meta localLatitude1 bits(keyData,72,25,-9000000,100000) : dump;
meta localLongitude2 bits(keyMore,0,26,-18000000,100000) : dump;
meta localLatitude2 bits(keyMore,32,25,-9000000,100000) : dump;
meta localLongitude1 bits(keyData,40,26,-18000000,100000) : dump,no_copy;
meta localLatitude1 bits(keyData,72,25,-9000000,100000) : dump,no_copy;
meta localLongitude2 bits(keyMore,0,26,-18000000,100000) : dump,no_copy;
meta localLatitude2 bits(keyMore,32,25,-9000000,100000) : dump,no_copy;
if (numberOfSubsets>255 ||
( rdbSubtype>=121 && rdbSubtype <=130 ) ||
rdbSubtype==31) {
meta ls.numberOfObservations bits(keySat,0,16) : dump,long_type;
meta ls.satelliteID bits(keySat,16,16) : dump,long_type;
meta ls.numberOfObservations bits(keySat,0,16) : dump,long_type,no_copy;
meta ls.satelliteID bits(keySat,16,16) : dump,long_type,no_copy;
} else {
meta ls.numberOfObservations bits(keySat,0,8) : dump,long_type;
meta ls.satelliteID bits(keySat,8,16) : dump,long_type;
meta ls.numberOfObservations bits(keySat,0,8) : dump,long_type,no_copy;
meta ls.satelliteID bits(keySat,8,16) : dump,long_type,no_copy;
}
} else {
meta ls.localLatitude bits(keyData,72,25,-9000000,100000) : dump;
meta ls.localLongitude bits(keyData,40,26,-18000000,100000) : dump;
alias ls.ident=keyMore : dump,string_type;
meta ls.localLatitude bits(keyData,72,25,-9000000,100000) : dump,no_copy;
meta ls.localLongitude bits(keyData,40,26,-18000000,100000) : dump,no_copy;
alias ls.ident=keyMore : dump,string_type,no_copy;
}
}
flags[1] section3Flags 'bufr/section3_flags.table';
flagbit observedData(section3Flags,7) : dump;
flagbit compressedData(section3Flags,6) : dump;
flagbit observedData(section3Flags,7) : dump,no_copy;
flagbit compressedData(section3Flags,6) : dump,no_copy;
position offsetDescriptors;
#meta unexpandedDescriptorsEncoded raw(section3Length - 7,totalLength,section3Length) : hidden;
transient createNewData=1;
meta numberOfUnexpandedDescriptors evaluate( (section3Length - 7) / 2 ) ;
meta unexpandedDescriptors unexpanded_descriptors(numberOfUnexpandedDescriptors,createNewData) :dump;
meta numberOfUnexpandedDescriptors evaluate( (section3Length - 7) / 2 ) : no_copy;
#meta unexpandedDescriptors unexpanded_descriptors(unexpandedDescriptorsEncoded,createNewData) :dump,no_copy;
meta unexpandedDescriptors unexpanded_descriptors(numberOfUnexpandedDescriptors,createNewData) :dump,no_copy;
concept BufrTemplate (unknown,"BufrTemplate.def",templatesMasterDir,templatesLocalDir) : no_copy;
meta elementsTable bufr_elements_table("element.table",tablesMasterDir,tablesLocalDir) : hidden;
meta elementsTable bufr_elements_table("element.table",tablesMasterDir,tablesLocalDir) : hidden,no_copy;
meta expandedCodes expanded_descriptors(elementsTable,expandedCodes,0,unexpandedDescriptors,sequences);
meta expandedCodes expanded_descriptors(elementsTable,expandedCodes,0,unexpandedDescriptors,sequences) : no_copy;
alias expandedDescriptors=expandedCodes;
#meta expandedReferences expanded_descriptors(elemetsTable,expandedCodes,2);
#meta expandedWidths expanded_descriptors(elemetsTable,expandedCodes,3);
#meta expandedType expanded_descriptors(elemetsTable,expandedCodes,4);
meta bufrdcExpandedDescriptors bufrdc_expanded_descriptors(expandedCodes);
meta bufrdcExpandedDescriptors bufrdc_expanded_descriptors(expandedCodes) : no_copy;
#smart_table NAME (VALUES,FILE_NAME,MASTER_DIRECTORY,LOCAL_DIRECTORY,WIDTH_OF_CODE_IN_BITS,EXTRA_DIRECTORY,EXTRA_FILE_NAME);
smart_table expandedOriginalCodes (expandedCodes,"element.table",tablesMasterDir,tablesLocalDir,18,rootTablesDir,"operators.table") ;
meta expandedAbbreviations smart_table_column(expandedOriginalCodes,0,1) : string_type;
meta expandedTypes smart_table_column(expandedOriginalCodes,1,0) : string_type;
meta expandedNames smart_table_column(expandedOriginalCodes,2,0) : string_type;
meta expandedUnits smart_table_column(expandedOriginalCodes,3,0) : string_type;
meta expandedOriginalScales smart_table_column(expandedOriginalCodes,4,0) : long_type;
meta expandedOriginalReferences smart_table_column(expandedOriginalCodes,5,0) : long_type;
meta expandedOriginalWidths smart_table_column(expandedOriginalCodes,6,0) : long_type;
meta expandedCrex_units smart_table_column(expandedOriginalCodes,7,0) : long_type;
meta expandedCrex_scales smart_table_column(expandedOriginalCodes,8,0) : long_type;
meta expandedCrex_widths smart_table_column(expandedOriginalCodes,9,0) : long_type;
smart_table expandedOriginalCodes (expandedCodes,"element.table",tablesMasterDir,tablesLocalDir,18,rootTablesDir,"operators.table") :no_copy;
meta expandedAbbreviations smart_table_column(expandedOriginalCodes,0,1) : string_type,no_copy;
meta expandedTypes smart_table_column(expandedOriginalCodes,1,0) : string_type,no_copy;
meta expandedNames smart_table_column(expandedOriginalCodes,2,0) : string_type,no_copy;
meta expandedUnits smart_table_column(expandedOriginalCodes,3,0) : string_type,no_copy;
meta expandedOriginalScales smart_table_column(expandedOriginalCodes,4,0) : long_type,no_copy;
meta expandedOriginalReferences smart_table_column(expandedOriginalCodes,5,0) : long_type,no_copy;
meta expandedOriginalWidths smart_table_column(expandedOriginalCodes,6,0) : long_type,no_copy;
meta expandedCrex_units smart_table_column(expandedOriginalCodes,7,0) : long_type,no_copy;
meta expandedCrex_scales smart_table_column(expandedOriginalCodes,8,0) : long_type,no_copy;
meta expandedCrex_widths smart_table_column(expandedOriginalCodes,9,0) : long_type,no_copy;
position endDescriptors;
section_padding section3Padding;

View File

@ -9,21 +9,18 @@
position offsetSection4;
section_length[3] section4Length ;
unsigned[1] reserved = 0;
unsigned[1] reservedSection4 = 0;
position offsetBeforeData;
meta bufrDataEncoded raw(section4Length - 4,totalLength,section4Length) : hidden;
template dataKeys "bufr/dataKeys.def";
meta numericValues bufr_data_array(offsetSection4,offsetBeforeData,offsetEndSection4,section4Length, numberOfSubsets,expandedCodes,expandedFlags, elementsDescriptorsIndex,compressedData,dataKeys);
meta stringValues bufr_string_values(numericValues);
meta numericValues bufr_data_array(bufrDataEncoded, numberOfSubsets,expandedCodes,expandedFlags, elementsDescriptorsIndex,compressedData,dataKeys) : no_copy;
meta stringValues bufr_string_values(numericValues) : no_copy;
meta unpack unpack_bufr_values(numericValues) ;
meta pack pack_bufr_values(numericValues) ;
#when (changed(unexpandedDescriptors)) {
# resize data section and unpack
# set unpack=3;
#}
meta unpack unpack_bufr_values(numericValues) : no_copy;
meta pack pack_bufr_values(numericValues) : no_copy;
section_padding section4Padding;
position offsetEndSection4;

View File

@ -235,6 +235,7 @@ list( APPEND grib_api_srcs
grib_accessor_class_statistics_spectral.c
grib_accessor_class_unsigned.c
grib_accessor_class_unsigned_bits.c
grib_accessor_class_raw.c
grib_accessor_class_spd.c
grib_accessor_class_sum.c
grib_accessor_class_to_integer.c

View File

@ -261,6 +261,7 @@ libeccodes_la_prototypes= \
grib_accessor_class_statistics_spectral.c \
grib_accessor_class_unsigned.c \
grib_accessor_class_unsigned_bits.c \
grib_accessor_class_raw.c \
grib_accessor_class_spd.c \
grib_accessor_class_sum.c \
grib_accessor_class_to_integer.c \

View File

@ -164,6 +164,7 @@ extern grib_accessor_class* grib_accessor_class_padto;
extern grib_accessor_class* grib_accessor_class_padtoeven;
extern grib_accessor_class* grib_accessor_class_padtomultiple;
extern grib_accessor_class* grib_accessor_class_position;
extern grib_accessor_class* grib_accessor_class_raw;
extern grib_accessor_class* grib_accessor_class_reference_value_error;
extern grib_accessor_class* grib_accessor_class_round;
extern grib_accessor_class* grib_accessor_class_scale;

View File

@ -24,6 +24,7 @@
SUPER = grib_accessor_class_gen
IMPLEMENTS = get_native_type
IMPLEMENTS = unpack_long; pack_long
IMPLEMENTS = unpack_bytes; byte_count
IMPLEMENTS = unpack_double; pack_double
IMPLEMENTS = unpack_string
IMPLEMENTS = init
@ -50,9 +51,11 @@ or edit "accessor.class" and rerun ./make_class.pl
static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val,size_t *len);
static int pack_long(grib_accessor*, const long* val,size_t *len);
static int unpack_bytes (grib_accessor*,unsigned char*, size_t *len);
static int unpack_double(grib_accessor*, double* val,size_t *len);
static int unpack_long(grib_accessor*, long* val,size_t *len);
static int unpack_string (grib_accessor*, char*, size_t *len);
static long byte_count(grib_accessor*);
static void init(grib_accessor*,const long, grib_arguments* );
static void init_class(grib_accessor_class*);
@ -83,7 +86,7 @@ static grib_accessor_class _grib_accessor_class_bits = {
0, /* get length of section */
0, /* get length of string */
0, /* get number of values */
0, /* get number of bytes */
&byte_count, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
@ -98,7 +101,7 @@ static grib_accessor_class _grib_accessor_class_bits = {
0, /* grib_pack array procedures string */
0, /* grib_unpack array procedures string */
0, /* grib_pack procedures bytes */
0, /* grib_unpack procedures bytes */
&unpack_bytes, /* grib_unpack procedures bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
@ -123,7 +126,6 @@ static void init_class(grib_accessor_class* c)
c->next_offset = (*(c->super))->next_offset;
c->string_length = (*(c->super))->string_length;
c->value_count = (*(c->super))->value_count;
c->byte_count = (*(c->super))->byte_count;
c->byte_offset = (*(c->super))->byte_offset;
c->sub_section = (*(c->super))->sub_section;
c->pack_missing = (*(c->super))->pack_missing;
@ -132,7 +134,6 @@ static void init_class(grib_accessor_class* c)
c->pack_string_array = (*(c->super))->pack_string_array;
c->unpack_string_array = (*(c->super))->unpack_string_array;
c->pack_bytes = (*(c->super))->pack_bytes;
c->unpack_bytes = (*(c->super))->unpack_bytes;
c->pack_expression = (*(c->super))->pack_expression;
c->notify_change = (*(c->super))->notify_change;
c->update_size = (*(c->super))->update_size;
@ -323,3 +324,22 @@ static int unpack_string(grib_accessor*a , char* v, size_t *len){
}
return ret;
}
static long byte_count(grib_accessor* a){
grib_context_log(a->context,GRIB_LOG_DEBUG,"byte_count of %s = %ld",a->name,a->length);
return a->length;
}
static int unpack_bytes (grib_accessor* a,unsigned char* buffer, size_t *len) {
if (*len < a->length) {
*len = a->length;
return GRIB_ARRAY_TOO_SMALL;
}
*len = a->length;
memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len);
return GRIB_SUCCESS;
}

View File

@ -22,13 +22,9 @@
IMPLEMENTS = byte_count; value_count
IMPLEMENTS = byte_offset; unpack_double
IMPLEMENTS = get_native_type
IMPLEMENTS = update_size
IMPLEMENTS = compare
IMPLEMENTS = pack_long; unpack_double; pack_double
MEMBERS = const char* offsetSection4Name
MEMBERS = const char* offsetBeforeDataName
MEMBERS = const char* offsetEndSection4Name
MEMBERS = const char* section4LengthName
MEMBERS = const char* bufrDataEncodedName
MEMBERS = const char* numberOfSubsetsName
MEMBERS = const char* expandedDescriptorsName
MEMBERS = const char* flagsName
@ -89,17 +85,13 @@ static void destroy(grib_context*,grib_accessor*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*,const long, grib_arguments* );
static void init_class(grib_accessor_class*);
static void update_size(grib_accessor*,size_t);
static int compare(grib_accessor*, grib_accessor*);
typedef struct grib_accessor_bufr_data_array {
grib_accessor att;
/* Members defined in gen */
/* Members defined in bufr_data_array */
const char* offsetSection4Name;
const char* offsetBeforeDataName;
const char* offsetEndSection4Name;
const char* section4LengthName;
const char* bufrDataEncodedName;
const char* numberOfSubsetsName;
const char* expandedDescriptorsName;
const char* flagsName;
@ -168,7 +160,7 @@ static grib_accessor_class _grib_accessor_class_bufr_data_array = {
0, /* grib_unpack procedures bytes */
0, /* pack_expression */
0, /* notify_change */
&update_size, /* update_size */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
@ -199,6 +191,7 @@ static void init_class(grib_accessor_class* c)
c->unpack_bytes = (*(c->super))->unpack_bytes;
c->pack_expression = (*(c->super))->pack_expression;
c->notify_change = (*(c->super))->notify_change;
c->update_size = (*(c->super))->update_size;
c->preferred_size = (*(c->super))->preferred_size;
c->resize = (*(c->super))->resize;
c->nearest_smaller_value = (*(c->super))->nearest_smaller_value;
@ -243,16 +236,16 @@ static void cancel_bitmap(grib_accessor_bufr_data_array *self) { self->bitmapCur
static int is_bitmap_start_defined(grib_accessor_bufr_data_array *self) { return self->bitmapStart==-1 ? 0 : 1; }
static long init_length(grib_accessor* a)
static size_t get_length(grib_accessor* a)
{
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
long section4Length=0;
size_t len=0;
grib_handle* h=grib_handle_of_accessor(a);
grib_get_long(h,self->section4LengthName,&section4Length);
grib_get_size(h,self->bufrDataEncodedName,&len);
return section4Length-4;
return len;
}
static void init(grib_accessor* a,const long v, grib_arguments* params)
@ -262,10 +255,7 @@ static void init(grib_accessor* a,const long v, grib_arguments* params)
const char* dataKeysName=NULL;
grib_accessor* dataKeysAcc=NULL;
self->offsetSection4Name = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->offsetBeforeDataName = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->offsetEndSection4Name = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->section4LengthName = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->bufrDataEncodedName = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->numberOfSubsetsName = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->expandedDescriptorsName = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->flagsName = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
@ -283,8 +273,8 @@ static void init(grib_accessor* a,const long v, grib_arguments* params)
self->expanded=0;
self->expandedAccessor=0;
a->length = init_length(a);
self->bitsToEndData=a->length*8;
a->length=0;
self->bitsToEndData=get_length(a)*8;
self->unpackMode=CODES_BUFR_UNPACK_STRUCTURE;
/* Assert(a->length>=0); */
@ -334,7 +324,7 @@ static int get_native_type(grib_accessor* a)
static long byte_count(grib_accessor* a)
{
return a->length;
return 0;
}
static long byte_offset(grib_accessor* a)
@ -344,15 +334,9 @@ static long byte_offset(grib_accessor* a)
static long next_offset(grib_accessor* a)
{
return a->offset+a->length;
return a->offset;
}
static void update_size(grib_accessor* a,size_t s)
{
grib_context_log(a->context,GRIB_LOG_DEBUG,"updating size of %s old %ld new %ld",a->name,a->length,s);
a->length = s;
Assert(a->length>=0);
}
static int compare(grib_accessor* a, grib_accessor* b)
{
@ -1679,7 +1663,7 @@ static int process_elements(grib_accessor* a,int flag)
int i;
grib_iarray* elementsDescriptorsIndex=0;
long pos=0;
long pos=0,dataOffset=0;
int iss,end,elementIndex,index;
long numberOfDescriptors;
long totalSize;
@ -1689,6 +1673,7 @@ static int process_elements(grib_accessor* a,int flag)
grib_buffer* buffer=NULL;
codec_element_proc codec_element;
codec_replication_proc codec_replication;
grib_accessor* dataAccessor=NULL;
grib_darray* dval = NULL;
grib_sarray* sval = NULL;
@ -1706,7 +1691,10 @@ static int process_elements(grib_accessor* a,int flag)
buffer=h->buffer;
decoding=1;
do_clean=1;
pos=a->offset*8;
dataAccessor=grib_find_accessor(grib_handle_of_accessor(a),self->bufrDataEncodedName);
Assert(dataAccessor);
dataOffset=accessor_raw_get_offset(dataAccessor);
pos=dataOffset*8;
codec_element=&decode_element;
codec_replication=&decode_replication;
break;
@ -1966,6 +1954,7 @@ static int process_elements(grib_accessor* a,int flag)
err=create_keys(a);
self->bitsToEndData=totalSize;
} else {
/*
long totalLength;
long section4Length;
@ -1974,13 +1963,18 @@ static int process_elements(grib_accessor* a,int flag)
grib_get_long(grib_handle_of_accessor(a),"section4Length",&section4Length);
section4Length+=buffer->ulength-a->length;
grib_buffer_replace(a,buffer->data,buffer->ulength,1,1);
grib_set_bytes(grib_handle_of_accessor(a),self->bufrDataEncodedName,buffer->data,&(buffer->ulength));
grib_buffer_delete(c,buffer);
grib_set_long(grib_handle_of_accessor(a),"totalLength",totalLength);
grib_set_long(grib_handle_of_accessor(a),"section4Length",section4Length);
a->length = section4Length-4;
self->bitsToEndData=a->length*8;
*/
self->bitsToEndData=buffer->ulength*8;
grib_set_bytes(grib_handle_of_accessor(a),self->bufrDataEncodedName,buffer->data,&(buffer->ulength));
grib_buffer_delete(c,buffer);
}

View File

@ -0,0 +1,222 @@
/*
* Copyright 2005-2016 ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = get_native_type;init;update_size; pack_bytes
IMPLEMENTS = compare;unpack_bytes;byte_count;value_count
MEMBERS = const char* totalLength
MEMBERS = const char* sectionLength
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_bytes(grib_accessor*,const unsigned char*, size_t *len);
static int unpack_bytes (grib_accessor*,unsigned char*, size_t *len);
static long byte_count(grib_accessor*);
static int value_count(grib_accessor*,long*);
static void init(grib_accessor*,const long, grib_arguments* );
static void init_class(grib_accessor_class*);
static void update_size(grib_accessor*,size_t);
static int compare(grib_accessor*, grib_accessor*);
typedef struct grib_accessor_raw {
grib_accessor att;
/* Members defined in gen */
/* Members defined in raw */
const char* totalLength;
const char* sectionLength;
} grib_accessor_raw;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_raw = {
&grib_accessor_class_gen, /* super */
"raw", /* name */
sizeof(grib_accessor_raw), /* size */
0, /* inited */
&init_class, /* init_class */
&init, /* init */
0, /* post_init */
0, /* free mem */
0, /* describes himself */
0, /* get length of section */
0, /* get length of string */
&value_count, /* get number of values */
&byte_count, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* grib_pack procedures long */
0, /* grib_pack procedures long */
0, /* grib_pack procedures long */
0, /* grib_unpack procedures long */
0, /* grib_pack procedures double */
0, /* grib_unpack procedures double */
0, /* grib_pack procedures string */
0, /* grib_unpack procedures string */
0, /* grib_pack array procedures string */
0, /* grib_unpack array procedures string */
&pack_bytes, /* grib_pack procedures bytes */
&unpack_bytes, /* grib_unpack procedures bytes */
0, /* pack_expression */
0, /* notify_change */
&update_size, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
&compare, /* compare vs. another accessor */
0, /* unpack only ith value */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class* grib_accessor_class_raw = &_grib_accessor_class_raw;
static void init_class(grib_accessor_class* c)
{
c->dump = (*(c->super))->dump;
c->next_offset = (*(c->super))->next_offset;
c->string_length = (*(c->super))->string_length;
c->byte_offset = (*(c->super))->byte_offset;
c->sub_section = (*(c->super))->sub_section;
c->pack_missing = (*(c->super))->pack_missing;
c->is_missing = (*(c->super))->is_missing;
c->pack_long = (*(c->super))->pack_long;
c->unpack_long = (*(c->super))->unpack_long;
c->pack_double = (*(c->super))->pack_double;
c->unpack_double = (*(c->super))->unpack_double;
c->pack_string = (*(c->super))->pack_string;
c->unpack_string = (*(c->super))->unpack_string;
c->pack_string_array = (*(c->super))->pack_string_array;
c->unpack_string_array = (*(c->super))->unpack_string_array;
c->pack_expression = (*(c->super))->pack_expression;
c->notify_change = (*(c->super))->notify_change;
c->preferred_size = (*(c->super))->preferred_size;
c->resize = (*(c->super))->resize;
c->nearest_smaller_value = (*(c->super))->nearest_smaller_value;
c->next = (*(c->super))->next;
c->unpack_double_element = (*(c->super))->unpack_double_element;
c->unpack_double_subarray = (*(c->super))->unpack_double_subarray;
c->clear = (*(c->super))->clear;
c->make_clone = (*(c->super))->make_clone;
}
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long len , grib_arguments* arg )
{
int n=0;
grib_accessor_raw *self =(grib_accessor_raw*)a;
grib_expression* e=grib_arguments_get_expression(grib_handle_of_accessor(a), arg,n++);
a->length=0;
grib_expression_evaluate_long(grib_handle_of_accessor(a),e,&(a->length));
self->totalLength = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++);
self->sectionLength = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++);
Assert(a->length>=0);
}
static int get_native_type(grib_accessor* a){
return GRIB_TYPE_BYTES;
}
static int compare(grib_accessor* a, grib_accessor* b) {
int retval=GRIB_SUCCESS;
size_t alen = (size_t)grib_byte_count(a);
size_t blen = (size_t)grib_byte_count(b);
if (alen != blen) return GRIB_COUNT_MISMATCH;
return retval;
}
static long byte_count(grib_accessor* a){
return a->length;
}
static int value_count(grib_accessor* a,long* len){
*len=a->length;
return 0;
}
static int unpack_bytes (grib_accessor* a,unsigned char* buffer, size_t *len) {
if (*len < a->length) {
*len = a->length;
return GRIB_ARRAY_TOO_SMALL;
}
*len = a->length;
memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len);
return GRIB_SUCCESS;
}
static void update_size(grib_accessor* a,size_t s)
{
grib_context_log(a->context,GRIB_LOG_DEBUG,"updating size of %s old %ld new %ld",a->name,a->length,s);
a->length = s;
Assert(a->length>=0);
}
void accessor_raw_set_length(grib_accessor* a,size_t len) {
a->length=len;
}
long accessor_raw_get_offset(grib_accessor* a) {
return a->offset;
}
static int pack_bytes(grib_accessor* a, const unsigned char* val, size_t *len)
{
size_t length = *len;
long totalLength;
long section4Length;
grib_handle* h=grib_handle_of_accessor(a);
grib_context* c=h->context;
grib_accessor_raw *self =(grib_accessor_raw*)a;
grib_get_long(grib_handle_of_accessor(a),self->totalLength,&totalLength);
totalLength+=length-a->length;
grib_get_long(grib_handle_of_accessor(a),self->sectionLength,&section4Length);
section4Length+=length-a->length;
grib_buffer_replace(a, val, length,1,1);
grib_set_long(grib_handle_of_accessor(a),self->totalLength,totalLength);
grib_set_long(grib_handle_of_accessor(a),self->sectionLength,section4Length);
a->length = section4Length-4;
return GRIB_SUCCESS;
}

View File

@ -163,6 +163,7 @@
{ "padtoeven", &grib_accessor_class_padtoeven, },
{ "padtomultiple", &grib_accessor_class_padtomultiple, },
{ "position", &grib_accessor_class_position, },
{ "raw", &grib_accessor_class_raw, },
{ "reference_value_error", &grib_accessor_class_reference_value_error, },
{ "round", &grib_accessor_class_round, },
{ "scale", &grib_accessor_class_scale, },

View File

@ -172,6 +172,7 @@ padto, &grib_accessor_class_padto
padtoeven, &grib_accessor_class_padtoeven
padtomultiple, &grib_accessor_class_padtomultiple
position, &grib_accessor_class_position
raw, &grib_accessor_class_raw
reference_value_error, &grib_accessor_class_reference_value_error
round, &grib_accessor_class_round
scale, &grib_accessor_class_scale

View File

@ -1431,3 +1431,6 @@ int grib_decode_double_array_complex(const unsigned char *p, long *bitp, long nb
int grib_encode_long_array(size_t n_vals, const long *val, long bits_per_value, unsigned char *p, long *off);
int grib_encode_double_array(size_t n_vals, const double *val, long bits_per_value, double reference_value, double d, double divisor, unsigned char *p, long *off);
int grib_encode_double_array_complex(size_t n_vals, double *val, long nbits, double reference_value, double *scal, double d, double divisor, unsigned char *p, long *bitp);
long accessor_raw_get_offset(grib_accessor* a);

View File

@ -246,6 +246,7 @@ int grib_init_accessor_from_handle(grib_loader* loader,grib_accessor* ga,grib_ar
case GRIB_TYPE_BYTES:
len=grib_byte_count(ga);
uval = (unsigned char*)grib_context_malloc(h->context,len*sizeof(char));
ret = grib_get_bytes_internal(h,name,uval,&len);
if(ret == GRIB_SUCCESS)