function buildOptickleSys01(varargin) %buildOptickleSys Pops-up a window containing an Optickle based subsystem for simulinkNB % buildOptickleSys(optName,fVecName,inputs,outputs) % ARGUMENTS % optName: a string giving the name of the optickle model object % note: if the input and output ports are not provided, then % the optickle model object must exist with this name in the % workspace where this function is called. % fVecName: a string giving the name of the frequency vector % OPTIONAL ARGUMENTS % inputs: a cell array of strings that define which optickle inputs % (drives) will be used % outputs: a cell array of strings that define which optickle outputs % (probes) will be used % % This is for ASC ===================================================== % Uses optickleFrd01.m instead of optickleFrd.m % % this is the string that appears in the noise budget legend NOISEGROUP = 'Quantum Vacuum'; narginchk(2,4); optName = varargin{1}; fVecName = varargin{2}; if nargin<4 opt = evalin('caller',optName); probearray = opt.probe; outputs = cell(length(probearray),1); for j =1:length(probearray) outputs{j} = probearray(j).name; end else outputs = varargin{4}; end if nargin<3 inputs = getDriveNames(opt); else inputs = varargin{3}; end % settings for placement of blocks origin.Inport = [20 50 50 70]; offset.Inport = [0 100 0 100]; origin.opt = [200 20 500 600]; origin.optInport = origin.Inport; offset.optInport = offset.Inport; origin.Outport = [800 50 830 70]; offset.Outport = offset.Inport; origin.optOutport = origin.Outport; offset.optOutport = offset.Outport; origin.noiseBlock = origin.Outport - [150 50 150 50]; offset.noiseBlock = offset.Outport; origin.internalSum = [400 20 425 400]; origin.outputSum = [700 50 720 70]; offset.outputSum = offset.Outport; base = 'simulinkNBOptickleBlock'; try new_system(base) catch exception if exist(base,'file') == 4 close_system(base,0) new_system(base) else rethrow(exception) end end sys = [base '/OptickleModel']; sysblock = add_block('built-in/SubSystem',sys,'Position',origin.opt,'BackGroundColor','purple'); set(sysblock,'AttributesFormatString','%'); % argument string for autogenerated tag argstring = ['''' optName ''',''' fVecName '''']; if nargin > 2 argstring = [argstring ',' makeCellLiteralString(inputs)]; end if nargin > 3 argstring = [argstring ',' makeCellLiteralString(outputs)]; end set(sysblock,'Description',['Autogenerated using buildOptickleSys01(' argstring ')']); % add the optickleFrd block optFrd = add_block('built-in/SubSystem',[sys '/' optName]); set(optFrd,'Position',origin.opt); set(optFrd,'AttributesFormatString','%'); set(optFrd,'Description',['flexTF: optickleFrd01(' optName ',' fVecName ')']); % add internals of optickleFrd sumblock = add_block('built-in/Sum',[sys '/' optName '/Sum']); set(sumblock,'Position',origin.internalSum); set(sumblock,'IconShape','rectangular'); set(sumblock,'Inputs',repmat('+',1,length(inputs))); % loop on inputs for jj = 1:length(inputs); input = inputs{jj}; % inputs add_block('built-in/Inport',[sys '/' input],'Position',origin.Inport+(jj-1)*offset.Inport); % optickleFrd inputs add_block('built-in/Inport',[sys '/' optName '/' input],'Position',origin.optInport+(jj-1)*offset.optInport); % add links add_line(sys,[input '/1'],[optName '/' num2str(jj)],'autorouting','on'); add_line([sys '/' optName],[input '/1'],['Sum/' num2str(jj)],'autorouting','on'); end % loop on outputs for jj = 1:length(outputs); output = outputs{jj}; % outputs add_block('built-in/Outport',[sys '/' output],'Position',origin.Outport+(jj-1)*offset.Outport); % optickleFrd outputs add_block('built-in/Outport',[sys '/' optName '/' output],'Position',origin.optOutport+(jj-1)*offset.optOutport); % add the noiseblock noiseBlock = add_block('NbLibrary/NbNoiseSource',[sys '/' output '_Noise']); set(noiseBlock,'Position',origin.noiseBlock+(jj-1)*offset.noiseBlock); set(noiseBlock,'asd',['optickleNoiseBlock01(' optName ',' fVecName ',''' output ''','... 'makeOptickleDriveIndex(' optName ',' makeCellLiteralString(inputs) '))']) set(noiseBlock,'groupNest','2'); set(noiseBlock,'group',['''' NOISEGROUP '''']); set(noiseBlock,'subgroup',['''' output '''']); % add sum block sumblock = add_block('built-in/Sum',[sys '/Sum' num2str(jj)]); set(sumblock,'Position',origin.outputSum + (jj-1)*offset.outputSum); set(sumblock,'IconShape','round'); set(sumblock,'Inputs','++|'); % add links add_line([sys '/' optName],'Sum/1',[output '/1'],'autorouting','on'); add_line(sys,[output '_Noise/1'],['Sum' num2str(jj) '/1'],'autorouting','on'); add_line(sys,[optName '/' num2str(jj)],['Sum' num2str(jj) '/2'],'autorouting','on'); add_line(sys,['Sum' num2str(jj) '/1'],[output '/1'],'autorouting','on'); end open_system(base); end function outputString = makeCellLiteralString(inputCell) outputString = '{'; for jj = 1:length(inputCell) outputString = [outputString '''' inputCell{jj} ''',']; %#ok end outputString = [outputString(1:end-1) '}']; end