      SUBROUTINE EFFRV(ANUM,AMAS,PN0,PHI0,PSI,PHIS0,DPHI0, &
                       WETRC,DRYRC,DRYDN,ALD,RE,VE,ILGA,LEVA,ISEC)
!-----------------------------------------------------------------------
!     PURPOSE:
!     --------
!     CALCULATION OF EFFECTIVE RADIUS AND VARIANCE USING MOMENTS.
!
!     HISTORY:
!     --------
!     * FEB 15/2010 - K. VONSALZEN   INCLUDE DEALLOCATION FOR AM1
!     * NOV 24/2008 - X. MA MODIFIED FOR NEW PLA CODE
!     * FEB 10/2006 - X. MA
!
!-----------------------------------------------------------------------
!
      USE SDPARM
      USE SDCODE
!
      IMPLICIT REAL (A-H,O-Z), INTEGER (I-N)
!
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA) :: ALD,RE,VE
      INTEGER, INTENT(IN) :: ILGA,LEVA,ISEC
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA,ISEC) :: &
                                         ANUM,AMAS,PN0,PHI0,PSI,WETRC, &
                                         DRYDN,PHIS0,DPHI0
      REAL, INTENT(IN), DIMENSION(ISEC) :: DRYRC
!
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: PHI0W,PHIS0W,WETDN, &
                                              AM0,AM1,AM2,AM3,AM4
      REAL, ALLOCATABLE, DIMENSION(:,:) :: TAM0,TAM2,TAM3,TAM4
!
!---------------------------------------------------------------------
!     * ALLOCATE MEMORY.
!
      ALLOCATE(PHI0W (ILGA,LEVA,ISEC))
      ALLOCATE(PHIS0W(ILGA,LEVA,ISEC))
      ALLOCATE(WETDN (ILGA,LEVA,ISEC))
      ALLOCATE(AM0  (ILGA,LEVA,ISEC))
      ALLOCATE(AM1  (ILGA,LEVA,ISEC))
      ALLOCATE(AM2  (ILGA,LEVA,ISEC))
      ALLOCATE(AM3  (ILGA,LEVA,ISEC))
      ALLOCATE(AM4  (ILGA,LEVA,ISEC))
      ALLOCATE(TAM0 (ILGA,LEVA))
      ALLOCATE(TAM2 (ILGA,LEVA))
      ALLOCATE(TAM3 (ILGA,LEVA))
      ALLOCATE(TAM4 (ILGA,LEVA))
!
!     * HYGROSCOPIC GROWTH EFFECTS ON RADIUS AND PARTICLE DENSITY.
!
      PHI0W =PHI0
      PHIS0W=PHIS0
      WETDN=DRYDN
      DO IS=1,ISEC
      DO L=1,LEVA
      DO IL=1,ILGA
        IF ( ANUM(IL,L,IS) > YTINY .AND. AMAS(IL,L,IS) > YTINY ) THEN
          FGR=WETRC(IL,L,IS)/DRYRC(IS)
          ALFGR=LOG(FGR)
          PHI0W (IL,L,IS)=PHI0W (IL,L,IS)+ALFGR
          PHIS0W(IL,L,IS)=PHIS0W(IL,L,IS)+ALFGR
          FGR3I=1./FGR**3
          WETDN(IL,L,IS)=DNH2O*(1.-FGR3I)+DRYDN(IL,L,IS)*FGR3I
        ENDIF
      ENDDO
      ENDDO
      ENDDO
!
!     * MOMENTS OF THE SIZE DISTRIBUTION.
!
      AM0=PN0*SDINT0(PHI0W,PSI,PHIS0W,DPHI0,ILGA,LEVA,ISEC)
      RMOM=1.
      AM1=PN0*SDINT (PHI0W,PSI,RMOM,PHIS0W,DPHI0,ILGA,LEVA,ISEC)
      RMOM=2.
      AM2=PN0*SDINT (PHI0W,PSI,RMOM,PHIS0W,DPHI0,ILGA,LEVA,ISEC)
      RMOM=3.
      AM3=PN0*SDINT (PHI0W,PSI,RMOM,PHIS0W,DPHI0,ILGA,LEVA,ISEC)
      RMOM=4.
      AM4=PN0*SDINT (PHI0W,PSI,RMOM,PHIS0W,DPHI0,ILGA,LEVA,ISEC)
!
!     * INTEGRATE MOMENTS OVER SIZE DISTRIBUTION.
!
      TAM0=0.
      TAM2=0.
      TAM3=0.
      TAM4=0.
      ALD=0.
      DO IS=1,ISEC
        TAM0=TAM0+AM0(:,:,IS)
        TAM2=TAM2+AM2(:,:,IS)
        TAM3=TAM3+AM3(:,:,IS)
        TAM4=TAM4+AM4(:,:,IS)
        ALD=ALD+YCNST*WETDN(:,:,IS)*AM3(:,:,IS)
      ENDDO
!
!     * EFFECTIVE RADIUS AND VARIANCE.
!
      WHERE ( TAM0 > 100. )
        WHERE ( TAM3 > YTINY .AND. TAM2 > YTINY )
          RE=TAM3/TAM2
        ENDWHERE
        WHERE ( TAM2 > YTINY .AND. TAM3**2 > YTINY .AND. TAM4 > YTINY )
          VE=TAM2*TAM4/TAM3**2-1.
        ENDWHERE
      ELSEWHERE
        RE=0.
        VE=0.
        ALD=0.
      ENDWHERE
!
!     * DEALLOCATE MEMORY.
!
      DEALLOCATE(PHIS0W)
      DEALLOCATE(PHI0W )
      DEALLOCATE(WETDN )
      DEALLOCATE(AM0  )
      DEALLOCATE(AM1  )
      DEALLOCATE(AM2  )
      DEALLOCATE(AM3  )
      DEALLOCATE(AM4  )
      DEALLOCATE(TAM0 )
      DEALLOCATE(TAM2 )
      DEALLOCATE(TAM3 )
      DEALLOCATE(TAM4 )
!
      END SUBROUTINE EFFRV
