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

波变换

开发平台:

Matlab

  1. function varargout = wp1dcomp(option,varargin)
  2. %WP1DCOMP Wavelet packets 1-D compression.
  3. %   VARARGOUT = WP1DCOMP(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 03-Feb-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.20.4.2 $
  8. % Memory Blocks of stored values.
  9. %================================
  10. % MB1.
  11. %-----
  12. n_param_anal   = 'WP1D_Par_Anal';
  13. ind_sig_name   = 1;
  14. ind_wav_name   = 2;
  15. ind_lev_anal   = 3;
  16. ind_ent_anal   = 4;
  17. ind_ent_par    = 5;
  18. ind_sig_size   = 6;
  19. ind_act_option = 7;
  20. ind_thr_val    = 8;
  21. nb1_stored     = 8;
  22. % MB3.
  23. %-----
  24. n_structures = 'Structures';
  25. ind_tree_st  = 1;
  26. ind_data_st  = 2;
  27. nb3_stored   = 2;
  28. % MB1 (local).
  29. %-------------
  30. n_misc_loc = ['MB1_' mfilename];
  31. ind_sav_menus  = 1;
  32. ind_status     = 2;
  33. ind_win_caller = 3;
  34. ind_axe_datas  = 4;
  35. ind_hdl_datas  = 5;
  36. ind_cfsMode    = 6;
  37. nbLOC_1_stored = 6;
  38. % MB2 (local).
  39. %-------------
  40. n_thrDATA = 'thrDATA';
  41. ind_value = 1;
  42. nbLOC_2_stored = 1;
  43. % Tag property (Main Window).
  44. %----------------------------
  45. tag_pop_colm = 'Txt_PopM';
  46. tag_axe_cfs  = 'Axe_Cfs';
  47. % Tag property.
  48. %--------------
  49. tag_axetxt_perf = 'Txt_Perf';
  50. if ~isequal(option,'create') , win_compress = varargin{1}; end
  51. switch option
  52.     case 'create'
  53.         % Get Globals.
  54.         %-------------
  55.         [Def_Btn_Height,Y_Spacing,Def_FraBkColor] = ...
  56.             mextglob('get','Def_Btn_Height','Y_Spacing','Def_FraBkColor');
  57.         % Calling figure.
  58.         %----------------
  59.         win_caller = varargin{1};
  60.         str_win_caller = sprintf('%.0f',win_caller);
  61.         pop = wfindobj(win_caller,'style','popupmenu','tag',tag_pop_colm);
  62.         cfsMode = get(pop,'Value');
  63.         % Window initialization.
  64.         %----------------------
  65.         win_name = 'Wavelet Packet 1-D  --  Compression';
  66.         [win_compress,pos_win,win_units,str_win_compress,...
  67.                 frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  68.                     wfigmngr('create',win_name,'','ExtFig_CompDeno', ...
  69.                         strvcat(mfilename,'cond'),1,1,0);
  70.         set(win_compress,'userdata',win_caller);
  71.         if nargout>0 , varargout{1} = win_compress; end
  72. % Add Help for Tool.
  73. %------------------
  74. wfighelp('addHelpTool',win_compress,'Signal Compression','WP1D_COMP_GUI');
  75. % Add Help Item.
  76. %----------------
  77. wfighelp('addHelpItem',win_compress,'Compression Procedure','COMP_PROCEDURE');
  78. wfighelp('addHelpItem',win_compress,'Available Methods','COMP_DENO_METHODS');
  79.         % Menu construction for current figure.
  80.         %--------------------------------------
  81. m_save  = wfigmngr('getmenus',win_compress,'save');
  82.         sav_menus(1) = uimenu(m_save,...
  83.                               'Label','Compressed &Signal ',...
  84.                               'Position',1,                   ...
  85.                               'Enable','Off',                 ...
  86.                               'Callback',                     ...
  87.                               [mfilename '(''save_synt'','    ...
  88.                                       str_win_compress ');']  ...
  89.                               );
  90.         sav_menus(2) = uimenu(m_save,...
  91.                               'Label','&Decomposition ', ...
  92.                               'Position',2,                  ...
  93.                               'Enable','Off',                ...
  94.                               'Callback',                    ...
  95.                               [mfilename '(''save_dec'','    ...
  96.                                       str_win_compress ');'] ...
  97.                               );
  98.         % Begin waiting.
  99.         %---------------
  100.         wwaiting('msg',win_compress,'Wait ... initialization');
  101.         % Getting variables from wp1dtool figure memory block.
  102.         %-----------------------------------------------------
  103.         [WP_Tree,WP_Data] = wmemtool('rmb',win_caller,n_structures,...
  104.                                            ind_tree_st,ind_data_st);
  105.         depth = treedpth(WP_Tree);
  106.         [Sig_Name,Sig_Size,Wav_Name,Ent_Nam,Ent_Par] = ...
  107.                 wmemtool('rmb',win_caller,n_param_anal, ...
  108.                                ind_sig_name,ind_sig_size,...
  109.                                ind_wav_name,ind_ent_anal,ind_ent_par);
  110.         Wav_Fam = wavemngr('fam_num',Wav_Name);
  111.         isBior  = wavemngr('isbior',Wav_Fam);        
  112.         % General graphical parameters initialization.
  113.         %---------------------------------------------
  114.         dy = Y_Spacing;
  115.         % Command part of the window.
  116.         %============================
  117.         % Data, Wavelet and Level parameters.
  118.         %------------------------------------
  119.         xlocINI = pos_frame0([1 3]);
  120.         ytopINI = pos_win(4)-dy;
  121.         toolPos = utanapar('create_copy',win_compress, ...
  122.                     {'xloc',xlocINI,'top',ytopINI},...
  123.                     {'n_s',{Sig_Name,Sig_Size},'wav',Wav_Name,'lev',depth}...
  124.                     );
  125.  
  126.         % Entropy parameters.
  127.         %--------------------
  128.         ytopENT = toolPos(2)-dy;
  129.         toolPos = utentpar('create_copy',win_compress, ...
  130.                     {'xloc',xlocINI,'top',ytopENT,...
  131.                      'ent',{Ent_Nam,Ent_Par}} ...
  132.                     );
  133.         % Global Compression tool.
  134.         %-------------------------
  135.         ytopTHR = toolPos(2)-4*dy;
  136.         utthrgbl('create',win_compress,'toolOPT','wp1dcomp', ...
  137.                  'xloc',xlocINI,'top',ytopTHR, ...
  138.                  'isbior',isBior,   ...
  139.                  'caller',mfilename ...
  140.                  );
  141.         % Adding colormap GUI.
  142.         %---------------------
  143.         pop_pal_caller = cbcolmap('get',win_caller,'pop_pal');
  144.         prop_pal = get(pop_pal_caller,{'String','Value','Userdata'});
  145.         utcolmap('create',win_compress, ...
  146.                  'xloc',xlocINI, ...
  147.                  'bkcolor',Def_FraBkColor, ...
  148.                  'enable','on',...
  149.                  'briFlag',0);
  150.         pop_pal_loc = cbcolmap('get',win_compress,'pop_pal');
  151.         set(pop_pal_loc,'String',prop_pal{1},'Value',prop_pal{2}, ...
  152.                         'Userdata',prop_pal{3});
  153.         set(win_compress,'Colormap',get(win_caller,'Colormap'));        
  154.         % General graphical parameters initialization.
  155.         %--------------------------------------------
  156.         bdx     = 0.08*pos_win(3);
  157.         bdy     = 0.06*pos_win(4);
  158.         ecy     = 0.03*pos_win(4);
  159.         y_graph = 2*Def_Btn_Height+dy;
  160.         h_graph = pos_frame0(4)-y_graph;
  161.         w_graph = pos_frame0(1);
  162.         % Axes construction parameters.
  163.         %------------------------------
  164.         w_left     = (w_graph-3*bdx)/2;
  165.         x_left     = bdx;
  166.         w_right    = w_left;
  167.         x_right    = x_left+w_left+5*bdx/4;
  168.         n_axeright = 3;
  169.         ind_right  = n_axeright;
  170.         % Vertical separation.
  171.         %---------------------
  172.         w_fra   = 0.01*pos_win(3);
  173.         x_fra   = (w_graph-w_fra)/2;
  174.         uicontrol('Parent',win_compress,...
  175.                   'Style','frame',...
  176.                   'Unit',win_units,...
  177.                   'Position',[x_fra,y_graph,w_fra,h_graph],...
  178.                   'Backgroundcolor',Def_FraBkColor...
  179.                   );
  180.         % Building axes on the right part.
  181.         %---------------------------------
  182.         ecy_right = 2*ecy;
  183.         h_right   =(h_graph-2*bdy-(n_axeright-1)*ecy_right)/n_axeright;
  184.         y_right   = y_graph+2*bdy/3;
  185.         axe_datas = zeros(1,n_axeright);
  186.         pos_right = [x_right y_right w_right h_right];
  187.         for k = 1:n_axeright
  188.             axe_datas(k) = axes('Parent',win_compress,...
  189.                                 'Units',win_units,...
  190.                                 'Position',pos_right,...
  191.                                 'Drawmode','fast',...
  192.                                 'Box','On'...
  193.                                 );
  194.             pos_right(2) = pos_right(2)+pos_right(4)+ecy_right;
  195.         end
  196.         set(axe_datas(1),'visible','off');
  197.         % Computing and drawing original signal.
  198.         %---------------------------------------
  199.         Signal_Anal = get(wp1ddraw('r_orig',win_caller),'Ydata');
  200.         axeAct = axe_datas(3);
  201.         curr_color   = wtbutils('colors','sig');
  202.         hdl_datas    = [NaN ; NaN];
  203.         hdl_datas(1) = line(...
  204.                          1:length(Signal_Anal),Signal_Anal,...
  205.                          'erasemode','none',...
  206.                          'Color',curr_color,...
  207.                          'Parent',axeAct);
  208.         wtitle('Original signal','Parent',axeAct);
  209.         xmin = 1;                       
  210.         xmax = length(Signal_Anal);
  211.         ylim = [min(Signal_Anal) max(Signal_Anal)];
  212.         ymin = min(Signal_Anal);
  213.         ymax = max(Signal_Anal);
  214.         if abs(ylim(1)-ylim(2))<eps , ylim = ylim+0.01*[-1 1]; end
  215.         set(axeAct,'Xlim',[xmin xmax],'Ylim',ylim);
  216.         % Displaying original details coefficients.
  217.         %------------------------------------------
  218.         axe_handles = findobj(get(win_caller,'Children'),'flat','type','axes');
  219.         WP_Axe_Cfs  = findobj(axe_handles,'flat','Tag',tag_axe_cfs);
  220.         xylim   = get(WP_Axe_Cfs,{'Xlim','Ylim'});
  221.         ylim   = get(WP_Axe_Cfs,'Ylim');
  222.         axeAct = axe_datas(2);
  223.         commonProp = {...
  224.             'Xlim',xylim{1},           ...
  225.             'Ylim',xylim{2},           ...
  226.             'YTicklabelMode','manual', ...
  227.             'YTicklabel',[],           ...
  228.             'YTick',[],                ...
  229.             'Box','On'                 ...
  230.             };
  231.         set(axeAct,commonProp{:});
  232.         if isa(WP_Tree,'wptree')
  233.             wpplotcf(WP_Tree,cfsMode,axeAct);
  234.         else
  235.             wpplotcf(WP_Tree,WP_Data,cfsMode,axeAct);
  236.         end
  237.         wtitle('Original coefficients','Parent',axeAct);
  238.         set(axe_datas(1),commonProp{:});
  239.         % Initializing global threshold.
  240.         %-------------------------------
  241.         [valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR] = ...
  242.             wp1dcomp('compute_GBL_THR',win_compress,win_caller);
  243.         utthrgbl('set',win_compress,'thrBOUNDS',[0,valTHR,maxTHR]);
  244.         % Displaying perfos & legend.
  245.         %----------------------------
  246.         y_axe   = y_graph+2*bdy/3+h_right+ecy_right;
  247.         h_axe   = 2*h_right+ecy_right;
  248.         pos_axe_perfo = [x_left y_axe w_left h_axe];
  249.         y_axe   = y_graph+h_right/2;
  250.         h_axe   = h_right/2;
  251.         pos_axe_legend = [x_left y_axe w_left h_axe];
  252.         utthrgbl('displayPerf',win_compress, ...
  253.                   pos_axe_perfo,pos_axe_legend,thresVALUES,n0SCR,rl2SCR,valTHR);
  254.         [perfl2,perf0] = utthrgbl('getPerfo',win_compress);
  255.         utthrgbl('set',win_compress,'perfo',[perfl2,perf0]);
  256.         drawnow
  257.         % Memory blocks update.
  258.         %----------------------
  259.         utthrgbl('set',win_compress,'handleORI',hdl_datas(1));
  260.         wmemtool('ini',win_compress,n_misc_loc,nbLOC_1_stored);
  261.         wmemtool('wmb',win_compress,n_misc_loc,  ...
  262.                        ind_sav_menus,sav_menus,  ...
  263.                        ind_status,0,             ...
  264.                        ind_win_caller,win_caller,...
  265.                        ind_cfsMode,cfsMode,      ...
  266.                        ind_axe_datas,axe_datas,  ...
  267.                        ind_hdl_datas,hdl_datas   ...
  268.                        );
  269.         wmemtool('ini',win_compress,n_thrDATA,nbLOC_2_stored);
  270.         % Axes attachment.
  271.         %-----------------
  272.         axe_cmd = axe_datas(3);
  273.         axe_act = axe_datas(1:2);
  274.         dynvtool('init',win_compress,[],axe_cmd,axe_act,[1 0]);
  275.         % Setting units to normalized.
  276.         %-----------------------------
  277.         wfigmngr('normalize',win_compress);
  278.         % End waiting.
  279.         %-------------
  280.         wwaiting('off',win_compress);
  281.        %%% PROVISOIRE BUG %%%%
  282.        % refresh(win_compress)
  283.        %%%%%%%%%%%%%%%%%%%%%%%
  284.     case 'compress'
  285.         % Waiting message.
  286.         %-----------------
  287.         wwaiting('msg',win_compress,'Wait ... computing');
  288.         % Handles.
  289.         %---------
  290.         wp1dcomp('clear_GRAPHICS',win_compress);
  291.         [axe_datas,hdl_datas] = wmemtool('rmb',win_compress,n_misc_loc, ...
  292.                                                ind_axe_datas,ind_hdl_datas);
  293.         % Getting memory blocks.
  294.         %-----------------------
  295.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  296.         [WP_Tree,WP_Data] = wmemtool('rmb',win_caller,n_structures,...
  297.                                            ind_tree_st,ind_data_st);
  298.         depth    = treedpth(WP_Tree);
  299.         Wav_Name = wmemtool('rmb',win_caller,n_param_anal,ind_wav_name);
  300.         isBior   = wavemngr('isbior',Wav_Name);
  301.         % Compression.
  302.         %-------------
  303.         valTHR = utthrgbl('get',win_compress,'valthr');
  304.         thrParams = {'h','nobest',valTHR,1};
  305.         if isBior
  306.             if isa(WP_Tree,'wptree')
  307.                 [C_Sig,C_Tree,perf0] = wpdencmp(WP_Tree,thrParams{:});
  308.                 C_Data = [];
  309.             else
  310.                 [C_Sig,C_Tree,C_Data,perf0] = ...
  311.                        wpdencmp(WP_Tree,WP_Data,thrParams{:});
  312.             end
  313.             lin_sig  = hdl_datas(1);
  314.             Sig_Anal = get(lin_sig,'Ydata');
  315.             perfl2   = 100*(norm(C_Sig)/norm(Sig_Anal))^2;
  316.             topTitle = 'Energy ratio ';
  317.         else
  318.             if isa(WP_Tree,'wptree')
  319.                 [C_Sig,C_Tree] = wpdencmp(WP_Tree,thrParams{:});
  320.                 C_Data = [];
  321.             else
  322.                 [C_Sig,C_Tree,C_Data] = wpdencmp(WP_Tree,WP_Data,thrParams{:});
  323.             end
  324.             [perfl2,perf0] = utthrgbl('getPerfo',win_compress);
  325.             topTitle = 'Retained energy ';
  326.         end
  327.         % Displaying compressed signal.
  328.         %------------------------------
  329.         axes(axe_datas(3));
  330.         hdl_comp = hdl_datas(2);
  331.         if ishandle(hdl_comp)
  332.             set(hdl_comp,'Ydata',C_Sig,'Visible','on');
  333.         else
  334.             curr_color = wtbutils('colors','ssig');
  335.             hdl_comp = line('Xdata',1:length(C_Sig),...
  336.                             'Ydata',C_Sig,...
  337.                             'color',curr_color,...
  338.                             'Parent',axe_datas(3));
  339.             hdl_datas(2) = hdl_comp;
  340.             utthrgbl('set',win_compress,'handleTHR',hdl_comp);
  341.             wmemtool('wmb',win_compress,n_misc_loc,...
  342.                            ind_hdl_datas,hdl_datas);
  343.         end     
  344.         % Set a text as a super title.
  345.         %-----------------------------
  346.         wtitle('Original and compressed signals','Parent',axe_datas(3));
  347.         strPerfo = [topTitle num2str(perfl2,'%5.2f') ...
  348.                     ' % -- Zeros ' num2str(perf0,'%5.2f') ' %'];
  349.         wtxttitl(axe_datas(3),strPerfo,tag_axetxt_perf);
  350.         % Displaying thresholded details coefficients.
  351.         %---------------------------------------------
  352.         cfsMode = wmemtool('rmb',win_compress,n_misc_loc,ind_cfsMode);
  353.         delete(findobj(axe_datas(1),'type','image'));
  354.         if isa(C_Tree,'wptree')
  355.             wpplotcf(C_Tree,cfsMode,axe_datas(1));
  356.         else
  357.             wpplotcf(C_Tree,C_Data,cfsMode,axe_datas(1));
  358.         end
  359.         xylim = get(axe_datas(2),{'Xlim','Ylim'});
  360.         set(axe_datas(1),'Xlim',xylim{1},'Ylim',xylim{2});
  361.         wtitle('Thresholded coefficients','Parent',axe_datas(1));
  362.         set(findobj(axe_datas(1)),'Visible','on');       
  363.         % Memory blocks update.
  364.         %----------------------
  365.         wmemtool('wmb',win_compress,n_thrDATA, ...
  366.                        ind_value,{C_Sig,C_Tree,C_Data,valTHR});
  367.         wp1dcomp('enable_menus',win_compress,'on');
  368.         % End waiting.
  369.         %-------------
  370.         wwaiting('off',win_compress);
  371.     case 'compute_GBL_THR'
  372.         win_caller = varargin{2};
  373.         [numMeth,meth,sliVal] = utthrgbl('get_GBL_par',win_compress);
  374.         [WP_Tree,WP_Data] = wmemtool('rmb',win_caller,n_structures,...
  375.                                            ind_tree_st,ind_data_st);
  376.         thrFLAGS = 'wp1dcompGBL';
  377.         switch numMeth
  378.           case 1
  379.             [valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR] = ...
  380.                 wthrmngr(thrFLAGS,meth,WP_Tree,WP_Data);
  381.             if nargout==1 , varargout = {valTHR};
  382.             else          , varargout = {valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR};
  383.             end
  384.           case 2
  385.             sig    = get(wp1ddraw('r_orig',win_caller),'Ydata');
  386.             valTHR = wthrmngr(thrFLAGS,meth,sig);
  387.             if isa(WP_Tree,'wptree')
  388.                 cfs = read(WP_Tree,'allcfs');
  389.             else
  390.                 cfs = wdatamgr('rallcfs',WP_Data);
  391.             end
  392.             maxTHR = max(abs(cfs));
  393.             valTHR = min(valTHR,maxTHR);
  394.             varargout = {valTHR};
  395.         end
  396.     case 'update_GBL_meth'
  397.         wp1dcomp('clear_GRAPHICS',win_compress);
  398.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  399.         valTHR = wp1dcomp('compute_GBL_THR',win_compress,win_caller);
  400.         utthrgbl('update_GBL_meth',win_compress,valTHR);
  401.     case 'clear_GRAPHICS'
  402.         status = wmemtool('rmb',win_compress,n_misc_loc,ind_status);
  403.         if status==0 , return; end
  404.         % Diseable save Menus.
  405.         %--------------------
  406.         wp1dcomp('enable_menus',win_compress,'off');
  407.         % Get Handles.
  408.         %-------------
  409.         [axe_datas,hdl_datas] = wmemtool('rmb',win_compress,n_misc_loc, ...
  410.                                                ind_axe_datas,ind_hdl_datas);
  411.         % Setting the compressed coefs axes invisible.
  412.         %---------------------------------------------
  413.         hdl_comp = hdl_datas(2);
  414.         if  ishandle(hdl_comp)
  415.             vis = get(hdl_comp,'Visible');
  416.             if vis(1:2)=='on'
  417.                txt_perf = findobj(axe_datas(3),'Tag',tag_axetxt_perf);
  418.                set([findobj(axe_datas(1));hdl_comp;txt_perf],'Visible','off');
  419.                wtitle('Original signal','Parent',axe_datas(3));
  420.             end
  421.         end
  422.         drawnow
  423.     case 'enable_menus'
  424.         enaVal = varargin{2};
  425.         sav_menus = wmemtool('rmb',win_compress,n_misc_loc,ind_sav_menus);
  426.         set(sav_menus,'Enable',enaVal);
  427.         utthrgbl('enable_tog_res',win_compress,enaVal);
  428.         if strncmpi(enaVal,'on',2) , status = 1; else , status = 0; end
  429.         wmemtool('wmb',win_compress,n_misc_loc,ind_status,status);
  430.     case 'save_synt'
  431.         % Testing file.
  432.         %--------------
  433.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  434.                                      '*.mat','Save Compressed Signal');
  435.         if ~ok, return; end
  436.         % Begin waiting.
  437.         %--------------
  438.         wwaiting('msg',win_compress,'Wait ... saving');
  439.         % Getting Analysis values.
  440.         %-------------------------
  441.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  442.         wname = wmemtool('rmb',win_caller,n_param_anal,ind_wav_name);
  443.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  444.         xc = thrDATA{1};
  445.         valTHR = thrDATA{4};
  446.         % Saving file.
  447.         %--------------
  448.         [name,ext] = strtok(filename,'.');
  449.         if isempty(ext) | isequal(ext,'.')
  450.             ext = '.mat'; filename = [name ext];
  451.         end
  452.         saveStr = name;
  453.         eval([saveStr '= xc ;']);
  454.         wwaiting('off',win_compress);
  455.         try
  456.           save([pathname filename],saveStr,'valTHR','wname');
  457.         catch
  458.           errargt(mfilename,'Save FAILED !','msg');
  459.         end
  460.     case 'save_dec'
  461.         % Testing file.
  462.         %--------------
  463.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  464.                                    '*.wp1','Save Wavelet Packet Analysis (1D)');
  465.         if ~ok, return; end
  466.         % Begin waiting.
  467.         %--------------
  468.         wwaiting('msg',win_compress,'Wait ... saving decomposition');
  469.         % Getting Analysis parameters.
  470.         %-----------------------------
  471.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  472.         data_name = wmemtool('rmb',win_caller,n_param_anal,ind_sig_name);
  473.         % Getting Analysis values.
  474.         %-------------------------
  475.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  476.         tree_struct = thrDATA{2};
  477.         data_struct = thrDATA{3};
  478.         valTHR = thrDATA{4};
  479.         % Saving file.
  480.         %--------------
  481.         [name,ext] = strtok(filename,'.');
  482.         if isempty(ext) | isequal(ext,'.')
  483.             ext = '.wp1'; filename = [name ext];
  484.         end
  485.         if isa(tree_struct,'wptree')
  486.             saveStr = {'tree_struct','data_name','valTHR'};
  487.         else
  488.             saveStr = {'tree_struct','data_struct','data_name','valTHR'};
  489.         end
  490.         wwaiting('off',win_compress);
  491.         try
  492.           save([pathname filename],saveStr{:});
  493.         catch
  494.           errargt(mfilename,'Save FAILED !','msg');
  495.         end
  496.     case 'close'
  497.         [status,win_caller] = wmemtool('rmb',win_compress,n_misc_loc, ...
  498.                                              ind_status,ind_win_caller);
  499.         if status==1
  500.             % Test for Updating.
  501.             %--------------------
  502.             status = wwaitans(win_compress,...
  503.                               'Update the synthesized signal ?',2,'cancel');
  504.         end
  505.         switch status
  506.             case 1
  507.               wwaiting('msg',win_compress,'Wait ... computing');
  508.               thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  509.               valTHR  = thrDATA{4};
  510.               wmemtool('wmb',win_caller,n_param_anal,ind_thr_val,valTHR);
  511.               hdl_datas = wmemtool('rmb',win_compress,n_misc_loc,ind_hdl_datas);
  512.               hdl_comp  = hdl_datas(2);
  513.               wp1dmngr('return_comp',win_caller,status,hdl_comp);
  514.               wwaiting('off',win_compress);
  515.             case 0 , wp1dmngr('return_comp',win_caller,status);
  516.         end
  517.         if nargout>0 , varargout{1} = status; end
  518.     otherwise
  519.         errargt(mfilename,'Unknown Option','msg');
  520.         error('*');
  521. end