ECC-992: New environment variable ECCODES_DEFINITION_PATH_SUPPLEMENT. Also added test

This commit is contained in:
Shahram Najm 2019-11-28 15:53:46 +00:00
parent ebcd2168f7
commit beba803afb
3 changed files with 40 additions and 4 deletions

View File

@ -461,6 +461,16 @@ grib_context* grib_context_get_default()
}
}
/* Definitions path supplement: Added at the head of existing path */
{
const char* defs_supp = codes_getenv("ECCODES_DEFINITION_PATH_SUPPLEMENT");
if (defs_supp) {
char buffer[DEF_PATH_MAXLEN];
ecc_snprintf(buffer, DEF_PATH_MAXLEN, "%s:%s", defs_supp, default_grib_context.grib_definition_files_path);
default_grib_context.grib_definition_files_path = strdup(buffer);
}
}
grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Definitions path: %s",
default_grib_context.grib_definition_files_path);
grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Samples path: %s",

View File

@ -11,7 +11,7 @@
. ./include.sh
set -u
# ---------------------------------------------------------
# This is the test for data quality checks
# Tests for data quality checks
# ---------------------------------------------------------
label="grib_data_quality"
tempOut=temp.${label}.out
@ -19,6 +19,8 @@ tempErr=temp.${label}.err
input1=${data_dir}/reduced_gaussian_surface.grib1
input2=${data_dir}/reduced_gaussian_surface.grib2
grib_check_key_equals $input1 paramId 167
grib_check_key_equals $input2 paramId 167
# Data quality checks disabled. Create cause huge values for temperature
unset ECCODES_GRIB_DATA_QUALITY_CHECKS
@ -43,6 +45,30 @@ set -e
grep -q 'GRIB2 simple packing: unable to set values' $tempErr
grep -q 'outside allowable limits' $tempErr
# Override the defaults
# ----------------------
tempDir=tempdir.$label
rm -rf $tempDir
mkdir -p $tempDir
# Set a large limit for temperature
cat > $tempDir/param_limits.def <<EOF
constant default_min_val = -1e9 : long_type, hidden;
constant default_max_val = +1e9 : long_type, hidden;
concept param_value_min(default_min_val) {
0 = { paramId=167; }
} : long_type, hidden;
concept param_value_max(default_max_val) {
40000 = { paramId=167; }
} : long_type, hidden;
EOF
# Command should not fail now
export ECCODES_GRIB_DATA_QUALITY_CHECKS=1
export ECCODES_DEFINITION_PATH_SUPPLEMENT=$test_dir/$tempDir
${tools_dir}/grib_set -s scaleValuesBy=100 $input1 $tempOut
# Clean up
rm -rf $tempDir
rm -f $tempOut $tempErr

View File

@ -35,6 +35,7 @@ int main( int argc,char* argv[])
int major=ECCODES_MAJOR_VERSION;
int minor=ECCODES_MINOR_VERSION;
int revision=ECCODES_REVISION_VERSION;
grib_context* context = grib_context_get_default();
while (1) {
int c = getopt (argc, argv, "vds");
@ -61,7 +62,6 @@ int main( int argc,char* argv[])
if (nfiles != 0) usage_and_exit(argv[0]);
if (print_flags == INFO_PRINT_ALL) {
grib_context* context = grib_context_get_default();
printf("\n");
printf("%s Version %d.%d.%d",
grib_get_package_name(), major,minor,revision);
@ -90,7 +90,7 @@ int main( int argc,char* argv[])
printf("(This is for backward compatibility. "
"It is recommended you use ECCODES_DEFINITION_PATH instead!)\n");
} else {
printf("Default definition files path is used: %s\n",ECCODES_DEFINITION_PATH);
printf("Default definition files path is used: %s\n",context->grib_definition_files_path);
printf("Definition files path can be changed by setting ECCODES_DEFINITION_PATH environment variable\n");
}
printf("\n");
@ -118,7 +118,7 @@ int main( int argc,char* argv[])
if ((path=codes_getenv("ECCODES_DEFINITION_PATH")) != NULL) {
printf("%s",path);
} else {
printf("%s",ECCODES_DEFINITION_PATH);
printf("%s",context->grib_definition_files_path);
}
}