2013-03-25 12:04:10 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2013-03-25 12:04:10 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the terms of the Apache Licence Version 2.0
|
|
|
|
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
2013-03-25 14:23:07 +00:00
|
|
|
#
|
2013-03-25 12:04:10 +00:00
|
|
|
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
|
|
|
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
|
|
|
#
|
|
|
|
|
2022-04-03 22:02:48 +00:00
|
|
|
. ./include.ctest.sh
|
2022-03-29 21:58:42 +00:00
|
|
|
|
2022-07-22 16:57:02 +00:00
|
|
|
label="grib_change_scanning_test"
|
2024-05-04 13:33:13 +00:00
|
|
|
tempFilt=temp.$label.filt
|
|
|
|
tempGribA=temp.$label.A.grib
|
|
|
|
tempGribB=temp.$label.B.grib
|
|
|
|
tempText=temp.$label.txt
|
|
|
|
tempRef=temp.$label.ref
|
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
editions="1 2"
|
|
|
|
gridTypes="regular_ll rotated_ll"
|
|
|
|
Ni_list="5 8"
|
|
|
|
Nj_list="7 4"
|
|
|
|
|
|
|
|
file=${data_dir}/regular_latlon_surface.grib1
|
|
|
|
|
|
|
|
for edition in `echo ${editions}`; do
|
|
|
|
for gridType in `echo $gridTypes`; do
|
|
|
|
for Ni in `echo ${Ni_list}`; do
|
|
|
|
for Nj in `echo ${Nj_list}`; do
|
|
|
|
|
|
|
|
#echo $gridType Ni=$Ni Nj=$Nj
|
|
|
|
|
|
|
|
N=`expr $Ni \* $Nj`
|
|
|
|
cat > ${data_dir}/change_scanning_${gridType}.filter <<EOF
|
|
|
|
set edition=$edition;
|
|
|
|
set gridType="$gridType";
|
|
|
|
set Ni=$Ni;
|
|
|
|
set Nj=$Nj;
|
|
|
|
set latitudeFirstInDegrees=20.0;
|
|
|
|
set longitudeFirstInDegrees=20.0;
|
|
|
|
set latitudeLastInDegrees=`expr 20 - $Nj + 1`;
|
|
|
|
set longitudeLastInDegrees=`expr 20 + $Ni - 1`;
|
|
|
|
set DiInDegrees=1.0;
|
|
|
|
set DjInDegrees=1.0;
|
|
|
|
set iScansNegatively=0;
|
|
|
|
set jScansPositively=0;
|
|
|
|
set jPointsAreConsecutive=0;
|
|
|
|
set values = {1
|
|
|
|
EOF
|
|
|
|
list=""
|
|
|
|
i=2
|
|
|
|
while [ $i -le $N ]; do
|
|
|
|
list="$list,$i"
|
|
|
|
i=`expr $i + 1`
|
|
|
|
done
|
|
|
|
|
|
|
|
cat >> ${data_dir}/change_scanning_${gridType}.filter <<EOF
|
|
|
|
$list };
|
|
|
|
write "${data_dir}/scan1.grib";
|
|
|
|
EOF
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_filter ${data_dir}/change_scanning_${gridType}.filter $file
|
|
|
|
#ed=`${tools_dir}/grib_get -p edition ${data_dir}/scan1.grib`
|
2013-03-25 12:04:10 +00:00
|
|
|
#echo edition=$ed
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s swapScanningX=1 ${data_dir}/scan1.grib ${data_dir}/scan.grib
|
|
|
|
${tools_dir}/grib_get_data -F "%g" ${data_dir}/scan.grib > ${data_dir}/scan_x_${gridType}_${Ni}_${Nj}.dump
|
2013-03-25 12:04:10 +00:00
|
|
|
diff ${data_dir}/scan_x_${gridType}_${Ni}_${Nj}.dump ${data_dir}/scan_x_${gridType}_${Ni}_${Nj}_good.dump
|
|
|
|
rm -f ${data_dir}/scan_x_${gridType}_${Ni}_${Nj}.dump
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s swapScanningY=1 ${data_dir}/scan1.grib ${data_dir}/scan.grib
|
|
|
|
${tools_dir}/grib_get_data -F "%g" ${data_dir}/scan.grib > ${data_dir}/scan_y_${gridType}_${Ni}_${Nj}.dump
|
2013-03-25 12:04:10 +00:00
|
|
|
diff ${data_dir}/scan_y_${gridType}_${Ni}_${Nj}.dump ${data_dir}/scan_y_${gridType}_${Ni}_${Nj}_good.dump
|
|
|
|
rm -f ${data_dir}/scan_y_${gridType}_${Ni}_${Nj}.dump
|
2013-11-13 12:49:54 +00:00
|
|
|
rm -f ${data_dir}/change_scanning_${gridType}.filter
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2022-03-29 21:58:42 +00:00
|
|
|
# alternativeRowScanning
|
|
|
|
# -----------------------
|
|
|
|
cat > $tempFilt <<EOF
|
|
|
|
set Nj = 2;
|
|
|
|
set latitudeOfFirstGridPointInDegrees = 60;
|
|
|
|
set latitudeOfLastGridPointInDegrees = 59;
|
|
|
|
set Ni = 3;
|
|
|
|
set longitudeOfFirstGridPointInDegrees = 0;
|
|
|
|
set longitudeOfLastGridPointInDegrees = 2;
|
|
|
|
set DjInDegrees = 1;
|
|
|
|
set DiInDegrees = 1;
|
|
|
|
|
|
|
|
set alternativeRowScanning = 1;
|
|
|
|
set values={ 12, 13, 14, 15, 16, 17 };
|
|
|
|
write;
|
|
|
|
EOF
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2022-03-29 21:58:42 +00:00
|
|
|
${tools_dir}/grib_filter -o $tempGribA $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
${tools_dir}/grib_set -s swapScanningAlternativeRows=1 $tempGribA $tempGribB
|
|
|
|
grib_check_key_equals $tempGribB alternativeRowScanning 0
|
|
|
|
|
|
|
|
${tools_dir}/grib_get_data -F "%.2f" $tempGribB > $tempText
|
|
|
|
cat > $tempRef << EOF
|
|
|
|
Latitude Longitude Value
|
|
|
|
60.000 0.000 12.00
|
|
|
|
60.000 1.000 13.00
|
|
|
|
60.000 2.000 14.00
|
|
|
|
59.000 0.000 17.00
|
|
|
|
59.000 1.000 16.00
|
|
|
|
59.000 2.000 15.00
|
|
|
|
EOF
|
|
|
|
diff $tempRef $tempText
|
|
|
|
|
2022-03-30 11:31:02 +00:00
|
|
|
# It must fail when Ni=missing (reduced grids)
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s swapScanningAlternativeRows=1 $ECCODES_SAMPLES_PATH/reduced_gg_pl_96_grib2.tmpl $tempGribB 2>/dev/null
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
2022-03-29 21:58:42 +00:00
|
|
|
|
2023-08-21 18:30:52 +00:00
|
|
|
# Invalid Ni/Nj
|
|
|
|
${tools_dir}/grib_set -s Ni=9 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $tempGribA
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s swapScanningAlternativeRows=1 $tempGribA $tempGribB
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
2022-12-06 22:02:07 +00:00
|
|
|
# ECC-1492
|
|
|
|
grib_check_key_equals "$ECCODES_SAMPLES_PATH/GRIB1.tmpl" iScansNegatively,iScansPositively '0 1'
|
|
|
|
grib_check_key_equals "$ECCODES_SAMPLES_PATH/GRIB1.tmpl" jScansNegatively,jScansPositively '1 0'
|
|
|
|
|
|
|
|
grib_check_key_equals "$ECCODES_SAMPLES_PATH/GRIB2.tmpl" iScansNegatively,iScansPositively '0 1'
|
|
|
|
grib_check_key_equals "$ECCODES_SAMPLES_PATH/GRIB2.tmpl" jScansNegatively,jScansPositively '1 0'
|
|
|
|
|
2023-06-18 17:39:28 +00:00
|
|
|
# Rare case of pack_string for an integer key
|
|
|
|
${tools_dir}/grib_set -s swapScanningX:s=1 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $tempGribA 2>/dev/null
|
|
|
|
${tools_dir}/grib_set -s swapScanningX:i=1 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $tempGribB 2>/dev/null
|
|
|
|
cmp $tempGribA $tempGribB
|
|
|
|
|
2024-05-04 13:33:13 +00:00
|
|
|
|
|
|
|
# Check constraint keys follow (observe) their expressions
|
|
|
|
# --------------------------------------------------------
|
|
|
|
cat > $tempFilt <<EOF
|
|
|
|
set iScansNegatively = 1; # Change from 0 to 1
|
|
|
|
assert (0 == iScansPositively); # should change too
|
|
|
|
set jScansPositively = 1; # Same for j
|
|
|
|
assert (0 == jScansNegatively);
|
|
|
|
EOF
|
|
|
|
grib_check_key_equals $file 'iScansNegatively,jScansPositively' '0 0'
|
|
|
|
grib_check_key_equals $file 'iScansPositively,jScansNegatively' '1 1'
|
|
|
|
${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
|
|
|
${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
|
|
|
|
|
|
|
|
# ECC-1819: Keys iScansPositively and jScansNegatively should be read-only
|
|
|
|
for s in GRIB1.tmpl GRIB2.tmpl; do
|
|
|
|
for k in iScansPositively jScansNegatively; do
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s $k=0 $ECCODES_SAMPLES_PATH/$s $tempGribA 2>$tempText
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Value is read only" $tempText
|
|
|
|
rm $tempText
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2022-03-29 21:58:42 +00:00
|
|
|
# Clean up
|
|
|
|
rm -f $tempFilt $tempGribA $tempGribB $tempRef $tempText
|
|
|
|
rm -f ${data_dir}/scan1.grib ${data_dir}/scan.grib
|