function iduicra(arg)
%IDUICRA Handles the correlation analysis dialog.

%   L. Ljung 9-27-94
%   Copyright 1986-2000 The MathWorks, Inc.
%   $Revision: 1.9 $ $Date: 2000/08/24 12:53:26 $

%global XIDplotw XIDlayout
Xsum = findobj(get(0,'children'),'flat','tag','sitb16');
XID = get(Xsum,'Userdata');

if strcmp(arg,'open')
   figname=idlaytab('figname',32);
   if ~figflag(figname,0)
      iduistat('Opening the correlation analysis dialog box ...')
      layout
      FigW = iduilay2(3);
      
      f=figure('vis','off',...
         'NumberTitle','off','Name',figname,'HandleVisibility','callback',...
         'Color',get(0,'DefaultUIControlBackgroundColor'),...
         'tag','sitb32','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);iduistat(''Compiling ...'');',...
            'iduinpar(''cra'');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(''cra.hlp'',''Help: Correlation Analysis'');');
      
      % LEVEL 2
      
      lev2 =pos(1,2)+pos(1,4);
      pos = iduilay1(FigW,2,2,lev2,[],3);
      
      uicontrol(f,'pos',pos(1,:),'style','frame');
      h1=uicontrol(f,'pos',pos(3,:),'style','edit','Horizontalalignment',...
         'left',...
         'backgroundcolor','white','callback',...
         'iduipoin(1);iduicra(''filt_ord'');iduipoin(2);');
      uicontrol(f,'pos',[pos(2,:)],'style','text','string',...
         'Order of prewhitening filter:','HorizontalAlignment','left');
      usd=get(XID.plotw(16,1),'userdata');
      if isempty(usd)
         str = 'Default';
      else
         str = deblank(usd(1,:));
         end
      set(h1,'string',deblank(usd(1,:)));
      
      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(XID.layout)>39,if XID.layout(40,3)
            eval('set(f,''pos'',XID.layout(40,1:4))','')
         end,end
      set(f,'vis','on')
      iduistat('')
   end
elseif strcmp(arg,'filt_ord')
   usd=get(XID.plotw(16,1),'userdata');
   fo=get(iduigco,'string');
   if isempty(fo),fo='Default';end
   %if ~ischar(fo)&isempty(eval(fo))
    %  fo='Default';
   %end
   flag=0;
   if ~strcmp(lower(fo(1)),'d')
      ifo=0;
	  try
      ifo=eval(fo);
  catch
	  flag=1;
  end
      if ifo<0|floor(ifo)~=ifo|ifo>100,flag=1;end
   end
   if flag,
      set(iduigco,'string',usd(1,:));
      errordlg('The filter order must be an integer between 0 and 100.'...
	       ,'Error Dialog','modal');
      return
   end
   usd=str2mat(fo,usd(2,:),usd(3,:));
   set(XID.plotw(16,1),'userdata',usd);
end

