      SUBROUTINE BACK UP(HS)                                            BACK001 
	implicit real*8 (a-h,o-z)
	character*8 id
      COMMON /RK/ N,STEP,MODE,E1MAX,E1MIN,E2MAX,E2MIN,FACT,RSTART       BACK002 
      COMMON /TRAC/ GROUND,PERIGE,THERE,MINDIS,NEWRAY,SMT               BACK003 
      COMMON R(20),T,STP,DRDT(20) /WW/ ID(10),W0,W(400)                 BACK004 
      EQUIVALENCE (EARTHR,W(2)),(INTYP,W(41)),(STEP1,W(44))             BACK005 
      REAL*8 INTYP                                                      BACK006 
      LOGICAL GROUND,PERIGE,THERE,MINDIS,NEWRAY,HOME                    BACK007 
C********* DIAGNOSTIC PRINTOUT                                          BACK008 
C        CALL PRINTR (8HBACK UP0,0.d0)                                  BACK009 
C********* GOING AWAY FROM THE HEIGHT HS                                BACK010 
      HOME=DRDT(1)*(R(1)-EARTHR-HS).GE.0.d0                             BACK011 
      IF (HS.GT.0.d0.AND..NOT.HOME.OR.HS.EQ.0.d0.AND.DRDT(1).GT.0.d0)
     a GO TO 30                                                         BACK012 
C********* FIND NEAREST INTERSECTION OF RAY WITH THE HEIGHT HS          BACK013 
      DO 10 I=1,10                                                      BACK014 
      STEP=-(R(1)-EARTHR-HS)/DRDT(1)                                    BACK015 
      STEP=dSIGN(dMIN1(dABS(STP),dABS(STEP)),STEP)                      BACK016 
      IF(dABS(R(1)-EARTHR-HS).LT..5d-4.AND.dABS(STEP).LT.1.d0) GO TO 60 BACK017 
C********* DIAGNOSTIC PRINTOUT                                          BACK018 
C        CALL PRINTR(8HBACK UP1,0.d0)                                   BACK019 
      MODE=1                                                            BACK020 
      RSTART=1.d0                                                       BACK021 
      CALL RKAM                                                         BACK022 
   10 RSTART=1.d0                                                       BACK023 
C                                                                       BACK024 
C********* FIND NEAREST CLOSEST APPROACH OF RAY TO THE HEIGHT HS        BACK025 
      ENTRY GRAZE                                                       BACK026 
      THERE=.FALSE.                                                     BACK027 
C********* DIAGNOSTIC PRINTOUT                                          BACK028 
C        CALL PRINTR (8HGRAZE 0 ,0.d0)                                  BACK029 
      IF (SMT.GT.dABS(R(1)-EARTHR-HS)) GO TO 30                         BACK030 
      DO 20 I=1,10                                                      BACK031 
      STEP=-R(4)/DRDT(4)                                                BACK032 
      STEP=dSIGN(dMIN1(dABS(STP),dABS(STEP)),STEP)                      BACK033 
      IF (dABS(R(4)).LE.1.d-6.AND.dABS(STEP).LT.1.d0) GO TO 60          BACK034 
C********* DIAGNOSTIC PRINTOUT                                          BACK035 
C        CALL PRINTR (8HGRAZE 1 ,0.d0)                                  BACK036 
      MODE=1                                                            BACK037 
      RSTART=1.d0                                                       BACK038 
      CALL RKAM                                                         BACK039 
      RSTART=1.d0                                                       BACK040 
      IF (DRDT(4)*(R(1)-EARTHR-HS).LT.0.d0) GO TO 30                    BACK041 
      IF(R(5).EQ.0.d0.AND.R(6).EQ.0.d0) GO TO 60                        BACK042 
   20 CONTINUE                                                          BACK043 
C********* IF A CLOSEST APPROACH COULD NOT BE FOUND IN 10 STEPS, IT     BACK044 
C********* PROBABLY MEANS THAT THE RAY INTERSECTS THE HEIGHT HS         BACK045 
   30 CONTINUE                                                          BACK046 
C********* DIAGNOSTIC PRINTOUT                                          BACK047 
C        CALL PRINTR (8HBACK UP2,0.d0)                                  BACK048 
      MODE=1                                                            BACK049 
C********* ESTIMATE DISTANCE TO NEAREST INTERSECTION OF RAY WITH HEIGHT BACK050 
C********* HS BEHIND THE PRESENT RAY POINT                              BACK051 
      STEP=(-R(4)-dSQRT(R(4)**2-2.d0*(R(1)-EARTHR-HS)*DRDT(4)))/DRDT(4) BACK052 
      RSTART=1.d0                                                       BACK053 
      CALL RKAM                                                         BACK054 
      RSTART=1.d0                                                       BACK055 
C********* FIND NEAREST INTERSECTION OF RAY WITH HEIGHT HS              BACK056 
      DO 40 I=1,10                                                      BACK057 
      STEP=-(R(1)-EARTHR-HS)/DRDT(1)                                    BACK058 
      STEP=dSIGN(dMIN1(dABS(STP),dABS(STEP)),STEP)                      BACK059 
      IF(dABS(R(1)-EARTHR-HS).LT..5d-4.AND.dABS(STEP).LT.1.d0) GO TO 60 BACK060 
C********* DIAGNOSTIC PRINTOUT                                          BACK061 
C        CALL PRINTR (8HBACK UP3,0.d0)                                   BACK062 
      MODE=1                                                            BACK063 
      RSTART=1.d0                                                       BACK064 
      CALL RKAM                                                         BACK065 
   40 RSTART=1.d0                                                       BACK066 
   50 THERE=.TRUE.                                                      BACK067 
C********* RESET STANDARD MODE AND INTEGRATION TYPE                     BACK068 
   60 MODE=INTYP                                                        BACK069 
      STEP=STEP1                                                        BACK070 
      RETURN                                                            BACK071 
         END                                                            BACK072-
