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

%	L. Ljung 9-27-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%       $Revision: 1.9 $  $Date: 1995/05/10 21:36:59 $

global XIDplotw XIDlayout

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,'NextPlot','New',...
             '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(XIDplotw(16,1),'userdata');
      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(XIDlayout)>39,if XIDlayout(40,3)
       eval('set(f,''pos'',XIDlayout(40,1:4))','')
      end,end
      set(f,'vis','on')
     iduistat('')
   end
elseif strcmp(arg,'filt_ord')
  usd=get(XIDplotw(16,1),'userdata');
  fo=get(gco,'string');
  flag=0;
  if ~strcmp(fo,'[]')
      ifo=0;
      eval('ifo=eval(fo);','flag=1;')
      if ifo<0|floor(ifo)~=ifo|ifo>100,flag=1;end
  end
  if flag,
    set(gco,'string',usd(1,:));
   errordlg('The filter order must be an integer between 1 and 100.');
    return
  end
  usd=str2mat(get(gco,'string'),usd(2,:),usd(3,:));
  set(XIDplotw(16,1),'userdata',usd);
end
