ECC-1784: Add support for N=1 nested

This commit is contained in:
shahramn 2024-03-12 11:59:49 +00:00
parent f46e49b185
commit 1bbca16e3f
2 changed files with 18 additions and 20 deletions

View File

@ -265,8 +265,8 @@ static int iterate_healpix(grib_iterator_healpix* self, long N)
p -= 8 * Nside; p -= 8 * Nside;
} }
int i = (r + p) >> 1; int i = std::max(0, (r + p)) >> 1;
int j = (r - p) >> 1; int j = std::max(0, (r - p)) >> 1;
Assert(f < 12 && i < Nside && j < Nside); Assert(f < 12 && i < Nside && j < Nside);
return CodecFijNest::fij_to_nest(f, i, j, k); return CodecFijNest::fij_to_nest(f, i, j, k);
@ -362,10 +362,10 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args)
grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Only orderingConvention=(ring|nested) are supported", ITER); grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Only orderingConvention=(ring|nested) are supported", ITER);
return GRIB_GEOCALCULUS_PROBLEM; return GRIB_GEOCALCULUS_PROBLEM;
} }
if (self->nested && N == 1) { // if (self->nested && N == 1) {
grib_context_log(h->context, GRIB_LOG_ERROR, "%s: For orderingConvention=nested, N must be greater than 1", ITER); // grib_context_log(h->context, GRIB_LOG_ERROR, "%s: For orderingConvention=nested, N must be greater than 1", ITER);
return GRIB_GEOCALCULUS_PROBLEM; // return GRIB_GEOCALCULUS_PROBLEM;
} // }
if (grib_is_earth_oblate(h)) { if (grib_is_earth_oblate(h)) {
grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Only spherical earth is supported", ITER); grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Only spherical earth is supported", ITER);

View File

@ -19,7 +19,8 @@ input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
latest=`${tools_dir}/grib_get -p tablesVersionLatest $input` latest=`${tools_dir}/grib_get -p tablesVersionLatest $input`
# Create a filter # Check basic keys and grid template
# -----------------------------------
cat > $tempFilt <<EOF cat > $tempFilt <<EOF
set tablesVersion = $latest; set tablesVersion = $latest;
set gridType = "healpix"; set gridType = "healpix";
@ -45,8 +46,8 @@ ${tools_dir}/grib_dump -O -p section_3 $tempGrib
${tools_dir}/grib_ls -jn geography $tempGrib > $tempLog ${tools_dir}/grib_ls -jn geography $tempGrib > $tempLog
grep -q "orderingConvention.*ring" $tempLog grep -q "orderingConvention.*ring" $tempLog
# Geoiterator # Geoiterator ring-ordering
# ------------- # --------------------------
rm -f $tempGrib rm -f $tempGrib
cat > $tempFilt <<EOF cat > $tempFilt <<EOF
set tablesVersion = $latest; set tablesVersion = $latest;
@ -73,8 +74,8 @@ EOF
${tools_dir}/grib_filter $tempFilt $tempGrib ${tools_dir}/grib_filter $tempFilt $tempGrib
# Nested ordering # Geoiterator Nested ordering
# --------------- # ---------------------------
rm -f $tempGrib rm -f $tempGrib
cat > $tempFilt <<EOF cat > $tempFilt <<EOF
set tablesVersion = $latest; set tablesVersion = $latest;
@ -105,16 +106,13 @@ set -e
grep -q "Nside must be a power of 2" $tempLog grep -q "Nside must be a power of 2" $tempLog
# Nested. Bad N # Nested N=1
${tools_dir}/grib_set -s gridType=healpix,Nside=1,orderingConvention=nested $input $tempGrib input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
set +e ${tools_dir}/grib_set -s gridType=healpix,Nside=1,orderingConvention=nested,numberOfDataPoints=12,numberOfValues=12 $input $tempGrib
${tools_dir}/grib_get_data $tempGrib > $tempLog 2>&1 ${tools_dir}/grib_get_data $tempGrib > $tempLog
status=$?
set -e
[ $status -ne 0 ]
cat $tempLog
grep -q "N must be greater than 1" $tempLog
# Invalid cases
# ------------------
# Bad ordering # Bad ordering
${tools_dir}/grib_set -s gridType=healpix,Nside=1,ordering=6 $input $tempGrib ${tools_dir}/grib_set -s gridType=healpix,Nside=1,ordering=6 $input $tempGrib
set +e set +e