      SUBROUTINE GTSOA (DGDT,PEDNDT,PEDMDT,PIDNDT,PIDMDT,PIDFDT, &
                        PEDDN,PEMAS,PEN0,PENUM,PEPHI0,PEPSI,PEWETRC, &
                        PIFRC,PIDDN,PIMAS,PIN0,PINUM,PIPHI0,PIPSI, &
                        PIWETRC,T,RHOA,SOAPI,SGPR,DT,ILGA,LEVA, &
                        DERSN,DERSM,DIRSN,DIRSMN,DIRSMS,DECND, &
                        DICND,IERR)
!-----------------------------------------------------------------------
!     PURPOSE:
!     --------
!     GAS-TO-PARTICLE CONVERSTION FOR SECONDARY ORGANIC AEROSOL.
!
!     NOTE: IT IS CRITICAL THAT THE DRY PARTICLE DENSITIES (PEDDN,
!     PIDDN) AND MASS FRACTIONS FOR INTERNALLY MIXED AEROSOL (PIFRC)
!     ARE CONSISTENT WITH THE AEROSOL MASS (PEMAS, PIMAS) AND NUMBER
!     (PENUM, PINUM) CONCENTRATIONS. MAKE SURE THESE ARE CALCULATED
!     BEFORE THIS SUBROUTINE.
!
!     HISTORY:
!     --------
!     * DEC  6/2017 - K.VONSALZEN   CORRECTION OF GROWTH TERM CALCULATION
!     * APR 17/2015 - K.VONSALZEN   CHANGES TO SUPPORT SINGLE PRECISION
!     * FEB 19/2010 - K.VONSALZEN   CORRECT PIDFDT
!     * MAR 16/2009 - K.VONSALZEN   NEW, BASED ON GTPCNV.
!
!     ************************ INDEX OF VARIABLES **********************
!
!     PRIMARY INPUT/OUTPUT VARIABLES (ARGUMENT LIST):
!
! O   DGDT     GAS-PHASE SOA PRECURSOR TENDENCY (KG/KG/SEC)
! O   DECND    SOA PRECURSOR CONDENSATION RATE (KG/KG/SEC), EXT. MIXTURE
! O   DERSM    MASS RESIDUUM FROM NUMERICAL TRUNCATION IN GROWTH
!              CALCULATIONS (KG/KG), EXT. MIXTURE
! O   DERSN    NUMBER RESIDUUM FROM NUMERICAL TRUNCATION IN GROWTH
!              CALCULATIONS (KG/KG), EXT. MIXTURE
! O   DICND    SOA PRECURSOR CONDENSATION RATE (KG/KG/SEC), INT. MIXTURE
! O   DIRSMN   MASS RESIDUUM FOR NON-SOA SPECIES FROM NUM.
!              TRUNCATION IN GROWTH CALCULATIONS (KG/KG), INT. MIXTURE
! O   DIRSMS   MASS RESIDUUM FOR SOA FROM NUM. TRUNCATION
!              IN GROWTH CALCULATIONS (KG/KG), INT. MIXTURE
! O   DIRSN    NUMBER RESIDUUM FROM NUMERICAL TRUNCATION IN GROWTH
!              CALCULATIONS (KG/KG), INT. MIXTURE
! I   DT       TIME STEP (SEC)
! O   IERR     WARNING CODE INDEX
! I   ILGA     NUMBER OF GRID POINTS IN HORIZONTAL DIRECTION
! I   LEVA     NUMBER OF GRID POINTA IN VERTICAL DIRECTION
! I   PEDDN    DENSITY OF DRY AEROSOL PARTICLE (KG/M3), EXT. MIXTURE
! O   PEDMDT   MASS TENDENCY (KG/KG/SEC), EXT. MIXTURE
! O   PEDNDT   NUMBER TENDENCY (1/KG/SEC), EXT. MIXTURE
! I   PEMAS    AEROSOL MASS CONCENTRATION (KG/KG), EXT. MIXTURE
! I   PEN0     1ST PLA SIZE DISTRIBUTION PARAMETER (AMPLITUDE), EXT.
!              MIXTURE
! I   PENUM    AEROSOL NUMBER CONCENTRATION (1/KG), EXT. MIXTURE
! I   PEPHI0   3RD PLA SIZE DISTRIBUTION PARAMETER (MODE SIZE), EXT.
!              MIXTURE
! I   PEPSI    2ND PLA SIZE DISTRIBUTION PARAMETER (WIDTH), EXT. MIXTURE
! I   PEWETRC  TOTAL/WET PARICLE RADIUS (M), EXT. MIXTURE
! I   PIDDN    DENSITY OF DRY AEROSOL PARTICLE (KG/M3), INT. MIXTURE
! O   PIDFDT   AEROSOL SPECIES MASS FRACTION TENDENCY (1/SEC), INT.
!              MIXTURE
! O   PIDMDT   MASS TENDENCY (KG/KG/SEC), INT. MIXTURE
! O   PIDNDT   NUMBER TENDENCY (1/KG/SEC), INT. MIXTURE
! I   PIFRC    AEROSOL SPECIES MASS FRACTION
! I   PIMAS    AEROSOL MASS CONCENTRATION (KG/KG), INT. MIXTURE
! I   PIN0     1ST PLA SIZE DISTRIBUTION PARAMETER (AMPLITUDE), INT.
!              MIXTURE
! I   PINUM    AEROSOL NUMBER CONCENTRATION (1/KG), INT. MIXTURE
! I   PIPHI0   3RD PLA SIZE DISTRIBUTION PARAMETER (MODE SIZE), INT.
!              MIXTURE
! I   PIPSI    2ND PLA SIZE DISTRIBUTION PARAMETER (WIDTH), INT. MIXTURE
! I   PIWETRC  TOTAL/WET PARICLE RADIUS (M), INT. MIXTURE
! I   RHOA     AIR DENSITY (KG/M3)
! I   SGPR     GAS-PHASE PRODUCTION RATE OF SOA PRECURSORS (KG/KG/SEC)
! I   SOAPI    INITIAL SOA PRECURSOR MIXING RATIO (KG/KG)
! I   T        AIR TEMPERATURE (K)
!
!     SECONDARY INPUT/OUTPUT VARIABLES (VIA MODULES AND COMMON BLOCKS):
!
! I   AEXTF%TP(:)%DRYRC(:)
!              DRY PARTICLE RADIUS IN SECTION CENTRE (M), EXT. MIXTURE
! I   AEXTF%TP(:)%DRYR(:)%VL
!              LOWER DRY PARTICLE RADIUS FOR EACH SECTION (M), EXT.
!              MIXTURE
! I   AEXTF%TP(:)%DRYR(:)%VR
!              UPPER DRY PARTICLE RADIUS FOR EACH SECTION (M), EXT.
!              MIXTURE
! I   AINTF%DRYRC(:)
!              DRY PARTICLE RADIUS IN SECTION CENTRE (M), INT. MIXTURE
! I   AINTF%DRYR(:)%VL
!              LOWER DRY PARTICLE RADIUS FOR EACH SECTION (M), INT.
!              MIXTURE
! I   AINTF%DRYR(:)%VR
!              UPPER DRY PARTICLE RADIUS FOR EACH SECTION (M), INT.
!              MIXTURE
! I   IEXOC    AEROSOL TRACER INDEX FOR ORGANIC CARBON, EXT. MIXTURE
! I   IINOC    AEROSOL TRACER INDEX FOR ORGANIC CARBON, INT. MIXTURE
! I   ISAEXT   NUMBER OF AEROSOL TRACERS, EXT. MIXTURE
! I   ISAINT   NUMBER OF AEROSOL TRACERS, INT. MIXTURE
! I   ISEXTOC  NUMBER OF SECTIONS FOR OC, EXT. MIXTURE
! I   ISINTOC  NUMBER OF SECTIONS FOR OC, INT. MIXTURE
! I   IOCS     NUMBER OF NON-OC AEROSOL SPECIES, INT. MIXTURE
! I   KEXTOC   SPECIES INDEX FOR OC, EXT. MIXTURE
! I   KINT     NUMBER OF INTERNALLY MIXED AEROSOL TYPES, INT. MIXTURE
! I   KINTOC   SPECIES INDEX FOR OC, INT. MIXTURE
! I   PEDPHIS  SECTION WIDTH, EXT. MIXTURE
! I   PEPHISS  LOWER DRY PARTICLE SIZE (=LOG(R/R0)), EXT. MIXTURE
! I   PIDPHIS  SECTION WIDTH, INT. MIXTURE
! I   PIPHISS  LOWER DRY PARTICLE SIZE (=LOG(R/R0)), INT. MIXTURE
! I   YLARGE   LARGE NUMBER
! I   YSEC     SECURITY PARAMETER FOR ADJUSTMENT OF TIMESTEP
! I   YSMALL   SMALL NUMBER
! I   YTINY    SMALLEST VALID NUMBER
!
!-----------------------------------------------------------------------
!
      USE SDPARM
      USE FPDEF
!
      IMPLICIT REAL (A-H,O-Z), INTEGER (I-N)
!
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA) :: DGDT
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA,ISAEXT) :: PEDNDT,PEDMDT
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA,ISAINT) :: PIDNDT,PIDMDT
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA,ISAINT,KINT) :: PIDFDT
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA) :: DERSN,DERSM,DECND
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA) :: DIRSMN,DIRSN,DIRSMS, &
                                                 DICND
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA) :: SGPR,T,RHOA,SOAPI
!
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA,ISAEXT) :: &
                            PEDDN,PEMAS,PEN0,PENUM,PEPHI0,PEPSI,PEWETRC
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA,ISAINT) :: &
                            PIDDN,PIMAS,PIN0,PINUM,PIPHI0,PIPSI,PIWETRC
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA,ISAINT,KINT) :: PIFRC
      INTEGER, INTENT(OUT) :: IERR
      INTEGER, INTENT(IN) :: ILGA,LEVA
      REAL, ALLOCATABLE, DIMENSION(:,:,:,:) :: TIMN,TIFRCN
      REAL(R8), ALLOCATABLE, DIMENSION(:,:,:) :: TECNDGP,TECT1,TECT2
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: &
                                    TEWETRC,TEDDN, &
                                    TECGR1,TECGR2,TEN0,TEPHI0, &
                                    TEPSI,TEDPHIT,TEPHIST, &
                                    TECORF,TEDCCND,TENT,TEFRC, &
                                    TEDRYRT
      REAL(R8), ALLOCATABLE, DIMENSION(:,:,:) :: &
                                    TEDP0L,TEDP1L,TEDP2L,TEDP3L, &
                                    TEDP4L,TEDP5L,TEDP6L,TEDM1L, &
                                    TEDM2L,TEDM3L,TEDP0R,TEDP1R, &
                                    TEDP2R,TEDP3R,TEDP4R,TEDP5R, &
                                    TEDP6R,TEDM1R,TEDM2R,TEDM3R, &
                                    TEDP0S,TEDP1S,TEDP2S,TEDP3S, &
                                    TEDP4S,TEDP5S,TEDP6S,TEDM1S, &
                                    TEDM2S,TEDM3S
      REAL(R8), ALLOCATABLE, DIMENSION(:,:,:) :: TICNDGP,TICT1,TICT2
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: &
                                    TIWETRC,TIDDN, &
                                    TICGR1,TICGR2,TIN0,TIPHI0, &
                                    TIPSI,TIDPHIT,TIPHIST, &
                                    TICORF,TIDCCND,TINT,TIFRCS, &
                                    TIDRYRT
      REAL(R8), ALLOCATABLE, DIMENSION(:,:,:) :: &
                                    TIDP0L,TIDP1L,TIDP2L,TIDP3L, &
                                    TIDP4L,TIDP5L,TIDP6L,TIDM1L, &
                                    TIDM2L,TIDM3L,TIDP0R,TIDP1R, &
                                    TIDP2R,TIDP3R,TIDP4R,TIDP5R, &
                                    TIDP6R,TIDM1R,TIDM2R,TIDM3R, &
                                    TIDP0S,TIDP1S,TIDP2S,TIDP3S, &
                                    TIDP4S,TIDP5S,TIDP6S,TIDM1S, &
                                    TIDM2S,TIDM3S
      REAL(R8), ALLOCATABLE, DIMENSION(:,:,:) :: &
                                    TEMT,TIMST
      REAL(R8), ALLOCATABLE, DIMENSION(:,:,:,:) :: TIMNT
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: &
                                    TEN,TEM,TIN,TIM,TIMT,TIMS
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: TIRSMN,TITM1,TITM2
      REAL(R8), ALLOCATABLE, DIMENSION(:,:) :: DFSOAP,DBL1,DBL2,ACND
      REAL, ALLOCATABLE, DIMENSION(:,:) :: &
                                    PLFN,CNDM,CNDMX,TERMX,TERM1,TERM2, &
                                    TERM3,TERM4,FRP,PLAM,PERTC,CORFA, &
                                    CORFAR,DTC,EXPT,SADT,CTMP
      REAL, ALLOCATABLE, DIMENSION(:,:) :: &
                                    TECORFA
      REAL, ALLOCATABLE, DIMENSION(:,:) :: &
                                    TICORFA
      REAL, ALLOCATABLE, DIMENSION(:) :: &
                                    TECORFS,TEDRYR,TEDRYRC
      REAL, ALLOCATABLE, DIMENSION(:) :: &
                                    TICORFS,TIDRYR,TIDRYRC
      INTEGER, ALLOCATABLE, DIMENSION(:,:,:) :: TEI0L,TEI0R
      INTEGER, ALLOCATABLE, DIMENSION(:,:,:) :: TII0L,TII0R
!
!     * NUMERICAL CONSTANTS.
!
      REAL, PARAMETER :: YEPS=0.1      ! THRESHOLD FOR CONVERGENCE TEST
      INTEGER, PARAMETER :: ITER=3     ! NUMBER OF ITERATIONS FOR
                                       ! NEWTON-RHAPSON CALCULATION
      INTEGER, PARAMETER :: IMODC=1
!
!-----------------------------------------------------------------------
!
      IERR=0
!
!     * ALLOCATE MEMORY FOR LOCAL FIELDS.
!
      IF ( ISEXTOC > 0 ) THEN
        ALLOCATE(TEWETRC(ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEN    (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TENT   (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEM    (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEMT   (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDDN  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEN0   (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEPHI0 (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEPSI  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TECT1  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TECT2  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TECGR1 (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TECGR2 (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TECNDGP(ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDCCND(ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDPHIT(ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEPHIST(ILGA,LEVA,ISEXTOC))
        ALLOCATE(TECORF (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEI0L  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEI0R  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP0L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP1L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP2L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP3L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP4L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP5L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP6L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM1L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM2L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM3L (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP0R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP1R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP2R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP3R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP4R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP5R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP6R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM1R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM2R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM3R (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP0S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP1S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP2S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP3S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP4S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP5S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDP6S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM1S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM2S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDM3S (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEFRC  (ILGA,LEVA,ISEXTOC))
        ALLOCATE(TEDRYRT(ILGA,LEVA,ISEXTOC+1))
        ALLOCATE(TECORFS(ISEXTOC))
        ALLOCATE(TEDRYR (ISEXTOC+1))
        ALLOCATE(TEDRYRC(ISEXTOC))
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        ALLOCATE(TIMN   (ILGA,LEVA,ISINTOC,IOCS))
        ALLOCATE(TIMNT  (ILGA,LEVA,ISINTOC,IOCS))
        ALLOCATE(TIFRCN (ILGA,LEVA,ISINTOC,IOCS))
        ALLOCATE(TIMS   (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIMST  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIWETRC(ILGA,LEVA,ISINTOC))
        ALLOCATE(TIN    (ILGA,LEVA,ISINTOC))
        ALLOCATE(TINT   (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIM    (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIMT   (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDDN  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIN0   (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIPHI0 (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIPSI  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TICT1  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TICT2  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TICGR1 (ILGA,LEVA,ISINTOC))
        ALLOCATE(TICGR2 (ILGA,LEVA,ISINTOC))
        ALLOCATE(TICNDGP(ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDCCND(ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDPHIT(ILGA,LEVA,ISINTOC))
        ALLOCATE(TIPHIST(ILGA,LEVA,ISINTOC))
        ALLOCATE(TICORF (ILGA,LEVA,ISINTOC))
        ALLOCATE(TII0L  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TII0R  (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP0L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP1L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP2L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP3L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP4L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP5L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP6L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM1L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM2L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM3L (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP0R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP1R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP2R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP3R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP4R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP5R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP6R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM1R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM2R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM3R (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP0S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP1S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP2S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP3S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP4S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP5S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDP6S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM1S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM2S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDM3S (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIFRCS (ILGA,LEVA,ISINTOC))
        ALLOCATE(TIDRYRT(ILGA,LEVA,ISINTOC+1))
        ALLOCATE(TIRSMN (ILGA,LEVA,IOCS))
        ALLOCATE(TITM1  (ILGA,LEVA,IOCS))
        ALLOCATE(TITM2  (ILGA,LEVA,IOCS))
        ALLOCATE(TICORFS(ISINTOC))
        ALLOCATE(TIDRYR (ISINTOC+1))
        ALLOCATE(TIDRYRC(ISINTOC))
      ENDIF
      ALLOCATE(TECORFA(ILGA,LEVA))
      ALLOCATE(TICORFA(ILGA,LEVA))
      ALLOCATE(CTMP   (ILGA,LEVA))
      ALLOCATE(ACND   (ILGA,LEVA))
      ALLOCATE(PLFN   (ILGA,LEVA))
      ALLOCATE(CNDM   (ILGA,LEVA))
      ALLOCATE(CNDMX  (ILGA,LEVA))
      ALLOCATE(TERMX  (ILGA,LEVA))
      ALLOCATE(TERM1  (ILGA,LEVA))
      ALLOCATE(TERM2  (ILGA,LEVA))
      ALLOCATE(TERM3  (ILGA,LEVA))
      ALLOCATE(TERM4  (ILGA,LEVA))
      ALLOCATE(DFSOAP (ILGA,LEVA))
      ALLOCATE(FRP    (ILGA,LEVA))
      ALLOCATE(PLAM   (ILGA,LEVA))
      ALLOCATE(PERTC  (ILGA,LEVA))
      ALLOCATE(CORFA  (ILGA,LEVA))
      ALLOCATE(CORFAR (ILGA,LEVA))
      ALLOCATE(DTC    (ILGA,LEVA))
      ALLOCATE(EXPT   (ILGA,LEVA))
      ALLOCATE(SADT   (ILGA,LEVA))
      ALLOCATE(DBL1   (ILGA,LEVA))
      ALLOCATE(DBL2   (ILGA,LEVA))
!
!     * INITIALIZATION.
!
      IF ( ISAEXT > 0 ) THEN
        PEDNDT=0.
        PEDMDT=0.
      ENDIF
      IF ( ISAINT > 0 ) THEN
        PIDNDT=0.
        PIDMDT=0.
        PIDFDT=0.
      ENDIF
!
!     * TEMPORARY AEROSOL FIELDS FOR OC AEROSOL FOR DRY
!     * AND WET PARTICLE SIZES FOR EXTERNALLY MIXED AEROSOL TYPE.
!
      IF ( KEXTOC > 0 ) THEN
        DO IS=1,ISEXTOC
          TEWETRC(:,:,IS)=PEWETRC(:,:,IEXOC(IS))
          TEN    (:,:,IS)=PENUM  (:,:,IEXOC(IS))
          TEM    (:,:,IS)=PEMAS  (:,:,IEXOC(IS))
          TEDDN  (:,:,IS)=PEDDN  (:,:,IEXOC(IS))
          TEN0   (:,:,IS)=PEN0   (:,:,IEXOC(IS))
          TEPHI0 (:,:,IS)=PEPHI0 (:,:,IEXOC(IS))
          TEPSI  (:,:,IS)=PEPSI  (:,:,IEXOC(IS))
          TEDPHIT(:,:,IS)=PEDPHIS(IEXOC(IS))
          TEPHIST(:,:,IS)=PEPHISS(IEXOC(IS))
          TEDRYRC(IS)=AEXTF%TP(KEXTOC)%DRYRC(IS)
          TEDRYR(IS)=AEXTF%TP(KEXTOC)%DRYR(IS)%VL
          TEDRYRT(:,:,IS)=TEDRYR(IS)
        ENDDO
        TEDRYR(ISEXTOC+1)=AEXTF%TP(KEXTOC)%DRYR(ISEXTOC)%VR
        TEDRYRT(:,:,ISEXTOC+1)=TEDRYR(ISEXTOC+1)
      ENDIF
!
!     * TEMPORARY AEROSOL FIELDS FOR OC AEROSOL FOR DRY
!     * AND WET PARTICLE SIZES FOR INTERNALLY MIXED AEROSOL TYPE.
!
      IF ( KINTOC > 0 ) THEN
        DO IS=1,ISINTOC
          TIWETRC(:,:,IS)=PIWETRC(:,:,IINOC(IS))
          TIN    (:,:,IS)=PINUM  (:,:,IINOC(IS))
          TIM    (:,:,IS)=PIMAS  (:,:,IINOC(IS))
          TIMS   (:,:,IS)=PIMAS  (:,:,IINOC(IS)) &
                         *PIFRC  (:,:,IINOC(IS),KINTOC)
          TIFRCS (:,:,IS)=PIFRC  (:,:,IINOC(IS),KINTOC)
          DO IT=1,IOCS
            TIMN(:,:,IS,IT)=PIMAS  (:,:,IINOC(IS)) &
                           *PIFRC  (:,:,IINOC(IS),ITOC(IT))
            TIFRCN(:,:,IS,IT)=PIFRC(:,:,IINOC(IS),ITOC(IT))
          ENDDO
          TIDDN  (:,:,IS)=PIDDN  (:,:,IINOC(IS))
          TIN0   (:,:,IS)=PIN0   (:,:,IINOC(IS))
          TIPHI0 (:,:,IS)=PIPHI0 (:,:,IINOC(IS))
          TIPSI  (:,:,IS)=PIPSI  (:,:,IINOC(IS))
          TIDPHIT(:,:,IS)=PIDPHIS(IINOC(IS))
          TIPHIST(:,:,IS)=PIPHISS(IINOC(IS))
          TIDRYRC(IS)=AINTF%DRYRC(IINOC(IS))
          TIDRYR(IS)=AINTF%DRYR(IINOC(IS))%VL
          TIDRYRT(:,:,IS)=TIDRYR(IS)
        ENDDO
        TIDRYR(ISINTOC+1)=AINTF%DRYR(AINTF%TP(KINTOC)%ISCE)%VR
        TIDRYRT(:,:,ISINTOC+1)=TIDRYR(ISINTOC+1)
      ENDIF
!
!-----------------------------------------------------------------------
!     * DIFFUSIVITY OF SOA PRECURSORS, MEAN FREE PATH, AND RATE
!     * COEFFICIENTS FOR CONDENSATION OF SOA PRECURSORS ONTO PRE-
!     * EXISTING AEROSOL (CNDGP, IN 1/S).
!
      TERM1=SQRT(T)
      TERM1=TERM1*T
      DFSOAP = 2.150E-09_R8 * TERM1
      DBL1=1.62864E-25/T
      DBL2=SQRT(DBL1)
      FRP = 3.372999311E+11_R8*DFSOAP*DBL2
      WRAT=1.
      ACND=0.
      IF ( ISEXTOC > 0 ) THEN
        CALL GRWTRM(TECNDGP,TECGR1,TECGR2,TECT1,TECT2,TEN0,TEN,TEWETRC, &
                    TEDRYRC,TEDRYR,TEDDN,TEPHI0,TEPSI,TEPHIST,TEDPHIT, &
                    FRP,DFSOAP,WRAT,RHOA,LEVA,ILGA,ISEXTOC)
        ACND=ACND+SUM(TECNDGP,DIM=3)
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        CALL GRWTRM(TICNDGP,TICGR1,TICGR2,TICT1,TICT2,TIN0,TIN,TIWETRC, &
                    TIDRYRC,TIDRYR,TIDDN,TIPHI0,TIPSI,TIPHIST,TIDPHIT, &
                    FRP,DFSOAP,WRAT,RHOA,LEVA,ILGA,ISINTOC)
        ACND=ACND+SUM(TICNDGP,DIM=3)
      ENDIF
!
!-----------------------------------------------------------------------
!     * PARAMETERS FOR TIME-EVOLUTION OF SOA PRECURSOR CONCENTRATIONS
!     * TO EQUILIBRIUM SOLUTION (CTMP).
!
      CTMP=SGPR/MAX(ACND,YTINY)
      PLAM=ACND
      DBL1=-PLAM*DT
      DBL2=EXP(DBL1)
      EXPT=DBL2
!
!     * TIME-INTEGRATED SOA PRECURSOR CONCENTRATION (SADT).
!
      PERTC=SOAPI-CTMP
      TERM2=PERTC*(EXPT-1.)
      WHERE ( PLAM <= MAX(ABS(TERM2)/YLARGE,YTINY) )
        PLFN=-PERTC*DT
        SADT=SOAPI*DT+.5*SGPR*DT**2
      ELSEWHERE
        PLFN=TERM2/PLAM
        SADT=CTMP*DT-PLFN
      ENDWHERE
      SADT=MAX(SADT,0.)
!
!     * GROWTH FACTOR FROM TIME-INTEGRATION OF R*DR/DT. UNITS: M**2.
!     * YSEC IS THE THRESHOLD FOR THE ADJUSTMENT TO TIME STEP.
!
      TECORFM=1./YSEC
      TECORFA=1./YSEC
      IF ( ISEXTOC > 0 ) THEN
        DO IS=1,ISEXTOC
          TECGR1(:,:,IS)=TECGR1(:,:,IS)*SADT(:,:)
          TECGR2(:,:,IS)=TECGR2(:,:,IS)*SADT(:,:)
          TERM1=MAX(TECGR1(:,:,IS)+TECGR2(:,:,IS)*TEDRYR(IS  ),YSMALL)
          TERM2=MAX(TECGR1(:,:,IS)+TECGR2(:,:,IS)*TEDRYR(IS+1),YSMALL)
          TECORF(:,:,IS)=YSEC*MIN(TEDRYR(IS  )**2/TERM1(:,:), &
                                  TEDRYR(IS+1)**2/TERM2(:,:))
        ENDDO
        TECORF=MIN(1./YSEC,TECORF)
        TECORFM=MINVAL(TECORF)
        DO L=1,LEVA
        DO IL=1,ILGA
          TECORFS(:)=TECORF(IL,L,:)
          TECORFA(IL,L)=MINVAL(TECORFS)
        ENDDO
        ENDDO
      ENDIF
      TICORFM=1./YSEC
      TICORFA=1./YSEC
      IF ( ISINTOC > 0 ) THEN
        DO IS=1,ISINTOC
          TICGR1(:,:,IS)=TICGR1(:,:,IS)*SADT(:,:)
          TICGR2(:,:,IS)=TICGR2(:,:,IS)*SADT(:,:)
          TERM1=MAX(TICGR1(:,:,IS)+TICGR2(:,:,IS)*TIDRYR(IS  ),YSMALL)
          TERM2=MAX(TICGR1(:,:,IS)+TICGR2(:,:,IS)*TIDRYR(IS+1),YSMALL)
          TICORF(:,:,IS)=YSEC*MIN(TIDRYR(IS  )**2/TERM1(:,:), &
                                  TIDRYR(IS+1)**2/TERM2(:,:))
        ENDDO
        TICORF=MIN(1./YSEC,TICORF)
        TICORFM=MINVAL(TICORF)
        DO L=1,LEVA
        DO IL=1,ILGA
          TICORFS(:)=TICORF(IL,L,:)
          TICORFA(IL,L)=MINVAL(TICORFS)
        ENDDO
        ENDDO
      ENDIF
!
!-----------------------------------------------------------------------
!     * IF NECESSARY, ADJUST TIME STEP TO LIMIT AEROSOL GROWTH
!     * IF GROWTH RATE EXCEEDS CRITICAL THRSHOLD FOR TREATMENT
!     * OF CONDENSATION IN SUBROUTINE PGRWTH.
!
      DTC=DT
      CORFM=MIN(TECORFM,TICORFM)
      CORFAR=1.
      IF ( CORFM < 1. ) THEN
        CORFA=MIN(TECORFA,TICORFA)
        CORFAR=MIN(CORFA,1.)
        SADT=SADT*CORFAR
        IF ( ISEXTOC > 0 ) THEN
          DO IS=1,ISEXTOC
            TECGR1(:,:,IS)=TECGR1(:,:,IS)*CORFAR(:,:)
            TECGR2(:,:,IS)=TECGR2(:,:,IS)*CORFAR(:,:)
          ENDDO
        ENDIF
        IF ( ISINTOC > 0 ) THEN
          DO IS=1,ISINTOC
            TICGR1(:,:,IS)=TICGR1(:,:,IS)*CORFAR(:,:)
            TICGR2(:,:,IS)=TICGR2(:,:,IS)*CORFAR(:,:)
          ENDDO
        ENDIF
!
!       * ITERATE TO OBTAIN REDUCED TIME STEP.
!
        TERMX=CTMP+PERTC*EXPT
        WHERE ( TERMX < YTINY .AND. CORFA < 1. ) DTC=0.
        TERM2=0.
        DO INDS = 1,ITER
          TERM1=PERTC*(EXPT-1.)
          WHERE ( CORFA < 1. .AND. PLAM > MAX(ABS(TERM1)/YLARGE,YTINY) &
                           .AND. TERMX > MAX(ABS(TERM2)/YLARGE,YTINY) )
            PLFN=TERM1/PLAM
            TERM2=CTMP*DTC-PLFN-SADT
            DTC=MIN(MAX(DTC-TERM2/TERMX,0.),DT)
          ENDWHERE
          EXPT=EXP(-PLAM*DTC)
          TERMX=CTMP+PERTC*EXPT
        ENDDO
        TERM1=ABS(TERM2)
        WHERE ( SADT > MAX(TERM1/YLARGE,YTINY) )
          TERMX=TERM1/SADT
        ELSEWHERE
          TERMX=0.
        ENDWHERE
        IF ( MAXVAL(TERMX) > YEPS ) IERR=-2
        TERM1=PERTC*(EXPT-1.)
        WHERE ( ABS(PLAM) > MAX(ABS(TERM1)/YLARGE,YTINY) )
          PLFN=TERM1/PLAM
        ELSEWHERE
          PLFN=-PERTC*DTC
        ENDWHERE
      ENDIF
      IF ( MINVAL(DTC) < DT ) IERR=-3
!
!-----------------------------------------------------------------------
!     * CHANGE IN SOA PRECURSOR CONCENTRATION FROM CONDENSATION.
!
      IF ( ISEXTOC > 0 ) THEN
        DO IS=1,ISEXTOC
          TEDCCND(:,:,IS)=-TECNDGP(:,:,IS)*SADT(:,:)/RHOA(:,:)
        ENDDO
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        DO IS=1,ISINTOC
          TIDCCND(:,:,IS)=-TICNDGP(:,:,IS)*SADT(:,:)/RHOA(:,:)
        ENDDO
      ENDIF
!
!     * DIAGNOSE CONDENSATION RATES.
!
      DECND=0.
      DICND=0.
      CNDM=0.
      IF ( ISEXTOC > 0 ) THEN
        TERMX=SUM(TEDCCND,DIM=3)
        CNDM=CNDM+TERMX
        DECND=DECND-TERMX/DT
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        TERMX=SUM(TIDCCND,DIM=3)
        CNDM=CNDM+TERMX
        DICND=DICND-TERMX/DT
      ENDIF
!
!     * ADJUST CONDENSATION RATES TO MAKE SURE THAT TRUNCATION ERRORS
!     * IN CALCULATIONS OF CONDENSATION RATES DO NOT LEAD TO ANY
!     * NEGATIVE SOA PRECURSOR CONCENTRATIONS.
!
      CNDMX=-SOAPI-SGPR*DT
      TERMX=1.
      WHERE ( CNDM < CNDMX .AND. CNDM < MIN(CNDMX/YLARGE,-YTINY) )
        TERMX=CNDMX/CNDM
        CNDM=CNDMX
        DECND=DECND*TERMX
        DICND=DICND*TERMX
      ENDWHERE
      IF ( ISEXTOC > 0 ) THEN
        DO IS=1,ISEXTOC
          TEDCCND(:,:,IS)=TEDCCND(:,:,IS)*TERMX(:,:)
        ENDDO
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        DO IS=1,ISINTOC
          TIDCCND(:,:,IS)=TIDCCND(:,:,IS)*TERMX(:,:)
        ENDDO
      ENDIF
!
!-----------------------------------------------------------------------
!     * PARTICLE GROWTH DUE TO CONDENSATION/EVAPORATION. THE FOLLOWING
!     * CALCULATIONS PROVIDE THE UPDATED SIZE DISTRIBUTIONS FOR
!     * PARTICLE NUMBER,OC AEROSOL MASS, AND MASS OF OTHER AEROSOL
!     * SPECIES AFTER THE CONDENSATION STEP.
!
      DERSN=0.
      DERSM=0.
      IF ( ISEXTOC > 0 ) THEN
        CALL PGRPAR (TEDP0L,TEDP1L,TEDP2L,TEDP3L,TEDP4L,TEDP5L,TEDP6L, &
                     TEDM1L,TEDM2L,TEDM3L,TEDP0R,TEDP1R,TEDP2R,TEDP3R, &
                     TEDP4R,TEDP5R,TEDP6R,TEDM1R,TEDM2R,TEDM3R,TEDP0S, &
                     TEDP1S,TEDP2S,TEDP3S,TEDP4S,TEDP5S,TEDP6S,TEDM1S, &
                     TEDM2S,TEDM3S,TEI0L,TEI0R,TECGR1,TECGR2,TEN0, &
                     TEDRYRT,TEPHIST,TEDPHIT,TEPHI0,TEPSI,ILGA,LEVA, &
                     ISEXTOC,IERR,IMODC)
        CALL PGRWTH0(TENT,DERSN,TEI0L,TEI0R,TEDP0L,TEDP0R,TEDP0S, &
                     TEN0,ILGA,LEVA,ISEXTOC)
        TEFRC(:,:,:)=1.
        CALL PGRWTHS(TEMT,DERSM,TEFRC,TEI0L,TEI0R, &
                     TEDP0L,TEDP1L,TEDP2L,TEDP3L,TEDM1L,TEDM2L,TEDM3L, &
                     TEDP0R,TEDP1R,TEDP2R,TEDP3R,TEDM1R,TEDM2R,TEDM3R, &
                     TEDP0S,TEDP1S,TEDP2S,TEDP3S,TEDM1S,TEDM2S,TEDM3S, &
                     TECGR1,TECGR2,TEN0,TEDDN,ILGA,LEVA,ISEXTOC)
      ENDIF
      DIRSN=0.
      DIRSMS=0.
      DIRSMN=0.
      IF ( ISINTOC > 0 ) THEN
        CALL PGRPAR (TIDP0L,TIDP1L,TIDP2L,TIDP3L,TIDP4L,TIDP5L,TIDP6L, &
                     TIDM1L,TIDM2L,TIDM3L,TIDP0R,TIDP1R,TIDP2R,TIDP3R, &
                     TIDP4R,TIDP5R,TIDP6R,TIDM1R,TIDM2R,TIDM3R,TIDP0S, &
                     TIDP1S,TIDP2S,TIDP3S,TIDP4S,TIDP5S,TIDP6S,TIDM1S, &
                     TIDM2S,TIDM3S,TII0L,TII0R,TICGR1,TICGR2,TIN0, &
                     TIDRYRT,TIPHIST,TIDPHIT,TIPHI0,TIPSI,ILGA,LEVA, &
                     ISINTOC,IERR,IMODC)
        CALL PGRWTH0(TINT,DIRSN,TII0L,TII0R,TIDP0L,TIDP0R,TIDP0S, &
                     TIN0,ILGA,LEVA,ISINTOC)
        CALL PGRWTHS(TIMST,DIRSMS,TIFRCS,TII0L,TII0R, &
                     TIDP0L,TIDP1L,TIDP2L,TIDP3L,TIDM1L,TIDM2L,TIDM3L, &
                     TIDP0R,TIDP1R,TIDP2R,TIDP3R,TIDM1R,TIDM2R,TIDM3R, &
                     TIDP0S,TIDP1S,TIDP2S,TIDP3S,TIDM1S,TIDM2S,TIDM3S, &
                     TICGR1,TICGR2,TIN0,TIDDN,ILGA,LEVA,ISINTOC)
        IF ( IOCS > 0 ) THEN
          TIRSMN=0.
          CALL PGRWTHN(TIMNT,TIRSMN,TIFRCN,TII0L,TII0R,TIDP3L,TIDP3R, &
                       TIDP3S,TIN0,TIDDN,ILGA,LEVA,IOCS,ISINTOC)
          DIRSMN=SUM(TIRSMN,DIM=3)
        ENDIF
      ENDIF
!
!-----------------------------------------------------------------------
!     * NUMBER AND MASS FIXERS. THIS CORRECTS FOR ANY TRUNCATION
!     * ERRORS THAT MAY HAVE OCCURRED PREVIOUSLY. THE APPROACH IS
!     * TO SCALE THE TOTAL NUMBER AND MASS CONCENTRATIONS SO THAT THE
!     * FINAL TOTAL MASS WILL BE CONSISTENT WITH THE CORRESPONDING
!     * PHYSICO-CHEMICAL PRODUCTION AND LOSS RATES.
!
      TERM1=0.
      TERM2=0.
      TERM3=0.
      TERM4=0.
      IF ( ISEXTOC > 0 ) THEN
        TENT=MAX(TENT,0.)
        TEMT=MAX(TEMT,0._R8)
        TERM1=TERM1+SUM(TEMT,DIM=3)+DERSM
        TERM2=TERM2+SUM(TENT,DIM=3)+DERSN
        TERM3=TERM3+SUM(TEM ,DIM=3)
        TERM4=TERM4+SUM(TEN ,DIM=3)
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        TINT=MAX(TINT,0.)
        TIMST=MAX(TIMST,0._R8)
        TERM1=TERM1+SUM(TIMST,DIM=3)+DIRSMS
        TERM2=TERM2+SUM(TINT ,DIM=3)+DIRSN
        TERM3=TERM3+SUM(TIMS ,DIM=3)
        TERM4=TERM4+SUM(TIN  ,DIM=3)
        IF ( IOCS > 0 ) THEN
          TITM1=SUM(TIMNT,DIM=3)+TIRSMN
          TITM2=SUM(TIMN ,DIM=3)
        ENDIF
      ENDIF
!
      DO L=1,LEVA
      DO IL=1,ILGA
!
!       * CORRECT AEROSOL NUMBER CONCENTRATION.
!
        IF ( TERM2(IL,L) > MAX(TERM4(IL,L)/YLARGE,YTINY) ) THEN
          CFN=TERM4(IL,L)/TERM2(IL,L)
          IF ( ISEXTOC > 0 ) TENT(IL,L,:)=TENT(IL,L,:)*CFN
          IF ( ISINTOC > 0 ) TINT(IL,L,:)=TINT(IL,L,:)*CFN
        ENDIF
!
!       * CORRECT SOA CONCENTRATION.
!
        TERM5=TERM3(IL,L)-CNDM(IL,L)
        IF ( TERM1(IL,L) > MAX(TERM5/YLARGE,YTINY) ) THEN
          CFM=TERM5/TERM1(IL,L)
          IF ( ISEXTOC > 0 ) TEMT (IL,L,:)=TEMT (IL,L,:)*CFM
          IF ( ISINTOC > 0 ) TIMST(IL,L,:)=TIMST(IL,L,:)*CFM
        ENDIF
      ENDDO
      ENDDO
!
!     * CORRECT NON-SOA MASS CONCENTRATION.
!
      IF ( ISINTOC > 0 ) THEN
        DO IT=1,IOCS
        DO L=1,LEVA
        DO IL=1,ILGA
          IF ( TITM1(IL,L,IT) > MAX(TITM2(IL,L,IT)/YLARGE,YTINY) ) THEN
            CFM=TITM2(IL,L,IT)/TITM1(IL,L,IT)
            TIMNT(IL,L,:,IT)=TIMNT(IL,L,:,IT)*CFM
          ENDIF
        ENDDO
        ENDDO
        ENDDO
      ENDIF
!
!-----------------------------------------------------------------------
!     * TOTAL AEROSOL MASS FOR INTERNALLY MIXED AEROSOL SPECIES.
!
      IF ( KINTOC > 0 ) THEN
        TIMT=TIMST
        DO IT=1,IOCS
          TIMT(:,:,:)=TIMT(:,:,:)+TIMNT(:,:,:,IT)
        ENDDO
      ENDIF
!
!-----------------------------------------------------------------------
!     * SOA PRECURSOR TENDENCY.
!
      DGDT=(SGPR*DT+CNDM)/DT
!
!-----------------------------------------------------------------------
!     * TRACER TENDENCIES.
!
      IF ( KEXTOC > 0 ) THEN
        DO IS=1,ISEXTOC
          PEDNDT(:,:,IEXOC(IS))=(TENT(:,:,IS)-TEN(:,:,IS))/DT
          PEDMDT(:,:,IEXOC(IS))=(TEMT(:,:,IS)-TEM(:,:,IS))/DT
        ENDDO
      ENDIF
      IF ( KINTOC > 0 ) THEN
        DO IS=1,ISINTOC
          PIDNDT(:,:,IINOC(IS))=(TINT(:,:,IS)-TIN(:,:,IS))/DT
          PIDMDT(:,:,IINOC(IS))=(TIMT(:,:,IS)-TIM(:,:,IS))/DT
          WHERE ( TIMT(:,:,IS) > YTINY )
            PIDFDT(:,:,IINOC(IS),KINTOC)= &
                         (TIMST(:,:,IS)/TIMT(:,:,IS)-TIFRCS(:,:,IS))/DT
          ELSEWHERE
            PIDFDT(:,:,IINOC(IS),KINTOC)=0.
          ENDWHERE
          DO IT=1,IOCS
            WHERE ( TIMT(:,:,IS) > YTINY )
              PIDFDT(:,:,IINOC(IS),ITOC(IT))= &
                   (TIMNT(:,:,IS,IT)/TIMT(:,:,IS)-TIFRCN(:,:,IS,IT))/DT
            ELSEWHERE
              PIDFDT(:,:,IINOC(IS),ITOC(IT))=0.
            ENDWHERE
          ENDDO
        ENDDO
      ENDIF
!
!     * RESET TENDENCIES IN CASE NO CONDENSATION OCCURS TO ACCOUNT
!     * FOR NUMERICAL TRUNCATION ERRORS.
!
      IF ( ISEXTOC > 0 ) THEN
        DO L=1,LEVA
        DO IL=1,ILGA
          IF ( CNDM(IL,L) > -YTINY ) THEN
            PEDNDT(IL,L,:)=0.
            PEDMDT(IL,L,:)=0.
          ENDIF
        ENDDO
        ENDDO
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        DO L=1,LEVA
        DO IL=1,ILGA
          IF ( CNDM(IL,L) > -YTINY ) THEN
            PIDNDT(IL,L,:)=0.
            PIDMDT(IL,L,:)=0.
            PIDFDT(IL,L,:,:)=0.
          ENDIF
        ENDDO
        ENDDO
      ENDIF
!
!     * DEALLOCATION.
!
      IF ( ISEXTOC > 0 ) THEN
        DEALLOCATE(TEWETRC)
        DEALLOCATE(TEN    )
        DEALLOCATE(TENT   )
        DEALLOCATE(TEM    )
        DEALLOCATE(TEMT   )
        DEALLOCATE(TEDDN  )
        DEALLOCATE(TEN0   )
        DEALLOCATE(TEPHI0 )
        DEALLOCATE(TEPSI  )
        DEALLOCATE(TECT1  )
        DEALLOCATE(TECT2  )
        DEALLOCATE(TECGR1 )
        DEALLOCATE(TECGR2 )
        DEALLOCATE(TECNDGP)
        DEALLOCATE(TEDCCND)
        DEALLOCATE(TEDPHIT)
        DEALLOCATE(TEPHIST)
        DEALLOCATE(TECORF )
        DEALLOCATE(TEI0L  )
        DEALLOCATE(TEI0R  )
        DEALLOCATE(TEDP0L )
        DEALLOCATE(TEDP1L )
        DEALLOCATE(TEDP2L )
        DEALLOCATE(TEDP3L )
        DEALLOCATE(TEDP4L )
        DEALLOCATE(TEDP5L )
        DEALLOCATE(TEDP6L )
        DEALLOCATE(TEDM1L )
        DEALLOCATE(TEDM2L )
        DEALLOCATE(TEDM3L )
        DEALLOCATE(TEDP0R )
        DEALLOCATE(TEDP1R )
        DEALLOCATE(TEDP2R )
        DEALLOCATE(TEDP3R )
        DEALLOCATE(TEDP4R )
        DEALLOCATE(TEDP5R )
        DEALLOCATE(TEDP6R )
        DEALLOCATE(TEDM1R )
        DEALLOCATE(TEDM2R )
        DEALLOCATE(TEDM3R )
        DEALLOCATE(TEDP0S )
        DEALLOCATE(TEDP1S )
        DEALLOCATE(TEDP2S )
        DEALLOCATE(TEDP3S )
        DEALLOCATE(TEDP4S )
        DEALLOCATE(TEDP5S )
        DEALLOCATE(TEDP6S )
        DEALLOCATE(TEDM1S )
        DEALLOCATE(TEDM2S )
        DEALLOCATE(TEDM3S )
        DEALLOCATE(TEFRC  )
        DEALLOCATE(TEDRYRT)
        DEALLOCATE(TECORFS)
        DEALLOCATE(TEDRYR )
        DEALLOCATE(TEDRYRC)
      ENDIF
      IF ( ISINTOC > 0 ) THEN
        DEALLOCATE(TIMN   )
        DEALLOCATE(TIMNT  )
        DEALLOCATE(TIFRCN )
        DEALLOCATE(TIMS   )
        DEALLOCATE(TIMST  )
        DEALLOCATE(TIWETRC)
        DEALLOCATE(TIN    )
        DEALLOCATE(TINT   )
        DEALLOCATE(TIM    )
        DEALLOCATE(TIMT   )
        DEALLOCATE(TIDDN  )
        DEALLOCATE(TIN0   )
        DEALLOCATE(TIPHI0 )
        DEALLOCATE(TIPSI  )
        DEALLOCATE(TICT1  )
        DEALLOCATE(TICT2  )
        DEALLOCATE(TICGR1 )
        DEALLOCATE(TICGR2 )
        DEALLOCATE(TICNDGP)
        DEALLOCATE(TIDCCND)
        DEALLOCATE(TIDPHIT)
        DEALLOCATE(TIPHIST)
        DEALLOCATE(TICORF )
        DEALLOCATE(TII0L  )
        DEALLOCATE(TII0R  )
        DEALLOCATE(TIDP0L )
        DEALLOCATE(TIDP1L )
        DEALLOCATE(TIDP2L )
        DEALLOCATE(TIDP3L )
        DEALLOCATE(TIDP4L )
        DEALLOCATE(TIDP5L )
        DEALLOCATE(TIDP6L )
        DEALLOCATE(TIDM1L )
        DEALLOCATE(TIDM2L )
        DEALLOCATE(TIDM3L )
        DEALLOCATE(TIDP0R )
        DEALLOCATE(TIDP1R )
        DEALLOCATE(TIDP2R )
        DEALLOCATE(TIDP3R )
        DEALLOCATE(TIDP4R )
        DEALLOCATE(TIDP5R )
        DEALLOCATE(TIDP6R )
        DEALLOCATE(TIDM1R )
        DEALLOCATE(TIDM2R )
        DEALLOCATE(TIDM3R )
        DEALLOCATE(TIDP0S )
        DEALLOCATE(TIDP1S )
        DEALLOCATE(TIDP2S )
        DEALLOCATE(TIDP3S )
        DEALLOCATE(TIDP4S )
        DEALLOCATE(TIDP5S )
        DEALLOCATE(TIDP6S )
        DEALLOCATE(TIDM1S )
        DEALLOCATE(TIDM2S )
        DEALLOCATE(TIDM3S )
        DEALLOCATE(TIFRCS )
        DEALLOCATE(TIDRYRT)
        DEALLOCATE(TIRSMN )
        DEALLOCATE(TITM1  )
        DEALLOCATE(TITM2  )
        DEALLOCATE(TICORFS)
        DEALLOCATE(TIDRYR )
        DEALLOCATE(TIDRYRC)
      ENDIF
      DEALLOCATE(TECORFA)
      DEALLOCATE(TICORFA)
      DEALLOCATE(CTMP   )
      DEALLOCATE(ACND   )
      DEALLOCATE(PLFN   )
      DEALLOCATE(CNDM   )
      DEALLOCATE(CNDMX  )
      DEALLOCATE(TERMX  )
      DEALLOCATE(TERM1  )
      DEALLOCATE(TERM2  )
      DEALLOCATE(TERM3  )
      DEALLOCATE(TERM4  )
      DEALLOCATE(DFSOAP )
      DEALLOCATE(FRP    )
      DEALLOCATE(PLAM   )
      DEALLOCATE(PERTC  )
      DEALLOCATE(CORFA  )
      DEALLOCATE(CORFAR )
      DEALLOCATE(DTC    )
      DEALLOCATE(EXPT   )
      DEALLOCATE(SADT   )
      DEALLOCATE(DBL1   )
      DEALLOCATE(DBL2   )
!
      END SUBROUTINE GTSOA
