From 692f4ffe1fb204fd58fa9e9b6c72d46dbb1b609d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Wed, 19 Jun 2019 12:47:31 +0300 Subject: [PATCH] Don't be quiet when loading a NAN-containing t-matrix Former-commit-id: 71d3c1573b073e3edbd7693ca5848633be279998 --- qpms/qpms_types.h | 4 +++- qpms/tmatrices.c | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/qpms/qpms_types.h b/qpms/qpms_types.h index 4c1585f..f15d71c 100644 --- a/qpms/qpms_types.h +++ b/qpms/qpms_types.h @@ -79,7 +79,9 @@ typedef unsigned long long qpms_uvswfi_t; typedef enum { QPMS_SUCCESS = 0, ///< Success. QPMS_ERROR = 1, ///< Unspecified error. - QPMS_ENOMEM = 8 ///< Out of memory. + QPMS_ENOMEM = 8, ///< Out of memory. + QPMS_NAN_ENCOUNTERED = 1024 ///< NaN value encountered in data processing. + } qpms_errno_t; diff --git a/qpms/tmatrices.c b/qpms/tmatrices.c index 9ee21f1..baf6ae4 100644 --- a/qpms/tmatrices.c +++ b/qpms/tmatrices.c @@ -454,6 +454,14 @@ qpms_errno_t qpms_load_scuff_tmatrix( "Could not open T-matrix file %s", path); qpms_errno_t retval = qpms_read_scuff_tmatrix(f, bs, n, freqs, freqs_su, tmatrices_array, tmdata); + + for (size_t i = 0; i < *n * bs->n * bs->n; ++i) + if(isnan(creal((*tmdata)[i])) || isnan(cimag((*tmdata)[i]))) { + QPMS_WARN("Encountered NAN in a loaded T-matrix"); + retval |= QPMS_NAN_ENCOUNTERED; + break; + } + if(fclose(f)) qpms_pr_error_at_line(__FILE__, __LINE__, __func__, "Could not close the T-matrix file %s (well, that's weird, " "since it's read only).", path);