      SUBROUTINE SDDENS(PIDDN,PIFRC,ILGA,LEVA)
!-----------------------------------------------------------------------
!     PURPOSE:
!     --------
!     CALCULATION OF DRY AEROSOL DENSITY FOR INTERNALLY MIXED AEROSOL.
!
!     HISTORY:
!     --------
!     * APR 07/2006 - K.VONSALZEN   NEW.
!
!     ************************ INDEX OF VARIABLES **********************
!
!     PRIMARY INPUT/OUTPUT VARIABLES (ARGUMENT LIST):
!
! I   ILGA     NUMBER OF GRID POINTS IN HORIZONTAL DIRECTION
! I   LEVA     NUMBER OF GRID POINTA IN VERTICAL DIRECTION
! I   PIFRC    AEROSOL SPECIES MASS FRACTION
! O   PIDDN    DENSITY OF DRY AEROSOL PARTICLE (KG/M3), INT. MIXTURE
!
!     SECONDARY INPUT/OUTPUT VARIABLES (VIA MODULES AND COMMON BLOCKS):
!
! I   AINTF%TP(:)%DENS
!              DRY PARTICLE DENSITY (KG/M3), INT. MIXTURE
! I   ISAINT   NUMBER OF AEROSOL TRACERS, INT. MIXTURE
! I   KINT     NUMBER OF INTERNALLY MIXED AEROSOL TYPES, INT. MIXTURE
! I   SINTF%ISAER(:)%ISI
!              AEROSOL TRACER INDEX, INT. MIXTURE
! I   SINTF%ISAER(:)%ITYP(:)
!              AEROSOL TYPE INDEX, INT. MIXTURE
! I   SINTF%ISAER(:)%ITYPT
!              NUMBER OF AEROSOL TYPES, INT. MIXTURE
! I   YTINY    SMALLEST VALID NUMBER
!
!-----------------------------------------------------------------------
!
      USE SDPARM
!
      IMPLICIT REAL (A-H,O-Z), INTEGER (I-N)
!
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA,ISAINT,KINT) :: PIFRC
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA,ISAINT) :: PIDDN
      INTEGER, INTENT(IN) :: ILGA,LEVA
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: DM0,DV0
!
!-----------------------------------------------------------------------
!
      IF ( ISAINT > 0 ) THEN
!
!       * ALLOCATE AND INITIALIZE WORK ARRAYS.
!
        ALLOCATE(DM0(ILGA,LEVA,ISAINT))
        ALLOCATE(DV0(ILGA,LEVA,ISAINT))
        DM0=0.
        DV0=0.
!
!       * AEROSOL MASSES AND VOLUMES IN EACH SECTION.
!
        DO IS=1,ISAINT
          DO KXT=1,SINTF%ISAER(IS)%ITYPT
            KX=SINTF%ISAER(IS)%ITYP(KXT)
            ISI=SINTF%ISAER(IS)%ISI
            DM0(:,:,IS)=DM0(:,:,IS)+PIFRC(:,:,ISI,KX)
            DV0(:,:,IS)=DV0(:,:,IS)+PIFRC(:,:,ISI,KX)/AINTF%TP(KX)%DENS
          ENDDO
        ENDDO
        PIDDN=YNA
        WHERE ( DV0 > MAX(DM0/YLARGE,YTINY) )
          PIDDN=DM0/DV0
        ENDWHERE
!
!       * DEALLOCATE WORK ARRAYS.
!
        DEALLOCATE(DM0)
        DEALLOCATE(DV0)
      ENDIF
!
      END SUBROUTINE SDDENS
