ECC-1868: CMake: Add option for enabling the Geoiterator and nearest neighbour functionality

This commit is contained in:
shahramn 2024-07-12 09:51:12 +01:00
parent 2cbf603427
commit 9808b03d76
46 changed files with 260 additions and 91 deletions

View File

@ -99,6 +99,10 @@ ecbuild_add_option( FEATURE BUILD_TOOLS
DESCRIPTION "Build the command line tools"
DEFAULT ON )
ecbuild_add_option( FEATURE GEOGRAPHY
DESCRIPTION "Support for Geoiterator and nearest neighbour"
DEFAULT ON )
ecbuild_add_option( FEATURE JPG
DESCRIPTION "Support for JPG decoding/encoding"
DEFAULT ON )
@ -457,7 +461,7 @@ ecbuild_pkgconfig(
DESCRIPTION "The ecCodes library"
LIBRARIES eccodes
IGNORE_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIRS} ${NETCDF_INCLUDE_DIRS}
VARIABLES HAVE_MEMFS HAVE_JPEG HAVE_LIBJASPER HAVE_LIBOPENJPEG
VARIABLES HAVE_MEMFS HAVE_GEOGRAPHY HAVE_JPEG HAVE_LIBJASPER HAVE_LIBOPENJPEG
HAVE_ECCODES_THREADS HAVE_ECCODES_OMP_THREADS
HAVE_NETCDF HAVE_FORTRAN HAVE_PNG HAVE_AEC
)
@ -469,7 +473,7 @@ if( HAVE_FORTRAN )
DESCRIPTION "The ecCodes library for Fortran 90"
IGNORE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/fortran ${PROJECT_BINARY_DIR}/fortran
${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIRS} ${NETCDF_INCLUDE_DIRS}
VARIABLES HAVE_MEMFS HAVE_JPEG HAVE_LIBJASPER HAVE_LIBOPENJPEG
VARIABLES HAVE_MEMFS HAVE_GEOGRAPHY HAVE_JPEG HAVE_LIBJASPER HAVE_LIBOPENJPEG
HAVE_ECCODES_THREADS HAVE_ECCODES_OMP_THREADS
HAVE_NETCDF HAVE_PNG HAVE_AEC
)

View File

@ -111,6 +111,7 @@
#cmakedefine HAVE_NETCDF
#cmakedefine HAVE_GEOGRAPHY
#cmakedefine HAVE_MEMFS
#ifdef HAVE_MEMFS

View File

@ -8,5 +8,10 @@
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
. ./include.ctest.sh
set -u
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
${examples_dir}/c_grib_get_data > /dev/null

View File

@ -8,8 +8,13 @@
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
. ./include.ctest.sh
temp=temp.c_grib_iterator.txt
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# These two do not have any missing data
${examples_dir}/c_grib_iterator ${data_dir}/reduced_gaussian_model_level.grib1 > /dev/null
${examples_dir}/c_grib_iterator ${data_dir}/regular_gaussian_model_level.grib1 > /dev/null

View File

@ -11,6 +11,10 @@
. ./include.ctest.sh
set -u
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
label="grib_nearest_c"
tempTxt=temp.$label.txt
tempRef=temp.$label.ref

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
label="grib_nearest_multiple_c"
temp1=$label.temp1.$$
temp2=$label.temp2.$$

View File

@ -27,6 +27,7 @@ data_dir=@PROJECT_BINARY_DIR@/data
HAVE_PRODUCT_BUFR=@HAVE_PRODUCT_BUFR@
HAVE_PRODUCT_GRIB=@HAVE_PRODUCT_GRIB@
HAVE_MEMFS=@HAVE_MEMFS@
HAVE_GEOGRAPHY=@HAVE_GEOGRAPHY@
# use definitions from binary dir to test if installation will be correct
def_dir="@CMAKE_BINARY_DIR@/@ECCODES_DEFINITION_SUFF@"

View File

@ -9,4 +9,8 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
${examples_dir}/eccodes_f_grib_get_data > /dev/null

View File

@ -9,4 +9,8 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
${examples_dir}/eccodes_f_grib_get_data_real4 > /dev/null

View File

@ -9,4 +9,8 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
${examples_dir}/eccodes_f_grib_nearest > /dev/null

View File

@ -9,4 +9,8 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
${examples_dir}/eccodes_f_grib_nearest_four_single

View File

@ -9,4 +9,8 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
${examples_dir}/eccodes_f_grib_nearest_single

View File

@ -26,6 +26,7 @@ data_dir=@PROJECT_BINARY_DIR@/data
HAVE_PRODUCT_BUFR=@HAVE_PRODUCT_BUFR@
HAVE_PRODUCT_GRIB=@HAVE_PRODUCT_GRIB@
HAVE_MEMFS=@HAVE_MEMFS@
HAVE_GEOGRAPHY=@HAVE_GEOGRAPHY@
# use definitions from binary dir to test if installation will be correct
def_dir="@CMAKE_BINARY_DIR@/@ECCODES_DEFINITION_SUFF@"

View File

@ -26,6 +26,7 @@ void grib_accessor_class_iterator_t::dump(grib_accessor* a, grib_dumper* dumper)
grib_dump_label(dumper, a, NULL);
}
#if defined(HAVE_GEOGRAPHY)
grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error)
{
grib_handle* h = (grib_handle*)ch;
@ -46,3 +47,13 @@ grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int
return iter;
}
#else
grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error)
{
*error = GRIB_FUNCTIONALITY_NOT_ENABLED;
grib_context_log(ch->context, GRIB_LOG_ERROR,
"Geoiterator support not enabled. Please rebuild with -DENABLE_GEOGRAPHY=ON");
return NULL;
}
#endif

View File

@ -87,12 +87,13 @@ EOF
${tools_dir}/grib_filter -o $temp1 $tempRules $grib1
${tools_dir}/grib_filter -o $temp2 $tempRules $grib2
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data -m missing $temp1 > $tempData1
${tools_dir}/grib_get_data -m missing $temp2 > $tempData2
diff $tempData1 $tempData2
rm -f $tempData1 $tempData2
fi
# ECC-1233: Allow printing of 'byte' keys e.g., bitmap, section paddings
# -----------------------------------------------------------------------

View File

@ -17,6 +17,9 @@ tempGribB=temp.$label.B.grib
tempText=temp.$label.txt
tempRef=temp.$label.ref
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
editions="1 2"
gridTypes="regular_ll rotated_ll"

View File

@ -12,6 +12,10 @@
label="grib_dump_debug_test"
temp=temp.$label.txt
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
if [ $HAVE_MEMFS -eq 1 ]; then
unset ECCODES_DEFINITION_PATH
unset ECCODES_SAMPLES_PATH

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# ---------------------------------------------------------
# This is the test for the JIRA issue ECC-1000
# Nearest neighbour using grib_get/grib_ls on severa files

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# ---------------------------------------------------------
# This is the test for the JIRA issue ECC-1001
# grib_ls -j -l command (JSON for nearest)

View File

@ -16,6 +16,10 @@ tempGrib=temp.$label.grib
tempOut=temp.$label.txt
sample_grib1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
cat > $tempFilt <<EOF
set Ni = 16;
set Nj = 21;

View File

@ -10,6 +10,9 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# ECC-1364: GRIB: Geoiterator for Lambert Conformal in the southern hemisphere

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# ---------------------------------------------------------
# This is the test for the JIRA issue ECC-1397
# grib_ls -j -l command (JSON for nearest)

View File

@ -12,6 +12,10 @@
label="grib_ecc-1406_test"
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
tempGrib=temp.$label.grib
tempFilt=temp.${label}.filt
tempOut=temp.${label}.txt

View File

@ -12,6 +12,10 @@
label="grib_ecc-1671_test"
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
tempGrib=temp.$label.grib
tempFilt=temp.${label}.filt
tempOut=temp.${label}.txt

View File

@ -12,6 +12,10 @@
label="grib_ecc-1708_test"
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
tempGrib=temp.$label.grib
tempFilt=temp.${label}.filt
tempOut=temp.${label}.txt

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
REDIRECT=/dev/null
label="grib_ecc-1792_test"

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# ---------------------------------------------------------
# This is the test for the JIRA issue ECC-600.
# Nearest neighbour for rotated lat/lon grids.

View File

@ -9,7 +9,11 @@
#
. ./include.ctest.sh
set -u
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# ---------------------------------------------------------
# This is the test for the JIRA issue ECC-984
# grib_get_data: missing jDirectionIncrement produces huge values

View File

@ -12,6 +12,10 @@
label="grib_geo_iter_test"
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
infiles="
$ECCODES_SAMPLES_PATH/gg_sfc_grib2.tmpl
$ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib1.tmpl

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# Define a common label for all the tmp files
label="grib_healpix_test"
tempFilt="temp.${label}.filt"

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
label="grib_grid_lamb_az_eq_area_test"
input=${data_dir}/regular_gaussian_pressure_level_constant.grib2

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# Define a common label for all the tmp files
label="grib_lambert_conformal_test"
tempFilt="temp.${label}.filt"

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# Define a common label for all the tmp files
label="grib_mercator_test"
tempOut="temp.${label}.out"

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# Define a common label for all the tmp files
label="grib_polar_stereographic_test"
tempFilt="temp.${label}.filt"

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
# Define a common label for all the tmp files
label="grib_space_view_test"
tempFilt="temp.${label}.filt"

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
label="grib_iterator_test"
tempText=temp.$label.txt
tempGrib=temp.$label.grib

View File

@ -60,11 +60,12 @@ do_tests()
rm -f $outfile2
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
# GRIB-564 nearest 4 neighbours with JPEG packing
res=`${tools_dir}/grib_get -l 0,50 $outfile1`
[ "$res" = "2.47244 2.47244 2.5115 2.51931 " ]
rm -f $outfile1
fi
# ECC-317: Constant JPEG field numberOfValues
# Create a JPEG encoded GRIB message to have all constant values and one more value

View File

@ -54,8 +54,10 @@ set -e
${tools_dir}/grib_ls -P count $infile > $tempLog
${tools_dir}/grib_ls -p count,step $infile >> $tempLog
${tools_dir}/grib_ls $infile >> $tempLog
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_ls -l 0,0,1 $infile >> $tempLog
${tools_dir}/grib_get -l 0,0,1 $infile >> $tempLog
fi
${tools_dir}/grib_get -p count,step $infile >> $tempLog
${tools_dir}/grib_get -P count $infile >> $tempLog
@ -90,7 +92,7 @@ regular_gaussian_surface.grib2
regular_latlon_surface.grib1
regular_latlon_surface.grib2
"
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
for file in $files; do
[ -f "$file" ]
echo $file >> $tempLog
@ -99,6 +101,7 @@ done
diff $tempLog ls.log
rm -f $tempLog
fi
echo "Test for bug GRIB-56..."
# ------------------------------
@ -123,6 +126,7 @@ type=`${tools_dir}/grib_get -wcount=1 -p typeOfLevel test_uuid.grib2`
[ "$type" = "generalVertical" ]
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
echo "GRIB-213 nearest with land-sea mask..."
# ----------------------------------------------------------
${tools_dir}/grib_ls -l 85,13,1,reduced_gaussian_lsm.grib1 reduced_gaussian_surface.grib1 >$tempText
@ -133,6 +137,7 @@ grep -q 'Point chosen #2 index=749 .* distance=204\.' $tempText
${tools_dir}/grib_get -F%.2f -l 85,13,1,reduced_gaussian_lsm.grib1 reduced_gaussian_surface.grib1 >$tempText
grep -q '252.88' $tempText
fi
echo "ECC-278: grib_ls -n namespace..."
# ----------------------------------------------------------
@ -247,6 +252,7 @@ file=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
grib_check_key_equals $file 'expver:d' 1
grib_check_key_equals $file 'expver:s' '0001'
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
# JSON and lat/lon
${tools_dir}/grib_ls -j -l0,0 -p referenceValue:d $data_dir/sample.grib2
${tools_dir}/grib_ls -j -l0,0 -p referenceValue:i $data_dir/sample.grib2
@ -254,11 +260,13 @@ ${tools_dir}/grib_ls -j -l0,0 -p bitmap $data_dir/simple_bitmap.grib > $tempText
grep -q "invalid_type" $tempText
${tools_dir}/grib_ls -j -l0,0 -p nosuchkey $data_dir/sample.grib2 > $tempText 2>&1
grep -q "nosuchkey.* null" $tempText
fi
# -M and -g options
${tools_dir}/grib_ls -M -g $data_dir/gts.grib
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get -l0,0,4 $data_dir/sample.grib2
set +e
@ -275,14 +283,13 @@ set -e
[ $status -ne 0 ]
grep -q "Wrong latitude value" $tempText
set +e
${tools_dir}/grib_ls -l0,0,1,nonexistingmask $data_dir/sample.grib2 > $tempText 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "unable to open mask file" $tempText
fi
# Clean up
rm -f $temp1 $temp2 $tempText $tempLog

View File

@ -10,6 +10,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
label="grib_nearest_test"
temp=temp.$label.txt
tempGrib=temp.$label.grib

View File

@ -25,9 +25,8 @@ grib_check_key_equals $input "global,isOctahedral" "1 1"
# Check numberOfDataPoints
grib_check_key_equals $input "numberOfDataPoints,numberOfCodedValues" "6599680 6599680"
# Only do lengthy iterator test if extra tests are enabled
if [ $HAVE_EXTRA_TESTS -eq 1 ]; then
if [ $HAVE_EXTRA_TESTS -eq 1 -a $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data $input > $temp
numlines=`wc -l $temp | awk '{print $1}'`
[ "$numlines" = "6599681" ] # 1 + numberOfDataPoints

View File

@ -57,6 +57,7 @@ grep -q "Unable to set double array 'codedValues'" $tempErr
# Nearest neighbour
# ----------------------
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
infile=${data_dir}/reduced_gaussian_model_level.grib2
${tools_dir}/grib_set -r -s packingType=grid_png $infile $temp
${tools_dir}/grib_get -F%.6g -l 48.835,327.600,1 $temp > $temp1
@ -64,6 +65,7 @@ grep -q "224.455" $temp1
${tools_dir}/grib_ls -F%.6g -l 48.835,327.600 $temp > $temp1
grep -q "Grid Point chosen #4 index=936 " $temp1
fi
# jPointsAreConsecutive
infile=${data_dir}/reduced_gaussian_model_level.grib2

View File

@ -39,7 +39,11 @@ $EXEC ${test_dir}/grib_run_length_packing $tempGrib
unset ECCODES_DEBUG
${tools_dir}/grib_dump -O $tempGrib
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data -mXXX $tempGrib
fi
grib_check_key_equals $tempGrib packingType grid_run_length
stats=`${tools_dir}/grib_get -M -F%.1f -p min,max,avg $tempGrib`

View File

@ -94,6 +94,7 @@ grib_check_key_equals $sec_ord_bmp accuracy 4
nums=`${tools_dir}/grib_get -p numberOfDataPoints,numberOfCodedValues,numberOfMissing $sec_ord_bmp`
[ "$nums" = "5969 4 5965" ]
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
res=`${tools_dir}/grib_get -l 33,88.5 $sec_ord_bmp`
[ "$res" = "9999 5.51552 9999 9999 " ]
@ -109,6 +110,7 @@ res=`${tools_dir}/grib_get -l 28.5,90 $sec_ord_bmp`
# GRIB-203 nearest on M-F second order boustrophedonic
res=`${tools_dir}/grib_get -w count=1 -l 0,0,1 lfpw.grib1`
[ "$res" = "20563.4 " ]
fi
# Unpack/pack test for second order grib1 data
# --------------------------------------------
@ -196,10 +198,11 @@ set -e
[ $status -ne 0 ]
grep -q "Not implemented" $tempText
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data $temp1 > $REDIRECT
${tools_dir}/grib_ls -l46,1 $temp1 > $REDIRECT
${tools_dir}/grib_ls -j -l46,1,1 $temp1 > $REDIRECT
fi
# Encoding
input=second_ord_rbr.grib1

View File

@ -9,6 +9,10 @@
. ./include.ctest.sh
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
exit 0
fi
if [ $ECCODES_ON_WINDOWS -eq 1 ]; then
# m2-bash messes with the system path.
# %CONDA_PREFIX%\Library\usr\bin is converted to /usr/bin.

View File

@ -27,8 +27,10 @@ $EXEC $grib_util_set_spec -e 2 -r $infile $outfile > /dev/null
res=`${tools_dir}/grib_get -p edition,section2Used,Ni,Nj,numberOfValues,bitsPerValue $outfile`
[ "$res" = "2 0 17 14 238 24" ]
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
# Check output file geometry
${tools_dir}/grib_get_data $outfile > /dev/null
fi
# Remove the local definition from input
${tools_dir}/grib_set -s deleteLocalDefinition=1 $infile $tempOut
@ -110,11 +112,13 @@ grib_check_key_equals $outfile packingType grid_second_order
stats_new=`${tools_dir}/grib_get -F%.2f -p min,max $outfile`
[ "$stats_new" = "4.84 246.90" ]
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data $outfile > /dev/null
CHECK_TOOL="${tools_dir}/grib_check_gaussian_grid"
if [ -x $CHECK_TOOL ]; then
$CHECK_TOOL $outfile
fi
fi
### Constant field N=32
# ---------------------------
@ -123,8 +127,9 @@ rm -f $outfile
$EXEC $grib_util_set_spec $infile $outfile
grib_check_key_equals $outfile "packingType,const" "grid_simple 0"
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data $outfile > /dev/null
fi
# CCSDS input
# ---------------------------

View File

@ -65,6 +65,7 @@ HAVE_LIBJASPER=@HAVE_LIBJASPER@
HAVE_LIBOPENJPEG=@HAVE_LIBOPENJPEG@
HAVE_PNG=@HAVE_PNG@
HAVE_AEC=@HAVE_AEC@
HAVE_GEOGRAPHY=@HAVE_GEOGRAPHY@
HAVE_EXTRA_TESTS=@HAVE_EXTRA_TESTS@
HAVE_MEMFS=@HAVE_MEMFS@
ECCODES_ON_WINDOWS=@ECCODES_ON_WINDOWS@