From d7f9ee7aaea006c7ef0a2dfda7dc8270fd76f2e4 Mon Sep 17 00:00:00 2001
From: Antoine Merle <Antoine.Merle@epfl.ch>
Date: Thu, 22 Jun 2017 11:24:09 +0000
Subject: [PATCH] Keep results from previous machines in
 get_data_request_names_...

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@7608 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 .../get_data_request_names_from_gdat_xxx.m    | 37 +++++++++----------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/crpptbx/get_data_request_names_from_gdat_xxx.m b/crpptbx/get_data_request_names_from_gdat_xxx.m
index 3c35af49..133f1b20 100644
--- a/crpptbx/get_data_request_names_from_gdat_xxx.m
+++ b/crpptbx/get_data_request_names_from_gdat_xxx.m
@@ -8,40 +8,38 @@ function [data_request_names] = get_data_request_names_from_gdat_xxx(machine_in)
 data_request_names = [];
 
 expected_machines = [{'aug'}, {'d3d'}, {'jet'}, {'tcv'}]; % substrutures created for these at this stage (all means all of these)
-for j=1:length(expected_machines)
-  data_request_names.(expected_machines{j}) = [];
-end
-ij=strmatch(lower(machine_in),expected_machines);
-if isempty(ij)
-  disp(['machine ' machine_in ' not expected in get_data_request_names_from_gdat_xxx'])
-  return
+try machine_in = validatestring(machine_in,expected_machines);
+catch ME,
+  disp(ME.message);
+  return;
 end
-machine_in = lower(machine_in);
 
 % Avoid running this function over and over
 % This is another bottleneck in the gdat execution.
-persistent last_machine last_answer
+persistent last_answer
 
-if ~isempty(last_machine) && strcmpi(last_machine,machine_in)
+if ~isempty(last_answer),
   data_request_names = last_answer;
-  return;
+  if  ~isempty(data_request_names.(machine_in)), return;end
+else
+  for j=1:length(expected_machines)
+    data_request_names.(expected_machines{j}) = [];
+  end
 end
 
 fid=fopen([machine_in '_requests_mapping.m'],'r');
 nextline=fgetl(fid);
-keywds = [];
 while isempty(nextline) || ~isnumeric(nextline) || nextline~=-1 %length(nextline)>2 || ~strcmp(nextline,'-1')
   if length(nextline)>7 && strcmp(nextline(1:6),' case ')
     ij=find(nextline==['''']);
     if ~isempty(ij)
       for i=1:2:length(ij)-1
-	keywds_next = nextline(ij(i)+1:ij(i+1)-1);
-	i_backslash = find(keywds_next=='\');
-	i_column = find(keywds_next==':');
-	if isempty(i_backslash) && isempty(i_column)
-	  keywds{end+1} = keywds_next;
-	  data_request_names.(machine_in).(keywds{end}) = keywds{end};
-	end
+        keywds_next = nextline(ij(i)+1:ij(i+1)-1);
+        i_backslash = find(keywds_next=='\', 1);
+        i_column = find(keywds_next==':', 1);
+        if isempty(i_backslash) && isempty(i_column)
+          data_request_names.(machine_in).(keywds_next) = keywds_next;
+        end
       end
     end
   end
@@ -50,6 +48,5 @@ end
 fclose(fid);
 data_request_names.all = [];
 
-last_machine = machine_in;
 last_answer = data_request_names;
 
-- 
GitLab