SUBROUTINE CALSFT(ISTL_,IS2TL_)
  !
  ! CHANGE RECORD
  ! **  SUBROUTINE CALSFT CALCULATES THE TRANSPORT OF SHELL FISH LARVAE
  ! **  AT TIME LEVEL (N+1).
  ! **  CALLED ONLY ON ODD THREE TIME LEVEL STEPS  (PMC - NO, CALLED IN BOTH HDMT & HDMT2T)
  !

  USE GLOBAL
  ! *** DS-INTL BEGIN BLOCK
  IMPLICIT NONE
  INTEGER :: ISTL_,IS2TL_
  INTEGER :: ISDARK,ITIME,K,L,LN,LF,LL,ND
  REAL :: TIME,RTIME,TIMTMP,FANGTMP,UTMP,VTMP,VELEKB,VELNKB,CURANG,ANGDIF,RCDZKMK,CCLBTMP
  REAL :: RABOVE,HABOVE,TMPVAL,WMAXX,DZCIT,TMPVAL1,CDYETMP,RCDZKK,CCUBTMP,CCMBTMP,EEB
  REAL,SAVE,ALLOCATABLE,DIMENSION(:) :: WTFKB
  REAL,SAVE,ALLOCATABLE,DIMENSION(:) :: WTFKC

  IF(  .NOT. ALLOCATED(WTFKB) )THEN
    ALLOCATE(WTFKB(KCM))
    ALLOCATE(WTFKC(KCM))
    ! *** ZERO LOCAL ARRAYS
    WTFKB=0.0
    WTFKC=0.0
  ENDIF
  ! *** DS-INTL END BLOCK
  !
  !PMC      DELT=DT2
  ! *** PMC
  IF( ISTL_ == 2 )THEN
    IF( ISDYNSTP == 0 )THEN
      DELT=DT
    ELSE
      DELT=DTDYN
    END IF
  ELSE
    DELT=DT2
  ENDIF
  ! *** PMC
  !
  ! **  UPDATED TIME SERIES CONCENTRATION BOUNDARY CONDITIONS
  ! **  DETERMINE IF CURRENT TIME STEP IS DURING DAYLIGHT OR DARKNESS
  !
  IF( ISSFLDN >= 1 )THEN
    ISDARK=1
    IF( ISDYNSTP == 0 )THEN
      TIME=(DT*FLOAT(N)+TCON*TBEGIN)/86400.
    ELSE
      TIME=TIMESEC/86400.
    ENDIF
    ITIME=INT(TIME)
    RTIME=FLOAT(ITIME)
    TIMTMP=TIME-RTIME
    IF( TIMTMP >= TSRSF .AND. TIMTMP <= TSSSF) ISDARK=0
  ENDIF
  !
  ! **  DETERMINE IF LOCAL CONDITIONS ARE EBB OR FLOOD
  !
  IF( ISSFLFE >= 1 )THEN
    IF( KC == 1 )THEN
      WTFKB(1)=1.
      WTFKC(1)=0.
    ENDIF
    IF( KC == 2 )THEN
      WTFKB(1)=1.0
      WTFKC(1)=0.0
      WTFKB(2)=0.0
      WTFKC(2)=1.0
    ENDIF
    IF( KC == 3 )THEN
      DO K=1,KC
        WTFKB(K)=FLOAT(KC-K)/FLOAT(KS)
        WTFKC(K)=1.0-WTFKB(K)
      ENDDO
    ENDIF
  !
  ! **  SET SWITCHES TO EBB
  !
    DO K=1,KC
      DO L=2,LA
        UUU(L,K)=0.
        VVV(L,K)=1.
      ENDDO
    ENDDO
  !
  ! **  RESET SWITCHES FOR FLOOD
  !
    DO K=1,KC
      DO L=2,LA
        LN=LNC(L)
        FANGTMP=ACCWFLD(L,1)*WTFKB(K)+ACCWFLD(L,2)*WTFKC(K)
        UTMP=0.5*STCUV(L)*(UWQ(LEC(L),K)+UWQ(L,K))
        VTMP=0.5*STCUV(L)*(VWQ(LN ,K)+VWQ(L,K))
        VELEKB=CUE(L)*UTMP+CVE(L)*VTMP+1.E-12
        VELNKB=CUN(L)*UTMP+CVN(L)*VTMP
        CURANG=ATAN2(VELNKB,VELEKB)
        ANGDIF=ABS(FANGTMP-CURANG)
        IF( ANGDIF < 1.5708 )THEN
          UUU(L,K)=1.
          VVV(L,K)=0.
        ENDIF
      ENDDO
    ENDDO
  ENDIF
  !
  ! **  SET UP ADVECTION FIELD
  ! **  SET ATTACHED TO BOTTOM AND NO ADVECTIVE TRANSPORT IN BOTTOM
  ! **  LAYER DURING EBB IF APPROPRIATE
  !
  IF( ISSFLFE >= 1 )THEN
    IF( SFNTBET < 1. )THEN
      DO L=2,LA
        K=KSZ(L)
        UHDYWQ(L,K)=UUU(L,K)*UHDYWQ(L,K)+SFNTBET*VVV(L,K)*UHDYWQ(L,K)
        VHDXWQ(L,K)=UUU(L,K)*UHDYWQ(L,K)+SFNTBET*VVV(L,K)*VHDXWQ(L,K)
        UWQ(L,K)=UUU(L,K)*UWQ(L,K)+SFNTBET*VVV(L,K)*UWQ(L,K)
        VWQ(L,K)=UUU(L,K)*VWQ(L,K)+SFNTBET*VVV(L,K)*VWQ(L,K)
      ENDDO
    ENDIF
  ENDIF

  ! *** COMPUTE SHELLFISH LARVAE ADVECTION
  CALL CALTRAN (ISTL_,IS2TL_,4,4,SFL,SFL2,1)
  !CALL CALTRWQ (4,0,SFL,SFL2)   ! PMC
  !
  ! **  SET UP VERTICAL MIGRATION AND SETTLING BEHAVIOR
  ! **  INITIALIZE VERTICAL VELOCTIY TO TIME DEPENDENT SETTLING VELOCITY
  !
  DO K=1,KS
    DO L=2,LA
      WWQ(L,K)=-WSFLSTT
    ENDDO
  ENDDO
  DO L=2,LA
    WWQ(L,KC)=0.
    WWQ(L,0)=0.
  ENDDO
  IF( ISSFLFE >= 1 .AND. ISSFLDN >= 1 )THEN
  !
  ! **  DAYLIGHT CONDITIONS
  !
    IF( ISDARK == 0 )THEN
      DO K=1,KS
        RABOVE=FLOAT(KC-K)/DZI
        DO L=2,LA
  !
  ! **   DETERMINE DISTANCE TO SURFACE
  !
          HABOVE=RABOVE*HWQ(L)
          IF( UUU(L,K) > 0. )THEN
  !
  ! **    FLOOD CONDITION : SWIM UP TO MIN DIST BELOW SURFACE
  !
            IF( HABOVE > DSFLMNT) WWQ(L,K)=WSFLSMT
          ELSE
  !
  ! **    EBB CONDITION : CONTINUE TO SINK OR SWIM UP TO MAX DIST BL SURF
  !
            IF( HABOVE > DSFLMXT) WWQ(L,K)=WSFLSMT
          ENDIF
        ENDDO
      ENDDO
    ENDIF
  !
  ! **  DARK CONDITIONS
  !
    IF( ISDARK == 1 )THEN
      DO K=1,KS
        DO L=2,LA
  !
  ! **   FLOOD CONDITION : SWIM UP TO  SURFACE
  !
          WWQ(L,K)=VVV(L,K)*WWQ(L,K)+UUU(L,K)*WSFLSMT
        ENDDO
      ENDDO
    ENDIF
  ENDIF
  IF( SFATBTT > 0. )THEN
    DO L=2,LA
      WWQ(L,0)=-WSFLSTT
    ENDDO
  ENDIF
  !
  ! **  CALCULATE NET VERTICAL SWIMING OR SETTLING
  !
  IF( WSFLSMT == 0. ) GOTO 100
  !
  ! **  LIMIT VERTICAL SETTLING AND/OR SWIMMING FOR STABILITY
  !
  DO K=0,KS
    DO L=2,LA
      WWW(L,K)=MIN(WWQ(L,K),0.)
      WWW(L,K)=ABS(WWW(L,K))
      WWQ(L,K)=MAX(WWQ(L,K),0.)
    ENDDO
  ENDDO
  TMPVAL=0.25/(DELT*DZI)
  DO K=1,KS
    DO L=2,LA
      WMAXX=TMPVAL*HWQ(L)
      WWW(L,K)=MIN(WWW(L,K),WMAXX)
      WWQ(L,K)=MIN(WWQ(L,K),WMAXX)
      WWQ(L,K)=WWQ(L,K)-WWW(L,K)
    ENDDO
  ENDDO
  DO K=1,KS
    DO L=2,LA
      FWU(L,K)=MAX(WWQ(L,K),0.)*SFL(L,K) &
          +MIN(WWQ(L,K),0.)*SFL(L,K+1)
    ENDDO
  ENDDO
  IF( SFATBTT > 0. )THEN
    DO L=2,LA
      SFLSBOT(L)=SFLSBOT(L)-DELT*FWU(L,0)
    ENDDO
  ENDIF
  DO K=1,KC
    DO L=2,LA
      SFL(L,K)=SFL(L,K) + DELT*(FWU(L,K-1)-FWU(L,K))*DZIC(L,K)/HWQ(L)
    ENDDO
  ENDDO
  GOTO 200
    100 CONTINUE
  !
  ! **  FULLY IMPLICIT SETTLING IF SWIMMING IS ZERO EVERYWHERE
  ! **  FULLY IMPLICIT SETTLING IN SURFACE LAYER
  !
  TMPVAL=DELT*WSFLSTT
  DZCIT=TMPVAL*DZIC(L,KC)
  DO L=2,LA
    TMPVAL1=DZCIT/HWQ(L)
    SFL(L,KC)=SFL(L,KC)/(1.+TMPVAL1)
  ENDDO
  !
  ! **  FULLY IMPLICIT SETTLING IN REMAINING LAYERS
  !
  IF( KC > 1 )THEN
    DO K=KS,1,-1
      IF( K < KSZ(L) )CYCLE
      DZCIT=TMPVAL*DZIC(L,K)
      DO L=2,LA
        TMPVAL1=DZCIT/HWQ(L)
        SFL(L,K)=(SFL(L,K)+TMPVAL1*SFL(L,K+1))/(1.+TMPVAL1)
      ENDDO
    ENDDO
  ENDIF
  IF( SFATBTT > 0. )THEN
    DO L=2,LA
      SFLSBOT(L)=SFLSBOT(L)+TMPVAL*SFL(L,KSZ(L))
    ENDDO
  ENDIF
    200 CONTINUE
  DO L=2,LA
    FWU(L,0)=0.
    WWQ(L,0)=0.
    WWW(L,0)=0.
  ENDDO
  !
  ! **  CALCULATE LINEAR DECAY
  !
  IF( RKDSFLT >= 0. )THEN
    CDYETMP=1./(1.+DELT*RKDSFLT)
    DO K=1,KC
      DO L=2,LA
        SFL(L,K)=CDYETMP*SFL(L,K)
      ENDDO
    ENDDO
  ENDIF
  IF( KC == 1 ) GOTO 2000
  !
  ! **  VERTICAL DIFFUSION CALCULATION
  !
  DO L=2,LA
    HWQI(L)=1./HWQ(L)
  ENDDO
  DO ND=1,NDM
    LF=2+(ND-1)*LDM
    LL=MIN(LF+LDM-1,LA)
    DO L=LF,LL
      RCDZKK=-DELT*CDZKK(L,KSZ(L))
      CCUBTMP=RCDZKK*HWQI(L)*AB(L,KSZ(L))
      CCMBTMP=1.-CCUBTMP
      EEB=1./CCMBTMP
      CU1(L,KSZ(L))=CCUBTMP*EEB
      SFL(L,KSZ(L))=SFL(L,KSZ(L))*EEB
    ENDDO
  ENDDO
  DO ND=1,NDM
    LF=2+(ND-1)*LDM
    LL=MIN(LF+LDM-1,LA)
    DO K=2,KS
      DO L=LF,LL
        IF( K < KSZ(L)+1 )CYCLE
        RCDZKMK=-DELT*CDZKMK(L,K)
        RCDZKK=-DELT*CDZKK(L,K)
        CCLBTMP=RCDZKMK*HWQI(L)*AB(L,K-1)
        CCUBTMP=RCDZKK*HWQI(L)*AB(L,K)
        CCMBTMP=1.-CCLBTMP-CCUBTMP
        EEB=1./(CCMBTMP-CCLBTMP*CU1(L,K-1))
        CU1(L,K)=CCUBTMP*EEB
        SFL(L,K)=(SFL(L,K)-CCLBTMP*SFL(L,K-1))*EEB
      ENDDO
    ENDDO
  ENDDO
  K=KC
  DO ND=1,NDM
    LF=2+(ND-1)*LDM
    LL=MIN(LF+LDM-1,LA)
    DO L=LF,LL
      RCDZKMK=-DELT*CDZKMK(L,K)
      CCLBTMP=RCDZKMK*HWQI(L)*AB(L,K-1)
      CCMBTMP=1.-CCLBTMP
      EEB=1./(CCMBTMP-CCLBTMP*CU1(L,K-1))
      SFL(L,K)=(SFL(L,K)-CCLBTMP*SFL(L,K-1))*EEB
    ENDDO
  ENDDO
  DO ND=1,NDM
    LF=2+(ND-1)*LDM
    LL=MIN(LF+LDM-1,LA)
    DO K=KC-1,1,-1
      DO L=LF,LL
        SFL(L,K)=SFL(L,K)-CU1(L,K)*SFL(L,K+1)
      ENDDO
    ENDDO
  ENDDO
  !
  ! **  UPDATE SHELL FISH LARVAE CONCENTRATIONS
  !
    2000 CONTINUE
  DO K=1,KC
    DO L=2,LA
      SFL2(L,K)=SFL(L,K)
    ENDDO
  ENDDO
  RETURN

END

