diff --git a/crpptbx/gdat.m b/crpptbx/gdat.m index 65e2483da2366bd7753d847350f882ff19abf774..52ff9dfac3a9ae48688942f73b7a1e1c21abfecb 100644 --- a/crpptbx/gdat.m +++ b/crpptbx/gdat.m @@ -115,10 +115,17 @@ if nargin>=2 % need at least 2 inputs to have 'machine','aug' as arguments (to a end end -% add paths to each machine which are in subdirectory of gdat and working -% add only given machine directory using machine_eff... -gdat_path = mfilename('fullpath'); -eval(['addpath ' gdat_path(1:end-4) upper(machine_eff)]); +% Avoid running addpath over and over, this can take some time when there +% are many folders in the path +persistent last_machine + +if isempty(last_machine) || ~strcmpi(last_machine,machine_eff) + % add paths to each machine which are in subdirectory of gdat and working + % add only given machine directory using machine_eff... + gdat_path = mfilename('fullpath'); + addpath([gdat_path(1:end-4) upper(machine_eff)]); + last_machine = machine_eff; +end % copy gdat present call: gdat_call = []; @@ -156,21 +163,22 @@ gdat_call = [subcall ' % nargout = ' num2str(nargout)]; % copy subcall here so is last subnode try if nargin==0 - eval(['[gdat_data,gdat_params,error_status,varargout] = gdat_' lower(machine_eff) ';']); + args = {}; elseif nargin==1 - eval(['[gdat_data,gdat_params,error_status,varargout] = gdat_' lower(machine_eff) '(shot);']); + args = {shot}; elseif nargin==2 - eval(['[gdat_data,gdat_params,error_status,varargout] = gdat_' lower(machine_eff) '(shot,data_request);']); + args = {shot,data_request}; else - eval(['[gdat_data,gdat_params,error_status,varargout] = gdat_' lower(machine_eff) '(shot,data_request,varargin_eff{:});']); + args = [{shot,data_request},varargin_eff]; end + [gdat_data,gdat_params,error_status,varargout] = feval(['gdat_' lower(machine_eff)],args{:}); catch ME_gdat warning(['problems calling gdat_' lower(machine_eff)]); - if ~exist('gdat_data'); gdat_data.data = []; end + if ~exist('gdat_data','var'); gdat_data.data = []; end if ~isfield(gdat_data,'dim'); gdat_data.dim=[]; end - if ~exist('gdat_params'); gdat_params.plot = []; end - if ~exist('error_status'); error_status = 998; end - if exist('ME_gdat') + if ~exist('gdat_params','var'); gdat_params.plot = []; end + if ~exist('error_status','var'); error_status = 998; end + if exist('ME_gdat','var') getReport(ME_gdat) end return @@ -186,7 +194,7 @@ if gdat_data.gdat_params.doplot hhh = []; end if nargout >=3 - if length(varargout)==0 || isempty(varargout{1}) + if isempty(varargout) || isempty(varargout{1}) varargout{1} = hhh; else varargout{end+1} = hhh; @@ -194,6 +202,6 @@ if gdat_data.gdat_params.doplot end end -if exist('ME_gdat_plot') +if exist('ME_gdat_plot','var') getReport(ME_gdat_plot) end diff --git a/crpptbx/get_data_request_names_from_gdat_xxx.m b/crpptbx/get_data_request_names_from_gdat_xxx.m index 427ac9bc4e2c1aad594e4a5410c798e01b67400d..ad3fe9678de5b382579dabb1abfe354991e2888b 100644 --- a/crpptbx/get_data_request_names_from_gdat_xxx.m +++ b/crpptbx/get_data_request_names_from_gdat_xxx.m @@ -17,6 +17,16 @@ if isempty(ij) 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 + +if ~isempty(last_machine) && strcmpi(last_machine,machine_in) + data_request_names = last_answer; + return; +end + fid=fopen([machine_in '_requests_mapping.m'],'r'); nextline=fgetl(fid); keywds = []; @@ -40,3 +50,6 @@ end fclose(fid); data_request_names.all = []; +last_machine = machine_in; +last_answer = data_request_names; +