Home > m > gui > gltpda > buildLibrary.m

buildLibrary

PURPOSE ^

Function to update the library with all the methods functions.

SYNOPSIS ^

function buildLibrary(varargin)

DESCRIPTION ^

 Function to update the library with all the methods functions.
  $Id: buildLibrary.m,v 1.9 2008/08/04 20:07:33 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function buildLibrary(varargin)
0002 % Function to update the library with all the methods functions.
0003 %  $Id: buildLibrary.m,v 1.9 2008/08/04 20:07:33 nicola Exp $
0004 
0005 %   clear all
0006   bdclose('all');
0007   disp('=====================================================')
0008   disp('Updating the LTPDA Library...');
0009 
0010 % Retrieve the list of all functions and methods:
0011 ltpda_versions
0012 
0013 % This creates a variable named 'versions', so structured:
0014 % | 1.filename | 2.functionName | 3.version | 4.date | 5.hour | 6.author | 7.folder | 8.hash | 9.category | 10.class |
0015 % [The 'class' is set to None if it's not a method]
0016 
0017   origSize = size(versions,1); %#ok<NODEF>
0018   disp(['The overall number of LTPDA functions is ',num2str(origSize),'.'])
0019 
0020 
0021 % =========================================================================
0022 %%              Remove functions not meant for the library:
0023 % =========================================================================
0024 
0025    % Remove all test functions:
0026      for i=origSize:-1:1
0027          if numel(versions{i,2})>4 && strcmpi(versions{i,2}(1:5),'test_')
0028              versions(i,:)=[];
0029          end
0030      end
0031      newSize = size(versions,1);
0032      disp(['--- ',num2str(origSize-newSize),' test functions ignored'])
0033      origSize = newSize;
0034 
0035    % Remove all Internal functions:
0036      for i=origSize:-1:1
0037          if numel(versions{i,9})>7 && strcmpi(versions{i,9}(1:8),'Internal')
0038              versions(i,:)=[];
0039          end
0040      end
0041      newSize = size(versions,1);
0042      disp(['--- ',num2str(origSize-newSize),' Internal functions ignored'])
0043      origSize = newSize;
0044 
0045    % Remove all private functions:
0046      for i=origSize:-1:1
0047          x = numel(versions{i,10});
0048          if x>8 && strcmpi(versions{i,10}(x-7:x),'/private')
0049              versions(i,:)=[];
0050          end
0051      end
0052      newSize = size(versions,1);
0053      disp(['--- ',num2str(origSize-newSize),' private functions ignored'])
0054      origSize = newSize;
0055 
0056    % Remove all remaining examples:
0057      for i=origSize:-1:1
0058          x = numel(versions{i,7});
0059          if x>10 && strcmpi(versions{i,7}(x-9:x),'/examples/')
0060              versions(i,:)=[];
0061          end
0062      end
0063      newSize = size(versions,1);
0064      disp(['--- ',num2str(origSize-newSize),' examples ignored'])
0065      origSize = newSize;
0066 
0067    % Remove templates:
0068      for i=origSize:-1:1
0069          funcName = versions{i,2};
0070          x = numel(funcName);
0071          if x>9 && strcmpi(funcName(x-8:x),'_template')
0072              versions(i,:)=[];
0073          end
0074      end
0075      newSize = size(versions,1);
0076      disp(['--- ',num2str(origSize-newSize),' templates ignored'])
0077      origSize = newSize;
0078 
0079    % Remove all uncategorized functions:
0080      for i=origSize:-1:1
0081          if isempty(versions{i,9})
0082              versions(i,:)=[];
0083          end
0084      end
0085      newSize = size(versions,1);
0086      disp(['--- ',num2str(origSize-newSize),' uncategorized functions ignored'])
0087      origSize = newSize;
0088 
0089    % Remove all functions with no class:
0090      for i=origSize:-1:1
0091          if strcmp(versions{i,10},'None')
0092              versions(i,:)=[];
0093          end
0094      end
0095      newSize = size(versions,1);
0096      disp(['--- ',num2str(origSize-newSize),' functions with class ''None'' ignored'])
0097      origSize = newSize;
0098      
0099    % Remove all functions with non user classes:
0100      for i=origSize:-1:1
0101          if numel(versions{i,10})>5 && strncmpi(versions{i,10},'ltpda_',6)
0102             versions(i,:)=[];
0103          elseif numel(versions{i,10})>3 && strncmpi(versions{i,10},'data',4)
0104             versions(i,:)=[];
0105          end
0106      end
0107      newSize = size(versions,1);
0108      disp(['--- ',num2str(origSize-newSize),' functions with class ''ltpda_***'' ignored'])
0109      origSize = newSize;
0110 % =========================================================================
0111 %%                    Prepare the library for update:
0112 % =========================================================================
0113 
0114     disp(['The number of LTPDA functions for the library is ',num2str(origSize),'.'])
0115        numbFunctions = 0;
0116        funcCategories = {};
0117        for i=1:origSize
0118            if numel(versions{i,10})>3 && strcmpi(versions{i,10}(1:4),'None')
0119                numbFunctions = numbFunctions +1;
0120                if ~ismember(versions{i,9},funcCategories)
0121                    funcCategories = [funcCategories,versions{i,9}];
0122                end
0123            end
0124        end
0125      % These are the root level subsystems:
0126        funcCategories = [funcCategories,'Methods'];
0127     disp([num2str(numbFunctions),' are functions, ',num2str(origSize-numbFunctions),' are methods.'])
0128     disp('=====================================================')
0129    
0130     load_system libraryBase.mdl
0131     open ltpda_library.mdl
0132     set(get_param(gcs,'Handle'),'Lock','off')
0133     
0134   % Delete all functions/methods folders in the root and create them anew:
0135     for i=1:numel(funcCategories)
0136         try %#ok<ALIGN>
0137         subsystem = find_system(bdroot,'Name',funcCategories{i});
0138         subsysPos = get(get_param(subsystem{1},'Handle'),'Position');
0139         delete_block(subsystem);
0140         catch end %#ok<CTCH>
0141         SubSystemBlock = add_block('libraryBase/SubSystName',['ltpda_library/',funcCategories{i}]);
0142         disp(['-- ',funcCategories{i},' updated'])
0143         if ~isempty(subsystem), set(SubSystemBlock,'Position',subsysPos); end
0144         set(SubSystemBlock,'LinkStatus','inactive')
0145         set(SubSystemBlock,'MaskDisplay',['disp(''',funcCategories{i},''')'])
0146         clear subsysPos subsystem SubSystemBlock
0147     end
0148 
0149   % Creating the Methods/<class> folder for each class anew:
0150     classes = utils.helper.ltpda_classes;
0151 
0152   % Remove improper classes:
0153     for i=numel(classes):-1:1
0154        if (numel(classes{i})>5 && strncmpi(classes{i},'ltpda_',6)) || (numel(classes{i})>3 && strncmpi(classes{i},'data',4)),          
0155             classes(i)=[];
0156        end;
0157     end
0158 
0159     for i=1:numel(classes)
0160         classFolder = add_block('libraryBase/SubSystName',['ltpda_library/Methods/',classes{i}]);
0161         set(classFolder,'LinkStatus','inactive')
0162         set(classFolder,'MaskDisplay',['disp(''',classes{i},''')'])
0163         % Cycle to set proper position:
0164         x=1;y=1;
0165         while ~isempty(find_system('ltpda_library/Methods','SearchDepth',1,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)]))
0166             y=y+1;
0167             if y==6, x=x+1; y=1; end
0168         end
0169         set(classFolder,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)])
0170     end
0171     
0172 % =========================================================================
0173 %%                     Rebuild the library contents:
0174 % =========================================================================
0175 
0176   for i=1:origSize
0177           currMethod = versions{i,2};
0178           currCateg = versions{i,9};
0179           currClass = versions{i,10};
0180           
0181           % Check to verify whether a folder for this category exists:
0182             categFolder = find_system(['ltpda_library/Methods/',currClass],'SearchDepth',1,'Name',currCateg);
0183             try categFolder = categFolder{1}; catch end %#ok<CTCH>
0184             if isempty(categFolder)
0185                 categFolder = add_block('libraryBase/SubSystName',['ltpda_library/Methods/',currClass,'/',currCateg]);
0186                 set(categFolder,'LinkStatus','inactive')
0187                 set(categFolder,'MaskDisplay',['disp(''',currCateg,''')'])
0188               % Cycle to set proper position:
0189                 x=1;y=1;
0190                 while ~isempty(find_system(['ltpda_library/Methods/',currClass],'SearchDepth',1,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)]))
0191                     aaa = find_system(['ltpda_library/Methods/',currClass],'SearchDepth',1,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)]);
0192                     if (strcmp(aaa{1},['ltpda_library/Methods/',currClass]) && numel(aaa)==1), break; end
0193                     y=y+1;
0194                     if y==5, x=x+1; y=1; end
0195                 end                
0196                 set(categFolder,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)])
0197             end
0198 
0199           % Adding the proper method block:
0200             if strcmp(currCateg,'Constructor')
0201                 blockH = add_block('libraryBase/constructor',['ltpda_library/Methods/',currClass,'/',currCateg,'/',currMethod]);
0202             elseif strcmp(currCateg,'Output')
0203                 blockH = add_block('libraryBase/output',['ltpda_library/Methods/',currClass,'/',currCateg,'/',currMethod]);
0204             elseif ~strcmp(currMethod,'Contents')
0205                 blockH = add_block('libraryBase/function',['ltpda_library/Methods/',currClass,'/',currCateg,'/',currMethod]);
0206             end
0207 
0208           % Cycle to set proper position:
0209             x=1;y=1;
0210             while ~isempty(find_system(['ltpda_library/Methods/',currClass,'/',currCateg],'SearchDepth',1,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)]))
0211                 aaa = find_system(['ltpda_library/Methods/',currClass,'/',currCateg],'SearchDepth',1,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)]);
0212                 if (strcmp(aaa{1},['ltpda_library/Methods/',currClass,'/',currCateg]) && numel(aaa)==1), break; end
0213                 y=y+1;
0214                 if y==5, x=x+1; y=1; end
0215             end
0216             set(blockH,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)])
0217             
0218             set(blockH,'LinkStatus','inactive')
0219             set(blockH,'MaskDisplay',['disp(''',currMethod,''')'])
0220             set(blockH,'Tag',['method ',currClass])
0221             set(blockH,'Description','')
0222             maskText = eval(['help(''',currClass,'/',currMethod,''');']);
0223             maskText = strtok(maskText,'%%');
0224             set(blockH,'MaskDescription',maskText);
0225             set(blockH,'OpenFcn','ltpdagui(''callback'',1,''redraw'',2);if (~strcmp(bdroot,''ltpda_library'') && ~isempty(findobj(''Tag'',''LTPDAGUI''))), figure(findobj(''Tag'',''LTPDAGUI'')); end');
0226             childpath = find_system(blockH,'LookUnderMasks','all','BlockType','M-S-Function');
0227             set(childpath,'Tag',currMethod)
0228             set(childpath,'Name',currMethod)
0229             set(childpath,'Description','')
0230   end
0231 
0232   % Setting proper position and size for subsystem folders in the root:
0233     subsystems = find_system(bdroot,'LookUnderMasks','all','SearchDepth',1,'BlockType','SubSystem');
0234     x=1; y=1;
0235     for i=1:numel(subsystems)
0236         set_param(subsystems{i},'Position',[30+100*(y-1) , 30+100*(x-1) , 95+100*(y-1) , 90+100*(x-1)])
0237         y=y+1;
0238         if y==4, x=x+1; y=1; end
0239     end
0240   
0241     close_system libraryBase.mdl
0242     
0243   % Update the annotation:
0244     annotationHandle = find_system(bdroot,'FindAll','on','SearchDepth',1,'type','annotation');
0245     caption1 = 'LTPDA Library';
0246     caption2 = ['v3.0 - ',datestr(now,1)];
0247     caption = strvcat(caption1,caption2); %#ok<VCAT>
0248     set_param(annotationHandle, 'HorizontalAlignment','center','Text',caption)
0249 
0250     warning off all
0251     save_system ltpda_library.mdl
0252     warning on all
0253     close_system ltpda_library.mdl
0254 
0255 end
0256

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003