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

Generated on Tue 25-Mar-2008 23:00:00 by m2html © 2003