function iduispa(arg)
%IDUISPA Handles the spectral analysis dialog.

%	L. Ljung 9-27-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.7 $  $Date: 1995/05/02 16:32:08 $

global XIDplotw XIDlayout

if strcmp(arg,'open')
   figname=idlaytab('figname',33);
   if ~figflag(figname,0)
       iduistat('Opening the spectral analysis dialog box ...')
       layout
       FigW = iduilay2(3);

       f=figure('vis','off',...
             'NumberTitle','off','Name',figname,'NextPlot','New',...
             'Color',get(0,'DefaultUIControlBackgroundColor'),...
             'tag','sitb33','Menubar','none');

       % LEVEL1 

       pos = iduilay1(FigW,3);
       uicontrol(f,'pos',pos(1,:),'style','frame');
       uicontrol(f,'Pos',pos(2,:),'style','push',...
                   'string','Estimate','callback',...
                   'iduipoin(1);iduinpar(''spa'');iduipoin(2);');
       uicontrol(f,'Pos',pos(3,:),'style','push',...
          'callback','set(gcf,''visible'',''off'')','string','Close');
       uicontrol(f,'Pos',pos(4,:),'style','push','string','Help',...
          'callback','iduihelp(''spa.hlp'',''Help: Spectral Analysis'');');

      % LEVEL 2
      lev2 = pos(1,2)+pos(1,4);
      boxno=1;
      pos = iduilay1(FigW,4,4,lev2,[],3);
      uicontrol(f,'pos',pos(1,:),'style','frame');
      h1=uicontrol(f,'pos',pos(5,:),'style','edit','Horizontalalignment',...
             'left',...
             'backgroundcolor','white','callback','iduispa(''resol'');');
      uicontrol(f,'pos',pos(4,:),'style','text','string',...
              'Frequency resolution parameter (M)','Horizontalalignment',...
              'left');
      h2=uicontrol(f,'pos',pos(3,:),'style','popup',...
             'string','Blackman-Tukey (spa)|Smoothed Fourier Transform (etfe)',...
             'backgroundcolor',get(0,'defaultUIcontrolbackgroundcolor'),...
             'callback','iduispa(''method'');');
      uicontrol(f,'pos',pos(2,:),'style','text','string',...
             'Choice of method','HorizontalAlignment','left');
      usd=get(XIDplotw(16,1),'userdata');
      mspa=deblank(usd(2,:));
      set(h1,'string',mspa);
      set(h2,'value',eval(usd(3,:)));
      poslev=pos(1,2)+pos(1,4)+mEdgeToFrame;
       ScreenPos = get(0,'ScreenSize');
       FigWH=[FigW poslev];
       FigPos=[(ScreenPos(3:4)-FigWH)/2 FigWH];
      set(f,'pos',FigPos);
      set(get(f,'children'),'unit','norm')
      if length(XIDlayout)>32,if XIDlayout(33,3)
       eval('set(f,''pos'',XIDlayout(33,1:4))','')
      end,end
      set(f,'vis','on')
     iduistat('')
   end

elseif strcmp(arg,'resol')
  usd=get(XIDplotw(16,1),'userdata');
  mspa=get(gco,'string');
  flag=0;
  if ~strcmp(mspa,'[]')
      imspa=0;
      eval('imspa=eval(mspa);','flag=1;')
      if imspa<0|floor(imspa)~=imspa,flag=1;end
  end
  if flag,
    set(gco,'string',usd(2,:));
    errordlg('The resolution parameter must be a nonnegative integer.');
    return
  end
  usd=str2mat(usd(1,:),mspa,usd(3,:));
  set(XIDplotw(16,1),'userdata',usd);

elseif strcmp(arg,'method')
  usd=get(XIDplotw(16,1),'userdata');
  usd=str2mat(usd(1,:),usd(2,:),int2str(get(gco,'value')));  
  set(XIDplotw(16,1),'userdata',usd);
end
