      SUBROUTINE CTEMG (
     1                  CO2CG1GAT,CO2CG2GAT,CO2CS1GAT,CO2CS2GAT,
     2                  CFLUXCSGAT,CFLUXCGGAT,CO2GAT,FSFGAT,
     3                  LGHTGAT,WETFGAT,WETSGAT,
     4                  SOILCGAT,LITRCGAT,ROOTCGAT,STEMCGAT,
     5                  GLEAFCGAT,BLEAFCGAT,FALLHGAT,POSPHGAT,
     6                  LEAFSGAT,GROWTGAT,LASTRGAT,LASTSGAT,
     7                  THISYLGAT,STEMHGAT,ROOTHGAT,TEMPCGAT,   
     9                  PREFGAT,NEWFGAT,FCOLGAT,AREAGAT,
     A                  SANDGAT,CLAYGAT,SDEPGAT,
     B                  TAGTL,FSNOWGTL,TCANOGTL,TCANSGTL,
     C                  TBARGTL,TBARCGTL,TBARCSGTL,TBARGGTL,
     D                  TBARGSGTL,THLIQCGTL,THLIQGGTL,THICECGTL,
     E                  ANCSGTL,ANCGGTL,RMLCSGTL,RMLCGGTL,
     F                  ILMOS,JLMOS,
     G                  NML,NL,NT,NM,ILG,IG,IC,ICP1,
     H                  ICTEM,ICTEMP1,KOUNT,GMT,
     J                  CO2CG1ROT,CO2CG2ROT,CO2CS1ROT,CO2CS2ROT,
     K                  CFLUXCSROT,CFLUXCGROT,CO2ROW,FSFROT,
     L                  LGHTROW,WETFROW,WETSROW,
     M                  SOILCROT,LITRCROT,ROOTCROT,STEMCROT,
     N                  GLEAFCROT,BLEAFCROT,FALLHROT,POSPHROT,
     O                  LEAFSROT,GROWTROT,LASTRROT,LASTSROT,
     P                  THISYLROT,STEMHROT,ROOTHROT,TEMPCROT,
     R                  PREFROT,NEWFROT,FCOLROT,AREAROW,
     S                  SANDROT,CLAYROT,SDEPROT,
     T                  TARTL,FSNOWRTL,TCANORTL,TCANSRTL,
     U                  TBARRTL,TBARCRTL,TBARCSRTL,TBARGRTL,
     V                  TBARGSRTL,THLIQCRTL,THLIQGRTL,THICECRTL,
     W                  ANCSRTL,ANCGRTL,RMLCSRTL,RMLCGRTL    )
C
C     * Oct 02/2018 - M.Lazare.   - Add FCOL to CTEMG so that exists on timesteps
C     *                             where CTEM is not called, so garbage is not
C     *                             put into FCOLROT from FCOLGAT in the call to
C     *                             CTEMS at those timesteps.
C     * Aug 23/2018 - Vivek Arora - Remove PFHC and PEXF 
C     * Feb 20/16 - M.LAZARE. New version for gcm19+:
C     *                       - Add all necessary extra arrays to
C     *                         support moving CTEM into AGCM.
C     * Jan 15/15 - M.LAZARE. Previous version for gcm18:
C     *                       Remove FIELDSM,WILTSM (replaced by
C     *                       THFC,THLW used for both CTEM and CLASS).
C     * JAN 26/13 - M.LAZARE. ADD PAICROT/PAICGAT AND SLAICROT/SLAICGAT.
C     * NOV 10/11 - M.LAZARE. GATHER ROUTINE FOR CTEM BASED ON CLASSG.
C 
      IMPLICIT NONE
C
C     * INTEGER CONSTANTS.
C
      INTEGER  NML,NL,NT,NM,ILG,IG,IC,ICP1,ICTEM,ICTEMP1,J,K,L,M,KOUNT
      REAL     GMT
C
C     * CTEM VARIABLES.
C
      REAL CO2CG1ROT(NL,NT,ICTEM), CO2CG2ROT(NL,NT,ICTEM),
     1     CO2CS1ROT(NL,NT,ICTEM), CO2CS2ROT(NL,NT,ICTEM)

      REAL CFLUXCSROT(NL,NT),      CFLUXCGROT(NL,NT)
C
C     * INVARIANT CTEM FIELDS.
C
      REAL LGHTROW (NL),  
     1     WETFROW (NL),   WETSROW (NL) 
C
C     * INPUT FIELDS TO MAIN CTEM ROUTINE FROM AVERAGE OVER
C     * COUPLING PERIOD OF PREVIOUS COUPLING CYCLE.
C     * THESE ARE NOT GATHERED AT GMT=0. SINCE THE "ROT"
C     * FIELDS DON'T EXIST AT THIS POINT UNTIL THEY ARE INITIALIZED.
C
      REAL TBARRTL  (NL,NT,IG),    TBARCRTL (NL,NT,IG),
     1     TBARCSRTL(NL,NT,IG),    TBARGRTL (NL,NT,IG),
     2     TBARGSRTL(NL,NT,IG),    THLIQCRTL(NL,NT,IG),
     3     THLIQGRTL(NL,NT,IG),    THICECRTL(NL,NT,IG)
C
      REAL ANCSRTL  (NL,NT,ICTEM), ANCGRTL  (NL,NT,ICTEM),
     1     RMLCSRTL (NL,NT,ICTEM), RMLCGRTL (NL,NT,ICTEM)
C
      REAL TARTL    (NL,NT),       FSNOWRTL (NL,NT), 
     1     TCANORTL (NL,NT),       TCANSRTL (NL,NT)
C
C     * INPUT/OUTPUT FIELDS FROM MAIN CTEM ROUTINE.
C
      REAL SOILCROT (NL,NT,ICTEMP1),  LITRCROT (NL,NT,ICTEMP1),
     1     ROOTCROT (NL,NT,ICTEM),    STEMCROT (NL,NT,ICTEM),
     2     GLEAFCROT(NL,NT,ICTEM),    BLEAFCROT(NL,NT,ICTEM),
     3     FALLHROT (NL,NT,ICTEM),    POSPHROT (NL,NT,ICTEM),
     4     LEAFSROT (NL,NT,ICTEM),    GROWTROT (NL,NT,ICTEM),
     5     LASTRROT (NL,NT,ICTEM),    LASTSROT (NL,NT,ICTEM),
     6     THISYLROT(NL,NT,ICTEM),    STEMHROT (NL,NT,ICTEM),
     7     ROOTHROT (NL,NT,ICTEM),    TEMPCROT (NL,NT,2)
C
C     * CTEM VEGEGATION CLASS FRACTION FIELDS (3 TIME LEVELS).
C
      REAL PREFROT  (NL,NT,ICTEM),    NEWFROT  (NL,NT,ICTEM)
C
C     * CO2 LAND FLUX.
C
      REAL FCOLROT  (NL,NT)
C
C     * FRACTION AREA OF LAND.
C
      REAL AREAROW (NL)
C
C     * INVARIANT CLASS INPUT FIELDS.
C
      REAL SANDROT (NL,NT,IG),         CLAYROT (NL,NT,IG)
      REAL SDEPROT (NL,NT)
C-------------------------------------------------------------
      REAL CO2CG1GAT(ILG,ICTEM), CO2CG2GAT(ILG,ICTEM), 
     1     CO2CS1GAT(ILG,ICTEM), CO2CS2GAT(ILG,ICTEM)

      REAL CFLUXCSGAT(ILG),      CFLUXCGGAT(ILG)
C
C     * INVARIANT CTEM FIELDS.
C
      REAL LGHTGAT  (ILG),      WETFGAT  (ILG), 
     2     WETSGAT  (ILG) 
C
C     * INPUT FIELDS TO MAIN CTEM ROUTINE FROM AVERAGE OVER
C     * COUPLING PERIOD OF PREVIOUS COUPLING CYCLE.
C     * THESE ARE NOT GATHERED AT GMT=0. SINCE THE "ROT"
C     * FIELDS DON'T EXIST AT THIS POINT UNTIL THEY ARE INITIALIZED.
C
      REAL TBARGTL  (ILG,IG),  TBARCGTL (ILG,IG),
     1     TBARCSGTL(ILG,IG),  TBARGGTL (ILG,IG),
     2     TBARGSGTL(ILG,IG),  THLIQCGTL(ILG,IG),
     3     THLIQGGTL(ILG,IG),  THICECGTL(ILG,IG)
C
      REAL ANCSGTL  (ILG,ICTEM), ANCGGTL  (ILG,ICTEM),
     1     RMLCSGTL (ILG,ICTEM), RMLCGGTL (ILG,ICTEM)
C
      REAL TAGTL    (ILG),       FSNOWGTL (ILG), 
     1     TCANOGTL (ILG),       TCANSGTL (ILG)
C
C     * INPUT/OUTPUT FIELDS FROM MAIN CTEM ROUTINE.
C
      REAL    SOILCGAT (ILG,ICTEMP1),  LITRCGAT (ILG,ICTEMP1),
     1        ROOTCGAT (ILG,ICTEM),    STEMCGAT (ILG,ICTEM),
     2        GLEAFCGAT(ILG,ICTEM),    BLEAFCGAT(ILG,ICTEM),
     3        FALLHGAT (ILG,ICTEM),    GROWTGAT (ILG,ICTEM),
     5        LASTRGAT (ILG,ICTEM),    LASTSGAT (ILG,ICTEM),
     6        THISYLGAT(ILG,ICTEM),    STEMHGAT (ILG,ICTEM),
     7        ROOTHGAT (ILG,ICTEM)
      INTEGER POSPHGAT (ILG,ICTEM),    LEAFSGAT (ILG,ICTEM),
     1        TEMPCGAT (ILG,2)
C
C     * CTEM VEGEGATION CLASS FRACTION FIELDS (3 TIME LEVELS).
C
      REAL    PREFGAT  (ILG,ICTEM),    NEWFGAT  (ILG,ICTEM)
C
C     * CO2 LAND FLUX.
C
      REAL FCOLGAT     (ILG)
C
C     * FRACTION AREA OF LAND.
C
      REAL    AREAGAT  (ILG)
C
C     * INVARIANT CLASS INPUT FIELDS.
C
      REAL    SANDGAT  (ILG,IG),       CLAYGAT  (ILG,IG)
      REAL    SDEPGAT  (ILG)
C
C     * ATMOSPHERIC AND GRID-CONSTANT INPUT VARIABLES.
C
      REAL  CO2ROW( NL), FSFROT( NL,NM)
C
      REAL  CO2GAT(ILG), FSFGAT(ILG)
C
C     * GATHER-SCATTER INDEX ARRAYS.
C
      INTEGER  ILMOS (ILG),  JLMOS  (ILG)
C----------------------------------------------------------------------

      DO 100 K=1,NML
        CFLUXCSGAT(K)=CFLUXCSROT(ILMOS(K),JLMOS(K))  
        CFLUXCGGAT(K)=CFLUXCGROT(ILMOS(K),JLMOS(K))  
        CO2GAT    (K)=CO2ROW    (ILMOS(K))  
        FSFGAT    (K)=FSFROT    (ILMOS(K),JLMOS(K))
        LGHTGAT   (K)=LGHTROW   (ILMOS(K))  
        WETFGAT   (K)=WETFROW   (ILMOS(K))  
        WETSGAT   (K)=WETSROW   (ILMOS(K))  
        SDEPGAT   (K)=SDEPROT   (ILMOS(K),JLMOS(K))
        FCOLGAT   (K)=FCOLROT   (ILMOS(K),JLMOS(K))
        AREAGAT   (K)=AREAROW   (ILMOS(K))
  100 CONTINUE
C
      DO 200 L=1,ICTEM
      DO 200 K=1,NML
        CO2CG1GAT(K,L)=CO2CG1ROT(ILMOS(K),JLMOS(K),L)
        CO2CG2GAT(K,L)=CO2CG2ROT(ILMOS(K),JLMOS(K),L)
        CO2CS1GAT(K,L)=CO2CS1ROT(ILMOS(K),JLMOS(K),L)
        CO2CS2GAT(K,L)=CO2CS2ROT(ILMOS(K),JLMOS(K),L)
C
        ROOTCGAT (K,L)=ROOTCROT (ILMOS(K),JLMOS(K),L)
        STEMCGAT (K,L)=STEMCROT (ILMOS(K),JLMOS(K),L)
        GLEAFCGAT(K,L)=GLEAFCROT(ILMOS(K),JLMOS(K),L)
        BLEAFCGAT(K,L)=BLEAFCROT(ILMOS(K),JLMOS(K),L)
        FALLHGAT (K,L)=FALLHROT (ILMOS(K),JLMOS(K),L)
        POSPHGAT (K,L)=NINT(POSPHROT(ILMOS(K),JLMOS(K),L))
        LEAFSGAT (K,L)=NINT(LEAFSROT(ILMOS(K),JLMOS(K),L))
        GROWTGAT (K,L)=GROWTROT (ILMOS(K),JLMOS(K),L)
        LASTRGAT (K,L)=LASTRROT (ILMOS(K),JLMOS(K),L)
        LASTSGAT (K,L)=LASTSROT (ILMOS(K),JLMOS(K),L)
        THISYLGAT(K,L)=THISYLROT(ILMOS(K),JLMOS(K),L)
        STEMHGAT (K,L)=STEMHROT (ILMOS(K),JLMOS(K),L)
        ROOTHGAT (K,L)=ROOTHROT (ILMOS(K),JLMOS(K),L)
C
        PREFGAT  (K,L)=PREFROT  (ILMOS(K),JLMOS(K),L)
        NEWFGAT  (K,L)=NEWFROT  (ILMOS(K),JLMOS(K),L)
  200 CONTINUE
C
      DO 250 L=1,ICTEMP1
      DO 250 K=1,NML
        SOILCGAT (K,L)=SOILCROT (ILMOS(K),JLMOS(K),L)
        LITRCGAT (K,L)=LITRCROT (ILMOS(K),JLMOS(K),L)
  250 CONTINUE
C
      DO 280 L=1,2
      DO 280 K=1,NML
        TEMPCGAT (K,L)=NINT(TEMPCROT(ILMOS(K),JLMOS(K),L))
  280 CONTINUE
C
      IF(GMT.GT.0. .AND. KOUNT.GT.0) THEN
      DO 400 L=1,IG
      DO 400 K=1,NML
        TBARGTL  (K,L)=TBARRTL  (ILMOS(K),JLMOS(K),L)
        TBARCGTL (K,L)=TBARCRTL (ILMOS(K),JLMOS(K),L)
        TBARCSGTL(K,L)=TBARCSRTL(ILMOS(K),JLMOS(K),L)
        TBARGGTL (K,L)=TBARGRTL (ILMOS(K),JLMOS(K),L)
        TBARGSGTL(K,L)=TBARGSRTL(ILMOS(K),JLMOS(K),L)
        THLIQCGTL(K,L)=THLIQCRTL(ILMOS(K),JLMOS(K),L)
        THLIQGGTL(K,L)=THLIQGRTL(ILMOS(K),JLMOS(K),L)
        THICECGTL(K,L)=THICECRTL(ILMOS(K),JLMOS(K),L)
  400 CONTINUE
C
      DO 500 L=1,ICTEM
      DO 500 K=1,NML
        ANCSGTL  (K,L)=ANCSRTL  (ILMOS(K),JLMOS(K),L)
        ANCGGTL  (K,L)=ANCGRTL  (ILMOS(K),JLMOS(K),L)
        RMLCSGTL (K,L)=RMLCSRTL (ILMOS(K),JLMOS(K),L)
        RMLCGGTL (K,L)=RMLCGRTL (ILMOS(K),JLMOS(K),L)
  500 CONTINUE
C
      DO 600 K=1,NML
        TAGTL     (K)=TARTL     (ILMOS(K),JLMOS(K))
        FSNOWGTL  (K)=FSNOWRTL  (ILMOS(K),JLMOS(K)) 
        TCANOGTL  (K)=TCANORTL  (ILMOS(K),JLMOS(K)) 
        TCANSGTL  (K)=TCANSRTL  (ILMOS(K),JLMOS(K))
  600 CONTINUE      
      ENDIF
C
      DO 700 L=1,IG
      DO 700 K=1,NML
        SANDGAT (K,L)  =SANDROT (ILMOS(K),JLMOS(K),L)
        CLAYGAT (K,L)  =CLAYROT (ILMOS(K),JLMOS(K),L)
  700 CONTINUE

      RETURN
      END
