Newer
Older
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);
obj@SCDclass_mdswg();
destidxvalchecker=@(x) isscalar(x);
%addParameter(obj.cparser,'destindex',1,destidxvalchecker);
obj.cparser.addParameter('destindex',1,destidxvalchecker)
obj=obj.parseconstructorcommon(srctdi, destwavegen, varargin);
%parse(p,varargin{:});
obj.destidx=obj.cparser.Results.destindex;
obj.classname=mfilename;
obj.marteclassname='MDSWgSigSingle';
end
end
methods
function actualizedata(obj, shot)
try
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; % name of base workspace structure
structparam=obj.wavegentarget; % name of target field
wgentryval = evalin('base',baseparam); % structure of wavegen in base workspace
assert(isfield(wgentryval,structparam),...
'Wavegen field %s does not exist in target structure %s. ',structparam,baseparam)
% assign field from wavegen entry value
ddtssamples=numel(wgentryval.(structparam).Time);
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
wgentryval.(structparam)=value;
else
% the dd timeseries has the same size than the signals
% to be loaded, we can do a partial loading
wgentryval.(structparam).Time=value.Time;
wgentryval.(structparam).Data(:,obj.destidx)=value.Data;
end
assignin('base','temp',wgentryval);
assigncmd=sprintf('%s=temp;',baseparam);
evalin('base',assigncmd);
evalin('base','clear temp');
catch
warning('SCDclass_mdswgsigsingle:actualizationerror','Actualization error for wavegen %s. Actualization skipped.',obj.wavegentarget);
end
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))';
dbdata=mdsvalue(obj.tdiexpr);
dbtime=mdsvalue(['dim_of(' obj.tdiexpr ')']);
value.Data = single(interp1(dbtime,dbdata,timebase,'linear',0))';
firstindexes=find(timebase<dbtime(1));
lastindexes=find(timebase>dbtime(end));
value.Data(firstindexes)=single(dbdata(1));
value.Data(lastindexes)=single(dbdata(end));
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) ' }'];
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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
%