Formatting and cleanups

This commit is contained in:
shahramn 2024-07-31 13:12:01 +01:00
parent f7fe36b2cf
commit 2554d17256
22 changed files with 592 additions and 480 deletions

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,16 +10,17 @@
#include "grib_accessor_class_data_apply_boustrophedonic_bitmap.h"
grib_accessor_class_data_apply_boustrophedonic_bitmap_t _grib_accessor_class_data_apply_boustrophedonic_bitmap{"data_apply_boustrophedonic_bitmap"};
grib_accessor_class_data_apply_boustrophedonic_bitmap_t _grib_accessor_class_data_apply_boustrophedonic_bitmap{ "data_apply_boustrophedonic_bitmap" };
grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic_bitmap = &_grib_accessor_class_data_apply_boustrophedonic_bitmap;
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_gen_t::init(a, v, args);
int n = 0;
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
grib_handle* gh = grib_handle_of_accessor(a);
int n = 0;
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++);
@ -33,15 +33,18 @@ void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor
a->length = 0;
}
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_values(dumper, a);
}
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_accessor* a, long* count){
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_accessor* a, long* count)
{
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
size_t len = 0;
int ret = 0;
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(gh, self->bitmap));
@ -51,9 +54,10 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_ac
return ret;
}
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
grib_handle* gh = grib_handle_of_accessor(a);
size_t i = 0, j = 0, n_vals = 0, irow = 0;
long nn = 0;
@ -63,7 +67,8 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_
double missing_value = 0;
long numberOfPoints, numberOfRows, numberOfColumns;
err = a->value_count(&nn); n_vals = nn;
err = a->value_count(&nn);
n_vals = nn;
if (err)
return err;
@ -159,9 +164,10 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_
return err;
}
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0, i = 0;
size_t cidx = 0;
double missing_value = 0;
@ -169,7 +175,8 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
size_t n_vals = 0;
long nn = 0;
err = a->value_count(&nn); n_vals = nn;
err = a->value_count(&nn);
n_vals = nn;
if (err)
return err;
@ -204,19 +211,21 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
return grib_get_double_element_internal(gh, self->coded_values, cidx, val);
}
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0, all_missing = 1;
size_t cidx = 0; /* index into the coded_values array */
size_t* cidx_array = NULL; /* array of indexes into the coded_values */
double* cval_array = NULL; /* array of values of the coded_values */
size_t cidx = 0; /* index into the coded_values array */
size_t* cidx_array = NULL; /* array of indexes into the coded_values */
double* cval_array = NULL; /* array of values of the coded_values */
double missing_value = 0;
double* bvals = NULL;
size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0;
long nn = 0;
err = a->value_count(&nn); n_vals = nn;
err = a->value_count(&nn);
n_vals = nn;
if (err) return err;
if (!grib_find_accessor(gh, self->bitmap))
@ -230,7 +239,8 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
for (i = 0; i < len; i++) {
if (val_array[i] == 0) {
val_array[i] = missing_value;
} else {
}
else {
all_missing = 0;
count_1s++;
}
@ -255,7 +265,7 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
ci = 0;
for (i = 0; i < len; i++) {
if (val_array[i] == 1) {
idx = index_array[i];
idx = index_array[i];
cidx = 0;
for (j = 0; j < idx; j++) {
cidx += bvals[j];
@ -282,17 +292,19 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme
return GRIB_SUCCESS;
}
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0;
size_t bmaplen = *len;
size_t irow = 0;
long coded_n_vals = 0;
double* coded_vals = NULL;
double* values = 0;
long i = 0;
long j = 0;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0;
size_t bmaplen = *len;
size_t irow = 0;
long coded_n_vals = 0;
double* coded_vals = NULL;
double* values = 0;
long i = 0;
long j = 0;
long numberOfPoints, numberOfRows, numberOfColumns;
double missing_value = 0;
@ -381,9 +393,10 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac
return err;
}
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::get_native_type(grib_accessor* a){
//grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
//return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::get_native_type(grib_accessor* a)
{
// grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
// return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
return GRIB_TYPE_DOUBLE;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,24 +10,26 @@
#include "grib_accessor_class_data_dummy_field.h"
grib_accessor_class_data_dummy_field_t _grib_accessor_class_data_dummy_field{"data_dummy_field"};
grib_accessor_class_data_dummy_field_t _grib_accessor_class_data_dummy_field{ "data_dummy_field" };
grib_accessor_class* grib_accessor_class_data_dummy_field = &_grib_accessor_class_data_dummy_field;
void grib_accessor_class_data_dummy_field_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_dummy_field_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_g1simple_packing_t::init(a, v, args);
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->numberOfPoints = 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->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->numberOfPoints = 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++);
}
int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
size_t i = 0, n_vals = 0;
long numberOfPoints;
double missing_value = 0;
int err = 0;
int err = 0;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS)
return err;
@ -54,15 +55,16 @@ int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, doub
return err;
}
int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
size_t n_vals = *len;
int err = 0;
size_t n_vals = *len;
int err = 0;
long bits_per_value = 0;
long half_byte = 0;
size_t buflen = 0;
unsigned char* buf = NULL;
long half_byte = 0;
size_t buflen = 0;
unsigned char* buf = NULL;
if (*len == 0)
return GRIB_NO_VALUES;
@ -89,9 +91,10 @@ int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const
return GRIB_SUCCESS;
}
int grib_accessor_class_data_dummy_field_t::value_count(grib_accessor* a, long* numberOfPoints){
int grib_accessor_class_data_dummy_field_t::value_count(grib_accessor* a, long* numberOfPoints)
{
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
int err = 0;
int err = 0;
*numberOfPoints = 0;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints)) != GRIB_SUCCESS) {

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,58 +10,62 @@
#include "grib_accessor_class_data_g1complex_packing.h"
grib_accessor_class_data_g1complex_packing_t _grib_accessor_class_data_g1complex_packing{"data_g1complex_packing"};
grib_accessor_class_data_g1complex_packing_t _grib_accessor_class_data_g1complex_packing{ "data_g1complex_packing" };
grib_accessor_class* grib_accessor_class_data_g1complex_packing = &_grib_accessor_class_data_g1complex_packing;
void grib_accessor_class_data_g1complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g1complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_complex_packing_t::init(a, v, args);
grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a;
self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->N = 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->edition = 1;
self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->N = 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->edition = 1;
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a;
int ret = GRIB_SUCCESS;
long seclen = 0;
long sub_j = 0;
long sub_k = 0;
long sub_m = 0;
long n = 0;
long half_byte = 0;
long bits_per_value = 0;
size_t buflen = 0;
int ret = GRIB_SUCCESS;
long seclen = 0;
long sub_j = 0;
long sub_k = 0;
long sub_m = 0;
long n = 0;
long half_byte = 0;
long bits_per_value = 0;
size_t buflen = 0;
if (*len == 0)
return GRIB_NO_VALUES;
// /* TODO: spectral_ieee does not work */
// if (c->ieee_packing && self->ieee_packing) {
// grib_handle* h = grib_handle_of_accessor(a);
// grib_context* c = a->context;
// char* packingType_s = NULL;
// char* ieee_packing_s = NULL;
// long precision = c->ieee_packing == 32 ? 1 : 2;
// size_t lenstr = strlen(self->ieee_packing);
// /* TODO: spectral_ieee does not work */
// if (c->ieee_packing && self->ieee_packing) {
// grib_handle* h = grib_handle_of_accessor(a);
// grib_context* c = a->context;
// char* packingType_s = NULL;
// char* ieee_packing_s = NULL;
// long precision = c->ieee_packing == 32 ? 1 : 2;
// size_t lenstr = strlen(self->ieee_packing);
// packingType_s = grib_context_strdup(c, self->packingType);
// ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
// precision_s = grib_context_strdup(c, self->precision);
// packingType_s = grib_context_strdup(c, self->packingType);
// ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
// precision_s = grib_context_strdup(c, self->precision);
// grib_set_string(h, packingType_s, ieee_packing_s, &lenstr);
// grib_set_long(h, precision_s, precision);
// grib_set_string(h, packingType_s, ieee_packing_s, &lenstr);
// grib_set_long(h, precision_s, precision);
// grib_context_free(c, packingType_s);
// grib_context_free(c, ieee_packing_s);
// grib_context_free(c, precision_s);
// return grib_set_double_array(h, "values", val, *len);
// }
// grib_context_free(c, packingType_s);
// grib_context_free(c, ieee_packing_s);
// grib_context_free(c, precision_s);
// return grib_set_double_array(h, "values", val, *len);
// }
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS)
return ret;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,14 +11,15 @@
#include "grib_accessor_class_data_g1second_order_constant_width_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_g1second_order_constant_width_packing_t _grib_accessor_class_data_g1second_order_constant_width_packing{"data_g1second_order_constant_width_packing"};
grib_accessor_class_data_g1second_order_constant_width_packing_t _grib_accessor_class_data_g1second_order_constant_width_packing{ "data_g1second_order_constant_width_packing" };
grib_accessor_class* grib_accessor_class_data_g1second_order_constant_width_packing = &_grib_accessor_class_data_g1second_order_constant_width_packing;
void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
self->half_byte = grib_arguments_get_name(hand, args, self->carg++);
self->packingType = grib_arguments_get_name(hand, args, self->carg++);
@ -41,23 +41,26 @@ void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g1second_order_constant_width_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues){
int err = 0;
int grib_accessor_class_data_g1second_order_constant_width_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
{
int err = 0;
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
*numberOfSecondOrderPackedValues = 0;
*numberOfSecondOrderPackedValues = 0;
err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues);
return err;
}
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_float(grib_accessor*, float* val, size_t* len){
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_float(grib_accessor*, float* val, size_t* len)
{
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len)
{
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
int ret = 0;
int ret = 0;
long numberOfGroups, numberOfSecondOrderPackedValues;
long groupWidth = 0;
long* firstOrderValues = 0;
@ -139,7 +142,7 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
i += secondaryBitmap[n];
long fovi = 0;
// ECC-1703
if ( i >=0 && i < numberOfGroups )
if (i >= 0 && i < numberOfGroups)
fovi = firstOrderValues[i];
X[n] = fovi + X[n];
n++;
@ -151,7 +154,7 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
while (n < numberOfSecondOrderPackedValues) {
i += secondaryBitmap[n];
long fovi = 0;
if ( i >=0 && i < numberOfGroups )
if (i >= 0 && i < numberOfGroups)
fovi = firstOrderValues[i];
X[n] = fovi;
n++;
@ -177,17 +180,19 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
return ret;
}
int grib_accessor_class_data_g1second_order_constant_width_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
int grib_accessor_class_data_g1second_order_constant_width_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
{
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s: Not implemented", cclass_name, __func__);
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0;
double* values = NULL;
int err = 0;
size_t size = 0;
double* values = NULL;
int err = 0;
/* TODO: This should be 'codedValues' not 'values'
but GRIB1 version of this packing does not have that key!! */
@ -208,11 +213,12 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou
return GRIB_SUCCESS;
}
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0, i = 0;
double* values = NULL;
int err = 0;
int err = 0;
/* TODO: This should be 'codedValues' not 'values'
but GRIB1 version of this packing does not have that key!! */

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,20 +10,22 @@
#include "grib_accessor_class_data_g1secondary_bitmap.h"
grib_accessor_class_data_g1secondary_bitmap_t _grib_accessor_class_data_g1secondary_bitmap{"data_g1secondary_bitmap"};
grib_accessor_class_data_g1secondary_bitmap_t _grib_accessor_class_data_g1secondary_bitmap{ "data_g1secondary_bitmap" };
grib_accessor_class* grib_accessor_class_data_g1secondary_bitmap = &_grib_accessor_class_data_g1secondary_bitmap;
void grib_accessor_class_data_g1secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g1secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_secondary_bitmap_t::init(a, v, args);
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
self->number_of_ones = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
self->number_of_ones = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
}
int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, long* count){
int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, long* count)
{
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
size_t len = 0;
int err = 0;
size_t len = 0;
int err = 0;
long expand_by;
*count = 0;
@ -40,11 +41,11 @@ int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a,
return GRIB_SUCCESS;
}
int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
int err = 0;
int err = 0;
long primary_len = 0;
long secondary_len = 0;
double* primary_bitmap = NULL;
@ -52,11 +53,11 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a,
long i = 0;
long j = 0;
long on = 0;
long k;
long m;
double missing_value = 0;
double present_value = 0;
long expand_by = 0;
long k = 0;
long m = 0;
double missing_value = 0;
double present_value = 0;
long expand_by = 0;
if (*len == 0)
return GRIB_NO_VALUES;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,11 +11,12 @@
#include "grib_accessor_class_data_g1simple_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_g1simple_packing_t _grib_accessor_class_data_g1simple_packing{"data_g1simple_packing"};
grib_accessor_class_data_g1simple_packing_t _grib_accessor_class_data_g1simple_packing{ "data_g1simple_packing" };
grib_accessor_class* grib_accessor_class_data_g1simple_packing = &_grib_accessor_class_data_g1simple_packing;
void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
@ -28,9 +28,10 @@ void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const l
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, long* number_of_values){
int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, long* number_of_values)
{
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
*number_of_values = 0;
*number_of_values = 0;
/* Special case for when values are cleared */
/*if(a->length == 0)
@ -39,7 +40,8 @@ int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, l
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values);
}
int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
{
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
size_t n_vals = *len;
@ -108,7 +110,7 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c
packingType_s = grib_context_strdup(c, self->packingType);
ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
precision_s = grib_context_strdup(c, self->precision);
precision = c->ieee_packing == 32 ? 1 : 2;
precision = c->ieee_packing == 32 ? 1 : 2;
if ((ret = grib_set_string(h, packingType_s, ieee_packing_s, &lenstr)) != GRIB_SUCCESS)
return ret;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -13,17 +12,18 @@
#include "grib_scaling.h"
#include <algorithm>
grib_accessor_class_data_g2bifourier_packing_t _grib_accessor_class_data_g2bifourier_packing{"data_g2bifourier_packing"};
grib_accessor_class_data_g2bifourier_packing_t _grib_accessor_class_data_g2bifourier_packing{ "data_g2bifourier_packing" };
grib_accessor_class* grib_accessor_class_data_g2bifourier_packing = &_grib_accessor_class_data_g2bifourier_packing;
typedef unsigned long (*encode_float_proc)(double);
typedef double (*decode_float_proc)(unsigned long);
void grib_accessor_class_data_g2bifourier_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g2bifourier_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
grib_handle* gh = grib_handle_of_accessor(a);
self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++);
self->laplacianOperatorIsSet = grib_arguments_get_name(gh, args, self->carg++);
@ -43,10 +43,11 @@ void grib_accessor_class_data_g2bifourier_packing_t::init(grib_accessor* a, cons
self->dirty = 1;
}
int grib_accessor_class_data_g2bifourier_packing_t::value_count(grib_accessor* a, long* numberOfValues){
int grib_accessor_class_data_g2bifourier_packing_t::value_count(grib_accessor* a, long* numberOfValues)
{
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
*numberOfValues = 0;
grib_handle* gh = grib_handle_of_accessor(a);
*numberOfValues = 0;
return grib_get_long_internal(gh, self->number_of_values, numberOfValues);
}
@ -249,7 +250,7 @@ static double laplam(bif_trunc_t* bt, const double val[])
free(itab2);
return 0.;
}
Assert(lmax>0);
Assert(lmax > 0);
/*
* Now, itab2 contains all possible values of i*i+j*j, and itab1 contains
@ -426,8 +427,8 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a)
bt->jtruncation_bif = (long*)grib_context_malloc(gh->context, sizeof(long) * (1 + bt->bif_i));
#define RECTANGLE 77
#define ELLIPSE 88
#define DIAMOND 99
#define ELLIPSE 88
#define DIAMOND 99
switch (bt->biFourierTruncationType) {
case RECTANGLE:
@ -471,9 +472,10 @@ cleanup:
return NULL;
}
int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
grib_handle* gh = grib_handle_of_accessor(a);
unsigned char* buf = NULL;
unsigned char* hres = NULL;
@ -568,19 +570,20 @@ cleanup:
return ret;
}
int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
size_t buflen = 0;
size_t hsize = 0;
size_t lsize = 0;
unsigned char* buf = NULL;
unsigned char* hres = NULL;
unsigned char* lres = NULL;
long hpos = 0;
long lpos = 0;
size_t buflen = 0;
size_t hsize = 0;
size_t lsize = 0;
unsigned char* buf = NULL;
unsigned char* hres = NULL;
unsigned char* lres = NULL;
long hpos = 0;
long lpos = 0;
int isp;
bif_trunc_t* bt = NULL;
@ -619,7 +622,7 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a
if (*len != bt->n_vals_bif) {
grib_context_log(gh->context, GRIB_LOG_ERROR, "BIFOURIER_PACKING: wrong number of values, expected %lu - got %lu",
bt->n_vals_bif, *len);
bt->n_vals_bif, *len);
ret = GRIB_INTERNAL_ERROR;
goto cleanup;
}
@ -745,7 +748,7 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a
grib_get_double_internal(gh, self->reference_value, &ref);
if (ref != bt->reference_value) {
grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)",
cclass_name, __func__, self->reference_value, ref, bt->reference_value);
cclass_name, __func__, self->reference_value, ref, bt->reference_value);
return GRIB_INTERNAL_ERROR;
}
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,29 +10,32 @@
#include "grib_accessor_class_data_g2complex_packing.h"
grib_accessor_class_data_g2complex_packing_t _grib_accessor_class_data_g2complex_packing{"data_g2complex_packing"};
grib_accessor_class_data_g2complex_packing_t _grib_accessor_class_data_g2complex_packing{ "data_g2complex_packing" };
grib_accessor_class* grib_accessor_class_data_g2complex_packing = &_grib_accessor_class_data_g2complex_packing;
void grib_accessor_class_data_g2complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g2complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_complex_packing_t::init(a, v, args);
grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a;
self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->edition = 2;
self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->edition = 2;
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g2complex_packing_t::value_count(grib_accessor* a, long* numberOfValues){
int grib_accessor_class_data_g2complex_packing_t::value_count(grib_accessor* a, long* numberOfValues)
{
grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a;
*numberOfValues = 0;
*numberOfValues = 0;
return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, numberOfValues);
}
int grib_accessor_class_data_g2complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_g2complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a;
int ret = GRIB_SUCCESS;
int ret = GRIB_SUCCESS;
if (*len == 0)
return GRIB_NO_VALUES;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,25 +10,28 @@
#include "grib_accessor_class_data_g2secondary_bitmap.h"
grib_accessor_class_data_g2secondary_bitmap_t _grib_accessor_class_data_g2secondary_bitmap{"data_g2secondary_bitmap"};
grib_accessor_class_data_g2secondary_bitmap_t _grib_accessor_class_data_g2secondary_bitmap{ "data_g2secondary_bitmap" };
grib_accessor_class* grib_accessor_class_data_g2secondary_bitmap = &_grib_accessor_class_data_g2secondary_bitmap;
void grib_accessor_class_data_g2secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g2secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_secondary_bitmap_t::init(a, v, args);
grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a;
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
}
int grib_accessor_class_data_g2secondary_bitmap_t::value_count(grib_accessor* a, long* len){
int grib_accessor_class_data_g2secondary_bitmap_t::value_count(grib_accessor* a, long* len)
{
grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a;
*len = 0;
*len = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, len);
}
int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a;
int err = 0;
int err = 0;
long primary_len = 0, secondary_len = 0;
double* primary_bitmap = NULL;
@ -85,7 +87,7 @@ int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a,
primary_bitmap[k++] = present_value;
for (j = 0; j < expand_by; j++)
secondary_bitmap[m++] = val[i + j];
//on++;
// on++;
}
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,11 +10,12 @@
#include "grib_accessor_class_data_g2shsimple_packing.h"
grib_accessor_class_data_g2shsimple_packing_t _grib_accessor_class_data_g2shsimple_packing{"data_g2shsimple_packing"};
grib_accessor_class_data_g2shsimple_packing_t _grib_accessor_class_data_g2shsimple_packing{ "data_g2shsimple_packing" };
grib_accessor_class* grib_accessor_class_data_g2shsimple_packing = &_grib_accessor_class_data_g2shsimple_packing;
void grib_accessor_class_data_g2shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g2shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_shsimple_packing_t::init(a, v, args);
grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a;
@ -24,15 +24,17 @@ void grib_accessor_class_data_g2shsimple_packing_t::init(grib_accessor* a, const
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g2shsimple_packing_t::value_count(grib_accessor* a, long* len){
int grib_accessor_class_data_g2shsimple_packing_t::value_count(grib_accessor* a, long* len)
{
grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a;
*len = 0;
*len = 0;
return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, len);
}
int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a;
int err = GRIB_SUCCESS;
int err = GRIB_SUCCESS;
size_t n_vals = 0;
@ -61,9 +63,10 @@ int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor*
return err;
}
int grib_accessor_class_data_g2shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_g2shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a;
int err = GRIB_SUCCESS;
int err = GRIB_SUCCESS;
size_t coded_n_vals = *len - 1;
size_t n_vals = *len;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,43 +11,46 @@
#include "grib_accessor_class_data_g2simple_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_g2simple_packing_t _grib_accessor_class_data_g2simple_packing{"data_g2simple_packing"};
grib_accessor_class_data_g2simple_packing_t _grib_accessor_class_data_g2simple_packing{ "data_g2simple_packing" };
grib_accessor_class* grib_accessor_class_data_g2simple_packing = &_grib_accessor_class_data_g2simple_packing;
void grib_accessor_class_data_g2simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_g2simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a;
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
self->edition = 2;
}
int grib_accessor_class_data_g2simple_packing_t::value_count(grib_accessor* a, long* n_vals){
int grib_accessor_class_data_g2simple_packing_t::value_count(grib_accessor* a, long* n_vals)
{
grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a;
*n_vals = 0;
*n_vals = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals);
}
int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
{
grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a;
//grib_accessor_class* super = *(a->cclass->super);
size_t n_vals = *len;
double reference_value = 0;
long binary_scale_factor = 0;
long bits_per_value = 0;
long decimal_scale_factor = 0;
double decimal = 1;
size_t buflen = 0;
unsigned char* buf = NULL;
unsigned char* encoded = NULL;
double divisor = 1;
long off = 0;
int ret = 0;
double units_factor = 1.0;
double units_bias = 0.0;
double* val = (double*)cval;
// grib_accessor_class* super = *(a->cclass->super);
size_t n_vals = *len;
double reference_value = 0;
long binary_scale_factor = 0;
long bits_per_value = 0;
long decimal_scale_factor = 0;
double decimal = 1;
size_t buflen = 0;
unsigned char* buf = NULL;
unsigned char* encoded = NULL;
double divisor = 1;
long off = 0;
int ret = 0;
double units_factor = 1.0;
double units_bias = 0.0;
double* val = (double*)cval;
int i;
grib_context* c = a->context;
grib_context* c = a->context;
if (*len == 0) {
grib_buffer_replace(a, NULL, 0, 1, 1);
@ -76,7 +78,8 @@ int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, c
for (i = 0; i < n_vals; i++) {
val[i] = val[i] * units_factor + units_bias;
}
} else {
}
else {
for (i = 0; i < n_vals; i++) {
val[i] *= units_factor;
}
@ -147,7 +150,8 @@ int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, c
return ret;
}
int grib_accessor_class_data_g2simple_packing_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len){
int grib_accessor_class_data_g2simple_packing_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len)
{
size_t length = *len;
grib_buffer_replace(a, val, length, 1, 1);
return GRIB_SUCCESS;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,20 +10,21 @@
#include "grib_accessor_class_data_jpeg2000_packing.h"
grib_accessor_class_data_jpeg2000_packing_t _grib_accessor_class_data_jpeg2000_packing{"data_jpeg2000_packing"};
grib_accessor_class_data_jpeg2000_packing_t _grib_accessor_class_data_jpeg2000_packing{ "data_jpeg2000_packing" };
grib_accessor_class* grib_accessor_class_data_jpeg2000_packing = &_grib_accessor_class_data_jpeg2000_packing;
static int first = 1;
#define JASPER_LIB 1
#define JASPER_LIB 1
#define OPENJPEG_LIB 2
void grib_accessor_class_data_jpeg2000_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_jpeg2000_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
const char* user_lib = NULL;
const char* user_lib = NULL;
grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
self->jpeg_lib = 0;
self->type_of_compression_used = grib_arguments_get_name(hand, args, self->carg++);
@ -78,9 +78,10 @@ void grib_accessor_class_data_jpeg2000_packing_t::init(grib_accessor* a, const l
}
}
int grib_accessor_class_data_jpeg2000_packing_t::value_count(grib_accessor* a, long* n_vals){
int grib_accessor_class_data_jpeg2000_packing_t::value_count(grib_accessor* a, long* n_vals)
{
grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a;
*n_vals = 0;
*n_vals = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals);
}
@ -88,16 +89,18 @@ int grib_accessor_class_data_jpeg2000_packing_t::value_count(grib_accessor* a, l
#define EXTRA_BUFFER_SIZE 10240
#if HAVE_JPEG
int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor*, float* val, size_t* len){
int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor*, float* val, size_t* len)
{
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a;
int err = GRIB_SUCCESS;
size_t i = 0;
size_t buflen = a->byte_count();
int err = GRIB_SUCCESS;
size_t i = 0;
size_t buflen = a->byte_count();
double bscale = 0;
double dscale = 0;
unsigned char* buf = NULL;
@ -112,7 +115,8 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a,
double units_bias = 0.0;
n_vals = 0;
err = a->value_count(&nn); n_vals = nn;
err = a->value_count(&nn);
n_vals = nn;
if (err)
return err;
@ -176,7 +180,8 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a,
for (i = 0; i < n_vals; i++) {
val[i] = val[i] * units_factor + units_bias;
}
} else {
}
else {
for (i = 0; i < n_vals; i++) {
val[i] *= units_factor;
}
@ -191,10 +196,11 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a,
return err;
}
int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len)
{
grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a;
size_t n_vals = *len;
int err = 0;
size_t n_vals = *len;
int err = 0;
int i;
double reference_value = 0;
long binary_scale_factor = 0;
@ -215,9 +221,9 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c
long number_of_data_points;
int ret = 0;
j2k_encode_helper helper;
double units_factor = 1.0;
double units_bias = 0.0;
double* val = (double*)cval;
double units_factor = 1.0;
double units_bias = 0.0;
double* val = (double*)cval;
const char* cclass_name = a->cclass->name;
self->dirty = 1;
@ -329,28 +335,28 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c
/* ECC-802: We cannot bomb out here as the user might have changed Ni/Nj and the packingType
* but has not yet submitted the new data values. So len will be out of sync!
* So issue a warning but proceed.
*/
*/
/*return GRIB_INTERNAL_ERROR;*/
grib_context_free(a->context, buf);
return GRIB_SUCCESS;
}
switch (type_of_compression_used) {
case 0: // Lossless
case 0: // Lossless
if (target_compression_ratio != 255) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s %s: When %s=0 (Lossless), %s must be set to 255",
cclass_name, __func__, self->type_of_compression_used, self->target_compression_ratio);
"%s %s: When %s=0 (Lossless), %s must be set to 255",
cclass_name, __func__, self->type_of_compression_used, self->target_compression_ratio);
return GRIB_ENCODING_ERROR;
}
helper.compression = 0;
break;
case 1: // Lossy
case 1: // Lossy
if (target_compression_ratio == 255 || target_compression_ratio == 0) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s %s: When %s=1 (Lossy), %s must be specified",
cclass_name, __func__, self->type_of_compression_used, self->target_compression_ratio);
"%s %s: When %s=1 (Lossy), %s must be specified",
cclass_name, __func__, self->type_of_compression_used, self->target_compression_ratio);
return GRIB_ENCODING_ERROR;
}
Assert(target_compression_ratio != 255);
@ -428,34 +434,39 @@ cleanup:
}
#else
static void print_error_feature_not_enabled(grib_context* c){
static void print_error_feature_not_enabled(grib_context* c)
{
grib_context_log(c, GRIB_LOG_ERROR,
"JPEG support not enabled. Please rebuild with -DENABLE_JPG=ON");
}
int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len){
int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
#endif
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0;
double* values = NULL;
int err = 0;
double reference_value = 0;
long bits_per_value = 0;
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0;
double* values = NULL;
int err = 0;
double reference_value = 0;
long bits_per_value = 0;
if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;
@ -486,14 +497,15 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element(grib_acce
return GRIB_SUCCESS;
}
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0, i = 0;
double* values = NULL;
int err = 0;
double* values = NULL;
int err = 0;
double reference_value = 0;
long bits_per_value = 0;
long bits_per_value = 0;
if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -14,14 +13,15 @@
#define PNG_ANYBITS
grib_accessor_class_data_png_packing_t _grib_accessor_class_data_png_packing{"data_png_packing"};
grib_accessor_class_data_png_packing_t _grib_accessor_class_data_png_packing{ "data_png_packing" };
grib_accessor_class* grib_accessor_class_data_png_packing = &_grib_accessor_class_data_png_packing;
void grib_accessor_class_data_png_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_png_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_values_t::init(a, v, args);
grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
grib_handle* h = grib_handle_of_accessor(a);
self->number_of_values = grib_arguments_get_name(h, args, self->carg++);
self->reference_value = grib_arguments_get_name(h, args, self->carg++);
@ -36,15 +36,16 @@ void grib_accessor_class_data_png_packing_t::init(grib_accessor* a, const long v
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_png_packing_t::value_count(grib_accessor* a, long* n_vals){
int grib_accessor_class_data_png_packing_t::value_count(grib_accessor* a, long* n_vals)
{
grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a;
*n_vals = 0;
*n_vals = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals);
}
#if HAVE_LIBPNG
#include <png.h>
#include <png.h>
typedef struct png_read_callback_data
{
@ -69,7 +70,7 @@ static void png_write_callback(png_structp png, png_bytep data, png_size_t lengt
if (p->offset + length > p->length) {
/* Errors handled through png_error() are fatal, meaning that png_error() should never return to its caller.
Currently, this is handled via setjmp() and longjmp() */
png_error(png,"Failed to write PNG data");
png_error(png, "Failed to write PNG data");
}
memcpy(p->buffer + p->offset, data, length);
p->offset += length;
@ -80,12 +81,13 @@ static void png_flush_callback(png_structp png)
/* Empty */
}
int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a;
int err = GRIB_SUCCESS;
int i, j;
size_t buflen = a->byte_count();
size_t buflen = a->byte_count();
double bscale = 0;
double dscale = 0;
unsigned char* buf = NULL;
@ -109,7 +111,8 @@ int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, doub
self->dirty = 0;
err = a->value_count(&nn); n_vals = nn;
err = a->value_count(&nn);
n_vals = nn;
if (err) return err;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
@ -195,11 +198,11 @@ int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, doub
depth = 32;
bits8 = ((bits_per_value + 7) / 8) * 8;
#ifdef PNG_ANYBITS
#ifdef PNG_ANYBITS
Assert(depth == bits8);
#else
#else
Assert(bits_per_value % 8 == 0);
#endif
#endif
i = 0;
@ -224,10 +227,11 @@ cleanup:
static bool is_constant(const double* values, size_t n_vals)
{
bool isConstant = true;
double v = 0;
double v = 0;
size_t i;
for (i = 0; i < n_vals; i++) {
if (i == 0) v = values[i];
if (i == 0)
v = values[i];
else if (v != values[i]) {
isConstant = false;
break;
@ -236,11 +240,12 @@ static bool is_constant(const double* values, size_t n_vals)
return isConstant;
}
int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a;
const char* cclass_name = a->cclass->name;
const char* cclass_name = a->cclass->name;
int err = GRIB_SUCCESS;
int err = GRIB_SUCCESS;
bool is_constant_field = false;
int i, j;
size_t buflen = 0;
@ -299,11 +304,11 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const
}
if (is_constant_field) {
#ifdef DEBUG
#ifdef DEBUG
for (i = 1; i < n_vals; i++) {
Assert(val[i] == val[0]);
}
#endif
#endif
if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->reference_value, val[0])) != GRIB_SUCCESS)
return err;
@ -313,7 +318,7 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const
grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &ref);
if (ref != reference_value) {
grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)",
cclass_name, __func__, self->reference_value, ref, reference_value);
cclass_name, __func__, self->reference_value, ref, reference_value);
return GRIB_INTERNAL_ERROR;
}
}
@ -370,7 +375,7 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const
/* ECC-802: We cannot bomb out here as the user might have changed Ni/Nj and the packingType
* but has not yet submitted the new data values. So len will be out of sync!
* So issue a warning but proceed.
*/
*/
return GRIB_SUCCESS;
}
@ -379,8 +384,10 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const
max = val[0];
min = max;
for (i = 1; i < n_vals; i++) {
if (val[i] > max) max = val[i];
else if (val[i] < min) min = val[i];
if (val[i] > max)
max = val[i];
else if (val[i] < min)
min = val[i];
}
min *= d;
max *= d;
@ -393,16 +400,16 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const
if (reference_value > min) {
grib_context_log(a->context, GRIB_LOG_ERROR, "reference_value=%g min_value=%g diff=%g",
reference_value, min, reference_value - min);
reference_value, min, reference_value - min);
return GRIB_INTERNAL_ERROR;
}
binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err);
divisor = codes_power<double>(-binary_scale_factor, 2);
#ifndef PNG_ANYBITS
#ifndef PNG_ANYBITS
Assert(bits_per_value % 8 == 0);
#endif
#endif
bits8 = (bits_per_value + 7) / 8 * 8;
encoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context, bits8 / 8 * n_vals);
if (!encoded) {
@ -531,15 +538,16 @@ cleanup:
return err;
}
int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
/* The index idx relates to codedValues NOT values! */
grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int err = 0;
size_t size = 0;
double reference_value = 0;
long bits_per_value = 0;
double* values = NULL;
grib_handle* hand = grib_handle_of_accessor(a);
int err = 0;
size_t size = 0;
double reference_value = 0;
long bits_per_value = 0;
double* values = NULL;
if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;
@ -566,15 +574,16 @@ int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor*
return GRIB_SUCCESS;
}
int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
/* The index idx relates to codedValues NOT values! */
grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int err = 0;
grib_handle* hand = grib_handle_of_accessor(a);
int err = 0;
size_t size = 0, i = 0;
double reference_value = 0;
long bits_per_value = 0;
double* values = NULL;
double reference_value = 0;
long bits_per_value = 0;
double* values = NULL;
if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;
@ -612,24 +621,29 @@ int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_acces
#else
static void print_error_feature_not_enabled(grib_context* c){
static void print_error_feature_not_enabled(grib_context* c)
{
grib_context_log(c, GRIB_LOG_ERROR,
"PNG support not enabled. Please rebuild with -DENABLE_PNG=ON");
}
int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,11 +11,12 @@
#include "grib_accessor_class_data_raw_packing.h"
#include "grib_ieeefloat.h"
grib_accessor_class_data_raw_packing_t _grib_accessor_class_data_raw_packing{"data_raw_packing"};
grib_accessor_class_data_raw_packing_t _grib_accessor_class_data_raw_packing{ "data_raw_packing" };
grib_accessor_class* grib_accessor_class_data_raw_packing = &_grib_accessor_class_data_raw_packing;
void grib_accessor_class_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_values_t::init(a, v, args);
grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a;
@ -25,19 +25,21 @@ void grib_accessor_class_data_raw_packing_t::init(grib_accessor* a, const long v
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_raw_packing_t::value_count(grib_accessor* a, long* n_vals){
int grib_accessor_class_data_raw_packing_t::value_count(grib_accessor* a, long* n_vals)
{
grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a;
*n_vals = 0;
*n_vals = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals);
}
int grib_accessor_class_data_raw_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_raw_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a;
unsigned char* buf = NULL;
int bytes = 0;
size_t nvals = 0;
long inlen = a->byte_count();
long precision = 0;
unsigned char* buf = NULL;
int bytes = 0;
size_t nvals = 0;
long inlen = a->byte_count();
long precision = 0;
int code = GRIB_SUCCESS;
@ -71,7 +73,8 @@ int grib_accessor_class_data_raw_packing_t::unpack_double(grib_accessor* a, doub
return code;
}
int grib_accessor_class_data_raw_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_raw_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a;
int bytes = 0;
@ -127,7 +130,7 @@ clean_up:
* free(buffer);
* if (free_values)
* free(values);
*/
*/
grib_buffer_replace(a, buffer, bufsize, 1, 1);
@ -142,14 +145,16 @@ clean_up:
return code;
}
int grib_accessor_class_data_raw_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
int ret = 0;
int grib_accessor_class_data_raw_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int ret = 0;
grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a;
unsigned char* buf = NULL;
int bytes = 0;
size_t nvals = 0;
long inlen = a->byte_count(); long pos = 0;
long precision = 0;
unsigned char* buf = NULL;
int bytes = 0;
size_t nvals = 0;
long inlen = a->byte_count();
long pos = 0;
long precision = 0;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS)
return ret;
@ -183,11 +188,12 @@ int grib_accessor_class_data_raw_packing_t::unpack_double_element(grib_accessor*
return ret;
}
int grib_accessor_class_data_raw_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
int err = 0;
int grib_accessor_class_data_raw_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
int err = 0;
size_t i = 0;
for (i=0; i<len; ++i) {
if ((err = unpack_double_element(a, index_array[i], val_array+i)) != GRIB_SUCCESS)
for (i = 0; i < len; ++i) {
if ((err = unpack_double_element(a, index_array[i], val_array + i)) != GRIB_SUCCESS)
return err;
}
return GRIB_SUCCESS;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,44 +11,47 @@
#include "grib_accessor_class_data_run_length_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_run_length_packing_t _grib_accessor_class_data_run_length_packing{"data_run_length_packing"};
grib_accessor_class_data_run_length_packing_t _grib_accessor_class_data_run_length_packing{ "data_run_length_packing" };
grib_accessor_class* grib_accessor_class_data_run_length_packing = &_grib_accessor_class_data_run_length_packing;
void grib_accessor_class_data_run_length_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_run_length_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_values_t::init(a, v, args);
grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
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->max_level_value = grib_arguments_get_name(gh, args, self->carg++);
self->number_of_level_values = grib_arguments_get_name(gh, args, self->carg++);
self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++);
self->level_values = grib_arguments_get_name(gh, args, self->carg++);
grib_handle* gh = grib_handle_of_accessor(a);
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->max_level_value = grib_arguments_get_name(gh, args, self->carg++);
self->number_of_level_values = grib_arguments_get_name(gh, args, self->carg++);
self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++);
self->level_values = grib_arguments_get_name(gh, args, self->carg++);
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_run_length_packing_t::value_count(grib_accessor* a, long* number_of_values){
int grib_accessor_class_data_run_length_packing_t::value_count(grib_accessor* a, long* number_of_values)
{
grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a;
*number_of_values = 0;
*number_of_values = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values);
}
int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
int err = GRIB_SUCCESS;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
int err = GRIB_SUCCESS;
long seclen, number_of_values, bits_per_value, max_level_value, number_of_level_values, decimal_scale_factor;
long* level_values = NULL;
long* level_values = NULL;
size_t level_values_size = 0;
long i = 0, number_of_compressed_values = 0, range = 0, offsetBeforeData = 0, pos = 0;
long v, n, factor, k, j;
long* compressed_values = NULL;
long* compressed_values = NULL;
double level_scale_factor = 0;
double* levels = NULL;
unsigned char* buf = NULL;
double missingValue = 9999.0;
double* levels = NULL;
unsigned char* buf = NULL;
double missingValue = 9999.0;
if ((err = grib_get_long_internal(gh, self->seclen, &seclen)) != GRIB_SUCCESS)
return err;
@ -66,12 +68,12 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor*
if ((err = grib_get_double(gh, "missingValue", &missingValue)) != GRIB_SUCCESS)
return err;
level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values);
level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values);
level_values_size = number_of_level_values;
if ((err = grib_get_long_array_internal(gh, self->level_values, level_values, &level_values_size)) != GRIB_SUCCESS)
return err;
*len = number_of_values;
i = 0;
*len = number_of_values;
i = 0;
number_of_compressed_values = ((seclen - 5) * 8) / bits_per_value;
if (number_of_compressed_values == 0 || max_level_value == 0) {
for (i = 0; i < number_of_values; i++) {
@ -82,23 +84,24 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor*
range = (1 << bits_per_value) - 1 - max_level_value;
if ((max_level_value <= 0) || (number_of_level_values <= 0) || (max_level_value > number_of_level_values) || (range <= 0)) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: parameters are invalid: max_level_value=%ld(>0, <=number_of_level_values), "
"number_of_level_values=%ld(>0, >=max_level_value), range=%ld(>0)",
cclass_name, max_level_value, number_of_level_values, range);
"%s: parameters are invalid: max_level_value=%ld(>0, <=number_of_level_values), "
"number_of_level_values=%ld(>0, >=max_level_value), range=%ld(>0)",
cclass_name, max_level_value, number_of_level_values, range);
return GRIB_DECODING_ERROR;
}
if (decimal_scale_factor > 127) {
decimal_scale_factor = -(decimal_scale_factor - 128);
}
level_scale_factor = codes_power<double>(-decimal_scale_factor, 10.0);
levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1));
levels[0] = missingValue;
levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1));
levels[0] = missingValue;
for (i = 0; i < number_of_level_values; i++) {
levels[i + 1] = level_values[i] * level_scale_factor;
}
compressed_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_compressed_values);
buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data;
offsetBeforeData = a->byte_offset(); buf += offsetBeforeData;
buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data;
offsetBeforeData = a->byte_offset();
buf += offsetBeforeData;
pos = 0;
grib_decode_long_array(buf, &pos, bits_per_value, number_of_compressed_values, compressed_values);
j = 0;
@ -106,13 +109,13 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor*
while (i < number_of_compressed_values) {
if (compressed_values[i] > max_level_value) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: numberOfValues mismatch: i=%ld, "
"compressed_values[i]=%ld, max_level_value=%ld",
cclass_name, i, compressed_values[i], max_level_value);
"%s: numberOfValues mismatch: i=%ld, "
"compressed_values[i]=%ld, max_level_value=%ld",
cclass_name, i, compressed_values[i], max_level_value);
break;
}
v = compressed_values[i++];
n = 1;
v = compressed_values[i++];
n = 1;
factor = 1;
while (i < number_of_compressed_values && compressed_values[i] > max_level_value) {
n += factor * (compressed_values[i] - max_level_value - 1);
@ -121,7 +124,7 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor*
}
if (n > number_of_values) {
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: numberOfValues mismatch: n=%ld, number_of_values=%ld",
cclass_name, n, number_of_values);
cclass_name, n, number_of_values);
break;
}
for (k = 0; k < n; k++) {
@ -139,19 +142,20 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor*
return err;
}
int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
int err = GRIB_SUCCESS;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
int err = GRIB_SUCCESS;
long number_of_values, bits_per_value, max_level_value, number_of_level_values, decimal_scale_factor;
long* level_values = NULL;
long* level_values = NULL;
size_t level_values_size = 0;
long i = 0, range = 0, pos = 0, n = 0, j = 0, k = 0, l = 0, missingValueLong = 0;
double level_scale_factor = 0;
unsigned char* buf = NULL;
double missingValue = 9999.0;
size_t n_vals = *len;
unsigned char* buf = NULL;
double missingValue = 9999.0;
size_t n_vals = *len;
if ((err = grib_get_long_internal(gh, self->number_of_values, &number_of_values)) != GRIB_SUCCESS)
return err;
@ -177,7 +181,7 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
return GRIB_SUCCESS;
}
level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values);
level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values);
level_values_size = number_of_level_values;
if ((err = grib_get_long_array_internal(gh, self->level_values, level_values, &level_values_size)) != GRIB_SUCCESS)
return err;
@ -185,7 +189,7 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
decimal_scale_factor = -(decimal_scale_factor - 128);
}
level_scale_factor = grib_power(-decimal_scale_factor, 10.0);
missingValueLong = (long)(round(missingValue / level_scale_factor));
missingValueLong = (long)(round(missingValue / level_scale_factor));
for (i = 0; i < number_of_level_values; i++) {
if (missingValueLong == level_values[i]) {
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Parameters are invalid: level_values[%ld]=%ld, missingValueLong=%ld",
@ -196,22 +200,23 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
range = (1 << bits_per_value) - 1 - max_level_value;
if ((max_level_value <= 0) || (number_of_level_values <= 0) || (max_level_value > number_of_level_values) || (range <= 0)) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Parameters are invalid: max_level_value=%ld(>0, <=number_of_level_values), "
"number_of_level_values=%ld(>0, >=max_level_value), range=%ld(>0)",
cclass_name, max_level_value, number_of_level_values, range);
"%s: Parameters are invalid: max_level_value=%ld(>0, <=number_of_level_values), "
"number_of_level_values=%ld(>0, >=max_level_value), range=%ld(>0)",
cclass_name, max_level_value, number_of_level_values, range);
return GRIB_ENCODING_ERROR;
}
buf = (unsigned char*)grib_context_malloc(a->context, 2 * number_of_values);
for (i = 0; i < number_of_values; i++) {
k = (long)(round(val[i] / level_scale_factor));
k = (long)(round(val[i] / level_scale_factor));
err = GRIB_ENCODING_ERROR;
if (missingValueLong == k) {
k = 0;
k = 0;
err = GRIB_SUCCESS;
} else {
}
else {
for (j = 0; j < max_level_value; j++) {
if (level_values[j] == k) {
k = j + 1;
k = j + 1;
err = GRIB_SUCCESS;
break;
}
@ -219,17 +224,19 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
}
if (err != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Values and/or parameters are invalid: val[%ld]=%lf, level_value=%ld, max_level_value=%ld",
cclass_name, i, val[i], k, max_level_value);
"%s: Values and/or parameters are invalid: val[%ld]=%lf, level_value=%ld, max_level_value=%ld",
cclass_name, i, val[i], k, max_level_value);
return GRIB_ENCODING_ERROR;
}
if (i == 0) {
grib_encode_unsigned_longb(buf, k, &pos, bits_per_value);
} else if (i == number_of_values - 1) {
}
else if (i == number_of_values - 1) {
if (k != l) {
if (n == 0) {
grib_encode_unsigned_longb(buf, k, &pos, bits_per_value);
} else {
}
else {
while (n >= range) {
grib_encode_unsigned_longb(buf, (n % range) + max_level_value + 1, &pos, bits_per_value);
n = n / range;
@ -237,7 +244,8 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
grib_encode_unsigned_longb(buf, n + max_level_value + 1, &pos, bits_per_value);
grib_encode_unsigned_longb(buf, k, &pos, bits_per_value);
}
} else {
}
else {
n = n + 1;
while (n >= range) {
grib_encode_unsigned_longb(buf, (n % range) + max_level_value + 1, &pos, bits_per_value);
@ -245,11 +253,13 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
}
grib_encode_unsigned_longb(buf, n + max_level_value + 1, &pos, bits_per_value);
}
} else {
}
else {
if (k != l) {
if ( n == 0 ) {
if (n == 0) {
grib_encode_unsigned_longb(buf, k, &pos, bits_per_value);
} else {
}
else {
while (n >= range) {
grib_encode_unsigned_longb(buf, (n % range) + max_level_value + 1, &pos, bits_per_value);
n = n / range;
@ -258,14 +268,15 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a,
grib_encode_unsigned_longb(buf, k, &pos, bits_per_value);
n = 0;
}
} else {
}
else {
n = n + 1;
}
}
l = k;
}
grib_context_free(a->context, level_values);
grib_buffer_replace(a, buf, pos/8, 1, 1);
grib_buffer_replace(a, buf, pos / 8, 1, 1);
grib_context_buffer_free(a->context, buf);
return err;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,26 +10,29 @@
#include "grib_accessor_class_data_secondary_bitmap.h"
grib_accessor_class_data_secondary_bitmap_t _grib_accessor_class_data_secondary_bitmap{"data_secondary_bitmap"};
grib_accessor_class_data_secondary_bitmap_t _grib_accessor_class_data_secondary_bitmap{ "data_secondary_bitmap" };
grib_accessor_class* grib_accessor_class_data_secondary_bitmap = &_grib_accessor_class_data_secondary_bitmap;
void grib_accessor_class_data_secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_gen_t::init(a, v, args);
grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a;
self->primary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0);
self->secondary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1);
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2);
self->expand_by = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3);
self->primary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0);
self->secondary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1);
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2);
self->expand_by = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3);
a->length = 0;
}
void grib_accessor_class_data_secondary_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){
void grib_accessor_class_data_secondary_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_values(dumper, a);
}
int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a;
size_t i = 0;
@ -45,7 +47,8 @@ int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a,
size_t secondary_len;
double* primary_vals;
double* secondary_vals;
err = a->value_count(&nn); n_vals = nn;
err = a->value_count(&nn);
n_vals = nn;
if (err)
return err;
@ -111,8 +114,9 @@ int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a,
return err;
}
int grib_accessor_class_data_secondary_bitmap_t::get_native_type(grib_accessor* a){
int grib_accessor_class_data_secondary_bitmap_t::get_native_type(grib_accessor* a)
{
// grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a;
//return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
// return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
return GRIB_TYPE_DOUBLE;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,17 +11,18 @@
#include "grib_accessor_class_data_sh_packed.h"
#include "grib_scaling.h"
grib_accessor_class_data_sh_packed_t _grib_accessor_class_data_sh_packed{"data_sh_packed"};
grib_accessor_class_data_sh_packed_t _grib_accessor_class_data_sh_packed{ "data_sh_packed" };
grib_accessor_class* grib_accessor_class_data_sh_packed = &_grib_accessor_class_data_sh_packed;
typedef unsigned long (*encode_float_proc)(double);
typedef double (*decode_float_proc)(unsigned long);
void grib_accessor_class_data_sh_packed_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_sh_packed_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand, args, self->carg++);
self->ieee_floats = grib_arguments_get_name(hand, args, self->carg++);
@ -39,11 +39,12 @@ void grib_accessor_class_data_sh_packed_t::init(grib_accessor* a, const long v,
a->length = 0;
}
int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* count){
int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* count)
{
grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int ret = 0;
const char* cclass_name = a->cclass->name;
grib_handle* hand = grib_handle_of_accessor(a);
int ret = 0;
const char* cclass_name = a->cclass->name;
long sub_j = 0;
long sub_k = 0;
@ -75,42 +76,44 @@ int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* co
return ret;
}
int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a;
size_t i = 0;
int ret = GRIB_SUCCESS;
size_t i = 0;
int ret = GRIB_SUCCESS;
// long lup = 0;
long hcount = 0, lcount = 0, hpos = 0, mmax = 0, n_vals = 0;
double* scals = NULL;
/* double *pscals=NULL; */
double s = 0, d = 0, laplacianOperator = 0;
unsigned char* buf = NULL;
unsigned char* hres = NULL;
unsigned char* lres = NULL;
unsigned char* buf = NULL;
unsigned char* hres = NULL;
unsigned char* lres = NULL;
unsigned long packed_offset;
long lpos = 0;
long maxv = 0;
long GRIBEX_sh_bug_present = 0;
long ieee_floats = 0;
long offsetdata = 0;
long bits_per_value = 0;
double reference_value = 0;
long binary_scale_factor = 0;
long decimal_scale_factor = 0;
long offsetdata = 0;
long bits_per_value = 0;
double reference_value = 0;
long binary_scale_factor = 0;
long decimal_scale_factor = 0;
long sub_j = 0, sub_k = 0, sub_m = 0, pen_j = 0, pen_k = 0, pen_m = 0;
double operat = 0;
int bytes = 0;
int err = 0;
int bytes = 0;
int err = 0;
decode_float_proc decode_float = NULL;
n_vals = 0;
err = a->value_count(&n_vals); if (err)
err = a->value_count(&n_vals);
if (err)
return err;
if (*len < n_vals) {
@ -191,7 +194,7 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double
d = codes_power<double>(-decimal_scale_factor, 10);
scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double));
if(!scals) return GRIB_OUT_OF_MEMORY;
if (!scals) return GRIB_OUT_OF_MEMORY;
scals[0] = 0;
for (i = 1; i < maxv; i++) {

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,17 +11,18 @@
#include "grib_accessor_class_data_sh_unpacked.h"
#include "grib_scaling.h"
grib_accessor_class_data_sh_unpacked_t _grib_accessor_class_data_sh_unpacked{"data_sh_unpacked"};
grib_accessor_class_data_sh_unpacked_t _grib_accessor_class_data_sh_unpacked{ "data_sh_unpacked" };
grib_accessor_class* grib_accessor_class_data_sh_unpacked = &_grib_accessor_class_data_sh_unpacked;
typedef unsigned long (*encode_float_proc)(double);
typedef double (*decode_float_proc)(unsigned long);
void grib_accessor_class_data_sh_unpacked_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_sh_unpacked_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_data_simple_packing_t::init(a, v, args);
grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand, args, self->carg++);
self->ieee_floats = grib_arguments_get_name(hand, args, self->carg++);
@ -39,9 +39,10 @@ void grib_accessor_class_data_sh_unpacked_t::init(grib_accessor* a, const long v
a->length = 0;
}
int grib_accessor_class_data_sh_unpacked_t::value_count(grib_accessor* a, long* count){
int grib_accessor_class_data_sh_unpacked_t::value_count(grib_accessor* a, long* count)
{
grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a;
int ret = 0;
int ret = 0;
long sub_j = 0;
long sub_k = 0;
@ -62,7 +63,8 @@ int grib_accessor_class_data_sh_unpacked_t::value_count(grib_accessor* a, long*
return ret;
}
int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a;
size_t i = 0;
@ -110,7 +112,8 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub
decode_float_proc decode_float = NULL;
n_vals = 0;
err = a->value_count(&n_vals); if (err)
err = a->value_count(&n_vals);
if (err)
return err;
if (*len < n_vals) {

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,11 +10,12 @@
#include "grib_accessor_class_data_shsimple_packing.h"
grib_accessor_class_data_shsimple_packing_t _grib_accessor_class_data_shsimple_packing{"data_shsimple_packing"};
grib_accessor_class_data_shsimple_packing_t _grib_accessor_class_data_shsimple_packing{ "data_shsimple_packing" };
grib_accessor_class* grib_accessor_class_data_shsimple_packing = &_grib_accessor_class_data_shsimple_packing;
void grib_accessor_class_data_shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_data_shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_gen_t::init(a, v, args);
grib_accessor_data_shsimple_packing_t* self = (grib_accessor_data_shsimple_packing_t*)a;
@ -26,13 +26,15 @@ void grib_accessor_class_data_shsimple_packing_t::init(grib_accessor* a, const l
a->length = 0;
}
void grib_accessor_class_data_shsimple_packing_t::dump(grib_accessor* a, grib_dumper* dumper){
void grib_accessor_class_data_shsimple_packing_t::dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_values(dumper, a);
}
int grib_accessor_class_data_shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_data_shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_shsimple_packing_t* self = (grib_accessor_data_shsimple_packing_t*)a;
int err = GRIB_SUCCESS;
int err = GRIB_SUCCESS;
size_t coded_n_vals = *len - 1;
size_t n_vals = *len;
@ -55,6 +57,7 @@ int grib_accessor_class_data_shsimple_packing_t::pack_double(grib_accessor* a, c
return err;
}
int grib_accessor_class_data_shsimple_packing_t::get_native_type(grib_accessor* a){
int grib_accessor_class_data_shsimple_packing_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_DOUBLE;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,31 +10,33 @@
#include "grib_accessor_class_g1day_of_the_year_date.h"
grib_accessor_class_g1day_of_the_year_date_t _grib_accessor_class_g1day_of_the_year_date{"g1day_of_the_year_date"};
grib_accessor_class_g1day_of_the_year_date_t _grib_accessor_class_g1day_of_the_year_date{ "g1day_of_the_year_date" };
grib_accessor_class* grib_accessor_class_g1day_of_the_year_date = &_grib_accessor_class_g1day_of_the_year_date;
void grib_accessor_class_g1day_of_the_year_date_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_g1day_of_the_year_date_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_g1date_t::init(a, l, c);
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
void grib_accessor_class_g1day_of_the_year_date_t::dump(grib_accessor* a, grib_dumper* dumper){
void grib_accessor_class_g1day_of_the_year_date_t::dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_string(dumper, a, NULL);
}
int grib_accessor_class_g1day_of_the_year_date_t::unpack_string(grib_accessor* a, char* val, size_t* len){
int grib_accessor_class_g1day_of_the_year_date_t::unpack_string(grib_accessor* a, char* val, size_t* len)
{
/* special clim case where each mont have 30 days.. to comply with mars*/
grib_accessor_g1day_of_the_year_date_t* self = (grib_accessor_g1day_of_the_year_date_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
char tmp[1024];
long year = 0;
long century = 0;
long month = 0;
long day = 0;
long fullyear = 0;
long year = 0;
long century = 0;
long month = 0;
long day = 0;
long fullyear = 0;
long fake_day_of_year = 0;
grib_get_long_internal(hand, self->century, &century);
@ -43,7 +44,7 @@ int grib_accessor_class_g1day_of_the_year_date_t::unpack_string(grib_accessor* a
grib_get_long_internal(hand, self->month, &month);
grib_get_long_internal(hand, self->year, &year);
fullyear = ((century - 1) * 100 + year);
fullyear = ((century - 1) * 100 + year);
fake_day_of_year = ((month - 1) * 30) + day;
snprintf(tmp, sizeof(tmp), "%04ld-%03ld", fullyear, fake_day_of_year);

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,14 +10,15 @@
#include "grib_accessor_class_g1end_of_interval_monthly.h"
grib_accessor_class_g1end_of_interval_monthly_t _grib_accessor_class_g1end_of_interval_monthly{"g1end_of_interval_monthly"};
grib_accessor_class_g1end_of_interval_monthly_t _grib_accessor_class_g1end_of_interval_monthly{ "g1end_of_interval_monthly" };
grib_accessor_class* grib_accessor_class_g1end_of_interval_monthly = &_grib_accessor_class_g1end_of_interval_monthly;
void grib_accessor_class_g1end_of_interval_monthly_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_g1end_of_interval_monthly_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_abstract_vector_t::init(a, l, c);
grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a;
int n = 0;
int n = 0;
self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
@ -26,20 +26,23 @@ void grib_accessor_class_g1end_of_interval_monthly_t::init(grib_accessor* a, con
a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN;
self->number_of_elements = 6;
self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements);
self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements);
a->length = 0;
a->dirty = 1;
}
int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a;
int ret = 0;
char verifyingMonth[7] = {0,};
int ret = 0;
char verifyingMonth[7] = {
0,
};
size_t slen = 7;
long year = 0, month = 0, date = 0;
const long mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
long days = 0;
long days = 0;
if (!a->dirty)
return GRIB_SUCCESS;
@ -50,7 +53,7 @@ int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor
if ((ret = grib_get_string(grib_handle_of_accessor(a), self->verifyingMonth, verifyingMonth, &slen)) != GRIB_SUCCESS)
return ret;
date = atoi(verifyingMonth);
date = atoi(verifyingMonth);
if (date < 0) {
return GRIB_INVALID_ARGUMENT;
}
@ -85,19 +88,22 @@ int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor
return ret;
}
int grib_accessor_class_g1end_of_interval_monthly_t::value_count(grib_accessor* a, long* count){
int grib_accessor_class_g1end_of_interval_monthly_t::value_count(grib_accessor* a, long* count)
{
grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a;
*count = self->number_of_elements;
*count = self->number_of_elements;
return 0;
}
void grib_accessor_class_g1end_of_interval_monthly_t::destroy(grib_context* c, grib_accessor* a){
void grib_accessor_class_g1end_of_interval_monthly_t::destroy(grib_context* c, grib_accessor* a)
{
grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a;
grib_context_free(c, self->v);
grib_accessor_class_abstract_vector_t::destroy(c, a);
}
int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, grib_accessor* b){
int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, grib_accessor* b)
{
int retval = GRIB_SUCCESS;
double* aval = 0;
double* bval = 0;
@ -107,11 +113,13 @@ int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, g
size_t blen = 0;
int err = 0;
err = a->value_count(&count); if (err)
err = a->value_count(&count);
if (err)
return err;
alen = count;
err = b->value_count(&count); if (err)
err = b->value_count(&count);
if (err)
return err;
blen = count;
@ -124,8 +132,9 @@ int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, g
b->dirty = 1;
a->dirty = 1;
err = a->unpack_double(aval, &alen); err = b->unpack_double(bval, &blen);
for(size_t i=0; i<alen && retval == GRIB_SUCCESS; ++i) {
err = a->unpack_double(aval, &alen);
err = b->unpack_double(bval, &blen);
for (size_t i = 0; i < alen && retval == GRIB_SUCCESS; ++i) {
if (aval[i] != bval[i]) retval = GRIB_DOUBLE_VALUE_MISMATCH;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,15 +10,16 @@
#include "grib_accessor_class_gds_not_present_bitmap.h"
grib_accessor_class_gds_not_present_bitmap_t _grib_accessor_class_gds_not_present_bitmap{"gds_not_present_bitmap"};
grib_accessor_class_gds_not_present_bitmap_t _grib_accessor_class_gds_not_present_bitmap{ "gds_not_present_bitmap" };
grib_accessor_class* grib_accessor_class_gds_not_present_bitmap = &_grib_accessor_class_gds_not_present_bitmap;
void grib_accessor_class_gds_not_present_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
void grib_accessor_class_gds_not_present_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_class_gen_t::init(a, v, args);
int n = 0;
int n = 0;
grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
self->missing_value = grib_arguments_get_name(hand, args, n++);
self->number_of_values = grib_arguments_get_name(hand, args, n++);
@ -29,15 +29,17 @@ void grib_accessor_class_gds_not_present_bitmap_t::init(grib_accessor* a, const
a->length = 0;
}
int grib_accessor_class_gds_not_present_bitmap_t::value_count(grib_accessor* a, long* number_of_points){
int grib_accessor_class_gds_not_present_bitmap_t::value_count(grib_accessor* a, long* number_of_points)
{
grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a;
*number_of_points = 0;
*number_of_points = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_points, number_of_points);
}
int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_handle* hand = grib_handle_of_accessor(a);
long number_of_points = 0, number_of_values = 0, ni = 0;
long latitude_of_first_point = 0;
@ -47,8 +49,8 @@ int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a
long missing_value;
double* coded_vals = NULL;
int err = a->value_count(&nn);
n_vals = nn;
int err = a->value_count(&nn);
n_vals = nn;
if (err)
return err;
@ -98,12 +100,14 @@ int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a
return err;
}
int grib_accessor_class_gds_not_present_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
int grib_accessor_class_gds_not_present_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len)
{
// See deprecated/grib_accessor_class_gds_not_present_bitmap.cc for
// a possible implementation
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_gds_not_present_bitmap_t::get_native_type(grib_accessor* a){
int grib_accessor_class_gds_not_present_bitmap_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_DOUBLE;
}