diff --git a/src/grib_accessor_class_data_2order_packing.c b/src/grib_accessor_class_data_2order_packing.c index ce3359ba7..195e49d65 100644 --- a/src/grib_accessor_class_data_2order_packing.c +++ b/src/grib_accessor_class_data_2order_packing.c @@ -187,39 +187,40 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long v, grib_arguments* args) { + grib_handle* gh = grib_handle_of_accessor(a); grib_accessor_data_2order_packing *self =(grib_accessor_data_2order_packing*)a; - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->bits_per_value = grib_arguments_get_name(gh,args,self->carg++); - self->reference_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->reference_value = grib_arguments_get_name(gh,args,self->carg++); - self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->binary_scale_factor = grib_arguments_get_name(gh,args,self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->decimal_scale_factor = grib_arguments_get_name(gh,args,self->carg++); - self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->half_byte = grib_arguments_get_name(gh,args,self->carg++); - self->n1 = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->n2 = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->p1 = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->extraValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->p2 = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->n1 = grib_arguments_get_name(gh,args,self->carg++); + self->n2 = grib_arguments_get_name(gh,args,self->carg++); + self->p1 = grib_arguments_get_name(gh,args,self->carg++); + self->extraValues = grib_arguments_get_name(gh,args,self->carg++); + self->p2 = grib_arguments_get_name(gh,args,self->carg++); - self->matrix_values = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->snd_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->snd_ordr_wdiff = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->matrix_values = grib_arguments_get_name(gh ,args,self->carg++); + self->snd_bitmap = grib_arguments_get_name(gh ,args,self->carg++); + self->snd_ordr_wdiff = grib_arguments_get_name(gh ,args,self->carg++); - self->general_ext = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->boustrophedonic = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->two_ordr_spd = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->plus1_spd = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->general_ext = grib_arguments_get_name(gh ,args,self->carg++); + self->boustrophedonic = grib_arguments_get_name(gh ,args,self->carg++); + self->two_ordr_spd = grib_arguments_get_name(gh ,args,self->carg++); + self->plus1_spd = grib_arguments_get_name(gh ,args,self->carg++); - self->width_widths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->width_lengths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->octet_start_group = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->width_spd_sp_desc = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->nap = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->width_widths = grib_arguments_get_name(gh ,args,self->carg++); + self->width_lengths = grib_arguments_get_name(gh ,args,self->carg++); + self->octet_start_group = grib_arguments_get_name(gh ,args,self->carg++); + self->width_spd_sp_desc = grib_arguments_get_name(gh ,args,self->carg++); + self->nap = grib_arguments_get_name(gh ,args,self->carg++); + self->bitmap = grib_arguments_get_name(gh, args,self->carg++); a->flags |= GRIB_ACCESSOR_FLAG_DATA; } @@ -448,12 +449,12 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) long nbits_per_group_size =0; long octet_start_group =0; long width_spd_sp_desc =0; + grib_handle* gh = grib_handle_of_accessor(a); - - unsigned char* buf_size_of_groups = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - unsigned char* buf_width_of_group = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - unsigned char* bufrefs = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - unsigned char* bufvals = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + unsigned char* buf_size_of_groups = (unsigned char*)gh->buffer->data; + unsigned char* buf_width_of_group = (unsigned char*)gh->buffer->data; + unsigned char* bufrefs = (unsigned char*)gh->buffer->data; + unsigned char* bufvals = (unsigned char*)gh->buffer->data; double s = 0; double d = 0; @@ -481,49 +482,49 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) err=grib_value_count(a,&nn); n_vals=nn; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetsection,&offsetsection)) + if((err = grib_get_long_internal(gh,self->offsetsection,&offsetsection)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return err; - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value, &reference_value)) + if((err = grib_get_double_internal(gh,self->reference_value, &reference_value)) != GRIB_SUCCESS)return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, &binary_scale_factor)) + if((err = grib_get_long_internal(gh,self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, &decimal_scale_factor)) + if((err = grib_get_long_internal(gh,self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->n1,&n1)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->n2, &n2)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->p1, &p1)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->extraValues, &extraValues)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->n1,&n1)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->n2, &n2)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->p1, &p1)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->extraValues, &extraValues)) != GRIB_SUCCESS) return err; p1=p1+65536*extraValues; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->p2, &p2)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->matrix_values, &matrix_values)) + if((err = grib_get_long_internal(gh,self->p2, &p2)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->matrix_values, &matrix_values)) != GRIB_SUCCESS)return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->snd_bitmap, &snd_bitmap)) + if((err = grib_get_long_internal(gh,self->snd_bitmap, &snd_bitmap)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->snd_ordr_wdiff, &snd_ordr_wdiff)) + if((err = grib_get_long_internal(gh,self->snd_ordr_wdiff, &snd_ordr_wdiff)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->general_ext, &general_ext)) + if((err = grib_get_long_internal(gh,self->general_ext, &general_ext)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->boustrophedonic, &boustrophedonic)) + if((err = grib_get_long_internal(gh,self->boustrophedonic, &boustrophedonic)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->two_ordr_spd, &two_ordr_spd)) + if((err = grib_get_long_internal(gh,self->two_ordr_spd, &two_ordr_spd)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->plus1_spd, &plus1_spd)) + if((err = grib_get_long_internal(gh,self->plus1_spd, &plus1_spd)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->width_widths, &nbits_per_width)) + if((err = grib_get_long_internal(gh,self->width_widths, &nbits_per_width)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->width_lengths, &nbits_per_group_size)) + if((err = grib_get_long_internal(gh,self->width_lengths, &nbits_per_group_size)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->octet_start_group, &octet_start_group)) + if((err = grib_get_long_internal(gh,self->octet_start_group, &octet_start_group)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->width_spd_sp_desc, &width_spd_sp_desc)) + if((err = grib_get_long_internal(gh,self->width_spd_sp_desc, &width_spd_sp_desc)) != GRIB_SUCCESS) width_spd_sp_desc=-1; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->nap, &nap)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->nap, &nap)) != GRIB_SUCCESS) return err; self->dirty=0; @@ -531,7 +532,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) Assert(bits_per_value < (sizeof(unsigned long)*8)-1); - if ((abitmap=grib_find_accessor(grib_handle_of_accessor(a),self->bitmap))!=NULL) { + if ((abitmap=grib_find_accessor(gh,self->bitmap))!=NULL) { bitmap_len=grib_byte_count(abitmap); bitmap=(unsigned char*)grib_context_malloc_clear(a->context,sizeof(char)*bitmap_len); err=grib_unpack_bytes(abitmap,bitmap,&bitmap_len); @@ -671,6 +672,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_data_2order_packing* self = (grib_accessor_data_2order_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; size_t j = 0; @@ -710,7 +712,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) unsigned char* buf_refs = NULL; unsigned char* buf_vals = NULL; - double d = 0; unsigned long* sec_val = NULL; @@ -742,20 +743,20 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) if (*len ==0) return GRIB_NO_VALUES; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetsection,&offsetsection)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetdata,&offsetdata)) != GRIB_SUCCESS) + if((err = grib_get_long_internal(gh,self->offsetsection,&offsetsection)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->offsetdata,&offsetdata)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->matrix_values, &matrix_values)) != GRIB_SUCCESS)return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->snd_bitmap, &snd_bitmap)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->snd_ordr_wdiff, &snd_ordr_wdiff)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->general_ext, &general_ext)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->boustrophedonic, &boustrophedonic)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->width_spd_sp_desc, &width_spd_sp_desc)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->nap, &nap)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->matrix_values, &matrix_values)) != GRIB_SUCCESS)return err; + if((err = grib_get_long_internal(gh,self->snd_bitmap, &snd_bitmap)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->snd_ordr_wdiff, &snd_ordr_wdiff)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->general_ext, &general_ext)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->boustrophedonic, &boustrophedonic)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->width_spd_sp_desc, &width_spd_sp_desc)) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->nap, &nap)) != GRIB_SUCCESS) return err; - if ((abitmap=grib_find_accessor(grib_handle_of_accessor(a),self->bitmap))!=NULL) { + if ((abitmap=grib_find_accessor(gh,self->bitmap))!=NULL) { bitmap_len=grib_byte_count(abitmap); bitmap=(unsigned char*)grib_context_malloc_clear(a->context,sizeof(char)*bitmap_len); err=grib_unpack_bytes(abitmap,bitmap,&bitmap_len); @@ -784,7 +785,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) max *= d; bit_per_val_rectified_for_gribex = bits_per_value+8-bits_per_value%8; - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value,min,&reference_value) + if (grib_get_nearest_smaller_value(gh,self->reference_value,min,&reference_value) !=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); @@ -892,13 +893,13 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } octet_start_group += 1+ a->offset-offsetsection; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->octet_start_group, octet_start_group)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->octet_start_group, octet_start_group)) != GRIB_SUCCESS) return err; n1 += 1+a->offset-offsetsection; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->n1,n1)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->n1,n1)) != GRIB_SUCCESS) return err; n2 += 1+a->offset-offsetsection; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->n2,n2)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->n2,n2)) != GRIB_SUCCESS) return err; extraValues=0; while (p1 > 65535) { @@ -906,29 +907,29 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) extraValues++; } - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->p1,p1)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->p1,p1)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->extraValues,extraValues)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->extraValues,extraValues)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->p2,n_vals - n_sp_diff)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->p2,n_vals - n_sp_diff)) != GRIB_SUCCESS) return err; - if((err = grib_set_double_internal(grib_handle_of_accessor(a),self->reference_value, reference_value)) != GRIB_SUCCESS)return err; + if((err = grib_set_double_internal(gh,self->reference_value, reference_value)) != GRIB_SUCCESS)return err; { /* Make sure we can decode it again */ double ref = 1e-100; - grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&ref); + grib_get_double_internal(gh,self->reference_value,&ref); Assert(ref == reference_value); } - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->width_widths, sd->nbits_per_widths)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->width_lengths, sd->nbits_per_group_size)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->width_widths, sd->nbits_per_widths)) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->width_lengths, sd->nbits_per_group_size)) != GRIB_SUCCESS) return err; - err = grib_set_long_internal(grib_handle_of_accessor(a),self->half_byte, n_unused_bits); + err = grib_set_long_internal(gh,self->half_byte, n_unused_bits); if(err != GRIB_SUCCESS) return err; #if KEEP_OLD == 1 @@ -946,12 +947,14 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a,long* count){ +static int value_count(grib_accessor* a,long* count) +{ int err=0; grib_accessor_data_2order_packing* self = (grib_accessor_data_2order_packing*)a; long two_ordr_spd = 0; long plus1_spd = 0; - unsigned char* buf_size_of_groups = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + grib_handle* gh = grib_handle_of_accessor(a); + unsigned char* buf_size_of_groups = (unsigned char*)gh->buffer->data; long octet_start_group = 0; long offsetsection = 0; long nbits_per_lengths = 0; @@ -961,19 +964,19 @@ static int value_count(grib_accessor* a,long* count){ size_t i = 0; - if((err=grib_get_long_internal(grib_handle_of_accessor(a),self->two_ordr_spd, &two_ordr_spd)) != GRIB_SUCCESS) + if((err=grib_get_long_internal(gh,self->two_ordr_spd, &two_ordr_spd)) != GRIB_SUCCESS) return err; - if( (err=grib_get_long_internal(grib_handle_of_accessor(a),self->plus1_spd, &plus1_spd)) != GRIB_SUCCESS) + if( (err=grib_get_long_internal(gh,self->plus1_spd, &plus1_spd)) != GRIB_SUCCESS) return err; - if( (err=grib_get_long_internal(grib_handle_of_accessor(a),self->width_lengths, &nbits_per_lengths)) != GRIB_SUCCESS) + if( (err=grib_get_long_internal(gh,self->width_lengths, &nbits_per_lengths)) != GRIB_SUCCESS) return err; - if( (err=grib_get_long_internal(grib_handle_of_accessor(a),self->offsetsection, &offsetsection)) != GRIB_SUCCESS) + if( (err=grib_get_long_internal(gh,self->offsetsection, &offsetsection)) != GRIB_SUCCESS) return err; - if( (err=grib_get_long_internal(grib_handle_of_accessor(a),self->octet_start_group, &octet_start_group)) != GRIB_SUCCESS) + if( (err=grib_get_long_internal(gh,self->octet_start_group, &octet_start_group)) != GRIB_SUCCESS) return err; - if( (err=grib_get_long_internal(grib_handle_of_accessor(a),self->p1, &p1)) != GRIB_SUCCESS) + if( (err=grib_get_long_internal(gh,self->p1, &p1)) != GRIB_SUCCESS) return err; - if( (err=grib_get_long_internal(grib_handle_of_accessor(a),self->extraValues, &extraValues)) != GRIB_SUCCESS) + if( (err=grib_get_long_internal(gh,self->extraValues, &extraValues)) != GRIB_SUCCESS) return err; p1+=extraValues*65536; diff --git a/src/grib_accessor_class_data_apply_boustrophedonic_bitmap.c b/src/grib_accessor_class_data_apply_boustrophedonic_bitmap.c index 7cc1aaeef..3ede277a2 100644 --- a/src/grib_accessor_class_data_apply_boustrophedonic_bitmap.c +++ b/src/grib_accessor_class_data_apply_boustrophedonic_bitmap.c @@ -149,18 +149,20 @@ static void init(grib_accessor* a,const long v, grib_arguments* args) { int n=0; grib_accessor_data_apply_boustrophedonic_bitmap *self =(grib_accessor_data_apply_boustrophedonic_bitmap*)a; + grib_handle* gh = grib_handle_of_accessor(a); - self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); - self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); - self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); - self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); + self->coded_values = grib_arguments_get_name(gh,args,n++); + self->bitmap = grib_arguments_get_name(gh,args,n++); + self->missing_value = grib_arguments_get_name(gh,args,n++); + self->binary_scale_factor = grib_arguments_get_name(gh,args,n++); - self->numberOfRows = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); - self->numberOfColumns = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); - self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a),args,n++); + self->numberOfRows = grib_arguments_get_name(gh,args,n++); + self->numberOfColumns = grib_arguments_get_name(gh,args,n++); + self->numberOfPoints = grib_arguments_get_name(gh,args,n++); a->length = 0; } + static void dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_values(dumper,a); @@ -169,13 +171,14 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int value_count(grib_accessor* a,long* count) { grib_accessor_data_apply_boustrophedonic_bitmap *self =(grib_accessor_data_apply_boustrophedonic_bitmap*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t len = 0; int ret = 0; /* This accessor is for data with a bitmap after all */ - Assert(grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)); + Assert(grib_find_accessor(gh, self->bitmap)); - ret = grib_get_size(grib_handle_of_accessor(a), self->bitmap, &len); + ret = grib_get_size(gh, self->bitmap, &len); *count=len; return ret; } @@ -183,6 +186,7 @@ static int value_count(grib_accessor* a,long* count) static int unpack_double(grib_accessor* a, double* val, size_t *len) { grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0, j = 0, n_vals = 0, irow = 0; long nn=0; @@ -196,21 +200,21 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) n_vals=nn; if (err) return err; - err=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfRows,&numberOfRows); + err=grib_get_long_internal(gh,self->numberOfRows,&numberOfRows); if (err) return err; - err=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfColumns,&numberOfColumns); + err=grib_get_long_internal(gh,self->numberOfColumns,&numberOfColumns); if (err) return err; - err=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfPoints,&numberOfPoints); + err=grib_get_long_internal(gh,self->numberOfPoints,&numberOfPoints); if (err) return err; Assert(nn == numberOfPoints); - if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)) - return grib_get_double_array_internal(grib_handle_of_accessor(a),self->coded_values,val,len); + if(!grib_find_accessor(gh,self->bitmap)) + return grib_get_double_array_internal(gh,self->coded_values,val,len); - if((err = grib_get_size(grib_handle_of_accessor(a),self->coded_values,&coded_n_vals)) != GRIB_SUCCESS) + if((err = grib_get_size(gh,self->coded_values,&coded_n_vals)) != GRIB_SUCCESS) return err; - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->missing_value,&missing_value)) + if((err = grib_get_double_internal(gh,self->missing_value,&missing_value)) != GRIB_SUCCESS) return err; if(*len < n_vals) { @@ -226,14 +230,14 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) return GRIB_SUCCESS; } - if((err = grib_get_double_array_internal(grib_handle_of_accessor(a),self->bitmap,val,&n_vals)) + if((err = grib_get_double_array_internal(gh,self->bitmap,val,&n_vals)) != GRIB_SUCCESS) return err; coded_vals = (double*)grib_context_malloc(a->context,coded_n_vals*sizeof(double)); if(coded_vals == NULL) return GRIB_OUT_OF_MEMORY; - if((err = grib_get_double_array_internal(grib_handle_of_accessor(a),self->coded_values,coded_vals,&coded_n_vals)) + if((err = grib_get_double_array_internal(gh,self->coded_values,coded_vals,&coded_n_vals)) != GRIB_SUCCESS) { grib_context_free(a->context,coded_vals); @@ -296,6 +300,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) static int unpack_double_element(grib_accessor* a, size_t idx,double* val) { grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; + grib_handle* gh = grib_handle_of_accessor(a); int err = 0,i=0; size_t cidx=0; double missing_value = 0; @@ -307,13 +312,13 @@ static int unpack_double_element(grib_accessor* a, size_t idx,double* val) n_vals=nn; if (err) return err; - if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)) - return grib_get_double_element_internal(grib_handle_of_accessor(a),self->coded_values,idx,val); + if(!grib_find_accessor(gh,self->bitmap)) + return grib_get_double_element_internal(gh,self->coded_values,idx,val); - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->missing_value,&missing_value)) != GRIB_SUCCESS) + if((err = grib_get_double_internal(gh,self->missing_value,&missing_value)) != GRIB_SUCCESS) return err; - if((err = grib_get_double_element_internal(grib_handle_of_accessor(a),self->bitmap,idx,val)) != GRIB_SUCCESS) + if((err = grib_get_double_element_internal(gh,self->bitmap,idx,val)) != GRIB_SUCCESS) return err; if (*val == 0) {*val=missing_value;return GRIB_SUCCESS;} @@ -321,7 +326,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx,double* val) bvals = (double*)grib_context_malloc(a->context,n_vals*sizeof(double)); if(bvals == NULL) return GRIB_OUT_OF_MEMORY; - if((err = grib_get_double_array_internal(grib_handle_of_accessor(a),self->bitmap,bvals,&n_vals)) != GRIB_SUCCESS) + if((err = grib_get_double_array_internal(gh,self->bitmap,bvals,&n_vals)) != GRIB_SUCCESS) return err; cidx=0; @@ -329,12 +334,13 @@ static int unpack_double_element(grib_accessor* a, size_t idx,double* val) grib_context_free(a->context,bvals); - return grib_get_double_element_internal(grib_handle_of_accessor(a),self->coded_values,cidx,val); + return grib_get_double_element_internal(gh,self->coded_values,cidx,val); } static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; + grib_handle* gh = grib_handle_of_accessor(a); int err = 0; size_t bmaplen = *len; size_t irow = 0; @@ -348,22 +354,22 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) if (*len ==0) return GRIB_NO_VALUES; - if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)){ - err = grib_set_double_array_internal(grib_handle_of_accessor(a),self->coded_values,val,*len); + if(!grib_find_accessor(gh,self->bitmap)){ + err = grib_set_double_array_internal(gh,self->coded_values,val,*len); /*printf("SETTING TOTAL number_of_data_points %s %ld\n",self->number_of_data_points,*len);*/ /*if(self->number_of_data_points) - grib_set_long_internal(grib_handle_of_accessor(a),self->number_of_data_points,*len);*/ + grib_set_long_internal(gh,self->number_of_data_points,*len);*/ return err; } - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->missing_value,&missing_value)) != GRIB_SUCCESS) + if((err = grib_get_double_internal(gh,self->missing_value,&missing_value)) != GRIB_SUCCESS) return err; - err=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfRows, &numberOfRows); + err=grib_get_long_internal(gh,self->numberOfRows, &numberOfRows); if (err) return err; - err=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfColumns, &numberOfColumns); + err=grib_get_long_internal(gh,self->numberOfColumns, &numberOfColumns); if (err) return err; - err=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfPoints,&numberOfPoints); + err=grib_get_long_internal(gh,self->numberOfPoints,&numberOfPoints); if (err) return err; Assert(numberOfPoints == bmaplen); @@ -392,7 +398,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } } /* Now set the bitmap based on the array with the boustrophedonic ordering */ - if((err = grib_set_double_array_internal(grib_handle_of_accessor(a),self->bitmap,values,bmaplen)) != GRIB_SUCCESS) + if((err = grib_set_double_array_internal(gh,self->bitmap,values,bmaplen)) != GRIB_SUCCESS) return err; grib_context_free(a->context,values); @@ -400,7 +406,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) coded_n_vals = *len; if(coded_n_vals < 1){ - err = grib_set_double_array_internal(grib_handle_of_accessor(a),self->coded_values,NULL,0); + err = grib_set_double_array_internal(gh,self->coded_values,NULL,0); return err; } @@ -416,12 +422,12 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } } - err = grib_set_double_array_internal(grib_handle_of_accessor(a),self->coded_values,coded_vals,j); + err = grib_set_double_array_internal(gh,self->coded_values,coded_vals,j); if (j==0) { /*if (self->number_of_values) - err=grib_set_long_internal(grib_handle_of_accessor(a),self->number_of_values,0);*/ + err=grib_set_long_internal(gh,self->number_of_values,0);*/ if (self->binary_scale_factor) - err=grib_set_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor,0); + err=grib_set_long_internal(gh,self->binary_scale_factor,0); } grib_context_free(a->context,coded_vals); diff --git a/src/grib_accessor_class_data_complex_packing.c b/src/grib_accessor_class_data_complex_packing.c index 92e0daad0..354b63f93 100644 --- a/src/grib_accessor_class_data_complex_packing.c +++ b/src/grib_accessor_class_data_complex_packing.c @@ -173,26 +173,27 @@ typedef double (*decode_float_proc)(unsigned long); static void init(grib_accessor* a,const long v, grib_arguments* args) { grib_accessor_data_complex_packing *self =(grib_accessor_data_complex_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); - self->GRIBEX_sh_bug_present = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->ieee_floats = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->laplacianOperatorIsSet = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->laplacianOperator = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->sub_j = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->sub_k = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->sub_m = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->pen_j = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->pen_k = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->pen_m = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->GRIBEX_sh_bug_present = grib_arguments_get_name(gh,args,self->carg++); + self->ieee_floats = grib_arguments_get_name(gh,args,self->carg++); + self->laplacianOperatorIsSet = grib_arguments_get_name(gh,args,self->carg++); + self->laplacianOperator = grib_arguments_get_name(gh,args,self->carg++); + self->sub_j = grib_arguments_get_name(gh,args,self->carg++); + self->sub_k = grib_arguments_get_name(gh,args,self->carg++); + self->sub_m = grib_arguments_get_name(gh,args,self->carg++); + self->pen_j = grib_arguments_get_name(gh,args,self->carg++); + self->pen_k = grib_arguments_get_name(gh,args,self->carg++); + self->pen_m = grib_arguments_get_name(gh,args,self->carg++); a->flags |= GRIB_ACCESSOR_FLAG_DATA; } - static int value_count(grib_accessor* a,long* count) { grib_accessor_data_complex_packing *self =(grib_accessor_data_complex_packing*)a; int ret = 0; + grib_handle* gh = grib_handle_of_accessor(a); long pen_j= 0; long pen_k= 0; @@ -202,11 +203,11 @@ static int value_count(grib_accessor* a,long* count) if(a->length == 0) return 0; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_j,&pen_j)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_j,&pen_j)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_k,&pen_k)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_k,&pen_k)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_m,&pen_m)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_m,&pen_m)) != GRIB_SUCCESS) return ret; if (pen_j != pen_k || pen_j!=pen_m ) { @@ -222,6 +223,7 @@ static int value_count(grib_accessor* a,long* count) static int unpack_double(grib_accessor* a, double* val, size_t *len) { grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; int ret = GRIB_SUCCESS; @@ -253,7 +255,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) long binary_scale_factor = 0; long decimal_scale_factor = 0; - long sub_j= 0; long sub_k= 0; long sub_m= 0; @@ -275,40 +276,40 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) return GRIB_ARRAY_TOO_SMALL; } - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetdata,&offsetdata)) + if((ret = grib_get_long_internal(gh,self->offsetdata,&offsetdata)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) + if((ret = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&reference_value)) + if((ret = grib_get_double_internal(gh,self->reference_value,&reference_value)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor,&binary_scale_factor)) + if((ret = grib_get_long_internal(gh,self->binary_scale_factor,&binary_scale_factor)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor,&decimal_scale_factor)) + if((ret = grib_get_long_internal(gh,self->decimal_scale_factor,&decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->GRIBEX_sh_bug_present,&GRIBEX_sh_bug_present)) + if((ret = grib_get_long_internal(gh,self->GRIBEX_sh_bug_present,&GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->ieee_floats,&ieee_floats)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->ieee_floats,&ieee_floats)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_double_internal(grib_handle_of_accessor(a),self->laplacianOperator,&laplacianOperator)) + if((ret = grib_get_double_internal(gh,self->laplacianOperator,&laplacianOperator)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_j,&sub_j)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->sub_j,&sub_j)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_k,&sub_k)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->sub_k,&sub_k)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_m,&sub_m)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->sub_m,&sub_m)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_j,&pen_j)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_j,&pen_j)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_k,&pen_k)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_k,&pen_k)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_m,&pen_m)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_m,&pen_m)) != GRIB_SUCCESS) return ret; self->dirty=0; @@ -335,7 +336,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) Assert (pen_j == pen_k); Assert (pen_j == pen_m); - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + buf = (unsigned char*)gh->buffer->data; maxv = pen_j+1; @@ -553,6 +554,7 @@ static double calculate_pfactor(grib_context *ctx,const double* spectralField, l static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; int ret = GRIB_SUCCESS; @@ -570,11 +572,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) { unsigned char* buf = NULL; size_t buflen = 0; - size_t hsize = 0; size_t lsize = 0; - unsigned char* hres = NULL; unsigned char* lres = NULL; @@ -607,36 +607,36 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) { if (*len ==0) return GRIB_NO_VALUES; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->offsetdata,&offsetdata)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->offsetdata,&offsetdata)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor,&decimal_scale_factor)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->decimal_scale_factor,&decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->GRIBEX_sh_bug_present,&GRIBEX_sh_bug_present)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->GRIBEX_sh_bug_present,&GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->ieee_floats,&ieee_floats)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->ieee_floats,&ieee_floats)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->laplacianOperatorIsSet,&laplacianOperatorIsSet)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->laplacianOperatorIsSet,&laplacianOperatorIsSet)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_double_internal(grib_handle_of_accessor(a),self->laplacianOperator,&laplacianOperator)) != GRIB_SUCCESS) + if((ret = grib_get_double_internal(gh,self->laplacianOperator,&laplacianOperator)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_j,&sub_j)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->sub_j,&sub_j)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_k,&sub_k)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->sub_k,&sub_k)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_m,&sub_m)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->sub_m,&sub_m)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_j,&pen_j)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_j,&pen_j)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_k,&pen_k)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_k,&pen_k)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_m,&pen_m)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(gh,self->pen_m,&pen_m)) != GRIB_SUCCESS) return ret; self->dirty=1; @@ -689,9 +689,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) { if(!laplacianOperatorIsSet) { laplacianOperator = calculate_pfactor(a->context,val,pen_j,sub_j); - if((ret = grib_set_double_internal(grib_handle_of_accessor(a),self->laplacianOperator,laplacianOperator)) + if((ret = grib_set_double_internal(gh,self->laplacianOperator,laplacianOperator)) != GRIB_SUCCESS) return ret; - grib_get_double_internal(grib_handle_of_accessor(a),self->laplacianOperator,&laplacianOperator); + grib_get_double_internal(gh,self->laplacianOperator,&laplacianOperator); } /* @@ -764,7 +764,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) { mmax++; } - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value,min,&reference_value) + if (grib_get_nearest_smaller_value(gh,self->reference_value,min,&reference_value) !=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); @@ -872,16 +872,16 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) { buflen = ((hpos + lpos)/8); - if((ret = grib_set_double_internal(grib_handle_of_accessor(a),self->reference_value, reference_value)) != GRIB_SUCCESS) + if((ret = grib_set_double_internal(gh,self->reference_value, reference_value)) != GRIB_SUCCESS) return ret; { /* Make sure we can decode it again */ double ref = 1e-100; - grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&ref); + grib_get_double_internal(gh,self->reference_value,&ref); Assert(ref == reference_value); } - if((ret = grib_set_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(gh,self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) return ret; grib_buffer_replace(a, buf, buflen,1,1); diff --git a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.c b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.c index 41145dd49..074dc4370 100644 --- a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.c +++ b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.c @@ -181,252 +181,252 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long v, grib_arguments* args) { - grib_accessor_data_g1second_order_row_by_row_packing *self =(grib_accessor_data_g1second_order_row_by_row_packing*)a; - - self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->precision = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->widthOfFirstOrderValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->N1 = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->N2 = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->numberOfGroups = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->numberOfSecondOrderPackedValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->extraValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->Ni = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->Nj = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->pl = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->jPointsAreConsecutive = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->groupWidths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->edition=1; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + grib_accessor_data_g1second_order_row_by_row_packing *self =(grib_accessor_data_g1second_order_row_by_row_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); + self->half_byte = grib_arguments_get_name(gh,args,self->carg++); + self->packingType = grib_arguments_get_name(gh,args,self->carg++); + self->ieee_packing = grib_arguments_get_name(gh,args,self->carg++); + self->precision = grib_arguments_get_name(gh,args,self->carg++); + self->widthOfFirstOrderValues = grib_arguments_get_name(gh,args,self->carg++); + self->N1 = grib_arguments_get_name(gh,args,self->carg++); + self->N2 = grib_arguments_get_name(gh,args,self->carg++); + self->numberOfGroups = grib_arguments_get_name(gh,args,self->carg++); + self->numberOfSecondOrderPackedValues = grib_arguments_get_name(gh,args,self->carg++); + self->extraValues = grib_arguments_get_name(gh,args,self->carg++); + self->Ni = grib_arguments_get_name(gh,args,self->carg++); + self->Nj = grib_arguments_get_name(gh,args,self->carg++); + self->pl = grib_arguments_get_name(gh,args,self->carg++); + self->jPointsAreConsecutive = grib_arguments_get_name(gh,args,self->carg++); + self->groupWidths = grib_arguments_get_name(gh,args,self->carg++); + self->bitmap = grib_arguments_get_name(gh,args,self->carg++); + self->edition=1; + a->flags |= GRIB_ACCESSOR_FLAG_DATA; } static int value_count(grib_accessor* a,long* count) { - grib_accessor_data_g1second_order_row_by_row_packing *self =(grib_accessor_data_g1second_order_row_by_row_packing*)a; - long n=0,i=0; - long numberOfRows=0; - long jPointsAreConsecutive=0; - long Ni=0,Nj=0; - int bitmapPresent=0; - size_t plSize=0; - long* pl=0; - int ret=0; - grib_context* c=a->context; + grib_accessor_data_g1second_order_row_by_row_packing *self =(grib_accessor_data_g1second_order_row_by_row_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); + long n=0,i=0; + long numberOfRows=0; + long jPointsAreConsecutive=0; + long Ni=0,Nj=0; + int bitmapPresent=0; + size_t plSize=0; + long* pl=0; + int ret=0; + grib_context* c=a->context; - if (self->bitmap) bitmapPresent=1; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->jPointsAreConsecutive,&jPointsAreConsecutive)) != GRIB_SUCCESS) - return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->Ni,&Ni)) != GRIB_SUCCESS) - return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->Nj,&Nj)) != GRIB_SUCCESS) - return ret; - if (jPointsAreConsecutive) { - numberOfRows=Ni; - } else { - numberOfRows=Nj; - } + if (self->bitmap) bitmapPresent=1; + if((ret=grib_get_long_internal(gh,self->jPointsAreConsecutive,&jPointsAreConsecutive)) != GRIB_SUCCESS) + return ret; + if((ret=grib_get_long_internal(gh,self->Ni,&Ni)) != GRIB_SUCCESS) + return ret; + if((ret=grib_get_long_internal(gh,self->Nj,&Nj)) != GRIB_SUCCESS) + return ret; + if (jPointsAreConsecutive) { + numberOfRows=Ni; + } else { + numberOfRows=Nj; + } - plSize=0; - ret=grib_get_size(grib_handle_of_accessor(a),self->pl,&plSize); - if (ret==GRIB_SUCCESS) { + plSize=0; + ret=grib_get_size(gh,self->pl,&plSize); + if (ret==GRIB_SUCCESS) { pl=(long*)grib_context_malloc_clear(a->context,sizeof(long)*plSize); - if((ret=grib_get_long_array(grib_handle_of_accessor(a),self->pl,pl,&plSize)) != GRIB_SUCCESS) - return ret; - } - ret=0; + if((ret=grib_get_long_array(gh,self->pl,pl,&plSize)) != GRIB_SUCCESS) + return ret; + } + ret=0; - n=0; - if (bitmapPresent) { - long *bitmap,*pbitmap; - size_t numberOfPoints = 0; + n=0; + if (bitmapPresent) { + long *bitmap,*pbitmap; + size_t numberOfPoints = 0; - if (plSize) { - for (i=0;icontext,sizeof(long)*numberOfPoints); - pbitmap=bitmap; - grib_get_long_array(grib_handle_of_accessor(a),self->bitmap,bitmap,&numberOfPoints); - for (i=0;ibitmap,bitmap,&numberOfPoints); + for (i=0;icontext,pbitmap); - } else { - if (plSize) { - for (i=0;icontext,pbitmap); + } else { + if (plSize) { + for (i=0;ibuffer->data; - long k,i,j,n,Ni,Nj; - double reference_value; - long binary_scale_factor; - long decimal_scale_factor; - double s,d; - size_t groupWidthsSize=0; - int bitmapPresent=0; - size_t plSize=0; - long* pl=0; + grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); + int ret=0; + long numberOfGroups,numberOfSecondOrderPackedValues; + long* groupWidths=0; + long* firstOrderValues=0; + long* X=0; + long numberOfRows,numberOfColumns; + long *numbersPerRow; + long pos=0; + long widthOfFirstOrderValues=0; + long jPointsAreConsecutive; + unsigned char* buf = (unsigned char*)gh->buffer->data; + long k,i,j,n,Ni,Nj; + double reference_value; + long binary_scale_factor; + long decimal_scale_factor; + double s,d; + size_t groupWidthsSize=0; + int bitmapPresent=0; + size_t plSize=0; + long* pl=0; - buf += grib_byte_offset(a); + buf += grib_byte_offset(a); - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfGroups,&numberOfGroups)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_long_internal(gh,self->numberOfGroups,&numberOfGroups)) != GRIB_SUCCESS) + return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->jPointsAreConsecutive,&jPointsAreConsecutive)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_long_internal(gh,self->jPointsAreConsecutive,&jPointsAreConsecutive)) != GRIB_SUCCESS) + return ret; - if (self->bitmap) bitmapPresent=1; - ret=grib_get_size(grib_handle_of_accessor(a),self->pl,&plSize); - if (ret==GRIB_SUCCESS) { + if (self->bitmap) bitmapPresent=1; + ret=grib_get_size(gh,self->pl,&plSize); + if (ret==GRIB_SUCCESS) { pl=(long*)grib_context_malloc_clear(a->context,sizeof(long)*plSize); - if((ret=grib_get_long_array(grib_handle_of_accessor(a),self->pl,pl,&plSize)) != GRIB_SUCCESS) - return ret; - } + if((ret=grib_get_long_array(gh,self->pl,pl,&plSize)) != GRIB_SUCCESS) + return ret; + } - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->Ni,&Ni)) != GRIB_SUCCESS) - return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->Nj,&Nj)) != GRIB_SUCCESS) - return ret; - if (jPointsAreConsecutive) { - numberOfRows=Ni; - numberOfColumns=Nj; - } else { - numberOfRows=Nj; - numberOfColumns=Ni; - } + if((ret=grib_get_long_internal(gh,self->Ni,&Ni)) != GRIB_SUCCESS) + return ret; + if((ret=grib_get_long_internal(gh,self->Nj,&Nj)) != GRIB_SUCCESS) + return ret; + if (jPointsAreConsecutive) { + numberOfRows=Ni; + numberOfColumns=Nj; + } else { + numberOfRows=Nj; + numberOfColumns=Ni; + } numbersPerRow=(long*)grib_context_malloc_clear(a->context,sizeof(long)*numberOfRows); - if (bitmapPresent) { - long *bitmap,*pbitmap; - size_t numberOfPoints=Ni*Nj; + if (bitmapPresent) { + long *bitmap,*pbitmap; + size_t numberOfPoints=Ni*Nj; - if (plSize) { - numberOfPoints=0; - for (i=0;icontext,sizeof(long)*numberOfPoints); - pbitmap=bitmap; - grib_get_long_array(grib_handle_of_accessor(a),self->bitmap,bitmap,&numberOfPoints); - if (plSize) { - for (i=0;ibitmap,bitmap,&numberOfPoints); + if (plSize) { + for (i=0;icontext,pbitmap); - } else { - if (plSize) { - for (i=0;icontext,pbitmap); + } else { + if (plSize) { + for (i=0;iwidthOfFirstOrderValues,&widthOfFirstOrderValues)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_long_internal(gh,self->widthOfFirstOrderValues,&widthOfFirstOrderValues)) != GRIB_SUCCESS) + return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor,&binary_scale_factor)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_long_internal(gh,self->binary_scale_factor,&binary_scale_factor)) != GRIB_SUCCESS) + return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor,&decimal_scale_factor)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_long_internal(gh,self->decimal_scale_factor,&decimal_scale_factor)) != GRIB_SUCCESS) + return ret; - if((ret=grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&reference_value)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_double_internal(gh,self->reference_value,&reference_value)) != GRIB_SUCCESS) + return ret; - if((ret=grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfSecondOrderPackedValues, - &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) - return ret; + if((ret=grib_get_long_internal(gh,self->numberOfSecondOrderPackedValues, + &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) + return ret; groupWidths=(long*)grib_context_malloc_clear(a->context,sizeof(long)*numberOfGroups); - groupWidthsSize=numberOfGroups; - if((ret=grib_get_long_array_internal(grib_handle_of_accessor(a),self->groupWidths, groupWidths,&groupWidthsSize)) != GRIB_SUCCESS) - return ret; + groupWidthsSize=numberOfGroups; + if((ret=grib_get_long_array_internal(gh,self->groupWidths, groupWidths,&groupWidthsSize)) != GRIB_SUCCESS) + return ret; firstOrderValues=(long*)grib_context_malloc_clear(a->context,sizeof(long)*numberOfGroups); - grib_decode_long_array(buf,&pos,widthOfFirstOrderValues,numberOfGroups,firstOrderValues); - pos = 8 * ( (pos + 7 ) / 8); + grib_decode_long_array(buf,&pos,widthOfFirstOrderValues,numberOfGroups,firstOrderValues); + pos = 8 * ( (pos + 7 ) / 8); - n=0; - for (i=0; icontext,sizeof(long)*n); - n=0; - k=0; - for (i=0; i0) { - for (j=0;j0) { + for (j=0;jcontext,firstOrderValues); - grib_context_free(a->context,X); - grib_context_free(a->context,groupWidths); - if (plSize) grib_context_free(a->context,pl); + s = grib_power(binary_scale_factor,2); + d = grib_power(-decimal_scale_factor,10) ; + for (i=0; icontext,firstOrderValues); + grib_context_free(a->context,X); + grib_context_free(a->context,groupWidths); + if (plSize) grib_context_free(a->context,pl); - return ret; + return ret; } static int pack_double(grib_accessor* a, const double* cval, size_t *len) { - char type[]="grid_second_order"; - size_t size=strlen(type); + grib_handle* gh = grib_handle_of_accessor(a); + char type[]="grid_second_order"; + size_t size=strlen(type); - grib_set_string(grib_handle_of_accessor(a),"packingType",type,&size); + grib_set_string(gh,"packingType",type,&size); - return grib_set_double_array(grib_handle_of_accessor(a),"values",cval,*len); + return grib_set_double_array(gh,"values",cval,*len); } - diff --git a/src/grib_accessor_class_data_g22order_packing.c b/src/grib_accessor_class_data_g22order_packing.c index 0da3def0b..235b14215 100644 --- a/src/grib_accessor_class_data_g22order_packing.c +++ b/src/grib_accessor_class_data_g22order_packing.c @@ -181,28 +181,29 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long v, grib_arguments* args) { grib_accessor_data_g22order_packing *self =(grib_accessor_data_g22order_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->reference_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->numberOfValues = grib_arguments_get_name(gh,args,self->carg++); + self->bits_per_value = grib_arguments_get_name(gh,args,self->carg++); + self->reference_value = grib_arguments_get_name(gh,args,self->carg++); + self->binary_scale_factor = grib_arguments_get_name(gh,args,self->carg++); + self->decimal_scale_factor = grib_arguments_get_name(gh,args,self->carg++); - self->typeOfOriginalFieldValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->groupSplittingMethodUsed = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->missingValueManagementUsed = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->primaryMissingValueSubstitute = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->secondaryMissingValueSubstitute = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->numberOfGroupsOfDataValues = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->referenceForGroupWidths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->numberOfBitsUsedForTheGroupWidths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->referenceForGroupLengths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->lengthIncrementForTheGroupLengths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->trueLengthOfLastGroup = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->numberOfBitsUsedForTheScaledGroupLengths = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->typeOfOriginalFieldValues = grib_arguments_get_name(gh,args,self->carg++); + self->groupSplittingMethodUsed = grib_arguments_get_name(gh,args,self->carg++); + self->missingValueManagementUsed = grib_arguments_get_name(gh,args,self->carg++); + self->primaryMissingValueSubstitute = grib_arguments_get_name(gh,args,self->carg++); + self->secondaryMissingValueSubstitute = grib_arguments_get_name(gh,args,self->carg++); + self->numberOfGroupsOfDataValues = grib_arguments_get_name(gh,args,self->carg++); + self->referenceForGroupWidths = grib_arguments_get_name(gh,args,self->carg++); + self->numberOfBitsUsedForTheGroupWidths = grib_arguments_get_name(gh,args,self->carg++); + self->referenceForGroupLengths = grib_arguments_get_name(gh,args,self->carg++); + self->lengthIncrementForTheGroupLengths = grib_arguments_get_name(gh,args,self->carg++); + self->trueLengthOfLastGroup = grib_arguments_get_name(gh,args,self->carg++); + self->numberOfBitsUsedForTheScaledGroupLengths = grib_arguments_get_name(gh,args,self->carg++); - self->orderOfSpatialDifferencing = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->numberOfOctetsExtraDescriptors = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + self->orderOfSpatialDifferencing = grib_arguments_get_name(gh,args,self->carg++); + self->numberOfOctetsExtraDescriptors = grib_arguments_get_name(gh,args,self->carg++); a->flags |= GRIB_ACCESSOR_FLAG_DATA; } @@ -386,8 +387,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) int err = GRIB_SUCCESS; unsigned long* sec_val = NULL; + grib_handle* gh = grib_handle_of_accessor(a); - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + unsigned char* buf = (unsigned char*)gh->buffer->data; unsigned char* buf_ref = NULL; unsigned char* buf_width = NULL; unsigned char* buf_length = NULL; @@ -427,25 +429,25 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) err=grib_value_count(a,&n_vals); if (err) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value )) != GRIB_SUCCESS) return err; - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&reference_value )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor,&binary_scale_factor )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor,&decimal_scale_factor )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->typeOfOriginalFieldValues,&typeOfOriginalFieldValues )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->groupSplittingMethodUsed,&groupSplittingMethodUsed )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->missingValueManagementUsed,&missingValueManagementUsed )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->primaryMissingValueSubstitute,&primaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->secondaryMissingValueSubstitute,&secondaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfGroupsOfDataValues,&numberOfGroupsOfDataValues )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->referenceForGroupWidths,&referenceForGroupWidths )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfBitsUsedForTheGroupWidths,&numberOfBitsUsedForTheGroupWidths )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->referenceForGroupLengths,&referenceForGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value )) != GRIB_SUCCESS) return err; + if((err = grib_get_double_internal(gh,self->reference_value,&reference_value )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->binary_scale_factor,&binary_scale_factor )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->decimal_scale_factor,&decimal_scale_factor )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->typeOfOriginalFieldValues,&typeOfOriginalFieldValues )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->groupSplittingMethodUsed,&groupSplittingMethodUsed )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->missingValueManagementUsed,&missingValueManagementUsed )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->primaryMissingValueSubstitute,&primaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->secondaryMissingValueSubstitute,&secondaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->numberOfGroupsOfDataValues,&numberOfGroupsOfDataValues )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->referenceForGroupWidths,&referenceForGroupWidths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->numberOfBitsUsedForTheGroupWidths,&numberOfBitsUsedForTheGroupWidths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->referenceForGroupLengths,&referenceForGroupLengths )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->lengthIncrementForTheGroupLengths,&lengthIncrementForTheGroupLengths )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->trueLengthOfLastGroup,&trueLengthOfLastGroup )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfBitsUsedForTheScaledGroupLengths,&numberOfBitsUsedForTheScaledGroupLengths )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->orderOfSpatialDifferencing,&orderOfSpatialDifferencing )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfOctetsExtraDescriptors,&numberOfOctetsExtraDescriptors )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->lengthIncrementForTheGroupLengths,&lengthIncrementForTheGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->trueLengthOfLastGroup,&trueLengthOfLastGroup )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->numberOfBitsUsedForTheScaledGroupLengths,&numberOfBitsUsedForTheScaledGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->orderOfSpatialDifferencing,&orderOfSpatialDifferencing )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->numberOfOctetsExtraDescriptors,&numberOfOctetsExtraDescriptors )) != GRIB_SUCCESS) return err; self->dirty=0; @@ -542,6 +544,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_data_g22order_packing* self = (grib_accessor_data_g22order_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; size_t j = 0; @@ -555,7 +558,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) unsigned char* buf_length = NULL; unsigned char* buf_vals = NULL; - double d = 0; double divisor = 0; @@ -581,7 +583,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) long nbits_per_group_val = 0; long group_ref_val = 0; - long binary_scale_factor; long decimal_scale_factor; long typeOfOriginalFieldValues; @@ -602,15 +603,15 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) if (*len ==0) return GRIB_NO_VALUES; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor,&decimal_scale_factor )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->typeOfOriginalFieldValues,&typeOfOriginalFieldValues )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->groupSplittingMethodUsed,&groupSplittingMethodUsed )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->missingValueManagementUsed,&missingValueManagementUsed )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->primaryMissingValueSubstitute,&primaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->secondaryMissingValueSubstitute,&secondaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfBitsUsedForTheGroupWidths,&numberOfBitsUsedForTheGroupWidths )) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->numberOfBitsUsedForTheScaledGroupLengths,&numberOfBitsUsedForTheScaledGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->decimal_scale_factor,&decimal_scale_factor )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->typeOfOriginalFieldValues,&typeOfOriginalFieldValues )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->groupSplittingMethodUsed,&groupSplittingMethodUsed )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->missingValueManagementUsed,&missingValueManagementUsed )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->primaryMissingValueSubstitute,&primaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->secondaryMissingValueSubstitute,&secondaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->numberOfBitsUsedForTheGroupWidths,&numberOfBitsUsedForTheGroupWidths )) != GRIB_SUCCESS) return err; + if((err = grib_get_long_internal(gh,self->numberOfBitsUsedForTheScaledGroupLengths,&numberOfBitsUsedForTheScaledGroupLengths )) != GRIB_SUCCESS) return err; self->dirty=1; @@ -639,7 +640,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) min *= d; max *= d; - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value,min,&reference_value) + if (grib_get_nearest_smaller_value(gh,self->reference_value,min,&reference_value) !=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); @@ -712,31 +713,31 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) grib_context_free (a->context,buf); grib_context_free (a->context,sec_val); - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->bits_per_value,bits_per_value )) != GRIB_SUCCESS) return err; - if((err = grib_set_double_internal(grib_handle_of_accessor(a),self->reference_value,reference_value )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->bits_per_value,bits_per_value )) != GRIB_SUCCESS) return err; + if((err = grib_set_double_internal(gh,self->reference_value,reference_value )) != GRIB_SUCCESS) return err; { /* Make sure we can decode it again */ double ref = 1e-100; - grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&ref); + grib_get_double_internal(gh,self->reference_value,&ref); Assert(ref == reference_value); } - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor,binary_scale_factor )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor,decimal_scale_factor )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->typeOfOriginalFieldValues,typeOfOriginalFieldValues )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->groupSplittingMethodUsed,groupSplittingMethodUsed )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->missingValueManagementUsed,missingValueManagementUsed )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->primaryMissingValueSubstitute,primaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->secondaryMissingValueSubstitute,secondaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->numberOfGroupsOfDataValues,numberOfGroupsOfDataValues )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->referenceForGroupWidths,referenceForGroupWidths )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->numberOfBitsUsedForTheGroupWidths,numberOfBitsUsedForTheGroupWidths )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->referenceForGroupLengths,referenceForGroupLengths )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->lengthIncrementForTheGroupLengths,lengthIncrementForTheGroupLengths )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->trueLengthOfLastGroup,trueLengthOfLastGroup )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->numberOfBitsUsedForTheScaledGroupLengths,numberOfBitsUsedForTheScaledGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->binary_scale_factor,binary_scale_factor )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->decimal_scale_factor,decimal_scale_factor )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->typeOfOriginalFieldValues,typeOfOriginalFieldValues )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->groupSplittingMethodUsed,groupSplittingMethodUsed )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->missingValueManagementUsed,missingValueManagementUsed )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->primaryMissingValueSubstitute,primaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->secondaryMissingValueSubstitute,secondaryMissingValueSubstitute )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->numberOfGroupsOfDataValues,numberOfGroupsOfDataValues )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->referenceForGroupWidths,referenceForGroupWidths )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->numberOfBitsUsedForTheGroupWidths,numberOfBitsUsedForTheGroupWidths )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->referenceForGroupLengths,referenceForGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->lengthIncrementForTheGroupLengths,lengthIncrementForTheGroupLengths )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->trueLengthOfLastGroup,trueLengthOfLastGroup )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->numberOfBitsUsedForTheScaledGroupLengths,numberOfBitsUsedForTheScaledGroupLengths )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->orderOfSpatialDifferencing,0 )) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->numberOfOctetsExtraDescriptors,0 )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->orderOfSpatialDifferencing,0 )) != GRIB_SUCCESS) return err; + if((err = grib_set_long_internal(gh,self->numberOfOctetsExtraDescriptors,0 )) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } diff --git a/src/grib_accessor_class_data_simple_packing.c b/src/grib_accessor_class_data_simple_packing.c index c10d08af8..eaa449426 100644 --- a/src/grib_accessor_class_data_simple_packing.c +++ b/src/grib_accessor_class_data_simple_packing.c @@ -163,14 +163,15 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long v, grib_arguments* args) { grib_accessor_data_simple_packing *self =(grib_accessor_data_simple_packing*)a; - self->units_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->units_bias = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->changing_precision = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->reference_value = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++); + grib_handle* gh = grib_handle_of_accessor(a); + self->units_factor = grib_arguments_get_name(gh,args,self->carg++); + self->units_bias = grib_arguments_get_name(gh,args,self->carg++); + self->changing_precision = grib_arguments_get_name(gh,args,self->carg++); + self->number_of_values = grib_arguments_get_name(gh,args,self->carg++); + self->bits_per_value = grib_arguments_get_name(gh,args,self->carg++); + self->reference_value = grib_arguments_get_name(gh,args,self->carg++); + self->binary_scale_factor = grib_arguments_get_name(gh,args,self->carg++); + self->decimal_scale_factor = grib_arguments_get_name(gh,args,self->carg++); a->flags |= GRIB_ACCESSOR_FLAG_DATA; self->dirty=1; } @@ -213,12 +214,13 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) long n_vals; int err = 0; + grib_handle* gh = grib_handle_of_accessor(a); double reference_value; long binary_scale_factor; long bits_per_value; long decimal_scale_factor; - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + unsigned char* buf = (unsigned char*)gh->buffer->data; double s = 0; double d = 0; long pos = 0; @@ -227,21 +229,21 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) err=grib_value_count(a,&n_vals); if (err) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) != + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return err; self->dirty=0; - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value, &reference_value)) != + if((err = grib_get_double_internal(gh,self->reference_value, &reference_value)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, &binary_scale_factor)) + if((err = grib_get_long_internal(gh,self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, &decimal_scale_factor)) + if((err = grib_get_long_internal(gh,self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; @@ -301,6 +303,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) static int _unpack_double(grib_accessor* a, double* val, size_t *len,unsigned char* buf,long pos, size_t n_vals) { grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; int err = 0; @@ -320,7 +323,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t *len,unsigned c return GRIB_ARRAY_TOO_SMALL; } - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) != + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return err; @@ -333,13 +336,13 @@ static int _unpack_double(grib_accessor* a, double* val, size_t *len,unsigned c } if(self->units_factor && - (grib_get_double_internal(grib_handle_of_accessor(a),self->units_factor,&units_factor)== GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a),self->units_factor,1.0); + (grib_get_double_internal(gh,self->units_factor,&units_factor)== GRIB_SUCCESS)) { + grib_set_double_internal(gh,self->units_factor,1.0); } if(self->units_bias && - (grib_get_double_internal(grib_handle_of_accessor(a),self->units_bias,&units_bias)== GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a),self->units_bias,0.0); + (grib_get_double_internal(gh,self->units_bias,&units_bias)== GRIB_SUCCESS)) { + grib_set_double_internal(gh,self->units_bias,0.0); } if(n_vals==0){ @@ -349,15 +352,15 @@ static int _unpack_double(grib_accessor* a, double* val, size_t *len,unsigned c self->dirty=0; - if((err = grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value, &reference_value)) != + if((err = grib_get_double_internal(gh,self->reference_value, &reference_value)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, &binary_scale_factor)) + if((err = grib_get_long_internal(gh,self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, &decimal_scale_factor)) + if((err = grib_get_long_internal(gh,self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; @@ -419,7 +422,8 @@ static int unpack_double_subarray(grib_accessor* a, double* val, size_t start, s return _unpack_double(a,val,plen,buf,pos,nvals); } -static int unpack_double(grib_accessor* a, double* val, size_t *len) { +static int unpack_double(grib_accessor* a, double* val, size_t *len) +{ unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; size_t nvals=0; long pos=0; @@ -463,6 +467,7 @@ static int producing_large_constant_fields(const grib_context* c, grib_handle* h static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; size_t n_vals = *len; @@ -490,13 +495,13 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) return GRIB_NO_VALUES; } - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->bits_per_value,&bits_per_value)) != + if((err = grib_get_long_internal(gh,self->bits_per_value,&bits_per_value)) != GRIB_SUCCESS) return err; if(*len == 0) return GRIB_SUCCESS; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, &decimal_scale_factor_get)) + if((err = grib_get_long_internal(gh,self->decimal_scale_factor, &decimal_scale_factor_get)) != GRIB_SUCCESS) return err; /*/ @@ -523,37 +528,37 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) /* constant field only reference_value is set and bits_per_value=0 */ if(max==min) { int large_constant_fields = 0; - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value,val[0],&reference_value) + if (grib_get_nearest_smaller_value(gh,self->reference_value,val[0],&reference_value) !=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); return GRIB_INTERNAL_ERROR; } - if((err = grib_set_double_internal(grib_handle_of_accessor(a),self->reference_value, reference_value)) != + if((err = grib_set_double_internal(gh,self->reference_value, reference_value)) != GRIB_SUCCESS) return err; { /* Make sure we can decode it again */ double ref = 1e-100; - grib_get_double_internal(grib_handle_of_accessor(a),self->reference_value,&ref); + grib_get_double_internal(gh,self->reference_value,&ref); if (ref != reference_value) printf("%.20e != %.20e",ref,reference_value); Assert(ref == reference_value); } - large_constant_fields = producing_large_constant_fields(c, grib_handle_of_accessor(a), self->edition); + large_constant_fields = producing_large_constant_fields(c, gh, self->edition); if (large_constant_fields) { - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, 0)) != + if((err = grib_set_long_internal(gh,self->binary_scale_factor, 0)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, 0)) != + if((err = grib_set_long_internal(gh,self->decimal_scale_factor, 0)) != GRIB_SUCCESS) return err; if (bits_per_value==0) { - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->bits_per_value, 16)) != + if((err = grib_set_long_internal(gh,self->bits_per_value, 16)) != GRIB_SUCCESS) return err; } @@ -561,7 +566,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) return GRIB_SUCCESS; } else { bits_per_value=0; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->bits_per_value, bits_per_value)) != + if((err = grib_set_long_internal(gh,self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) return err; @@ -569,11 +574,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } } - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, &binary_scale_factor)) + if((err = grib_get_long_internal(gh,self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_get_long_internal(grib_handle_of_accessor(a),self->changing_precision, &changing_precision)) + if((err = grib_get_long_internal(gh,self->changing_precision, &changing_precision)) != GRIB_SUCCESS) return err; @@ -588,7 +593,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) self->bits_per_value); bits_per_value=24; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->bits_per_value, + if((err = grib_set_long_internal(gh,self->bits_per_value, bits_per_value))!= GRIB_SUCCESS) return err; } @@ -612,10 +617,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) return err; } /*printf("bits_per_value=%ld\n",bits_per_value);*/ - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->bits_per_value, bits_per_value)) != + if((err = grib_set_long_internal(gh,self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) return err; - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value,min,&reference_value) + if (grib_get_nearest_smaller_value(gh,self->reference_value,min,&reference_value) !=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); @@ -631,7 +636,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) if (max == min) { binary_scale_factor=0; /* divisor=1; */ - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value,min,&reference_value) + if (grib_get_nearest_smaller_value(gh,self->reference_value,min,&reference_value) !=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); @@ -663,7 +668,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) range=(max-min); } - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a),self->reference_value, + if (grib_get_nearest_smaller_value(gh,self->reference_value, min,&reference_value)!=GRIB_SUCCESS) { grib_context_log(a->context,GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s",min,self->reference_value); @@ -674,17 +679,17 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } } - if((err = grib_set_double_internal(grib_handle_of_accessor(a),self->reference_value, reference_value)) != + if((err = grib_set_double_internal(gh,self->reference_value, reference_value)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->changing_precision, 0)) != + if((err = grib_set_long_internal(gh,self->changing_precision, 0)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->binary_scale_factor, binary_scale_factor)) != + if((err = grib_set_long_internal(gh,self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) return err; - if((err = grib_set_long_internal(grib_handle_of_accessor(a),self->decimal_scale_factor, decimal_scale_factor)) + if((err = grib_set_long_internal(gh,self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) return err; diff --git a/src/grib_accessor_class_sum.c b/src/grib_accessor_class_sum.c index 48840a1bb..287cddb7d 100644 --- a/src/grib_accessor_class_sum.c +++ b/src/grib_accessor_class_sum.c @@ -139,89 +139,87 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_sum* self = (grib_accessor_sum*)a; - int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - a->length=0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - + grib_accessor_sum* self = (grib_accessor_sum*)a; + int n = 0; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + a->length=0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int unpack_long (grib_accessor* a, long* val, size_t *len) +static int unpack_long (grib_accessor* a, long* val, size_t *len) { - grib_accessor_sum* self = (grib_accessor_sum*)a; - int ret = 0; - size_t size=0; - long* values=0; - long i; - long count=0; + grib_accessor_sum* self = (grib_accessor_sum*)a; + int ret = 0; + size_t size=0; + long* values=0; + long i; + long count=0; - ret=value_count(a,&count); - if (ret) return ret; - size=count; + ret=value_count(a,&count); + if (ret) return ret; + size=count; - if (size==0) { - *val=0; - return ret; - } - values=(long*)grib_context_malloc_clear(a->context,sizeof(long)*size); - if (!values) return GRIB_OUT_OF_MEMORY; + if (size==0) { + *val=0; + return ret; + } + values=(long*)grib_context_malloc_clear(a->context,sizeof(long)*size); + if (!values) return GRIB_OUT_OF_MEMORY; - grib_get_long_array(grib_handle_of_accessor(a),self->values,values,&size); + grib_get_long_array(grib_handle_of_accessor(a),self->values,values,&size); - *val=0; - for (i=0;icontext,values); + grib_context_free(a->context,values); - return ret; + return ret; } -static int unpack_double (grib_accessor* a, double* val, size_t *len) +static int unpack_double (grib_accessor* a, double* val, size_t *len) { - grib_accessor_sum* self = (grib_accessor_sum*)a; - int ret = 0; - size_t size=0; - double* values=0; - long i; - long count=0; + grib_accessor_sum* self = (grib_accessor_sum*)a; + int ret = 0; + size_t size=0; + double* values=0; + long i; + long count=0; - ret=value_count(a,&count); - if (ret) return ret; - size=count; + ret=value_count(a,&count); + if (ret) return ret; + size=count; - if (size==0) { - *val=0; - return ret; - } - values=(double*)grib_context_malloc_clear(a->context,sizeof(double)*size); - if (!values) return GRIB_OUT_OF_MEMORY; + if (size==0) { + *val=0; + return ret; + } + values=(double*)grib_context_malloc_clear(a->context,sizeof(double)*size); + if (!values) return GRIB_OUT_OF_MEMORY; - grib_get_double_array(grib_handle_of_accessor(a),self->values,values,&size); + grib_get_double_array(grib_handle_of_accessor(a),self->values,values,&size); - *val=0; - for (i=0;icontext,values); + grib_context_free(a->context,values); - return ret; + return ret; } - static int value_count(grib_accessor* a,long* count) { - grib_accessor_sum* self = (grib_accessor_sum*)a; - size_t n=0; - int ret=0; + grib_accessor_sum* self = (grib_accessor_sum*)a; + size_t n=0; + int ret=0; ret = grib_get_size(grib_handle_of_accessor(a), self->values,&n); - *count=n; + *count=n; - if (ret) - grib_context_log(a->context,GRIB_LOG_ERROR, - "%s is unable to get size of %s",a->name,self->values); + if (ret) + grib_context_log(a->context,GRIB_LOG_ERROR, + "%s is unable to get size of %s",a->name,self->values); - return ret; + return ret; } diff --git a/src/grib_accessor_class_suppressed.c b/src/grib_accessor_class_suppressed.c index b232ec347..130aaa47f 100644 --- a/src/grib_accessor_class_suppressed.c +++ b/src/grib_accessor_class_suppressed.c @@ -135,73 +135,73 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_suppressed* self = (grib_accessor_suppressed*)a; - self->args = c; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length=0; + grib_accessor_suppressed* self = (grib_accessor_suppressed*)a; + self->args = c; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length=0; } -static void log_message(grib_accessor* a) { - grib_accessor_suppressed* self = (grib_accessor_suppressed*)a; - int i=0; - - grib_context_log(a->context,GRIB_LOG_ERROR, - "key %s is unvailable in this version.",a->name); - grib_context_log(a->context,GRIB_LOG_ERROR, - "Please use the following keys:"); - while (grib_arguments_get_name(grib_handle_of_accessor(a),self->args,i)) { +static void log_message(grib_accessor* a) +{ + grib_accessor_suppressed* self = (grib_accessor_suppressed*)a; + int i=0; + grib_context_log(a->context,GRIB_LOG_ERROR, - "\t- %s", - grib_arguments_get_name(grib_handle_of_accessor(a),self->args,i)); - i++; - } + "key %s is unavailable in this version.",a->name); + grib_context_log(a->context,GRIB_LOG_ERROR, + "Please use the following keys:"); + while (grib_arguments_get_name(grib_handle_of_accessor(a),self->args,i)) { + grib_context_log(a->context,GRIB_LOG_ERROR, + "\t- %s", + grib_arguments_get_name(grib_handle_of_accessor(a),self->args,i)); + i++; + } } -static int pack_string(grib_accessor* a, const char* val, size_t *len){ - - log_message(a); - return GRIB_NOT_IMPLEMENTED; - +static int pack_string(grib_accessor* a, const char* val, size_t *len) +{ + log_message(a); + return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* val, size_t *len){ - - log_message(a); - return GRIB_NOT_IMPLEMENTED; - +static int pack_long(grib_accessor* a, const long* val, size_t *len) +{ + log_message(a); + return GRIB_NOT_IMPLEMENTED; } -static int pack_double(grib_accessor* a, const double* val, size_t *len){ - - log_message(a); - return GRIB_NOT_IMPLEMENTED; - +static int pack_double(grib_accessor* a, const double* val, size_t *len) +{ + log_message(a); + return GRIB_NOT_IMPLEMENTED; } - -static int unpack_string(grib_accessor* a, char* val, size_t *len) +static int unpack_string(grib_accessor* a, char* val, size_t *len) { - /*log_message(a);*/ - return GRIB_NOT_IMPLEMENTED; + /*log_message(a);*/ + return GRIB_NOT_IMPLEMENTED; } static int unpack_long(grib_accessor* a, long* val, size_t *len) { - log_message(a); - return GRIB_NOT_IMPLEMENTED; + log_message(a); + return GRIB_NOT_IMPLEMENTED; } static int unpack_double(grib_accessor* a, double* val, size_t *len) { - log_message(a); - return GRIB_NOT_IMPLEMENTED; + log_message(a); + return GRIB_NOT_IMPLEMENTED; } - -static int value_count(grib_accessor* a,long* count) { *count=1;return 0; } - -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_STRING; +static int value_count(grib_accessor* a,long* count) +{ + *count=1; + return 0; } +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} diff --git a/src/grib_accessor_class_time.c b/src/grib_accessor_class_time.c index 3c24a0e92..99835a587 100644 --- a/src/grib_accessor_class_time.c +++ b/src/grib_accessor_class_time.c @@ -138,101 +138,101 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_time* self = (grib_accessor_time*)a; - int n = 0; + grib_accessor_time* self = (grib_accessor_time*)a; + int n = 0; - self->hour = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->minute = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->second = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->hour = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->minute = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->second = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_long(dumper,a,NULL); + grib_dump_long(dumper,a,NULL); } static int unpack_long(grib_accessor* a, long* val, size_t *len) { - int ret=0; - grib_accessor_time* self = (grib_accessor_time*)a; + int ret=0; + grib_accessor_time* self = (grib_accessor_time*)a; - long hour = 0; - long minute = 0; - long second = 0; + long hour = 0; + long minute = 0; + long second = 0; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->hour,&hour))!=GRIB_SUCCESS) - return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->minute,&minute))!=GRIB_SUCCESS) - return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->second,&second))!=GRIB_SUCCESS) - return ret; + if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->hour,&hour))!=GRIB_SUCCESS) + return ret; + if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->minute,&minute))!=GRIB_SUCCESS) + return ret; + if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->second,&second))!=GRIB_SUCCESS) + return ret; - /* We ignore the 'seconds' in our time calculation! */ - if (second != 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Truncating time: non-zero seconds(%d) ignored", second); - } + /* We ignore the 'seconds' in our time calculation! */ + if (second != 0) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Truncating time: non-zero seconds(%d) ignored", second); + } - if(*len < 1) - return GRIB_WRONG_ARRAY_SIZE; + if(*len < 1) + return GRIB_WRONG_ARRAY_SIZE; - *val = hour*100 + minute; + *val = hour*100 + minute; - if(hour == 255) - *val = 12*100; + if(hour == 255) + *val = 12*100; - if(hour != 255 && minute == 255) - *val = hour*100; + if(hour != 255 && minute == 255) + *val = hour*100; - return GRIB_SUCCESS; + return GRIB_SUCCESS; } /* TODO: Check for a valid date */ static int pack_long(grib_accessor* a, const long* val, size_t *len) { - int ret=0; - long v = val[0]; - grib_accessor_time* self = (grib_accessor_time*)a; + int ret=0; + long v = val[0]; + grib_accessor_time* self = (grib_accessor_time*)a; - long hour = 0; - long minute = 0; - long second = 0; + long hour = 0; + long minute = 0; + long second = 0; - if(*len != 1) - return GRIB_WRONG_ARRAY_SIZE; + if(*len != 1) + return GRIB_WRONG_ARRAY_SIZE; - hour = v / 100; - minute = v % 100; - second = 0; /* We ignore the 'seconds' in our time calculation! */ + hour = v / 100; + minute = v % 100; + second = 0; /* We ignore the 'seconds' in our time calculation! */ - if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->hour,hour))!=GRIB_SUCCESS) - return ret; - if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->minute,minute))!=GRIB_SUCCESS) - return ret; - if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->second,second))!=GRIB_SUCCESS) - return ret; + if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->hour,hour))!=GRIB_SUCCESS) + return ret; + if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->minute,minute))!=GRIB_SUCCESS) + return ret; + if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->second,second))!=GRIB_SUCCESS) + return ret; - return GRIB_SUCCESS; + return GRIB_SUCCESS; } static int unpack_string(grib_accessor* a, char* val, size_t *len) { - long v = 0; - size_t lsize = 1; + long v = 0; + size_t lsize = 1; - unpack_long(a, &v, &lsize); + unpack_long(a, &v, &lsize); - if(*len < 5) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_time : unpack_string : Buffer too small for %s ", a->name ); + if(*len < 5) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_time : unpack_string : Buffer too small for %s ", a->name ); - *len = 5; - return GRIB_BUFFER_TOO_SMALL; - } + *len = 5; + return GRIB_BUFFER_TOO_SMALL; + } - sprintf(val,"%04ld",v); + sprintf(val,"%04ld",v); - len[0] = 5; - return GRIB_SUCCESS; + len[0] = 5; + return GRIB_SUCCESS; } diff --git a/src/grib_accessor_class_to_double.c b/src/grib_accessor_class_to_double.c index c0bc0226f..d80d58872 100644 --- a/src/grib_accessor_class_to_double.c +++ b/src/grib_accessor_class_to_double.c @@ -147,172 +147,174 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len , grib_arguments* arg ) { - grib_accessor_to_double* self=(grib_accessor_to_double*)a; + grib_accessor_to_double* self=(grib_accessor_to_double*)a; - self->key=grib_arguments_get_name(grib_handle_of_accessor(a),arg,0); - self->start=grib_arguments_get_long(grib_handle_of_accessor(a),arg,1); - self->length=grib_arguments_get_long(grib_handle_of_accessor(a),arg,2); - self->scale=grib_arguments_get_long(grib_handle_of_accessor(a),arg,3); - if (!self->scale) self->scale=1; + self->key=grib_arguments_get_name(grib_handle_of_accessor(a),arg,0); + self->start=grib_arguments_get_long(grib_handle_of_accessor(a),arg,1); + self->length=grib_arguments_get_long(grib_handle_of_accessor(a),arg,2); + self->scale=grib_arguments_get_long(grib_handle_of_accessor(a),arg,3); + if (!self->scale) self->scale=1; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length=0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length=0; } static void post_init(grib_accessor* a ) { - return; + return; } -static int value_count(grib_accessor* a,long* count){ - grib_accessor_to_double* self=(grib_accessor_to_double*)a; - size_t size=0; +static int value_count(grib_accessor* a,long* count) +{ + grib_accessor_to_double* self=(grib_accessor_to_double*)a; + size_t size=0; - int err=grib_get_size(grib_handle_of_accessor(a), self->key,&size); - *count=size; + int err=grib_get_size(grib_handle_of_accessor(a), self->key,&size); + *count=size; - return err; + return err; } -static size_t string_length(grib_accessor* a){ - grib_accessor_to_double* self=(grib_accessor_to_double*)a; - size_t size=0; +static size_t string_length(grib_accessor* a) +{ + grib_accessor_to_double* self=(grib_accessor_to_double*)a; + size_t size=0; - if (self->length) return self->length; + if (self->length) return self->length; - _grib_get_string_length(a,&size); - return size; + _grib_get_string_length(a,&size); + return size; } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_string(dumper,a,NULL); + grib_dump_string(dumper,a,NULL); } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_LONG; +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; } static int unpack_string(grib_accessor* a, char* val, size_t *len) { - int err=0; - grib_accessor_to_double* self=(grib_accessor_to_double*)a; - char buff[512]={0,}; - size_t length; - size_t size=512; + int err=0; + grib_accessor_to_double* self=(grib_accessor_to_double*)a; + char buff[512]={0,}; + size_t length; + size_t size=512; - length=string_length(a); + length=string_length(a); - if( len[0] < length+1 ) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } + if( len[0] < length+1 ) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } - err=grib_get_string(grib_handle_of_accessor(a),self->key,buff,&size); - if (err) return err; - if (length > size) { - err=GRIB_STRING_TOO_SMALL; - length=size; - } + err=grib_get_string(grib_handle_of_accessor(a),self->key,buff,&size); + if (err) return err; + if (length > size) { + err=GRIB_STRING_TOO_SMALL; + length=size; + } - memcpy(val,buff+self->start,length); + memcpy(val,buff+self->start,length); - val[length] = 0; - len[0] = length; - return GRIB_SUCCESS; + val[length] = 0; + len[0] = length; + return GRIB_SUCCESS; } static int pack_string(grib_accessor* a, const char* val, size_t *len) { - - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_long(grib_accessor* a, const long* v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); + return GRIB_NOT_IMPLEMENTED; } -static int pack_double(grib_accessor* a, const double*v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_double(grib_accessor* a, const double*v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); + return GRIB_NOT_IMPLEMENTED; } +static int unpack_long (grib_accessor* a, long* v, size_t *len) +{ + grib_accessor_to_double* self=(grib_accessor_to_double*)a; + char val[1024]={0,}; + size_t l = sizeof(val); + char *last = NULL; + int err=grib_unpack_string (a , val, &l); -static int unpack_long (grib_accessor* a, long* v, size_t *len){ + if (err) return err; - grib_accessor_to_double* self=(grib_accessor_to_double*)a; - char val[1024]={0,}; - size_t l = sizeof(val); - char *last = NULL; - int err=grib_unpack_string (a , val, &l); - - if (err) return err; - - *v = strtol(val,&last,10); - if (*last) {err=GRIB_WRONG_CONVERSION;} - *v/=self->scale; - - return err; + *v = strtol(val,&last,10); + if (*last) {err=GRIB_WRONG_CONVERSION;} + *v/=self->scale; + return err; } -static int unpack_double (grib_accessor* a, double* v, size_t *len){ +static int unpack_double (grib_accessor* a, double* v, size_t *len) +{ + grib_accessor_to_double* self=(grib_accessor_to_double*)a; + char val[1024]={0,}; + size_t l = sizeof(val); + char *last = NULL; + int err=grib_unpack_string (a , val, &l); - grib_accessor_to_double* self=(grib_accessor_to_double*)a; - char val[1024]={0,}; - size_t l = sizeof(val); - char *last = NULL; - int err=grib_unpack_string (a , val, &l); + if (err) return err; - if (err) return err; + *v = strtod(val,&last); + if (*last) {err=GRIB_WRONG_CONVERSION;} + *v/=self->scale; - *v = strtod(val,&last); - if (*last) {err=GRIB_WRONG_CONVERSION;} - *v/=self->scale; - - return err; + return err; } static long next_offset(grib_accessor* a) { - return a->offset+a->length; + return a->offset+a->length; } -static int compare(grib_accessor* a,grib_accessor* b) { - int retval=0; - char *aval=0; - char *bval=0; - int err=0; +static int compare(grib_accessor* a,grib_accessor* b) +{ + int retval=0; + char *aval=0; + char *bval=0; + int err=0; - size_t alen = 0; - size_t blen = 0; - long count=0; + size_t alen = 0; + size_t blen = 0; + long count=0; - err=grib_value_count(a,&count); - if (err) return err; - alen=count; + err=grib_value_count(a,&count); + if (err) return err; + alen=count; - err=grib_value_count(b,&count); - if (err) return err; - blen=count; + err=grib_value_count(b,&count); + if (err) return err; + blen=count; - if (alen != blen) return GRIB_COUNT_MISMATCH; + if (alen != blen) return GRIB_COUNT_MISMATCH; - aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); - bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); + aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); + bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); - grib_unpack_string(a,aval,&alen); - grib_unpack_string(b,bval,&blen); + grib_unpack_string(a,aval,&alen); + grib_unpack_string(b,bval,&blen); - retval = GRIB_SUCCESS; - if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; + retval = GRIB_SUCCESS; + if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; - grib_context_free(a->context,aval); - grib_context_free(b->context,bval); + grib_context_free(a->context,aval); + grib_context_free(b->context,bval); - return retval; + return retval; } - diff --git a/src/grib_accessor_class_to_integer.c b/src/grib_accessor_class_to_integer.c index 448d26a37..2632e51e4 100644 --- a/src/grib_accessor_class_to_integer.c +++ b/src/grib_accessor_class_to_integer.c @@ -145,161 +145,163 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len , grib_arguments* arg ) { - grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; + grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; - self->key=grib_arguments_get_name(grib_handle_of_accessor(a),arg,0); - self->start=grib_arguments_get_long(grib_handle_of_accessor(a),arg,1); - self->length=grib_arguments_get_long(grib_handle_of_accessor(a),arg,2); + self->key=grib_arguments_get_name(grib_handle_of_accessor(a),arg,0); + self->start=grib_arguments_get_long(grib_handle_of_accessor(a),arg,1); + self->length=grib_arguments_get_long(grib_handle_of_accessor(a),arg,2); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length=0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length=0; } static void post_init(grib_accessor* a ) { - return; + return; } -static int value_count(grib_accessor* a,long* count){ - grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; - size_t size=0; +static int value_count(grib_accessor* a,long* count) +{ + grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; + size_t size=0; - int err=grib_get_size(grib_handle_of_accessor(a), self->key,&size); - *count=size; + int err=grib_get_size(grib_handle_of_accessor(a), self->key,&size); + *count=size; - return err; + return err; } -static size_t string_length(grib_accessor* a){ - grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; - size_t size=0; +static size_t string_length(grib_accessor* a) +{ + grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; + size_t size=0; - if (self->length) return self->length; + if (self->length) return self->length; - grib_get_string_length(grib_handle_of_accessor(a),self->key,&size); - return size; + grib_get_string_length(grib_handle_of_accessor(a),self->key,&size); + return size; } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_long(dumper,a,NULL); + grib_dump_long(dumper,a,NULL); } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_LONG; +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; } static int unpack_string(grib_accessor* a, char* val, size_t *len) { - int err=0; - grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; - char buff[512]={0,}; - size_t length; - size_t size=512; + int err=0; + grib_accessor_to_integer* self=(grib_accessor_to_integer*)a; + char buff[512]={0,}; + size_t length; + size_t size=512; - length=string_length(a); + length=string_length(a); - if( len[0] < length+1 ) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } + if( len[0] < length+1 ) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } - err=grib_get_string(grib_handle_of_accessor(a),self->key,buff,&size); - if (err) return err; - if (length > size) { - err=GRIB_STRING_TOO_SMALL; - length=size; - } + err=grib_get_string(grib_handle_of_accessor(a),self->key,buff,&size); + if (err) return err; + if (length > size) { + err=GRIB_STRING_TOO_SMALL; + length=size; + } - memcpy(val,buff+self->start,length); + memcpy(val,buff+self->start,length); - val[length] = 0; - len[0] = length; - return GRIB_SUCCESS; + val[length] = 0; + len[0] = length; + return GRIB_SUCCESS; } static int pack_string(grib_accessor* a, const char* val, size_t *len) { - - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_long(grib_accessor* a, const long* v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); + return GRIB_NOT_IMPLEMENTED; } -static int pack_double(grib_accessor* a, const double*v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_double(grib_accessor* a, const double*v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); + return GRIB_NOT_IMPLEMENTED; } +static int unpack_long (grib_accessor* a, long* v, size_t *len) +{ + char val[1024]={0,}; + size_t l = sizeof(val); + char *last = NULL; + int err=unpack_string (a , val, &l); -static int unpack_long (grib_accessor* a, long* v, size_t *len){ + if (err) return err; - char val[1024]={0,}; - size_t l = sizeof(val); - char *last = NULL; - int err=unpack_string (a , val, &l); - - if (err) return err; - - *v = strtol(val,&last,10); - /* if (*last) {err=GRIB_WRONG_CONVERSION;} */ - - return err; + *v = strtol(val,&last,10); + /* if (*last) {err=GRIB_WRONG_CONVERSION;} */ + return err; } -static int unpack_double (grib_accessor* a, double *v, size_t *len){ - size_t l=1; - long val; - int err = unpack_long (a , &val, &l); +static int unpack_double (grib_accessor* a, double *v, size_t *len) +{ + size_t l=1; + long val; + int err = unpack_long (a , &val, &l); - *v = (double)val; - return err; + *v = (double)val; + return err; } +static int compare(grib_accessor* a,grib_accessor* b) +{ + int retval=0; + char *aval=0; + char *bval=0; + int err=0; -static int compare(grib_accessor* a,grib_accessor* b) { - int retval=0; - char *aval=0; - char *bval=0; - int err=0; + size_t alen = 0; + size_t blen = 0; + long count=0; - size_t alen = 0; - size_t blen = 0; - long count=0; + err=grib_value_count(a,&count); + if (err) return err; + alen=count; - err=grib_value_count(a,&count); - if (err) return err; - alen=count; + err=grib_value_count(b,&count); + if (err) return err; + blen=count; - err=grib_value_count(b,&count); - if (err) return err; - blen=count; + if (alen != blen) return GRIB_COUNT_MISMATCH; - if (alen != blen) return GRIB_COUNT_MISMATCH; + aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); + bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); - aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); - bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); + grib_unpack_string(a,aval,&alen); + grib_unpack_string(b,bval,&blen); - grib_unpack_string(a,aval,&alen); - grib_unpack_string(b,bval,&blen); + retval = GRIB_SUCCESS; + if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; - retval = GRIB_SUCCESS; - if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; + grib_context_free(a->context,aval); + grib_context_free(b->context,bval); - grib_context_free(a->context,aval); - grib_context_free(b->context,bval); - - return retval; + return retval; } static long next_offset(grib_accessor* a) { - return a->offset+a->length; + return a->offset+a->length; } - diff --git a/src/grib_accessor_class_to_string.c b/src/grib_accessor_class_to_string.c index e8265f2f9..98653d0ca 100644 --- a/src/grib_accessor_class_to_string.c +++ b/src/grib_accessor_class_to_string.c @@ -145,161 +145,163 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len , grib_arguments* arg ) { - grib_accessor_to_string* self=(grib_accessor_to_string*)a; + grib_accessor_to_string* self=(grib_accessor_to_string*)a; - self->key=grib_arguments_get_name(grib_handle_of_accessor(a),arg,0); - self->start=grib_arguments_get_long(grib_handle_of_accessor(a),arg,1); - self->length=grib_arguments_get_long(grib_handle_of_accessor(a),arg,2); + self->key=grib_arguments_get_name(grib_handle_of_accessor(a),arg,0); + self->start=grib_arguments_get_long(grib_handle_of_accessor(a),arg,1); + self->length=grib_arguments_get_long(grib_handle_of_accessor(a),arg,2); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length=0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length=0; } static void post_init(grib_accessor* a ) { - return; + return; } -static int value_count(grib_accessor* a,long* count){ - grib_accessor_to_string* self=(grib_accessor_to_string*)a; - size_t size=0; +static int value_count(grib_accessor* a,long* count) +{ + grib_accessor_to_string* self=(grib_accessor_to_string*)a; + size_t size=0; - int err=grib_get_size(grib_handle_of_accessor(a), self->key,&size); - *count=size; + int err=grib_get_size(grib_handle_of_accessor(a), self->key,&size); + *count=size; - return err; + return err; } -static size_t string_length(grib_accessor* a){ - grib_accessor_to_string* self=(grib_accessor_to_string*)a; - size_t size=0; +static size_t string_length(grib_accessor* a) +{ + grib_accessor_to_string* self=(grib_accessor_to_string*)a; + size_t size=0; - if (self->length) return self->length; + if (self->length) return self->length; - grib_get_string_length(grib_handle_of_accessor(a),self->key,&size); - return size; + grib_get_string_length(grib_handle_of_accessor(a),self->key,&size); + return size; } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_string(dumper,a,NULL); + grib_dump_string(dumper,a,NULL); } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_STRING; +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; } static int unpack_string(grib_accessor* a, char* val, size_t *len) { - int err=0; - grib_accessor_to_string* self=(grib_accessor_to_string*)a; - char buff[512]={0,}; - size_t length; - size_t size=512; + int err=0; + grib_accessor_to_string* self=(grib_accessor_to_string*)a; + char buff[512]={0,}; + size_t length; + size_t size=512; - length=string_length(a); + length=string_length(a); - if( len[0] < length+1 ) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } + if( len[0] < length+1 ) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } - err=grib_get_string(grib_handle_of_accessor(a),self->key,buff,&size); - if (err) return err; - if (length > size) { - err=GRIB_STRING_TOO_SMALL; - length=size; - } + err=grib_get_string(grib_handle_of_accessor(a),self->key,buff,&size); + if (err) return err; + if (length > size) { + err=GRIB_STRING_TOO_SMALL; + length=size; + } - memcpy(val,buff+self->start,length); + memcpy(val,buff+self->start,length); - val[length] = 0; - len[0] = length; - return GRIB_SUCCESS; + val[length] = 0; + len[0] = length; + return GRIB_SUCCESS; } static int pack_string(grib_accessor* a, const char* val, size_t *len) { - - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_long(grib_accessor* a, const long* v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); + return GRIB_NOT_IMPLEMENTED; } -static int pack_double(grib_accessor* a, const double*v, size_t *len){ - grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); - return GRIB_NOT_IMPLEMENTED; +static int pack_double(grib_accessor* a, const double*v, size_t *len) +{ + grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); + return GRIB_NOT_IMPLEMENTED; } +static int unpack_long (grib_accessor* a, long* v, size_t *len) +{ + char val[1024]={0,}; + size_t l = sizeof(val); + char *last = NULL; + int err=unpack_string (a , val, &l); -static int unpack_long (grib_accessor* a, long* v, size_t *len){ + if (err) return err; - char val[1024]={0,}; - size_t l = sizeof(val); - char *last = NULL; - int err=unpack_string (a , val, &l); - - if (err) return err; - - *v = strtol(val,&last,10); - if (*last) {err=GRIB_WRONG_CONVERSION;} - - return err; + *v = strtol(val,&last,10); + if (*last) {err=GRIB_WRONG_CONVERSION;} + return err; } -static int unpack_double (grib_accessor* a, double *v, size_t *len){ - size_t l=1; - long val; - int err = unpack_long (a , &val, &l); +static int unpack_double (grib_accessor* a, double *v, size_t *len) +{ + size_t l=1; + long val; + int err = unpack_long (a , &val, &l); - *v = (double)val; - return err; + *v = (double)val; + return err; } +static int compare(grib_accessor* a,grib_accessor* b) +{ + int retval=0; + char *aval=0; + char *bval=0; + int err=0; -static int compare(grib_accessor* a,grib_accessor* b) { - int retval=0; - char *aval=0; - char *bval=0; - int err=0; + size_t alen = 0; + size_t blen = 0; + long count=0; - size_t alen = 0; - size_t blen = 0; - long count=0; + err=grib_value_count(a,&count); + if (err) return err; + alen=count; - err=grib_value_count(a,&count); - if (err) return err; - alen=count; + err=grib_value_count(b,&count); + if (err) return err; + blen=count; - err=grib_value_count(b,&count); - if (err) return err; - blen=count; + if (alen != blen) return GRIB_COUNT_MISMATCH; - if (alen != blen) return GRIB_COUNT_MISMATCH; + aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); + bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); - aval=(char*)grib_context_malloc(a->context,alen*sizeof(char)); - bval=(char*)grib_context_malloc(b->context,blen*sizeof(char)); + grib_unpack_string(a,aval,&alen); + grib_unpack_string(b,bval,&blen); - grib_unpack_string(a,aval,&alen); - grib_unpack_string(b,bval,&blen); + retval = GRIB_SUCCESS; + if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; - retval = GRIB_SUCCESS; - if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH; + grib_context_free(a->context,aval); + grib_context_free(b->context,bval); - grib_context_free(a->context,aval); - grib_context_free(b->context,bval); - - return retval; + return retval; } static long next_offset(grib_accessor* a) { - return a->offset+a->length; + return a->offset+a->length; } -