Merge branch 'feature/mtg2' of github.com:ecmwf/eccodes into feature/mtg2

This commit is contained in:
Shahram Najm 2024-08-09 16:11:50 +00:00
commit 598db6f70c
11 changed files with 69 additions and 6 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

@ -786,7 +786,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
// long nvals_per_group = 0;
// long nbits_per_group_val = 0;
long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues;
long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues, optimize_scale_factor;
// long groupSplittingMethodUsed, numberOfGroupsOfDataValues, referenceForGroupWidths;
long missingValueManagementUsed, primaryMissingValueSubstitute, secondaryMissingValueSubstitute;
long numberOfBitsUsedForTheGroupWidths, numberOfBitsUsedForTheScaledGroupLengths, orderOfSpatialDifferencing;
@ -815,7 +815,10 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c
if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS)
return err;
int use_scale = 1;
if ((err = grib_get_long_internal(gh, self->optimize_scale_factor, &optimize_scale_factor)) != GRIB_SUCCESS)
return err;
int use_scale = !optimize_scale_factor;
if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS)
return err;

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

@ -127,6 +127,8 @@ ${tools_dir}/grib_copy -r $infile $temp2
${tools_dir}/grib_compare -R all=0.3 -c data:n $infile $temp2
grib_check_key_equals $temp2 bitsPerValue 9 # Note: The input file has bpv=9
${tools_dir}/grib_set -rs optimizeScaleFactor=1 $infile $temp2
${tools_dir}/grib_compare $infile $temp2
# Simple to grid_complex
tempComplex=temp.grib_bitmap.complex.grib

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