classdef SCDclass_mdswgsigsingle < SCDclass_mdswg % This class loads a signal from MDS+ and puts it into % the target wavegen timeseries, the signal postition % in the target timeseries structure is remapped according to % the optional destidx constructor parameter. If it is not % specified, no remapping takes places (1-1 load) properties destidx end methods function obj=SCDclass_mdswgsigsingle(srctdi, destwavegen, varargin) obj@SCDclass_mdswg(srctdi, destwavegen, varargin); destidxvalchecker=@(x) isscalar(x); p=inputParser; addParameter(p,'destindex',1,destidxvalchecker); parse(p,varargin{:}); obj.destidx=p.Results.destindex; obj.classname='SCDclass_mdswgsigsingle'; end end methods function actualizedata(obj, shot) mdsconnect(obj.mdsserver); mdsopen(obj.mdstree, shot); targetfullexpansion=[obj.wavegenbasestruct,'.',obj.wavegentarget]; if obj.verbose==1 fprintf('Actualizing wavegen: ''%s'' [%d] <- ''%s'' (%s, shot %d)\n', ... targetfullexpansion, obj.destidx, ... obj.tdiexpr, ... obj.classname, shot); end value=obj.getdata(); baseparam=obj.wavegenbasestruct; structparam=obj.wavegentarget; wgentryval=evalin('base',baseparam); getcurrenttssize =sprintf('ddtssamples=numel(wgentryval.%s.Time);',structparam); eval(getcurrenttssize); if(ddtssamples~=numel(value.Time)) % the dd timeseries has different dims w.r.t. the signals % to be loaded, we have to load the timeseries as it is assigncmd =sprintf('wgentryval.%s=value;',structparam); eval(assigncmd); else % the dd timeseries has the same size than the signals % to be loaded, we can do a partial loading assigncmdtime =sprintf('wgentryval.%s.Time=value.Time;',structparam); assigncmddata =sprintf('wgentryval.%s.Data(:,%d)=value.Data;',structparam,obj.destidx); eval(assigncmdtime); eval(assigncmddata); end assignin('base','temp',wgentryval); assigncmd=sprintf('%s=temp;',baseparam); evalin('base',assigncmd); evalin('base','clear temp'); end function value=getdata(obj) value=timeseries; % Getting the timebase of the model tstart=obj.timebasestart; dt=obj.timebasedt; tstop=obj.timebasestop; timebase=tstart:dt:tstop; value.Time = timebase; value.Data = single(zeros(numel(timebase),1)); data=tdi(obj.tdiexpr); value.Data = single(interp1(data.dim{1},data.data,timebase,'linear',0))'; end function out=gettargetwavegen(obj) if(isempty(obj.wavegenbasestruct)) out=sprintf('%s[%d]',obj.wavegentarget, obj.destidx); else out=sprintf('%s.%s[%d]',obj.wavegenbasestruct,obj.wavegentarget, obj.destidx); end end function printinfo(obj) obj.printinfocommon; if(obj.destidx~=1) fprintf(' Remapping: destination signal index is %d\n', obj.destidx); end end function entrystring = genMARTe2entry(obj, shot) entrystring=obj.genMARTe2entrycommon(shot); end end end % methods(Access=protected) % % function actualizedatadd(obj, shot) % % Actualizes data in the data dictionary % % BEWARE at saving and committing big dimension useless % % data dictionaries % % errstr=sprintf('%s:actualizedatadd', obj.classname); % error(errstr,'actualizing wavegens on data dictionaries not supported'); % % mdsconnect(obj.mdsserver); % mdsopen(obj.mdstree, shot); % % if obj.verbose==1 % fprintf('Actualizing (DATADICT!) wavegen: ''%s'' [%d] <- ''%s'' (%s, shot %d)\n', ... % obj.wavegentarget, obj.destidx, ... % obj.tdiexpr, ... % obj.classname, shot); % end % % value=obj.getdata(); % % % We need to access the data dictionary directly here, % % no way to used automatic dd assign and eval functions, % % they do not work with timeseries % % d=Simulink.data.dictionary.open(sprintf('%s.sldd',obj.modelname)); % dd=getSection(d, 'Design Data'); % % pointspos=strfind(obj.wavegentarget,'.'); % baseparam=obj.wavegentarget(1:pointspos(1)-1); % structparam=obj.wavegentarget(pointspos(1)+1:end); % wgentry=dd.getEntry(baseparam); % wgentryval=wgentry.getValue; % % getcurrenttssize =sprintf('ddtssamples=numel(wgentryval.%s.Time);',structparam); % eval(getcurrenttssize); % if(ddtssamples~=numel(value.Time)) % % the dd timeseries has different dims w.r.t. the signals % % to be loaded, we have to load the timeseries as it is % % assigncmd =sprintf('wgentryval.%s=value;',structparam); % eval(assigncmd); % else % % the dd timeseries has the same size than the signals % % to be loaded, we can do a partial loading % % assigncmdtime =sprintf('wgentryval.%s.Time=value.Time;',structparam); % assigncmddata =sprintf('wgentryval.%s.Data(:,%d)=value.Data;',structparam,obj.destidx); % % eval(assigncmdtime); % eval(assigncmddata); % end % % wgentry.setValue(wgentryval); % % end % % % % function cleandata(obj) % % error('SCDclass_mdswgsigsingle:cleandata','cleandata has been deprecated'); % % % if obj.verbose==1 % fprintf('Cleaning wavegen: %s [%d] (%s)\n', ... % obj.wavegentarget, obj.destidx, ... % obj.classname); % end % % d=Simulink.data.dictionary.open(sprintf('%s.sldd',obj.modelname)); % dd=getSection(d, 'Design Data'); % % pointspos=strfind(obj.wavegentarget,'.'); % baseparam=obj.wavegentarget(1:pointspos(1)-1); % structparam=obj.wavegentarget(pointspos(1)+1:end); % wgentry=dd.getEntry(baseparam); % wgentryval=wgentry.getValue; % % datasizecmd=sprintf('datasize=size(wgentryval.%s.Data);',structparam); % eval(datasizecmd); % datasize=datasize(2); % % emptyts=timeseries; % emptyts.Time=[0;1]; % emptyts.Data=single(zeros(2,datasize)); % % assigncmd=sprintf('wgentryval.%s=emptyts;',structparam); % eval(assigncmd); % wgentry.setValue(wgentryval); % % % end % % % end %