Skip to content

Commit

Permalink
Merge branch 'develop' into feature/modernisation_action_const_destr
Browse files Browse the repository at this point in the history
  • Loading branch information
joobog committed Jan 15, 2025
2 parents dd2875f + 0e88697 commit d5d1fe8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/dumper/grib_dumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ class Dumper
virtual void header(const grib_handle*) const {};
virtual void footer(const grib_handle*) const {};

long count() { return count_; }
long count() const { return count_; }
void count(long count) { count_ = count; }

int depth_ = 0;
void* arg_ = nullptr;
unsigned long option_flags_ = 0;
grib_context* context_ = nullptr;
FILE* out_ = nullptr;
int inited_ = 0;

protected:
const char* class_name_ = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/dumper/grib_dumper_class_bufr_decode_C.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void BufrDecodeC::dump_string(grib_accessor* a, const char* comment)
(void)err; /* TODO */
}

void BufrDecodeC::dump_bytes(grib_accessor* a, const char* comment)
void BufrDecodeC::dump_bytes(grib_accessor* a, const char* comment)
{
}

Expand Down Expand Up @@ -547,7 +547,7 @@ void BufrDecodeC::dump_section(grib_accessor* a, grib_block_of_accessors* block)
}
}

void BufrDecodeC::dump_attributes(grib_accessor* a, const char* prefix)
void BufrDecodeC::dump_attributes(grib_accessor* a, const char* prefix)
{
int i = 0;
unsigned long flags;
Expand Down
4 changes: 2 additions & 2 deletions src/geo/iterator/grib_iterator_class_gaussian_reduced.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ int GaussianReduced::init(grib_handle* h, grib_arguments* args)

grib_get_long_array_internal(h, spl, pl, &plsize);

lats_ = (double*)grib_context_malloc(h->context, nv_ * sizeof(double));
lats_ = (double*)grib_context_malloc_clear(h->context, nv_ * sizeof(double));
if (!lats_)
return GRIB_OUT_OF_MEMORY;
lons_ = (double*)grib_context_malloc(h->context, nv_ * sizeof(double));
lons_ = (double*)grib_context_malloc_clear(h->context, nv_ * sizeof(double));
if (!lons_)
return GRIB_OUT_OF_MEMORY;

Expand Down
61 changes: 28 additions & 33 deletions src/grib_dumper_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static omp_nest_lock_t mutex;

static void init_mutex()
{
GRIB_OMP_CRITICAL(lock_dumper_c)
GRIB_OMP_CRITICAL(lock_grib_dumper_factory_c)
{
if (once == 0) {
omp_init_nest_lock(&mutex);
Expand All @@ -50,51 +50,47 @@ struct table_entry
};

static struct table_entry table[] = {
{"bufr_decode_C",&grib_dumper_bufr_decode_c,},
{"bufr_decode_filter",&grib_dumper_bufr_decode_filter,},
{"bufr_decode_fortran",&grib_dumper_bufr_decode_fortran,},
{"bufr_decode_python",&grib_dumper_bufr_decode_python,},
{"bufr_encode_C",&grib_dumper_bufr_encode_c,},
{"bufr_encode_filter",&grib_dumper_bufr_encode_filter,},
{"bufr_encode_fortran",&grib_dumper_bufr_encode_fortran,},
{"bufr_encode_python",&grib_dumper_bufr_encode_python,},
{"bufr_simple",&grib_dumper_bufr_simple,},
{"debug",&grib_dumper_debug,},
{"default",&grib_dumper_default,},
{"grib_encode_c",&grib_dumper_grib_encode_c,},
{"json",&grib_dumper_json,},
{"serialize",&grib_dumper_serialize,},
{"wmo",&grib_dumper_wmo,},
{"bufr_decode_C",&grib_dumper_bufr_decode_c,},
{"bufr_decode_filter",&grib_dumper_bufr_decode_filter,},
{"bufr_decode_fortran",&grib_dumper_bufr_decode_fortran,},
{"bufr_decode_python",&grib_dumper_bufr_decode_python,},
{"bufr_encode_C",&grib_dumper_bufr_encode_c,},
{"bufr_encode_filter",&grib_dumper_bufr_encode_filter,},
{"bufr_encode_fortran",&grib_dumper_bufr_encode_fortran,},
{"bufr_encode_python",&grib_dumper_bufr_encode_python,},
{"bufr_simple",&grib_dumper_bufr_simple,},
{"debug",&grib_dumper_debug,},
{"default",&grib_dumper_default,},
{"grib_encode_c",&grib_dumper_grib_encode_c,},
{"json",&grib_dumper_json,},
{"serialize",&grib_dumper_serialize,},
{"wmo",&grib_dumper_wmo,},
};

eccodes::Dumper* grib_dumper_factory(const char* op, const grib_handle* h, FILE* out, unsigned long option_flags, void* arg)
{
constexpr size_t num_table_entries = sizeof(table) / sizeof(table[0]);
for (size_t i = 0; i < num_table_entries; i++)
for (size_t i = 0; i < num_table_entries; i++) {
if (strcmp(op, table[i].type) == 0) {
eccodes::Dumper* d = *(table[i].dumper);
GRIB_MUTEX_INIT_ONCE(&once, &init_mutex);
GRIB_MUTEX_LOCK(&mutex);
if (!d->inited_) {
d->depth_ = 0;
d->context_ = h->context;
d->option_flags_ = option_flags;
d->arg_ = arg;
d->out_ = out;
d->init();
d->inited_ = 1;
}
d->depth_ = 0;
d->context_ = h->context;
d->option_flags_ = option_flags;
d->arg_ = arg;
d->out_ = out;
d->init();
GRIB_MUTEX_UNLOCK(&mutex);
grib_context_log(
h->context, GRIB_LOG_DEBUG, "Creating dumper of type : %s ", op);
return d;
}
grib_context_log(
h->context, GRIB_LOG_ERROR, "Unknown type : '%s' for dumper", op);
}
grib_context_log(h->context, GRIB_LOG_ERROR, "Unknown type : '%s' for dumper", op);
return NULL;
}


void grib_dump_content(const grib_handle* h, FILE* f, const char* mode, unsigned long flags, void* data)
{
eccodes::Dumper* dumper = grib_dumper_factory(mode ? mode : "serialize", h, f, flags, data);
Expand All @@ -115,7 +111,6 @@ void grib_dump_content(const grib_handle* h, FILE* f, const char* mode, unsigned
dumper->destroy();
}


void grib_dump_accessors_block(eccodes::Dumper* dumper, grib_block_of_accessors* block)
{
grib_accessor* a = block->first;
Expand Down Expand Up @@ -160,15 +155,15 @@ void grib_dump_keys(grib_handle* h, FILE* f, const char* mode, unsigned long fla
eccodes::Dumper* dumper = grib_dumper_factory(mode ? mode : "serialize", h, f, flags, data);
if (!dumper)
return;
GRIB_MUTEX_INIT_ONCE(&once, &init_mutex);
GRIB_MUTEX_LOCK(&mutex);
for (size_t i = 0; i < num_keys; ++i) {
acc = grib_find_accessor(h, keys[i]);
if (acc) {
GRIB_MUTEX_INIT_ONCE(&once, &init_mutex);
GRIB_MUTEX_LOCK(&mutex);
acc->dump(dumper);
GRIB_MUTEX_UNLOCK(&mutex);
}
}
GRIB_MUTEX_UNLOCK(&mutex);
dumper->destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion src/grib_iterator_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static omp_nest_lock_t mutex;

static void init_mutex()
{
GRIB_OMP_CRITICAL(lock_grib_accessor_class_c)
GRIB_OMP_CRITICAL(lock_grib_iterator_factory_c)
{
if (once == 0) {
omp_init_nest_lock(&mutex);
Expand Down
9 changes: 3 additions & 6 deletions src/grib_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,12 @@ int grib_set_long(grib_handle* h, const char* name, long val)
fprintf(stderr, "ECCODES DEBUG grib_set_long h=%p %s=%ld\n", (void*)h, name, val);
}

if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) {
if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)
return GRIB_READ_ONLY;
}

ret = a->pack_long(&val, &l);
if (ret == GRIB_SUCCESS) {
auto ret = grib_dependency_notify_change(a);
return ret;
}
if (ret == GRIB_SUCCESS)
return grib_dependency_notify_change(a);

return ret;
}
Expand Down

0 comments on commit d5d1fe8

Please sign in to comment.