ECC-1899: API function to allow setting debug level

This commit is contained in:
shahramn 2024-08-09 14:27:16 +01:00
parent f5b8a9b7f1
commit eac06e8853
9 changed files with 62 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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
*

View File

@ -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
*

View File

@ -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();