
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% private_570_ROUTINE-- Called by STEPIT
%
%
%
% Written by Jason Lott, University of Alabama at Birmingham
% CONTACT:hoffa@uab.edu
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function a = private_570_ROUTINE(b)						%again, really nothing but a script file

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 DLX
global XS
global fortag
global KFLAGENCOUNTER


FSTORE(JX) = FBEST;
tag = 1;

if NTRACE>=1 & tag ==1
   
   disp('PRINTING REMAINING TRACES')
   disp('FBEST= '), disp(FBEST)
   disp('NF= '), disp(NF)
   disp('VALUES OF X(J)= ')
                  
   for J=1:NV
      
      disp(X(J))
      
   end
   
elseif tag == 1
   
   NGATE = 1;
   
   for J=1:NV
      
      if MASK(J)~=0
         
         DX(J) = DX(J)/STCUT;
         
      else
         
         if ABSDX<RZERO
            
            ABSDX = -ABSDX;
            
         end
         
         if ABSDX>DELMIN(J)
            
            NGATE = 0;
            
         end
         
         DX(J) = DX(J)/STCUT;
         
      end
      
   end
                  
   if NGATE == 1
      
      KFLAG = 1
      private_KFLAG_EXIT(KFLAG);
                     
   elseif NFLAT<=0
      
      if NTRACE>=1
         
         disp('STEP SIZES REDUCED TO: ')
         
         for J=1:NV
            
            disp(DX(J))
            
         end
         
      end
      
      if NF>NFMAX
         
         KFLAG = -2
         private_KFLAG_EXIT(KFLAG);
                        
      else
         
         NCIRC = 0;			%%CALL TO 640 ROUTINE!!!
         NZIP = 0;
         NACK = 0;
         grandtag = 1;
         fortag = 0;
         
      end
      
   else
      
      JFLMIN = 5;
      
      for J=1:NV
         
         if MASK(J) == 0 & JFLAT(J)<JFLMIN
            
            JFLMIN = JFLAT(J);
            
         end
         
      end
      
      if JFLMIN>=1
         
         KFLAG=2
         private_KFLAG_EXIT(KFLAG);
                        
      else
         
         if NTRACE>=1
            
            disp('STEP SIZES REDUCED TO:')
            
            for J=1:NV
               
               disp(DX(J))
               
            end
            
         end
         
         if NF>NFMAX
            
            KFLAG = -2;
            disp('ENTERING KFLAG EXIT from 570 4')
            pause
            private_KFLAG_EXIT(KFLAG);
                           
         else
            
            NCIRC = 0;			%%CALL TO 640 ROUTINE!!
            NZIP = 0;
            NACK = 0;
            grandtag = 0;
            fortag = 0;
            
         end
            
      end
      
   end
   
end
