From 1bbca16e3fa0f2cf8e001ae6b7ff359628b06178 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 12 Mar 2024 11:59:49 +0000 Subject: [PATCH] ECC-1784: Add support for N=1 nested --- src/grib_iterator_class_healpix.cc | 12 ++++++------ tests/grib_grid_healpix.sh | 26 ++++++++++++-------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/grib_iterator_class_healpix.cc b/src/grib_iterator_class_healpix.cc index 0b5c09da0..7befaf894 100644 --- a/src/grib_iterator_class_healpix.cc +++ b/src/grib_iterator_class_healpix.cc @@ -265,8 +265,8 @@ static int iterate_healpix(grib_iterator_healpix* self, long N) p -= 8 * Nside; } - int i = (r + p) >> 1; - int j = (r - p) >> 1; + int i = std::max(0, (r + p)) >> 1; + int j = std::max(0, (r - p)) >> 1; Assert(f < 12 && i < Nside && j < Nside); 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); return GRIB_GEOCALCULUS_PROBLEM; } - if (self->nested && N == 1) { - grib_context_log(h->context, GRIB_LOG_ERROR, "%s: For orderingConvention=nested, N must be greater than 1", ITER); - return GRIB_GEOCALCULUS_PROBLEM; - } + // if (self->nested && N == 1) { + // grib_context_log(h->context, GRIB_LOG_ERROR, "%s: For orderingConvention=nested, N must be greater than 1", ITER); + // return GRIB_GEOCALCULUS_PROBLEM; + // } if (grib_is_earth_oblate(h)) { grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Only spherical earth is supported", ITER); diff --git a/tests/grib_grid_healpix.sh b/tests/grib_grid_healpix.sh index 1557a84a7..7ff56382c 100755 --- a/tests/grib_grid_healpix.sh +++ b/tests/grib_grid_healpix.sh @@ -19,7 +19,8 @@ input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl latest=`${tools_dir}/grib_get -p tablesVersionLatest $input` -# Create a filter +# Check basic keys and grid template +# ----------------------------------- cat > $tempFilt < $tempLog grep -q "orderingConvention.*ring" $tempLog -# Geoiterator -# ------------- +# Geoiterator ring-ordering +# -------------------------- rm -f $tempGrib cat > $tempFilt < $tempFilt < $tempLog 2>&1 -status=$? -set -e -[ $status -ne 0 ] -cat $tempLog -grep -q "N must be greater than 1" $tempLog +# Nested N=1 +input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl +${tools_dir}/grib_set -s gridType=healpix,Nside=1,orderingConvention=nested,numberOfDataPoints=12,numberOfValues=12 $input $tempGrib +${tools_dir}/grib_get_data $tempGrib > $tempLog +# Invalid cases +# ------------------ # Bad ordering ${tools_dir}/grib_set -s gridType=healpix,Nside=1,ordering=6 $input $tempGrib set +e