
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%           a = private_KFLAG_EXIT(b) --AN EXIT METHOD CALLED BY STEPIT 
%         
%           routine that determines exit of program
%
%				WRITTEN BY JASON LOTT, University of Alabama at Birmingham 2001
%           CONTACT: hoffa@uab.edu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function a = private_KFLAG_EXIT(b)						%Possible values of b: b=1, b=2, b=-2, b=-3

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


if b == 1	& NTRACE>=0
  
   disp('TERMINATED WHEN THE STEP SIZES BECAME AS SMALL AS THE DELMIN(J)')
   
end

if b == 2 & NTRACE>=0
  
   disp('TERMINATED WHEN THE FUNCTION VALUES AT ALL TRIAL POINTS WERE IDENTICAL')
   
end

if b == -2 & NTRACE>=-1
   
   disp('ABNORMAL TERMINATION: MORE THAN NFMAX CALLS TO THE FOBJ SUBROUTINE.')
   
end

if b == -3 & NTRACE>=-1
   
   disp('ABNORMAL TERMINATION: TERMINATED BY OPERATOR VIA SWITCH.')
   
end


if b == 1 | b == 2
   
   if NTRACE<0 
                           
      JVARY = 0;
      private_FUNK(1);
      NF = NF+1;
      
      if FBEST<=FSAVE & FOBJ==FBEST
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '),disp(FOBJ);
            disp('FINAL VALUE OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
                              
         end
         
         if KFLAG<0
            
            disp(KFLAG)
            grandtag =0;
            
         elseif MATRX<70 | MATRX >130
            
            disp('MATRIX-OR STATEMENT IN STEPIT REACHED.')
            
            
         else
            
            % feval(STERR, dummyvariable);
            disp('STERR CALLED');
            
            
         end
         
      else
         
         NOREP = NOREP +2;
         
         if NTRACE>=-1
            
            disp('****WARNING! FOBJ IS NOT A REPRODUCIBLE FUNCTION OF X(J)')
            
         end
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '),disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
                                 
         end
         
         if KFLAG<0
            
            disp(KFLAG)
            
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRIX-OR STATEMENT IN STEPIT REACHED')
            grandtag = 0;
            
         else
            
            %feval(STEER, dummyvariable)
            disp('STERR CALLED');
            
            
         end
         
      end
      
   elseif NTRACE <-1
      
      JVARY = 0;
      private_FUNK(1);
      NF = NF + 1;
      
      if FBEST<=FSAVE & FOBJ==FBEST
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '),disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG <0
                                
            disp(KFLAG)
            
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT IN STEPIT REACHED')
            
            
         else
            
            %feval(STERR, dummy variable)
            disp('STERR CALLED');
            
            
         end
         
      else
                           
         NOREP = NOREP + 2;
         
         if NTRACE >=-1
            
            disp('****WARNING! FOBJ IS NOT A REPRODUCIBLE FUNCTION OF X(J).')
            
         end
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '), disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG<0
            
            disp(KFLAG)
           
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT REACHED IN STEPIT')
            
            
         else
            
            %feval(STERR, dummyvariable)
            disp('STERR CALLED');
            
            
         end
         
      end
      
   else
      
      disp('CURRENT STEP SIZES: ')
      
      for J=1:NV
         
                           
         disp(DX(J))
         
      end
      
      JVARY = 0;
      private_FUNK(1);
      NF = NF+1;
      
      if FBEST<=FSAVE & FOBJ == FBEST
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '), disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG<0
            
            disp(KFLAG)
            
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT IN STEPIT REACHED');
            
            
         else
            
            %feval(STERR, dummyvariable)
            disp('STERR CALLED.')
            
            
         end
         
      else
                              
         NOREP = NOREP + 2;
         
         if NTRACE<=-1
            
            disp('****WARNING! FOBJ IS NOT A REPRODUCIBLE FUNCTION OF X(J).')
            
         end
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '), disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG<0
            
            disp(KFLAG)
           
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT REACHED IN STEPIT')
            
            
         else
            
            %feval(STERR, dummyvariable);
            disp('STERR CALLED.')
            
            
         end
         
      end
      
   end
   
end

if b == -2 | b == -3
   
   if NTRACE <-1
      
      JVARY = 0;
      private_FUNK(1);
      NF = NF + 1;
      
      if FBEST<=FSAVE & FOBJ==FBEST
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '),disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG <0
            
            disp(KFLAG)
            grandtag = 0;
           
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT IN STEPIT REACHED')
            
            
         else
                                 
            %feval(STERR, dummy variable)
            disp('STERR CALLED')
            
            
         end
         
      else
         
         NOREP = NOREP + 2;
         
         if NTRACE >=-1
            
            disp('****WARNING! FOBJ IS NOT A REPRODUCIBLE FUNCTION OF X(J).')
            
            
         end
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '), disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG<0
            
            disp(KFLAG)
            
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT REACHED IN STEPIT')
            
            
         else
            
            %feval(STERR, dummyvariable)
            disp('STERR CALLED.')
            
            
         end
         
      end
      
   else
      
      disp('CURRENT STEP SIZES: ')
      
      for J=1:NV
         
         disp(DX(J))
         
      end
      
      JVARY = 0;
      private_FUNK(1);
      NF = NF+1;
      
      if NBEST<=FSAVE & FOBJ == FBEST
         
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '), disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
         
         if KFLAG<0
            
            disp(KFLAG)
            
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT IN STEPIT REACHED');
            
            
         else
            
            %feval(STERR, dummyvariable)
            disp('STERR CALLED');
            
            
         end
         
      else
         
         NOREP = NOREP + 2;
         
         if NTRACE<=-1
            
            disp('****WARNING! FOBJ IS NOT A REPRODUCIBLE FUNCTION OF X(J).')
         end
                              
         if NTRACE>=0
            
            disp('FUNCTION COMPUTATIONS:')
            disp('FINAL VALUE OF FOBJ= '), disp(FOBJ)
            disp('FINAL VALUES OF X(J)= ')
            
            for J=1:NV
               
               disp(X(J))
               
            end
            
         end
                              
         if KFLAG<0
            
            disp(KFLAG)
            
            
         elseif MATRX<70 | MATRX>130
            
            disp('MATRX-OR STATEMENT REACHED IN STEPIT')
            
            
         else
            
            %feval(STERR, dummyvariable);
            disp('STERR CALLED.')
            
            
         end
         
      end
      
   end
   
end


fortag = 0;
grandtag = 0;
KFLAGENCOUNTER = 1;




   



