Testing: subarray unpack

This commit is contained in:
shahramn 2024-03-08 17:55:13 +00:00
parent 0da31890f1
commit 7b0a779890
3 changed files with 28 additions and 34 deletions

View File

@ -111,17 +111,15 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg)
self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1);
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
grib_accessor_bit* self = (grib_accessor_bit*)a;
int ret = 0;
long data = 0;
if (*len < 1) {
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit : unpack_long : Wrong size for %s it contains %d values ", a->name, 1);
*len = 0;
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: unpack_long: Wrong size for %s, it contains %d values ", a->name, 1);
*len = 1;
return GRIB_ARRAY_TOO_SMALL;
}
@ -142,23 +140,22 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
grib_accessor_bit* self = (grib_accessor_bit*)a;
grib_accessor* owner = NULL;
unsigned char* mdata = 0;
if (*len < 1) {
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: pack_long: At least one value to pack for %s", a->name);
*len = 0;
*len = 1;
return GRIB_ARRAY_TOO_SMALL;
}
owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner);
grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner);
if (!owner) {
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit : Cannot get the owner %s for computing the bit value of %s ", self->owner, a->name);
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: Cannot get the owner %s for computing the bit value of %s",
self->owner, a->name);
*len = 0;
return GRIB_NOT_FOUND;
}
mdata = grib_handle_of_accessor(a)->buffer->data;
unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data;
mdata += grib_byte_offset(owner);
/* Note: In the definitions, flagbit numbers go from 7 to 0 (the bit_index), while WMO convention is from 1 to 8 */

View File

@ -192,21 +192,19 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
long pos = a->offset * 8;
long tlen = 0;
long i = 0;
int err = 0;
const grib_handle* hand = grib_handle_of_accessor(a);
err = grib_value_count(a, &tlen);
int err = grib_value_count(a, &tlen);
if (err)
return err;
if (*len < tlen) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
*len = 0;
*len = tlen;
return GRIB_ARRAY_TOO_SMALL;
}
for (i = 0; i < tlen; i++) {
for (long i = 0; i < tlen; i++) {
val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
}
*len = tlen;
@ -219,21 +217,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
long pos = a->offset * 8;
long tlen;
long i;
int err = 0;
grib_handle* hand = grib_handle_of_accessor(a);
err = grib_value_count(a, &tlen);
int err = grib_value_count(a, &tlen);
if (err)
return err;
if (*len < tlen) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
*len = 0;
*len = tlen;
return GRIB_ARRAY_TOO_SMALL;
}
for (i = 0; i < tlen; i++) {
for (long i = 0; i < tlen; i++) {
val[i] = (T)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
}
*len = tlen;
@ -261,8 +257,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
size_t i = 0;
for (i=0; i<len; ++i) {
for (size_t i=0; i<len; ++i) {
unpack_double_element(a, index_array[i], val_array + i);
}
return GRIB_SUCCESS;
@ -280,7 +275,6 @@ static size_t string_length(grib_accessor* a)
static int unpack_string(grib_accessor* a, char* val, size_t* len)
{
long i = 0;
grib_handle* hand = grib_handle_of_accessor(a);
const size_t l = a->length;
@ -293,7 +287,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
return GRIB_BUFFER_TOO_SMALL;
}
for (i = 0; i < a->length; i++) {
for (long i = 0; i < a->length; i++) {
val[i] = hand->buffer->data[a->offset + i];
}

View File

@ -13,6 +13,9 @@
label="grib_unpack_subarray_test"
temp=${label}".grib.tmp"
infile=$data_dir/constant_field.grib2
$EXEC ${test_dir}/grib_unpack_subarray $infile
infile=$data_dir/sample.grib2
$EXEC ${test_dir}/grib_unpack_subarray $infile