From 9be7d194cda303619d427636cea40115dba5f144 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 9 Aug 2019 17:08:59 +0100 Subject: [PATCH] Refactoring: move the grib_context functions out of grib_handle --- src/grib_api_prototypes.h | 14 ++++++------- src/grib_context.c | 42 +++++++++++++++++++++++++++++++++++++-- src/grib_handle.c | 42 --------------------------------------- 3 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index 208004772..f7a0386e9 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -1008,6 +1008,13 @@ bufr_descriptors_array* grib_context_expanded_descriptors_list_get(grib_context* void grib_context_expanded_descriptors_list_push(grib_context* c,const char* key,bufr_descriptors_array* expanded,bufr_descriptors_array* unexpanded); void codes_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc); void codes_assertion_failed(const char *message, const char *file, int line); +int grib_get_gribex_mode(grib_context* c); +void grib_gribex_mode_on(grib_context* c); +void grib_gribex_mode_off(grib_context* c); +void grib_gts_header_on(grib_context* c); +void grib_gts_header_off(grib_context* c); +void grib_multi_support_on(grib_context* c); +void grib_multi_support_off(grib_context* c); /* grib_date.c */ int grib_julian_to_datetime(double jd, long *year, long *month, long *day, long *hour, long *minute, long *second); @@ -1093,14 +1100,7 @@ grib_handle *grib_handle_new(grib_context *c); grib_action *grib_action_from_filter(const char *filter); int grib_handle_apply_action(grib_handle *h, grib_action *a); int grib_handle_prepare_action(grib_handle *h, grib_action *a); -void grib_multi_support_on(grib_context *c); -void grib_multi_support_off(grib_context *c); void grib_multi_support_reset_file(grib_context *c, FILE *f); -void grib_gts_header_on(grib_context *c); -void grib_gts_header_off(grib_context *c); -int grib_get_gribex_mode(grib_context *c); -void grib_gribex_mode_on(grib_context *c); -void grib_gribex_mode_off(grib_context *c); void grib_multi_support_reset(grib_context *c); /* grib_header_compute.c */ diff --git a/src/grib_context.c b/src/grib_context.c index d8c473d75..247d41682 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -375,8 +375,8 @@ grib_context* grib_context_get_default() #endif write_on_fail = codes_getenv("ECCODES_GRIB_WRITE_ON_FAIL"); - bufrdc_mode = codes_getenv("ECCODES_BUFRDC_MODE_ON"); - bufr_set_to_missing_if_out_of_range = codes_getenv("ECCODES_BUFR_SET_TO_MISSING_IF_OUT_OF_RANGE"); + bufrdc_mode = getenv("ECCODES_BUFRDC_MODE_ON"); + bufr_set_to_missing_if_out_of_range = getenv("ECCODES_BUFR_SET_TO_MISSING_IF_OUT_OF_RANGE"); large_constant_fields = codes_getenv("ECCODES_GRIB_LARGE_CONSTANT_FIELDS"); no_abort = codes_getenv("ECCODES_NO_ABORT"); debug = codes_getenv("ECCODES_DEBUG"); @@ -1089,3 +1089,41 @@ void codes_assertion_failed(const char* message, const char* file, int line) assertion(buffer); } } + +int grib_get_gribex_mode(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + return c->gribex_mode_on; +} +void grib_gribex_mode_on(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gribex_mode_on=1; +} +void grib_gribex_mode_off(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gribex_mode_on=0; +} + +void grib_gts_header_on(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gts_header_on=1; +} +void grib_gts_header_off(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->gts_header_on=0; +} + +void grib_multi_support_on(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->multi_support_on=1; +} +void grib_multi_support_off(grib_context* c) +{ + if ( !c ) c=grib_context_get_default(); + c->multi_support_on=0; +} diff --git a/src/grib_handle.c b/src/grib_handle.c index 4364b8c8b..d351cde5a 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -1531,18 +1531,6 @@ static void grib2_build_message ( grib_context* context,unsigned char* sections[ *len=msglen; } -void grib_multi_support_on ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->multi_support_on=1; -} - -void grib_multi_support_off ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->multi_support_on=0; -} - /* For multi support mode: Reset all file handles equal to f. See GRIB-249 */ void grib_multi_support_reset_file(grib_context* c, FILE* f) { @@ -1557,36 +1545,6 @@ void grib_multi_support_reset_file(grib_context* c, FILE* f) } } -void grib_gts_header_on ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gts_header_on=1; -} - -void grib_gts_header_off ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gts_header_on=0; -} - -int grib_get_gribex_mode ( grib_context* c) -{ - if ( !c ) c=grib_context_get_default(); - return c->gribex_mode_on; -} - -void grib_gribex_mode_on ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gribex_mode_on=1; -} - -void grib_gribex_mode_off ( grib_context* c ) -{ - if ( !c ) c=grib_context_get_default(); - c->gribex_mode_on=0; -} - static grib_multi_support* grib_get_multi_support ( grib_context* c, FILE* f ) { int i=0;