Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ecc 1467 float data values #83

Merged
merged 49 commits into from
Mar 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6a26e0f
ECC-1467: GRIB: Support data values array decoded as floats (Part 01)
shahramn Dec 28, 2022
78af61b
ECC-1467: GRIB: Support data values array decoded as floats (Part 02)
shahramn Dec 29, 2022
4dd790f
ECC-1467: Debugging
shahramn Dec 29, 2022
573f2f9
ECC-1467: First working version for simple packing
shahramn Dec 29, 2022
445798c
ECC-1467: Testing
shahramn Dec 29, 2022
8d55550
ECC-1467: GRIB: Support data values array decoded as floats (Part 03)
shahramn Dec 29, 2022
e0e4655
ECC-1467: GRIB: Support data values array decoded as floats (Part 04)
shahramn Dec 30, 2022
f16ba71
ECC-1467: GRIB: Support data values array decoded as floats (Part 04)
shahramn Dec 30, 2022
5fea28e
ECC-1467: Added test
shahramn Dec 30, 2022
ff77426
ECC-1467: Cleanup
shahramn Dec 30, 2022
4cb2e12
ECC-1467: Add grib_accessors_list_unpack_float
shahramn Dec 30, 2022
cc4ef5a
ECC-1467: Add codes_keys_iterator_get_float
shahramn Dec 30, 2022
c36ac36
ECC-1467: GRIB: Support data values array decoded as floats (Part 05)
shahramn Dec 30, 2022
6fcef54
ECC-1467: GRIB: Support data values array decoded as floats (Part 06)
shahramn Dec 31, 2022
ffc9f13
ECC-1467: cpplint warnings
shahramn Jan 2, 2023
d1275b0
ECC-1467: Placeholder for spherical harmonics (to be done)
shahramn Jan 2, 2023
dab6eef
ECC-1467: TODO items
shahramn Jan 2, 2023
e1beaac
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
shahramn Jan 4, 2023
7f076a3
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
shahramn Jan 6, 2023
19dbc00
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
shahramn Jan 22, 2023
b669abf
ECC-1508: Set project language to be C++
shahramn Jan 29, 2023
a555f55
ECC-1508: Set C++ standard to 11 and re-enable test
shahramn Jan 30, 2023
1d3b074
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
shahramn Jan 30, 2023
995ed22
ECC-1508: Change file extensions to '.cc'
shahramn Jan 30, 2023
2cad3be
ECC-1467: Complex packing single-precision
Jan 30, 2023
b8da4f1
ECC-1467: Minor changes
Jan 30, 2023
43f7faf
Merge branch 'feature/ECC-1467-FloatDataValues-Compression' into feat…
Jan 30, 2023
370f046
ECC-1467: Complex single-precision
Jan 30, 2023
213b250
ECC-1467: Cleanup debug output
Jan 30, 2023
c6717ff
ECC-1467: Basic shell constructs
Jan 30, 2023
0300878
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
shahramn Feb 12, 2023
150c538
Remove unused variables
shahramn Feb 12, 2023
0a9d311
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
Feb 17, 2023
687e3f4
ECC-1467: Single-precision implementation with the use of templates
Feb 20, 2023
9d5d888
Merge develop
shahramn Feb 26, 2023
b1f5856
ECC-1467: template for second order packing
Mar 1, 2023
9371a32
ECC-1467: typename check in templates
Mar 1, 2023
3079588
ECC-1467: Simplification of templates
Mar 6, 2023
8486b71
ECC-1467: Missing header file
Mar 6, 2023
3a300d7
Pseudo code
Mar 7, 2023
58ee3be
ECC-1467: Revert changes in the unpack_double_element_set() function
Mar 8, 2023
8425eeb
ECC-1467: Minor changes
Mar 8, 2023
d300abb
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
joobog Mar 13, 2023
94f69da
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
joobog Mar 13, 2023
b892ff1
ECC-1467: Fixed data run length class
joobog Mar 13, 2023
ce053e1
ECC-1467: Fixed data run length class
joobog Mar 13, 2023
97a007a
ECC-1467: Use __func__ in log messages
joobog Mar 13, 2023
c41518d
Merge branch 'feature/ECC-1467-FloatDataValues' of github.com:joobog/…
joobog Mar 13, 2023
46b6736
Merge branch 'develop' into feature/ECC-1467-FloatDataValues
shahramn Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ECC-1467: GRIB: Support data values array decoded as floats (Part 03)
  • Loading branch information
shahramn committed Dec 29, 2022
commit 8d55550732c727ad426c7fa82eba0d049bfd918d
121 changes: 119 additions & 2 deletions src/grib_accessor_class_data_ccsds_packing.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SUPER = grib_accessor_class_values
IMPLEMENTS = init
IMPLEMENTS = unpack_double
IMPLEMENTS = unpack_float
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double_element;unpack_double_element_set
IMPLEMENTS = value_count
Expand Down Expand Up @@ -49,6 +50,7 @@ or edit "accessor.class" and rerun ./make_class.pl

static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
static void init_class(grib_accessor_class*);
Expand Down Expand Up @@ -103,7 +105,7 @@ static grib_accessor_class _grib_accessor_class_data_ccsds_packing = {
&pack_double, /* grib_pack procedures double */
0, /* grib_pack procedures float */
&unpack_double, /* grib_unpack procedures double */
0, /* grib_unpack procedures float */
&unpack_float, /* grib_unpack procedures float */
0, /* grib_pack procedures string */
0, /* grib_unpack procedures string */
0, /* grib_pack array procedures string */
Expand Down Expand Up @@ -143,7 +145,6 @@ static void init_class(grib_accessor_class* c)
c->pack_long = (*(c->super))->pack_long;
c->unpack_long = (*(c->super))->unpack_long;
c->pack_float = (*(c->super))->pack_float;
c->unpack_float = (*(c->super))->unpack_float;
c->pack_string = (*(c->super))->pack_string;
c->unpack_string = (*(c->super))->unpack_string;
c->pack_string_array = (*(c->super))->pack_string_array;
Expand Down Expand Up @@ -329,6 +330,117 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return err;
}

// TODO: Not ideal!! First attempt at unpacking floats...
// Should be merged with unpack_double and refactored! Most probably using C++ templates
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
grib_handle* hand = grib_handle_of_accessor(a);

int err = GRIB_SUCCESS, i = 0;
size_t buflen = 0;
struct aec_stream strm;
double bscale = 0;
double dscale = 0;
unsigned char* buf = NULL;
size_t n_vals = 0;
size_t size = 0;
unsigned char* decoded = NULL;
/*unsigned char* p = NULL;*/
long pos = 0;
long nn = 0;

long binary_scale_factor = 0;
long decimal_scale_factor = 0;
double reference_value = 0;
long bits_per_value = 0;
long bits8;

long ccsds_flags;
long ccsds_block_size;
long ccsds_rsi;

self->dirty = 0;

if ((err = grib_value_count(a, &nn)) != GRIB_SUCCESS)
return err;
n_vals = nn;

if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(hand, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(hand, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS)
return err;

/* ECC-477: Don't call grib_get_long_internal to suppress error message being output */
if ((err = grib_get_long(hand, self->ccsds_flags, &ccsds_flags)) != GRIB_SUCCESS)
return err;

if ((err = grib_get_long_internal(hand, self->ccsds_block_size, &ccsds_block_size)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(hand, self->ccsds_rsi, &ccsds_rsi)) != GRIB_SUCCESS)
return err;

/* TODO: This should be called upstream */
if (*len < n_vals)
return GRIB_ARRAY_TOO_SMALL;

/* Special case */
if (bits_per_value == 0) {
for (i = 0; i < n_vals; i++)
val[i] = reference_value;
*len = n_vals;
return GRIB_SUCCESS;
}

bscale = grib_power(binary_scale_factor, 2);
dscale = grib_power(-decimal_scale_factor, 10);

buflen = grib_byte_count(a);
buf = (unsigned char*)hand->buffer->data;
buf += grib_byte_offset(a);

strm.flags = ccsds_flags;
strm.bits_per_sample = bits_per_value;
strm.block_size = ccsds_block_size;
strm.rsi = ccsds_rsi;

strm.next_in = buf;
strm.avail_in = buflen;

bits8 = ((bits_per_value + 7) / 8) * 8;
size = n_vals * ((bits_per_value + 7) / 8);
decoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context, size);
if (!decoded) {
err = GRIB_OUT_OF_MEMORY;
goto cleanup;
}
strm.next_out = decoded;
strm.avail_out = size;

if (hand->context->debug) print_aec_stream_info(&strm, "unpack_float");

if ((err = aec_buffer_decode(&strm)) != AEC_OK) {
grib_context_log(a->context, GRIB_LOG_ERROR, "CCSDS unpack_float: aec_buffer_decode error %d (%s)\n",
err, aec_get_error_message(err));
err = GRIB_ENCODING_ERROR;
goto cleanup;
}

pos = 0;

/* ECC-1427: Performance improvement */
grib_decode_float_array(decoded, &pos, bits8 , reference_value, bscale, dscale, n_vals, val);
*len = n_vals;

cleanup:
grib_context_buffer_free(a->context, decoded);
return err;
}

static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
Expand Down Expand Up @@ -676,6 +788,11 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
print_error_feature_not_enabled(a->context);
Expand Down