C=====================================================================
      SUBROUTINE RISESET(ZLIM,RA,DEC,LONG,LAT,GAST0,UTDOWN,UTUP,EVERUP)
C Calculate UT set and rise time past some zenith angle ZLIM
C ZLIM    Zenith angle limit (deg)
C RA      Right ascension (hr)
C DEC     Declination (deg)
C LONG    West longitude (deg)
C LAT     North latitude (deg)
C GAST0   Greenwich apparent sidereal time at UT = 0 (hr)
C UTDOWN  Setting (UT hrs)
C UTUP    Rising (UT hrs)
C EVERUP  1 = circumpolar,  0 = sometimes up,  -1 = never up

      IMPLICIT UNDEFINED (A-Z)

      REAL*8 ZLIM,RA,DEC,GAST0,COSZL,COSD,SIND,COSL,SINL,HALIM
      REAL*8 LONG,LAT,COSHAL
      REAL*8 DEGRAD,RADHRS,PI
      REAL*8 UTUP, UTDOWN, STUP, STDOWN
      INTEGER*4 EVERUP, INC, OUTC

      PARAMETER (PI=3.14159265358979D0)
      PARAMETER (DEGRAD=PI/180.D0)            ! Radians per degree
      PARAMETER (RADHRS=1.D0/(DEGRAD*15.D0))  ! Hrs UT per radian
      PARAMETER (INC=5)                       ! Console input
      PARAMETER (OUTC=6)                      ! Console output

      COSZL = COS(ZLIM*DEGRAD)
      COSD  = COS(DEC*DEGRAD)
      SIND  = SIN(DEC*DEGRAD)
      COSL  = COS(LAT*DEGRAD)
      SINL  = SIN(LAT*DEGRAD)

      COSHAL = (COSZL - SIND*SINL)/(COSD*COSL)
      IF (COSHAL.GE.1.0) THEN
          HALIM = -0.01                          ! Never visible
          EVERUP = -1
      ELSE IF (COSHAL.LE.-1.0) THEN
          HALIM = 12.                            ! Circumpolar
          EVERUP = 1
      ELSE
          HALIM = ACOS(COSHAL) * RADHRS
      END IF

D     WRITE(OUTC,'(A,F10.4)') ' Hour angle limit: ',HALIM

      STDOWN = RA + ABS(HALIM)                    ! Sid. time of setting
      STUP   = RA - ABS(HALIM) + 24.              ! Sid. time of rising
      UTDOWN = STDOWN - GAST0  + LONG/15.         ! UT time of setting
      UTUP   = STUP   - GAST0  + LONG/15.         ! UT time of rising
      IF(UTDOWN.LT.0.) THEN
          UTDOWN = UTDOWN + 24.
          UTUP   = UTUP   + 24.
      ELSE IF(UTDOWN.GE.24.) THEN
          UTDOWN = UTDOWN - 24.
          UTUP   = UTUP   - 24.
      END IF
D     WRITE(OUTC,'(A,F10.4,1X,F10.4)') 
D    1    ' Set, rise (UT): ',UTDOWN, UTUP

      RETURN
      END

