function dguidw1d(varargin)
%DGUIDW1D Demonstrates 1D wavelet GUI tools in the Wavelet Toolbox. 

%   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
%   Last Revision: 27-Jun-1999.
%   Copyright 1995-2000 The MathWorks, Inc.
% $Revision: 1.10 $

% Check arguments.
%=================
switch nargin
  case 0 , figNumber = 0; wait_mode = 1;
  case 2 ,   
    if isequal(varargin{1},'noGUI')
        figNumber = 0;
        wait_mode = varargin{2};
    else
        figNumber = varargin{1};
        wait_mode = 1;
    end
end

if wshowdrv('init',figNumber)
    if figNumber==0 
        active_fig = dw1dtool;
        wenamngr('Inactive',active_fig);
    else
        active_fig = demoguim('startshow',figNumber,'dw1dtool');
        wenamngr('Inactive',active_fig);
        wshowdrv('setactfig',figNumber,active_fig);
        return;
    end
end
if exist('wait_mode')~=1 , wait_mode = 1; end
if figNumber , active_fig = wshowdrv('getactfig',figNumber); end

dw1dmngr('demo',active_fig,'noisdopp','db2',6);
wenamngr('Inactive',active_fig);
if wshowdrv('pause',figNumber,wait_mode), return; end;

tag_pop_viewm   = 'View_Mode';
tag_declev      = 'Pop_DecLev';
pop_handles     = findobj(active_fig,'style','popupmenu');
pop_viewm       = findobj(pop_handles,'tag',tag_pop_viewm);
pop_decm        = findobj(pop_handles,'tag',tag_declev);
cba_viewm       = get(pop_viewm,'Callback');
cba_decm        = get(pop_decm,'Callback');

msg = str2mat(...
         'The present Display mode is Full Decomposition mode.', ...
        ['To change the Display mode use the corresponding popupmenu ' ...
         'in the middle of the window.'],...
         'Six display modes are available.'...
        );
if dguiwait('pause',figNumber,0,active_fig,msg); return; end


msg = ['We select the Superimpose Mode.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_viewm,'value',4);
eval(cba_viewm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We select the Show and Scroll Mode.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_viewm,'value',1);
eval(cba_viewm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We select the Separate Mode.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_viewm,'value',3);
eval(cba_viewm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We select the Tree Mode.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_viewm,'value',5);
eval(cba_viewm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We select the Show and Scroll (Stem Cfs) Mode.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_viewm,'value',6);
eval(cba_viewm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We go back to the Full Decomposition mode.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_viewm,'value',2);
eval(cba_viewm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We select the Full Decomposition at level 2.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_decm,'value',2);
eval(cba_decm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = ['We restore the Full Decomposition at level 6.'];
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

set(pop_decm,'value',6);
eval(cba_decm);
if wshowdrv('pause',figNumber,wait_mode), return; end;

msg = 'The Compress pushbutton is used to call the compression tool.';
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

out2 = dw1dmngr('comp',active_fig);
wenamngr('Inactive',out2);

msg = 'We compress the signal with the default options.';
if dguiwait('pause',figNumber,0,out2,msg); return; end

dw1dcomp('compress',out2,active_fig);
if wshowdrv('pause',figNumber,wait_mode), return; end;
delete(out2); drawnow; pause(2)
dw1dmngr('return_comp',active_fig,0);
wenamngr('Inactive',active_fig);

msg = 'The De-noise pushbutton is used to call the de-noising tool.';
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

out3 = dw1dmngr('deno',active_fig);
wenamngr('Inactive',out3);

msg = 'We de-noise the signal with the default options.';
if dguiwait('pause',figNumber,0,out3,msg); return; end

dw1ddeno('denoise',out3,active_fig);
if wshowdrv('pause',figNumber,wait_mode), return; end;
delete(out3); drawnow; pause(2)
dw1dmngr('return_deno',active_fig,0);
wenamngr('Inactive',active_fig);

msg = 'The Statistics pushbutton is used to call the statistics tool.';
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

out4 = dw1dmngr('stat',active_fig);
dw1dstat('demo',out4);
wenamngr('Inactive',out4);
if wshowdrv('pause',figNumber,wait_mode), return; end;
delete(out4); drawnow; pause(2)

msg = 'The Histograms pushbutton is used to call the histograms tool.';
if dguiwait('pause',figNumber,0,active_fig,msg); return; end

out5 = dw1dmngr('hist',active_fig);
dw1dhist('demo',out5);
wenamngr('Inactive',out5);
if wshowdrv('pause',figNumber,wait_mode), return; end;

delete(out5); drawnow; pause(2)
if figNumber==0
    wshowdrv('pause',figNumber,wait_mode);
    dw1dtool('close',active_fig);
    delete(active_fig)
end
