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
Show file tree
Hide file tree
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: Simplification of templates
  • Loading branch information
Eugen Betke committed Mar 6, 2023
commit 3079588f3ea63e81fd94964bb8b876068609363c
16 changes: 14 additions & 2 deletions src/grib_accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
***************************************************************************/

#include "grib_api_internal.h"
#include "grib_accessor.h"

/* Note: A fast cut-down version of strcmp which does NOT return -1 */
/* 0 means input strings are equal and 1 means not equal */
Expand Down Expand Up @@ -233,7 +233,19 @@ int grib_unpack_float(grib_accessor* a, float* v, size_t* len)
c = c->super ? *(c->super) : NULL;
}
DebugAssert(0);
return GRIB_NOT_IMPLEMENTED;
return 0;
}

template <>
int grib_unpack<double>(grib_accessor* a, double* v, size_t* len)
{
return grib_unpack_double(a, v, len);
}

template <>
int grib_unpack<float>(grib_accessor* a, float* v, size_t* len)
{
return grib_unpack_float(a, v, len);
}

int grib_unpack_double_element(grib_accessor* a, size_t i, double* v)
Expand Down
45 changes: 41 additions & 4 deletions src/grib_accessor_class_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ or edit "accessor.class" and rerun ./make_class.pl

*/

//static int unpack_double(grib_accessor*, double* val, size_t* len);
//static int unpack_float(grib_accessor*, float* 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 unpack_long(grib_accessor*, long* val, size_t* len);
static int unpack_string(grib_accessor*, char*, size_t* len);
static long next_offset(grib_accessor*);
Expand Down Expand Up @@ -89,8 +89,8 @@ static grib_accessor_class _grib_accessor_class_bitmap = {
&unpack_long, /* grib_unpack procedures long */
0, /* grib_pack procedures double */
0, /* grib_pack procedures float */
&GribAccessorClassBitmap<double>::unpack, /* grib_unpack procedures double */
&GribAccessorClassBitmap<float>::unpack, /* grib_unpack procedures float */
&unpack_double, /* grib_unpack procedures double */
&unpack_float, /* grib_unpack procedures float */
0, /* grib_pack procedures string */
&unpack_string, /* grib_unpack procedures string */
0, /* grib_pack array procedures string */
Expand Down Expand Up @@ -247,6 +247,43 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
return GRIB_SUCCESS;
}

template <typename T>
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);
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;
return GRIB_ARRAY_TOO_SMALL;
}

for (i = 0; i < tlen; i++) {
val[i] = (T)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
}
*len = tlen;
return GRIB_SUCCESS;
}

static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
return unpack<double>(a, val, len);
}

static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
return unpack<float>(a, val, len);
}

static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
long pos = a->offset * 8;
Expand Down
117 changes: 113 additions & 4 deletions src/grib_accessor_class_data_apply_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/

#include "grib_api_internal.h"
#include "grib_accessor_class_data_apply_bitmap.h"
#include "grib_api_internal_cpp.h"
#include <typeinfo>
#include <type_traits>

/*
This is used by make_class.pl
Expand Down Expand Up @@ -44,13 +45,28 @@ or edit "accessor.class" and rerun ./make_class.pl

static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
template <typename T> static int unpack(grib_accessor* a, T* 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 dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
static void init_class(grib_accessor_class*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);

typedef struct grib_accessor_data_apply_bitmap
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in data_apply_bitmap */
const char* coded_values;
const char* bitmap;
const char* missing_value;
const char* number_of_data_points;
const char* number_of_values;
const char* binary_scale_factor;
} grib_accessor_data_apply_bitmap;

extern grib_accessor_class* grib_accessor_class_gen;

Expand All @@ -77,8 +93,8 @@ static grib_accessor_class _grib_accessor_class_data_apply_bitmap = {
0, /* grib_unpack procedures long */
&pack_double, /* grib_pack procedures double */
0, /* grib_pack procedures float */
&GribAccessorDataApplyBitmap<double>::unpack, /* grib_unpack procedures double */
&GribAccessorDataApplyBitmap<float>::unpack, /* grib_unpack procedures float */
&unpack_double, /* grib_unpack procedures double */
&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 @@ -363,6 +379,99 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return err;
}

template <typename T>
static int unpack(grib_accessor* a, T* val, size_t* len)
{
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;

size_t i = 0;
size_t j = 0;
size_t n_vals = 0;
long nn = 0;
int err = 0;
size_t coded_n_vals = 0;
T* coded_vals = NULL;
double missing_value = 0;

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

if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap))
return grib_get_array<T>(grib_handle_of_accessor(a), self->coded_values, val, len);

if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &coded_n_vals)) != GRIB_SUCCESS)
return err;

if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
return err;

if (*len < n_vals) {
*len = n_vals;
return GRIB_ARRAY_TOO_SMALL;
}

if (coded_n_vals == 0) {
for (i = 0; i < n_vals; i++)
val[i] = missing_value;

*len = n_vals;
return GRIB_SUCCESS;
}

if ((err = grib_get_array_internal<T>(grib_handle_of_accessor(a), self->bitmap, val, &n_vals)) != GRIB_SUCCESS)
return err;

coded_vals = (T*)grib_context_malloc(a->context, coded_n_vals * sizeof(T));
if (coded_vals == NULL)
return GRIB_OUT_OF_MEMORY;

if ((err = grib_get_array<T>(grib_handle_of_accessor(a), self->coded_values, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) {
grib_context_free(a->context, coded_vals);
return err;
}

grib_context_log(a->context, GRIB_LOG_DEBUG,
"grib_accessor_class_data_apply_bitmap: %s : creating %s, %d values",
__PRETTY_FUNCTION__,
a->name, n_vals);

for (i = 0; i < n_vals; i++) {
if (val[i] == 0) {
val[i] = missing_value;
}
else {
val[i] = coded_vals[j++];
if (j > coded_n_vals) {
grib_context_free(a->context, coded_vals);
grib_context_log(a->context, GRIB_LOG_ERROR,
"grib_accessor_class_data_apply_bitmap [%s]:"
" %s : number of coded values does not match bitmap %ld %ld",
a->name, __PRETTY_FUNCTION__, coded_n_vals, n_vals);

return GRIB_ARRAY_TOO_SMALL;
}
}
}

*len = n_vals;

grib_context_free(a->context, coded_vals);
return err;
}

static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
return unpack<double>(a, val, len);
}

static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
return unpack<float>(a, val, len);
}

static int get_native_type(grib_accessor* a)
{
/* grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
Expand Down
109 changes: 0 additions & 109 deletions src/grib_accessor_class_data_apply_bitmap.h

This file was deleted.

Loading