From 96c8799b0c68040f63501e7c68e2eadd7c39a0aa Mon Sep 17 00:00:00 2001
From: Michele Marin <michele.marin@epfl.ch>
Date: Thu, 13 Feb 2025 18:26:08 +0100
Subject: [PATCH] Handling of situations where all values for a variable are
 nans

---
 matlab/TCV_IMAS/tcv_get_ids_summary.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_summary.m b/matlab/TCV_IMAS/tcv_get_ids_summary.m
index bda11cc2..7c44e778 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_summary.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_summary.m
@@ -252,7 +252,12 @@ for i=1:numel(global_quantities_fieldnames)
         ~isempty(global_quantities.(global_quantities_fieldnames{i}).data)
       % setup mask to get rid of nans
       mask = ~isnan(global_quantities.(global_quantities_fieldnames{i}).data);
-      % interpolate quantity on ids_summary.time
+      % assign a flat 1 to the array if it is all nans
+      if all(mask(:) == 0)
+	fprintf('Warning, %s is filled with NaNs, substituting 1\n', global_quantities_fieldnames{i});
+        global_quantities.(global_quantities_fieldnames{i}).data(:)=1;
+	mask(:)=1;
+      end
       ids_summary.global_quantities.(global_quantities_fieldnames{i}).value = ...
         interpos(21,global_quantities.(global_quantities_fieldnames{i}).t(mask),...
         global_quantities.(global_quantities_fieldnames{i}).data(mask), ...
-- 
GitLab