      SUBROUTINE CTEM_INIT(NLU,NEWFRAC,PREFRAC,C_CLIM_TIME,
     1                     MONTH,IYEAR,IDAY,
     2                     LNDCVRYR1,LNDCVRYR2,LNDCVRMOD,LNDCVR_OFFSET,
     3                     LCTEM,ICC,NTLD,NLON,NLAT,IJPAK,GG)
C
C     * FEB 29, 2016 - M.LAZARE. NEW ROUTINE BASED ON FIRST PART OF CTEM_INIT.DK
C     *                          TO GET CTEM LAND FRACTIONS FOR PRESENT AND 
C     *                          NEXT MONTH.
C     *                          AS WELL, WE CALCULATE CTEM TIME-COUNTING VARIABLES
C     *                          AND PLACE THEM IN A COMMON BLOCK PASSED
C     *                          TO ROUTINE INTCTEMF.
C
      IMPLICIT NONE
C
      integer NLU  ! I/O UNIT NUMBER FOR FILE THAT CONTAINS LAND COVER + MAY BE OTHER VARIABLES
C
C     * OUTPUT FIELDS:
C
      REAL NEWFRAC(IJPAK,NTLD,ICC), PREFRAC(IJPAK,NTLD,ICC)
      REAL C_CLIM_TIME(3,2)
C
C     * REST.
C
      INTEGER LCTEM(ICC)

      INTEGER*4 MYNODE
      COMMON /MPINFO/ MYNODE
C
C     * I/O WORK ARRAY.
C
      REAL GG(*)
C
      INTEGER MID_MONTH_DAYS(12)
C
      INTEGER IYEAR          ! Compressed time year    (... -2, -1, 0, 1, 2 ....)
      INTEGER IDAY           ! Compressed time day     (1, 2, 3 ...   364, 365)
      INTEGER MONTH          ! Extended time month     (1, 2, 3 ...  12)
C
      INTEGER LNDCVRYR1,LNDCVRYR2,LNDCVRMOD,LNDCVR_OFFSET
      INTEGER MONTHL1,TMESTMP1,TMESTMP2,nc4to8
      INTEGER IJPAK,NTLD,K,M,NLON,NLAT,ICC
C
      DATA MID_MONTH_DAYS /15,46,74,105,135,166,196,227,258,288,319,
     +349/
C-----------------------------------------------------------------------------
      IF(LNDCVRMOD.EQ.12345)THEN
         LNDCVRYR2 = IYEAR + LNDCVR_OFFSET ! YEAR FOR WHICH WE WANT TO GET THE LAND COVER
C
         MONTHL1 = MONTH - 1
         IF (MONTHL1.NE.0) THEN
           TMESTMP1 = LNDCVRYR2*100 + MONTHL1
           C_CLIM_TIME(1,1)=REAL(LNDCVRYR2) 
           C_CLIM_TIME(2,1)=REAL(MID_MONTH_DAYS(MONTHL1))
           C_CLIM_TIME(3,1)=0.0
         ELSE IF( MONTHL1.EQ.0) THEN
           TMESTMP1 = (LNDCVRYR2-1)*100 + 12 ! DECEMBER OF LAST YEAR
           C_CLIM_TIME(1,1)=REAL(LNDCVRYR2-1) 
           C_CLIM_TIME(2,1)=REAL(MID_MONTH_DAYS(12))
           C_CLIM_TIME(3,1)=0.0
         ENDIF
         TMESTMP2 = LNDCVRYR2*100 + MONTH 
         C_CLIM_TIME(1,2)=REAL(LNDCVRYR2)
         C_CLIM_TIME(2,2)=REAL(MID_MONTH_DAYS(MONTH))
         C_CLIM_TIME(3,2)=0.0
      ELSE
C
C        *  GET LAND COVER FOR THE PARTICULAR YEAR, LNDCVRMOD. SINCE LAND
C        *  COVER DATA ARE AT MONTHLY RESOLUTION WE GET THE VALUES FOR THE
C        *  1st OF JULY FOR THIS YEAR
C
         LNDCVRYR2 = LNDCVRMOD 
C
C        *  ALSO BOTH TIME STAMPS ARE SAME BECAUSE WHEN RUNNING CTEM FOR A
C        *  GIVEN YEAR OVER AND OVER AGAIN WE DON'T WANT ANY LAND USE CHANGE
C        *  TO BE HAPPENING
C
         TMESTMP1 = LNDCVRYR2*100 + 7   ! 7 FOR JULY
         TMESTMP2 = LNDCVRYR2*100 + 7   
C
C        * HOWEVER, FOR INTERPOLATION USING WARREN'S SUBROUTINE I DO NEED 
C        * C_CLIM_TIME SO LETS SET THEM AS THE START AND END OF THE GIVEN
C        * YEAR
C          
         C_CLIM_TIME(1,1)=REAL(LNDCVRYR2)
         C_CLIM_TIME(2,1)=1.0
         C_CLIM_TIME(3,1)=0.0
C
         C_CLIM_TIME(1,2)=REAL(LNDCVRYR2+1)
         C_CLIM_TIME(2,2)=1.0
         C_CLIM_TIME(3,2)=0.0

      ENDIF
C
C     * IF ANY TIME STAMP IS GREATER THAN 210012 THAN SET IT TO
C     * 210012 SO THAT AFTER 1st DECEMBER, 2100 THE LAND COVER
C     * DOESN'T CHANGE.
C
      IF(TMESTMP1.GT.210012)THEN
        TMESTMP1 = 210012
      ENDIF
      IF(TMESTMP2.GT.210012)THEN
        TMESTMP2 = 210012
      ENDIF
C
C     * IF ANY TIME STAMP IS LESS THAN 185001 THEN SET IT TO
C     * 185001 SO THAT BEFORE 1st JANUARY, 1850 THE LAND COVER
C     * USED IS THAT OF 1850
C
      IF(TMESTMP1.LT.185001)THEN
        TMESTMP1 = 185001
      ENDIF
      IF(TMESTMP2.LT.185001)THEN
        TMESTMP2 = 185001
      ENDIF
C
C     * EXTRACT LAND COVER DATA FOR THIS AND THE NEXT MONTH 
C
      REWIND NLU
      DO K = 1, ICC
      DO M = 1, NTLD
        CALL GETGGBX(PREFRAC(1,M,K),NC4TO8("FRAC"),NLU,NLON,NLAT,
     1               TMESTMP1,LCTEM(K),GG)
      ENDDO
      ENDDO
C
      IF(LNDCVRMOD.EQ.12345.AND.TMESTMP1.NE.TMESTMP2)THEN
        DO K = 1, ICC
        DO M = 1, NTLD
          CALL GETGGBX(NEWFRAC(1,M,K),NC4TO8("FRAC"),NLU,NLON,NLAT,
     1                 TMESTMP2,LCTEM(K),GG)
        ENDDO
        ENDDO
      ELSE
        NEWFRAC(:,:,:)=PREFRAC(:,:,:)
      ENDIF

      RETURN
      END
