From 57a106f26248d0f93f67ee247a620a9a94e0a114 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Fri, 31 Jan 2020 13:26:26 +0100
Subject: [PATCH] fix getting empty ids at ITER, either tcv or imas machines

---
 matlab/IMAS/gdat_imas.m |  3 ++-
 matlab/TCV/gdat_tcv.m   | 20 +++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/matlab/IMAS/gdat_imas.m b/matlab/IMAS/gdat_imas.m
index 0e2cf4d7..49722c68 100644
--- a/matlab/IMAS/gdat_imas.m
+++ b/matlab/IMAS/gdat_imas.m
@@ -438,7 +438,7 @@ elseif strcmp(mapping_for_imas.method,'switchcase')
     for i=1:length(ids_top_names)
       ids_top_name = ids_top_names{i};
       if ids_gen_ok
-	ids_empty = ids_gen(ids_top_name); % generate ids from gateway function ids_gen
+	ids_empty = ids_gen(ids_top_name); % generate ids from ids_gen
       else
 	% load empty ids structure from template file
 	fname = sprintf('ids_empty_%s',ids_top_name);
@@ -469,6 +469,7 @@ elseif strcmp(mapping_for_imas.method,'switchcase')
 	  gdat_data.(ids_top_name) = ids_top;
 	else
 	  gdat_data.(ids_top_name) = ids_empty;
+	  return
 	end
       catch ME_imas_ids_get
 	disp(['there is a problem with: imas_get_ids_' ids_top_name ...
diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m
index d716210c..796f3c0e 100644
--- a/matlab/TCV/gdat_tcv.m
+++ b/matlab/TCV/gdat_tcv.m
@@ -140,7 +140,11 @@ if nargin>=1
   if isempty(shot)
     % means mdsopen(shot) already performed or not shot asked for
     try
-      shot_mds = mdsipmex(2,'$SHOT');
+      if ~mdsremotelist
+	shot_mds = shot;
+      else
+	shot_mds = mdsipmex(2,'$SHOT');
+      end
     catch
       shot_mds = shot;
     end
@@ -150,14 +154,20 @@ if nargin>=1
     if ischar(shot) || isempty(shot)
       if gdat_params.nverbose>=1
         if isstruct(data_request) && isfield(data_request,'data_request')
-          warning(['shot cannot be opened with ' data_request.data_request]);
-        elseif ischar(data_request)
-          warning(['shot cannot be opened with ' data_request]);
+	  if ~strcmp(data_request.data_request,'ids')
+	    warning(['shot cannot be opened with ' data_request.data_request]);
+	    return
+	  end
+        elseif ischar(data_request) 
+	  if ~strcmp(data_request,'ids')
+	    warning(['shot cannot be opened with ' data_request]);
+	    return
+	  end
         else
           warning(['shot cannot be opened']);
+	  return
         end
       end
-      if ~strcmp(data_request,'ids'); return; end % empty shot return empty ids so valid command
     end
   elseif isnumeric(shot)
     gdat_data.shot = shot;
-- 
GitLab