From 2002fe122079c4a51ae2f9374c5b6a05cf913cc6 Mon Sep 17 00:00:00 2001 From: Olivier Sauter <olivier.sauter@epfl.ch> Date: Wed, 15 Jan 2020 18:40:30 +0100 Subject: [PATCH] allow calling several ids source at once --- matlab/IMAS/gdat_imas.m | 95 ++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/matlab/IMAS/gdat_imas.m b/matlab/IMAS/gdat_imas.m index 1547090f..064916de 100644 --- a/matlab/IMAS/gdat_imas.m +++ b/matlab/IMAS/gdat_imas.m @@ -7,7 +7,7 @@ function [gdat_data,gdat_params,error_status,varargout] = gdat_imas(shot,data_re % % If no inputs are provided, return the list of available pre-defined data_request in gdat_data and default parameters gdat_params % -% IMAS means assume access data from IDS database ala IMAS with tokamakname and dataversion and run_number using imas_open_env and ids_get calls +% IMAS means assume access data from IDS database ala IMAS with run_number, database_user, tokamak_name, data_major_version and using imas_open_env and ids_get calls % Should be the same on ITER hpc and gateway, to be checked % % At first only "ids" request implemented, but keywords like ip etc should relate to specific IDS as for any machine @@ -394,7 +394,8 @@ elseif strcmp(mapping_for_imas.method,'switchcase') params_eff = gdat_data.gdat_params; if isfield(params_eff,'source') && ~isempty(params_eff.source) - ids_top_name = params_eff.source; + ids_top_names = params_eff.source; + if ischar(ids_top_names); ids_top_names = {ids_top_names}; end else ids_top_name = []; warning('gdat:EmptyIDSName','Need an ids name in ''source'' parameter\n check substructure gdat_params.sources_available for an ids list'); @@ -405,29 +406,6 @@ elseif strcmp(mapping_for_imas.method,'switchcase') return end ids_gen_ok = ~~exist('ids_gen','file'); - - if ids_gen_ok - ids_empty = ids_gen(ids_top_name); % generate ids from gateway function ids_gen - else - % load empty ids structure from template file - fname = sprintf('ids_empty_%s',ids_top_name); - - try - assert(~~exist(ids_empty_path,'dir'),'folder %s not found',ids_empty_path); - addpath(ids_empty_path); - assert(~~exist(fname,'file'),'file %s does not exist in %s',fname,ids_empty_path); - - ids_empty = eval(fname); - disp(['use structure in .mat file: ' ids_empty_path '/' fname]); - rmpath(ids_empty_path); - catch ME - fprintf('Could not load empty template for %s\n',ids_top_name); - fprintf('Available templates:\n'); - disp(dir(ids_empty_path)); - rmpath(ids_empty_path); - rethrow(ME); - end - end if ~isfield(gdat_data.gdat_params,'error_bar') || isempty(gdat_data.gdat_params.error_bar) gdat_data.gdat_params.error_bar = 'delta'; end @@ -445,37 +423,66 @@ elseif strcmp(mapping_for_imas.method,'switchcase') end if ~isfield(gdat_data.gdat_params,'ipsign_in') || isempty(gdat_data.gdat_params.ipsign_in) if gdat_data.gdat_params.ipsign_out~=0 - gdat_data.gdat_params.ipsign_in = mdsvalue('\pcs::data:iohfb'); + gdat_data.gdat_params.ipsign_in = -1; else - gdat_data.gdat_params.ipsign_in = 0; + gdat_data.gdat_params.ipsign_in = 0; end end if ~isfield(gdat_data.gdat_params,'b0sign_in') || isempty(gdat_data.gdat_params.b0sign_in) if gdat_data.gdat_params.b0sign_out~=0 - gdat_data.gdat_params.b0sign_in = mdsvalue('\pcs::data:if36fb'); + gdat_data.gdat_params.b0sign_in = -1; else - gdat_data.gdat_params.b0sign_in = 0; + gdat_data.gdat_params.b0sign_in = 0; end end - try - if isfield(gdat_data.gdat_params,'idx_imas_open_env') && gdat_data.gdat_params.idx_imas_open_env >= 0 - if gdat_data.gdat_params.occurence == 0 - ids_top = ids_get(gdat_data.gdat_params.idx_imas_open_env,ids_top_name); + 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 + else + % load empty ids structure from template file + fname = sprintf('ids_empty_%s',ids_top_name); + try + assert(~~exist(ids_empty_path,'dir'),'folder %s not found',ids_empty_path); + addpath(ids_empty_path); + assert(~~exist(fname,'file'),'file %s does not exist in %s',fname,ids_empty_path); + + ids_empty = eval(fname); + disp(['use structure in .mat file: ' ids_empty_path '/' fname]); + rmpath(ids_empty_path); + catch ME + fprintf('Could not load empty template for %s\n',ids_top_name); + fprintf('Available templates:\n'); + disp(dir(ids_empty_path)); + rmpath(ids_empty_path); + rethrow(ME); + end + end + % load data + try + if isfield(gdat_data.gdat_params,'idx_imas_open_env') && gdat_data.gdat_params.idx_imas_open_env >= 0 + if gdat_data.gdat_params.occurence == 0 + ids_top = ids_get(gdat_data.gdat_params.idx_imas_open_env,ids_top_name); + else + ids_top = ids_get(gdat_data.gdat_params.idx_imas_open_env,[ids_top_name '/' num2str(gdat_data.gdat_params.occurence)]); + end + gdat_data.(ids_top_name) = ids_top; else - ids_top = ids_get(gdat_data.gdat_params.idx_imas_open_env,[ids_top_name '/' num2str(gdat_data.gdat_params.occurence)]); + gdat_data.(ids_top_name) = ids_empty; end - gdat_data.(ids_top_name) = ids_top; - else - gdat_data.(ids_top_name) = ids_empty; + catch ME_imas_ids_get + disp(['there is a problem with: imas_get_ids_' ids_top_name ... + ' , may be check if it exists in your path or test it by itself']) + gdat_data.(ids_top_name) = ids_empty; + gdat_data.([ids_top_name '_help']) = getReport(ME_imas_ids_get); + rethrow(ME_imas_ids_get) + end + % Perform cocos transformation if cocos_out ~= cocos_in + if gdat_data.gdat_params.cocos_in ~= gdat_data.gdat_params.cocos_out + warning('should perform cocos transformation, to include...') end - catch ME_imas_ids_get - disp(['there is a problem with: imas_get_ids_' ids_top_name ... - ' , may be check if it exists in your path or test it by itself']) - gdat_data.(ids_top_name) = ids_empty; - gdat_data.([ids_top_name '_help']) = getReport(ME_imas_ids_get); - rethrow(ME_imas_ids_get) end - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% otherwise if (gdat_params.nverbose>=1); warning(['switchcase= ' data_request_eff ' not known in gdat_imas']); end -- GitLab