diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m index 671d1f625877e7b7b5bfc0f41173348fedeb75ea..f5cd1e07d69e2b66178d5029874683ebc6442175 100644 --- a/matlab/TCV/gdat_tcv.m +++ b/matlab/TCV/gdat_tcv.m @@ -1090,35 +1090,42 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% case {'ids'} + ids_empty_path = fullfile(fileparts(mfilename('fullpath')),'..','TCV_IMAS','ids_empty'); + params_eff = gdat_data.gdat_params; if isfield(params_eff,'source') && ~isempty(params_eff.source) ids_top_name = params_eff.source; else ids_top_name = []; - disp('need an ids name in ''source'' parameter'); - disp('check substructure gdat_params.source_available for an ids list'); - end - ids_gen_ok = ~isempty(which('ids_gen')); - ids_empty = struct([]); - if ~ids_gen_ok - ids_struct_saved = '/home/sauter/matlab/gdat_develop/crpptbx/TCV_IMAS/ids_structures_20190312.mat'; - if ~exist(ids_struct_saved,'file') - warning(['function ids_gen not available neither file ids_structures_20190312.mat thus cannot create empty ids: ids_gen(''' ids_top_name ''')']); - return - else - load(ids_struct_saved) - if isfield(ids_structures,ids_top_name) - ids_empty = ids_structures.(ids_top_name); - else - if ~isempty(ids_top_name); - warning(['ids ''' ids_top_name ''' does not exist in ids_structures saved in ' ids_struct_saved]); - end - gdat_data.gdat_params.source_available = ids_list; - return - end - end + warning('gdat:EmptyIDSName','Need an ids name in ''source'' parameter\n check substructure gdat_params.sources_available for an ids list'); + addpath(ids_empty_path); + assert(~~exist('ids_list','file'),'could not find ids_list.m in %s',ids_empty_path); + gdat_data.gdat_params.sources_available = ids_list; + rmpath(ids_empty_path); + 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 - ids_empty = ids_gen(ids_top_name); + % 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); + 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'; @@ -1129,12 +1136,12 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') gdat_data.(ids_top_name) = ids_top; gdat_data.([ids_top_name '_description']) = ids_top_description; else - gdat_data.(ids_top_name) = ids_empty; - gdat_data.([ids_top_name '_description']) = ['shot empty so return default empty structure for ' ids_top_name]; + gdat_data.(ids_top_name) = ids_empty; + gdat_data.([ids_top_name '_description']) = ['shot empty so return default empty structure for ' ids_top_name]; end catch ME_tcv_get_ids disp(['there is a problem with: tcv_get_ids_' ids_top_name ... - ' , may be check if it exists in your path or test it by itself']) + ' , 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 '_description']) = getReport(ME_tcv_get_ids); rethrow(ME_tcv_get_ids) diff --git a/matlab/TCV_IMAS/test_tcv_get_ids.m b/matlab/TCV_IMAS/test_tcv_get_ids.m index bff81d9c749128d3067b7f1d16be8513749e429c..d4642d48c8a2f01a35a0b95b8dd00bdeaabb92ca 100644 --- a/matlab/TCV_IMAS/test_tcv_get_ids.m +++ b/matlab/TCV_IMAS/test_tcv_get_ids.m @@ -1,15 +1,25 @@ classdef (SharedTestFixtures={... - check_mds,setup_gdatpaths})... - test_tcv_get_ids < matlab.unittest.TestCase + check_mds,setup_gdatpaths})... + test_tcv_get_ids < matlab.unittest.TestCase properties(TestParameter) shot = {-1,40000,61400}; ids_name = {'pf_active','wall'}; end - methods(Test,TestTags = {'IMAS'}) + methods(Test,TestTags = {'imas'}) + function test_get_ids_list(testCase,shot) + gg = testCase.assertWarning(@() gdat(shot,'ids'),'gdat:EmptyIDSName'); + + testCase.assertTrue(iscell(gg.gdat_params.sources_available)); + end + function test_tcv2ids(testCase,shot,ids_name) - ids = tcv2ids(shot,'ids_name',{ids_name}); + if shot==-1 && strcmp(ids_name,'pf_active') + ids = testCase.assertWarning(@() tcv2ids(shot,'ids_name',{ids_name}),'TCV:IDS:NoTimeData'); + else + ids = testCase.assertWarningFree(@() tcv2ids(shot,'ids_name',{ids_name})); + end testCase.assertTrue(~isempty(ids)) end end