From 808539ae01791c927fffa3329a25486678eaf8e8 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Tue, 23 Jun 2015 20:41:40 +0000
Subject: [PATCH] add check if thomson:times is not empty

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@4839 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/TCV/loadTCVdata.m | 94 +++++++++++++++++++++++++++++++++++----
 1 file changed, 85 insertions(+), 9 deletions(-)

diff --git a/crpptbx/TCV/loadTCVdata.m b/crpptbx/TCV/loadTCVdata.m
index 1dbaf9dd..4af7b51a 100644
--- a/crpptbx/TCV/loadTCVdata.m
+++ b/crpptbx/TCV/loadTCVdata.m
@@ -558,6 +558,14 @@ switch TCVkeywrdcase{index}
           ix=1; 
           trace.t=tracetdi.dim{2};
           disp(['assumes time array is 1D array, so x from dim{' num2str(ix) '}'])
+        elseif tracetdi.dim{1}(end)<1.1 && tracetdi.dim{2}(end)>1.1
+          ix=1; 
+          trace.t=tracetdi.dim{2};
+          disp(['assumes x array is 1D array with max <1.1'])          
+        elseif tracetdi.dim{1}(end)>1.1 && tracetdi.dim{2}(end)<1.1
+          ix=2; 
+          trace.t=tracetdi.dim{1};
+          disp(['assumes x array is 1D array with max <1.1'])          
         elseif length(size(tracetdi.dim{1}))==2 && min(size(tracetdi.dim{1}))==1 && length(size(tracetdi.dim{2}))==2 && min(size(tracetdi.dim{2}))==1
           % if both are 1D arrays, assumes time array with values having most number of digits
           ab1=num2str(tracetdi.dim{1}-fix(tracetdi.dim{1}));
@@ -626,7 +634,19 @@ switch TCVkeywrdcase{index}
     trace.std=tracestd.data';
     trace.name=[num2str(shot) ';' nodenameeff];
     % add correct dimensions
-    time=mdsdata('\results::thomson:times');
+    try
+      time=mdsdata('\results::thomson:times');
+    catch
+      warning('Problems with \results::thomson:times')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
+    if isempty(time) || ischar(time)
+      thomsontimes=time
+      warning('!!!!!!!!!!!!!!!!!!!!!!!!!\results::thomson:times  is empty? Check')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
     z=mdsdata('\diagz::thomson_set_up:vertical_pos');
     trace.dim=[{z};{time}];
     trace.dimunits=[{'Z [m]'} ; {'time [s]'}];
@@ -656,7 +676,19 @@ switch TCVkeywrdcase{index}
     trace.std=tracestd.data';
     trace.name=[num2str(shot) ';' nodenameeff];
     % add correct dimensions
-    time=mdsdata('\results::thomson:times');
+    try
+      time=mdsdata('\results::thomson:times');
+    catch
+      warning('Problems with \results::thomson:times')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
+    if isempty(time) || ischar(time)
+      thomsontimes=time
+      warning('!!!!!!!!!!!!!!!!!!!!!!!!!\results::thomson:times  is empty? Check')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
     z=mdsdata('\diagz::thomson_set_up.edge:vertical_pos');
     trace.dim=[{z};{time}];
     trace.dimunits=[{'Z [m]'} ; {'time [s]'}];
@@ -672,7 +704,19 @@ switch TCVkeywrdcase{index}
   case {'nerho','terho'}
     % ne or Te from Thomson data on rho=sqrt(psi_normalised) mesh: (rho,t)
     mdsopen(shot);
-    time=mdsdata('\results::thomson:times');
+    try
+      time=mdsdata('\results::thomson:times');
+    catch
+      warning('Problems with \results::thomson:times')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
+    if isempty(time) || ischar(time)
+      thomsontimes=time
+      warning('!!!!!!!!!!!!!!!!!!!!!!!!!\results::thomson:times  is empty? Check')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
     if strcmp(TCVkeywrdcase{index},'nerho')
       nodenameeff='\results::thomson:ne';
       tracetdi=tdi(nodenameeff);
@@ -721,8 +765,12 @@ switch TCVkeywrdcase{index}
     % construct rho mesh
     psi_max=tdi(['\results::thomson:psi_max' endstr]);
     psiscatvol=tdi(['\results::thomson:psiscatvol' endstr]);
-    for ir=1:length(psiscatvol.dim{2})
-      rho(ir,:)= sqrt(1.-psiscatvol.data(:,ir)./psi_max.data(:))';
+    if ~isempty(psiscatvol.data) && ~ischar(psiscatvol.data) && ~isempty(psi_max.data) && ~ischar(psi_max.data)
+      for ir=1:length(psiscatvol.dim{2})
+        rho(ir,:)= sqrt(1.-psiscatvol.data(:,ir)./psi_max.data(:))';
+      end
+    else
+      rho=NaN;
     end
     trace.dim=[{rho};{time}];
     trace.dimunits=[{'sqrt(psi)'} ; {'time [s]'}];
@@ -738,7 +786,19 @@ switch TCVkeywrdcase{index}
   case {'nerho_edge','terho_edge'}
     % ne or Te from Thomson.Edge data on rho=sqrt(psi_normalised) mesh: (rho,t)
     mdsopen(shot);
-    time=mdsdata('\results::thomson:times');
+    try
+      time=mdsdata('\results::thomson:times');
+    catch
+      warning('Problems with \results::thomson:times')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
+    if isempty(time) || ischar(time)
+      thomsontimes=time
+      warning('!!!!!!!!!!!!!!!!!!!!!!!!!\results::thomson:times  is empty? Check')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
     if strcmp(TCVkeywrdcase{index},'nerho_edge')
       nodenameeff='\results::thomson.edge:ne';
       tracetdi=tdi(nodenameeff);
@@ -815,7 +875,19 @@ switch TCVkeywrdcase{index}
       zshift=0.;
     end
     mdsopen(shot);
-    time=mdsdata('\results::thomson:times');
+    try
+      time=mdsdata('\results::thomson:times');
+    catch
+      warning('Problems with \results::thomson:times')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
+    if isempty(time) || ischar(time)
+      thomsontimes=time
+      warning('!!!!!!!!!!!!!!!!!!!!!!!!!\results::thomson:times  is empty? Check')
+      disp(['!!!!!!!!!!!!!!!!!!!!!!!!! cannot continue with ' TCVkeywrdcase{index}])
+      return
+    end
     if strcmp(TCVkeywrdcase{index},'nerhozshift')
       nodenameeff='\results::thomson:ne';
       tracetdi=tdi(nodenameeff);
@@ -887,8 +959,12 @@ switch TCVkeywrdcase{index}
         psiscatvol.data(it,:)=psiscatvol0;
       end
     end
-    for ir=1:length(psiscatvol.dim{2})
-      rho(ir,:)= sqrt(1.-psiscatvol.data(:,ir)./psi_max.data(:))';
+    if ~isempty(psiscatvol.data) && ~ischar(psiscatvol.data) && ~isempty(psi_max.data) && ~ischar(psi_max.data)
+      for ir=1:length(psiscatvol.dim{2})
+        rho(ir,:)= sqrt(1.-psiscatvol.data(:,ir)./psi_max.data(:))';
+      end
+    else
+      rho=NaN;
     end
     trace.dim=[{rho};{time}];
     trace.dimunits=[{'sqrt(psi)'} ; {'time [s]'}];
-- 
GitLab