Home > m > gui > gltpda > pan2param.m

pan2param

PURPOSE ^

This is the GUI m-file able to read the list of parameters to be set for

SYNOPSIS ^

function pan2param(varargin)

DESCRIPTION ^

 This is the GUI m-file able to read the list of parameters to be set for
 the function/block currently selected and to build the window with the
 parameters panel accordingly.

  $Id: pan2param.m,v 1.25 2008/03/28 13:39:50 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pan2param(varargin)
0002 % This is the GUI m-file able to read the list of parameters to be set for
0003 % the function/block currently selected and to build the window with the
0004 % parameters panel accordingly.
0005 %
0006 %  $Id: pan2param.m,v 1.25 2008/03/28 13:39:50 nicola Exp $
0007 
0008 global params selBlocks objName paramEnabled LTPDAinvar noParamsReq functionName paramSets enlargedFont
0009 
0010 %%
0011 currPanel   = varargin{1};
0012 panelDimens = get(currPanel, 'Position');
0013 backColor   = get(currPanel, 'BackgroundColor');
0014 selBlocks   = 0;
0015 
0016 alltimers = timerfindall;
0017 stop(alltimers(1));
0018 set(alltimers(1),'TimerFcn',@ContinuousParamCheck,'Period',0.3);
0019 start(alltimers(1));
0020 
0021 
0022 %%
0023     %----------------------------------------------------------------------
0024     function buildplistFigureParam()
0025     %----------------------------------------------------------------------
0026     
0027     enlargedFont = 0;
0028     clear params paramEnabled functionName paramSets objName
0029     panelDimens = getappdata(0, 'ltpda_currPanelDimens');
0030     delete(findobj(gcf,'Parent',currPanel))
0031     close(findobj('Tag','expandedEditField'))
0032 
0033   paramcommand = get_param(gcbh,'Description');
0034   noParamsReq=0;
0035   if isempty(paramcommand)
0036       paramcommand = RetrievePlist();
0037       selBlocks = gcbsh;
0038       for kk=1:length(selBlocks)
0039           set_param(selBlocks(kk),'Description',paramcommand);
0040       end
0041   end
0042 % ======================================================================
0043   eval(paramcommand)
0044 % ======================================================================
0045   if ~exist('paramEnabled','var') && isempty(find(params,'Sets')) && noParamsReq==0
0046       paramEnabled = zeros(1,nparams(params));
0047   end
0048   if exist('functionName','var') && ~isempty(functionName)
0049       setappdata(0,'ltpda_currFunctionName',functionName);
0050     % Text:
0051       uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[40 panelDimens(4)-40 100 14],'FontSize',enlargedFont+7,'String','Function name:','TooltipString','Function name','Visible','on','Style','text');
0052     % Edit field:
0053       uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','center','Position',[150 panelDimens(4)-40 100 16],'FontSize',enlargedFont+7,'String', functionName,'TooltipString','Name of the function','Visible','on','Callback',@functionNameSet,'Style','edit');
0054       panelDimens = getappdata(0, 'ltpda_currPanelDimens');
0055       panelDimens(4) = panelDimens(4)-40;
0056   else
0057       childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0058       setappdata(0,'ltpda_currFunctionName',get_param(childpath,'Tag'));
0059   end
0060   
0061   y=nparams(params);
0062 
0063   if y==0 && ~exist('paramSets','var') && noParamsReq==0
0064       paramcommand=[paramcommand,'noParamsReq=1;'];
0065       selBlocks = gcbsh;
0066       for kk=1:length(selBlocks)
0067           set_param(selBlocks(kk),'Description',paramcommand);
0068       end
0069       buildplistFigureParam()
0070   end
0071 % =========================================================================
0072 % Help Button
0073   uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[panelDimens(3)-70 10 60 16],'FontAngle','italic','FontSize',enlargedFont+8,'String','?','TooltipString','Open the Help associated to this function','Visible','on','Callback',@HelpButtonCallback,'Style','pushbutton');
0074 % Reset Parameters Button
0075   uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[20 10 120 16],'FontAngle','italic','FontSize',enlargedFont+7,'String','Reset Parameters','TooltipString','Reset the parameters for this block','Visible','on','Callback',@ResetButtonCallback,'Style','pushbutton');
0076 % Keep local result
0077   probe = get_param(gcbh,'MaskHelp');
0078   if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe')
0079       keepRes = 1;
0080   else
0081       keepRes = 0;
0082   end
0083   uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[panelDimens(3)-300 10 150 16],'FontAngle','italic','FontSize',enlargedFont+8,'String','Keep local result','TooltipString','Do not delete the result of this block at the end of the calculation','Visible','on','Callback',@KeepResultCallback,'Value',keepRes,'Style','checkbox');
0084 % Set name:
0085   setName = get(gcbh,'UserData');
0086   if isempty(setName), setName = 0; end
0087   uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[panelDimens(3)-500 10 150 16],'FontAngle','italic','FontSize',enlargedFont+8,'String','Set name','TooltipString','Set the signal name equal to the block name','Visible','on','Callback',@SetNameCallback,'Value',setName,'Style','checkbox');
0088   
0089 % % =========================================================================
0090 % % No parameters required:
0091 %   if noParamsReq==1
0092 %     % Text: no params required
0093 %       uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[150 7 120 16],'String','No parameters required','Visible','on','Style','text');
0094 %   end
0095 %
0096 % =========================================================================
0097 % The function has different sets of parameters:
0098   if exist('paramSets','var') && ~isempty(paramSets)
0099       sets = find(paramSets,'sets');
0100       currSet = find(paramSets,'currSet');
0101     % Sets text:
0102       uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-44 150 20],'String','Possible params sets:','Visible','on','Style','text');
0103     % Sets popup menu:
0104       uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2+150 panelDimens(4)-40 250 20],'String',sets,'Value',currSet,'Visible','on','UserData',sets,'Callback',@SetsUpdate,'Style','popup');
0105       panelDimens(4) = panelDimens(4)-40;
0106   end
0107 
0108 % =========================================================================
0109 % Cycle to verify whether gaps (= extra lines for complex params, such as
0110 % pzmodels) are necessary or not:
0111   totalGaps=0;
0112   for ii=1:y
0113       paramkeys{ii} = params.params(ii).key;
0114       paramvals{ii} = params.params(ii).val;
0115       switch class(paramvals{ii})
0116           case 'pzmodel'
0117               if numel(get(paramvals{ii},'poles'))>1 || numel(get(paramvals{ii},'zeros'))>1
0118                   totalGaps=totalGaps+1;
0119               end
0120           case 'miir'
0121               if ~isempty(find(paramvals{ii}.plist,'pzmodel'))
0122                   totalGaps=totalGaps+1;
0123                   if numel(get(find(paramvals{ii}.plist,'pzmodel'),'poles'))>1 || numel(get(find(paramvals{ii}.plist,'pzmodel'),'zeros'))>1
0124                       totalGaps=totalGaps+1;
0125                   end
0126               end
0127           case {'pole','zero'}
0128               if numel(paramvals{ii})>1
0129                   totalGaps=totalGaps+1;
0130               end
0131       end
0132   end
0133   currGap = 0;
0134 
0135 % =========================================================================
0136 for ii=1:y
0137     paramkeys{ii}=params.params(ii).key;
0138     paramvals{ii}=params.params(ii).val;
0139     addedPar = 0;
0140   % Checkbox to enable input setting:
0141     objName{ii,1}   =   uicontrol('Parent',currPanel,'Units','pixels','Position',[10,panelDimens(4)-24*(ii+1+currGap),14,14],'Value',paramEnabled(ii),'Visible','on','Enable','on','Callback', @EnableSetCallback,'Tag',paramkeys{ii},'UserData',ii,'Style','checkbox');
0142   % Remove Param Button:
0143     try %#ok<ALIGN>
0144     if strcmpi(paramkeys{ii}(1:7),'addPar_')
0145         uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-30 panelDimens(4)-24*(ii+1+currGap) 20 20],'String','-','Visible','on','Enable','on','UserData',ii,'Callback', @RemParamCallback,'Style','pushbutton');
0146         addedPar = 1;
0147         paramkeys{ii}(1:7) = [];
0148     end
0149     catch end
0150 
0151     switch class(paramvals{ii})
0152 
0153       % ==========================================================================
0154         case {'double'}
0155       % ==========================================================================
0156           % Key text:
0157             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-24*(ii+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0158           % Key value:
0159             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',paramkeys{ii},'FontSize',enlargedFont+8,'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0160             if ~noParamsReq && ~addedPar
0161                 set(objName{ii,2},'Visible','off');
0162                 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20]);
0163             end
0164 
0165           % Val text:
0166             objName{ii,4} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-24*(ii+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0167           % Val value:
0168             data = mat2str(paramvals{ii});
0169             objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 200 20],'String',data,'Fontsize',enlargedFont+9,'Visible','on','Enable','off','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0170             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',[],'Callback',@fromSimulinkCallback,'Style','checkbox');
0171           % Val button to expand the edit field:
0172             objName{ii,8} =   uicontrol('UserData',objName{ii,5},'TooltipString','Expand the edit field','Parent',currPanel,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','left','Position',[455 panelDimens(4)+3-24*(ii+1+currGap) 13 13],'Visible','on','Callback',@ExpandEdit,'Style','pushbutton');
0173             
0174           % Enable parameters from Simulink:
0175             if strcmp(paramvals{ii},'-->')
0176                 set(objName{ii,4},'Visible','off');
0177                 set(objName{ii,5},'Visible','off');
0178                 set(objName{ii,6},'Value',1);
0179                 set(objName{ii,8},'Visible','off');
0180             end
0181 
0182       % ==========================================================================
0183         case {'char'}
0184       % ==========================================================================
0185           % Key text:
0186             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-24*(ii+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0187           % Key value:
0188             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',paramkeys{ii},'FontSize',enlargedFont+8,'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0189             if ~noParamsReq && ~addedPar
0190                 set(objName{ii,2},'Visible','off');
0191                 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20]);
0192             end
0193 
0194           % Val text:
0195             objName{ii,4} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-24*(ii+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0196           % Val value:
0197             objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 200 20],'String',['''',paramvals{ii},''''],'Fontsize',enlargedFont+9,'Visible','on','Enable','off','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0198             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',[],'Callback',@fromSimulinkCallback,'Style','checkbox');
0199           % Val button to expand the edit field:
0200             objName{ii,8} =   uicontrol('UserData',objName{ii,5},'TooltipString','Expand the edit field','Parent',currPanel,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','left','Position',[455 panelDimens(4)+3-24*(ii+1+currGap) 13 13],'Visible','on','Callback',@ExpandEdit,'Style','pushbutton');
0201             
0202           % Browse button:
0203             if strcmpi(paramkeys{ii},'filename')
0204                 objName{ii,7} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[560 panelDimens(4)-24*(ii+1+currGap) 90 20],'String','Browse','Visible','on','Enable','off','UserData',objName{ii,5},'Callback',@browseCallback,'Style','pushbutton');
0205                 set(objName{ii,5},'Position',[250 panelDimens(4)-24*(ii+1+currGap) 300 20]);
0206                 set(objName{ii,6},'Position',[670 panelDimens(4)-24*(ii+1+currGap) 120 20]);
0207                 delete(objName{ii,8});
0208             end
0209 
0210             % Enable parameters from Simulink:
0211             if strcmp(paramvals{ii},'-->')
0212                 set(objName{ii,4},'Visible','off');
0213                 set(objName{ii,5},'Visible','off');
0214                 set(objName{ii,7},'Visible','off');
0215                 set(objName{ii,8},'Visible','off');
0216                 set(objName{ii,6},'Value',1);
0217             end
0218 
0219       % ==========================================================================
0220         case 'specwin'
0221       % ==========================================================================
0222             selectWind      = paramvals{ii}.name;
0223             listWindows         = ['Kaiser',specwin('Types')];
0224             selectWindValue = strmatch(selectWind,listWindows,'exact');
0225           % Window text:
0226             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-24*(ii+1+currGap)-5 50 20],'String','Window:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0227           % Window type popup:
0228             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[100 panelDimens(4)-24*(ii+1+currGap) 80 20],'String',listWindows,'TooltipString','Window names','Value',selectWindValue,'Visible','on','Enable','off','Tag',paramkeys{ii},'UserData',ii,'Callback', @WindListCallback,'Style','popupmenu');
0229           % Length text:
0230             objName{ii,4} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-24*(ii+1+currGap)-5 50 20],'String','Length:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0231           % Length value:
0232             currLength = num2str(length(params.params(ii).val.win));
0233             objName{ii,5} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currLength),'TooltipString','Window Length','Visible','on','Enable','off','UserData',ii,'Callback', @WindlengthCallback,'Style','edit');
0234             if strcmp(selectWind,'Kaiser')
0235              % PSL text if Kaiser:
0236                objName{ii,6} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[320 panelDimens(4)-24*(ii+1+currGap)-5 50 20],'String','PSL:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0237              % PSL value if Kaiser:
0238                currPSL = params.params(ii).val.psll;
0239                objName{ii,7} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[350 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currPSL),'TooltipString','Peak Sidelobe','Visible','on','Enable','off','UserData',ii,'Callback',@WindPSLCallback,'Style','edit');
0240             end
0241           % Simulink checkbox:
0242             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0243 
0244       % ==========================================================================
0245         case 'pzmodel'
0246       % ==========================================================================
0247           % Simulink checkbox:
0248             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0249 
0250             clear pzObj currPoles poleFreqs poleQs poleFQs currZeros zeroFreqs zeroQs zeroFQs
0251             pzObj = params.params(ii).val;
0252             currPoles = pzObj.poles;
0253             currZeros = pzObj.zeros;
0254           % Load button:
0255             objName{ii,2} =   uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[50 panelDimens(4)-24*(ii+1+currGap) 50 20],'String','Load','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@pzmodelLoad,'enable','off','Style','pushbutton');
0256           % Gain text:
0257             objName{ii,3} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[120 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Gain:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0258           % Gain value:
0259             currGain = pzObj.gain;
0260             objName{ii,4} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[155 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currGain),'Visible','on','Enable','off','UserData',ii,'Callback',@pzmodelGainEdit,'Style','edit');
0261           % Poles text:
0262             objName{ii,5} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[240 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Poles:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0263           % Poles value:
0264             for kk=1:numel(currPoles)
0265                 poleFreqs(kk,1) = get(currPoles(kk),'f');
0266                 poleQs(kk,1)    = get(currPoles(kk),'q');
0267                 if ~isnan(poleQs(kk,1))
0268                     poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0269                 else
0270                     poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0271                 end
0272             end
0273             if numel(currPoles)>1 || numel(currZeros)>1
0274                 currGap=currGap+1;
0275             end
0276             if isempty(currPoles)
0277                 poleFQs = '';
0278             else
0279                 poleFQs=char(poleFQs);
0280             end
0281             objName{ii,6} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[275 panelDimens(4)-24*(ii-1+currGap)-47 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',poleFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','off','UserData',ii,'Callback',@pzmodelPoleEdit,'Style','edit');
0282           % Zeros text:
0283             objName{ii,7} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[355 panelDimens(4)-24*(ii+currGap)-7 40 20],'String','Zeros:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0284           % Zeros value:
0285             for kk=1:numel(currZeros)
0286                 zeroFreqs(kk,1) = get(currZeros(kk),'f');
0287                 zeroQs(kk,1)    = get(currZeros(kk),'q');
0288                 if ~isnan(zeroQs(kk,1))
0289                     zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0290                 else
0291                     zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
0292                 end
0293             end
0294             if isempty(currZeros)
0295                 zeroFQs = '';
0296             else
0297                 zeroFQs = char(zeroFQs);
0298             end
0299             objName{ii,8} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[390 panelDimens(4)-24*(ii-1+currGap)-47 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',zeroFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','off','UserData',ii,'Callback',@pzmodelZeroEdit,'Style','edit');
0300 
0301       % ==========================================================================
0302         case 'miir'
0303       % ==========================================================================
0304           % Simulink checkbox:
0305             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[680 panelDimens(4)-24*(ii+1+currGap) 80 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0306 
0307             miirObj = params.params(ii).val;
0308             miirPlist = miirObj.plist;
0309             try 
0310                 currMiirType = find(miirPlist,'type');
0311                 currMiirType = strmatch(currMiirType,{'highpass','lowpass','bandpass','bandreject','pzmodel'});
0312             catch
0313                 currMiirType = 5;
0314             end
0315           % (Miir) Load button:
0316             objName{ii,2} =   uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[50 panelDimens(4)-24*(ii+1+currGap) 50 20],'String','Load','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@miirLoad,'Style','pushbutton');
0317           % Miir type popup:
0318             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 80 20],'String',{'highpass','lowpass','bandpass','bandreject','pzmodel'},'Value',currMiirType,'TooltipString','Select the type of filter','Visible','on','Enable','on','UserData',ii,'Callback',@miirTypeEdit,'Style','popupmenu');
0319           % Gain text:
0320             objName{ii,4} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[220 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Gain:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0321           % Gain value:
0322             currGain = num2str(find(miirPlist,'gain'));
0323             if isempty(currGain), currGain = 'NA'; end
0324             objName{ii,5} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',currGain,'Visible','on','Enable','on','UserData',ii,'Tag','gain','Callback',@miirEdit,'Style','edit');
0325           % Fs text:
0326             objName{ii,6} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[320 panelDimens(4)-24*(ii+1+currGap)-7 20 20],'String','fs:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0327           % Fs value:
0328             fs = num2str(find(miirPlist,'fs'));
0329             if isempty(fs), fs = 'NA'; end
0330             objName{ii,7} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[340 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',fs,'TooltipString','Sample frequency to design for','Visible','on','Enable','on','UserData',ii,'Tag','fs','Callback',@miirEdit,'Style','edit');
0331           % Order text:
0332             objName{ii,8} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Order:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0333           % Order value:
0334             miirOrder = num2str(find(miirPlist,'order'));
0335             if isempty(miirOrder), miirOrder = 'NA'; end
0336             objName{ii,9} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[440 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',miirOrder,'TooltipString','Order of filter','Visible','on','Enable','on','UserData',ii,'Tag','order','Callback',@miirEdit,'Style','edit');
0337           % Fc text:
0338             objName{ii,10} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap)-7 20 20],'String','fc:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0339           % Fc value:
0340             miirFc = find(miirPlist,'fc');
0341             if numel(miirFc)>1, miirFc = strcat(num2str(miirFc(1)),',',num2str(miirFc(2)));
0342             else miirFc = num2str(miirFc);
0343             end
0344             if isempty(miirFc), miirFc = 'NA'; end
0345             objName{ii,11} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[520 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',miirFc,'TooltipString','Corner frequencies: a two element vector for bandpass and bandreject filters (cannot be >fs/2)','Visible','on','Enable','on','UserData',ii,'Tag','fc','Callback',@miirEdit,'Style','edit');
0346           % Ripple text:
0347             objName{ii,12} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[580 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Ripple:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0348             miirRipple = find(miirPlist,'ripple');
0349           % Ripple value:
0350             if isempty(miirRipple), miirRipple = 'NA'; end
0351             objName{ii,13} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[620 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',num2str(miirRipple),'TooltipString','Specify pass/stop-band ripple for bandpass and bandreject filters','Visible','on','Enable','on','UserData',ii,'Tag','ripple','Callback',@miirEdit,'Style','edit');
0352           % ========================================
0353           % HERE BEGINS THE PZMODEL UNDER MIIR PARAM
0354             if currMiirType == 5
0355                 currGap=currGap+1;
0356 
0357                 clear pzObj currPoles poleFreqs poleQs poleFQs currZeros zeroFreqs zeroQs zeroFQs
0358                 pzObj = find(miirPlist,'pzmodel');
0359                 currPoles = get(pzObj,'poles');
0360                 currZeros = get(pzObj,'zeros');
0361               % (Pzmodel) Load button:
0362                 objName{ii,14} =   uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[130 panelDimens(4)-24*(ii+1+currGap) 50 20],'String','Load','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@pzmodelLoad,'Style','pushbutton');
0363               % Gain text:
0364                 objName{ii,15} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[190 panelDimens(4)-24*(ii+1+currGap)-2 40 20],'String','Gain:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0365               % Gain value:
0366                 currGain = pzObj.gain;
0367                 objName{ii,14} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[225 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currGain),'Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelGainEdit,'Style','edit');
0368               % Poles text:
0369                 objName{ii,15} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[300 panelDimens(4)-24*(ii+1+currGap)-2 40 20],'String','Poles:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0370               % Zeros text:
0371                 objName{ii,6} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[410 panelDimens(4)-24*(ii+1+currGap)-2 40 20],'String','Zeros:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0372               % Poles value:
0373                 for kk=1:numel(currPoles)
0374                     poleFreqs(kk,1) = get(currPoles(kk),'f');
0375                     poleQs(kk,1)    = get(currPoles(kk),'q');
0376                     if ~isnan(poleQs(kk,1)), poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0377                     else poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0378                     end
0379                 end
0380                 if numel(currPoles)>1 || numel(currZeros)>1, currGap=currGap+1; end
0381                 if isempty(currPoles)
0382                     poleFQs = '';
0383                 else
0384                     poleFQs=char(poleFQs);
0385                 end
0386                 objName{ii,5} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[335 panelDimens(4)-24*(ii+1+currGap) 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',poleFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelPoleEdit,'Style','edit');
0387               % Zeros value:
0388                 for kk=1:numel(currZeros)
0389                     zeroFreqs(kk,1) = get(currZeros(kk),'f');
0390                     zeroQs(kk,1)    = get(currZeros(kk),'q');
0391                     if ~isnan(zeroQs(kk,1)), zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0392                     else zeroFQs{kk,1}=num2str(zeroFreqs(kk,1)); end
0393                 end
0394                 if isempty(currZeros)
0395                     zeroFQs = '';
0396                 else
0397                     zeroFQs = char(zeroFQs);
0398                 end
0399                 objName{ii,7} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[445 panelDimens(4)-24*(ii+1+currGap) 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',zeroFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelZeroEdit,'Style','edit');
0400                 currGap=currGap+2;
0401                 % ===========================================================================================
0402             end % of pzmodel in the miir object
0403                 
0404       % ==========================================================================
0405         case 'pole'
0406       % ==========================================================================
0407             currPoles = params.params(ii).val;
0408             for kk=1:numel(currPoles)
0409                 poleFreqs(kk,1) = currPoles(kk).f;
0410                 poleQs(kk,1)    = currPoles(kk).q;
0411                 if ~isnan(poleQs(kk,1))
0412                     poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0413                 else
0414                     poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0415                 end
0416             end
0417             poleFQs=char(poleFQs);
0418           % Poles text:
0419             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[90 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','POLES','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Enable','off','Style','text');
0420             if numel(currPoles)>1
0421                 currGap=currGap+1;
0422             end
0423           % Poles value:
0424             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii-1+currGap)-47 100 20+(numel(currPoles)>1)*20],'String',poleFQs,'Max',2,'TooltipString','Insert ''freq'' or ''freq,q''','Visible','on','Enable','on','UserData',ii,'Callback',@poleEdit,'Style','edit');
0425                 
0426           % Simulink checkbox:
0427             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0428       
0429       % ==========================================================================
0430         case 'zero'
0431       % ==========================================================================
0432             currZeros = params.params(ii).val;
0433             for kk=1:numel(currZeros)
0434                 zeroFreqs(kk,1) = get(currZeros(kk),'f');
0435                 zeroQs(kk,1)    = get(currZeros(kk),'q');
0436                 if ~isnan(zeroQs(kk,1))
0437                     zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0438                 else
0439                     zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
0440                 end
0441             end
0442             zeroFQs=char(zeroFQs);
0443           % Zeros text:
0444             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[90 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','ZEROS','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Enable','off','Style','text');
0445             if numel(currZeros)>1
0446                 currGap=currGap+1;
0447             end
0448           % Zeros value:
0449             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii-1+currGap)-47 100 20+(numel(currZeros)>1)*20],'String',zeroFQs,'Max',2,'TooltipString','Insert ''freq'' or ''freq,q''','Visible','on','Enable','on','UserData',ii,'Callback',@zeroEdit,'Style','edit');
0450                 
0451           % Simulink checkbox:
0452             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0453       
0454       % ==========================================================================
0455         case 'cell'
0456       % ==========================================================================
0457             if isa(paramvals{ii}{1},'char') && strcmp(paramvals{ii}{1},'-->')
0458               % Key value:
0459                 objName{ii,3} =  uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20],'String',paramkeys{ii},'Visible','on','Enable','on','UserData',ii,'Callback',@editNameCallback,'Style','text');
0460               % Text: from Simulink environment:
0461                 objName{ii,4} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[230 panelDimens(4)-6-24*(ii+1+currGap) 200 20],'String','From Simulink environment','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0462                 fromSimulink = 1;
0463             else
0464               % Key text:
0465                 objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-24*(ii+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0466               % Key value:
0467                 objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0468                 if ~noParamsReq && ~addedPar
0469                     set(objName{ii,2},'Visible','off');
0470                     set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20]);
0471                 end
0472 
0473               % Val text:
0474                 objName{ii,4} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-24*(ii+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0475               % Val value:
0476                 data = cell2str(paramvals{ii});
0477                 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 130 20],'String',data,'Visible','on','Enable','on','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0478                 fromSimulink = 0;
0479             end
0480                 
0481           % Simulink checkbox:
0482             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',fromSimulink,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0483             
0484 
0485       % ==========================================================================
0486         otherwise % Other types of param?
0487       % ==========================================================================
0488           % Key value:
0489             objName{ii,3} =  uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20],'String',paramkeys{ii},'FontSize',enlargedFont+8,'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','text');
0490           % Text: input not supported. Please construct by proper block.
0491             objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[310 panelDimens(4)-4-24*(ii+1+currGap) 200 20],'String','Unsupported yet','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Visible','on','Style','text');
0492             fromSimulink = 0;
0493             
0494           % Simulink checkbox:
0495             objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',enlargedFont+8,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap) 120 20],'Max',1,'Min',0,'Value',fromSimulink,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0496             
0497   % ==============================================================================
0498     end % of SWITCH the param type
0499   % Cycle to activate enabled params:
0500     if paramEnabled(ii) || noParamsReq==1
0501         [xx,yy]       = size(objName);
0502         jj=2;
0503         while jj<=yy && ~isempty(objName{ii,jj})
0504             try set(objName{ii,jj},'Enable','on'); set(objName{ii,jj},'ForegroundColor',[0 0 0]); catch end
0505             jj=jj+1;
0506         end
0507     end
0508     
0509 end % of cycle among params
0510 
0511    % ==============================================================================
0512    % Button to add user-defined params:
0513       paramTypes      = {'double/char','specwin','pole','zero','pzmodel','miir','-->'};
0514       for kk=1:y, paramTypes(strmatch(class(params.params(kk).val),paramTypes,'exact'))=[]; end
0515     % ParamType popup
0516       hparamType = uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-40-24*(y+1+totalGaps) 80 20],'String',paramTypes,'Value',1,'Visible','on','Enable','on','Style','popupmenu');
0517     % Add params button
0518       uicontrol('Parent',currPanel,'Units','pixels','Position',[110 panelDimens(4)-40-24*(y+1+totalGaps) 20 20],'String','+','Visible','on','Enable','on','Callback', @AddParamCallback,'UserData',hparamType,'Style','pushbutton');
0519 
0520 
0521     end % of buildplistFigureParam function
0522     %----------------------------------------------------------------------
0523 
0524 %%
0525 % =========================================================================
0526 % =========================================================================
0527 % =========================================================================
0528     %----------------------------------------------------------------------
0529     function ContinuousParamCheck(varargin)   
0530   % This is the function to execute a continuous check on the status
0531   % of the current selection (system and block).
0532   
0533          if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0534        % it's selected a ltpda simulink analysis diagram.
0535        % In this case do the block selection check.
0536 
0537          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0538          consistent=1;
0539          
0540          if ~isempty(selBlocks) && isempty(gcbsh)
0541              delete(findobj(gcf,'Parent',currPanel))
0542              selBlocks = [];
0543              return
0544          end
0545         
0546          if ((length(selBlocks)==1 && selBlocks~=gcbh) || length(selBlocks)~=length(gcbsh)) && ~isempty(gcbsh)
0547                 selBlocks = gcbsh;
0548                 for i=1:length(selBlocks)
0549                     set_param(selBlocks(i),'LinkStatus','inactive');
0550                     currentTags{i}=get_param(selBlocks(i),'Tag');
0551                 end
0552                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0553                 if length(gcbsh)>1 % then the user has selected multiple blocks
0554                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0555                   % Check for consistency
0556                   % Check to verify that all blocks are alike (eg, not Input and
0557                   % Function blocks together)
0558                     for i=1:length(selBlocks)
0559                         if ~strcmp(currentTags{i},currentTags{1})
0560                             ErrorSelectionInconsistent();
0561                             consistent=0;
0562                             break
0563                         end
0564                     end
0565                   % If function blocks, they must recall the same function:
0566                     if strcmp(currentTags{1},'function')
0567                         for i=1:length(selBlocks)
0568                             childpath = find_system(selBlocks(i),'LookUnderMasks','all','BlockType','M-S-Function');
0569                             functionname{i}=get_param(childpath,'Tag');
0570                             if ~strcmp(functionname{i},functionname{1}) % different functions, inconsistent selection
0571                                 ErrorSelectionInconsistent();
0572                                 consistent=0;
0573                             end
0574                         end
0575                     end
0576                 end
0577                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0578 
0579         % Check if this block has parameters to set:
0580         if consistent
0581             delete(findobj(gcf,'Parent',currPanel))
0582             switch strtok(get(gcbh,'Tag'))
0583               % =========================================================
0584                 case 'input'
0585                     LoadInputParamCallback();
0586 
0587               %=========================================================
0588                 case {'mux','demux'}
0589                     LoadMuxParamCallback();
0590 
0591               %=========================================================
0592                 case {'function','freepl','method'}
0593                     buildplistFigureParam()
0594 
0595               %=========================================================
0596                 case 'from'
0597                     LoadFromBlockCallback();
0598 
0599               %=========================================================
0600             end % of switch
0601         end % of if consistent
0602 
0603         end % end of  blocks selection
0604         end   % end of system selection check
0605         
0606     end
0607     %----------------------------------------------------------------------
0608 
0609 %% ======================== Double functions ==============================
0610 %  ========================================================================
0611     %----------------------------------------------------------------------
0612     function editNameCallback(hObject, varargin)   
0613          currParamIndex = get(hObject,'UserData');
0614          newName  = get(hObject,'String');
0615          oldName  = params.params(currParamIndex).key;
0616          addedPar = 0;
0617          try %#ok<ALIGN>
0618          if strcmpi(oldName(1:7),'addPar_'), addedPar = 1; oldName(1:7)=[]; end
0619          catch end
0620          
0621          if strcmp(params.params(currParamIndex).val,'-->')
0622              block2change = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(oldName));
0623              while ~isempty(find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(newName)))
0624                  newName = [newName,'x'];
0625              end
0626              set_param(block2change{1},'Name',lower(newName))
0627          end
0628 
0629          if addedPar, newName = ['addPar_',newName]; end
0630          params.params(currParamIndex).key = newName;
0631 
0632          if strcmp(params.params(currParamIndex).val,'-->'), UpdateInports(lower(newName),2); end
0633          
0634          paramcommand = BuildParamCommand(params);
0635          for kk=1:length(selBlocks)
0636              set_param(selBlocks(kk),'Description',paramcommand);
0637          end
0638          AnnotationUpdate(params);
0639          buildplistFigureParam()
0640     end
0641     %----------------------------------------------------------------------
0642     %----------------------------------------------------------------------
0643     function editValueCallback(hObject, varargin) 
0644         
0645         expandedEdit = 0;
0646         if numel(get(hObject,'UserData'))>1
0647             hObject = get(hObject,'UserData');
0648             orighObject = hObject(2);
0649             hObject = hObject(1);
0650             expandedEdit = 1;
0651         else
0652             orighObject = hObject;
0653         end
0654         currParamIndex = get(hObject,'UserData');
0655         newValue = get(hObject,'String');
0656          
0657         if isempty(newValue)
0658             set(orighObject,'String',num2str(params.params(currParamIndex).val));
0659             return
0660         end
0661         if strcmp(newValue(1),''''),
0662             paramType = 'char';
0663             newValue(1) = []; newValue(numel(newValue)) = [];
0664             for j = numel(newValue)-1:-1:2
0665                 if strcmp(newValue(j),'''') && (~strcmp(newValue(j-1),'''') && ~strcmp(newValue(j+1),''''))
0666                     newValue = [newValue(1:j),'''',newValue(j+1:numel(newValue))];
0667                 end
0668             end
0669         elseif ~strcmp(newValue(1),'{'),
0670             paramType = 'double';
0671         else
0672             paramType = 'double';
0673         end
0674         
0675         switch paramType
0676             case 'double'
0677                 try
0678                     newValue = eval(newValue);
0679                     if isnumeric(newValue)
0680                         set(orighObject,'String',mat2str(newValue))
0681                     else
0682                         params = pset(params,params.params(currParamIndex).key,newValue);
0683                         paramcommand = BuildParamCommand(params);
0684                         for kk=1:length(selBlocks)
0685                             set_param(selBlocks(kk),'Description',paramcommand);
0686                         end
0687                         AnnotationUpdate(params);
0688                         buildplistFigureParam()
0689                         return
0690                     end
0691                 catch
0692                     oldValue = params.params(currParamIndex).val;
0693                     if ~isa(oldValue,'char'), mat2str(oldValue); end
0694                     set(orighObject,'String',oldValue)
0695                     return
0696                 end
0697         end
0698         
0699         if expandedEdit, paramEnabled(currParamIndex) = 1; end
0700         params = pset(params,params.params(currParamIndex).key,newValue);
0701         paramcommand = BuildParamCommand(params);
0702         for kk=1:length(selBlocks)
0703             set_param(selBlocks(kk),'Description',paramcommand);
0704         end
0705         AnnotationUpdate(params);
0706         if expandedEdit, buildplistFigureParam(); end
0707       % buildplistFigureParam()
0708     end
0709     %----------------------------------------------------------------------
0710     %----------------------------------------------------------------------
0711     function browseCallback(hObject, varargin)
0712         
0713         [meth,clas] = strtok(get_param(gcbh,'Tag'),' ');
0714         categ = 'none';
0715         if strcmp(meth,'method')
0716             clas = strtrim(clas);
0717             funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
0718             func = get_param(funcBlock{1},'Tag');
0719             categ = eval([func,'(',clas,',''Category'')']);
0720         end
0721 
0722         if strcmp(categ,'Output')
0723             [fileName,filePath] = uiputfile('*.*','Choose destination file');
0724         else
0725             [fileName,filePath] = uigetfile('*.*','Choose source file');
0726         end
0727         
0728         if fileName==0
0729             return
0730         else
0731             [file , ext] = strtok(fileName,'.');
0732             if strcmp(ext,'.*'), fileName(numel(fileName))=[]; fileName=[fileName,'dat']; end
0733             fileName = [filePath,fileName];
0734         end
0735         editFieldHandle = get(hObject,'UserData');
0736         set(editFieldHandle,'String',fileName);
0737 
0738         newValue = fileName;
0739         params = pset(params,'FILENAME',newValue);
0740         paramcommand = BuildParamCommand(params);
0741         for kk=1:length(selBlocks)
0742             set_param(selBlocks(kk),'Description',paramcommand);
0743         end
0744         AnnotationUpdate(params);
0745       % buildplistFigureParam()
0746          
0747     end
0748     %----------------------------------------------------------------------
0749 %% ======================= Specwin functions ==============================
0750 %  ========================================================================
0751     %----------------------------------------------------------------------
0752     function WindListCallback(hObject, varargin)   
0753         currParamID   = get(hObject,'UserData');
0754         currWindValue = get(hObject,'Value');
0755         listWindows   = ['Kaiser',specwin('Types')];
0756         currWindow    = listWindows{currWindValue};
0757         oldWindObj    = params.params(currParamID);
0758         oldWindow     = oldWindObj.name;
0759         if strcmp(currWindow,oldWindow)
0760             return;
0761         else
0762             currWindLength = str2double(get(objName{currParamID,5},'String'));
0763             if strcmp(currWindow,'Kaiser')
0764                 currPSL = oldWindObj.val.psll;
0765                 windobj = specwin(eval('currWindow'),currWindLength,currPSL);
0766             else
0767                 windobj = specwin(eval('currWindow'),currWindLength);
0768             end
0769         end
0770 
0771         params=pset(params,'Win',windobj);
0772         
0773         paramcommand = BuildParamCommand(params);
0774         for kk=1:length(selBlocks)
0775             set_param(selBlocks(kk),'Description',paramcommand);
0776         end
0777         AnnotationUpdate(params);
0778         delete(findobj(gcf,'Parent',currPanel))
0779         buildplistFigureParam()
0780 
0781     end
0782     %----------------------------------------------------------------------
0783     %----------------------------------------------------------------------
0784     function WindlengthCallback(hObject,varargin)   
0785     % Callback function: run when the user change the value in the Length
0786     % editable field for a specwin object
0787     
0788          currParamID   = get(hObject,'UserData');
0789          selectedWind=get(objName{currParamID,3},'Value');
0790        % Retrieve the name of the Window associated to that index:
0791          listWindows=specwin('Types');
0792          listWindows={'Kaiser',listWindows{:}};
0793          selectedWind=listWindows{selectedWind};
0794 
0795          currWindLength=str2double(get(hObject,'String'));
0796          
0797          if strcmp(selectedWind,'Kaiser')
0798              currPSL=str2double(get(objName{currParamID,7},'String'));
0799              windobj=specwin(eval('selectedWind'),currWindLength,currPSL);
0800          else
0801              windobj=specwin(eval('selectedWind'),currWindLength);
0802          end
0803          
0804          params=pset(params,'Win',windobj);
0805 
0806          paramcommand = BuildParamCommand(params);
0807          for kk=1:length(selBlocks)
0808              set_param(selBlocks(kk),'Description',paramcommand);
0809          end
0810 
0811          AnnotationUpdate(params);
0812 
0813     end
0814     %----------------------------------------------------------------------
0815     %----------------------------------------------------------------------
0816     function WindPSLCallback(hObject,varargin)   
0817     % Callback function: run when the user change the value in the PSL
0818     % editable field for a specwin object
0819 
0820          currParamID  = get(hObject,'UserData');
0821          selectedWind = get(objName{currParamID,3},'Value');
0822        % Retrieve the name of the Window associated to that index:
0823          listWindows  = specwin('Types');
0824          listWindows  = {'Kaiser',listWindows{:}};
0825          selectedWind = listWindows{selectedWind}; %#ok<NASGU>
0826 
0827          currWindLength = str2double(get(objName{currParamID,5},'String'));
0828          currPSL        = str2double(get(hObject,'String'));
0829 
0830          windobj=specwin(eval('selectedWind'),currWindLength,currPSL);
0831 
0832          params = pset(params,'Win',windobj);
0833 
0834          paramcommand = BuildParamCommand(params);
0835          for kk=1:length(selBlocks)
0836              set_param(selBlocks(kk),'Description',paramcommand);
0837          end
0838 
0839          AnnotationUpdate(params);
0840     end
0841     %----------------------------------------------------------------------
0842 
0843 %% ======================= Pzmodel functions ==============================
0844 %  ========================================================================
0845     %----------------------------------------------------------------------
0846     function pzmodelLoad(hObject, varargin)
0847          currParamIndex = get(hObject,'UserData');
0848          
0849          switch class(params.params(currParamIndex).val)
0850              case 'pzmodel'
0851                  try [FileName,PathName] = uigetfile('*.xml','Select the .XML pzmodel file');
0852                      FileAddress = strcat(PathName,FileName);
0853                      pzObj = pzmodel(FileAddress);
0854                      if isempty(pzObj), return; end
0855                      params = pset(params,params.params(currParamIndex).key,pzObj);
0856                  catch
0857                  end
0858              case 'miir' % the pzmodel param is inside the local plist of a miir object
0859                  miirObj   = params.params(currParamIndex).val;
0860                  miirPlist = miirObj.plist;
0861                  try [FileName,PathName] = uigetfile('*.xml','Select the .XML pzmodel file');
0862                      FileAddress = strcat(PathName,FileName);
0863                      pzObj = pzmodel(FileAddress);
0864                      miirPlist = pset(miirPlist,'pzmodel',pzObj);
0865                      params = pset(params,params.params(currParamIndex).key,miir(miirPlist));
0866                  catch
0867                  end
0868          end
0869 
0870          paramcommand = BuildParamCommand(params);
0871          for kk=1:length(selBlocks)
0872              set_param(selBlocks(kk),'Description',paramcommand);
0873          end
0874          AnnotationUpdate(params);
0875          buildplistFigureParam()
0876     end
0877     %----------------------------------------------------------------------
0878     %----------------------------------------------------------------------
0879     function pzmodelGainEdit(hObject, varargin)
0880          currParamIndex = get(hObject,'UserData');
0881          pzGain         = str2double(get(hObject,'String'));
0882          
0883          switch class(params.params(currParamIndex).val)
0884              case 'pzmodel'
0885                  pzObj          = params.params(currParamIndex);
0886                  pzKey          = pzObj.key;
0887                  pzObj          = pzObj.val;
0888                  poleList       = pzObj.poles;
0889                  zeroList       = pzObj.zeros;
0890                  pzObj      = pzmodel(pzGain,poleList,zeroList);
0891                  params     = pset(params,pzKey,pzObj);
0892 
0893              case 'miir'
0894                  miirObj    = params.params(currParamIndex).val;
0895                  miirKey    = params.params(currParamIndex).key;
0896                  miirPlist  = miirObj.plist;
0897                  pzObj      = find(miirPlist,'pzmodel');
0898                  poleList       = pzObj.poles;
0899                  zeroList       = pzObj.zeros;
0900 
0901                  pzObj = pzmodel(pzGain,poleList,zeroList);
0902                  miirPlist = pset(miirPlist,'pzmodel',pzObj);
0903                  params    = pset(params,miirKey,miir(miirPlist));
0904 
0905          end
0906 
0907        % To check the updated setting:
0908        % params.params(currParamIndex).val
0909          paramcommand = BuildParamCommand(params);
0910          for kk=1:length(selBlocks)
0911              set_param(selBlocks(kk),'Description',paramcommand);
0912          end
0913          AnnotationUpdate(params);
0914          % buildplistFigureParam()
0915     end
0916     %----------------------------------------------------------------------
0917     %----------------------------------------------------------------------
0918     function pzmodelPoleEdit(hObject, varargin)
0919          currParamIndex = get(hObject,'UserData');
0920          poles          = get(hObject,'String');
0921          poles          = readInput(poles,2);
0922          [xx,yy]=size(poles);
0923          poleList=pole();
0924          for kk=1:xx
0925              if (yy>1 && poles(kk,2)==0) || yy==1
0926                  poleList(kk)=pole(poles(kk,1));
0927              else
0928                  poleList(kk)=pole(poles(kk,1),poles(kk,2));
0929              end
0930          end
0931          
0932          switch class(params.params(currParamIndex).val)
0933              case 'pzmodel'
0934                  pzObj     = params.params(currParamIndex);
0935                  pzKey     = pzObj.key;
0936                  pzObj     = pzObj.val;
0937                  pzGain    = pzObj.gain;
0938                  zeroList  = pzObj.zeros;
0939                  pzObj     = pzmodel(pzGain,poleList,zeroList);
0940                  params    = pset(params,pzKey,pzObj);
0941                  
0942              case 'miir'
0943                  miirObj        = params.params(currParamIndex).val;
0944                  miirKey        = params.params(currParamIndex).key;
0945                  miirPlist      = miirObj.plist;
0946                  pzObj          = find(miirPlist,'pzmodel');
0947                  pzGain         = pzObj.gain;
0948                  zeroList       = pzObj.zeros;
0949                  pzObj     = pzmodel(pzGain,poleList,zeroList);
0950                  miirPlist = pset(miirPlist,'pzmodel',pzObj);
0951                  params    = pset(params,miirKey,miir(miirPlist));
0952                  
0953          end
0954          
0955        % To check the updated setting:
0956        % params.params(currParamIndex).val
0957          paramcommand = BuildParamCommand(params);
0958          for kk=1:length(selBlocks)
0959              set_param(selBlocks(kk),'Description',paramcommand);
0960          end
0961          AnnotationUpdate(params);
0962          % buildplistFigureParam()
0963     end
0964     %----------------------------------------------------------------------
0965     %----------------------------------------------------------------------
0966     function pzmodelZeroEdit(hObject, varargin)
0967          currParamIndex = get(hObject,'UserData');
0968          zeros          = get(hObject,'String');
0969          zeros          = readInput(zeros,2);
0970          [xx,yy]  = size(zeros);
0971          zeroList = zero();
0972          for kk=1:xx
0973                  if (yy>1 && zeros(kk,2)==0) || yy==1
0974                      zeroList(kk)=zero(zeros(kk,1));
0975                  else
0976                      zeroList(kk)=zero(zeros(kk,1),zeros(kk,2));
0977                  end
0978          end
0979 
0980          switch class(params.params(currParamIndex).val)
0981              case 'pzmodel'
0982                  pzObj     = params.params(currParamIndex);
0983                  pzKey     = pzObj.key;
0984                  pzObj     = pzObj.val;
0985                  pzGain    = pzObj.gain;
0986                  poleList  = pzObj.poles;
0987                  pzObj     = pzmodel(pzGain,poleList,zeroList);
0988                  params    = pset(params,pzKey,pzObj);
0989                  
0990              case 'miir'
0991                  miirObj        = params.params(currParamIndex).val;
0992                  miirKey        = params.params(currParamIndex).key;
0993                  miirPlist      = miirObj.plist;
0994                  pzObj          = find(miirPlist,'pzmodel');
0995                  pzGain         = pzObj.gain;
0996                  poleList       = pzObj.poles;
0997                  pzObj     = pzmodel(pzGain,poleList,zeroList);
0998                  miirPlist = pset(miirPlist,'pzmodel',pzObj);
0999                  params    = pset(params,miirKey,miir(miirPlist));
1000          end
1001          
1002        % To check the updated setting:
1003        % params.params(currParamIndex).val
1004          paramcommand = BuildParamCommand(params);
1005          for kk=1:length(selBlocks)
1006              set_param(selBlocks(kk),'Description',paramcommand);
1007          end
1008          AnnotationUpdate(params);
1009          % buildplistFigureParam()
1010     end
1011     %----------------------------------------------------------------------
1012 
1013 %% ========================== Miir functions ==============================
1014 %  ========================================================================
1015     %----------------------------------------------------------------------
1016     function miirLoad(hObject, varargin)
1017          currParamIndex = get(hObject,'UserData');
1018          try [FileName,PathName] = uigetfile({'*.xml';'*.fil';'*.filt'},'Select the .XML pzmodel file');
1019              FileAddress = strcat(PathName,FileName);
1020              miirObj     = miir(FileAddress);
1021              if isempty(miirObj), return; end
1022              params = pset(params,params.params(currParamIndex).key,miirObj);
1023          catch
1024          end
1025        
1026          buildplistFigureParam()
1027     end
1028     %----------------------------------------------------------------------
1029     %----------------------------------------------------------------------
1030     function miirTypeEdit(hObject, varargin)
1031          currParamIndex = get(hObject,'UserData');
1032          miirObj     = params.params(currParamIndex).val;
1033          miirPlist   = miirObj.plist;
1034          paramList   = {'type','gain','fs','order','fc','ripple'};
1035          miirTypes   = get(hObject,'String');
1036            currMiirType = miirTypes{get(hObject,'Value')};
1037            prevMiirType = find(miirPlist,'type');
1038             if isempty(prevMiirType), prevMiirType='pzmodel'; end
1039          
1040          miirPL      = plist();
1041          if strcmp(currMiirType,'pzmodel')
1042              pzObj = pzmodel(1,[pole(10,2),pole(100)],zero(1));
1043              miirPL  = append(miirPL, param('pzmodel', pzObj ));
1044              miirPL  = append(miirPL, param('fs', 1 ));
1045          else
1046              miirPL  = append(miirPL, param('type', currMiirType ));
1047              for ii=2:6
1048                  miirVals{ii} = find(miirPlist,paramList{ii});
1049                  if isempty(miirVals{ii}) && ii==6
1050                      miirVals{ii} = 0.5;
1051                  elseif isempty(miirVals{ii})
1052                      miirVals{ii} = 1;
1053                  end
1054                  if ii==5
1055                      if (strmatch(prevMiirType,miirTypes)<3 || strmatch(prevMiirType,miirTypes)==5) && (strmatch(currMiirType,miirTypes)==3 || strmatch(currMiirType,miirTypes)==4)
1056                          miirVals{5}=[0.1,0.3];
1057                      elseif (strmatch(prevMiirType,miirTypes)==3 || strmatch(prevMiirType,miirTypes)==4) && (strmatch(currMiirType,miirTypes)<3 || strmatch(currMiirType,miirTypes)==5)
1058                          miirVals{5}=0.25;
1059                      elseif strmatch(prevMiirType,miirTypes)==5 && strmatch(currMiirType,miirTypes)<3
1060                          miirVals{5}=0.25;
1061                      end
1062                  end
1063                  miirPL = append(miirPL, param(paramList{ii}, miirVals{ii} ));
1064              end
1065          end
1066          params = pset(params,params.params(currParamIndex).key,miir(miirPL));
1067          
1068        % To check the updated setting:
1069        % params.params(currParamIndex).val
1070          paramcommand = BuildParamCommand(params);
1071          for kk=1:length(selBlocks)
1072              set_param(selBlocks(kk),'Description',paramcommand);
1073          end
1074          AnnotationUpdate(params);
1075          buildplistFigureParam()
1076     end
1077     %----------------------------------------------------------------------
1078     %----------------------------------------------------------------------
1079     function miirEdit(hObject, varargin)
1080          currParamIndex = get(hObject,'UserData');
1081          miirObj     = params.params(currParamIndex).val;
1082          miirKey     = params.params(currParamIndex).key;
1083          miirPlist   = miirObj.plist;
1084        % paramList   = {'type','gain','fs','order','fc','ripple'};
1085          propName    = get(hObject,'Tag');
1086          
1087        % oldValue    = find(miirPlist,propName);
1088          newValue    = str2num(get(hObject,'String'));
1089          
1090        % Check for consistency
1091          if (isempty(newValue) || strcmp(newValue,'-') || strcmp(newValue,'NA')) && isempty(find(miirPlist,'type'))
1092              newMiirPlist = plist();
1093              for zz=1:nparams(miirPlist)
1094                  if ~strcmp(miirPlist.params(zz).key,propName)
1095                      newMiirPlist = append(newMiirPlist,miirPlist.params(zz));
1096                  end
1097              end
1098              miirPlist = newMiirPlist;
1099              params = pset(params, miirObj.name , miir(miirPlist));
1100              paramcommand = BuildParamCommand(params);
1101              for kk=1:length(selBlocks)
1102                  set_param(selBlocks(kk),'Description',paramcommand);
1103              end
1104              AnnotationUpdate(params);
1105              return
1106              
1107          elseif (isempty(newValue) || strcmp(newValue,'-') || strcmp(newValue,'NA')) && ~isempty(find(miirPlist,'type'))
1108              set(hObject,'String',num2str(find(miirPlist,propName)));
1109              return
1110          end
1111          
1112          fs = find(miirPlist,'fs');
1113          fc = find(miirPlist,'fc');
1114          if strcmp(propName,'fc') && numel(newValue)>2
1115              newValue = newValue(1:2);
1116          end
1117          if strcmp(propName,'fc') && numel(newValue)>2 && newValue(1)>newValue(2)
1118              newValue = fliplr(newValue);
1119          end
1120          if strcmp(propName,'fc') && numel(newValue)==1
1121              if newValue>=fs/2
1122                  newValue = fs/2-fs/200;
1123              end
1124          elseif strcmp(propName,'fc') && numel(newValue)==2
1125              if max(newValue)>=fs/2
1126                  if min(newValue)>=fs/2
1127                      newValue = [fs/4 fs/2-fs/200];
1128                  else
1129                      newValue = [min(newValue) fs/2-fs/200];
1130                  end
1131              end
1132 
1133          elseif strcmp(propName,'fs') && numel(fc)==1
1134              if newValue<=fc*2
1135                  miirPlist = set(miirPlist,'fc',newValue/2-newValue/20);
1136              end
1137          elseif strcmp(propName,'fs') && numel(fc)==2
1138              if newValue<=max(fc)*2
1139                  if newValue<=min(fc)
1140                      miirPlist = set(miirPlist,'fc',[newValue/4 newValue/2-newValue/20]);
1141                  else
1142                      miirPlist = set(miirPlist,'fc',[min(fc) newValue/2-newValue/20]);
1143                  end
1144              end
1145 
1146          elseif strcmp (propName,'order')
1147              newValue = ceil(newValue);
1148          end
1149          
1150          miirPlist = pset(miirPlist,propName,newValue);
1151          params    = pset(params,miirKey,miir(miirPlist));
1152 
1153        % To check the updated setting:
1154        % params.params(currParamIndex).val
1155          paramcommand = BuildParamCommand(params);
1156          for kk=1:length(selBlocks)
1157              set_param(selBlocks(kk),'Description',paramcommand);
1158          end
1159          AnnotationUpdate(params);
1160        % buildplistFigureParam()
1161     end
1162     %----------------------------------------------------------------------
1163 
1164 %% ========================== Pole functions ==============================
1165 %  ========================================================================
1166     %----------------------------------------------------------------------
1167     function poleEdit(hObject, varargin)
1168         currParamIndex = get(hObject,'UserData');
1169         poles           = get(hObject,'String');
1170         poles          = readInput(poles,2);
1171         [xx,yy]  = size(poles);
1172         poleList = pole();
1173         for kk=1:xx
1174             if (yy>1 && poles(kk,2)==0) || yy==1
1175                 poleList(kk)=pole(poles(kk,1));
1176             else
1177                 poleList(kk)=pole(poles(kk,1),poles(kk,2));
1178             end
1179         end
1180         params = pset(params,params.params(currParamIndex).key,poleList);
1181 
1182         paramcommand = BuildParamCommand(params);
1183         for kk=1:length(selBlocks)
1184             set_param(selBlocks(kk),'Description',paramcommand);
1185         end
1186         AnnotationUpdate(params);
1187         buildplistFigureParam()
1188     end
1189     %----------------------------------------------------------------------
1190     
1191 %% ========================== Zero functions ==============================
1192 %  ========================================================================
1193     %----------------------------------------------------------------------
1194     function zeroEdit(hObject, varargin)
1195         currParamIndex = get(hObject,'UserData');
1196         zeros           = get(hObject,'String');
1197         zeros          = readInput(zeros,2);
1198         [xx,yy]  = size(zeros);
1199         zeroList = zero();
1200         for kk=1:xx
1201             if (yy>1 && zeros(kk,2)==0) || yy==1
1202                 zeroList(kk)=zero(zeros(kk,1));
1203             else
1204                 zeroList(kk)=zero(zeros(kk,1),zeros(kk,2));
1205             end
1206         end
1207         params = pset(params,params.params(currParamIndex).key,zeroList);
1208 
1209         paramcommand = BuildParamCommand(params);
1210         for kk=1:length(selBlocks)
1211             set_param(selBlocks(kk),'Description',paramcommand);
1212         end
1213         AnnotationUpdate(params);
1214         buildplistFigureParam()
1215     end
1216     %----------------------------------------------------------------------
1217     
1218 % =========================================================================
1219 %% Add/Remove params, From Simulink, UpdateInports
1220     %----------------------------------------------------------------------
1221     function AddParamCallback(hObject,varargin)
1222         
1223         hparamType = get(hObject,'UserData');
1224         paramTypes = get(hparamType,'String');
1225         paramType = paramTypes{get(hparamType,'Value')};
1226         
1227         switch paramType
1228             case {'double','double/char'}
1229                 key = 'addPar_name';
1230                 while ~isempty(find(params,key))
1231                     key =[key,'x'];
1232                 end
1233                 params = append(params, param(key,1));
1234             case 'specwin'
1235                 newParam = param('addPar_Win',specwin('Kaiser',1000,200));
1236                 params = append(params, newParam);
1237             case 'pzmodel'
1238                 pzObj = pzmodel(1,[pole(10,2),pole(100)],zero(1));
1239                 newParam = param('addPar_pzmodel',pzObj);
1240                 params = append(params, newParam);
1241             case 'miir'
1242                 pl = plist();
1243                 pl = append(pl, param('type', 'highpass'));
1244                 pl = append(pl, param('gain', 1));
1245                 pl = append(pl, param('fs', 1));
1246                 pl = append(pl, param('order', 1));
1247                 pl = append(pl, param('fc', 0.25));
1248                 pl = append(pl, param('ripple', 0.5));
1249                 miirObj = miir(pl);
1250                 newParam = param('addPar_filt',miirObj);
1251                 params = append(params, newParam);
1252             case '-->'
1253                 key = 'addPar_name';
1254                 while find(params,key)
1255                     key = [key,'x'];
1256                 end
1257                 params = append(params, param(key,'-->'));
1258                 UpdateInports(key,1)
1259             case 'pole'
1260                 params = append(params, param('addPar_poles',pole(1)));
1261             case 'zero'
1262                 params = append(params, param('addPar_zeros',zero(1)));
1263 
1264         end
1265         
1266         if nparams(params)==1, paramEnabled=1;
1267         else paramEnabled=[paramEnabled,1];
1268         end
1269 
1270         paramcommand = BuildParamCommand(params);
1271         for kk=1:length(selBlocks)
1272             set_param(selBlocks(kk),'Description',paramcommand);
1273         end
1274 
1275         AnnotationUpdate(params);
1276 
1277         buildplistFigureParam()
1278     end
1279     %----------------------------------------------------------------------
1280 
1281     %----------------------------------------------------------------------
1282     function RemParamCallback(hObject, varargin)   
1283          currParamIndex = get(hObject,'UserData');
1284          
1285          paramKey = params.params(currParamIndex).key;
1286          paramVal = params.params(currParamIndex).val;
1287          
1288          newParams = plist();
1289          for jj=1:nparams(params)
1290              if jj~=currParamIndex
1291                  newParams = append(newParams,params.params(jj));
1292              end
1293          end
1294          paramEnabled(currParamIndex)=[];
1295          params = newParams;
1296          
1297          if strcmp(paramVal,'-->') % it's a data from Simulink: delete the relative inport block.
1298              UpdateInports(paramKey,-1);
1299          end
1300          
1301          paramcommand = BuildParamCommand(params);
1302          for kk=1:length(selBlocks)
1303              set_param(selBlocks(kk),'Description',paramcommand);
1304          end
1305          
1306          AnnotationUpdate(params);
1307          
1308          buildplistFigureParam()
1309     end
1310     %----------------------------------------------------------------------
1311 
1312     %----------------------------------------------------------------------
1313     function fromSimulinkCallback(hObject, varargin)
1314         currParamIndex = str2double(get(hObject,'Tag'));
1315         status = get(hObject,'Value'); % 1 activated, 0 deactivated
1316         
1317         paramval = get(hObject,'UserData');
1318         paramKey = params.params(currParamIndex).key;
1319         if status %activated
1320             if ~isempty(paramval)
1321                 params = pset(params,paramKey,{'-->'});
1322             else
1323                 params = pset(params,paramKey,'-->');
1324             end
1325             paramEnabled(currParamIndex) = 1;
1326             UpdateInports(paramKey,1)
1327         else %deactivated
1328           % Retrieve the original param:
1329             functionname = getappdata(0,'ltpda_currFunctionName');
1330             [func,clas] = strtok(get(gcbh,'Tag'));
1331             if strcmp(func,'method')
1332                 origParams = feval(functionname,eval(strtrim(clas)),'Params');
1333             else
1334                 origParams = feval(functionname,'Params');
1335             end
1336             if isa(origParams,'cell')
1337                 currSet   = find(paramSets,'currSet');
1338                 if strcmp(func,'method')
1339                     origParams = feval(functionname,eval(strtrim(clas)),'Params',origParams{currSet});
1340                 else
1341                     origParams = feval(functionname,'Params',origParams{currSet});
1342                 end
1343             
1344             end
1345             
1346             paramKey = params.params(currParamIndex).key;
1347             origPar = find(origParams,paramKey);
1348             if isempty(origPar), origPar = 1; end
1349 %             if ~isempty(paramval) && isa(paramval,'cell') && numel(paramval)==1 && strcmp(paramval{1},'-->')
1350 %                 params = pset(params,paramKey,{1});
1351 %             else
1352                 params = pset(params,paramKey,origPar);
1353 %             end
1354             paramEnabled(currParamIndex) = 0;
1355             UpdateInports(paramKey,-1)
1356         end
1357         paramcommand = BuildParamCommand(params);
1358         for kk=1:length(selBlocks)
1359             set_param(selBlocks(kk),'Description',paramcommand);
1360         end
1361         AnnotationUpdate(params);
1362         buildplistFigureParam()
1363     end
1364     %----------------------------------------------------------------------
1365 
1366     %----------------------------------------------------------------------
1367     function UpdateInports(varargin)
1368     % Update the MaskDisplay and the number of inports when the user user
1369     % changes the params from Simulink.
1370     
1371         paramKey = varargin{1};
1372         try %#ok<ALIGN>
1373         if strcmpi(paramKey(1:7),'addPar_'), paramKey(1:7)=[]; end
1374         catch end
1375         
1376         if varargin{2}==-1
1377             block2delete = find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(paramKey));
1378             if numel(block2delete)>1, block2delete(1)=[]; end
1379             blockLines   = get_param(block2delete{1},'LineHandles');
1380             if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))),   delete_line(blockLines.Outport(1)); end
1381             delete_block(block2delete);
1382         end
1383 
1384         if varargin{2}==1
1385             newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on');
1386             nameAlreadyPresent = find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(paramKey));
1387             if ~isempty(nameAlreadyPresent)
1388                 for j=1:numel(nameAlreadyPresent)
1389                     if ~strcmp(nameAlreadyPresent{j},gcb),
1390                         set_param(nameAlreadyPresent{j},'Name',[lower(paramKey),'_fun']);
1391                     end
1392                 end
1393             end
1394             set(newBlock,'Name',lower(paramKey))
1395         end
1396         
1397         if varargin{2}~=2
1398           % Deleting previous Mux block - if present - and its lines:
1399             muxblock   = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
1400             try
1401                 muxLines = get_param(muxblock{1},'LineHandles');
1402                 for k=1:numel(muxLines.Inport),  if (muxLines.Inport(k)~=-1 && ~isempty(muxLines.Inport(k))),   delete_line(muxLines.Inport(k)); end
1403                 end
1404                 for k=1:numel(muxLines.Outport), if (muxLines.Outport(k)~=-1 && ~isempty(muxLines.Outport(k))), delete_line(muxLines.Outport(k)); end
1405                 end
1406             catch
1407             end
1408             delete_block(muxblock);
1409 
1410             inports  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1411             fakeInp  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Constant');
1412             inports  = [fakeInp;inports];
1413 
1414             if numel(inports)>1
1415                 muxblock = add_block('built-in/Mux', [gcb,'/Mux']);
1416                 set(muxblock,'Position',[70 , 10 , 73 , 150])
1417                 set(muxblock,'Inputs',num2str(numel(inports)))
1418             end
1419             for k=1:numel(inports)
1420                 inports{k}=get_param(inports{k},'Handle');
1421                 blkLines = get(inports{k},'LineHandles');
1422                 for j=1:numel(blkLines.Outport), if (blkLines.Outport(j)~=-1 && ~isempty(blkLines.Outport(j))), delete_line(blkLines.Outport(j)); end
1423                 end
1424                 set(inports{k},'Position',[10 , 10+30*(k-1) , 30 , 30+30*(k-1)])
1425                 set(inports{k},'Tag',num2str(k))
1426                 if numel(inports)>1
1427                     add_line(gcb,[get(inports{k},'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(k)]);
1428                 end
1429             end
1430 
1431             funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1432             funcBlock = get_param(funcBlock,'Name');
1433             if numel(inports)>1
1434                 add_line(gcb,[get(muxblock,'Name'),'/1'],[funcBlock{1},'/1']);
1435             else
1436                 add_line(gcb,[get(inports{1},'Name'),'/1'],[funcBlock{1},'/1']);
1437             end
1438         else
1439             inports  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1440             fakeInp  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Constant');
1441             inports  = [fakeInp;inports];
1442         end
1443         
1444         simKey = {};
1445         for i=1:nparams(params)
1446             if isa(params.params(i).val,'char') && strcmp(params.params(i).val,'-->')
1447                 name = params.params(i).key;
1448                 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[];  end; catch end
1449                 simKey{numel(simKey)+1} = name;
1450             elseif isa(params.params(i).val,'cell') && isa(params.params(i).val{1},'char') && strcmp(params.params(i).val{1},'-->')
1451                 name = params.params(i).key;
1452                 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[];  end; catch end
1453                 simKey{numel(simKey)+1} = name;
1454             end
1455         end
1456         
1457         drawingCom = '';
1458         if numel(simKey)>0 % then there are params 'from simulink' added
1459             if numel(fakeInp)>0, currInp=1; else currInp=2; end
1460             for nn=1:numel(simKey)
1461                 drawingCom = [drawingCom,'port_label(''input'',',num2str(currInp),',''',lower(simKey{1}),''');'];
1462                 simKey(1)  = [];
1463                 currInp    = currInp+1;
1464             end
1465         else % then the only inport is the regular one
1466             funcBlock  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1467             funcName   = get_param(funcBlock{1},'Tag');
1468             if numel(funcName)>6 && strcmp(funcName(1:6),'ltpda_'), funcName(1:6)=[]; end
1469             drawingCom = strcat('disp(''',lower(funcName),''')');
1470         end
1471         set(gcbh,'MaskDisplay',drawingCom)
1472         
1473     end
1474     %----------------------------------------------------------------------
1475 
1476     %----------------------------------------------------------------------
1477     function EnableSetCallback(hObject,varargin)   
1478     % Callback function: run when the user click on the checkbox associated
1479     % to each parameter, to enable its setting.
1480     
1481          currParamID   = get(hObject,'UserData');
1482          [xx,yy]       = size(objName);
1483 
1484          switch get(hObject,'Value')
1485              case 1
1486                  jj=2;
1487                  while jj<=yy && ~isempty(objName{currParamID,jj})
1488                      try set(objName{currParamID,jj},'Enable','on'); set(objName{currParamID,jj},'ForegroundColor',[0 0 0]); catch end
1489                      jj=jj+1;
1490                  end
1491                  paramEnabled(currParamID)=1;
1492              case 0
1493                  jj=2;
1494                  while jj<=yy && ~isempty(objName{currParamID,jj})
1495                          try %#ok<ALIGN>
1496                              if strcmp(get(objName{currParamID,jj},'Style'),'checkbox') && strcmp(get(objName{currParamID,jj},'String'),'From Simulink')
1497                              else
1498                                  set(objName{currParamID,jj},'Enable','off');
1499                                  set(objName{currParamID,jj},'ForegroundColor',[0.7 0.7 0.7]);
1500                              end
1501                          catch end
1502                          jj=jj+1;
1503                  end
1504                  paramEnabled(currParamID)=0;
1505          end
1506          
1507          paramcommand = BuildParamCommand(params);
1508          for kk=1:length(selBlocks)
1509              set_param(selBlocks(kk),'Description',paramcommand);
1510          end
1511          
1512          AnnotationUpdate(params);
1513     end
1514     %----------------------------------------------------------------------
1515 
1516     %----------------------------------------------------------------------
1517     function ExpandEdit(hObject,varargin)
1518     % Callback function: run when the user click on the checkbox associated
1519     % to each parameter, to enable its setting.
1520 
1521         origEditField = get(hObject,'UserData');
1522         currParamIndex = get(origEditField,'UserData');
1523         paramkey = params.params(currParamIndex).key;
1524         if numel(paramkey)>6 && strcmpi(paramkey(1:7),'addpar_'), paramkey(1:7)=[]; end
1525         paramval = get(origEditField,'String');
1526         
1527         editFigPos = [200,200,800,300];
1528         
1529         editFigure =   figure('Name',paramkey,'Tag','expandedEditField','MenuBar','none','Toolbar','none','NumberTitle','off','Units','pixels','Position',editFigPos,'Resize','on','ResizeFcn','refresh(gcf)','Color', get(0, 'defaultuicontrolbackgroundcolor'));
1530       % Edit field title:
1531         uicontrol('Parent',editFigure,'HorizontalAlignment','left','Position',[5 editFigPos(4)-30 editFigPos(3)-10 20],'String','Use this box to type in the value of the selected parameter:','FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','Style','text');
1532       % Edit field:
1533         editField = uicontrol('Parent',editFigure,'String',paramval,'UserData',currParamIndex,'Units','pixels','HorizontalAlignment','left','Position',[5 30 editFigPos(3)-7 editFigPos(4)-60],'FontSize',enlargedFont+8,'Visible','on','max',100,'Style','edit');
1534       % Ok button:
1535         okButton  = uicontrol('UserData',[editField,origEditField],'TooltipString','Accept this setting','String','Ok','Parent',editFigure,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','center','Position',[editFigPos(3)-150 5 70 20],'Visible','on','Callback',@editValueCallback,'Style','pushbutton');
1536       % Cancel button:
1537         cancButton  = uicontrol('TooltipString','Discard this setting','String','Cancel','Parent',editFigure,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','center','Position',[editFigPos(3)-75 5 70 20],'Visible','on','Callback','closereq','Style','pushbutton');
1538     end
1539     %----------------------------------------------------------------------
1540     
1541 %% General subfunctions
1542     %----------------------------------------------------------------------
1543     function [array]=readInput(inputdata, maxnumb, varargin)
1544           [xx,yy]=size(inputdata);
1545         % xx is the number or rows, yy is the number of characters in the longest row
1546         % array={};
1547           array=[];
1548           for i=1:xx
1549               rowpos=1;
1550               elemidx(i)=1;
1551               for j=1:yy+1
1552                   if (j==yy+1 || inputdata(i,j)==',' || strcmp(inputdata(i,j),' ') ) && (j==1 || (j>1 && (~strcmp(inputdata(i,j-1),' '))))
1553                       if (j==1 || strcmp(inputdata(i,j-1),',')) && strcmp(inputdata(i,j),',')
1554                           array(i,elemidx(i))=0;
1555                           elemidx(i)=elemidx(i)+1;
1556                           rowpos=j+1;
1557                       else
1558                         % To consider numbers, eg [1]:
1559                         % try array{i,elemidx(i)}=eval(inputdata(i,rowpos:j-1));  catch elemidx(i)=elemidx(i)-1; end
1560                         % To consider strings, eg '1':
1561                         % array{i,elemidx(i)}=inputdata(i,rowpos:j-1);
1562                           array(i,elemidx(i))=eval(inputdata(i,rowpos:j-1));
1563                           rowpos=j+1;
1564                           elemidx(i)=elemidx(i)+1;
1565                       end
1566                   elseif j<yy+1 && strcmp(inputdata(i,j),' ')
1567                       rowpos=j+1;
1568                   end
1569               if maxnumb~=0 
1570                   if elemidx(i)==maxnumb+1, break; end
1571               end
1572               end
1573               elemidx(i)=elemidx(i)-1;
1574           end
1575     end
1576     %----------------------------------------------------------------------
1577 
1578     %----------------------------------------------------------------------
1579     function paramcommand = BuildParamCommand(params,varargin)
1580     % Reconstruct the command line necessary to build a given plist
1581     
1582        % Initialize of the paramcommand ojbect:
1583          paramcommand = strcat('params=',string(params),';');
1584          
1585          if exist('paramEnabled','var')
1586              paramcommand = [paramcommand,'paramEnabled=',mat2str(paramEnabled),';'];
1587          end
1588 
1589          if ~exist('params','var') || nparams(params)==0, paramcommand='params=plist();paramEnabled=[];'; end
1590          
1591          if exist('noParamsReq','var') && noParamsReq==1
1592              paramcommand = [paramcommand,'noParamsReq=1;'];
1593          end
1594 
1595          description = get_param(gcbh,'Description');
1596          funcname = findstr('functionName=',description);
1597          if funcname
1598              i = funcname+14;
1599              while ~strcmp(description(i),';'), i=i+1; end
1600              funcname = description(funcname+13:i-1);
1601              paramcommand = [paramcommand,'functionName=',funcname,';'];
1602          end
1603         
1604          if exist('paramSets','var')
1605              paramcommand = [paramcommand,'paramSets=',string(paramSets),';'];
1606          end
1607          
1608     end
1609     %----------------------------------------------------------------------
1610 
1611     %----------------------------------------------------------------------
1612     function paramcommand = RetrievePlist(varargin)   
1613     % Retrieve the name of the function from the block, then asks for
1614     % parameters.
1615     
1616     try functionname = varargin{1};
1617     catch
1618         childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1619         functionname=get_param(childpath,'Tag');
1620     end
1621 
1622     if isempty(functionname)
1623         description = get_param(gcbh,'Description');
1624         funcname = findstr('functionName=',description);
1625         if funcname
1626             i = funcname+14;
1627             while ~strcmp(description(i),';'), i=i+1; end
1628             functionname = description(funcname+14:i-2);
1629         end
1630     end
1631 
1632     setappdata(0,'ltpda_currFunctionName',functionname);
1633 
1634     try
1635         if strcmp(functionname,'generic')
1636             paramcommand = 'functionName=''generic'';params=plist();paramEnabled=[];';
1637             return
1638         end
1639         
1640         [func,class] = strtok(get(gcbh,'Tag'));
1641             
1642         if strcmp(func,'method')
1643             params=feval(functionname,eval(strtrim(class)),'Params');
1644         else
1645             params=feval(functionname,'Params');
1646         end
1647         if isa(params,'cell')
1648             paramSets = plist('sets',params,'currSet',1);
1649             paramcommand = strcat('paramSets=',string(paramSets),';','params=plist();');
1650         elseif nparams(params)
1651             paramcommand = strcat('params=',string(params),';');
1652         else
1653             paramcommand = 'params=plist();';
1654         end
1655     catch
1656         disp(sprintf('Error: unable to retrieve the parameters required by the function "%s". Maybe it''s not supported yet?',functionname));
1657         ErrorFuncNotSupported();
1658         paramcommand = '';
1659         rethrow(lasterror)
1660         return
1661     end
1662     
1663     end
1664     %----------------------------------------------------------------------
1665 
1666     %----------------------------------------------------------------------
1667     function AnnotationUpdate(params,varargin)
1668     % Update the block annotation (the text below the block) with all the
1669     % current parameters
1670     
1671          annotation='';
1672          numparams=nparams(params);
1673          firstpar=1;
1674          for kk=1:numparams
1675              if paramEnabled(kk)
1676                  paramkey = params.params(kk).key;
1677                  try %#ok<ALIGN>
1678                  if strcmpi(paramkey(1:7),'addPar_'), paramkey(1:7)=[]; end
1679                  catch end
1680                  paramval = params.params(kk).val;
1681                  switch class(paramval)
1682                      case 'specwin'
1683                          windowName = get(paramval,'name');
1684                          [xxx,windowlength] = size(get(paramval,'win'));
1685                          if firstpar==1 % it's the first parameter
1686                              annotation = ['specwin ',windowName,',',num2str(windowlength)];
1687                              firstpar=2;
1688                          else % it's not the first parameter
1689                              annotation = [annotation,'\n','specwin ',windowName,',',num2str(windowlength)];
1690                          end
1691                          if strcmp(windowName,'Kaiser')
1692                              windowPsll=get(paramval,'psll');
1693                              annotation = [annotation,',',num2str(windowPsll)];
1694                          end
1695                      case 'double'
1696                          paramval = mat2str(paramval);
1697                          if numel(paramval)>25, paramval=['...',paramval(numel(paramval)-25:numel(paramval))]; end
1698                          if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1699                          else annotation = [annotation,'\n',lower(paramkey),' ',num2str(paramval)];
1700                          end
1701                      case 'char'
1702                          if numel(paramval)>25, paramval=['...',paramval(numel(paramval)-25:numel(paramval))]; end
1703                          paramval = strrep(paramval,'''''','''');
1704                          if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1705                          else annotation = [annotation,'\n',lower(paramkey),' ',paramval];
1706                          end
1707                      case 'pzmodel'
1708                          if firstpar==1, annotation='pzmodel'; firstpar=2;
1709                          else annotation = [annotation,'\n','pzmodel'];
1710                          end
1711                      case 'miir'
1712                          if firstpar==1, annotation='miir'; firstpar=2;
1713                          else annotation = [annotation,'\n','miir'];
1714                          end
1715                      case 'cell'
1716                          if isa(paramval{1},'char') && strcmp(paramval{1},'-->'), strParKey = '-->';
1717                          else strParKey = cell2str(paramval);
1718                          end
1719                          if firstpar==1
1720                              annotation = [lower(paramkey),' ',strParKey]; firstpar=2;
1721                          else annotation = [annotation,'\n',lower(paramkey),' ',strParKey];
1722                          end
1723                      case 'pole'
1724                          for kk=1:numel(paramval)
1725                              poleFreqs(kk,1) = paramval(kk).f;
1726                              poleQs(kk,1)    = paramval(kk).q;
1727                              if ~isnan(poleQs(kk,1))
1728                                  poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
1729                              else
1730                                  poleFQs{kk,1}=num2str(poleFreqs(kk,1));
1731                              end
1732                          end
1733                          poleFQs=char(poleFQs);
1734                          if firstpar==1
1735                              annotation = ['pole ',poleFQs(1,:)]; firstpar=2;
1736                              for j=2:size(poleFQs,1), annotation = [annotation,'\n','pole ',poleFQs(j,:)]; end
1737                          else
1738                              annotation = [annotation,'\n','pole ',poleFQs(1,:)];
1739                              for j=2:size(poleFQs,1), annotation = [annotation,'\n','pole ',poleFQs(j,:)]; end
1740                          end
1741                      case 'zero'
1742                          for kk=1:numel(paramval)
1743                              zeroFreqs(kk,1) = paramval(kk).f;
1744                              zeroQs(kk,1)    = paramval(kk).q;
1745                              if ~isnan(zeroQs(kk,1))
1746                                  zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
1747                              else
1748                                  zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
1749                              end
1750                          end
1751                          zeroFQs=char(zeroFQs);
1752                          if firstpar==1
1753                              annotation = ['zero ',zeroFQs(1,:)]; firstpar=2;
1754                              for j=2:size(zeroFQs,1), annotation = [annotation,'\n','zero ',zeroFQs(j,:)]; end
1755                          else
1756                              annotation = [annotation,'\n','zero ',zeroFQs(1,:)];
1757                              for j=2:size(zeroFQs,1), annotation = [annotation,'\n','zero ',zeroFQs(j,:)]; end
1758                          end
1759                  end
1760              end
1761          end
1762          % Finally set the block annotation:
1763          for nn=1:length(selBlocks)
1764              set_param(selBlocks(nn),'AttributesFormatString',annotation);
1765          end
1766     end
1767     %----------------------------------------------------------------------
1768 
1769     %----------------------------------------------------------------------
1770     function functionName = functionNameSet(hObject, varargin)
1771     % Setting the name of the function in the 'generic' block.
1772     
1773        functionName2 = get(hObject,'String');
1774        classes = {'ao';'cdata';'fsdata';'history';'mfir';'miir';'param';'plist';'pole';'provenance';'pzmodel';'specwin';'time';'timeformat';'timespan';'tsdata';'xydata';'xyzdata';'zero'};
1775        for i=1:numel(classes)
1776            if ismethod(eval(classes{i}),functionName2)
1777                currSel = gcbsh;
1778                for j=1:numel(currSel), set(currSel(j),'Tag',['method ',classes{i}]); end
1779                break
1780            else
1781                currSel = gcbsh;
1782                for j=1:numel(currSel), set(currSel(j),'Tag','function'); end
1783            end
1784        end
1785        paramcommand = RetrievePlist(functionName2);
1786         
1787       if ~isempty(paramcommand)
1788         functionName = functionName2;
1789         setappdata(0,'ltpda_currFunctionName',functionName);
1790         paramcommand = strcat(paramcommand,'functionName=''',functionName2,''';');
1791         for i=1:1000
1792             try
1793                 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Name',functionName2); end
1794                 break;
1795             catch functionName2 = strcat(functionName,'_',num2str(i));
1796             end
1797         end
1798         for kk=1:length(selBlocks)
1799             set_param(selBlocks(kk),'Description',paramcommand);
1800         end
1801         delete(findobj(gcf,'Parent',currPanel))
1802         buildplistFigureParam()
1803         
1804       else % the functionName inserted it's not valid
1805           description = get_param(gcbh,'Description');
1806           funcname = findstr('functionName=',description);
1807           if funcname
1808               i = funcname+14;
1809               while ~strcmp(description(i),';'), i=i+1; end
1810               functionName = description(funcname+14:i-2);
1811           end
1812           set(hObject,'String',functionName);
1813           setappdata(0,'ltpda_currFunctionName',functionName);
1814       end
1815       
1816       
1817     end
1818     %----------------------------------------------------------------------
1819 
1820 % =========================================================================
1821 %% Sets
1822      %----------------------------------------------------------------------
1823     function SetsUpdate(hObject,varargin)
1824     % Whenever the user select a different set of params
1825          currSet   = get(hObject,'Value');
1826          paramSets = pset(paramSets,'currSet',currSet);
1827          sets      = get(hObject,'UserData');
1828          functionname = getappdata(0,'ltpda_currFunctionName');
1829          [func,classes] = strtok(get(gcbh,'Tag'));
1830          if strcmp(func,'method')
1831              params = feval(functionname,eval(strtrim(classes)),'Params',sets{currSet});
1832          else
1833              params = feval(functionname,'Params',sets{currSet});
1834          end
1835          
1836          paramEnabled = zeros(1,nparams(params));
1837          
1838          paramcommand = BuildParamCommand(params);
1839          for kk=1:length(selBlocks)
1840              set_param(selBlocks(kk),'Description',paramcommand);
1841          end
1842          
1843        % Finally set the block annotation:
1844          for nn=1:length(selBlocks)
1845              set_param(selBlocks(nn),'AttributesFormatString','');
1846          end
1847          
1848          buildplistFigureParam();
1849     end
1850     %----------------------------------------------------------------------
1851 
1852 % =========================================================================
1853 %% Special buttons: Help, Reset, KeepResults, SetName
1854     %----------------------------------------------------------------------
1855     function HelpButtonCallback(varargin)
1856     % Whenever the user click the Help button
1857     
1858          try
1859              childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1860              functionname = get_param(childpath,'Tag');
1861              
1862              description = get_param(gcbh,'Description');
1863              funcname = findstr('functionName=',description);
1864              if funcname
1865                  i = funcname+14;
1866                  while ~strcmp(description(i),';'), i=i+1; end
1867                  functionname = description(funcname+14:i-2);
1868              end
1869              
1870              [func,classes] = strtok(get(gcbh,'Tag'));
1871              if strcmp(func,'method')
1872                  helptext = help([strtrim(classes),'/',functionname]);
1873              else
1874                  helptext = help(functionname);
1875              end
1876              
1877              helpFigure    =   figure('MenuBar','none','Toolbar','none','Name',strcat(functionname,' help'),'NumberTitle','off','Units','pixels','Position',[200,200,500,300],'Resize','on','ResizeFcn','refresh(gcf)','Color', get(0, 'defaultuicontrolbackgroundcolor'));
1878            % Help text:
1879              uicontrol('Parent',helpFigure,'Units','normalized','HorizontalAlignment','left','Position',[0 0 1 1],'FontSize',enlargedFont+8,'String',helptext,'Visible','on','max',100,'Style','edit');
1880          catch
1881              disp('Something''s wrong with the creation of the Help figure. Please check ''HelpButtonCallback''')
1882          end
1883     end
1884     %----------------------------------------------------------------------
1885 
1886     %----------------------------------------------------------------------
1887     function ResetButtonCallback(varargin)
1888     % Whenever the user click the Reset Parameters button
1889     
1890          paramcommand = RetrievePlist();
1891          
1892          if findstr(paramcommand,'functionName=''generic''')
1893              for i=1:length(selBlocks), set_param(selBlocks(i),'Name','generic'); end
1894          end
1895          eval(paramcommand)
1896          paramEnabled = zeros(1,nparams(params));
1897          for kk=1:length(selBlocks)
1898              set_param(selBlocks(kk),'Description',paramcommand);
1899          end
1900          AnnotationUpdate(params);
1901 
1902          buildplistFigureParam()
1903 
1904     end
1905     %----------------------------------------------------------------------
1906 
1907     %----------------------------------------------------------------------
1908     function KeepResultCallback(hObject,varargin)
1909     % Whenever the user clicks on the checkbox to maintain local results.
1910     
1911          switch get(hObject,'Value')
1912              case 0
1913                  [meth,clas] = strtok(get_param(gcbh,'Tag'),' ');
1914                  categ = 'none';
1915                  if strcmp(meth,'method')
1916                      clas = strtrim(clas);
1917                      funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1918                      func = get_param(funcBlock{1},'Tag');
1919                      categ = eval([func,'(',clas,',''Category'')']);
1920                  end
1921 
1922                  switch categ
1923                      case 'Constructor'
1924                          set_param(gcbh,'Backgroundcolor','green')
1925                          set_param(gcbh,'MaskHelp','')
1926                      case 'Output'
1927                          set_param(gcbh,'Backgroundcolor','lightBlue')
1928                          set_param(gcbh,'MaskHelp','')
1929                      otherwise
1930                          set_param(gcbh,'Backgroundcolor','red')
1931                          set_param(gcbh,'MaskHelp','')
1932                  end
1933              case 1
1934                  set_param(gcbh,'Backgroundcolor','magenta')
1935                  set_param(gcbh,'MaskHelp','probe')
1936          end
1937     end
1938     %----------------------------------------------------------------------
1939 
1940     %----------------------------------------------------------------------
1941     function SetNameCallback(hObject,varargin)
1942     % Whenever the user clicks on the checkbox to maintain local results.
1943     
1944          setName = get(hObject,'Value');
1945          set(gcbh,'UserData',setName);
1946          set(gcbh,'UserDataPersistent','on');
1947 
1948     end
1949     %----------------------------------------------------------------------
1950 
1951 % =========================================================================
1952 %% Input, Mux, Demux, From blocks
1953     %----------------------------------------------------------------------
1954     function LoadInputParamCallback(varargin)   
1955     % This callback is called whenever the user selects an Input block. The
1956     % callback draws the panel to set the only parameter associated to this
1957     % type of block: the ordinal number of AO.
1958     
1959         if length(LTPDAinvar)<1
1960           % Text: 'Please load at least one AO in memory'
1961             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Please load at least one AO in memory','Visible','on','Style','text');
1962           % Button: 'Add data'
1963             uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-150 200 30],'String','Add data','FontSize',enlargedFont+8,'Visible','on','Enable','on','Callback',@AddButtonCallback,'Style','pushbutton');
1964         else
1965           % Text: 'AO input:'
1966             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 50 20],'String','AO input:','Visible','on','Style','text');
1967             children=get_param(gcb,'Blocks');
1968             inputblock=strcat(gcb,'/',children{1});
1969             currAOinput=get_param(inputblock,'Value');
1970           % Edit field:
1971             uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[170 panelDimens(4)-57 50 20],'String',currAOinput,'Visible','on','Enable','on','Callback',@InputEditCallback,'Style','edit');
1972         end
1973     end
1974     %----------------------------------------------------------------------
1975 
1976     %----------------------------------------------------------------------
1977     function InputEditCallback(hObject, varargin)   
1978     % This callback is called whenever the user modify the input parameter
1979     % associated to an Input block
1980     
1981          newValue   = str2double(get(hObject,'String'));
1982        % Check it's an integer:
1983          newValue = round(newValue);
1984        % Check if the value is acceptable, ie if it's <length(LTPDAinvar)
1985          if newValue>length(LTPDAinvar)
1986              newValue=length(LTPDAinvar);
1987          end
1988          set(hObject,'String',num2str(newValue));
1989 
1990          for i=1:length(selBlocks)
1991            % Since all input blocks are masks, and we want to change the
1992            % value deep inside a block INSIDE this mask, we can't use the
1993            % direct handles but the following:
1994              children{i}=get_param(selBlocks(i),'Blocks');
1995              inputblock=strcat(strcat(get(selBlocks(i),'Path'),'/',get(selBlocks(i),'Name')),'/',children{i}{1});
1996              set_param(inputblock,'Value',num2str(newValue));
1997            % On the contrary, for annotation we use just the handles:
1998            % Modify the block annotation:
1999              set_param(selBlocks(i),'AttributesFormatString',num2str(newValue));
2000          end
2001     end
2002     %----------------------------------------------------------------------
2003 
2004     %----------------------------------------------------------------------
2005     function AddButtonCallback(varargin)   
2006     % Callback function: run when the user click the "Add data" button
2007     
2008          filenames = uipickfiles('REFilter','.txt');
2009          if ~isempty(filenames) && ~isnumeric(filenames(1,1))
2010              [x,y]=size(filenames);
2011              for j=1:y
2012                  anobject={ao(filenames{j})};
2013                  LTPDAinvar=[LTPDAinvar;anobject];
2014              end
2015              disp(sprintf('  + %g AOs added to the global variable LTPDAinvar', y))
2016              buildplistFigureParam();
2017          end
2018     end   
2019     %----------------------------------------------------------------------
2020     
2021     %----------------------------------------------------------------------
2022     function LoadMuxParamCallback(varargin)   
2023     % This callback is called whenever the user selects a Mux block (or
2024     % Demux). The callback opens the panel to set the only parameter
2025     % associated to this type of block: the number of inputs.
2026     % The function sets also the dimension of the block accordingly.
2027         
2028         if strcmp(get(gcbh,'Tag'),'mux'),
2029           % Text: 'Number of inputs:'
2030             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of inputs:','Visible','on','Style','text');
2031           % Edit field:
2032             uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[210 panelDimens(4)-57 50 20],'String',get(gcbh,'Inputs'),'Visible','on','Enable','on','Callback',@MuxEditCallback,'Style','edit');
2033         elseif strcmp(get(gcbh,'Tag'),'demux'),
2034           % Text: 'Number of outputs:'
2035             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of outputs:','Visible','on','Style','text');
2036           % Edit field:
2037             uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[210 panelDimens(4)-57 50 20],'String',get(gcbh,'Outputs'),'Visible','on','Enable','on','Callback',@MuxEditCallback,'Style','edit');
2038         end
2039     end
2040     %----------------------------------------------------------------------
2041 
2042     %----------------------------------------------------------------------
2043     function MuxEditCallback(hObject, varargin)   
2044     % This callback is called whenever the user modify the number of inputs
2045     % associated to a Mux block (or outputs to a Demux)
2046     
2047          newValue   = str2double(get(hObject,'String'));
2048        % Check it's an integer:
2049          newValue = round(newValue);
2050          set(hObject,'String',num2str(newValue));
2051          for i=1:length(selBlocks)
2052              newDimens=get(selBlocks(i),'Position');
2053              newDimens(4)=newDimens(2)+25*(newValue+1);
2054              if strcmp(get(gcbh,'Tag'),'mux'),
2055                  set(selBlocks(i),'Inputs',num2str(newValue));
2056              elseif strcmp(get(gcbh,'Tag'),'demux'),
2057                  set(selBlocks(i),'Outputs',num2str(newValue));
2058              end
2059              set(selBlocks(i),'Position',newDimens);
2060          end
2061     end
2062     %----------------------------------------------------------------------
2063     
2064     %----------------------------------------------------------------------
2065     function LoadFromBlockCallback(varargin)   
2066     % This callback is called whenever the user selects a From block.
2067         
2068       % Button: 'Find origin'
2069         uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Find origin','FontSize',enlargedFont+8,'Visible','on','Enable','on','Callback',@FindOriginCallback,'Style','pushbutton');
2070     end
2071     %----------------------------------------------------------------------
2072 
2073     %----------------------------------------------------------------------
2074     function FindOriginCallback(varargin)   
2075     % This callback is called whenever click on the 'Find Origin' button,
2076     % having selected a 'From' block.
2077     
2078         varName = get(gcbh,'GotoTag');
2079         origin = find_in_models(bdroot,'LookUnderMasks','all','BlockType','Goto','GotoTag',varName);
2080         if numel(origin)>1
2081           % Error text: there are multiple origins.
2082             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String','Error: there are multiple sources','Visible','on','Style','text');
2083         elseif numel(origin)==1
2084           % Text: full path of the origin.
2085             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String',origin{1},'Visible','on','Style','text');
2086         else
2087           % Error text: no origin found.
2088             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String','Error: no source found','Visible','on','Style','text');
2089         end
2090             
2091         
2092         
2093     end
2094     %----------------------------------------------------------------------
2095 
2096 % =========================================================================
2097 %% Errors
2098     %----------------------------------------------------------------------
2099     function ErrorFuncNotSupported(varargin)   
2100     % Recalled whenever the call pl=function('Params') fails
2101     
2102       % Text: '[...] Maybe it''s not supported yet?'
2103         uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-100-100 300 30],'String','Error: unable to retrieve the parameters required by this function. Maybe it''s not supported yet?','Visible','on','Style','text');   
2104     end
2105     %----------------------------------------------------------------------
2106 
2107     %----------------------------------------------------------------------
2108     function ErrorSelectionInconsistent(varargin)   
2109     % Recalled whenever the user selects inconsistent multiple blocks
2110         uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[10 7 380 40],'String','Error: impossible to set unique parameters for the selected blocks','Visible','on','Style','text');   
2111     end
2112     %----------------------------------------------------------------------
2113 
2114 % =========================================================================
2115 %%
2116 
2117 end

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003