      SUBROUTINE INTCTEMF (CURFRAC,TODFRAC,FCANMX,
     1                     NEWFRAC,PREFRAC,SANDARRY,SOILDPTH,NOL2PFTS,
     2                     C_CLIM_TIME,MONTH,IDAY,GMT,LNDCVRYR2,
     3                     IC,IG,ICC,ILG,IL1,IL2)
C
C     * FEB 29, 2016 - M.LAZARE. NEW ROUTINE BASED ON MIDDLE PART OF CTEM_INTERPOL_LAND_COVER.DK
C     *                          TO INTERPOLATE TO GET CURRENT AND NEXT-DAY CTEM VEGETATION
C     *                          FRACTION FIELDS, FROM PREVIOUS AND NEXT MID-MONTH VALUES.
C
      IMPLICIT NONE
C
C     * OUTPUT FIELDS:
C
      REAL CURFRAC(ILG,ICC), TODFRAC(ILG,ICC)
      REAL FCANMX(ILG,IC) 
C
C     * I/O FIELDS:
C
      REAL NEWFRAC(ILG,ICC), PREFRAC(ILG,ICC)
      REAL SANDARRY(ILG,IG)
      REAL SOILDPTH(ILG)
      INTEGER NOL2PFTS(4)
C
      INTEGER ILG,IL,IL1,IL2,I,J,M,K,K1,K2,IC,IG,ICC,IDAY

      INTEGER MONTH             ! Extended time month     (1, 2, 3 ...  12)
      REAL GMT
C
      INTEGER LNDCVRYR2
      REAL C_CLIM_TIME(3,2)
C
C     * LOCAL WORK ARRAYS.
C     * THESE ARE DIMENSIONED ONLY WITH THE SIZE OF THE ACTUAL SIZE OF
C     * THE COMPUTE GRID, TO WORK PROPERLY WITH THE INTERPOLATION
C     * ROUTINE "CMINTR", WHICH WAS DESIGNED TO WORK ON THE "LON*LAT"
C     * GATHERED GRID IN THE OLD CTEM VERSION.
C
      REAL USEFRAC(IL2,2), CTEMP1(IL2)
C
C     * LOCAL DATA.
C
      REAL C_TMP_TIME(3)
C
      INTEGER MONTHP1, TMESTMP1, TMESTMP2
      INTEGER :: nint
C-----------------------------------------------------------------------------
C     * WE HAVE NEW AND PREVIOUS LAND COVER WE FIND THE LAND
C     * COVER FOR THE GIVEN DAY WHICH WE CALL CURFRAC (THIS IS INFACT
C     * LAND COVER AT THE START OF THE DAY). PLUS WE ALSO FIND LAND
C     * COVER FOR THE END OF THIS DAY/BEGINNING OF NEXT DAY FOR USE
C     * THE LAND USE CHANGE SUBROUTINE.
C
      DO K = 1, ICC
        DO IL=IL1,IL2
          USEFRAC(IL,1)=PREFRAC(IL,K)
          USEFRAC(IL,2)=NEWFRAC(IL,K)
        ENDDO
C
C       * TIME STAMPS FOR INTERPOLATION USING WARREN'S SUBROUTINE. THESE
C       * ARE FOR THE CURRENT DAY
C
        C_TMP_TIME(1)=REAL(LNDCVRYR2)
        C_TMP_TIME(2)=REAL(IDAY)
        C_TMP_TIME(3)=GMT
C
        CALL CTMINTR(USEFRAC,C_CLIM_TIME,2,CTEMP1,C_TMP_TIME,1,
     +               IL2,1)
        DO IL=IL1,IL2
          CURFRAC(IL,K)=CTEMP1(IL)
        ENDDO
C
C       * TIME STAMPS FOR THE NEXT DAY
C
        IF(IDAY.LT.365) THEN
          C_TMP_TIME(2)=REAL(IDAY+1)
        ELSE IF(IDAY.EQ.365) THEN
          C_TMP_TIME(1)=REAL(LNDCVRYR2 + 1)
          C_TMP_TIME(2)=1.
        ENDIF
C
        CALL CTMINTR(USEFRAC,C_CLIM_TIME,2,CTEMP1,C_TMP_TIME,1,
     +               IL2,1)
        DO IL=IL1,IL2
          TODFRAC(IL,K)=CTEMP1(IL)
        ENDDO
C
C       * SOME GLACIAL CELLS (TAGGED WITH SAND EQUAL TO -4) MAY HAVE SOME 
C       * VEGETATION ACCORDING TO DAVID PRICE'S LAND COVER DATA SETS. FORCE
C       * THE FRACTIONAL COVERAGE OF ALL PFTs EQUAL TO ZERO OVER GLACIAL CELLS.
C
        DO I = IL1, IL2
          IF( NINT(SANDARRY(I,1)).EQ.-4 .OR. 
     &      SOILDPTH(I).LT.1.E-05 )THEN
             CURFRAC(I,K)=0.0 
             TODFRAC(I,K)=0.0
             NEWFRAC(I,K)=0.0 
             PREFRAC(I,K)=0.0 
          ENDIF 
        ENDDO

      ENDDO 
C
C     * CONVERT FRACTIONAL COVERAGE OF CTEM 9 PFTs TO FRACTIONAL
C     * COVERAGE OF CLASS 4 PFTs
C
      DO J = 1, IC
      DO I = IL1, IL2
        FCANMX(I,J)=0.0
      ENDDO
      ENDDO
C
      K1=0
      DO J = 1, IC
        IF(J.EQ.1) THEN
          K1 = K1 + 1
        ELSE
          K1 = K1 + NOL2PFTS(J-1)
        ENDIF
        K2 = K1 + NOL2PFTS(J) - 1
        DO M = K1, K2
          DO I = IL1, IL2
            FCANMX(I,J)=FCANMX(I,J)+CURFRAC(I,M)
          ENDDO
        ENDDO
      ENDDO

      RETURN
      END
