Home > m > gui > gltpda > pan1main.m

pan1main

PURPOSE ^

This is the function for the main panel of the GUI LTPDA, the package of

SYNOPSIS ^

function varargout = pan1main(varargin)

DESCRIPTION ^

 This is the function for the main panel of the GUI LTPDA, the package of
 data analysis functions developed for the LISA Pathfinder Mission / LISA
 Technology Package.

  $Id: pan1main.m,v 1.3 2008/03/04 05:00:52 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = pan1main(varargin)
0002 % This is the function for the main panel of the GUI LTPDA, the package of
0003 % data analysis functions developed for the LISA Pathfinder Mission / LISA
0004 % Technology Package.
0005 %
0006 %  $Id: pan1main.m,v 1.3 2008/03/04 05:00:52 nicola Exp $
0007 
0008 global ltpdaGUIstatus LTPDAinvar LTPDAoutvar currentsystem % temp loopstatus
0009 
0010 % Initialize the list of AOs:
0011 InputObjList=''; OutputObjList='';
0012 UpdateListbox();
0013 
0014 alltimers = timerfindall;
0015 stop(alltimers(2));
0016 set(alltimers(2),'TimerFcn',@ContinuousCheck,'Period',1);
0017 start(alltimers(2));
0018 
0019 % Since the LTPDA Toolbox is now part of the Simulink Library, instead of
0020 % opening its window (which would require to open other minor windows to
0021 % access the single blocks) now the GUI will automatically open the
0022 % Simulink Library, which can be browsed more efficiently:
0023 
0024 % simulink    % commented just for debug phase, to be uncommented in the
0025               % final release
0026 
0027 %%
0028 
0029 currPanel   = varargin{1};
0030 if nargin>1, runSim = varargin{2}; else runSim = 0; end
0031 panelDimens = get(currPanel, 'Position');
0032 backColor   = get(currPanel, 'BackgroundColor');
0033 
0034                     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[30 panelDimens(4)-52 60 30],'String','Username:','FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','Style','text');
0035   hUserIDEdit   =   uicontrol('Parent',currPanel,'BackgroundColor',[0.9,0.9,0.9],'Units','pixels','HorizontalAlignment','center','Position',[95 panelDimens(4)-39 80 25],'String',ltpdaGUIstatus{1,1},'FontSize',8,'FontAngle','italic','Visible','on','Enable','off','Callback',@UserIDCallback,'Style','edit');
0036                     uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[190 panelDimens(4)-36 120 20],'String','Login / Logout','FontSize',8,'Visible','on','Enable','on','Callback',@LogoutCallback,'Style','pushbutton');
0037                     
0038                     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[400 panelDimens(4)-42 100 20],'String','Current system:','FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','Style','text');
0039   currsystem = bdroot;
0040   if isempty(currsys) || isempty(find_system(currsystem,'FindAll','on','Type','Annotation','Tag','ltpda model')), currsystem = 'None'; end
0041                     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[510 panelDimens(4)-42 150 20],'String',currsystem,'FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','UserData','currsystem','Style','text');
0042 
0043 
0044     AnalysPanPos   = [20 panelDimens(4)-100 panelDimens(3)-40 55];
0045 
0046 uipanel('Title','Analyses Control Panel','BackgroundColor',backColor,'FontSize',7,'Units','pixels','Position',AnalysPanPos);
0047 
0048     nbuttons    = 3;
0049     buttonWidth = (AnalysPanPos(3)-10*(nbuttons+1))/nbuttons;
0050     buttonPos   = [AnalysPanPos(1)+10 AnalysPanPos(2)+10 buttonWidth 25];
0051   hNewModelButton = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','New model','FontSize',8,'Visible','on','Enable','on','Callback',@hNewButtonCallback,'Style','pushbutton');
0052     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0053   hOpenModelButton = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Open model','FontSize',8,'Visible','on','Enable','on','Callback',@hOpenCallback,'Style','pushbutton');
0054     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0055   hSaveModelButton = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Save model','FontSize',8,'Visible','on','Enable','on','Callback',@hSaveCallback,'Style','pushbutton');
0056     clear AnalysPanPos nbuttons buttonWidth buttonPos
0057 
0058 
0059     DataPanPos   = [20 panelDimens(4)-415 panelDimens(3)-40 305];
0060   hDataPanel    =  uipanel(...
0061                       'Title','Data Control Panel',...
0062                       'BackgroundColor',[1,1,1],...
0063                       'FontSize',7,...
0064                       'Units','pixels',...
0065                       'Position',DataPanPos);
0066     nbuttons    = 5;
0067     buttonWidth = (DataPanPos(3)-10*(nbuttons+1))/nbuttons;
0068     buttonPos   = [10 DataPanPos(4)-40 buttonWidth 22];
0069   hLoadButton   =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Load','FontSize',8,'Visible','on','Enable','on','Callback',@hLoadDataButtonCallback,'Style','pushbutton');
0070     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0071   hCreateDataButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Create','FontSize',8,'Visible','on','Enable','off','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0072     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0073   hEditDataButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Edit','FontSize',8,'Visible','on','Enable','off','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0074     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0075   hRemoveButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Remove','FontSize',8,'Visible','on','Enable','on','Callback',@hRemoveButtonCallback,'Style','pushbutton');
0076     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0077   hExploreButton =  uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Explore','FontSize',8,'Visible','on','Enable','on','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0078     clear nbuttons buttonWidth buttonPos
0079 
0080     nbuttons    = 4;
0081     buttonWidth = (DataPanPos(3)-10*(nbuttons+1))/nbuttons;
0082     buttonPos   = [10 DataPanPos(4)-65 buttonWidth 22];
0083 %   hImportButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Import','FontSize',8,'Visible','on','Enable','on','Callback',@hImportButtonCallback,'Style','pushbutton');
0084 %     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0085   hExportButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Export to workspace','FontSize',8,'Visible','on','Enable','on','Callback',@hExportButtonCallback,'Style','pushbutton');
0086     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0087   hClearButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Clear input','FontSize',8,'Visible','on','Enable','on','Callback',@hClearButtonCallback,'Style','pushbutton');
0088     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0089   hSaveWorkButton =  uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Save workspace','FontSize',8,'Visible','on','Enable','on','Callback',@SaveWorkspaceCallback,'Style','pushbutton');
0090     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0091   hLoadWorkButton =  uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Load workspace','FontSize',8,'Visible','on','Enable','on','Callback',@LoadWorkspaceCallback,'Style','pushbutton');
0092     clear nbuttons buttonWidth buttonPos
0093 
0094 
0095     ntexts    = 2;
0096     textWidth = (DataPanPos(3)-10*(ntexts+1))/ntexts;
0097     textPos   = [10 DataPanPos(4)-100 textWidth 25];
0098   hListAOText   =   uicontrol('Parent',hDataPanel,'BackgroundColor',get(hDataPanel,'BackgroundColor'),'HorizontalAlignment','center','Position',textPos,'String','Input:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0099     clear ntexts textWidth textPos
0100 
0101 
0102     nlists    = 2;
0103     listWidth = (DataPanPos(3)-10*(nlists+1))/nlists;
0104     listPos   = [10 DataPanPos(4)-295 listWidth 200];
0105   InputObjList   = uicontrol('Parent',hDataPanel,'BackgroundColor',[0.95,0.95,0.95],'HorizontalAlignment','center','Position',listPos,'String',listInput,'Value',1,'Max',10,'Min',1,'FontSize',8,'FontWeight','normal','Visible','on','Enable','on','Callback',@hListObjsCallback,'Style','listbox');
0106     set(hExploreButton,'UserData',InputObjList);
0107     listPos(1) = listPos(1)+listWidth+10;
0108   % Info panel:
0109   uicontrol('Parent',hDataPanel,'BackgroundColor',[0.94,0.94,1],'Style','listbox','HorizontalAlignment', 'left','Fontsize', 8,'Units','pixels','Position',listPos,'Tag','infoPanel');
0110     hListObjsCallback(InputObjList,1);
0111     clear DataPanPos nlists listWidth listPos
0112     
0113     
0114   hExecutionPanel =  uipanel('Title','Execution control','BackgroundColor',[1,1,1],'FontSize',7,'Units','pixels','Position',[20 panelDimens(4)-485 panelDimens(3)-40 60]);
0115 
0116     if isempty(getappdata(0,'maintainresults')), setappdata(0,'maintainresults',0); end
0117   hKeepPrevData  = uicontrol('Parent',hExecutionPanel,'BackgroundColor',[1 1 1],'HorizontalAlignment','center','Position',[30 10 180 30],'Value',getappdata(0,'maintainresults'),'String',' Maintain intermediate results','ForeGroundColor','black','Visible','on','Enable','on','Callback',@MaintainResults,'Style','checkbox');
0118 
0119 % The execution of the analysis can be started using the common Start
0120 % button in the Simulink Window, but starting it from the GUI control panel
0121 % will offer a few more useful advantages, such as the autocompletion of
0122 % the model with terminators to the unconnected ports (to avoid useless
0123 % warnings). In case of programmed loop moreover it will be mandatory to
0124 % use the button in the GUI.
0125 
0126   hExecute        =   axes('Parent',findobj('Name','In GUI we trust'),'Units','pixels','Position',[panelDimens(3)-100 18 36 38]);
0127   image(imread('startgreen.jpg'),'Parent',hExecute,'AlphaData',imread('startalpha.gif'),'ButtonDownFcn',@StartExec,'Tag','StartButton1');
0128   axis off;
0129  
0130 if runSim == 1, StartExec(); end
0131 
0132 %%
0133 % Define default output and return it if it is requested by users
0134 mOutputArgs{1} = currPanel;
0135 if nargout>0
0136     [varargout{1:nargout}] = mOutputArgs{:};
0137 end
0138 
0139 
0140 %%
0141 
0142 % ========================================================================
0143 % ========================================================================
0144 % ============================== FUNCTIONS ===============================
0145 % ========================================================================
0146 % ========================================================================
0147 
0148 %%
0149     %----------------------------------------------------------------------
0150     function ContinuousCheck(varargin)   
0151         % This is the function to execute a continuous timer check
0152         
0153        % Keep alive the first timer:
0154          alltimers = timerfindall;
0155          if strcmp(get(alltimers(1),'Running'),'off')
0156              start(alltimers(1))
0157          end
0158 
0159          currsys = bdroot;
0160          if ~isempty(currsys) && ~isempty(find_system(currsys,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0161              set(findobj('UserData', 'currsystem'), 'String', currsys)
0162          else
0163              set(findobj('UserData', 'currsystem'), 'String', 'None')
0164          end
0165          
0166     end
0167     %----------------------------------------------------------------------
0168     
0169 %%
0170     %----------------------------------------------------------------------
0171     function UserIDCallback(hObject, varargin)   
0172     % Callback function: run when the user change the User ID
0173     
0174          if hObject~=-1
0175              ltpdaGUIstatus{1,1} = genvarname(get(hObject,'String'));
0176              set(hObject,'String',ltpdaGUIstatus{1,1});
0177          end
0178     end
0179     %----------------------------------------------------------------------
0180 
0181     %----------------------------------------------------------------------
0182     function LogoutCallback(varargin)
0183     % Callback function: run when the user click the "Logout" button
0184 
0185          setappdata(0,'ltpda_repo_pass','');
0186          userID = getappdata(0,'ltpda_repo_user');
0187          if isempty(userID), userID = ''; end
0188 
0189          [userID passwd] = loginLTPDA(userID,'');
0190          ltpdaGUIstatus{1,1} = userID;
0191          setappdata(0,'ltpda_repo_user',userID)
0192          setappdata(0,'ltpda_repo_pass',passwd)
0193 
0194          ltpdagui('Redraw',1);
0195          
0196     end
0197     %----------------------------------------------------------------------
0198 
0199 
0200 %%
0201     %----------------------------------------------------------------------
0202     function hLoadDataButtonCallback(varargin)   
0203     % Callback function: run when the user click the "Add data" button
0204     
0205          filenames=uipickfiles('REFilter','.txt');
0206          if ~isnumeric(filenames(1,1))
0207              [x,y]=size(filenames);
0208              for j=1:y
0209                  anobject={ao(filenames{j}),1};
0210                  LTPDAinvar=[LTPDAinvar;anobject];
0211              end
0212              disp(sprintf('  + %g AOs added to the global variable LTPDAinvar', y))
0213              UpdateListbox();
0214          end
0215     
0216     end
0217     %----------------------------------------------------------------------
0218 
0219     %----------------------------------------------------------------------
0220     function hRemoveButtonCallback(varargin)   
0221     % Callback function: run when the user click the "Remove data" button
0222 
0223            index_selected = get(InputObjList,'Value');
0224            listAOs = get(InputObjList,'String');
0225            if ~strcmp(listAOs,'The memory is empty')
0226                for i=1:numel(index_selected)
0227                    objSelect = str2double(strtok(listAOs{index_selected(i),1},'.'));
0228                    LTPDAinvar{objSelect,1} = [];
0229                end
0230                UpdateListbox();
0231            end
0232 
0233     end
0234     %----------------------------------------------------------------------
0235 
0236     %----------------------------------------------------------------------
0237     function hExportButtonCallback(varargin)   
0238     % Callback function: run when the user click the "Remove data" button
0239 
0240          currSelObjs   = get(InputObjList,'Value');
0241          listAOs = get(InputObjList,'String');
0242          if ~strcmp(listAOs,'The memory is empty')
0243              selectedObjs  = [];
0244              for i=1:numel(currSelObjs)
0245                  objSelect = str2double(strtok(listAOs{currSelObjs(i),1},'.'));
0246                  selectedObjs = [selectedObjs,LTPDAinvar{objSelect,1}];
0247              end
0248              if ~isempty(selectedObjs)
0249                  for i=1:numel(selectedObjs)
0250                      vars = evalin('base','who');
0251                      objName = [class(selectedObjs(i)),'_',selectedObjs(i).name,'_'];
0252                      j=1;
0253                      while strmatch([objName,num2str(j)],vars), j=j+1; end
0254                      objName = [objName,num2str(j)];
0255                      assignin('base', objName, selectedObjs(i));
0256                  end
0257              end
0258          end
0259          
0260     end
0261     %----------------------------------------------------------------------
0262 
0263     %----------------------------------------------------------------------
0264     function hExploreButtonCallback(varargin)   
0265     % Callback function: run when the user click the "Update list" button
0266 
0267          currSelObjs   = get(InputObjList,'Value');
0268          listAOs = get(InputObjList,'String');
0269          if ~strcmp(listAOs,'The memory is empty')
0270              selectedObjs  = [];
0271              for i=1:numel(currSelObjs)
0272                  objSelect = str2double(strtok(listAOs{currSelObjs(i),1},'.'));
0273                  selectedObjs = [selectedObjs,LTPDAinvar{objSelect,1}];
0274              end
0275 
0276              if ~isempty(selectedObjs)
0277                  explore_ao(selectedObjs);
0278              else
0279                  explore_ao(LTPDAinvar);
0280              end
0281 
0282              UpdateListbox();
0283          end
0284 
0285     end
0286     %----------------------------------------------------------------------
0287 
0288     %----------------------------------------------------------------------
0289     function hClearButtonCallback(varargin)
0290     % Callback function: run when the user click the "Clear input"
0291     % button
0292 
0293          LTPDAinvar={};
0294        % LTPDAoutvar={};
0295          set(InputObjList,'Value',1)
0296          set(findobj('Tag', 'infoPanel'), 'String', '')
0297          UpdateListbox();
0298 
0299     end
0300     %----------------------------------------------------------------------
0301 
0302     %----------------------------------------------------------------------
0303     function SaveWorkspaceCallback(varargin)
0304     % Callback function: run when the user click the "Save all"
0305     % button
0306 
0307          try
0308              [FileName,PathName] = uiputfile('*.mat','Save Workspace As');
0309              save(strcat(PathName,FileName),'LTPDAinvar');
0310              disp('Workspace saved')
0311          catch
0312          end
0313     end
0314     %----------------------------------------------------------------------
0315 
0316     %----------------------------------------------------------------------
0317     function LoadWorkspaceCallback(varargin)
0318     % Callback function: run when the user click the "Load workspace"
0319     % button
0320     
0321          try
0322              [FileName,PathName] = uigetfile('*.mat','Load Workspace');
0323              temp = load(strcat(PathName,FileName),'LTPDAinvar');
0324              LTPDAinvar = [LTPDAinvar ; temp.LTPDAinvar];
0325              disp('Workspace loaded')
0326              clear temp
0327              UpdateListbox()
0328          catch
0329          end
0330     end
0331     %----------------------------------------------------------------------
0332 
0333 %%
0334     %----------------------------------------------------------------------
0335     function UpdateListbox(varargin)
0336     % Updates the listboxes
0337 
0338          %==================================
0339          % Update the list of active AOs
0340          xx = size(LTPDAinvar,1);
0341          listInput=cell(xx,1);
0342          if xx>0
0343              for j=1:xx
0344                  switch class(LTPDAinvar{j,1})
0345                      case 'ao'
0346                          anobject  = LTPDAinvar{j,1};
0347                          aonumber  = sprintf('%g',j);
0348                          aoname    = anobject.name;
0349                          aocreated = get(get(anobject.provenance, 'created'),'time_str');
0350                          listInput{j,1} = [aonumber , ' . AO .' , aoname , '__' , aocreated];
0351                      case 'plist'
0352                          objnumber = sprintf('%g',j);
0353                          paramNumb = nparams(LTPDAinvar{j,1});
0354                          objcreated = get(LTPDAinvar{j,1}.created,'time_str');
0355                          listInput{j,1}=[objnumber,' . PLIST .',num2str(paramNumb),' params','__',objcreated];
0356                      case 'specwin'
0357                          objnumber = sprintf('%g',j);
0358                          listInput{j,1}=[objnumber,' . SPECWIN .','__','no creation time'];
0359                      case 'pzmodel'
0360                          objnumber = sprintf('%g',j);
0361                          objcreated = get(LTPDAinvar{j,1}.created,'time_str');
0362                          listInput{j,1}=[objnumber,' . PZMODEL .','__',objcreated];
0363                      case 'miir'
0364                          objnumber = sprintf('%g',j);
0365                          objcreated = get(LTPDAinvar{j,1}.created,'time_str');
0366                          listInput{j,1}=[objnumber,' . MIIR .','__',objcreated];
0367                      otherwise
0368                          if ltpda_isuserobject(LTPDAinvar{j,1})
0369                              objnumber = sprintf('%g',j);
0370                              objclass  = class(LTPDAinvar{j,1});
0371                              if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[objnumber,' . ',objclass]; end
0372                          end
0373                  end
0374              end
0375              for j=xx:-1:1
0376                  if isempty(listInput{j,1})
0377                      listInput(j,:)=[];
0378                  end                     
0379              end
0380          else
0381              listInput{1,1}='The memory is empty';
0382          end
0383          if ~isempty(InputObjList)
0384              set(InputObjList,'Value',1)
0385              set(InputObjList,'String',listInput)
0386          end
0387          
0388     end
0389     %----------------------------------------------------------------------
0390 
0391     %----------------------------------------------------------------------
0392     function hListObjsCallback(hObject, varargin)   
0393     % This callback is called whenever the user double click upon one of
0394     % the AOs in use.
0395     
0396         if ~isempty(varargin{1}) && varargin{1}==1 && size(LTPDAinvar,1)>0
0397                 val = get(hObject, 'Value');
0398                 if length(val) == 1
0399                     lines = get(hObject, 'String');
0400                     objnumb = str2double(deblank(strtok(lines{val})));
0401                     objtxt = display(LTPDAinvar{objnumb});
0402                 else
0403                     objtxt = '';
0404                 end
0405                 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
0406         elseif size(LTPDAinvar,1)>0
0407             if strcmp(get(gcf,'SelectionType'),'normal')
0408                 val = get(hObject, 'Value');
0409                 if length(val) == 1
0410                     lines = get(hObject, 'String');
0411                     objnumb = str2double(deblank(strtok(lines{val})));
0412                     try objtxt = display(LTPDAinvar{objnumb}); catch objtxt = class(LTPDAinvar{objnumb}); end
0413                 else
0414                     objtxt = '';
0415                 end
0416                 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
0417             end
0418 
0419             if strcmp(get(gcf,'SelectionType'),'open')
0420                 set_param(gcbsh,'Selected','off');
0421                 newBlkHandle=add_block('ltpda_library/Input/AO', strcat(currentsystem,'/AO1'),'MakeNameUnique', 'on');
0422                 children=get_param(newBlkHandle,'Blocks');
0423                 inputblock=strcat(get(newBlkHandle,'Path'),'/',get(newBlkHandle,'Name'),'/',children{1});
0424                 set_param(inputblock,'Value',int2str(get(hObject,'Value')));
0425                 % Modify the block annotation:
0426                 set_param(newBlkHandle,'AttributesFormatString',int2str(get(hObject,'Value')));
0427                 set_param(newBlkHandle,'Selected','on');
0428             end
0429         end
0430          
0431     end
0432     %----------------------------------------------------------------------
0433 
0434 %%
0435     %----------------------------------------------------------------------
0436     function hNewButtonCallback(varargin)
0437     % Callback function: run when the user click the "New model" button.
0438     % It starts also the timer associated to the continuous selection check
0439     % (this must be changed in order to allow multiple system execution).
0440 
0441          hour          = datestr(now,13); % HH:MM:SS
0442          hour(3)       = hour(4);hour(4)=hour(5);hour(5)=hour(7);hour(6)=hour(8);
0443          currentsystem = strcat(ltpdaGUIstatus{1,1},'_',datestr(now,7),datestr(now,5),datestr(now,11),'_',hour(1:6));
0444          new_system(currentsystem)
0445          open_system(currentsystem)
0446          
0447          systemHandle = get_param(gcs,'Handle');
0448          set(systemHandle,'SolverName','VariableStepDiscrete');
0449          set(systemHandle,'StopTime','0.0');
0450          set(systemHandle,'Location',[200 100 1100 600]);
0451          
0452          caption = strcat(gcs,'/1');
0453          add_block('built-in/Note',caption,'Position', [100 0 0 400],'UserData',1);
0454          annotationHandle = find_system(gcs, 'FindAll', 'on', 'type', 'annotation');
0455          caption1 = ['          Analysis designed by ',ltpdaGUIstatus{1,1}];
0456        % caption1b = strcat('creator: ',char(java.lang.System.getProperties.getProperty('user.name')));
0457          caption2 = ['created (UTC): ',get(time,'time_str')];
0458          caption3 = ['                 IP: ',char(getHostAddress(java.net.InetAddress.getLocalHost))];
0459          caption4 = ['               OS: ',computer];
0460          caption5 = ['MATLAB ver: ',getappdata(0, 'matlab_version')];
0461          caption6 = ['   LTPDA ver: ',getappdata(0, 'ltpda_version')];
0462          caption = strvcat(caption1,caption2,caption3,caption4,caption5,caption6); %#ok<VCAT>
0463          set_param(annotationHandle, 'HorizontalAlignment','left','Text',caption,'Tag','ltpda model')
0464          set_param(annotationHandle,'ClickFcn','disp(''You''''re not allowed to change this'')')
0465 
0466     end
0467     %----------------------------------------------------------------------
0468 
0469     %----------------------------------------------------------------------
0470     function hSaveCallback(varargin)   
0471     % This callback is called whenever the user click the 'Save' button to
0472     % store the current model on disk.
0473     
0474          if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0475              inputBlockHandles = get_param(find_system(bdroot,'AncestorBlock','ltpda_library/Input/AO'),'handle');
0476              for i=1:numel(inputBlockHandles)
0477                  children   = get_param(inputBlockHandles{i},'Blocks');
0478                  inputblock = strcat(get(inputBlockHandles{i},'Path'),'/',get(inputBlockHandles{i},'Name'),'/',children{1});
0479                  currIndex(i)  = str2double(get_param(inputblock,'Value'));
0480                  if currIndex(i)~=0
0481                      objcommand = string(LTPDAinvar{currIndex(i)});
0482                      set_param(inputBlockHandles{i},'Description',objcommand);
0483                  end
0484              end
0485 
0486              oldName  = bdroot;
0487              if ~isempty(oldName) && ~isempty(find_system(oldName,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0488                  try
0489                      [fileName,filePath] = uiputfile([oldName,'.mdl'],'Choose destination folder');
0490                      fileName = [filePath,fileName];
0491                      save_system(oldName,fileName)
0492                  catch
0493                  end
0494              end
0495          end
0496          
0497     end
0498     %----------------------------------------------------------------------
0499 
0500     %----------------------------------------------------------------------
0501     function hOpenCallback(varargin)   
0502     % This callback is called whenever the user click the 'Open' button, to
0503     % retrieve a previously saved model from disk.
0504     
0505          try
0506              [fileName,filePath] = uigetfile('.mdl','Choose source file');
0507              fileName = [filePath,fileName];
0508              open_system(fileName)
0509 
0510              inputBlockHandles = get_param(find_system(gcs,'AncestorBlock','ltpda_library/Input/AO'),'handle');
0511              for i=1:numel(inputBlockHandles)
0512                  objcommand = get_param(inputBlockHandles{i},'Description');
0513                  if ~isempty(objcommand)
0514                      xx         = size(LTPDAinvar,1);
0515                      objcommand = ['LTPDAinvar{',num2str(xx+1),',1}=',objcommand,';LTPDAinvar{',num2str(xx+1),',2}=0'];
0516                      eval(objcommand);
0517 
0518                      % Update the pointer inside the input block and the annotation:
0519                      children   = get_param(inputBlockHandles{i},'Blocks');
0520                      inputblock = strcat(get(inputBlockHandles{i},'Path'),'/',get(inputBlockHandles{i},'Name'),'/',children{1});
0521                      set_param(inputblock,'Value',num2str(xx+1))
0522                      set_param(inputBlockHandles{i},'AttributesFormatString',num2str(xx+1));
0523                  end
0524              end
0525              
0526              UpdateListbox()
0527          catch
0528          end
0529          
0530 %          currSelectObjs = get(InputObjList,'Value');
0531 %          try
0532 %              [fileName,filePath] = uiputfile([gcs,'.xml'],'Choose destination folder');
0533 %              for i=1:numel(currSelectObjs)
0534 %                  currAO = LTPDAinvar{currSelectObjs(i)};
0535 %                  currAO = attachmdl(currAO);
0536 %                  fileName = [filePath,'/',gcs,'_',num2str(i),'_',currAO.name,'.xml'];
0537 %                  save(currAO,fileName);
0538 %                  disp(sprintf('Object %s saved (with current Simulink model attached)',currAO.name))
0539 %              end
0540 %          catch
0541 %          end
0542          
0543     end
0544     %----------------------------------------------------------------------
0545 
0546 %%
0547     %----------------------------------------------------------------------
0548     function MaintainResults(hObject,varargin)   
0549     % This callback is called whenever the user check the 'Maintain
0550     % Results' box.
0551         setappdata(0,'maintainresults',get(hObject,'Value'));
0552     end
0553     %----------------------------------------------------------------------
0554 
0555     %----------------------------------------------------------------------
0556     function StartExec(varargin)   
0557     % This callback is called whenever the user click the 'Start' button.
0558     
0559          if isempty(bdroot) || isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model')), return; end
0560              
0561          disp('============================')
0562          disp('   Beginning the analysis')
0563          disp('============================')
0564          stop(timerfindall)
0565            button = findobj('Tag','StartButton1');
0566            set(button,'CData',imread('startred.jpg'));
0567            button = findobj('Tag','StartButton2');
0568            set(button,'CData',imread('startred.jpg'));
0569          progressBar();
0570          pause(0.1);
0571          currSystem = bdroot;
0572          addterms(currSystem)
0573                   
0574 %          if isempty(loopstatus) || loopstatus==0
0575 %              [ttt,xxx,yyy] = sim(gcs);
0576 %          end
0577 
0578 %        % Now the cycle to delete the objects produced in the analysis:
0579 %        % anobY=size(LTPDAinvar,1);
0580 %          for j=anobY:-1:1
0581 %              if LTPDAinvar{j,2}==0
0582 %                  LTPDAinvar(j,:)=[];
0583 %              end
0584 %          end
0585 
0586 % % % ==================================================================
0587 % % % Execution with nested loops
0588 % % % ==================================================================
0589 % % if loopstatus==1
0590 % %
0591 % % %   Example:      n°  order    appearance
0592 % % %   paramLoop={    1   1  ...   x-------
0593 % % %                  2   2  ...    x------
0594 % % %                  3   3  ...     x-----
0595 % % %                  4   2  ...    x------
0596 % % %                  5   3  ...     x-----
0597 % % %                  6   1  ...   x-------
0598 % %
0599 % %
0600 % %     branches=[];
0601 % %     [xx,yy]=size(paramLoop);
0602 % %   % xx is the total number of parameters to change in loops.
0603 % %
0604 % %     for ii=1:xx
0605 % %         if ii==xx || paramLoop{ii+1,2}<=paramLoop{ii,2}
0606 % %             branches=[branches,ii];
0607 % %         end
0608 % %     end
0609 % %
0610 % %   % 'branches' contains the ordinal number of those rows which do not have
0611 % %   % a children row, ie. the following rows have higher order. In the
0612 % %   % example, branches = [ 3 , 5 , 6 ];
0613 % %
0614 % %     family={};
0615 % %     numbIter={};
0616 % %     for ii=1:numel(branches)
0617 % %         currOrder=paramLoop{branches(ii),2};
0618 % %         family{ii,1}  = 0;
0619 % %         numbIter{ii,1} = 1;
0620 % %         for jj=branches(ii):-1:1
0621 % %             if paramLoop{jj,2}==currOrder
0622 % %                 family{ii,currOrder+1}  = jj;
0623 % %                 family{ii,1}            = family{ii,1}+1;
0624 % %                 numbIter{ii,currOrder+1} = paramLoop{jj,6};
0625 % %                 numbIter{ii,1}           = numbIter{ii,1}*paramLoop{jj,6};
0626 % %                 currOrder               = paramLoop{jj,2}-1;
0627 % %             end
0628 % %         end
0629 % %     end
0630 % %   % 'family' contains all the parents information for each branch: the
0631 % %   % first column contains how many parents there are. In the example:
0632 % %   % family = {  3    1    2    3
0633 % %   %             3    1    4    5
0634 % %   %             1    6              }
0635 % %   % Similarly, numbIter contains the number of iteration necessary to
0636 % %   % complete each param. The first column contains the total for each
0637 % %   % branch/row.
0638 % %   % numbIter   = {  40   2    4    5
0639 % %   %                 36   2    6    3
0640 % %   %                 10   10             }
0641 % %
0642 % %     for ii=1:numel(branches)
0643 % %         x = family{ii,1}; % x = how many params to change in this branch
0644 % %         status=ones(1,x); % status shows the current step in the loop;
0645 % %                           % [2,3,5] means eg. that we've executed the 2nd
0646 % %                           % value for the first param, the 3rd for the
0647 % %                           % second param, and the 5th for the third param.
0648 % %
0649 % %         for iter=1:numbIter{ii,1}
0650 % %           % ==============================================================
0651 % %           % Here goes what must be executed
0652 % %           % ==============================================================
0653 % %
0654 % %             if x==1
0655 % %                 disp(sprintf('===== Current status is: ====== %d',status(1)));
0656 % %             elseif x==2
0657 % %                 disp(sprintf('===== Current status is: ====== %d %d',status(1),status(2)));
0658 % %             elseif x==3
0659 % %                 disp(sprintf('===== Current status is: ====== %d %d %d',status(1),status(2),status(3)));
0660 % %             end
0661 % %
0662 % %             for nn=1:numel(status)
0663 % %                 value=paramLoop{family{ii,nn+1},9}(status(nn));
0664 % %                 paramcommand = BuildCommand(value,family{ii,nn+1});
0665 % %                 set(paramLoop{family{ii,nn+1},3},'Description',paramcommand);
0666 % %             end
0667 % %
0668 
0669 try
0670     
0671 % ========================================================================
0672           % ==============================================================
0673           % ==============================================================
0674           % ==============================================================
0675                              [ttt,xxx,yyy] = sim(currSystem);  %#ok<NASGU>
0676           % ==============================================================
0677           % ==============================================================
0678           % ==============================================================
0679             
0680           % ==============================================================
0681 % ========================================================================
0682 % %             for jj=x:-1:1
0683 % %                 if status(jj)<numbIter{ii,jj+1} % then we still have to complete iterations on i-th row
0684 % %                     status(jj)=status(jj)+1;
0685 % %                     if jj~=x % if we've just increased a line which is not the last one, set to zero the lower lines
0686 % %                         for kk=jj+1:x
0687 % %                             status(kk)=1;
0688 % %                         end
0689 % %                     end
0690 % %                     break
0691 % %                 end
0692 % %             end
0693 % %         end
0694 % %     end
0695 % %
0696 % % end
0697 % % % ==================================================================
0698 % % % End of execution with nested loops
0699 % % % ==================================================================
0700 
0701     close(findobj('Name','LTPDA Progress Bar'))
0702     
0703   % Remove intermediate results:
0704     keepRes = getappdata(0,'maintainresults');
0705     if ~keepRes
0706         for i=size(LTPDAinvar,1):-1:1
0707             if LTPDAinvar{i,2}==0, LTPDAinvar(i,:)=[]; end                
0708         end
0709     end
0710 
0711   % Reshape the results:
0712     for i = size(LTPDAinvar,1):-1:1
0713         objLength = numel(LTPDAinvar{i,1});
0714         if objLength > 1 && ltpda_isuserobject(LTPDAinvar{i,1})
0715           % Create empty rows beneath:
0716             if i~=size(LTPDAinvar,1) % ie, it's not the last row
0717               % Copy down elements:
0718                 for k = (size(LTPDAinvar,1)+objLength-1):-1:(i+objLength)
0719                     LTPDAinvar{k,1} = LTPDAinvar{k-objLength+1,1};
0720                     LTPDAinvar{k,2} = LTPDAinvar{k-objLength+1,2};
0721                 end
0722               % Free copied rows:
0723                 for k = i+1:i+objLength-1
0724                     LTPDAinvar(k,:) = {[],0};
0725                 end
0726             end
0727           % Relocate vector elements:
0728             for j = objLength:-1:1
0729                 LTPDAinvar{i+j-1,1} = LTPDAinvar{i,1}(j);
0730                 LTPDAinvar{i+j-1,2} = LTPDAinvar{i,2};
0731             end
0732         end
0733     end
0734     UpdateListbox();
0735     button = findobj('Tag','StartButton1');
0736     set(button,'CData',imread('startgreen.jpg'));
0737     button = findobj('Tag','StartButton2');
0738     set(button,'CData',imread('startgreen.jpg'));
0739     start(timerfindall)
0740     
0741 % ==================================
0742 catch
0743 % ==================================
0744     
0745   % Reshape the results:
0746     for i = size(LTPDAinvar,1):-1:1
0747         objLength = numel(LTPDAinvar{i,1});
0748         if objLength > 1 && ltpda_isuserobject(LTPDAinvar{i,1})
0749           % Create empty rows beneath:
0750             if i~=size(LTPDAinvar,1) % ie, it's not the last row
0751               % Copy down elements:
0752                 for k = (size(LTPDAinvar,1)+objLength-1):-1:(i+objLength)
0753                     LTPDAinvar{k,1} = LTPDAinvar{k-objLength+1,1};
0754                     LTPDAinvar{k,2} = LTPDAinvar{k-objLength+1,2};
0755                 end
0756               % Free copied rows:
0757                 for k = i+1:i+objLength-1
0758                     LTPDAinvar(k,:) = {[],0};
0759                 end
0760             end
0761           % Relocate vector elements:
0762             for j = objLength:-1:1
0763                 LTPDAinvar{i+j-1,1} = LTPDAinvar{i,1}(j);
0764                 LTPDAinvar{i+j-1,2} = LTPDAinvar{i,2};
0765             end
0766         end
0767     end
0768     UpdateListbox();
0769     button = findobj('Tag','StartButton1');
0770     set(button,'CData',imread('startgreen.jpg'));
0771     button = findobj('Tag','StartButton2');
0772     set(button,'CData',imread('startgreen.jpg'));
0773     start(timerfindall)
0774 
0775     rethrow(lasterror)
0776 end
0777 
0778     end
0779     %----------------------------------------------------------------------
0780 
0781 %%
0782 
0783 end  % end of ltpdagui

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003