      SUBROUTINE SHADEK(DIZ,PERSUN,PERSND,INDS,K,ISATD)
C
C           'SHADEK' COMPUTES SHADOWING OF ELEMENTS AND SWITCHES INDICES
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      COMMON/IPOOL1/ IGRAV,IDAMP,IK,K1,ITIM,IAB,IAPS,IBB,IBPS,NK(10),
     .               LK(10),LLK(10)
C
      COMMON/RPOOL1/ RHOK(10),TIME,SA(3,3),FM1(3,3),ZLK(10),OMEG(3),
     .               ZLKP(10),ZLKDP(10),CMAT(3,3),GBAR(3,3),YBCM(3),
     .               ZBZK(3,10),FCM(3,3),DTO,PHID,PHI
C
      COMMON/RPOOL6/ FM(3,3),CIY(3,3),CIZ(3,3),SAT(3,3),SZ1,SZ2,SZ3
C
      COMMON/SATLSH/ TAUK(10),OCULTK(10),RADSH
C
      DIMENSION DIZ(3),OMK(3),ISATD(10)
C
       INDS=0
      TEST=DIZ(1)
      IF(TEST.LT.0.0D0) GO TO 6
      DTRAN=DSQRT(DIZ(2)**2+DIZ(3)**2)
      IF(DTRAN.LE.0.001D0) GO TO 5
      SHADL=RADSH*DIZ(1)/DTRAN
      PERSUN=1.0D0-SHADL/ZLK(K)
      IF(PERSUN.GT.0.0D0) GO TO 10
    5 CONTINUE
      PERSUN=0.0D0
      GO TO 10
    6 CONTINUE
      PERSUN=1.0D0
   10 CONTINUE
      IF(PERSUN.EQ.1.0D0.OR.PERSUN.EQ.0.0D0) GO TO 30
C
      DO 11 I=1,3
      OMK(I)=FCM(1,I)*OMEG(1)+FCM(2,I)*OMEG(2)+FCM(3,I)*OMEG(3)
      IF(IDAMP.EQ.0.OR.K.GT.K1) GO TO 11
      OMK(I)=OMK(I)+FM(2,I)*PHID
   11 CONTINUE
      DIKDT=OMK(3)*DIZ(2)-OMK(2)*DIZ(3)
C
      INDS=ISATD (K)
      SHADLD=RADSH*DIKDT/DTRAN**3
      PERSND=-SHADLD/ZLK(K)
      MIND=0
      TEST=PERSND*TAUK(K)
      TEST=DABS(TEST)
      IF(TEST.GT.OCULTK(K)) MIND=1
      IF(PERSND.GT.0.0D0) GO TO 20
C     ENTERING SHADOW
      IF(ISATD(K).NE.1.AND.MIND.EQ.1) INDS=1
      GO TO 40
   20 CONTINUE
      IF(ISATD(K).NE.2.AND.MIND.EQ.1) INDS=2
      GO TO 40
   30 CONTINUE
      PERSND=0.0D0
   40 CONTINUE
      RETURN
      END
