wavemngr.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:30k
源码类别:

波变换

开发平台:

Matlab

  1. function varargout = wavemngr(option,varargin)
  2. %WAVEMNGR Wavelet manager.
  3. %   WAVEMNGR is a wavelet manager used to add, delete, restore
  4. %   or read wavelets.
  5. %
  6. %   WAVEMNGR('add',FN,FSN,WT,NUMS,FILE) or
  7. %   WAVEMNGR('add',FN,FSN,WT,NUMS,FILE,B) or 
  8. %   WAVEMNGR('add',FN,FSN,WT,{NUMS,TYPNUMS},FILE) or
  9. %   WAVEMNGR('add',FN,FSN,WT,{NUMS,TYPNUMS},FILE,B)
  10. %   adds a new wavelet family.
  11. %     FN  = family name (string).
  12. %     FSN = family short name (string).
  13. %
  14. %     WT defines the wavelet type: 
  15. %     WT = 1 for orthogonal wavelets.
  16. %     WT = 2 for biorthogonal wavelets.
  17. %     WT = 3 for wavelet with scale function.
  18. %     WT = 4 for wavelet without scale function.
  19. %     WT = 5 for complex wavelet without scale function.
  20. %
  21. %     If the wavelet is a single one, NUMS = ''.
  22. %       examples: mexh, morl.
  23. %     If the wavelet is part of a finite family of wavelets, NUMS
  24. %       is a string containing a blank separated list of items
  25. %       representing wavelet parameters.
  26. %       example: bior, NUMS = '1.1 1.3 ... 4.4 5.5 6.8'.
  27. %     If the wavelet is part of an infinite family of wavelets, 
  28. %       NUMS is a string containing a blank separated list of 
  29. %       items representing wavelet parameters, terminated by the 
  30. %       special sequence **.
  31. %       examples: 
  32. %         db,    NUMS = '1 2 3 4 5 6 7 8 9 10 **'.
  33. %         shan,  NUMS = '1-1.5 1-1 1-0.5 1-0.1 2-3 **'
  34. %     In these last two cases, TYPNUMS specifies the wavelet parameter 
  35. %       input format: 'integer' or 'real' or 'string'; the default 
  36. %       value is 'integer'.
  37. %       examples: db,   TYPNUMS = 'integer'
  38. %                 bior, TYPNUMS = 'real'
  39. %                 shan, TYPNUMS = 'string'
  40. %
  41. %     FILE  = MAT-file or M-file name (string).
  42. %
  43. %     B = [lb ub] specifies lower and upper bounds of
  44. %     effective support for wavelets of type = 3, 4 or 5.
  45. %
  46. %   WAVEMNGR('del',N), deletes a wavelet or a wavelet family where
  47. %     N is the wavelet name or the family short name.
  48. %
  49. %   WAVEMNGR('restore') restores the previous 
  50. %     wavelets.asc ASCII-file.
  51. %   WAVEMNGR('restore',IN2) restores the initial 
  52. %     wavelets.asc ASCII-file.
  53. %
  54. %   OUT1 = WAVEMNGR('read') returns all wavelets family names.
  55. %   OUT1 = WAVEMNGR('read',IN2) returns all wavelet names.
  56. %
  57. %   OUT1 = WAVEMNGR('read_asc') returns all wavelets information
  58. %   retrieved from wavelets.asc ASCII-file.
  59. %----------------------
  60. %   INTERNAL OPTIONS.
  61. %----------------------
  62. %   WAVEMNGR('create')
  63. %   creates wavelets.inf MAT-file using wavelets.asc ASCII-file.
  64. %
  65. %   OUT1 = WAVEMNGR('load') or WAVEMNGR('load')
  66. %   loads Wavelets_Info from wavelets.inf matfile,
  67. %   and puts it in the global variable: Wavelets_Info.
  68. %
  69. %   WAVEMNGR('clear') clear the global Wavelets_Info.
  70. %
  71. %   [OUT1,OUT2,OUT3,OUT4,OUT5,OUT6] = WAVEMNGR('indw',W)
  72. %   returns:
  73. %   family indice, number indice,
  74. %   family, number for the wavelet W.
  75. %   OUT5 is the family table of number.
  76. %   OUT6 is a flag for GUI.
  77. %
  78. %   OUT1 = WAVEMNGR('indf',F) returns indice
  79. %   for wavelet family F (short name).
  80. %
  81. %   varargout = wavemngr('fields',varargin) see below.
  82. %
  83. %   OUT1 = WAVEMNGR('read_struct')
  84. %   OUT1 gives all wavelets structures.
  85. %   OUT1 = WAVEMNGR('read_struct',NUMS)
  86. %   OUT1 gives the wavelets structures.
  87. %   specified by NUMS.
  88. %
  89. %   OUT1 = WAVEMNGR('tfsn') or WAVEMNGR('tfsn',T)
  90. %   returns shortname-table (of type = T : 'dwt' or 'cwt' or 'owt' or 'ccwt').
  91. %
  92. %   OUT1 = WAVEMNGR('tfn') or out1 = WAVEMNGR('tfn',T)
  93. %   returns name-table (of type = T : 'dwt' or 'cwt' or 'owt' or 'ccwt').
  94. %
  95. %   OUT1 = WAVEMNGR('isbior',W)
  96. %   returns 1 for biorthogonal wavelets.
  97. %
  98. %   [FAM,NUM] = WAVEMNGR('fam_num',W) returns
  99. %   family and number for the wavelet W.
  100. %
  101. %   LEN = WAVEMNGR('length',W) returns the
  102. %   length of the support of the wavelet W.
  103. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  104. %   Last Revision: 26-May-2003.
  105. %   Copyright 1995-2004 The MathWorks, Inc.
  106. % $Revision: 1.17.4.2 $
  107. global Wavelets_Info
  108. %----------------------%
  109. % Wavelets Structures. %
  110. %--------------------------------------------------------%
  111. % Wavelets_Info is a  structure array with size [nb_fam 1]
  112. %
  113. % Wavelet_Struct =
  114. %   struct(...
  115. %     'index'           integer
  116. %     'familyName'      string
  117. %     'familyShortName' string
  118. %     'type'            integer
  119. %     'tabNums'         matrix of string
  120. %     'typNums'         string
  121. %     'file'            string
  122. %     'bounds'          string
  123. %     );
  124. %---------------------------------------------------------%
  125. % Files Names.
  126. %--------------
  127. bin_ini_file = 'wavelets.bin';
  128. asc_ini_file = 'wavelets.ini';
  129. bin_file = 'wavelets.inf';
  130. asc_file = 'wavelets.asc';
  131. sav_file = 'wavelets.prv';
  132. if nargin==0 , option = 'create' ; end
  133. % Miscellaneous Values.
  134. %----------------------
  135. nb_InfoByWave =  7;
  136. NB_FamInWTB   = 11;
  137. WaveTypePOS   = [1:5];
  138. switch option
  139.     case 'load'
  140.       if isempty(Wavelets_Info)
  141.           try
  142.               load(bin_file,'-mat')
  143.           catch
  144.               try
  145.                   load(bin_ini_file,'-mat')
  146.               catch
  147.                   clc
  148.                   disp(' ');
  149.                   disp('---------------------------------------------');
  150.                   sprintf('*** File : %s not found ! ***', bin_ini_file);
  151.                   disp(['***     Using rescue resource ... !     ***']);
  152.                   disp('---------------------------------------------');
  153.                   disp(' ');
  154.                   Wavelets_Info  = wavemngr('rescue');
  155.               end
  156.           end
  157.       end
  158.       if nargout>0 , varargout{1} = Wavelets_Info; end
  159.     case 'clear' , clear global Wavelets_Info 
  160.     case 'indw'
  161.       % in2 : wavelet name
  162.       %-------------------
  163.       % out1 = i_fam
  164.       % out2 = i_num
  165.       % out3 = fam
  166.       % out4 = num_str
  167.       % out5 = tabNums
  168.       % out6 = flag '**' (for GUI)
  169.       %---------------------------
  170.       if isempty(Wavelets_Info) , wavemngr('load'); end
  171.       nb_fam = size(Wavelets_Info,1);
  172.       wname  = deblankl(varargin{1});
  173.       lwna   = length(wname);
  174.       for i_fam=1:nb_fam
  175.           fam = Wavelets_Info(i_fam).familyShortName;
  176.           len = length(fam);
  177.           ok_wave = 0;
  178.           if lwna>=len
  179.               if fam==wname(1:len)
  180.                   tabNums = Wavelets_Info(i_fam).tabNums;
  181.                   for i_num = 1:size(tabNums,1)
  182.                       num_str = noblank(tabNums(i_num,:));
  183.                       if strcmp(num_str,'no') , num_str = '' ; end
  184.                       if strcmp([fam num_str],wname)
  185.                           ok_wave = 1; add_num = 0; break;
  186.                       end
  187.                   end
  188.                   % test for ** number
  189.                   %------------------
  190.                   if ok_wave==0 && strcmp(num_str,'**') && (lwna>len)
  191.                       typNums = Wavelets_Info(i_fam).typNums;
  192.                       num_str = wname(len+1:lwna);
  193.                       switch typNums
  194.                         case 'integer'
  195.                           num = wstr2num(num_str);
  196.                           if ~isempty(num) && (num==fix(num)) && (0<num)
  197.                               ok_wave = 1; add_num = 1;
  198.                           end
  199.                         case 'real'
  200.                           num = wstr2num(num_str);
  201.                           if ~isempty(num)
  202.                               ok_wave = 1; add_num = 1;
  203.                           end
  204.                         case 'string'
  205.                           ok_wave = 1; add_num = 1;
  206.                       end                        
  207.                   end
  208.  
  209.               end
  210.           end
  211.           if ok_wave , break; end
  212.       end
  213.       if ok_wave
  214.           varargout = {i_fam,i_num};
  215.           if nargout<3 , return; end
  216.           varargout = {varargout{:},fam,num_str,tabNums,add_num};
  217.       else
  218.           msg = sprintf('Invalid wavelet name : %s', wname);
  219.           errargt('Wavelet test',msg,'msg');
  220.           error(['***  ' msg '  ***']);
  221.       end
  222.     case 'indf'
  223.       if isempty(Wavelets_Info) , wavemngr('load'); end
  224.       fsnCell  = {Wavelets_Info(:).familyShortName}';
  225.       fsnInput = deblankl(varargin{1});
  226.       varargout{1} = find(strcmp(fsnInput,fsnCell)==1);
  227.     case 'tfsn'
  228.       if isempty(Wavelets_Info) , wavemngr('load'); end
  229.       fsnCell = {Wavelets_Info(:).familyShortName}';
  230.       varargout{1} = strvcat(fsnCell{:});
  231.       if nargin==2
  232.           wtype = lower(varargin{1});
  233.           if isequal(wtype,'all') , return; end
  234.           tab_type = {Wavelets_Info(:).type}';
  235.           tab_type = cat(1,tab_type{:});
  236.           switch wtype
  237.             case {'dwt'}  , ind = find(tab_type==1 | tab_type==2);
  238.             case {'cwt'}  , ind = find(tab_type>0 & tab_type<5);
  239.             case {'owt'}  , ind = find(tab_type==1);
  240.             case {'ccwt'} , ind = find(tab_type==5);
  241.             case {'666'}
  242.                ind = [find(tab_type==5) ; find(tab_type>0 & tab_type<5)];
  243.           end
  244.           varargout{1} = varargout{1}(ind,:);
  245.        end
  246.     case 'tfn'
  247.       if isempty(Wavelets_Info) , wavemngr('load'); end
  248.       fnCell = {Wavelets_Info(:).familyName}';
  249.       varargout{1} = strvcat(fnCell{:});
  250.       if nargin==2
  251.           wtype = lower(varargin{1});
  252.           if isequal(wtype,'all') , return; end
  253.           tab_type = {Wavelets_Info(:).type}';
  254.           tab_type = cat(1,tab_type{:});
  255.           switch wtype
  256.             case {'dwt'}  , ind = find(tab_type==1 | tab_type==2);
  257.             case {'cwt'}  , ind = find(tab_type>0 & tab_type<5);
  258.             case {'owt'}  , ind = find(tab_type==1);
  259.             case {'ccwt'} , ind = find(tab_type==5);
  260.           end
  261.           varargout{1} = varargout{1}(ind,:);
  262.        end
  263.     case 'fields'
  264.       % in2 = {'ind', wavelet index} or
  265.       % in2 = {'fsn', family shortname} or
  266.       % in2 = {'wn' , wavelet name}
  267.       % or
  268.       % in2 = wavelet name
  269.       %----------------------------
  270.       % in3  ... = field(s) name(s)
  271.       %----------------------------
  272.       % out1 ... = field(s) value(s)
  273.       %-----------------------------
  274.       if iscell(varargin{1})
  275.           in_type = varargin{1}{1};
  276.           arg = varargin{1}{2};
  277.       else
  278.           in_type = 'wn';
  279.           arg = varargin{1};
  280.       end
  281.       switch in_type
  282.           case 'ind'
  283.               if isempty(Wavelets_Info) , wavemngr('load'); end
  284.               i_fam = arg;
  285.  
  286.           case 'fsn' , i_fam = wavemngr('indf',arg);
  287.           case 'wn'  , i_fam = wavemngr('indw',arg);
  288.       end
  289.       nb = nargin-2;
  290.       if nb==0
  291.           varargout{1} = Wavelets_Info(i_fam);
  292.           return;
  293.       end
  294.       for k=1:nb
  295.           switch varargin{k+1}
  296.               case 'ind'     , field = 'index';
  297.               case 'fn'      , field = 'familyName';
  298.               case 'fsn'     , field = 'familyShortName';
  299.               case 'type'    , field = 'type';
  300.               case 'tabNums' , field = 'tabNums';
  301.               case 'typNums' , field = 'typNums';
  302.               case 'file'    , field = 'file';
  303.               case 'bounds'  , field = 'bounds';
  304.               otherwise      , field = '';
  305.           end
  306.           if ~isempty(field)
  307.               varargout{k} = Wavelets_Info(i_fam).(field);
  308.           else
  309.               varargout{k} = Wavelets_Info(i_fam);
  310.           end
  311.       end
  312.     case 'type'
  313.         i_fam = wavemngr('indw',varargin{1});
  314.         varargout{1} = Wavelets_Info(i_fam).('type');
  315.     case 'file'
  316.         i_fam = wavemngr('indw',varargin{1});
  317.         varargout{1} = Wavelets_Info(i_fam).('file');
  318.     case 'fn'
  319.         i_fam = wavemngr('indw',varargin{1});
  320.         varargout{1} = Wavelets_Info(i_fam).('familyName');
  321.     case 'fsn'
  322.         i_fam = wavemngr('indw',varargin{1});
  323.         varargout{1} = Wavelets_Info(i_fam).('familyShortName');
  324.     case {'tabnums','tabNums'}
  325.         i_fam = wavemngr('indf',varargin{1});
  326.         varargout{1} = Wavelets_Info(i_fam).('tabNums');
  327.     case {'typNums'}
  328.         i_fam = wavemngr('indf',varargin{1});
  329.         varargout{1} = Wavelets_Info(i_fam).('typNums');
  330.     case 'bounds'
  331.         i_fam = wavemngr('indw',varargin{1});
  332.         varargout{1} = Wavelets_Info(i_fam).('bounds');
  333.     case 'isbior'
  334.         wname = varargin{1};
  335.         if length(wname)>3,
  336.             wname = wname(1:4);
  337.             varargout{1} = isequal(wname,'bior') | isequal(wname,'rbio');
  338.         else
  339.             varargout{1} = 0;
  340.         end
  341.     case 'fam_num'
  342.         [nul,nul,varargout{1},varargout{2}] = wavemngr('indw',varargin{1});
  343.     case 'length'
  344.         wname = varargin{1};
  345.         [wtype,bounds] = wavemngr('fields',{'wn',wname},'type','bounds');
  346.         switch wtype
  347.             case {1,2}
  348.                 Lo_D = wfilters(wname);
  349.                 varargout{1} = length(Lo_D);
  350.             case {3,4}
  351.                 varargout{1} = bounds(2)-bounds(1)+1;
  352.             otherwise
  353.                 errargt(mfilename,'invalid argument','msg'); error('*');
  354.         end
  355.                                        
  356.     case 'create'
  357.         wavemngr('clear')
  358.         beg_fam = 'Family Name : ';
  359.         fid = fopen(asc_file);
  360.         if fid==-1
  361.             fid   = fopen(asc_ini_file); 
  362.             winfo = fread(fid);
  363.             fclose(fid);
  364.             fid   = fopen(asc_file,'w');
  365.             fwrite(fid,winfo); 
  366.             fclose(fid);
  367.         else
  368.             winfo = fread(fid);
  369.             fclose(fid);
  370.         end
  371.         winfo   = setstr(winfo');
  372.         str_NL  = findNL('string',winfo);
  373.         lennewl = length(str_NL);
  374.         ind_NL  = findstr(str_NL,winfo);
  375.         first   = findstr(beg_fam,winfo)+length(beg_fam);
  376.         nb_fam  = length(first);
  377.         %------------------------------%
  378.         % Building Wavelets Structure. %
  379.         %------------------------------%
  380.         nul = cell(nb_fam,1);
  381.         Wavelets_Info = struct(...
  382.                     'index',nul,           ...
  383.                     'familyName',nul,      ...
  384.                     'familyShortName',nul, ...
  385.                     'type',nul,            ...
  386.                     'tabNums',nul,         ...
  387.                     'typNums',nul,         ...
  388.                     'file',nul,            ...
  389.                     'bounds',nul           ...
  390.                     );
  391.         for j = 1:nb_fam
  392.             i_fam   = first(j);
  393.             indexs  = find(ind_NL>i_fam);
  394.             indexs  = ind_NL(indexs(1:nb_InfoByWave));
  395.             fam     = winfo(i_fam:indexs(1)-1);
  396.             sname   = winfo(indexs(1)+lennewl:indexs(2)-1);
  397.             wtype   = winfo(indexs(2)+lennewl:indexs(3)-1);
  398.             nums    = winfo(indexs(3)+lennewl:indexs(4)-1);
  399.             typNums = winfo(indexs(4)+lennewl:indexs(5)-1);                  
  400.             fname   = winfo(indexs(5)+lennewl:indexs(6)-1);
  401.             bounds  = winfo(indexs(6)+lennewl:indexs(7)-1);
  402.             notspace = ~isspace(nums);
  403.             lnot     = length(notspace);
  404.             index1   = find(notspace==1);
  405.             k0       = index1(1);
  406.             k1       = index1(length(index1));
  407.             indnum   = diff(notspace);
  408.             fnum     = find(indnum==1)+1;
  409.             lnum     = find(indnum==-1);
  410.             if k0==1    , fnum = [1 fnum];  end
  411.             if k1==lnot , lnum = [lnum k1]; end
  412.             nb_num   = length(fnum);
  413.             tabNums  = '';
  414.             for p = 1:nb_num
  415.                 tabNums = strvcat(tabNums,nums(fnum(p):lnum(p)));
  416.             end
  417.             Wavelets_Info(j).index = j;
  418.             Wavelets_Info(j).familyName = fam;
  419.             Wavelets_Info(j).familyShortName = sname;
  420.             Wavelets_Info(j).type = wstr2num(wtype);
  421.             Wavelets_Info(j).tabNums = tabNums;
  422.             Wavelets_Info(j).typNums = typNums;
  423.             Wavelets_Info(j).file = fname;
  424.             Wavelets_Info(j).bounds = wstr2num(bounds);
  425.         end
  426.         try
  427.             save(bin_file,'Wavelets_Info')
  428.         catch
  429.             errargt(mfilename,'Changing Wavelets : Save FAILED !','msg');
  430.         end
  431.     case 'read'
  432.         if isempty(Wavelets_Info) , wavemngr('load'); end
  433.         nb_fam  = size(Wavelets_Info,1);
  434.         sep_fam = '=';
  435.         sep_fam = sep_fam(:,ones(1,35));
  436.         sep_num = '-';
  437.         sep_num = sep_num(:,ones(1,30));
  438.         varargout{1} = sep_fam; 
  439.         tab     = setstr(9);
  440.         families = strvcat(Wavelets_Info(:).familyName);
  441.         tabtab   = tab(ones(1,nb_fam),ones(1,2));
  442.         if  nargin==1
  443.             famSName    = strvcat(Wavelets_Info(:).familyShortName);
  444.             famTAB      = [families tabtab famSName];
  445.             varargout{1}= strvcat(varargout{1},famTAB,sep_fam);
  446.         else
  447.             famTAB = [families tabtab];
  448.             for k =1:nb_fam
  449.                  sfname = Wavelets_Info(k).familyShortName;
  450.                  varargout{1} = strvcat(varargout{1},[famTAB(k,:) sfname]);
  451.                  nb     = 0;
  452.                  wnames = [];
  453.                  tabNums = Wavelets_Info(k).tabNums;
  454.                  if size(tabNums,1)>1
  455.                      varargout{1} = strvcat(varargout{1},sep_num);
  456.                  end
  457.                  for j = 1:size(tabNums,1)
  458.                      num_str = noblank(tabNums(j,:));
  459.                      if ~strcmp(num_str,'no')
  460.                          wnames = [wnames sfname noblank(tabNums(j,:)) tab];
  461.                      end
  462.                      if nb<3
  463.                          nb = nb+1;
  464.                      else
  465.                          if ~isempty(wnames)
  466.                              varargout{1} = strvcat(varargout{1},wnames);
  467.                          end
  468.                          nb  = 0;
  469.                          wnames = [];
  470.                      end
  471.                  end
  472.                  if nb>0 && ~isempty(wnames)
  473.                      varargout{1} = strvcat(varargout{1},wnames);
  474.                  end
  475.                  varargout{1} = strvcat(varargout{1},sep_fam);
  476.             end
  477.         end
  478.     case 'read_asc'
  479.         fid = fopen(asc_file);
  480.         if fid==-1 , fid = fopen(asc_ini_file); end
  481.         winfo = fread(fid);
  482.         fclose(fid);
  483.         varargout{1} = setstr(winfo');
  484.     case 'read_struct'
  485.         if isempty(Wavelets_Info) , wavemngr('load'); end
  486.         if nargin==2
  487.             indfam = varargin{1};
  488.         else
  489.             nb_fam = size(Wavelets_Info,1);
  490.             indfam = [1:nb_fam];
  491.         end
  492.         if nargout==0
  493.             sep_fam = '*';
  494.             sep_fam = sep_fam(:,ones(1,35));
  495.             disp(' '); disp(' '); disp(' ');
  496.             disp(sep_fam);
  497.         end
  498.         for k =1:length(indfam)
  499.             tmp{k} = Wavelets_Info(indfam(k));
  500.             if nargout==0
  501.                 disp(tmp{k}); disp(sep_fam);
  502.             end
  503.         end
  504.         if nargout>0 , varargout = tmp; end
  505.     case 'add'
  506.         wavemngr('clear')
  507.         Wavelets_Info = wavemngr('load');
  508.         nb_fam = size(Wavelets_Info,1);
  509.         err = 0;
  510.         family_Name = varargin{1};        
  511.         if isempty(family_Name)
  512.             err = 1; 
  513.             msg = 'Wavelet Family Name is empty !';
  514.         else
  515.             fnIn  = noblank(family_Name);
  516.             tmpCell = {Wavelets_Info(:).familyName}';
  517.             ind   = find(strcmp(fnIn,tmpCell)==1);
  518.             err   = ~isempty(ind);
  519.             if err , msg = 'The Wavelet Family Name is already used !'; end
  520.         end
  521.         if err==0
  522.             family_Short_Name = varargin{2};
  523.             if isempty(family_Short_Name)
  524.                 err = 1; 
  525.                 msg = 'Wavelet Family Short Name is empty !';
  526.             else
  527.                 fsnIn   = deblankl(family_Short_Name);
  528.                 tmpCell = {Wavelets_Info(:).familyShortName}';
  529.                 ind     = find(strcmp(fsnIn,tmpCell)==1);
  530.                 err     = ~isempty(ind);
  531.                 if err
  532.                     msg = 'The Wavelet Family Short Name is already used !';
  533.                 end
  534.             end
  535.         end
  536.         if err==0
  537.             wavelet_Type = varargin{3};
  538.             if isempty(find(wavelet_Type==WaveTypePOS))
  539.                 err = 1;
  540.                 msg = 'Invalid Wavelet Type !';
  541.             end
  542.         end
  543.         if err==0            
  544.             if isempty(varargin{4})
  545.                 wavelet_tabNums = 'no';
  546.                 wavelet_typNums = 'no';
  547.             elseif ischar(varargin{4})
  548.                 wavelet_tabNums = deblank(varargin{4});
  549.                 wavelet_typNums = 'integer';
  550.             elseif iscell(varargin{4})
  551.                 wavelet_tabNums = deblank(varargin{4}{1});
  552.                 wavelet_typNums = deblank(varargin{4}{2});
  553.                 if ischar(wavelet_typNums)
  554.                    switch wavelet_typNums
  555.                      case {'integer','real','string'}
  556.                      otherwise
  557.                        err = 1;
  558.                        msg = 'Invalid Wavelet type of numbers !';
  559.                    end                 
  560.                 else
  561.                     err = 1;
  562.                     msg = 'Invalid Wavelet type of numbers !';
  563.                 end
  564.                 
  565.             else
  566.                 err = 1;
  567.                 msg = 'Invalid Wavelet numbers !';
  568.             end
  569.         end
  570.         if err==0
  571.             wavelet_File = varargin{5};
  572.             if isempty(wavelet_File)
  573.                 err = 1;
  574.             elseif findstr('.mat',wavelet_File)
  575.             else 
  576.                 wavelet_File = deblankl(wavelet_File);
  577.                 ind = findstr('.m',wavelet_File);
  578.                 if ind>0 , wavelet_File = wavelet_File(1:ind-1); end
  579.                 if isempty(wavelet_File) , err = 1; end
  580.             end
  581.             if err==1
  582.                 msg = 'Invalid Wavelet File Name !';
  583.             end
  584.         end
  585.         if err==0
  586.             nbArgIN = length(varargin);
  587.             switch wavelet_Type
  588.               case {1,2}
  589.                 if nbArgIN<6 , wavelet_Bounds = ''; end
  590.                 
  591.               otherwise  
  592.                 if nbArgIN<6
  593.                     err = 1;
  594.                     msg = 'Invalid number of arguments !';
  595.                 else
  596.                     wavelet_Bounds = varargin{6};
  597.                     if length(wavelet_Bounds)~=2,               err = 1;
  598.                     elseif wavelet_Bounds(1)>wavelet_Bounds(2), err = 1;
  599.                     end
  600.                     if err==1
  601.                         msg = 'Invalid value for wavelet bounds !';
  602.                     end
  603.                 end
  604.             end
  605.         end
  606.         if err
  607.             msg = strvcat('Add New Wavelet FAILED !!',msg);
  608.             errargt(mfilename,msg,'msg');
  609.             return
  610.         end
  611.         fid = fopen(asc_file);
  612.         if fid==-1 , fid = fopen(asc_ini_file); end
  613.         winfo = fread(fid);
  614.         fclose(fid);
  615.         fid = fopen(sav_file,'w');
  616.         fwrite(fid,winfo);
  617.         fclose(fid);
  618.         Chrline = findNL('char',winfo);
  619.         beg_fam = 'Family Name : ';
  620.         sep_fam = '------------------------';
  621.         wavelet_Type = sprintf('%.0f',wavelet_Type);
  622.         if ~isempty(wavelet_Bounds)
  623.             wavelet_Bounds = [num2str(wavelet_Bounds(1)) ' ' ...
  624.                               num2str(wavelet_Bounds(2))];
  625.         end
  626.         winfo = [winfo(1:end-1);           Chrline;  ...
  627.                 abs(beg_fam'); ...
  628.                 abs(family_Name(:));       Chrline;  ...
  629.                 abs(family_Short_Name(:)); Chrline;  ...
  630.                 abs(wavelet_Type(:));      Chrline;  ...
  631.                 abs(wavelet_tabNums(:));   Chrline;  ...
  632.                 abs(wavelet_typNums(:));   Chrline;  ...
  633.                 abs(wavelet_File(:));      Chrline;  ...
  634.                 abs(wavelet_Bounds(:));    Chrline;  ...
  635.                 abs(sep_fam');             Chrline   ...
  636.                 ];
  637.         fid = fopen(asc_file,'w');
  638.         fwrite(fid,winfo);
  639.         fclose(fid);
  640.         wavemngr('create');
  641.     case 'del'
  642.         wavemngr('clear')
  643.         Wavelets_Info = wavemngr('load');
  644.         err   = 0;
  645.         i_fam = [];
  646.         if isempty(varargin{1})
  647.             err = 1; 
  648.             msg = 'Wavelet Family (Short) Name is empty !';       
  649.         else
  650.             name = noblank(varargin{1});
  651.             tmpCell = {Wavelets_Info(:).familyName}';
  652.             i_fam = find(strcmp(name,tmpCell)==1);
  653.             if isempty(i_fam)
  654.                 tmpCell = {Wavelets_Info(:).familyShortName}';
  655.                 i_fam = find(strcmp(name,tmpCell)==1);
  656.             end
  657.         end
  658.         if err==0
  659.             if isempty(i_fam)
  660.                 err = 1;
  661.                 msg = 'Invalid Wavelet Family (Short) Name !';
  662.             elseif i_fam<=NB_FamInWTB
  663.                 err = 1;
  664.                 fn  = Wavelets_Info(i_fam).familyName;
  665.                 msg = sprintf('You can''t delete %s Wavelet Family !',fn);
  666.             end
  667.         end
  668.         if err
  669.             errargt(mfilename,msg,'msg');
  670.             return 
  671.         end
  672.         fid = fopen(asc_file);
  673.         if fid==-1 , fid = fopen(asc_ini_file); end
  674.         winfo = fread(fid);
  675.         fclose(fid);
  676.         fid = fopen(sav_file,'w');
  677.         fwrite(fid,winfo);
  678.         fclose(fid);
  679.         str_winfo = setstr(winfo');
  680.         str_NL    = findNL('string',winfo);
  681.         beg_fam   = 'Family Name : ';
  682.         first     = findstr(beg_fam,str_winfo);
  683.         first     = first(i_fam);
  684.         ind_NL    = findstr(str_NL',str_winfo);
  685.         indexs    = find(ind_NL>first);
  686.         indexs    = ind_NL(indexs(1:nb_InfoByWave+1));
  687.         last      = indexs(nb_InfoByWave+1)+length(str_NL)-1;
  688.         winfo(first:last) = [];
  689.         fid = fopen(asc_file,'w');
  690.         fwrite(fid,winfo);
  691.         fclose(fid);
  692.         wavemngr('create');
  693.     case 'restore'
  694.         wavemngr('clear')
  695.         if nargin==1
  696.             fid = fopen(sav_file);
  697.             if fid==-1 , fid = fopen(asc_ini_file); end
  698.         else
  699.             fid = fopen(asc_ini_file);
  700.         end
  701.         winfo = fread(fid);
  702.         fclose(fid);
  703.         fid = fopen(asc_file,'w');
  704.         fwrite(fid,winfo);
  705.         fclose(fid);
  706.         wavemngr('create');
  707.     case 'rescue'
  708.         famtype = ...
  709.            {...
  710.             1, 'Haar',         'haar',  1;
  711.             2, 'Daubechies',   'db',    1;
  712.             3, 'Symlets',      'sym',   1;
  713.             4, 'Coiflets',     'coif',  1;
  714.             5, 'BiorSplines',  'bior',  2;
  715.             6, 'ReverseBior',  'rbio',  2;
  716.             7, 'Meyer',        'meyr',  3;
  717.             8, 'DMeyer',       'dmey',  1;
  718.             9, 'Gaussian',     'gaus',  4;
  719.            10, 'Mexican_hat',  'mexh',  4;
  720.            11, 'Morlet',       'morl',  4;
  721.            10, 'Complex Gaussian',   'cgau',  5;
  722.            11, 'Shannon',            'shan',  5;
  723.            10, 'Frequency B-Spline', 'fbsp',  5;
  724.            11, 'Complex Morlet',     'cmor',  5
  725.             };
  726.         nums = ...
  727.            {...
  728.             '';
  729.             '1 2 3 4 5 6 7 8 9 10 **';
  730.             '2 3 4 5 6 7 8 **';
  731.             '1 2 3 4 5';
  732.             '1.1 1.3 1.5 2.2 2.4 2.6 2.8 3.1 3.3 3.5 3.7 3.9 4.4 5.5 6.8';
  733.             '1.1 1.3 1.5 2.2 2.4 2.6 2.8 3.1 3.3 3.5 3.7 3.9 4.4 5.5 6.8';
  734.             '';
  735.             '';
  736.             '1 2 3 4 5 6 7 8 **';
  737.             '';
  738.             '';
  739.             '1 2 3 4 5 **';
  740.             '1-1.5 1-1 1-0.5 1-0.1 2-3 **';
  741.             '1-1-1.5 1-1-1 1-1-0.5 2-1-1 2-1-0.5 2-1-0.1 **';
  742.             '1-1.5 1-1 1-0.5 1-1 1-0.5 1-0.1 **'
  743.             };
  744.         typNums = ...
  745.            {...
  746.             'no';
  747.             'integer';
  748.             'integer';
  749.             'integer';
  750.             'real';
  751.             'real';
  752.             'no';
  753.             'no';
  754.             'integer';
  755.             'no';
  756.             'no';
  757.             'integer';
  758.             'string';
  759.             'string';
  760.             'string'
  761.             };
  762.         files = ...
  763.            {...
  764.             'dbwavf';
  765.             'dbwavf';
  766.             'symwavf';
  767.             'coifwavf';
  768.             'biorwavf';
  769.             'rbiowavf';
  770.             'meyer';
  771.             'dmey.mat';
  772.             'gauswavf';
  773.             'mexihat';
  774.             'morlet'
  775.             'cgauwavf';
  776.             'shanwavf';
  777.             'fbspwavf';
  778.             'cmorwavf'
  779.             };
  780.         bounds = ...
  781.            {...
  782.             [];
  783.             [];
  784.             [];
  785.             [];
  786.             [];
  787.             [];
  788.             [-8 8];
  789.             [];
  790.             [-5 5];
  791.             [-8 8];
  792.             [-8 8];
  793.             [-5 5];
  794.             [-20 20];
  795.             [-20 20];
  796.             [-8 8]
  797.             };
  798.         nbfam   = size(famtype,1); 
  799.         tabNums = cell(nbfam,1);
  800.         for k = 1:nbfam
  801.             tabNums{k} = '';
  802.             s = deblank(nums{k});
  803.             if ~isempty(s)
  804.                 I = find(isspace(s));
  805.                 i_beg = 1;
  806.                 for j = 1:length(I)
  807.                     i_end = I(j)-1;
  808.                     ss = deblank(s(i_beg:i_end));
  809.                     if ~isempty(ss)
  810.                         tabNums{k} = strvcat(tabNums{k},ss);
  811.                     end
  812.                     i_beg = i_end+2;
  813.                 end
  814.                 ss = deblank(s(i_beg:end));
  815.                 tabNums{k} = strvcat(tabNums{k},ss);
  816.             end
  817.             if isempty(tabNums{k}) , tabNums{k} = 'no'; end
  818.         end
  819.         varargout{1} = ...
  820.            struct(...
  821.                   'index',           famtype(:,1), ...
  822.                   'familyName',      famtype(:,2), ...
  823.                   'familyShortName', famtype(:,3), ...
  824.                   'type',            famtype(:,4), ...
  825.                   'tabNums',         tabNums,      ...
  826.                   'typNums',         typNums,      ...
  827.                   'file',            files,        ...
  828.                   'bounds',          bounds        ...
  829.                   );
  830.     otherwise
  831.         errargt(mfilename,'Unknown Option','msg');
  832.         error('*');
  833. end
  834. %----------------------------------%
  835. % Internal Function(s)             %
  836. %----------------------------------%
  837. function nl = findNL(opt,txt)
  838. %FINDNL Find New Line char or string.
  839. ind10 = find(txt==10);
  840. ind13 = find(txt==13);
  841. if isempty(ind13) ,
  842.     nl = 10;
  843. elseif isempty(ind10)
  844.     nl = 13;
  845. else
  846.     nl = [13;10];
  847. end
  848. if isequal(opt,'string')
  849.     nl = setstr(nl);
  850. end
  851. if size(txt,2)>1 , nl = nl'; end
  852. %----------------------------------%
  853. function s = noblank(x)
  854. %NOBLANK Removes blanks in a string.
  855. if ~isempty(x)
  856.     s = x(find(x~=' ' & x~=0));
  857. else
  858.     s = '';
  859. end
  860. %----------------------------------%