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/modernisation_inheritance #209

Merged
merged 66 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a78865c
Prepare migration
joobog Mar 15, 2024
6647a21
Create a todo list
joobog Mar 17, 2024
be71970
Abstract grib_accessor and grib_accessor_class
joobog Mar 17, 2024
35b689a
Accessor backend ready for running accessors
joobog Mar 17, 2024
c598a51
Add "accessor/" prefix to grib_accessor_class_*.cc
joobog Mar 18, 2024
f1d68aa
18% tests passed, 276 tests failed out of 337
joobog Mar 18, 2024
8529fc3
Enable disabled BUFR function calls
joobog Mar 19, 2024
78c1129
Fix offsets
joobog Mar 19, 2024
6fc7074
Fix initialisation
joobog Mar 19, 2024
05e8b45
99% tests passed, 4 tests failed out of 337
joobog Apr 4, 2024
8a7f8c8
Fix compilation
shahramn Apr 4, 2024
1184bcc
Make local functions static
shahramn Apr 4, 2024
77d358a
Fix memory issue
joobog Apr 9, 2024
6bdef3a
Fix compare function
joobog Apr 9, 2024
6f54b96
Merge branch 'feature/modernisation-inheritance' of github.com:ecmwf/…
joobog Apr 9, 2024
ea48de7
PNG fix
joobog Apr 9, 2024
78a9429
Add PNG_ANYBITS
shahramn Apr 9, 2024
8a58ba1
Merge branch 'feature/modernisation-inheritance' of github.com:ecmwf/…
joobog Apr 9, 2024
cec5b2f
Fix destroy() function
joobog Apr 9, 2024
cc40569
Fix memory leak
joobog Apr 9, 2024
eb8bdcf
ECC-1800: GRIB2: Failure setting stepUnits=s,paramId=210203
shahramn Apr 16, 2024
a43c798
C++ modernisation: Added Fortran
shahramn Apr 16, 2024
6f9a1b6
C++ modernisation: Fix Fortran
shahramn Apr 16, 2024
14648c6
Print dataset when concept match fails
shahramn Apr 25, 2024
f229bd5
Remove staticForceStepUnits
shahramn Apr 25, 2024
5dd62ff
Initialise return values
shahramn Apr 25, 2024
17e250b
Cleanup
shahramn Apr 27, 2024
82cb39c
C++: Move function from header to local static
shahramn Apr 27, 2024
aca85e1
C++: Move function from header to local static. Use pragma once
shahramn Apr 27, 2024
6018a0a
Fix the includes: Do not use ..
shahramn Apr 27, 2024
bbcf302
Copyright notices
shahramn Apr 27, 2024
7857878
Remove unnecessary header files
shahramn Apr 27, 2024
f6d4295
Initialize all data members
shahramn Apr 27, 2024
f55015e
Testing: Catch error messages (Setting integer values double array)
shahramn Apr 30, 2024
3630e3b
Merge branch 'develop' into feature/modernisation-inheritance
joobog Apr 30, 2024
437d6c9
Merge branch 'feature/modernisation-inheritance' of github.com:ecmwf/…
joobog May 2, 2024
41a7e62
Merge branch 'develop' into feature/modernisation-inheritance
joobog May 2, 2024
4735c01
Simplify generic pack_double function
joobog May 2, 2024
33dbaa5
Fix reflection
joobog May 2, 2024
ea6fca2
Initialisation of accessors lists
joobog May 3, 2024
7ddc88a
Fix py_bufr_ecc-869.py test
joobog May 7, 2024
5d63a54
Merge branch 'develop' into feature/modernisation-inheritance
joobog May 7, 2024
677f73f
ECC-1820: Fix Windows build
shahramn May 7, 2024
481c78c
ECC-1820: Fix CCSDS class when -DENABLE_AEC=OFF
shahramn May 7, 2024
867da99
Cleanup
joobog May 7, 2024
45b5d55
Merge branch 'feature/modernisation-inheritance' of github.com:ecmwf/…
joobog May 7, 2024
41c513e
ECC-1820: Remove duplicate entry
shahramn May 7, 2024
6b1dae3
Cleanup
joobog May 7, 2024
1a3e11e
Better commment
joobog May 7, 2024
6aa4be2
Remove unnecessary includes
joobog May 7, 2024
ce1aac2
Merge branch 'feature/modernisation-inheritance' of github.com:ecmwf/…
joobog May 7, 2024
57b2698
Compiler warnings re sprintf
shahramn May 8, 2024
cf72dca
Move function from header to local static. Use pragma once
shahramn May 8, 2024
0d802de
Fix grib_accessor_class_gen definition
joobog May 8, 2024
e0f2213
ECC-1820: Remove unnecessary header files
shahramn May 8, 2024
f0b68e4
ECC-1820: Accessor hash
shahramn May 8, 2024
915935d
ECC-1820: Remove unused files
shahramn May 8, 2024
d397f58
ECC-1820: Local static functions
shahramn May 8, 2024
e47f092
Move functions from header to local static. Use 'pragma once'
shahramn May 9, 2024
afb4271
Cosmetics
shahramn May 9, 2024
5661700
ECC-1820: Use 'pragma once' in all header files
shahramn May 10, 2024
98cf979
ECC-1820: grib_accessors_list.rank made private
shahramn May 10, 2024
80d3a68
Cosmetics
shahramn May 10, 2024
ac80478
Cosmetics
shahramn May 10, 2024
22bd62c
Cosmetics
shahramn May 10, 2024
1514b73
Merge branch 'develop' into feature/modernisation-inheritance
shahramn May 13, 2024
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
Cosmetics
  • Loading branch information
shahramn committed May 10, 2024
commit ac80478fa4b8380915efd97b9ee084155920a485
16 changes: 10 additions & 6 deletions src/accessor/grib_accessor_class_position.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@

#include "grib_accessor_class_position.h"

grib_accessor_class_position_t _grib_accessor_class_position{"position"};
grib_accessor_class_position_t _grib_accessor_class_position{ "position" };
grib_accessor_class* grib_accessor_class_position = &_grib_accessor_class_position;


void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib_arguments* arg){
void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib_arguments* arg)
{
grib_accessor_class_gen_t::init(a, len, arg);
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN;
a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC;
}

int grib_accessor_class_position_t::get_native_type(grib_accessor* a){
int grib_accessor_class_position_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_LONG;
}

void grib_accessor_class_position_t::dump(grib_accessor* a, grib_dumper* dumper){
void grib_accessor_class_position_t::dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_long(dumper, a, NULL);
}

int grib_accessor_class_position_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int grib_accessor_class_position_t::unpack_long(grib_accessor* a, long* val, size_t* len)
{
if (*len < 1) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1);
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values ", a->name, 1);
*len = 0;
return GRIB_ARRAY_TOO_SMALL;
}
Expand Down
80 changes: 47 additions & 33 deletions src/accessor/grib_accessor_class_proj_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

#include "grib_accessor_class_proj_string.h"

grib_accessor_class_proj_string_t _grib_accessor_class_proj_string{"proj_string"};
grib_accessor_class_proj_string_t _grib_accessor_class_proj_string{ "proj_string" };
grib_accessor_class* grib_accessor_class_proj_string = &_grib_accessor_class_proj_string;


void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, grib_arguments* arg){
void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, grib_arguments* arg)
{
grib_accessor_class_gen_t::init(a, len, arg);
grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
grib_handle* h = grib_handle_of_accessor(a);

self->grid_type = grib_arguments_get_name(h, arg, 0);
self->endpoint = grib_arguments_get_long(h, arg, 1);
Expand All @@ -27,21 +28,23 @@ void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, g
a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC;
}

int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a){
int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_STRING;
}

// Function pointer than takes a handle and returns the proj string
typedef int (*proj_func)(grib_handle*, char*);
struct proj_mapping
{
const char* gridType; // key gridType
proj_func func; // function to compute proj string
const char* gridType; // key gridType
proj_func func; // function to compute proj string
};
typedef struct proj_mapping proj_mapping;

// This should only be called for GRID POINT data (not spherical harmonics etc)
static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor){
static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor)
{
int err = 0;
if (grib_is_earth_oblate(h)) {
if ((err = grib_get_double_internal(h, "earthMinorAxisInMetres", pMinor)) != GRIB_SUCCESS) return err;
Expand All @@ -56,19 +59,21 @@ static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor){
}

// Caller must have allocated enough space in the 'result' argument
static int get_earth_shape(grib_handle* h, char* result){
static int get_earth_shape(grib_handle* h, char* result)
{
int err = 0;
double major = 0, minor = 0;
if ((err = get_major_minor_axes(h, &major, &minor)) != GRIB_SUCCESS)
return err;
if (major == minor)
snprintf(result, 128, "+R=%lf", major); // spherical
snprintf(result, 128, "+R=%lf", major); // spherical
else
snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate
snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate
return err;
}

static int proj_space_view(grib_handle* h, char* result){
static int proj_space_view(grib_handle* h, char* result)
{
return GRIB_NOT_IMPLEMENTED;
// int err = 0;
// char shape[128] = {0,};
Expand All @@ -84,18 +89,22 @@ static int proj_space_view(grib_handle* h, char* result){
// return err;
}

static int proj_albers(grib_handle* h, char* result){
static int proj_albers(grib_handle* h, char* result)
{
return GRIB_NOT_IMPLEMENTED;
}
static int proj_transverse_mercator(grib_handle* h, char* result){
static int proj_transverse_mercator(grib_handle* h, char* result)
{
return GRIB_NOT_IMPLEMENTED;
}
static int proj_equatorial_azimuthal_equidistant(grib_handle* h, char* result){
static int proj_equatorial_azimuthal_equidistant(grib_handle* h, char* result)
{
return GRIB_NOT_IMPLEMENTED;
}

static int proj_lambert_conformal(grib_handle* h, char* result){
int err = 0;
static int proj_lambert_conformal(grib_handle* h, char* result)
{
int err = 0;
char shape[128] = {0,};
double LoVInDegrees = 0, LaDInDegrees = 0, Latin1InDegrees = 0, Latin2InDegrees = 0;

Expand All @@ -110,12 +119,13 @@ static int proj_lambert_conformal(grib_handle* h, char* result){
if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS)
return err;
snprintf(result, 1024, "+proj=lcc +lon_0=%lf +lat_0=%lf +lat_1=%lf +lat_2=%lf %s",
LoVInDegrees, LaDInDegrees, Latin1InDegrees, Latin2InDegrees, shape);
LoVInDegrees, LaDInDegrees, Latin1InDegrees, Latin2InDegrees, shape);
return err;
}

static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result){
int err = 0;
static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result)
{
int err = 0;
char shape[128] = {0,};
double standardParallel = 0, centralLongitude = 0;

Expand All @@ -126,11 +136,12 @@ static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result){
if ((err = grib_get_double_internal(h, "centralLongitudeInDegrees", &centralLongitude)) != GRIB_SUCCESS)
return err;
snprintf(result, 1024, "+proj=laea +lon_0=%lf +lat_0=%lf %s",
centralLongitude, standardParallel, shape);
centralLongitude, standardParallel, shape);
return err;
}

static int proj_polar_stereographic(grib_handle* h, char* result){
static int proj_polar_stereographic(grib_handle* h, char* result)
{
int err = 0;
double centralLongitude = 0, centralLatitude = 0;
int has_northPole = 0;
Expand All @@ -147,33 +158,35 @@ static int proj_polar_stereographic(grib_handle* h, char* result){
return err;
has_northPole = ((projectionCentreFlag & 128) == 0);
snprintf(result, 1024, "+proj=stere +lat_ts=%lf +lat_0=%s +lon_0=%lf +k_0=1 +x_0=0 +y_0=0 %s",
centralLatitude, has_northPole ? "90" : "-90", centralLongitude, shape);
centralLatitude, has_northPole ? "90" : "-90", centralLongitude, shape);
return err;
}

// ECC-1552: This is for regular_ll, regular_gg, reduced_ll, reduced_gg
// These are not 'projected' grids!
static int proj_unprojected(grib_handle* h, char* result){
static int proj_unprojected(grib_handle* h, char* result)
{
int err = 0;
//char shape[128] = {0,};
//if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err;
//snprintf(result, 1024, "+proj=longlat %s", shape);
// char shape[128] = {0,};
// if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err;
// snprintf(result, 1024, "+proj=longlat %s", shape);
snprintf(result, 1024, "+proj=longlat +datum=WGS84 +no_defs +type=crs");

return err;
}

static int proj_mercator(grib_handle* h, char* result){
static int proj_mercator(grib_handle* h, char* result)
{
int err = 0;
double LaDInDegrees = 0;
char shape[128] = {0,};
char shape[128] = {0,};

if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS)
return err;
if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS)
return err;
snprintf(result, 1024, "+proj=merc +lat_ts=%lf +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 %s",
LaDInDegrees, shape);
LaDInDegrees, shape);
return err;
}

Expand All @@ -195,17 +208,18 @@ static proj_mapping proj_mappings[] = {

#define ENDPOINT_SOURCE 0
#define ENDPOINT_TARGET 1
int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, size_t* len){
int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, size_t* len)
{
grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a;
int err = 0, found = 0;
size_t i = 0;
size_t i = 0;
char grid_type[64] = {0,};
grib_handle* h = grib_handle_of_accessor(a);
size_t size = sizeof(grid_type) / sizeof(*grid_type);
size_t size = sizeof(grid_type) / sizeof(*grid_type);

Assert(self->endpoint == ENDPOINT_SOURCE || self->endpoint == ENDPOINT_TARGET);

size_t l = 100; // Safe bet
size_t l = 100; // Safe bet
if (*len < l) {
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR,
Expand Down
33 changes: 21 additions & 12 deletions src/accessor/grib_accessor_class_raw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

#include "grib_accessor_class_raw.h"

grib_accessor_class_raw_t _grib_accessor_class_raw{"raw"};
grib_accessor_class_raw_t _grib_accessor_class_raw{ "raw" };
grib_accessor_class* grib_accessor_class_raw = &_grib_accessor_class_raw;


void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_arguments* arg){
void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_arguments* arg)
{
grib_accessor_class_gen_t::init(a, len, arg);
int n = 0;
int err = 0;
Expand All @@ -42,31 +43,37 @@ void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_argu
/* Assert(a->length>=0); */
}

int grib_accessor_class_raw_t::get_native_type(grib_accessor* a){
int grib_accessor_class_raw_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_BYTES;
}


int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b){
int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b)
{
int retval = GRIB_SUCCESS;

size_t alen = (size_t)a->byte_count(); size_t blen = (size_t)b->byte_count();
size_t alen = (size_t)a->byte_count();
size_t blen = (size_t)b->byte_count();
if (alen != blen)
return GRIB_COUNT_MISMATCH;

return retval;
}

long grib_accessor_class_raw_t::byte_count(grib_accessor* a){
long grib_accessor_class_raw_t::byte_count(grib_accessor* a)
{
return a->length;
}

int grib_accessor_class_raw_t::value_count(grib_accessor* a, long* len){
int grib_accessor_class_raw_t::value_count(grib_accessor* a, long* len)
{
*len = a->length;
return 0;
}

int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len){
int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len)
{
if (*len < a->length) {
*len = a->length;
return GRIB_ARRAY_TOO_SMALL;
Expand All @@ -78,7 +85,8 @@ int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buf
return GRIB_SUCCESS;
}

void grib_accessor_class_raw_t::update_size(grib_accessor* a, size_t s){
void grib_accessor_class_raw_t::update_size(grib_accessor* a, size_t s)
{
grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s);
a->length = s;
Assert(a->length >= 0);
Expand All @@ -94,13 +102,14 @@ long accessor_raw_get_offset(grib_accessor* a)
return a->offset;
}

int grib_accessor_class_raw_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len){
int grib_accessor_class_raw_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len)
{
size_t length = *len;
long totalLength;
long sectionLength;
grib_handle* h = grib_handle_of_accessor(a);
grib_handle* h = grib_handle_of_accessor(a);
grib_accessor_raw_t* self = (grib_accessor_raw_t*)a;
long dlen = length - a->length;
long dlen = length - a->length;

grib_get_long(h, self->totalLength, &totalLength);
totalLength += dlen;
Expand Down
16 changes: 9 additions & 7 deletions src/accessor/grib_accessor_class_rdbtime_guess_date.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ grib_accessor_class_rdbtime_guess_date_t _grib_accessor_class_rdbtime_guess_date
grib_accessor_class* grib_accessor_class_rdbtime_guess_date = &_grib_accessor_class_rdbtime_guess_date;


void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_long_t::init(a, l, c);
grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a;
int n = 0;
int n = 0;

self->typicalYear = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->typicalMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
Expand All @@ -29,14 +30,14 @@ void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long
/* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */
}

int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long* val, size_t* len)
{
grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
int ret = 0;
grib_handle* h = grib_handle_of_accessor(a);
long typicalYear, typicalMonth, typicalDay, rdbDay;
long rdbYear, rdbMonth;

ret = grib_get_long(h, self->typicalYear, &typicalYear);
int ret = grib_get_long(h, self->typicalYear, &typicalYear);
if (ret)
return ret;
ret = grib_get_long(h, self->typicalMonth, &typicalMonth);
Expand Down Expand Up @@ -70,7 +71,8 @@ int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long
return GRIB_SUCCESS;
}

int grib_accessor_class_rdbtime_guess_date_t::pack_long(grib_accessor* a, const long* v, size_t* len){
int grib_accessor_class_rdbtime_guess_date_t::pack_long(grib_accessor* a, const long* v, size_t* len)
{
/* do nothing*/
return GRIB_SUCCESS;
}
Loading