diff --git a/matlab/TCV/gdat_tcv.m b/matlab/TCV/gdat_tcv.m index b177db5366a348253725e2c84e30d00a73774ef1..e7ab04f1c2cc6789950a62dce34bfc3af88dbd9c 100644 --- a/matlab/TCV/gdat_tcv.m +++ b/matlab/TCV/gdat_tcv.m @@ -83,6 +83,7 @@ varargout{1}=cell(1,1); error_status=1; % construct main default parameters structure +% parameters and defaults related to a specific request should be defined in the relevant switch case section gdat_params.data_request = ''; default_machine = 'tcv'; @@ -1511,7 +1512,7 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') if ~isempty(gdat_data.gdat_params.trialindx) && gdat_data.gdat_params.trialindx < 0 gdat_data.gdat_params.trialindx = []; end - + % specific parameters check and default settings if ~isfield(gdat_data.gdat_params,'source') || isempty(gdat_data.gdat_params.source) switch data_request_eff case 'ec_data' @@ -1548,6 +1549,10 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') end end end + if ~isfield(gdat_data.gdat_params,'ec_inputs') || isempty(gdat_data.gdat_params.ec_inputs) || ~isnumeric(gdat_data.gdat_params.ec_inputs) + gdat_data.gdat_params.ec_inputs = 0; + end + gdat_params.ec_inputs = gdat_data.gdat_params.ec_inputs; % create structure for icd sources from params and complete with defaults source_icd.ec = 'toray'; @@ -1572,32 +1577,41 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') ec_help = ''; % EC - % fill ec_inputs from write_pgyro - [~,time,pgyro,pgyro_ecrh,gyro2launcher,freq2launcher,~,~] = write_pgyro(shot,'doplots',0); - - ec_inputs.pgyro.data = pgyro; - ec_inputs.pgyro.t = time; - ec_inputs.pgyro.units = 'W'; - ec_inputs.pgyro.label = 'Power injected per launcher ; last index is total'; - ec_inputs.pgyro.x = 1:numel(pgyro(1,:)); - ec_inputs.pgyro.dim = {ec_inputs.pgyro.x, ec_inputs.pgyro.t}; - launchers_label = cellfun(@num2str, num2cell(1:size(pgyro,2)-1),'UniformOutput',false); - launchers_label{end+1} = 'tot'; - ec_inputs.pgyro.dimunits = {launchers_label, 's'}; - - ec_inputs.launchers_active.data = zeros(numel(pgyro_ecrh),1); - for ii =1:numel(pgyro_ecrh) - if ~isempty(pgyro_ecrh{ii}.data); ec_inputs.launchers_active.data(ii) = 1; end - end - ec_inputs.launchers_active.label = 'Active launchers in the shot (1:active, 0:inactive)'; + if gdat_data.gdat_params.ec_inputs + % fill ec_inputs from write_pgyro + [~,time,pgyro,pgyro_ecrh,gyro2launcher,freq2launcher,~,~] = write_pgyro(shot,'doplots',0); + + ec_inputs.pgyro.data = pgyro; + ec_inputs.pgyro.t = time; + ec_inputs.pgyro.units = 'W'; + ec_inputs.pgyro.label = 'Power injected per launcher ; last index is total'; + ec_inputs.pgyro.x = 1:numel(pgyro(1,:)); + ec_inputs.pgyro.dim = {ec_inputs.pgyro.x, ec_inputs.pgyro.t}; + launchers_label = cellfun(@num2str, num2cell(1:size(pgyro,2)-1),'UniformOutput',false); + launchers_label{end+1} = 'tot'; + ec_inputs.pgyro.dimunits = {launchers_label, 's'}; + + ec_inputs.launchers_active.data = zeros(numel(pgyro_ecrh),1); + for ii =1:numel(pgyro_ecrh) + if ~isempty(pgyro_ecrh{ii}.data); ec_inputs.launchers_active.data(ii) = 1; end + end + ec_inputs.launchers_active.label = 'Active launchers in the shot (1:active, 0:inactive)'; - ec_inputs.gyro2launcher.data = gyro2launcher; - ec_inputs.gyro2launcher.label = 'Gyrotron connected to launcher'; + ec_inputs.gyro2launcher.data = gyro2launcher; + ec_inputs.gyro2launcher.label = 'Gyrotron connected to launcher'; - ec_inputs.freq2launcher.data = freq2launcher; - ec_inputs.freq2launcher.label = 'Frequency in launcher'; - ec_inputs.freq2launcher.units = 'Hz'; + ec_inputs.freq2launcher.data = freq2launcher; + ec_inputs.freq2launcher.label = 'Frequency in launcher'; + ec_inputs.freq2launcher.units = 'Hz'; + ec_inputs.comment = 'ec_inputs loaded from write_pyro(shot)'; + else + ec_inputs.pgyro = []; + ec_inputs.launchers_active = []; + ec_inputs.gyro2launcher = []; + ec_inputs.freq2launcher = []; + ec_inputs.comment = 'Run gdat with name-value pair (''ec_inputs'',1) for ec_input information from write_pgyro'; + end gdat_data.ec.ec_inputs = ec_inputs; % introduce flag to check whether ec_data could be retrieved successfully @@ -1744,10 +1758,12 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') getReport(ME) % without ; to get output % try to identify cause of the error if ~check_nodes_filled(shot,'toray') - if ~any(ec_inputs.launchers_active.data,1) - msg = 'write_pyro(shot) found NO active launchers, maybe there was no EC in this shot?'; - else - msg = 'write_pyro(shot) found active launchers, but TORAY nodes are no filled, check hldsi(shot), and (ask to) relaunch TORAY.'; + if ~isempty(ec_inputs.launchers_active) + if ~any(ec_inputs.launchers_active.data,1) + msg = 'write_pyro(shot) found NO active launchers, maybe there was no EC in this shot?'; + else + msg = 'write_pyro(shot) found active launchers, but TORAY nodes are not filled, check hldsi(shot), and (ask to) relaunch TORAY.'; + end end elseif ~isempty(gdat_data.gdat_params.trialindx) msg = 'Is the trial index filled? Check TORAY nodes with hdlsi(shot).'; @@ -3328,19 +3344,25 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') end return end + % time_out: times at which to provide output data, if 2 values provided, return all values within that time interval + % for xtomo, can only provide a time interval, for radcam, can provide a time_out array on which interpos is computed time_interval = []; if isfield(gdat_data.gdat_params,'time_out') && ~isempty(gdat_data.gdat_params.time_out) - if length(gdat_data.gdat_params.time_out) == 2 + if numel(gdat_data.gdat_params.time_out) == 2 time_interval = gdat_data.gdat_params.time_out; else - if length(gdat_data.gdat_params.time_out) == 1 + if numel(gdat_data.gdat_params.time_out) == 1 % 200ms includes all characteristic time constants time_interval = [gdat_data.gdat_params.time_out-0.1 gdat_data.gdat_params.time_out+0.1]; else - time_interval = [min(gdat_data.gdat_params.time_out)-0.1 max(gdat_data.gdat_params.time_out)+0.1]; + if strcmp(gdat_data.gdat_params.source,'radcam') + time_interval = gdat_data.gdat_params.time_out; % for radcam provide time array on which to do interpos + else + time_interval = [min(gdat_data.gdat_params.time_out)-0.1 max(gdat_data.gdat_params.time_out)+0.1]; + warning(['Expects a time interval [t1 t2] for ' data_request_eff ' in param time_out, uses [' ... + num2str(time_interval(1)) ',' num2str(time_interval(2)) ']' char(10)]) + end end - warning(['Expects a time interval [t1 t2] for ' data_request_eff ' in param time_out, uses [' ... - num2str(time_interval(1)) ',' num2str(time_interval(2)) ']' char(10)]) end end % at this stage 2 option for freq, raw data (fast, default), 10kHz or similar (slow) @@ -3428,11 +3450,41 @@ elseif strcmp(mapping_for_tcv.method,'switchcase') gdat_data.x(end+1:end+numel(gdat_data.(gdat_data.gdat_params.camera{i}).x)) = gdat_data.(gdat_data.gdat_params.camera{i}).x; end sxr = rc_load_diodes(shot,'diag_name',"sxr",'channels',gdat_data.x); % since all cameras with different channel number + % for "heavy" signals, can trim it to specified time_interval and/or reduce it to smaller nb points if freq_opt == 1 - gdat_data.data = sxr.data'; - gdat_data.t = sxr.time; + % default, fast/raw time array + if ~isempty(time_interval) + if numel(time_interval) == 2 + % extract data within [time_interval(1:2)] + ij = find(sxr.time>=time_interval(1) & sxr.time<=time_interval(end)); + gdat_data.data = sxr.data(ij,:)'; + gdat_data.t = sxr.time(ij); + else + % time_out array provided to obtain data, use closest points (since raw data on fast frequency) + ij = iround_os(sxr.time,time_interval); + gdat_data.data = sxr.data(ij,:)'; + gdat_data.t = sxr.time(ij); + end + else + % raw data requested (default), no time_out provided + gdat_data.data = sxr.data'; + gdat_data.t = sxr.time; + end else - gdat_data.t = linspace(sxr.time(1),sxr.time(end),round((sxr.time(end)-sxr.time(1))/1e-4)); + % slower frequency requested (or smoothed interpolation using interpos) + if ~isempty(time_interval) + if numel(time_interval) == 2 + % construct a default 40kHz time base within time_interval(1:2) + gdat_data.t = linspace(time_interval(1),time_interval(2),round((time_interval(2)-time_interval(1))/0.25e-4)); + else + % time array provided + gdat_data.t = time_interval; + end + else + % construct a default 40kHz time base within full raw time interval + gdat_data.t = linspace(sxr.time(1),sxr.time(end),round((sxr.time(end)-sxr.time(1))/0.25e-4)); + end + % compute interpolation with tension provided for i=1:size(sxr.data,2) gdat_data.data(i,:) = interpos(sxr.time,sxr.data(:,i),gdat_data.t,gdat_data.gdat_params.fit_tension); end diff --git a/matlab/TCV/tcv_help_parameters.m b/matlab/TCV/tcv_help_parameters.m index 15de8984169996ffdd2c5f1ea0e1b99a310aaa33..f864a08468e84d120646871535122a4e2c54b2e4 100644 --- a/matlab/TCV/tcv_help_parameters.m +++ b/matlab/TCV/tcv_help_parameters.m @@ -39,6 +39,7 @@ help_struct_all.cocos = ['cocos value desired in output, uses eqdsk_cocos_transf 'is wanted. See O. Sauter et al Comput. Phys. Commun. 184 (2013) 293']; help_struct_all.nrz_out = 'Nb of radial and vertical points in output eqdsk, default is [129,129], set to [-1,-1] to get original meshes'; help_struct_all.edge = '0 (default), 1 to get edge Thomson values'; +help_struct_all.ec_inputs = '0 (default), 1 to get characterics of gyrotrons connected to each launcher: active, freq, power'; help_struct_all.fit = '0, no fit profiles, 1 (default) if fit profiles desired as well, relevant for _rho profiles. See also fit_type'; help_struct_all.fit_type = 'provenance of fitted profiles ''conf'' (default) from conf nodes, ''avg'' or ''local'' for resp. proffit: nodes'; help_struct_all.trialindx = 'value of trialindx desired to get a specific one when relevant, otherwise gets ok_trialindx, that is 1 usually'; diff --git a/matlab/gdat.m b/matlab/gdat.m index 942b0dd5bc26b87db8cc082a9f597c36ef92aa35..0271c503d62497604cfe6a619d21584398e777ab 100644 --- a/matlab/gdat.m +++ b/matlab/gdat.m @@ -190,14 +190,18 @@ try % treat multiple shot numbers if nargin > 0 && isnumeric(shot) && ~isempty(shot) args_in = args; - for i=1:numel(shot) - args{1} = shot(i); - [gdat_data_i,gdat_params,error_status(i),varargout] = feval(['gdat_' lower(machine_eff)],args{:}); - gdat_data_i.gdat_params.machine = lower(gdat_data_i.gdat_params.machine); - gdat_data(i) = gdat_data_i; + if ~isempty(shot) + for i=1:numel(shot) + args{1} = shot(i); + [gdat_data_i,gdat_params,error_status(i),varargout_gdat] = feval(['gdat_' lower(machine_eff)],args{:}); + gdat_data_i.gdat_params.machine = lower(gdat_data_i.gdat_params.machine); + gdat_data(i) = gdat_data_i; + end + else + [gdat_data,gdat_params,error_status,varargout_gdat] = feval(['gdat_' lower(machine_eff)],args{:}); end else - [gdat_data,gdat_params,error_status,varargout] = feval(['gdat_' lower(machine_eff)],args{:}); + [gdat_data,gdat_params,error_status,varargout_gdat] = feval(['gdat_' lower(machine_eff)],args{:}); % because data request can be an actual detailed tree related signal, upper and lower case need to be kept, but other places remain with lower case when case insensitive % needed since some substructure have machine name like mapping_for gdat_data.gdat_params.machine = lower(gdat_data.gdat_params.machine); diff --git a/matlab/subcall_all2str.m b/matlab/subcall_all2str.m index 8966d184da44bc48e0c6973f93e9f0c7e8742ab0..bc88c279e055876b2631564b2e0e0862c75d3f58 100644 --- a/matlab/subcall_all2str.m +++ b/matlab/subcall_all2str.m @@ -33,9 +33,13 @@ for i_in=1:length(varargin) if prod(size(aa_values))~= length(aa_values) % multi-D input, do not treat it yet subcall = [subcall ',''multi-D input''']; - elseif length(aa_values) > 1 + elseif numel(aa_values) > 1 % array - subcall = [subcall ',[' num2str(reshape(aa_values,1,length(aa_values))) ']']; + if numel(aa_values) <=30 + subcall = [subcall ',[' num2str(reshape(aa_values,1,numel(aa_values))) ']']; + else + subcall = [subcall ',[' num2str(reshape(aa_values(1:4),1,4)) ' ... ' num2str(reshape(aa_values(end-3:end),1,4)) ']']; + end else subcall = [subcall ',' num2str(aa_values) '']; end @@ -47,9 +51,13 @@ for i_in=1:length(varargin) if prod(size(var_to_treat))~= length(var_to_treat) % multi-D input, do not treat it yet subcall = [subcall ',''multi-D input''']; - elseif length(var_to_treat) > 1 + elseif numel(var_to_treat) > 1 % array - subcall = [subcall ',[' num2str(var_to_treat) ']']; + if numel(var_to_treat) <=30 + subcall = [subcall ',[' num2str(reshape(var_to_treat,1,numel(var_to_treat))) ']']; + else + subcall = [subcall ',[' num2str(reshape(var_to_treat(1:4),1,4)) ' ... ' num2str(reshape(var_to_treat(end-3:end),1,4)) ']']; + end else subcall = [subcall ',' num2str(var_to_treat) '']; end