mirror of https://github.com/ecmwf/eccodes.git
eckit::geo: exception handling
This commit is contained in:
parent
87d8023f01
commit
26be54162d
|
@ -45,13 +45,14 @@ 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<eckit::geo::PointLonLat>(p);
|
||||
|
||||
|
@ -62,6 +63,11 @@ int GeoIterator::next(double* lat, double* lon, double* val) const
|
|||
}
|
||||
|
||||
++iter_;
|
||||
}
|
||||
catch(std::exception& e) {
|
||||
grib_context_log(h_->context, GRIB_LOG_FATAL, "GeoIterator::next: Exception thrown (%s)", e.what());
|
||||
return 0;
|
||||
}
|
||||
return 1; // (true)
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue