         END IF 
         IF(NOON) THEN
 -       DET=SQRT((acos(svbcos)*180./pi)**2-BETADG**2)
-+       DET=SQRT(MAX(0.0,(acos(svbcos)*180./pi)**2-BETADG**2))
++       DET=SQRT(MAX(0.0D0,(acos(svbcos)*180./pi)**2-BETADG**2))
  C Jan 16, 2015- start (NO IIR X-REVERSAL!)
  c        IF(IBLK(IPRN).EQ.4.OR.IBLK(IPRN).EQ.5) THEN
  c         IF(DABS(YANGLE).LT.90.d0) DET=-DET

 C Jan 10, 2017  end
       IF ( (NIGHT .OR. NOON)) THEN
-       DET=SQRT((180.d0-acos(svbcos)/DTR)**2-BETADG**2)
+       DET=SQRT(MAX(0.0,(180.d0-acos(svbcos)/DTR)**2-BETADG**2))
        PHI = PI/2.d0
 C Check if already after a midnight or noon
        IF(NIGHT) THEN

      &           .OR.(IPRN .GT.64.AND.IPRN.LE.100)).AND.NIGHT) THEN
              ECLSTM(IPRN,NECLIPS(IPRN))= ECLSTM(IPRN,NECLIPS(IPRN))-
-     &       SQRT((ANIGHT-180.d0)**2-BETADG**2)/MURATE
+     &       SQRT(MAX(0.0D0,(ANIGHT-180.d0)**2-BETADG**2))/MURATE
              ECLETM(IPRN,NECLIPS(IPRN))= ECLSTM(IPRN,NECLIPS(IPRN))+
-     &       2.d0*SQRT((ANIGHT-180.d0)**2-BETADG**2)/MURATE
+     &       2.d0*SQRT(MAX(0.0D0,(ANIGHT-180.d0)**2-BETADG**2))/MURATE
             END IF
         END IF
         ENDIF
