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

波变换

开发平台:

Matlab

  1. function varargout = wmoreres(option,varargin)
  2. %WMORERES "More information" on wavelet residuals tool.
  3. %   VARARGOUT = WMORERES(OPTION,VARARGIN)
  4. %
  5. %------------------------------------------------------------
  6. %   Internal options:
  7. %   OPTION =    'create', 'select', 'update_bins', 'close'
  8. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-Jul-98.
  9. %   Last Revision: 16-Jan-2001.
  10. %   Copyright 1995-2002 The MathWorks, Inc.
  11. %   $Revision: 1.8 $  $Date: 2002/04/14 19:49:17 $
  12. % MemBloc1 of stored values.
  13. %---------------------------
  14. n_membloc1     = [mfilename '_MB1'];
  15. ind_loc_struct = 1;
  16. nb1_stored     = 1;
  17. % Tag property.
  18. %--------------
  19. tag_figRes = 'Fig_Residual';
  20. % Parameters initialization.
  21. %---------------------------
  22. default_bins = 50;
  23. curr_color   = wtbutils('colors','res');
  24. nb_bins      = default_bins;
  25.         
  26. if ~isequal(option,'create') , fig = varargin{1}; end
  27. switch option
  28.     case 'create'
  29.         %**************************************************************%
  30.         %** OPTION = 'create' - Create the current figure            **%
  31.         %**************************************************************%
  32.         caller   = varargin{1};
  33.         oldFig   = wfindobj('figure','tag',tag_figRes);
  34.         existFig = ~isempty(oldFig);
  35.         if existFig
  36.             existFig = 0;
  37.             for k = 1:length(oldFig)
  38.                 ls = wmemtool('rmb',oldFig(k),n_membloc1,ind_loc_struct);
  39.                 if isequal(ls.caller,caller)
  40.                    existFig = oldFig(k);
  41.                    break
  42.                 end
  43.             end
  44.         end
  45.         if existFig ~= 0
  46.             try , delete(existFig); end
  47.             return
  48.         end    
  49.         % Get Globals.
  50.         %-------------
  51.         [Def_Txt_Height,Def_Btn_Height,Def_Btn_Width,Pop_Min_Width, ...
  52.          X_Spacing,Y_Spacing,Def_EdiBkColor,Def_FraBkColor] = ...
  53.             mextglob('get',...
  54.                 'Def_Txt_Height','Def_Btn_Height','Def_Btn_Width', ...
  55.                 'Pop_Min_Width','X_Spacing','Y_Spacing', ...
  56.                 'Def_EdiBkColor','Def_FraBkColor' ...
  57.                 );
  58.  
  59.         % Window initialization.
  60.         %-----------------------
  61.         CallerTitle = get(caller,'Name');
  62.         strTitle = sprintf('More on Residuals for %s', CallerTitle);
  63.         [fig,pos_win,win_units,str_numwin,...
  64.             frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  65.                 wfigmngr('create',strTitle,[],'ExtFig_Tool_3',mfilename,1,1,0);
  66.         varargout{1} = fig;
  67.         set(fig,'tag',tag_figRes);
  68. % Add Help for Tool.
  69. %------------------
  70. % See Below, after detection of typeDATA
  71.         % Menu construction for current figure.
  72.         %--------------------------------------
  73.         m_files = wfigmngr('getmenus',fig,'file');
  74.         m_save = uimenu(m_files,...
  75.                            'Label','&Save Residuals',               ...
  76.                            'Position',1,                            ...
  77.                            'Enable','On',                           ...
  78.                            'Callback',                              ...
  79.                            [mfilename '(''save'',' str_numwin ');'] ...
  80.                            );
  81.         
  82.         % Begin waiting.
  83.         %---------------
  84.         set(wfindobj('figure'),'Pointer','watch');
  85.         % Setting local structure.
  86.         %-------------------------
  87.         ls = struct('caller',caller,'toggle',varargin{2},...
  88.                     'handleRES',varargin{3},'handleORI',[],'handleTHR',[]);
  89.         Nb_Hdls_Inputs = length(varargin)-3;        
  90.         blocPAR = 0;
  91.         if Nb_Hdls_Inputs>0
  92.             ls.handleORI = varargin{4};
  93.             if Nb_Hdls_Inputs>1
  94.                ls.handleTHR = varargin{5};
  95.                if Nb_Hdls_Inputs>2 , blocPAR = 1; end
  96.             end           
  97.         end
  98.         
  99.         if ishandle(ls.handleRES)
  100.             [typeDATA,propDATA] = getDataType(ls.handleRES);
  101.             resVal = get(ls.handleRES,propDATA);
  102.             
  103.         elseif ishandle(ls.handleORI)
  104.             [typeDATA,propDATA] = getDataType(ls.handleORI);
  105.             resVal = get(ls.handleORI,propDATA);
  106.             if ishandle(ls.handleTHR)
  107.                 if isequal(propDATA,'Ydata');
  108.                   xdata = get(ls.handleORI,'Xdata');
  109.                   xTHR  = get(ls.handleTHR,'Xdata');
  110.                   if ~isequal(xdata,xTHR)
  111.                     typeDATA = 'regress';
  112.                     yTHR   = get(ls.handleTHR,'Ydata');
  113.                     resVal = resVal-interp1(xTHR,yTHR,xdata);
  114.                   else
  115.                     resVal = resVal-get(ls.handleTHR,propDATA);
  116.                   end
  117.                 else
  118.                   resVal = resVal-get(ls.handleTHR,propDATA);
  119.                 end
  120.             else
  121.                 resVal = zeros(size(resVal));
  122.             end
  123.         else
  124.             error('** STOP **')
  125.         end       
  126.         wmemtool('wmb',fig,n_membloc1,ind_loc_struct,ls);
  127. % Add Help for Tool.
  128. %-------------------
  129. switch typeDATA
  130.           case {'line','regress'}
  131.   helpName = 'RESI1D_GUI';
  132.   helpItem = 'One-Dimensional Residuals';
  133.           case 'image' 
  134.   helpName = 'RESI2D_GUI';
  135.   helpItem = 'Two-Dimensional Residuals';   
  136.   otherwise 
  137.   helpName = 'Error'; 
  138.         end
  139. wfighelp('addHelpTool',fig,helpItem,helpName);
  140.         % Creating the Command part of the window.
  141.         %=========================================
  142.        
  143.         % Building the "Data, Wavelet and Level" block.
  144.         %----------------------------------------------
  145.         if blocPAR
  146.             utanapar('create_copyB',caller,fig);
  147.             toolPos = utanapar('position',fig); 
  148.         end
  149.        
  150.         % General parameters initialization.
  151.         %-----------------------------------
  152.         dx = X_Spacing;  dx2 = 2*dx;
  153.         dy = Y_Spacing;  dy2 = 2*dy;
  154.         d_txt           = (Def_Btn_Height-Def_Txt_Height);
  155.         gra_width       = Pos_Graphic_Area(3);
  156.         x_frame0        = pos_frame0(1);
  157.         h_frame0        = pos_frame0(4);
  158.         xlocINI         = pos_frame0([1 3]);
  159.         cmd_width       = pos_frame0(3);
  160.         push_width      = (cmd_width-4*dx)/2;
  161.         txt_width       = Def_Btn_Width;
  162.         pop_width       = Pop_Min_Width;
  163.         ybottomINI      = pos_win(4)-3.5*Def_Btn_Height-dy2;
  164.         
  165.         % Position property of objects.
  166.         %------------------------------
  167.         x_fra           = x_frame0+3*dx/2;
  168.         y_fra           = ybottomINI-13*Def_Btn_Height;
  169.         w_fra           = cmd_width-3*dx;
  170.         h_fra           = 10*Def_Btn_Height;
  171.         pos_fra         = [x_fra y_fra w_fra h_fra];
  172.         y_low           = ybottomINI-11*Def_Btn_Height/4;
  173.         w_uic           = 15*push_width/8;
  174.         px              = x_frame0+(cmd_width-w_uic)/2;
  175.         pos_hist_chist  = [px, y_low-3*Def_Btn_Height,              ...
  176.                            w_uic, 3*Def_Btn_Height/2];     
  177.         y_low           = pos_hist_chist(2)-3*Def_Btn_Height;
  178.         pos_corr_spec   = [px, y_low , w_uic, 3*Def_Btn_Height/2];
  179.         y_low           = pos_corr_spec(2)-3*Def_Btn_Height;
  180.         pos_info_stat   = [px, y_low , w_uic, 3*Def_Btn_Height/2];
  181.         y_low           = pos_fra(2)-2*Def_Btn_Height;
  182.         pos_txt_bin     = [px, y_low+d_txt/2, 2*pop_width,          ...
  183.                             Def_Txt_Height];
  184.         pos_edi_bin     = [px+2*pop_width+dx, y_low, pop_width,     ...
  185.                            Def_Btn_Height];
  186.         y_low           = ybottomINI-3*Def_Btn_Height-Def_Btn_Height/2;
  187.         w_uic           = Def_Btn_Width+dx2;
  188.         x_uic           = x_fra+(w_fra-w_uic)/2; 
  189.         pos_txt_axe     = [x_uic, y_low, w_uic, Def_Txt_Height];
  190.                                    
  191.         % String property of objects.
  192.         %----------------------------
  193.         str_hist_chist  = 'Histogram and Cumul. Histogram';
  194.         str_txt_bin     = 'Number of bins';
  195.         str_edi_bin     = sprintf('%.0f',default_bins);       
  196.         str_corr_spec   = 'Autocorrelations and Spectrum';
  197.         str_info_stat   = 'Descriptive Statistics';
  198.         str_txt_axe     = 'Selected Axes';
  199.         
  200.         % Callbacks property of objects.
  201.         %-------------------------------
  202.         cba_chk         = [mfilename '(''select'',' str_numwin ');'];
  203.         cba_edi_bin     = [mfilename '(''update_bins'',' str_numwin ');'];
  204.         
  205.         % Uicontrols definition.
  206.         %-----------------------
  207.         commonProp      = {'Parent',fig,'Unit',win_units};
  208.         comChkProp      = {commonProp{:},'Style','Checkbox'};
  209.         comFraProp      = {commonProp{:},                                   ...
  210.                                     'BackGroundColor',Def_FraBkColor,       ...
  211.                                     'Style','frame'                         ...
  212.                                     };
  213.         comPropTxtCENT  = {commonProp{:},                                   ...
  214.                                     'Style','text',                         ...
  215.                                     'HorizontalAlignment','center',         ...
  216.                                     'Backgroundcolor',Def_FraBkColor        ...
  217.                                     };
  218.         fra_utl         = uicontrol(comFraProp{:},                          ...
  219.                                     'Style','frame',                        ...
  220.                                     'Position',pos_fra,                     ...
  221.                                     'Visible','off'                         ...
  222.                                     );
  223.         txt_axe         = uicontrol(comPropTxtCENT{:},                      ...
  224.                                     'Position',pos_txt_axe,                 ...
  225.                                     'String',str_txt_axe,                   ...
  226.                                     'Visible','off'                         ...
  227.                                     );
  228.         chk_hist_chist  = uicontrol(comChkProp{:},                          ...
  229.                                     'Position',pos_hist_chist,              ...
  230.                                     'String',str_hist_chist,                ...
  231.                                     'ToolTipString',                        ...
  232.                                     'Histogram and Cumulative Histogram',   ...
  233.                                     'UserData',1,                           ...
  234.                                     'Value',1,                              ...
  235.                                     'Callback',cba_chk,                     ...
  236.                                     'Visible','off'                         ...
  237.                                     );
  238.         txt_bin         = uicontrol(commonProp{:},                          ...
  239.                                     'Style','text',                         ...
  240.                                     'Position',pos_txt_bin,                 ...
  241.                                     'String',str_txt_bin,                   ...
  242.                                     'Backgroundcolor',Def_FraBkColor,       ...
  243.                                     'Visible','off'                         ...
  244.                                     );
  245.         edi_bin         = uicontrol(commonProp{:},                          ...
  246.                                     'Style','Edit',                         ...
  247.                                     'Position',pos_edi_bin,                 ...
  248.                                     'String',str_edi_bin,                   ...
  249.                                     'Backgroundcolor',Def_EdiBkColor,       ...
  250.                                     'Callback',cba_edi_bin,                 ...
  251.                                     'Visible','off'                         ...
  252.                                     );
  253.         chk_corr_spec   = uicontrol(comChkProp{:},                          ...
  254.                                     'Position',pos_corr_spec,               ...
  255.                                     'String',str_corr_spec,                 ...
  256.                                     'UserData',1,                           ...
  257.                                     'Value',1,                              ...
  258.                                     'Callback',cba_chk,                     ...
  259.                                     'Visible','off'                         ...
  260.                                     );
  261.         chk_info_stat   = uicontrol(comChkProp{:},                          ...
  262.                                     'Position',pos_info_stat,               ...
  263.                                     'String',str_info_stat,                 ...
  264.                                     'UserData',1,                           ...
  265.                                     'Value',1,                              ...
  266.                                     'Callback',cba_chk,                     ...
  267.                                     'Visible','off'                         ...
  268.                                     );
  269.         % End of Uicontrols definitions depending on signal or image case.
  270.         %-----------------------------------------------------------------
  271.         switch typeDATA
  272.           case 'line'
  273.             set([chk_info_stat;chk_corr_spec;chk_hist_chist;fra_utl;txt_axe]...
  274.                 ,'Visible','On');
  275.           case 'image'
  276.             % Adding colormap GUI.
  277.             %---------------------
  278.             pos_txt_bin(2) = pos_txt_bin(2)+10*Def_Btn_Height;
  279.             pos_edi_bin(2) = pos_edi_bin(2)+10*Def_Btn_Height;
  280.             set(txt_bin,'Position',pos_txt_bin);
  281.             set(edi_bin,'Position',pos_edi_bin);
  282.             pop_pal_caller = cbcolmap('get',caller,'pop_pal');
  283.             prop_pal = get(pop_pal_caller,{'String','Value','Userdata'});
  284.             utcolmap('create',fig, ...
  285.                      'xloc',xlocINI, ...
  286.                      'bkcolor',Def_FraBkColor, ...
  287.                      'enable','on');
  288.             pop_pal_loc = cbcolmap('get',fig,'pop_pal');
  289.             set(pop_pal_loc,'String',prop_pal{1},'Value',prop_pal{2}, ...
  290.                             'Userdata',prop_pal{3});
  291.             set(fig,'Colormap',get(caller,'Colormap'));
  292.           case 'regress'
  293.             pos_txt_bin(2) = pos_txt_bin(2)+10*Def_Btn_Height;
  294.             pos_edi_bin(2) = pos_edi_bin(2)+10*Def_Btn_Height;
  295.             set(txt_bin,'Position',pos_txt_bin);
  296.             set(edi_bin,'Position',pos_edi_bin);
  297.         end
  298.         set([txt_bin;edi_bin],'Visible','On');
  299.         % Creating the Graphical part of the window.
  300.         %===========================================
  301.         % Frame Stats. construction.
  302.         %---------------------------
  303.         [infos_hdls,h_frame1] = utstats('create',fig,...
  304.                                         'xloc',Pos_Graphic_Area([1,3]), ...
  305.                                         'bottom',Pos_Graphic_Area(2)+dy2);
  306.         fra_sta     = infos_hdls(1);
  307.         pos_fra_sta = get(fra_sta,'Position');
  308.         % Axes Positions.
  309.         %----------------
  310.         gra_width  = Pos_Graphic_Area(3);
  311.         xspace     = gra_width/12;
  312.         yspace     = Pos_Graphic_Area(4)/9;
  313.         ecy_up     = 0.06*pos_win(4);
  314.         ecy_down   = 0.06*pos_win(4);
  315.         ecy_mid    = 0.08*pos_win(4);
  316.         y_rem      = pos_frame0(4)-(pos_fra_sta(2)+pos_fra_sta(4)) ...
  317.                                   -ecy_up-ecy_down;
  318.         switch typeDATA
  319.           case 'line'    ,  y_rem = y_rem-2*ecy_mid;
  320.           case 'image'   ,  y_rem = y_rem-ecy_mid;
  321.           case 'regress' ,  y_rem = y_rem-ecy_mid;
  322.         end
  323.         axe_width  = gra_width-2*xspace;
  324.         half_width = axe_width/2-xspace/2;
  325.         
  326.         switch typeDATA
  327.           case 'line'
  328.             axe_height     = y_rem/3;
  329.             y_low          = pos_fra_sta(2)+pos_fra_sta(4)+ecy_down;
  330.             pos_ax_corr    = [xspace y_low half_width axe_height];
  331.             pos_ax_spec    = [2*xspace+half_width y_low half_width axe_height];
  332.             y_low          = y_low+axe_height+ecy_mid;
  333.             pos_ax_hist    = [xspace y_low half_width axe_height];
  334.             pos_ax_cumhist = [2*xspace+half_width y_low half_width axe_height];
  335.             y_low          = y_low+axe_height+ecy_mid;
  336.             pos_ax_signal  = [xspace y_low axe_width axe_height];
  337.           case 'image'
  338.             axe_height     = y_rem/3;
  339.             y_low          = pos_fra_sta(2)+pos_fra_sta(4)+ecy_down;
  340.             pos_ax_hist    = [xspace y_low half_width axe_height];
  341.             pos_ax_cumhist = [2*xspace+half_width y_low half_width axe_height];
  342.             y_low          = y_low+axe_height+ecy_mid;
  343.             axe_height     = 2*y_rem/3;
  344.             cx             = xspace+axe_width/2;
  345.             cy             = y_low+axe_height/2;
  346.             imageSize      = wrev(size(resVal));
  347.             [w_use,h_use]  = wpropimg(imageSize,axe_width,axe_height,'pixels');
  348.             pos_ax_signal  = [cx-w_use/2,cy-h_use/2,w_use,h_use];
  349.             
  350.           case 'regress'
  351.             axe_height     = y_rem/2;
  352.             y_low          = pos_fra_sta(2)+pos_fra_sta(4)+ecy_down;
  353.             pos_ax_hist    = [xspace y_low half_width axe_height];
  354.             pos_ax_cumhist = [2*xspace+half_width y_low half_width axe_height];
  355.             y_low          = y_low+axe_height+ecy_mid;
  356.             pos_ax_signal  = [xspace y_low axe_width axe_height];
  357.         end
  358.         % Axes Definitions.
  359.         %------------------
  360.         commonProp = {...
  361.            'Parent',fig,...
  362.            'Units',win_units,...
  363.            'Visible','Off',...
  364.            'box','on',...
  365.            'NextPlot','Replace',...
  366.            'Drawmode','fast'...
  367.            };
  368.         axe_signal  = axes(commonProp{:},'Position',pos_ax_signal);
  369.         axe_hist    = axes(commonProp{:},'Position',pos_ax_hist);
  370.         axe_cumhist = axes(commonProp{:},'Position',pos_ax_cumhist);
  371.         switch typeDATA
  372.           case 'line'
  373.             axe_corr = axes(commonProp{:},'Position',pos_ax_corr);
  374.             axe_spec = axes(commonProp{:},'Position',pos_ax_spec);
  375.         end
  376.         % Displaying signal or image.
  377.         %----------------------------        
  378.         axes(axe_signal);
  379.         switch typeDATA
  380.           case {'line','regress'}
  381.             len = length(resVal);
  382.             if     ishandle(ls.handleORI) , xdata = get(ls.handleORI,'Xdata');
  383.             elseif ishandle(ls.handleTHR) , xdata = get(ls.handleTHR,'Xdata');
  384.             else   , xdata = [1:len]
  385.             end          
  386.             hdl_RES = line('Xdata',xdata,'Ydata',resVal,'Color',curr_color);
  387.             set(axe_signal,'Xlim',[xdata(1),xdata(end)])
  388.           case 'image'
  389.             hdl_RES = image(wcodemat(resVal,128,'mat',0));
  390.         end
  391.         wtitle('Residuals','Parent',axe_signal);
  392.         % Setting units to normalized.
  393.         %-----------------------------
  394.         wfigmngr('normalize',fig);
  395.         % Displaying histogram.
  396.         %----------------------
  397.         his       = wgethist(resVal(:),nb_bins);
  398.         [xx,imod] = max(his(2,:));
  399.         mode_val  = (his(1,imod)+his(1,imod+1))/2;
  400.         his(2,:)  = his(2,:)/length(resVal(:));
  401.         axes(axe_hist);
  402.         wplothis(axe_hist,his,curr_color);
  403.         wtitle('Histogram','Parent',axe_hist);
  404.         % Displaying cumulated histogram.
  405.         %--------------------------------
  406.         for i=6:4:length(his(2,:));
  407.             his(2,i)   = his(2,i)+his(2,i-4);
  408.             his(2,i+1) = his(2,i);
  409.         end
  410.         axes(axe_cumhist);
  411.         wplothis(axe_cumhist,[his(1,:);his(2,:)],curr_color);
  412.         wtitle('Cumulative histogram','Parent',axe_cumhist);
  413.         switch typeDATA
  414.           case 'line'
  415.             % Displaying Autocorrelations.
  416.             %-----------------------------       
  417.             [corr,lags] = wautocor(resVal);
  418.             lenLagsPos  = (length(lags)-1)/2;
  419.             lenKeep     = min(200,lenLagsPos);
  420.             first       = lenLagsPos+1-lenKeep;
  421.             last        = lenLagsPos+1+lenKeep;
  422.             Xval        = lags(first:last);
  423.             Yval        = corr(first:last);
  424.             axes(axe_corr);
  425.             hdl_RES = line('Xdata',Xval,'Ydata',Yval,'Color',curr_color);
  426.             set(axe_corr,'Xlim',[Xval(1) Xval(end)],...
  427.                          'Ylim',[min(0,1.1*min(Yval)) 1]);
  428.             wtitle('Autocorrelations','Parent',axe_corr);
  429.             
  430.             % Displaying Spectrum.
  431.             %---------------------
  432.             [sp,f]  = wspecfft(resVal);
  433.             axes(axe_spec);
  434.             hdl_RES = line('Xdata',f,'Ydata',sp,'Color',curr_color);
  435.             set(axe_spec,'Xlim',[min(f) max(f)]);
  436.             wtitle('FFT - Spectrum','Parent',axe_spec);
  437.             xlabel('Frequency','Parent',axe_spec);
  438.             ylabel('Energy','Parent',axe_spec);
  439.         end
  440.         % Displaying statistics.
  441.         %-----------------------
  442.         switch typeDATA
  443.           case {'line','regress'}
  444.              errtol    = 1.0E-12;
  445.              mean_val  = mean(resVal);
  446.              max_val   = max(resVal);
  447.              min_val   = min(resVal);
  448.              range_val = max_val-min_val;
  449.              std_val   = std(resVal);
  450.              med_val   = median(resVal);
  451.            case 'image'
  452.              errtol    = 1.0E-12;
  453.              mean_val  = mean(mean(resVal));
  454.              if abs(mean_val)<errtol , mean_val = 0; end
  455.              max_val   = max(max(resVal));
  456.              if abs(max_val)<errtol , max_val = 0; end
  457.              min_val   = min(min(resVal));
  458.              if abs(min_val)<errtol , min_val = 0; end
  459.              range_val = max_val-min_val;
  460.              if abs(range_val)<errtol , range_val = 0; end
  461.              std_val   = std(resVal(:));
  462.              if abs(std_val)<errtol , std_val = 0; end
  463.              med_val   = median(resVal(:));
  464.              if abs(med_val)<errtol , med_val = 0; end
  465.         end
  466.         medDev_val = median(abs(resVal(:)-med_val)); 
  467.         if abs(medDev_val)<errtol , medDev_val = 0; end
  468.         meanDev_val = mean(abs(resVal(:)-mean_val));      
  469.         if abs(meanDev_val)<errtol , meanDev_val = 0; end
  470.         utstats('display',fig, ...
  471.             [mean_val; med_val ; mode_val;  ...
  472.              max_val ; min_val ; range_val; ...
  473.              std_val ; medDev_val; meanDev_val]);
  474.         % Set axes visible.
  475.         %------------------
  476.         set([infos_hdls;axe_signal;axe_hist;axe_cumhist],'visible','on');
  477.         switch typeDATA
  478.           case 'line' , set([axe_corr;axe_spec],'visible','on');
  479.         end
  480.         % Store values.
  481.         %--------------
  482.         group_hdls  = struct(...
  483.                             'chk_hist_chist',   chk_hist_chist,     ...
  484.                             'txt_bin',          txt_bin,            ...
  485.                             'edi_bin',          edi_bin,            ...
  486.                             'chk_corr_spec',    chk_corr_spec,      ...
  487.                             'chk_info_stat',    chk_info_stat       ...
  488.                             );
  489.         set(axe_signal,'Userdata',get(axe_signal,'Position'));
  490.         set(axe_hist,'Userdata',get(axe_hist,'Position'));
  491.         set(axe_cumhist,'Userdata',get(axe_cumhist,'Position'));
  492.         Glb_Infos = struct(...
  493.                        'typeDATA',      typeDATA,   ...
  494.                        'resVal',        resVal,     ...
  495.                        'infos_hdls',    infos_hdls, ...
  496.                        'axe_signal',    axe_signal, ...
  497.                        'axe_hist',      axe_hist,   ...
  498.                        'axe_cumhist',   axe_cumhist ...
  499.                        );
  500.          switch typeDATA
  501.           case 'line'
  502.             set(axe_corr,'Userdata',get(axe_corr,'Position'));
  503.             set(axe_spec,'Userdata',get(axe_spec,'Position'));
  504.             Glb_Infos.axe_corr = axe_corr;
  505.             Glb_Infos.axe_spec = axe_spec;
  506.           case {'image','regress'}
  507.         end
  508.         
  509.         wfigmngr('storeValue',fig,'group_hdls',group_hdls);
  510.         wfigmngr('storeValue',fig,'Glb_Infos',Glb_Infos);
  511.         wfigmngr('storeValue',fig,'Old_nb_bins',nb_bins);
  512.                 
  513.         % Dynvtool Attachement.
  514.         %---------------------
  515.         switch typeDATA
  516.           case 'line'
  517.             axe_ind = [axe_signal axe_corr axe_spec];
  518.           case {'image','regress'}
  519.             axe_ind = [axe_signal];
  520.         end
  521.         axe_cmd = [];
  522.         axe_act = [];
  523.         dynvtool('attach',fig,axe_ind,axe_cmd,axe_act,[1 0],'','','');
  524.         dynvtool('put',fig);
  525.         % End waiting.
  526.         %-------------
  527.         wwaiting('off',fig);
  528.     case 'select'
  529.         %**************************************************************%
  530.         %** OPTION = 'select' - GROUP AXES SELECTION                 **%
  531.         %**************************************************************%
  532.         sel_chk_btn      = gcbo;
  533.         % Get stored structure.
  534.         %----------------------
  535.         group_hdls     = wfigmngr('getValue',fig,'group_hdls');
  536.         chk_hist_chist = group_hdls.chk_hist_chist;
  537.         txt_bin        = group_hdls.txt_bin;
  538.         edi_bin        = group_hdls.edi_bin;
  539.         chk_corr_spec  = group_hdls.chk_corr_spec;
  540.         chk_info_stat  = group_hdls.chk_info_stat;
  541.         Glb_Infos      = wfigmngr('getValue',fig,'Glb_Infos');
  542.         resVal         = Glb_Infos.resVal;
  543.         infos_hdls     = Glb_Infos.infos_hdls;
  544.         axe_signal     = Glb_Infos.axe_signal;
  545.         axe_hist       = Glb_Infos.axe_hist;
  546.         axe_cumhist    = Glb_Infos.axe_cumhist;
  547.         axe_corr       = Glb_Infos.axe_corr;
  548.         axe_spec       = Glb_Infos.axe_spec;
  549.         fra_sta        = infos_hdls(1);
  550.         
  551.         % Get the current selection.
  552.         %---------------------------
  553.         hist_chist = (get(chk_hist_chist,'Userdata')~=0);
  554.         corr_spec  = (get(chk_corr_spec,'Userdata')~=0);
  555.         info_stat  = (get(chk_info_stat,'Userdata')~=0);
  556.         % Get the axes original positions.
  557.         %---------------------------------
  558.         pos_axe_signal  = get(axe_signal,'Userdata');
  559.         pos_axe_hist    = get(axe_hist,'Userdata');
  560.         pos_axe_cumhist = get(axe_cumhist,'Userdata');
  561.         pos_axe_corr    = get(axe_corr,'Userdata');
  562.         pos_axe_spec    = get(axe_spec,'Userdata');
  563.         pos_fra_sta     = get(fra_sta,'Position');
  564.         
  565.         % Graphical parameters.
  566.         %----------------------
  567.         yspace    = 2*pos_fra_sta(2);
  568.         heigh_max = pos_axe_signal(2)+pos_axe_signal(4)+yspace;
  569.         
  570.         % Redraw depending on the current selection.
  571.         %-------------------------------------------
  572.         switch sel_chk_btn
  573.             case chk_hist_chist
  574.                 if hist_chist
  575.                     set(chk_hist_chist,'Value',0,'Userdata',0);
  576.                     if info_stat
  577.                         y_rem = heigh_max-(pos_fra_sta(2)+ ...
  578.                                 pos_fra_sta(4))-7*yspace/4;
  579.                         y_low = pos_fra_sta(2)+pos_fra_sta(4)+yspace/3;
  580.                         if corr_spec
  581.                             axe_height        = y_rem/2;
  582.                             pos_axe_corr(2)   = y_low;
  583.                             pos_axe_corr(4)   = axe_height;
  584.                             pos_axe_spec(2)   = y_low;
  585.                             pos_axe_spec(4)   = axe_height;
  586.                             y_low             = y_low+axe_height+yspace/3;
  587.                             pos_axe_signal(2) = y_low;
  588.                             pos_axe_signal(4) = axe_height;
  589.                         else
  590.                             axe_height        = y_rem;
  591.                             pos_axe_signal(2) = y_low+yspace/6;
  592.                             pos_axe_signal(4) = axe_height;
  593.                         end
  594.                     else
  595.                         y_rem = heigh_max-9*yspace/4;
  596.                         y_low = pos_fra_sta(2)+yspace/3;
  597.                         if corr_spec
  598.                             axe_height        = y_rem/2;
  599.                             pos_axe_corr(2)   = y_low;
  600.                             pos_axe_corr(4)   = axe_height;
  601.                             pos_axe_spec(2)   = y_low;
  602.                             pos_axe_spec(4)   = axe_height;
  603.                             y_low             = y_low+axe_height+yspace/3;
  604.                             pos_axe_signal(2) = y_low;
  605.                             pos_axe_signal(4) = axe_height;
  606.                         else
  607.                             axe_height        = y_rem;
  608.                             pos_axe_signal(2) = y_low+yspace/6;
  609.                             pos_axe_signal(4) = axe_height;
  610.                         end
  611.                     end
  612.                 else
  613.                     set(chk_hist_chist,'Value',1,'Userdata',1);
  614.                     if info_stat
  615.                         y_rem = heigh_max-(pos_fra_sta(2)+ ...
  616.                                 pos_fra_sta(4))-8*yspace/4;
  617.                         y_low = pos_fra_sta(2)+pos_fra_sta(4)+yspace/3;
  618.                         if corr_spec
  619.                             axe_height         = y_rem/3;
  620.                             pos_axe_corr(2)    = y_low;
  621.                             pos_axe_corr(4)    = axe_height;
  622.                             pos_axe_spec(2)    = y_low;
  623.                             pos_axe_spec(4)    = axe_height;
  624.                             y_low              = y_low+axe_height+yspace/3;
  625.                             pos_axe_hist(2)    = y_low;
  626.                             pos_axe_hist(4)    = axe_height;
  627.                             pos_axe_cumhist(2) = y_low;
  628.                             pos_axe_cumhist(4) = axe_height;
  629.                             y_low              = y_low+axe_height+yspace/3;
  630.                             pos_axe_signal(2)  = y_low;
  631.                             pos_axe_signal(4)  = axe_height;
  632.                         else
  633.                             axe_height         = y_rem/2;
  634.                             pos_axe_hist(2)    = y_low;
  635.                             pos_axe_hist(4)    = axe_height;
  636.                             pos_axe_cumhist(2) = y_low;
  637.                             pos_axe_cumhist(4) = axe_height;
  638.                             y_low              = y_low+axe_height+yspace/3;
  639.                             pos_axe_signal(2)  = y_low;
  640.                             pos_axe_signal(4)  = axe_height;
  641.                         end
  642.                     else
  643.                         y_rem = heigh_max-10*yspace/4;
  644.                         y_low = pos_fra_sta(2)+yspace/3;
  645.                         if corr_spec
  646.                             axe_height         = y_rem/3;
  647.                             pos_axe_corr(2)    = y_low;
  648.                             pos_axe_corr(4)    = axe_height;
  649.                             pos_axe_spec(2)    = y_low;
  650.                             pos_axe_spec(4)    = axe_height;
  651.                             y_low              = y_low+axe_height+yspace/3;
  652.                             pos_axe_hist(2)    = y_low;
  653.                             pos_axe_hist(4)    = axe_height;
  654.                             pos_axe_cumhist(2) = y_low;
  655.                             pos_axe_cumhist(4) = axe_height;
  656.                             y_low              = y_low+axe_height+yspace/3;
  657.                             pos_axe_signal(2)  = y_low;
  658.                             pos_axe_signal(4)  = axe_height;
  659.                         else
  660.                             axe_height         = y_rem/2;
  661.                             pos_axe_hist(2)    = y_low;
  662.                             pos_axe_hist(4)    = axe_height;
  663.                             pos_axe_cumhist(2) = y_low;
  664.                             pos_axe_cumhist(4) = axe_height;
  665.                             y_low              = y_low+axe_height+yspace/3;
  666.                             pos_axe_signal(2)  = y_low;
  667.                             pos_axe_signal(4)  = axe_height;
  668.                         end
  669.                     end
  670.                 end
  671.             case chk_corr_spec
  672.                 if corr_spec
  673.                     set(chk_corr_spec,'Value',0,'Userdata',0);
  674.                     if info_stat
  675.                         y_rem = heigh_max-(pos_fra_sta(2)+ ...
  676.                                 pos_fra_sta(4))-7*yspace/4;
  677.                         y_low = pos_fra_sta(2)+pos_fra_sta(4)+yspace/3;
  678.                         if hist_chist
  679.                             axe_height         = y_rem/2;
  680.                             pos_axe_hist(2)    = y_low;
  681.                             pos_axe_hist(4)    = axe_height;
  682.                             pos_axe_cumhist(2) = y_low;
  683.                             pos_axe_cumhist(4) = axe_height;
  684.                             y_low              = y_low+axe_height+yspace/3;
  685.                             pos_axe_signal(2)  = y_low;
  686.                             pos_axe_signal(4)  = axe_height;
  687.                         else
  688.                             axe_height         = y_rem;
  689.                             pos_axe_signal(2)  = y_low+yspace/6;
  690.                             pos_axe_signal(4)  = axe_height;
  691.                         end
  692.                     else
  693.                         y_rem = heigh_max-9*yspace/4;
  694.                         y_low = pos_fra_sta(2)+yspace/3;
  695.                         if hist_chist
  696.                             axe_height         = y_rem/2;
  697.                             pos_axe_hist(2)    = y_low;
  698.                             pos_axe_hist(4)    = axe_height;
  699.                             pos_axe_cumhist(2) = y_low;
  700.                             pos_axe_cumhist(4) = axe_height;
  701.                             y_low              = y_low+axe_height+yspace/3;
  702.                             pos_axe_signal(2)  = y_low;
  703.                             pos_axe_signal(4)  = axe_height;
  704.                         else
  705.                             axe_height        = y_rem;
  706.                             pos_axe_signal(2) = y_low+yspace/6;
  707.                             pos_axe_signal(4) = axe_height;
  708.                         end
  709.                     end
  710.                 else
  711.                     set(chk_corr_spec,'Value',1,'Userdata',1);
  712.                     if info_stat
  713.                         y_rem = heigh_max-(pos_fra_sta(2)+ ...
  714.                                 pos_fra_sta(4))-8*yspace/4;
  715.                         y_low = pos_fra_sta(2)+pos_fra_sta(4)+yspace/3;
  716.                         if hist_chist
  717.                             axe_height         = y_rem/3;
  718.                             pos_axe_corr(2)    = y_low;
  719.                             pos_axe_corr(4)    = axe_height;
  720.                             pos_axe_spec(2)    = y_low;
  721.                             pos_axe_spec(4)    = axe_height;
  722.                             y_low              = y_low+axe_height+yspace/3;
  723.                             pos_axe_hist(2)    = y_low;
  724.                             pos_axe_hist(4)    = axe_height;
  725.                             pos_axe_cumhist(2) = y_low;
  726.                             pos_axe_cumhist(4) = axe_height;
  727.                             y_low              = y_low+axe_height+yspace/3;
  728.                             pos_axe_signal(2)  = y_low;
  729.                             pos_axe_signal(4)  = axe_height;
  730.                         else
  731.                             axe_height         = y_rem/2;
  732.                             pos_axe_corr(2)    = y_low;
  733.                             pos_axe_corr(4)    = axe_height;
  734.                             pos_axe_spec(2)    = y_low;
  735.                             pos_axe_spec(4)    = axe_height;
  736.                             y_low              = y_low+axe_height+yspace/3;
  737.                             pos_axe_signal(2)  = y_low;
  738.                             pos_axe_signal(4)  = axe_height;
  739.                         end
  740.                     else
  741.                         y_rem = heigh_max-10*yspace/4;
  742.                         y_low = pos_fra_sta(2)+yspace/3;
  743.                         if hist_chist
  744.                             axe_height         = y_rem/3;
  745.                             pos_axe_corr(2)    = y_low;
  746.                             pos_axe_corr(4)    = axe_height;
  747.                             pos_axe_spec(2)    = y_low;
  748.                             pos_axe_spec(4)    = axe_height;
  749.                             y_low              = y_low+axe_height+yspace/3;
  750.                             pos_axe_hist(2)    = y_low;
  751.                             pos_axe_hist(4)    = axe_height;
  752.                             pos_axe_cumhist(2) = y_low;
  753.                             pos_axe_cumhist(4) = axe_height;
  754.                             y_low              = y_low+axe_height+yspace/3;
  755.                             pos_axe_signal(2)  = y_low;
  756.                             pos_axe_signal(4)  = axe_height;
  757.                         else
  758.                             axe_height         = y_rem/2;
  759.                             pos_axe_corr(2)    = y_low;
  760.                             pos_axe_corr(4)    = axe_height;
  761.                             pos_axe_spec(2)    = y_low;
  762.                             pos_axe_spec(4)    = axe_height;
  763.                             y_low              = y_low+axe_height+yspace/3;
  764.                             pos_axe_signal(2)  = y_low;
  765.                             pos_axe_signal(4)  = axe_height;
  766.                         end
  767.                     end
  768.                 end
  769.             case chk_info_stat
  770.                 if info_stat
  771.                     set(chk_info_stat,'Value',0,'Userdata',0);
  772.                     y_low = pos_fra_sta(2)+yspace/3;
  773.                     if corr_spec
  774.                         y_rem = heigh_max-10*yspace/4;
  775.                         if hist_chist
  776.                             axe_height         = y_rem/3;
  777.                             pos_axe_corr(2)    = y_low;
  778.                             pos_axe_corr(4)    = axe_height;
  779.                             pos_axe_spec(2)    = y_low;
  780.                             pos_axe_spec(4)    = axe_height;
  781.                             y_low              = y_low+axe_height+yspace/3;
  782.                             pos_axe_hist(2)    = y_low;
  783.                             pos_axe_hist(4)    = axe_height;
  784.                             pos_axe_cumhist(2) = y_low;
  785.                             pos_axe_cumhist(4) = axe_height;
  786.                             y_low              = y_low+axe_height+yspace/3;
  787.                             pos_axe_signal(2)  = y_low;
  788.                             pos_axe_signal(4)  = axe_height;
  789.                         else
  790.                             axe_height         = y_rem/2;
  791.                             pos_axe_corr(2)    = y_low;
  792.                             pos_axe_corr(4)    = axe_height;
  793.                             pos_axe_spec(2)    = y_low;
  794.                             pos_axe_spec(4)    = axe_height;
  795.                             y_low              = y_low+axe_height+yspace/3;
  796.                             pos_axe_signal(2)  = y_low+yspace/6;
  797.                             pos_axe_signal(4)  = axe_height;
  798.                         end
  799.                     else
  800.                         y_rem = heigh_max-9*yspace/4;
  801.                         if hist_chist
  802.                             axe_height         = y_rem/2;
  803.                             pos_axe_hist(2)    = y_low;
  804.                             pos_axe_hist(4)    = axe_height;
  805.                             pos_axe_cumhist(2) = y_low;
  806.                             pos_axe_cumhist(4) = axe_height;
  807.                             y_low              = y_low+axe_height+yspace/3;
  808.                             pos_axe_signal(2)  = y_low;
  809.                             pos_axe_signal(4)  = axe_height;
  810.                         else
  811.                             axe_height        = y_rem;
  812.                             pos_axe_signal(2) = y_low+yspace/6;
  813.                             pos_axe_signal(4) = axe_height;
  814.                         end
  815.                     end
  816.                 else
  817.                     set(chk_info_stat,'Value',1,'Userdata',1);
  818.                     y_low = pos_fra_sta(2)+pos_fra_sta(4)+yspace/3;
  819.                     if corr_spec
  820.                         if hist_chist
  821.                             y_rem = heigh_max-(pos_fra_sta(2)+ ...
  822.                                     pos_fra_sta(4))-8*yspace/4;
  823.                             axe_height         = y_rem/3;
  824.                             pos_axe_corr(2)    = y_low;
  825.                             pos_axe_corr(4)    = axe_height;
  826.                             pos_axe_spec(2)    = y_low;
  827.                             pos_axe_spec(4)    = axe_height;
  828.                             y_low              = y_low+axe_height+yspace/3;
  829.                             pos_axe_hist(2)    = y_low;
  830.                             pos_axe_hist(4)    = axe_height;
  831.                             pos_axe_cumhist(2) = y_low;
  832.                             pos_axe_cumhist(4) = axe_height;
  833.                             y_low              = y_low+axe_height+yspace/3;
  834.                             pos_axe_signal(2)  = y_low;
  835.                             pos_axe_signal(4)  = axe_height;
  836.                         else
  837.                             y_rem = heigh_max-(pos_fra_sta(2)+ ...
  838.                                     pos_fra_sta(4))-7*yspace/4;
  839.                             axe_height         = y_rem/2;
  840.                             pos_axe_corr(2)    = y_low;
  841.                             pos_axe_corr(4)    = axe_height;
  842.                             pos_axe_spec(2)    = y_low;
  843.                             pos_axe_spec(4)    = axe_height;
  844.                             y_low              = y_low+axe_height+yspace/3;
  845.                             pos_axe_signal(2)  = y_low;
  846.                             pos_axe_signal(4)  = axe_height;
  847.                         end
  848.                     else
  849.                             y_rem = heigh_max-(pos_fra_sta(2)+ ...
  850.                                     pos_fra_sta(4))-7*yspace/4;
  851.                             if hist_chist
  852.                             axe_height         = y_rem/2;
  853.                             pos_axe_hist(2)    = y_low;
  854.                             pos_axe_hist(4)    = axe_height;
  855.                             pos_axe_cumhist(2) = y_low;
  856.                             pos_axe_cumhist(4) = axe_height;
  857.                             y_low              = y_low+axe_height+yspace/3;
  858.                             pos_axe_signal(2)  = y_low;
  859.                             pos_axe_signal(4)  = axe_height;
  860.                         else
  861.                             y_rem = heigh_max-(pos_fra_sta(2)+ ...
  862.                                     pos_fra_sta(4))-6*yspace/4;
  863.                             axe_height         = y_rem;
  864.                             pos_axe_signal(2)  = y_low;
  865.                             pos_axe_signal(4)  = axe_height;
  866.                         end
  867.                     end
  868.                 end
  869.         end
  870.         
  871.         % Set the current positions.
  872.         %---------------------------
  873.         set(axe_signal,'Position',pos_axe_signal);
  874.         set(axe_hist,'Position',pos_axe_hist);
  875.         set(axe_cumhist,'Position',pos_axe_cumhist);
  876.         set(axe_corr,'Position',pos_axe_corr);
  877.         set(axe_spec,'Position',pos_axe_spec);
  878.         % Set enability and visibility for each controlable axes or frames.
  879.         %------------------------------------------------------------------
  880.         set(axe_signal,'Visible','on');
  881.         set(get(axe_signal,'Children'),'Visible','on');
  882.                  
  883.         if  get(chk_hist_chist,'Value')
  884.             set(txt_bin,'Visible','on');
  885.             set(edi_bin,'Visible','on');
  886.             set(axe_hist,'Visible','on');
  887.             set(get(axe_hist,'Children'),'Visible','on');
  888.             set(axe_cumhist,'Visible','on');
  889.             set(get(axe_cumhist,'Children'),'Visible','on');
  890.         else
  891.             set(txt_bin,'Visible','off');
  892.             set(edi_bin,'Visible','off');
  893.             set(axe_hist,'Visible','off');
  894.             set(get(axe_hist,'Children'),'Visible','off');
  895.             set(axe_cumhist,'Visible','off');
  896.             set(get(axe_cumhist,'Children'),'Visible','off');            
  897.         end
  898.         if  get(chk_corr_spec,'Value')
  899.             set(axe_corr,'Visible','on');
  900.             set(get(axe_corr,'Children'),'Visible','on');
  901.             set(axe_spec,'Visible','on');
  902.             set(get(axe_spec,'Children'),'Visible','on');
  903.         else
  904.             set(axe_corr,'Visible','off');
  905.             set(get(axe_corr,'Children'),'Visible','off');
  906.             set(axe_spec,'Visible','off');
  907.             set(get(axe_spec,'Children'),'Visible','off');        
  908.         end
  909.                    
  910.         if  get(chk_info_stat,'Value')
  911.             set(infos_hdls,'Visible','on');
  912.         else
  913.             set(infos_hdls,'Visible','off');
  914.         end
  915.                
  916.     case 'update_bins'
  917.         %**************************************************************%
  918.         %** OPTION = 'update_bins' - UPDATE HISTOGRAMS WITH NEW BINS **%
  919.         %**************************************************************%
  920.         edi_bin     = gcbo;
  921.         % Get stored structure.
  922.         %----------------------
  923.         Old_nb_bins = wfigmngr('getValue',fig,'Old_nb_bins');
  924.         Glb_Infos   = wfigmngr('getValue',fig,'Glb_Infos');
  925.         resVal      = Glb_Infos.resVal;
  926.         infos_hdls  = Glb_Infos.infos_hdls;
  927.         axe_signal  = Glb_Infos.axe_signal;
  928.         axe_hist    = Glb_Infos.axe_hist;
  929.         axe_cumhist = Glb_Infos.axe_cumhist;
  930.         % Return if no current display.
  931.         %------------------------------
  932.         vis = get(axe_hist,'Visible');
  933.         if vis(1:2)=='of', return, end
  934.         % Check the bins number.
  935.         %-----------------------
  936.         if ~isempty(Old_nb_bins)
  937.             default_bins = Old_nb_bins;
  938.         end
  939.         nb_bins = wstr2num(get(edi_bin,'String'));
  940.         if isempty(nb_bins) | (nb_bins<2)
  941.             nb_bins = default_bins;   
  942.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  943.         end
  944.         if default_bins==nb_bins , return; end
  945.         % Waiting message.
  946.         %-----------------
  947.         wwaiting('msg',fig,'Wait ... computing');
  948.         % Save Userdata.
  949.         %---------------
  950.         pos_axe_hist    = get(axe_hist,'Userdata');
  951.         pos_axe_cumhist = get(axe_cumhist,'Userdata');
  952.         
  953.         % Updating histograms.
  954.         %---------------------
  955.         if ~isempty(resVal)
  956.             Old_nb_bins = nb_bins;
  957.             wfigmngr('storeValue',fig,'Old_nb_bins',Old_nb_bins);
  958.             his      = wgethist(resVal(:),nb_bins);
  959.             his(2,:) = his(2,:)/length(resVal(:));
  960.             axes(axe_hist);
  961.             wplothis(axe_hist,his,curr_color);
  962.             wtitle('Histogram','Parent',axe_hist);
  963.             for i=6:4:length(his(2,:));
  964.                 his(2,i)   = his(2,i)+his(2,i-4);
  965.                 his(2,i+1) = his(2,i);
  966.             end
  967.             axes(axe_cumhist);
  968.             wplothis(axe_cumhist,[his(1,:);his(2,:)],curr_color);
  969.             wtitle('Cumulative histogram','Parent',axe_cumhist);
  970.         end
  971.         
  972.         % Restore Userdata.
  973.         %------------------
  974.         set(axe_hist,'Userdata',pos_axe_hist);
  975.         set(axe_cumhist,'Userdata',pos_axe_cumhist);
  976.         
  977.         % End waiting.
  978.         %-------------
  979.         wwaiting('off',fig);
  980.         
  981.     case 'save'
  982.     %---------------------------------%
  983.     % Option: SAVE : Saving residuals %
  984.     %---------------------------------%
  985.         % Get arguments.
  986.         %---------------
  987.         fig = varargin{1};
  988.         % Testing file.
  989.         %--------------
  990.         [filename,pathname,ok] = utguidiv('test_save',fig, ...
  991.                                     '*.mat','Save Residuals');
  992.         if ~ok, return; end
  993.         % Begin waiting.
  994.         %--------------
  995.         wwaiting('msg',fig,'Wait ... saving');
  996.         % Get the residuals to save.
  997.         %---------------------------
  998.         Glb_Infos = wfigmngr('getValue',fig,'Glb_Infos');
  999.         resVal    = Glb_Infos.resVal;
  1000.         typeDATA  = Glb_Infos.typeDATA;
  1001.         % Saving transformed Signal.
  1002.         %---------------------------
  1003.         [name,ext] = strtok(filename,'.');
  1004.         if isempty(ext) | isequal(ext,'.')
  1005.             ext = '.mat'; filename = [name ext];
  1006.         end
  1007.         switch typeDATA
  1008.           case 'image'
  1009.             X   = resVal;
  1010.             map = get(fig,'Colormap');
  1011.             saveStr = {'X','map'};
  1012.             
  1013.           case 'regress'
  1014.             ls = wmemtool('rmb',fig,n_membloc1,ind_loc_struct);
  1015.             xdata = get(ls.handleTHR,'Xdata');
  1016.             x_ori = get(ls.handleORI,'Xdata');
  1017.             ydata = interp1(resVal,xdata);
  1018.             saveStr = {'xdata','ydata'};
  1019.           otherwise
  1020.             eval([name ' = resVal;']);
  1021.             saveStr = {name};
  1022.         end
  1023.         try
  1024.           save([pathname filename],saveStr{:});
  1025.         catch
  1026.           errargt(mfilename,'Save FAILED !','msg');
  1027.         end
  1028.         
  1029.         % End waiting.
  1030.         %-------------
  1031.         wwaiting('off',fig);
  1032.     case 'close'
  1033.         %**************************************************************%
  1034.         %** OPTION = 'close' - Close the current figure              **%
  1035.         %**************************************************************%
  1036.         fig = varargin{1};        
  1037.         ls      = wmemtool('rmb',fig,n_membloc1,ind_loc_struct);
  1038.         caller  = ls.caller;
  1039.         toggle  = ls.toggle;
  1040.         if ishandle(toggle) , set(toggle,'Value',0); end
  1041.     otherwise
  1042.         errargt(mfilename,'Unknown Option','msg');
  1043.         error('*');
  1044. end
  1045. %-------------------------------------------------------------------------%
  1046. function [type,prop] = getDataType(handle)
  1047. type = get(handle,'Type');
  1048. switch type
  1049.   case 'line'  , prop = 'Ydata';
  1050.   case 'image' , prop = 'Cdata';
  1051. end    
  1052. %-------------------------------------------------------------------------%
  1053. %-------------------------------------------------------------------------%
  1054. function [sp,f] = wspecfft(signal)
  1055. %WSPECFFT FFT spectrum of a signal.
  1056. %
  1057. % f is the frequency 
  1058. % sp is the energy, the square of the FFT transform
  1059. % The input signal is empty.
  1060. %---------------------------
  1061. if isempty(signal)
  1062.     sp = [];f =[];return
  1063. end
  1064. % Compute the spectrum.
  1065. %----------------------
  1066. n   = length(signal);
  1067. XTF = fft(fftshift(signal));
  1068. m   = ceil(n/2) + 1;
  1069. % Compute the output values.
  1070. %---------------------------
  1071. f   = linspace(0,0.5,m);
  1072. sp  = (abs(XTF(1:m))).^2;
  1073. %-------------------------------------------------------------------------%
  1074. %-------------------------------------------------------------------------%
  1075. function [c,lags] = wautocor(a,maxlag)
  1076. %WAUTOCOR Auto-correlation function estimates.
  1077. %   [C,LAGS] = WAUTOCOR(A,MAXLAG) computes the 
  1078. %   autocorrelation function c of a one dimensional
  1079. %   signal a, for lags = [-maxlag:maxlag]. 
  1080. %   The autocorrelation c(maxlag+1) = 1.
  1081. %   If nargin==1, by default, maxlag = length(a)-1.
  1082. if nargin == 1, maxlag = size(a,2)-1;end
  1083. lags = -maxlag:maxlag;
  1084. if isempty(a) , c = []; return; end
  1085. epsi = sqrt(eps);
  1086. a    = a(:);
  1087. a    = a - mean(a);
  1088. nr   = length(a); 
  1089. if std(a)>epsi
  1090.     % Test of the variance.
  1091.     %----------------------
  1092.     mr     = 2 * maxlag + 1;
  1093.     nfft   = 2^nextpow2(mr);
  1094.     nsects = ceil(2*nr/nfft);
  1095.     if nsects>4 & nfft<64
  1096.         nfft = min(4096,max(64,2^nextpow2(nr/4)));
  1097.     end
  1098.     c      = zeros(nfft,1);
  1099.     minus1 = (-1).^(0:nfft-1)';
  1100.     af_old = zeros(nfft,1);
  1101.     n1     = 1;
  1102.     nfft2  = nfft/2;
  1103.     while (n1<nr)
  1104.        n2 = min( n1+nfft2-1, nr );
  1105.        af = fft(a(n1:n2,:), nfft);
  1106.        c  = c + af.* conj( af + af_old);
  1107.        n1 = n1 + nfft2;
  1108.        af_old = minus1.*af;
  1109.     end
  1110.     if n1==nr
  1111.         af = ones(nfft,1)*a(nr,:);
  1112.     c  = c + af.* conj( af + af_old );
  1113.     end
  1114.     mxlp1 = maxlag+1;
  1115.     c = real(ifft(c));
  1116.     c = [ c(mxlp1:-1:2,:); c(1:mxlp1,1) ];
  1117.     % Compute the autocorrelation function.
  1118.     %-------------------------------------- 
  1119.     cdiv = c(mxlp1,1);
  1120.     c = c / cdiv;
  1121. else
  1122.     % If  the variance is too small.
  1123.     %-------------------------------
  1124.     c = ones(size(lags));
  1125. end
  1126. %-------------------------------------------------------------------------%