diff --git a/fortran/eccodes_f90_tail.f90 b/fortran/eccodes_f90_tail.f90 index fcc0c860b..05d59beb5 100644 --- a/fortran/eccodes_f90_tail.f90 +++ b/fortran/eccodes_f90_tail.f90 @@ -2765,6 +2765,12 @@ call grib_skip_read_only(iterid, status) end subroutine codes_skip_read_only + !> Set debug mode + subroutine codes_set_debug(mode) + integer(kind=kindOfInt), intent(in) :: mode + call grib_set_debug(mode) + end subroutine codes_set_debug + !> Set the definition path !> !> In case of error, if the status parameter (optional) is not given, the program will diff --git a/fortran/grib_api_externals.h b/fortran/grib_api_externals.h index f789fb92e..fd3d6c10a 100644 --- a/fortran/grib_api_externals.h +++ b/fortran/grib_api_externals.h @@ -79,7 +79,7 @@ integer, external :: grib_f_set_int, grib_f_set_int_array, & integer, external :: grib_f_get_message_size, grib_f_copy_message, grib_f_count_in_file integer, external :: grib_f_write, grib_f_multi_write, grib_f_multi_append integer, external :: grib_f_clone, grib_f_copy_namespace -external :: grib_f_check +external :: grib_f_check , grib_f_set_debug integer, external :: grib_f_util_sections_copy integer, external :: grib_f_set_definitions_path, grib_f_set_samples_path integer, external :: grib_f_julian_to_datetime, grib_f_datetime_to_julian, grib_f_copy_key diff --git a/fortran/grib_f90_tail.f90 b/fortran/grib_f90_tail.f90 index c178eedbe..be1a574ff 100644 --- a/fortran/grib_f90_tail.f90 +++ b/fortran/grib_f90_tail.f90 @@ -3177,6 +3177,13 @@ end if end subroutine grib_skip_read_only + !> Set debug mode + subroutine grib_set_debug(mode) + integer(kind=kindOfInt), intent(in) :: mode + call grib_f_set_debug(mode) + end subroutine grib_set_debug + + !> Set the definition path !> !> In case of error, if the status parameter (optional) is not given, the program will diff --git a/fortran/grib_fortran.cc b/fortran/grib_fortran.cc index 972118384..1539bc9db 100644 --- a/fortran/grib_fortran.cc +++ b/fortran/grib_fortran.cc @@ -975,8 +975,9 @@ int grib_f_close_file_(int* fid) /*****************************************************************************/ static int file_count=0; -void grib_f_write_on_fail(int* gid) { - grib_context* c=grib_context_get_default(); +void grib_f_write_on_fail(int* gid) +{ + grib_context* c = grib_context_get_default(); if (c->write_on_fail) { char filename[100]={0,}; grib_handle* h=NULL; @@ -993,7 +994,8 @@ void grib_f_write_on_fail(int* gid) { if (h) grib_write_message(h,filename,"w"); } } -void grib_f_write_on_fail_(int* gid) { +void grib_f_write_on_fail_(int* gid) +{ grib_f_write_on_fail(gid); } /*****************************************************************************/ @@ -2890,6 +2892,13 @@ int codes_f_bufr_multi_element_constant_arrays_off_(void) return GRIB_SUCCESS; } +/*****************************************************************************/ +void grib_f_set_debug_(int mode) +{ + grib_context* c = grib_context_get_default(); + grib_context_set_debug(c, mode); +} + /*****************************************************************************/ int grib_f_set_definitions_path_(char* path, int len) { diff --git a/fortran/grib_fortran_prototypes.h b/fortran/grib_fortran_prototypes.h index 4eb0a313d..7af6b2101 100644 --- a/fortran/grib_fortran_prototypes.h +++ b/fortran/grib_fortran_prototypes.h @@ -309,6 +309,7 @@ int grib_f_multi_append__(int *ingid, int *sec, int *mgid); int codes_f_bufr_keys_iterator_new_(int* gid,int* iterid); int grib_f_read_file_(int* fid, void* buffer, size_t* nbytes); int codes_f_bufr_keys_iterator_delete_(int* iterid); +void grib_f_set_debug_(int mode); int grib_f_set_definitions_path_(char* path, int len); int grib_f_read_any_from_file_(int* fid, void* buffer, size_t* nbytes); int any_f_new_from_file_(int* fid, int* gid); diff --git a/src/eccodes.cc b/src/eccodes.cc index 9ec6d8073..779690790 100644 --- a/src/eccodes.cc +++ b/src/eccodes.cc @@ -585,6 +585,11 @@ void codes_context_set_samples_path(grib_context* c, const char* path) grib_context_set_samples_path(c, path); } +void codes_context_set_debug(grib_context* c, int mode) +{ + grib_context_set_debug(c, mode); +} + void codes_context_set_memory_proc(grib_context* c, grib_malloc_proc p_malloc, grib_free_proc p_free, grib_realloc_proc p_realloc) { grib_context_set_memory_proc(c, p_malloc, p_free, p_realloc); diff --git a/src/eccodes.h b/src/eccodes.h index f0b110b86..0c8f7193c 100644 --- a/src/eccodes.h +++ b/src/eccodes.h @@ -1174,6 +1174,8 @@ void codes_context_set_definitions_path(codes_context* c, const char* path); */ void codes_context_set_samples_path(codes_context* c, const char* path); +void codes_context_set_debug(grib_context* c, int mode); + /** * Sets memory procedures of the context * diff --git a/src/grib_api.h b/src/grib_api.h index 84566b108..09601899f 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -1169,6 +1169,8 @@ void grib_context_set_definitions_path(grib_context* c, const char* path); */ void grib_context_set_samples_path(grib_context* c, const char* path); +void grib_context_set_debug(grib_context* c, int mode); + /** * Sets memory procedures of the context * diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc index 22a394548..d1575301a 100644 --- a/tests/unit_tests.cc +++ b/tests/unit_tests.cc @@ -742,10 +742,36 @@ void test_codes_get_error_message() Assert( STR_EQUAL(errmsg, "Unknown error -6666")); } +void test_codes_context_set_debug() +{ + printf("Running %s ...\n", __func__); + grib_context* context = NULL; + int err = 0; + + printf("\tEnable debugging...\n"); + grib_context_set_debug(context, -1); + + grib_handle* h = grib_handle_new_from_samples(context, "GRIB2"); + err = grib_set_long(h, "paramId", 167); + Assert(!err); + + printf("\tDisable debugging...\n"); + grib_context_set_debug(context, 0); + + err = grib_set_long(h, "edition", 1); + Assert(!err); + printf("\tEnable debugging again (verbose)...\n"); + grib_context_set_debug(context, 1); + grib_handle_delete(h); + + grib_context_set_debug(context, 0); +} + int main(int argc, char** argv) { printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version()); + test_codes_context_set_debug(); test_codes_get_error_message(); test_iarray();