From 41998a837b350107ff3fe75c7ce6c77b56bb6e21 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Wed, 30 Sep 2015 14:11:18 +0000
Subject: [PATCH] fix cxrs to have all subfields created even if no cxrs
 present, so for example isempty(cxrs.vtor.fit.data) would work always

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5082 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/TCV/gdat_tcv.m | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/crpptbx/TCV/gdat_tcv.m b/crpptbx/TCV/gdat_tcv.m
index d0db6bdd..4fc8fe88 100644
--- a/crpptbx/TCV/gdat_tcv.m
+++ b/crpptbx/TCV/gdat_tcv.m
@@ -285,6 +285,11 @@ if do_mdsopen_mdsclose
   end
 end
 
+% fill again at end to have full case, but here to have present status in case of early return
+gdat_data.gdat_params.help = tcv_help_parameters(fieldnames(gdat_data.gdat_params));
+gdat_data.mapping_for.tcv = mapping_for_tcv;
+gdat_params = gdat_data.gdat_params;
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % 1st treat the simplest method: "tdi" (and tdiliuqe)
 if strcmp(mapping_for_tcv.method(1:3),'tdi')
@@ -605,8 +610,28 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
     cxrs_params.k_plot = cxrs_plot;
     cxrs_profiles = CXRS_get_profiles(shot,[1 2 3],time_interval,cxrs_params);
     inb_times = length(cxrs_profiles.Times);
+    gdat_data.cxrs_params = cxrs_profiles.param;
     if isempty(cxrs_profiles.Times) || ~isfield(cxrs_profiles,'proffit')
       if (gdat_params.nverbose>=1); warning(['problems loading data with CXRS_get_profiles for data_request= ' data_request_eff]); end
+      for i=1:length(sub_nodes)
+        sub_eff_out = sub_nodes_out{i};
+        gdat_data.(sub_eff_out).fit.data = [];
+        gdat_data.(sub_eff_out).fit.rho = [];
+        gdat_data.(sub_eff_out).fit.error_bar = [];
+        gdat_data.(sub_eff_out).raw.data = [];
+        gdat_data.(sub_eff_out).raw.rho = [];
+        gdat_data.(sub_eff_out).raw.error_bar = [];
+        gdat_data.(sub_eff_out).raw.error_bar_rho = [];
+        gdat_data.(sub_eff_out).raw.cxrs_system = [];
+        gdat_data.time_interval = [];
+        gdat_data.(sub_eff_out).units = sub_nodes_units{i};
+        if i==1
+          gdat_data.data = gdat_data.(sub_eff_out).fit.data;
+          gdat_data.x = gdat_data.(sub_eff_out).fit.rho;
+          gdat_data.error_bar = gdat_data.(sub_eff_out).fit.error_bar;
+          gdat_data.units = gdat_data.(sub_eff_out).units;
+        end
+      end
       return
     end
     inb_channels =120; % need to change if gets bigger!!! but easier to prefill with NaNs and use the "use" part
@@ -649,7 +674,6 @@ elseif strcmp(mapping_for_tcv.method,'switchcase')
         gdat_data.units = gdat_data.(sub_eff_out).units;
       end
     end
-    gdat_data.cxrs_params = cxrs_profiles.param;
     gdat_data.t = cxrs_profiles.proffit.time;
     gdat_data.dim = {gdat_data.x; gdat_data.t};
     if isempty(time_interval)
-- 
GitLab