SUBROUTINE CMIP5_AEROSOLS

!     PURPOSE.
!     --------
!     Read aerosol fields for CMIP5 runs, interpolate in time
!     horizontal and vertical interp is done in radact
!
!     all concentrations are given as mixing ratios in kg/kg
!     IPCC_SO4   :   sulfate
!     IPCC_SOA   :   secondary organic aerosols
!     IPCC_OCx   :   organic matter (carbon content) (hydrophobic and -phylic)
!     IPCC_BCx   :   black carbon (hydrophobic and -phylic)
!     IPCC_DSTx  :   desert dust (4 size classes)
!     IPCC_SSLTx :   sea-salt (4 size classes)
!
!     IPCC_LEV   :   pressure on CAM model levels (Pa)
!
!
!     INTERFACE.
!     ----------
!     CALL *CMIP5_AEROSOLS* FROM *UPDTIM*

!     AUTHOR.
!     -------
!     K. Wyser for EC-EARTH 2/3/2011
!     Based on IPCC_Sulfate from v2

!     MODIFICATIONS.
!     --------------
!     T. Semmler 16-03-2011
!     Added DD and SS aerosols from CAM

!---------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMLUN    ,ONLY : NULOUT
USE YOERAD    ,ONLY : NRCP, NCMIPFIXYR, CMIP5DATADIR, &
 &                    IPCC_NMON, IPCC_NLON, IPCC_NLAT, IPCC_NLEV, &
 &                    IPCC_LON, IPCC_LAT, IPCC_LEV, IPCC_SO4 &
 &                    ,IPCC_SOA ,IPCC_OC1 ,IPCC_OC2 ,IPCC_BC1 ,IPCC_BC2 &
 &                    ,IPCC_DST1, IPCC_DST2, IPCC_DST3, IPCC_DST4 &
 &                    ,IPCC_SSLT1, IPCC_SSLT2, IPCC_SSLT3, IPCC_SSLT4
USE YOMRIP    ,ONLY : NINDAT, NSTADD
USE YOMCST    ,ONLY : RPI

USE YOMMP      ,ONLY : MYPROC
USE MPL_MODULE ,ONLY : MPL_BROADCAST


IMPLICIT NONE

REAL(KIND=JPRB)              :: ZHOOK_HANDLE

! define local arrays for forcing fields
REAL(KIND=JPRB)              :: LON1(IPCC_NLON),LON2(IPCC_NLON)
REAL(KIND=JPRB)              :: LAT1(IPCC_NLAT),LAT2(IPCC_NLAT)
REAL(KIND=JPRB),DIMENSION(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT) :: &
    & LEV1,LEV2,SO41,SO42,SOA1,SOA2,OC11,OC12,OC21,OC22,BC11,BC12,BC21,BC22 &
    & ,DST11,DST12,DST21,DST22,DST31,DST32,DST41,DST42 &
    & ,SSLT11,SSLT12,SSLT21,SSLT22,SSLT31,SSLT32,SSLT41,SSLT42
REAL(KIND=JPRB),DIMENSION(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT) :: &
    & LEV,SO4,SOA,OC1,OC2,BC1,BC2,DST1,DST2,DST3,DST4,SSLT1,SSLT2,SSLT3,SSLT4
REAL(KIND=JPRB),DIMENSION(IPCC_NMON*IPCC_NLEV*IPCC_NLON*IPCC_NLAT) :: &
    & LEV_BUF,SO4_BUF,SOA_BUF,OC1_BUF,OC2_BUF,BC1_BUF,BC2_BUF &
    & ,DST1_BUF,DST2_BUF,DST3_BUF,DST4_BUF &
    & ,SSLT1_BUF,SSLT2_BUF,SSLT3_BUF,SSLT4_BUF
REAL(KIND=JPRB)              :: ZYRI

INTEGER(KIND=JPIM)           :: ILAT, ILON, IMONTH, ILEV
INTEGER(KIND=JPIM)           :: IJ0, IM0, IA0, IDAY, IMON, IMODYR, ILMOIS(12)
INTEGER(KIND=JPIM)           :: IAERINPUT1,IAERINPUT2
INTEGER(KIND=JPIM),SAVE      :: IYROLD=-999,IMONOLD=-999

INTEGER ,PARAMETER :: RPRC=1,ITAG=23456

#include "netcdf.inc"
#include "abor1.intfb.h"
#include "updcal.intfb.h"
#include "fcttim.h"

IF (LHOOK) CALL DR_HOOK('CMIP5_AEROSOLS',0,ZHOOK_HANDLE)

WRITE(NULOUT,*)'Entering Subroutine CMIP5_AEROSOLS'


IJ0=NDD(NINDAT)
IM0=NMM(NINDAT)
IA0=NCCAA(NINDAT)
CALL UPDCAL(IJ0,IM0,IA0,NSTADD,IDAY,IMON,IMODYR,ILMOIS,NULOUT)
IF (NCMIPFIXYR>0) IMODYR=NCMIPFIXYR

!IF(IMODYR/=IYROLD) THEN
!  IYROLD=IMODYR
IF (IMON/=IMONOLD) THEN
  IMONOLD=IMON

  IF (MYPROC==RPRC) THEN
    ! read 2 files
    IAERINPUT1=MIN(2100,MAX(1850,10*INT((IMODYR-5)/10)))
    IAERINPUT2=MIN(2100,MAX(1850,10*INT((IMODYR+5)/10)))
    CALL READ_NC_FILE(IAERINPUT1,LON1,LAT1,LEV1,SO41,SOA1,OC11,OC21,BC11,BC21,DST11,DST21,DST31,DST41,SSLT11,SSLT21,SSLT31,SSLT41)
    CALL READ_NC_FILE(IAERINPUT2,LON2,LAT2,LEV2,SO42,SOA2,OC12,OC22,BC12,BC22,DST12,DST22,DST32,DST42,SSLT12,SSLT22,SSLT32,SSLT42)

    IPCC_LAT=LAT1*RPI/180.0_JPRB
    IPCC_LON=LON1*RPI/180.0_JPRB

    WRITE(NULOUT,*)'Data ranges'
    WRITE(NULOUT,*)'SO41: ',MinVal(SO41),MaxVal(SO41)
    WRITE(NULOUT,*)'SO42: ',MinVal(SO42),MaxVal(SO42)
    WRITE(NULOUT,*)'LEV1: ',MinVal(LEV1),MaxVal(LEV1)
    WRITE(NULOUT,*)'LEV2: ',MinVal(LEV2),MaxVal(LEV2)

    ! Time interpolation to the current year

    WRITE(NULOUT,'(" IAERINPUT1=",I4," IMODYR=",I4)') IAERINPUT1,IMODYR
    ZYRI=(IMODYR-IAERINPUT1-5)/10.0_JPRB
    WRITE(NULOUT,*)'ZYRI = ',ZYRI

    SO4=SO41+ZYRI*(SO42-SO41)
    WRITE(NULOUT,*)'SO4: ',MinVal(SO4),MaxVal(SO4)

    SOA=SOA1+ZYRI*(SOA2-SOA1)
    OC1=OC11+ZYRI*(OC12-OC11)
    OC2=OC21+ZYRI*(OC22-OC21)
    BC1=BC11+ZYRI*(BC12-BC11)
    BC2=BC21+ZYRI*(BC22-BC21)
    DST1=DST11+ZYRI*(DST12-DST11)
    DST2=DST21+ZYRI*(DST22-DST21)
    DST3=DST31+ZYRI*(DST32-DST31)
    DST4=DST41+ZYRI*(DST42-DST41)
    SSLT1=SSLT11+ZYRI*(SSLT12-SSLT11)
    SSLT2=SSLT21+ZYRI*(SSLT22-SSLT21)
    SSLT3=SSLT31+ZYRI*(SSLT32-SSLT31)
    SSLT4=SSLT41+ZYRI*(SSLT42-SSLT41)

    LEV=LEV1+ZYRI*(LEV2-LEV1)
    WRITE(NULOUT,*)'LEV: ',MinVal(LEV),MaxVal(LEV)

    SO4_BUF=RESHAPE(SO4,SHAPE(SO4_BUF))
    SOA_BUF=RESHAPE(SOA,SHAPE(SOA_BUF))
    OC1_BUF=RESHAPE(OC1,SHAPE(OC1_BUF))
    OC2_BUF=RESHAPE(OC2,SHAPE(OC2_BUF))
    BC1_BUF=RESHAPE(BC1,SHAPE(BC1_BUF))
    BC2_BUF=RESHAPE(BC2,SHAPE(BC2_BUF))
    DST1_BUF=RESHAPE(DST1,SHAPE(DST1_BUF))
    DST2_BUF=RESHAPE(DST2,SHAPE(DST2_BUF))
    DST3_BUF=RESHAPE(DST3,SHAPE(DST3_BUF))
    DST4_BUF=RESHAPE(DST4,SHAPE(DST4_BUF))
    SSLT1_BUF=RESHAPE(SSLT1,SHAPE(SSLT1_BUF))
    SSLT2_BUF=RESHAPE(SSLT2,SHAPE(SSLT2_BUF))
    SSLT3_BUF=RESHAPE(SSLT3,SHAPE(SSLT3_BUF))
    SSLT4_BUF=RESHAPE(SSLT4,SHAPE(SSLT4_BUF))
    LEV_BUF=RESHAPE(LEV,SHAPE(LEV_BUF))
  ENDIF
  ! distribute to all PROCS
  CALL MPL_BROADCAST(IPCC_LAT,KTAG=ITAG+1,KROOT=RPRC,CDSTRING='CMIP5AERO-1: ')
  CALL MPL_BROADCAST(IPCC_LON,KTAG=ITAG+2,KROOT=RPRC,CDSTRING='CMIP5AERO-2: ')

  CALL MPL_BROADCAST(LEV_BUF,KTAG=ITAG+3,KROOT=RPRC,CDSTRING='CMIP5AERO-3: ')
  IPCC_LEV=RESHAPE(LEV_BUF,SHAPE(IPCC_LEV))

  CALL MPL_BROADCAST(SO4_BUF,KTAG=ITAG+4,KROOT=RPRC,CDSTRING='CMIP5AERO-4: ')
  IPCC_SO4=RESHAPE(SO4_BUF,SHAPE(IPCC_SO4))

  CALL MPL_BROADCAST(SOA_BUF,KTAG=ITAG+5,KROOT=RPRC,CDSTRING='CMIP5AERO-5: ')
  IPCC_SOA=RESHAPE(SOA_BUF,SHAPE(IPCC_SOA))

  CALL MPL_BROADCAST(OC1_BUF,KTAG=ITAG+6,KROOT=RPRC,CDSTRING='CMIP5AERO-6: ')
  IPCC_OC1=RESHAPE(OC1_BUF,SHAPE(IPCC_OC1))
  CALL MPL_BROADCAST(OC2_BUF,KTAG=ITAG+7,KROOT=RPRC,CDSTRING='CMIP5AERO-7: ')
  IPCC_OC2=RESHAPE(OC2_BUF,SHAPE(IPCC_OC2))

  CALL MPL_BROADCAST(BC1_BUF,KTAG=ITAG+8,KROOT=RPRC,CDSTRING='CMIP5AERO-8: ')
  IPCC_BC1=RESHAPE(BC1_BUF,SHAPE(IPCC_BC1))
  CALL MPL_BROADCAST(BC2_BUF,KTAG=ITAG+9,KROOT=RPRC,CDSTRING='CMIP5AERO-9: ')
  IPCC_BC2=RESHAPE(BC2_BUF,SHAPE(IPCC_BC2))

  CALL MPL_BROADCAST(DST1_BUF,KTAG=ITAG+10,KROOT=RPRC,CDSTRING='CMIP5AERO-10: ')
  IPCC_DST1=RESHAPE(DST1_BUF,SHAPE(IPCC_DST1))
  CALL MPL_BROADCAST(DST2_BUF,KTAG=ITAG+11,KROOT=RPRC,CDSTRING='CMIP5AERO-11: ')
  IPCC_DST2=RESHAPE(DST2_BUF,SHAPE(IPCC_DST2))
  CALL MPL_BROADCAST(DST3_BUF,KTAG=ITAG+12,KROOT=RPRC,CDSTRING='CMIP5AERO-12: ')
  IPCC_DST3=RESHAPE(DST3_BUF,SHAPE(IPCC_DST3))
  CALL MPL_BROADCAST(DST4_BUF,KTAG=ITAG+13,KROOT=RPRC,CDSTRING='CMIP5AERO-13: ')
  IPCC_DST4=RESHAPE(DST4_BUF,SHAPE(IPCC_DST4))

  CALL MPL_BROADCAST(SSLT1_BUF,KTAG=ITAG+14,KROOT=RPRC,CDSTRING='CMIP5AERO-14: ')
  IPCC_SSLT1=RESHAPE(SSLT1_BUF,SHAPE(IPCC_SSLT1))
  CALL MPL_BROADCAST(SSLT2_BUF,KTAG=ITAG+15,KROOT=RPRC,CDSTRING='CMIP5AERO-15: ')
  IPCC_SSLT2=RESHAPE(SSLT2_BUF,SHAPE(IPCC_SSLT2))
  CALL MPL_BROADCAST(SSLT3_BUF,KTAG=ITAG+16,KROOT=RPRC,CDSTRING='CMIP5AERO-16: ')
  IPCC_SSLT3=RESHAPE(SSLT3_BUF,SHAPE(IPCC_SSLT3))
  CALL MPL_BROADCAST(SSLT4_BUF,KTAG=ITAG+17,KROOT=RPRC,CDSTRING='CMIP5AERO-17: ')
  IPCC_SSLT4=RESHAPE(SSLT4_BUF,SHAPE(IPCC_SSLT4))
ELSE
  WRITE(NULOUT,*)'Same month -> nothing to update '
ENDIF

WRITE(NULOUT,*)'Leaving Subroutine CMIP5_AEROSOLS'

IF (LHOOK) CALL DR_HOOK('CMIP5_AEROSOLS',1,ZHOOK_HANDLE)

CONTAINS

  SUBROUTINE READ_NC_FILE(IYR,LON,LAT,LEVX,SO4X,SOAX,OC1X,OC2X,BC1X,BC2X,DST1X,DST2X,DST3X,DST4X,SSLT1X,SSLT2X,SSLT3X,SSLT4X)

    INTEGER(KIND=JPIM),INTENT(IN):: IYR
    REAL(KIND=JPRB),INTENT(OUT):: LAT(IPCC_NLAT), LON(IPCC_NLON)
    REAL(KIND=JPRB),INTENT(OUT):: LEVX(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: SO4X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: SOAX(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: OC1X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: OC2X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: BC1X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: BC2X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: DST1X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: DST2X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: DST3X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: DST4X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: SSLT1X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: SSLT2X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: SSLT3X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)
    REAL(KIND=JPRB),INTENT(OUT):: SSLT4X(IPCC_NMON,IPCC_NLEV,IPCC_NLON,IPCC_NLAT)

    CHARACTER(LEN=32)            :: CC
    CHARACTER(LEN=256)           :: CAERINPUT
    INTEGER                      :: IUNIT

    CHARACTER (LEN=*), PARAMETER :: LAT_NAME='lat'
    CHARACTER (LEN=*), PARAMETER :: LON_NAME='lon'
    INTEGER :: LAT_VARID, LON_VARID

    CHARACTER (LEN=*), PARAMETER :: HYAM_NAME='hyam'
    CHARACTER (LEN=*), PARAMETER :: HYBM_NAME='hybm'
    REAL(KIND=JPRB) :: HYAM(IPCC_NLEV), HYBM(IPCC_NLEV)
    INTEGER :: HYAM_VARID, HYBM_VARID

    CHARACTER (LEN=*), PARAMETER :: PS_NAME='PS'
    INTEGER :: PS_VARID
    REAL(KIND=JPRB) :: PS(IPCC_NLON,IPCC_NLAT,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: SO4_NAME='SO4'
    INTEGER :: SO4_VARID
    REAL(KIND=JPRB) :: SO4_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: SOA_NAME='SOA'
    INTEGER :: SOA_VARID
    REAL(KIND=JPRB) :: SOA_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: OC1_NAME='OC1'
    INTEGER :: OC1_VARID
    REAL(KIND=JPRB) :: OC1_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: OC2_NAME='OC2'
    INTEGER :: OC2_VARID
    REAL(KIND=JPRB) :: OC2_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: BC1_NAME='CB1'
    INTEGER :: BC1_VARID
    REAL(KIND=JPRB) :: BC1_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: BC2_NAME='CB2'
    INTEGER :: BC2_VARID
    REAL(KIND=JPRB) :: BC2_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: DST1_NAME='DST01'
    INTEGER :: DST1_VARID
    REAL(KIND=JPRB) :: DST1_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: DST2_NAME='DST02'
    INTEGER :: DST2_VARID
    REAL(KIND=JPRB) :: DST2_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: DST3_NAME='DST03'
    INTEGER :: DST3_VARID
    REAL(KIND=JPRB) :: DST3_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: DST4_NAME='DST04'
    INTEGER :: DST4_VARID
    REAL(KIND=JPRB) :: DST4_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: SSLT1_NAME='SSLT01'
    INTEGER :: SSLT1_VARID
    REAL(KIND=JPRB) :: SSLT1_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: SSLT2_NAME='SSLT02'
    INTEGER :: SSLT2_VARID
    REAL(KIND=JPRB) :: SSLT2_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: SSLT3_NAME='SSLT03'
    INTEGER :: SSLT3_VARID
    REAL(KIND=JPRB) :: SSLT3_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: SSLT4_NAME='SSLT04'
    INTEGER :: SSLT4_VARID
    REAL(KIND=JPRB) :: SSLT4_CAM(IPCC_NLON,IPCC_NLAT,IPCC_NLEV,IPCC_NMON)

    CHARACTER (LEN=*), PARAMETER :: P0_NAME='P0'
    INTEGER :: P0_VARID
    REAL(KIND=JPRB) :: P0

    SELECT CASE (NRCP)
    CASE (0)
       CC='histo/aero_1.9x2.5_L26_'
    CASE (1)
       CC='rcp26/aero_1.9x2.5_L26_'
    CASE (2)
       CC='rcp45/aero_1.9x2.5_L26_'
    CASE (3)
       CC='rcp60/aero_1.9x2.5_L26_'
    CASE (4)
       CC='rcp85/aero_1.9x2.5_L26_'
    END SELECT

    WRITE(CAERINPUT,'(A,I4,A,I4,A)') TRIM(CMIP5DATADIR)//'/' &
                                     & //TRIM(CC),IYR,'-',IYR+9,'.nc'
    WRITE(NULOUT,*) 'CAERINPUT: ',TRIM(CAERINPUT)

    ! OPEN NETCDF FILE
    CALL CHECK( NF_OPEN(CAERINPUT,NF_NOWRITE,IUNIT) )

    ! READ LAT/LON
    CALL CHECK( NF_INQ_VARID(IUNIT, LAT_NAME, LAT_VARID) )
    CALL CHECK( NF_INQ_VARID(IUNIT, LON_NAME, LON_VARID) )
    CALL CHECK( NF_GET_VAR_DOUBLE(IUNIT, LAT_VARID, LAT) )
    CALL CHECK( NF_GET_VAR_DOUBLE(IUNIT, LON_VARID, LON) )

    ! READ P0
    CALL CHECK( NF_INQ_VARID(IUNIT, P0_NAME, P0_VARID) )
    CALL CHECK( NF_GET_VAR_DOUBLE(IUNIT, P0_VARID, P0) )

    ! READ HYAM/HYBM
    CALL CHECK( NF_INQ_VARID(IUNIT, HYAM_NAME, HYAM_VARID) )
    CALL CHECK( NF_INQ_VARID(IUNIT, HYBM_NAME, HYBM_VARID) )
    CALL CHECK( NF_GET_VAR_DOUBLE(IUNIT, HYAM_VARID, HYAM) )
    CALL CHECK( NF_GET_VAR_DOUBLE(IUNIT, HYBM_VARID, HYBM) )
  
    ! READ 3-D FIELDS
    CALL CHECK( NF_INQ_VARID(IUNIT, PS_NAME, PS_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, PS_VARID,   &
         & (/1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,1/), PS) )

    CALL CHECK( NF_INQ_VARID(IUNIT, SO4_NAME, SO4_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, SO4_VARID,  &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), SO4_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, SOA_NAME, SOA_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, SOA_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), SOA_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, OC1_NAME, OC1_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, OC1_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), OC1_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, OC2_NAME, OC2_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, OC2_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), OC2_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, BC1_NAME, BC1_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, BC1_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), BC1_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, BC2_NAME, BC2_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, BC2_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), BC2_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, DST1_NAME, DST1_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, DST1_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), DST1_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, DST2_NAME, DST2_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, DST2_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), DST2_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, DST3_NAME, DST3_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, DST3_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), DST3_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, DST4_NAME, DST4_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, DST4_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), DST4_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, SSLT1_NAME, SSLT1_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, SSLT1_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), SSLT1_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, SSLT2_NAME, SSLT2_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, SSLT2_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), SSLT2_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, SSLT3_NAME, SSLT3_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, SSLT3_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), SSLT3_CAM) )

    CALL CHECK( NF_INQ_VARID(IUNIT, SSLT4_NAME, SSLT4_VARID) )
    CALL CHECK( NF_GET_VARA_DOUBLE(IUNIT, SSLT4_VARID, &
         & (/1,1,1,IMON/), (/IPCC_NLON,IPCC_NLAT,IPCC_NLEV,1/), SSLT4_CAM) )

    ! CLOSE NETCDF FILE
    CALL CHECK( NF_CLOSE(IUNIT) )

    DO IMONTH=1,IPCC_NMON
      DO ILEV=1,IPCC_NLEV
        DO ILAT=1,IPCC_NLAT
          DO ILON=1,IPCC_NLON
            LEVX(IMONTH,ILEV,ILON,ILAT)=HYAM(ILEV)*P0 &
                                     &  + HYBM(ILEV)*PS(ILON,ILAT,IMONTH)
            SO4X(IMONTH,ILEV,ILON,ILAT)=SO4_CAM(ILON,ILAT,ILEV,IMONTH)
            SOAX(IMONTH,ILEV,ILON,ILAT)=SOA_CAM(ILON,ILAT,ILEV,IMONTH)
            OC1X(IMONTH,ILEV,ILON,ILAT)=OC1_CAM(ILON,ILAT,ILEV,IMONTH)
            OC2X(IMONTH,ILEV,ILON,ILAT)=OC2_CAM(ILON,ILAT,ILEV,IMONTH)
            BC1X(IMONTH,ILEV,ILON,ILAT)=BC1_CAM(ILON,ILAT,ILEV,IMONTH)
            BC2X(IMONTH,ILEV,ILON,ILAT)=BC2_CAM(ILON,ILAT,ILEV,IMONTH)
            DST1X(IMONTH,ILEV,ILON,ILAT)=DST1_CAM(ILON,ILAT,ILEV,IMONTH)
            DST2X(IMONTH,ILEV,ILON,ILAT)=DST2_CAM(ILON,ILAT,ILEV,IMONTH)
            DST3X(IMONTH,ILEV,ILON,ILAT)=DST3_CAM(ILON,ILAT,ILEV,IMONTH)
            DST4X(IMONTH,ILEV,ILON,ILAT)=DST4_CAM(ILON,ILAT,ILEV,IMONTH)
            SSLT1X(IMONTH,ILEV,ILON,ILAT)=SSLT1_CAM(ILON,ILAT,ILEV,IMONTH)
            SSLT2X(IMONTH,ILEV,ILON,ILAT)=SSLT2_CAM(ILON,ILAT,ILEV,IMONTH)
            SSLT3X(IMONTH,ILEV,ILON,ILAT)=SSLT3_CAM(ILON,ILAT,ILEV,IMONTH)
            SSLT4X(IMONTH,ILEV,ILON,ILAT)=SSLT4_CAM(ILON,ILAT,ILEV,IMONTH)
          ENDDO
        ENDDO
      ENDDO
    ENDDO
  END SUBROUTINE READ_NC_FILE

  SUBROUTINE CHECK(STATUS)
    INTEGER, INTENT ( IN) :: STATUS

    IF(STATUS /= NF_NOERR) THEN
      CALL ABOR1('CMIP5_AEROSOLS: '//TRIM(NF_STRERROR(STATUS)))
    END IF
  END SUBROUTINE CHECK

END SUBROUTINE CMIP5_AEROSOLS
