diff --git a/src/geo/GeoIterator.cc b/src/geo/GeoIterator.cc index 89e465fa0..e77b8dc4a 100644 --- a/src/geo/GeoIterator.cc +++ b/src/geo/GeoIterator.cc @@ -45,23 +45,29 @@ int GeoIterator::init(grib_handle*, grib_arguments*) NOTIMP; } - +// The C public API for this does not have a way of returning an error, +// So any exception thrown by eckit will is fatal! int GeoIterator::next(double* lat, double* lon, double* val) const { if (iter_ == end_) { return 0; // (false) } + try { + const auto p = *iter_; + const auto& q = std::get(p); - const auto p = *iter_; - const auto& q = std::get(p); + *lat = q.lat; + *lon = q.lon; + if (val != nullptr && data_ != nullptr) { + *val = data_[iter_->index()]; + } - *lat = q.lat; - *lon = q.lon; - if (val != nullptr && data_ != nullptr) { - *val = data_[iter_->index()]; + ++iter_; + } + catch(std::exception& e) { + grib_context_log(h_->context, GRIB_LOG_FATAL, "GeoIterator::next: Exception thrown (%s)", e.what()); + return 0; } - - ++iter_; return 1; // (true) } diff --git a/src/geo/iterator/grib_iterator.cc b/src/geo/iterator/grib_iterator.cc index 711f840c3..329ad4fbf 100644 --- a/src/geo/iterator/grib_iterator.cc +++ b/src/geo/iterator/grib_iterator.cc @@ -110,8 +110,8 @@ grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int grib_iterator* i = (grib_iterator*)grib_context_malloc_clear(ch->context, sizeof(grib_iterator)); #if defined(HAVE_ECKIT_GEO) - static const auto* eckit_geo = codes_getenv("ECCODES_ECKIT_GEO"); - if (eckit_geo != nullptr && strcmp(eckit_geo, "1") == 0) { + const int eckit_geo = ch->context->eckit_geo; // check environment variable + if (eckit_geo) { struct InitMain { InitMain() diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 256f270e8..c1c0b1f24 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -777,6 +777,7 @@ struct grib_context int bufr_multi_element_constant_arrays; int grib_data_quality_checks; int single_precision; + int eckit_geo; FILE* log_stream; grib_trie* classes; grib_trie* lists; diff --git a/src/grib_context.cc b/src/grib_context.cc index 1b9a98d11..2e067038e 100644 --- a/src/grib_context.cc +++ b/src/grib_context.cc @@ -369,6 +369,7 @@ static grib_context default_grib_context = { 0, /* bufr_multi_element_constant_arrays */ 0, /* grib_data_quality_checks */ 0, /* single_precision */ + 0, /* eckit_geo */ 0, /* log_stream */ 0, /* classes */ 0, /* lists */ @@ -406,18 +407,22 @@ grib_context* grib_context_get_default() const char* bufr_multi_element_constant_arrays = NULL; const char* grib_data_quality_checks = NULL; const char* single_precision = NULL; + const char* eckit_geo = NULL; const char* file_pool_max_opened_files = NULL; #ifdef ENABLE_FLOATING_POINT_EXCEPTIONS feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); #endif - write_on_fail = codes_getenv("ECCODES_GRIB_WRITE_ON_FAIL"); bufrdc_mode = getenv("ECCODES_BUFRDC_MODE_ON"); bufr_set_to_missing_if_out_of_range = getenv("ECCODES_BUFR_SET_TO_MISSING_IF_OUT_OF_RANGE"); bufr_multi_element_constant_arrays = getenv("ECCODES_BUFR_MULTI_ELEMENT_CONSTANT_ARRAYS"); grib_data_quality_checks = getenv("ECCODES_GRIB_DATA_QUALITY_CHECKS"); single_precision = getenv("ECCODES_SINGLE_PRECISION"); + file_pool_max_opened_files = getenv("ECCODES_FILE_POOL_MAX_OPENED_FILES"); + eckit_geo = getenv("ECCODES_ECKIT_GEO"); + // The following had an equivalent env. var in grib_api + write_on_fail = codes_getenv("ECCODES_GRIB_WRITE_ON_FAIL"); large_constant_fields = codes_getenv("ECCODES_GRIB_LARGE_CONSTANT_FIELDS"); no_abort = codes_getenv("ECCODES_NO_ABORT"); debug = codes_getenv("ECCODES_DEBUG"); @@ -429,7 +434,6 @@ grib_context* grib_context_get_default() no_spd = codes_getenv("ECCODES_GRIB_NO_SPD"); keep_matrix = codes_getenv("ECCODES_GRIB_KEEP_MATRIX"); show_hour_stepunit = codes_getenv("ECCODES_GRIB_HOURLY_STEPS_WITH_UNITS"); - file_pool_max_opened_files = getenv("ECCODES_FILE_POOL_MAX_OPENED_FILES"); /* On UNIX, when we read from a file we get exactly what is in the file on disk. * But on Windows a file can be opened in binary or text mode. In binary mode the system behaves exactly as in UNIX. @@ -564,6 +568,7 @@ grib_context* grib_context_get_default() default_grib_context.bufr_multi_element_constant_arrays = bufr_multi_element_constant_arrays ? atoi(bufr_multi_element_constant_arrays) : 0; default_grib_context.grib_data_quality_checks = grib_data_quality_checks ? atoi(grib_data_quality_checks) : 0; default_grib_context.single_precision = single_precision ? atoi(single_precision) : 0; + default_grib_context.eckit_geo = eckit_geo ? atoi(eckit_geo) : 0; default_grib_context.file_pool_max_opened_files = file_pool_max_opened_files ? atoi(file_pool_max_opened_files) : DEFAULT_FILE_POOL_MAX_OPENED_FILES; }