
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% private_290_ROUTINE -- Another routine called by STEPIT
%
%
%
%  Ported to Matlab Jason Lott, University of Alabama at Birmingham, 2001
%  CONTACT: hoffa@uab.edu
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function a = private_290_ROUTINE(b)							

global X
global XMAX
global XMIN
global DELTX
global DELMIN
global ERR
global FOBJ
global VEC
global DLX
global XS
global FSTORE
global DX
global SALVO
global XOSC
global FOSC
global ARG
global STCUT
global ACK
global FACUP
global RZERO
global XPLUS
global FSAVE
global FBEST
global XSAVE
global ABSDX
global FPREV
global DENOM
global DEL
global DXZ
global DXU
global DFZ
global DFU
global ABSVEC
global SUMV
global CINDER
global COXCOM
global COSIN
global STEPS
global J
global JFLAT
global JFLMIN
global JOCK
global JUMP
global JVARY
global JX
global K
global KERFEL
global KL
global KW
global MASK
global MATRX
global MINSOC
global MAXOSC
global MAXSTP
global NACK
global NACTIV
global NAH
global NCIRC
global NEQUAL
global NF
global NFLAT
global NFMAX
global NFSAV
global NGATE
global NGIANT
global NONZER
global NOREP
global NOSC
global NOUT
global NRETRY
global NSSW
global NSTEPS
global NT
global NTRACE
global NV
global NEXTRA
global NZIP
global tag_380
global tag_390
global wtag
global tag
global continueflag
global T
global Y
global YSIG
global grandtag
global KFLAG
global DX
global XS
global DLX
global fortag
global KFLAGENCOUNTER


SUMV = sqrt(SUMV);
                              
for J=1:NV
   
   XOSC(J,NOSC) = X(J);
   ERR(J,NOSC) = VEC(J)/SUMV;
                                 
end

FOSC(NOSC) = FBEST;

if NOSC<2
   
   %disp('ENTERING 380 from 290 1')
  % pause
   private_380_ROUTINE(1);
   
else

   for J=1:NV
      
      COXCOM = COXCOM+ERR(J,NOSC)*ERR(J,NOSC-1);
      
   end
   
   NAH = NOSC - MINSOC;
   
   if KL>NAH
      
      %disp('ENTERING 380 from 290 2')
      %pause
      private_380_ROUTINE(1);
      
   else
     
      tag = 1;
      
      for K=KL:NAH
         
         if tag == 1
            
            NRETRY = NAH-K;
            COSIN = RZERO;
                              
            for J=1:NV
               
               COSIN = COSIN+ERR(J,NOSC)*ERR(J,K);
               
            end
            
            if (K>=(NOSC-1)) | (COSIN>RZERO & COSIN>COXCOM)
               
               KL = K+1;
               NT = NOSC-K;
                                       
               if NTRACE>=1
                  
                  disp('******GIGANTIC STEP WITH PERIOD '),disp(NT),disp(' BEING ATTEMPTED.')
                  disp('COXCOM= '), disp(COXCOM)
                  disp('COSIN= '), disp(COSIN)
                  
               end
               
               for J=1:NV
                  
                  SALVO(J) = DLX(J);
                  DLX(J) = X(J) - XOSX(J,K);
               end
               
               FPREV = FOSC(K);
               tag = 0;
               %disp('ENTERING 390 from 290 1')
               %pause
               private_390_ROUTINE(1);
               
            end
            
         end
          
      end
      
      if tag == 1
         
         %disp('ENTERING 380 from 290 3')
         %pause
         private_380_ROUTINE(1);
         
      end
      
   end
   
end

      
 
          



