Index: /trunk/LMDZ.GENERIC/deftank/callphys.GJ581d
===================================================================
--- /trunk/LMDZ.GENERIC/deftank/callphys.GJ581d	(revision 2971)
+++ /trunk/LMDZ.GENERIC/deftank/callphys.GJ581d	(revision 2972)
@@ -97,4 +97,6 @@
 ## Tracer and aerosol options 
 ## ~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Number of radiatively active aerosols
+naerkind=1
 # Radiatively active CO2 aerosol?
 aeroco2       = .true.
Index: /trunk/LMDZ.GENERIC/deftank/callphys.earlymars
===================================================================
--- /trunk/LMDZ.GENERIC/deftank/callphys.earlymars	(revision 2971)
+++ /trunk/LMDZ.GENERIC/deftank/callphys.earlymars	(revision 2972)
@@ -75,4 +75,5 @@
 sedimentation = .false.
 
+
 ## Other physics options
 ## ~~~~~~~~~~~~~~~~~~~~~
@@ -92,4 +93,6 @@
 ## Tracer and aerosol options 
 ## ~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Number of radiatively active aerosols
+naerkind=2
 # Radiatively active CO2 aerosol?
 aeroco2       = .true.
Index: /trunk/LMDZ.GENERIC/deftank/callphys.earth
===================================================================
--- /trunk/LMDZ.GENERIC/deftank/callphys.earth	(revision 2971)
+++ /trunk/LMDZ.GENERIC/deftank/callphys.earth	(revision 2972)
@@ -91,4 +91,6 @@
 ## Tracer and aerosol options 
 ## ~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Number of radiatively active aerosols
+naerkind=1
 # Radiatively active CO2 aerosol?
 aeroco2       = .false.
Index: /trunk/LMDZ.GENERIC/deftank/callphys.kcm1d
===================================================================
--- /trunk/LMDZ.GENERIC/deftank/callphys.kcm1d	(revision 2971)
+++ /trunk/LMDZ.GENERIC/deftank/callphys.kcm1d	(revision 2972)
@@ -64,4 +64,6 @@
 ## Tracer and aerosol options 
 ## ~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Number of radiatively active aerosols
+naerkind=0
 # Fixed aerosol distributions?
 aerofixed     = .true.
Index: /trunk/LMDZ.GENERIC/libf/phystd/aeroptproperties.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/aeroptproperties.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/aeroptproperties.F90	(revision 2972)
@@ -44,5 +44,5 @@
 
 !     =============================================================
-      LOGICAL, PARAMETER :: varyingnueff(naerkind) = .false.
+!      LOGICAL, PARAMETER :: varyingnueff(naerkind) = .false. ! not used!
 !     =============================================================
 
@@ -105,67 +105,68 @@
       REAL,SAVE :: logvratgrid,vratgrid
 !     Grid used to remember which calculation is done
-      LOGICAL,SAVE :: checkgrid(refftabsize,nuefftabsize,naerkind,2) = .false.
+      LOGICAL,SAVE,ALLOCATABLE :: checkgrid(:,:,:,:)
 !$OMP THREADPRIVATE(refftab,nuefftab,logvratgrid,vratgrid,checkgrid)
 !     Optical properties of the grid (VISIBLE)
-      REAL,SAVE :: qsqrefVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind)
-      REAL,SAVE :: qextVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind)
-      REAL,SAVE :: qscatVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind)
-      REAL,SAVE :: omegVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind)
-      REAL,SAVE :: gVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind)
+      REAL,SAVE,ALLOCATABLE :: qsqrefVISgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qextVISgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qscatVISgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegVISgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: gVISgrid(:,:,:,:)
 !$OMP THREADPRIVATE(qsqrefVISgrid,qextVISgrid,qscatVISgrid,omegVISgrid,gVISgrid)
 !     Optical properties of the grid (INFRARED)
-      REAL,SAVE :: qsqrefIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind)
-      REAL,SAVE :: qextIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind)
-      REAL,SAVE :: qscatIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind)
-      REAL,SAVE :: omegIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind)
-      REAL,SAVE :: gIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind)
+      REAL,SAVE,ALLOCATABLE :: qsqrefIRgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qextIRgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qscatIRgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegIRgrid(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: gIRgrid(:,:,:,:)
 !$OMP THREADPRIVATE(qsqrefIRgrid,qextIRgrid,qscatIRgrid,omegIRgrid,gIRgrid)
 !     Optical properties of the grid (REFERENCE WAVELENGTHS)
-      REAL,SAVE :: qrefVISgrid(refftabsize,nuefftabsize,naerkind)
-      REAL,SAVE :: qscatrefVISgrid(refftabsize,nuefftabsize,naerkind)
-      REAL,SAVE :: qrefIRgrid(refftabsize,nuefftabsize,naerkind)
-      REAL,SAVE :: qscatrefIRgrid(refftabsize,nuefftabsize,naerkind)
-      REAL,SAVE :: omegrefVISgrid(refftabsize,nuefftabsize,naerkind)
-      REAL,SAVE :: omegrefIRgrid(refftabsize,nuefftabsize,naerkind)
+      REAL,SAVE,ALLOCATABLE :: qrefVISgrid(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qscatrefVISgrid(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qrefIRgrid(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qscatrefIRgrid(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegrefVISgrid(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegrefIRgrid(:,:,:)
 !$OMP THREADPRIVATE(qrefVISgrid,qscatrefVISgrid,qrefIRgrid,qscatrefIRgrid,omegrefVISgrid,&
-	!$OMP omegrefIRgrid)
+!$OMP omegrefIRgrid)
 !     Firstcall
       LOGICAL,SAVE :: firstcall = .true.
-!$OMP THREADPRIVATE(firstcall)
+      LOGICAL,SAVE :: first_allocate=.true.
+!$OMP THREADPRIVATE(firstcall,first_allocate)
 !     Variables used by the Gauss-Legendre integration:
-      REAL,SAVE :: normd(refftabsize,nuefftabsize,naerkind,2)
-      REAL,SAVE :: dista(refftabsize,nuefftabsize,naerkind,2,ngau)
-      REAL,SAVE :: distb(refftabsize,nuefftabsize,naerkind,2,ngau)
+      REAL,SAVE,ALLOCATABLE :: normd(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: dista(:,:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: distb(:,:,:,:,:)
 !$OMP THREADPRIVATE(normd,dista,distb)
 
-      REAL,SAVE :: radGAUSa(ngau,naerkind,2)
-      REAL,SAVE :: radGAUSb(ngau,naerkind,2)
+      REAL,SAVE,ALLOCATABLE :: radGAUSa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: radGAUSb(:,:,:)
 !$OMP THREADPRIVATE(radGAUSa,radGAUSb)
 
-      REAL,SAVE :: qsqrefVISa(L_NSPECTV,ngau,naerkind)
-      REAL,SAVE :: qrefVISa(ngau,naerkind)
-      REAL,SAVE :: qsqrefVISb(L_NSPECTV,ngau,naerkind)
-      REAL,SAVE :: qrefVISb(ngau,naerkind)
-      REAL,SAVE :: omegVISa(L_NSPECTV,ngau,naerkind)
-      REAL,SAVE :: omegrefVISa(ngau,naerkind)
-      REAL,SAVE :: omegVISb(L_NSPECTV,ngau,naerkind)
-      REAL,SAVE :: omegrefVISb(ngau,naerkind)
-      REAL,SAVE :: gVISa(L_NSPECTV,ngau,naerkind)
-      REAL,SAVE :: gVISb(L_NSPECTV,ngau,naerkind)
-!$OMP THREADPRIVATE(qsqrefVISa,qrefVISa,qsqrefVISb,qrefVISb,omegVISa, &
-	!$OMP omegrefVISa,omegVISb,omegrefVISb,gVISa,gVISb)
-
-      REAL,SAVE :: qsqrefIRa(L_NSPECTI,ngau,naerkind)
-      REAL,SAVE :: qrefIRa(ngau,naerkind)
-      REAL,SAVE :: qsqrefIRb(L_NSPECTI,ngau,naerkind)
-      REAL,SAVE :: qrefIRb(ngau,naerkind)
-      REAL,SAVE :: omegIRa(L_NSPECTI,ngau,naerkind)
-      REAL,SAVE :: omegrefIRa(ngau,naerkind)
-      REAL,SAVE :: omegIRb(L_NSPECTI,ngau,naerkind)
-      REAL,SAVE :: omegrefIRb(ngau,naerkind)
-      REAL,SAVE :: gIRa(L_NSPECTI,ngau,naerkind)
-      REAL,SAVE :: gIRb(L_NSPECTI,ngau,naerkind)
-!$OMP THREADPRIVATE(qsqrefIRa,qrefIRa,qsqrefIRb,qrefIRb,omegIRa,omegrefIRa,&
-	!$OMP omegIRb,omegrefIRb,gIRa,gIRb)
+      REAL,SAVE,ALLOCATABLE :: qsqrefVISa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qrefVISa(:,:)
+      REAL,SAVE,ALLOCATABLE :: qsqrefVISb(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qrefVISb(:,:)
+!$OMP THREADPRIVATE(qsqrefVISa,qrefVISa,qsqrefVISb,qrefVISb)
+      REAL,SAVE,ALLOCATABLE :: omegVISa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegrefVISa(:,:)
+      REAL,SAVE,ALLOCATABLE :: omegVISb(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegrefVISb(:,:)
+      REAL,SAVE,ALLOCATABLE :: gVISa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: gVISb(:,:,:)
+!$OMP THREADPRIVATE(omegVISa,omegrefVISa,omegVISb,omegrefVISb,gVISa,gVISb)
+
+      REAL,SAVE,ALLOCATABLE :: qsqrefIRa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qrefIRa(:,:)
+      REAL,SAVE,ALLOCATABLE :: qsqrefIRb(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: qrefIRb(:,:)
+!$OMP THREADPRIVATE(qsqrefIRa,qrefIRa,qsqrefIRb,qrefIRb)
+      REAL,SAVE,ALLOCATABLE :: omegIRa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegrefIRa(:,:)
+      REAL,SAVE,ALLOCATABLE :: omegIRb(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegrefIRb(:,:)
+      REAL,SAVE,ALLOCATABLE :: gIRa(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: gIRb(:,:,:)
+!$OMP THREADPRIVATE(omegIRa,omegrefIRa,omegIRb,omegrefIRb,gIRa,gIRb)
 
       REAL :: radiusm
@@ -197,4 +198,62 @@
 !      REAL :: omegaREFvis3d(ngrid,nlayer,naerkind)
 !      REAL :: omegaREFir3d(ngrid,nlayer,naerkind)
+
+!     0. Allocate local saved arrays at firstcall
+!     --------------------------------------------------
+      IF (first_allocate) THEN
+        ! Grid used to remember computations already done at previous calls
+        ALLOCATE(checkgrid(refftabsize,nuefftabsize,naerkind,2))
+        checkgrid(:,:,:,:)=.false.
+        ! Optical properties of the grid (VISIBLE)
+        ALLOCATE(qsqrefVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind))
+        ALLOCATE(qextVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind))
+        ALLOCATE(qscatVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind))
+        ALLOCATE(omegVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind))
+        ALLOCATE(gVISgrid(refftabsize,nuefftabsize,L_NSPECTV,naerkind))
+        ! Optical properties of the grid (INFRARED)
+        ALLOCATE(qsqrefIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind))
+        ALLOCATE(qextIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind))
+        ALLOCATE(qscatIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind))
+        ALLOCATE(omegIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind))
+        ALLOCATE(gIRgrid(refftabsize,nuefftabsize,L_NSPECTI,naerkind))
+        ! Optical properties of the grid (REFERENCE WAVELENGTHS)
+        ALLOCATE(qrefVISgrid(refftabsize,nuefftabsize,naerkind))
+        ALLOCATE(qscatrefVISgrid(refftabsize,nuefftabsize,naerkind))
+        ALLOCATE(qrefIRgrid(refftabsize,nuefftabsize,naerkind))
+        ALLOCATE(qscatrefIRgrid(refftabsize,nuefftabsize,naerkind))
+        ALLOCATE(omegrefVISgrid(refftabsize,nuefftabsize,naerkind))
+        ALLOCATE(omegrefIRgrid(refftabsize,nuefftabsize,naerkind))
+        ! Variables used by the Gauss-Legendre integration:
+        ALLOCATE(normd(refftabsize,nuefftabsize,naerkind,2))
+        ALLOCATE(dista(refftabsize,nuefftabsize,naerkind,2,ngau))
+        ALLOCATE(distb(refftabsize,nuefftabsize,naerkind,2,ngau))
+        ALLOCATE(radGAUSa(ngau,naerkind,2))
+        ALLOCATE(radGAUSb(ngau,naerkind,2))
+        !
+        ALLOCATE(qsqrefVISa(L_NSPECTV,ngau,naerkind))
+        ALLOCATE(qrefVISa(ngau,naerkind))
+        ALLOCATE(qsqrefVISb(L_NSPECTV,ngau,naerkind))
+        ALLOCATE(qrefVISb(ngau,naerkind))
+        ALLOCATE(omegVISa(L_NSPECTV,ngau,naerkind))
+        ALLOCATE(omegrefVISa(ngau,naerkind))
+        ALLOCATE(omegVISb(L_NSPECTV,ngau,naerkind))
+        ALLOCATE(omegrefVISb(ngau,naerkind))
+        ALLOCATE(gVISa(L_NSPECTV,ngau,naerkind))
+        ALLOCATE(gVISb(L_NSPECTV,ngau,naerkind))
+        !
+        ALLOCATE(qsqrefIRa(L_NSPECTI,ngau,naerkind))
+        ALLOCATE(qrefIRa(ngau,naerkind))
+        ALLOCATE(qsqrefIRb(L_NSPECTI,ngau,naerkind))
+        ALLOCATE(qrefIRb(ngau,naerkind))
+        
+        ALLOCATE(omegIRa(L_NSPECTI,ngau,naerkind))
+        ALLOCATE(omegrefIRa(ngau,naerkind))
+        ALLOCATE(omegIRb(L_NSPECTI,ngau,naerkind))
+        ALLOCATE(omegrefIRb(ngau,naerkind))
+        ALLOCATE(gIRa(L_NSPECTI,ngau,naerkind))
+        ALLOCATE(gIRb(L_NSPECTI,ngau,naerkind))
+        
+        first_allocate=.false.
+      ENDIF ! of IF (first_allocate)
 
       DO iaer = 1, naerkind ! Loop on aerosol kind
@@ -260,5 +319,5 @@
 
         firstcall = .false.
-      ENDIF
+      ENDIF ! of IF (firstcall)
 
 !       1.4 Radius middle point and range for Gauss integration
@@ -755,5 +814,4 @@
       ENDDO ! iaer (loop on aerosol kind)
 
-      RETURN
     END SUBROUTINE aeroptproperties
 
Index: /trunk/LMDZ.GENERIC/libf/phystd/aerosol_mod.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/aerosol_mod.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/aerosol_mod.F90	(revision 2972)
@@ -193,6 +193,8 @@
     if (is_master) then
       print*, 'Aerosols counted not equal to naerkind'
-      print*, 'Compile with tag -s',ia,'to run'
-      print*, 'or change options in callphys.def'
+      print*, 'set correct value for nearkind in callphys.def'
+      print*, 'which should be ',ia
+      print*, 'according to current options in callphys.def'
+      print*, 'or change/correct incompatible options there'
       print*, 'Abort in iniaerosol'
     endif
Index: /trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 2972)
@@ -117,11 +117,15 @@
       
 
-      ! Globally varying aerosol optical properties on GCM grid ; not needed everywhere so not in radcommon_h.   
-      REAL :: QVISsQREF3d(ngrid,nlayer,L_NSPECTV,naerkind)
-      REAL :: omegaVIS3d(ngrid,nlayer,L_NSPECTV,naerkind)
-      REAL :: gVIS3d(ngrid,nlayer,L_NSPECTV,naerkind)
-      REAL :: QIRsQREF3d(ngrid,nlayer,L_NSPECTI,naerkind)
-      REAL :: omegaIR3d(ngrid,nlayer,L_NSPECTI,naerkind)
-      REAL :: gIR3d(ngrid,nlayer,L_NSPECTI,naerkind)
+! Globally varying aerosol optical properties on GCM grid ; not needed everywhere so not in radcommon_h.   
+! made "save" variables so they are allocated once in for all, not because
+! the values need be saved from a time step to the next
+      REAL,SAVE,ALLOCATABLE :: QVISsQREF3d(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegaVIS3d(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: gVIS3d(:,:,:,:)
+!$OMP THREADPRIVATE(QVISsQREF3d,omegaVIS3d,gVIS3d)
+      REAL,SAVE,ALLOCATABLE :: QIRsQREF3d(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: omegaIR3d(:,:,:,:)
+      REAL,SAVE,ALLOCATABLE :: gIR3d(:,:,:,:)
+!$OMP THREADPRIVATE(QIRsQREF3d,omegaIR3d,gIR3d)
 
 !      REAL :: omegaREFvis3d(ngrid,nlayer,naerkind)
@@ -155,5 +159,6 @@
       REAL*8,allocatable,save :: taucumi(:,:,:)
 !$OMP THREADPRIVATE(tauv,taucumv,taucumi)
-      REAL*8 tauaero(L_LEVELS,naerkind)
+      REAL*8,allocatable,save :: tauaero(:,:)
+!$OMP THREADPRIVATE(tauaero)
       REAL*8 nfluxtopv,nfluxtopi,nfluxtop,fluxtopvdn
       REAL*8 nfluxoutv_nu(L_NSPECTV)                 ! Outgoing band-resolved VI flux at TOA (W/m2).
@@ -231,9 +236,31 @@
 
         ! test on allocated necessary because of CLFvarying (two calls to callcorrk in physiq)
+        if(.not.allocated(QVISsQREF3d)) then
+          allocate(QVISsQREF3d(ngrid,nlayer,L_NSPECTV,naerkind))
+        endif
+        if(.not.allocated(omegaVIS3d)) then
+          allocate(omegaVIS3d(ngrid,nlayer,L_NSPECTV,naerkind))
+        endif
+        if(.not.allocated(gVIS3d)) then
+          allocate(gVIS3d(ngrid,nlayer,L_NSPECTV,naerkind))
+        endif
+        if (.not.allocated(QIRsQREF3d)) then
+          allocate(QIRsQREF3d(ngrid,nlayer,L_NSPECTI,naerkind))
+        endif
+        if (.not.allocated(omegaIR3d)) then
+          allocate(omegaIR3d(ngrid,nlayer,L_NSPECTI,naerkind))
+        endif
+        if (.not.allocated(gIR3d)) then
+          allocate(gIR3d(ngrid,nlayer,L_NSPECTI,naerkind))
+        endif
+        if (.not.allocated(tauaero)) then
+          allocate(tauaero(L_LEVELS,naerkind))
+        endif
+        
         if(.not.allocated(QXVAER)) then 
           allocate(QXVAER(L_LEVELS,L_NSPECTV,naerkind), stat=ok)
           if (ok /= 0) then
              write(*,*) "memory allocation failed for QXVAER!"
-             call abort_physic(subname,'allocation failurei for QXVAER',1)
+             call abort_physic(subname,'allocation failure for QXVAER',1)
           endif
         endif
Index: /trunk/LMDZ.GENERIC/libf/phystd/callsedim.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/callsedim.F	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/callsedim.F	(revision 2972)
@@ -54,6 +54,7 @@
 
       ! for particles with varying radii:
-      real reffrad(ngrid,nlay,naerkind) ! particle radius (m) 
-      real nueffrad(ngrid,nlay,naerkind) ! aerosol effective radius variance
+      real,allocatable,save :: reffrad(:,:,:) ! particle radius (m) 
+      real,allocatable,save :: nueffrad(:,:,:) ! aerosol effective radius variance
+!$OMP THREADPRIVATE(reffrad,nueffrad)
 
       real zqi(ngrid,nlay,nq) ! to locally store tracers
@@ -79,4 +80,9 @@
           stop
         endif
+        ! allocate "naerkind" size local arrays (which are also
+        ! "saved" so that this is done only once in for all even if
+        ! we don't need to store the value from a time step to the next)
+        allocate(reffrad(ngrid,nlay,naerkind))
+        allocate(nueffrad(ngrid,nlay,naerkind))
       ENDIF ! of IF (firstcall)
       
Index: /trunk/LMDZ.GENERIC/libf/phystd/condense_co2.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/condense_co2.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/condense_co2.F90	(revision 2972)
@@ -6,5 +6,5 @@
           pdtc,pdtsrfc,pdpsrfc,pdqc)
 
-      use radinc_h, only : L_NSPECTV, naerkind
+      use radinc_h, only : L_NSPECTV
       use gases_h, only: gfrac, igas_co2
       use radii_mod, only : co2_reffrad
Index: /trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F	(revision 2972)
@@ -29,4 +29,5 @@
       USE vertical_layers_mod, ONLY: init_vertical_layers
       USE logic_mod, ONLY: hybrid
+      use radinc_h, only: naerkind
       use regular_lonlat_mod, only: init_regular_lonlat
       use planete_mod, only: ini_planete_mod
@@ -154,4 +155,33 @@
 c INITIALISATION
 c=======================================================================
+! check if 'rcm1d.def' file is around 
+      open(90,file='rcm1d.def',status='old',form='formatted',
+     &     iostat=ierr)
+      if (ierr.ne.0) then
+        write(*,*) 'Cannot find required file "rcm1d.def"'
+        write(*,*) 'which should contain some input parameters'
+        write(*,*) ' ... might as well stop here ...'
+        stop
+      else
+        close(90)
+      endif
+
+! now, run.def is needed anyway. so we create a dummy temporary one
+! for ioipsl to work. if a run.def is already here, stop the
+! program and ask the user to do a bit of cleaning
+      open(90,file='run.def',status='old',form='formatted',
+     &     iostat=ierr)
+      if (ierr.eq.0) then
+        close(90)
+        write(*,*) 'There is already a run.def file.'
+        write(*,*) 'This is not compatible with 1D runs.'
+        write(*,*) 'Please remove the file and restart the run.'
+        write(*,*) 'Runtime parameters are supposed to be in rcm1d.def'
+        stop
+      else
+        call system('touch run.def')
+        call system("echo 'INCLUDEDEF=callphys.def' >> run.def")
+        call system("echo 'INCLUDEDEF=rcm1d.def' >> run.def")
+      endif
 
       ! read nq from traceur.def
@@ -187,5 +217,10 @@
       ! Initialize dimphy module
       call init_dimphy(1,llm) 
+      
       ! now initialize arrays using phys_state_var_init
+      ! but first initialise naerkind (from callphys.def)
+      naerkind=0 !default
+      call getin("naerkind",naerkind)
+      
       call phys_state_var_init(nq)
       
@@ -221,33 +256,4 @@
 c ------------------------------------------------------
 
-! check if 'rcm1d.def' file is around 
-      open(90,file='rcm1d.def',status='old',form='formatted',
-     &     iostat=ierr)
-      if (ierr.ne.0) then
-        write(*,*) 'Cannot find required file "rcm1d.def"'
-        write(*,*) 'which should contain some input parameters'
-        write(*,*) ' ... might as well stop here ...'
-        stop
-      else
-        close(90)
-      endif
-
-! now, run.def is needed anyway. so we create a dummy temporary one
-! for ioipsl to work. if a run.def is already here, stop the
-! program and ask the user to do a bit of cleaning
-      open(90,file='run.def',status='old',form='formatted',
-     &     iostat=ierr)
-      if (ierr.eq.0) then
-        close(90)
-        write(*,*) 'There is already a run.def file.'
-        write(*,*) 'This is not compatible with 1D runs.'
-        write(*,*) 'Please remove the file and restart the run.'
-        write(*,*) 'Runtime parameters are supposed to be in rcm1d.def'
-        stop
-      else
-        call system('touch run.def')
-        call system("echo 'INCLUDEDEF=callphys.def' >> run.def")
-        call system("echo 'INCLUDEDEF=rcm1d.def' >> run.def")
-      endif
 
 ! check if we are going to run with or without tracers
Index: /trunk/LMDZ.GENERIC/libf/phystd/inifis_mod.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/inifis_mod.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/inifis_mod.F90	(revision 2972)
@@ -11,4 +11,5 @@
   use init_print_control_mod, only: init_print_control
   use radinc_h, only: ini_radinc_h, naerkind
+  use radcommon_h, only: ini_radcommon_h
   use radii_mod, only: radfixed, Nmix_co2
   use datafile_mod, only: datadir
@@ -615,8 +616,9 @@
      if (is_master) write(*,*)trim(rname)//": Nmix_co2 = ",Nmix_co2
 
-!         write(*,*)"Number of radiatively active aerosols:"
-!         naerkind=0. ! default value
-!         call getin_p("naerkind",naerkind)
-!         write(*,*)" naerkind = ",naerkind
+     if (is_master) write(*,*)trim(rname)//&
+       "Number of radiatively active aerosols:"
+     naerkind=0 ! default value
+     call getin_p("naerkind",naerkind)
+     if (is_master) write(*,*)trim(rname)//": naerkind = ",naerkind
 
      if (is_master) write(*,*)trim(rname)//": Opacity of dust (if used):"
@@ -1159,5 +1161,8 @@
   ! initialize variables in radinc_h
   call ini_radinc_h(nlayer,tplanckmin,tplanckmax,dtplanck)
- 
+
+  ! initialize variables and allocate arrays in radcommon_h
+  call ini_radcommon_h(naerkind)
+   
   ! allocate "comsoil_h" arrays
   call ini_comsoil_h(ngrid)
Index: /trunk/LMDZ.GENERIC/libf/phystd/optci.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/optci.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/optci.F90	(revision 2972)
@@ -58,6 +58,9 @@
   real*8,intent(in) ::  GIAER(L_LEVELS,L_NSPECTI,NAERKIND)
   real*8,intent(in) ::  TAUAERO(L_LEVELS,NAERKIND)
-  real*8  TAUAEROLK(L_LEVELS,L_NSPECTI,NAERKIND)
-  real*8  TAEROS(L_LEVELS,L_NSPECTI,NAERKIND)
+
+  ! local variables (saved for convenience as need be allocated)
+  real*8,save,allocatable :: TAUAEROLK(:,:,:)
+  real*8,save,allocatable :: TAEROS(:,:,:)
+!$OMP THREADPRIVATE(TAUAEROLK,TAEROS) 
 
   integer L, NW, NG, K, LK, IAER
@@ -94,4 +97,7 @@
 
   integer interm
+  
+  logical :: firstcall=.true.
+!$OMP THREADPRIVATE(firstcall)
 
   !--- Kasting's CIA ----------------------------------------
@@ -107,4 +113,13 @@
   !     -1.7,-1.7,-1.7,-1.7,-1.7,-1.7,-1.7, -1.7,0.0 ]
   !----------------------------------------------------------
+
+  if (firstcall) then
+    ! allocate local arrays of size "naerkind" (which are also
+    ! "saved" so that this is done only once in for all even if
+    ! we don't need to store the value from a time step to the next)
+    allocate(TAUAEROLK(L_LEVELS,L_NSPECTI,NAERKIND))
+    allocate(TAEROS(L_LEVELS,L_NSPECTI,NAERKIND))
+    firstcall=.false.
+  endif ! of if (firstcall)
 
   !! AS: to save time in computing continuum (see bilinearbig)
Index: /trunk/LMDZ.GENERIC/libf/phystd/optcv.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/optcv.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/optcv.F90	(revision 2972)
@@ -47,30 +47,33 @@
 
 
-  real*8 DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  real*8,intent(out) :: DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
   real*8 DTAUKV(L_LEVELS,L_NSPECTV,L_NGAUSS)
-  real*8 TAUV(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
-  real*8 TAUCUMV(L_LEVELS,L_NSPECTV,L_NGAUSS)
-  real*8 PLEV(L_LEVELS)
-  real*8 TMID(L_LEVELS), PMID(L_LEVELS)
-  real*8 COSBV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
-  real*8 WBARV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  real*8,intent(out) :: TAUV(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
+  real*8,intent(out) :: TAUCUMV(L_LEVELS,L_NSPECTV,L_NGAUSS)
+  real*8,intent(in) :: PLEV(L_LEVELS)
+  real*8,intent(in) :: TMID(L_LEVELS), PMID(L_LEVELS)
+  real*8,intent(out) :: COSBV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  real*8,intent(out) :: WBARV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
 
   ! for aerosols
-  real*8  QXVAER(L_LEVELS,L_NSPECTV,NAERKIND)
-  real*8  QSVAER(L_LEVELS,L_NSPECTV,NAERKIND)
-  real*8  GVAER(L_LEVELS,L_NSPECTV,NAERKIND)
-  real*8  TAUAERO(L_LEVELS,NAERKIND)
-  real*8  TAUAEROLK(L_LEVELS,L_NSPECTV,NAERKIND)
-  real*8  TAEROS(L_LEVELS,L_NSPECTV,NAERKIND)
+  real*8,intent(in) :: QXVAER(L_LEVELS,L_NSPECTV,NAERKIND)
+  real*8,intent(in) :: QSVAER(L_LEVELS,L_NSPECTV,NAERKIND)
+  real*8,intent(in) :: GVAER(L_LEVELS,L_NSPECTV,NAERKIND)
+  real*8,intent(in) :: TAUAERO(L_LEVELS,NAERKIND)
+  
+  ! local arrays (saved for convenience as need be allocated)
+  real*8,save,allocatable :: TAUAEROLK(:,:,:)
+  real*8,save,allocatable :: TAEROS(:,:,:)
+!$OMP THREADPRIVATE(TAUAEROLK,TAEROS) 
 
   integer L, NW, NG, K, LK, IAER
   integer MT(L_LEVELS), MP(L_LEVELS), NP(L_LEVELS)
   real*8  ANS, TAUGAS
-  real*8  TAURAY(L_NSPECTV)
+  real*8,intent(in) :: TAURAY(L_NSPECTV)
   real*8  TRAY(L_LEVELS,L_NSPECTV)
   real*8  DPR(L_LEVELS), U(L_LEVELS)
   real*8  LCOEF(4), LKCOEF(L_LEVELS,4)
 
-  real*8 taugsurf(L_NSPECTV,L_NGAUSS-1)
+  real*8,intent(out) :: taugsurf(L_NSPECTV,L_NGAUSS-1)
   real*8 DCONT,DAERO
   real*8 DRAYAER
@@ -79,5 +82,7 @@
 
   ! variable species mixing ratio variables
-  real*8  QVAR(L_LEVELS), WRATIO(L_LEVELS), MUVAR(L_LEVELS)
+  real*8,intent(in) :: QVAR(L_LEVELS)
+  real*8,intent(in) :: MUVAR(L_LEVELS)
+  real*8 :: WRATIO(L_LEVELS)
   real*8  KCOEF(4)
   integer NVAR(L_LEVELS)
@@ -99,4 +104,16 @@
 
   integer interm
+
+  logical :: firstcall=.true.
+!$OMP THREADPRIVATE(firstcall)
+
+  if (firstcall) then
+    ! allocate local arrays of size "naerkind" (which are also
+    ! "saved" so that this is done only once in for all even if
+    ! we don't need to store the value from a time step to the next)
+    allocate(TAUAEROLK(L_LEVELS,L_NSPECTV,NAERKIND))
+    allocate(TAEROS(L_LEVELS,L_NSPECTV,NAERKIND))
+    firstcall=.false.
+  endif ! of if (firstcall)
 
   !! AS: to save time in computing continuum (see bilinearbig)
Index: /trunk/LMDZ.GENERIC/libf/phystd/physiq_mod.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/physiq_mod.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/physiq_mod.F90	(revision 2972)
@@ -20,4 +20,5 @@
       use gases_h, only: gnom, gfrac
       use radcommon_h, only: sigma, glat, grav, BWNV, WNOI, DWNI, DWNV, WNOV
+      use suaer_corrk_mod, only: suaer_corrk
       use radii_mod, only: h2o_reffrad, co2_reffrad
       use aerosol_mod, only: iniaerosol, iaero_co2, iaero_h2o
@@ -260,5 +261,6 @@
 !     for the "naerkind" optically active aerosols:
 
-      real aerosol(ngrid,nlayer,naerkind) ! Aerosols.
+      real,save,allocatable :: aerosol(:,:,:) ! Aerosols
+!$OMP THREADPRIVATE(aerosol)
       real zh(ngrid,nlayer)               ! Potential temperature (K).
       real pw(ngrid,nlayer)               ! Vertical velocity (m/s). (NOTE : >0 WHEN DOWNWARDS !!)
@@ -342,4 +344,5 @@
       REAL,allocatable,save :: zdqchim(:,:,:) ! Calchim_asis routine
       REAL,allocatable,save :: zdqschim(:,:)  ! Calchim_asis routine
+!$OMP THREADPRIVATE(zdqchim,zdqschim)
 
       REAL array_zero1(ngrid)
@@ -441,5 +444,6 @@
       real muvar(ngrid,nlayer+1) ! For Runaway Greenhouse 1D study. By RW
 
-      real reffcol(ngrid,naerkind)
+      real,save,allocatable :: reffcol(:,:)
+!$OMP THREADPRIVATE(reffcol)
 
 !     Sourceevol for 'accelerated ice evolution'. By RW
@@ -513,4 +517,8 @@
 !        ~~~~~~~~~~~~~~~~~~~~~~~~~~~
          call iniaerosol
+         ! allocate related local arrays
+         ! (need be allocated instead of automatic because of "naerkind")
+         allocate(aerosol(ngrid,nlayer,naerkind))
+         allocate(reffcol(ngrid,naerkind))
 
 #ifdef CPP_XIOS
Index: /trunk/LMDZ.GENERIC/libf/phystd/radcommon_h.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/radcommon_h.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/radcommon_h.F90	(revision 2972)
@@ -1,5 +1,5 @@
 module radcommon_h
       use radinc_h, only: L_NSPECTI, L_NSPECTV, NTstart, NTstop, &
-                          naerkind, nsizemax
+                          nsizemax
       implicit none
 
@@ -93,10 +93,10 @@
 	!$OMP FZEROI,FZEROV)     !pgasmin,pgasmax,tgasmin,tgasmax read by master in sugas_corrk
 
-      real QVISsQREF(L_NSPECTV,naerkind,nsizemax)
-      real omegavis(L_NSPECTV,naerkind,nsizemax)
-      real gvis(L_NSPECTV,naerkind,nsizemax)
-      real QIRsQREF(L_NSPECTI,naerkind,nsizemax)
-      real omegair(L_NSPECTI,naerkind,nsizemax)
-      real gir(L_NSPECTI,naerkind,nsizemax)
+      real,allocatable,save :: QVISsQREF(:,:,:)
+      real,allocatable,save :: omegavis(:,:,:)
+      real,allocatable,save :: gvis(:,:,:)
+      real,allocatable,save :: QIRsQREF(:,:,:)
+      real,allocatable,save :: omegair(:,:,:)
+      real,allocatable,save :: gir(:,:,:)
 !$OMP THREADPRIVATE(QVISsQREF,omegavis,gvis,QIRsQREF,omegair,gir)
 
@@ -105,16 +105,17 @@
 ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-      REAL lamrefir(naerkind),lamrefvis(naerkind)
-
+      real,allocatable,save :: lamrefir(:),lamrefvis(:)
+!$OMP THREADPRIVATE(lamrefir,lamrefvis)
 ! Actual number of grain size classes in each domain for a
 !   given aerosol:
 
-      INTEGER          :: nsize(naerkind,2)
+      integer,allocatable,save :: nsize(:,:)
+!$OMP THREADPRIVATE(nsize) ! nsize filled by suaer_corrk
 
 ! Particle size axis (depend on the kind of aerosol and the
 !   radiation domain)
 
-      DOUBLE PRECISION :: radiustab(naerkind,2,nsizemax)
-!$OMP THREADPRIVATE(lamrefir,lamrefvis,radiustab) !nsize read by suaer_corrk
+      double precision,allocatable,save :: radiustab(:,:,:)
+!$OMP THREADPRIVATE(radiustab) 
 
 ! Extinction coefficient at reference wavelengths;
@@ -122,8 +123,8 @@
 !   longrefvis and longrefir.
 
-      REAL :: QREFvis(naerkind,nsizemax)
-      REAL :: QREFir(naerkind,nsizemax)
+      real,allocatable,save :: QREFvis(:,:)
+      real,allocatable,save :: QREFir(:,:)
 !      REAL :: omegaREFvis(naerkind,nsizemax)
-      REAL :: omegaREFir(naerkind,nsizemax)
+      real,allocatable,save :: omegaREFir(:,:)
 
       REAL,SAVE :: tstellar ! Stellar brightness temperature (SW)
@@ -160,3 +161,28 @@
 !$OMP THREADPRIVATE(glat,eclipse)
 
+contains
+      
+subroutine ini_radcommon_h(naerkind)
+  ! Initialize module variables
+  implicit none
+  integer,intent(in) :: naerkind
+
+  allocate(QVISsQREF(L_NSPECTV,naerkind,nsizemax))
+  allocate(omegavis(L_NSPECTV,naerkind,nsizemax))
+  allocate(gvis(L_NSPECTV,naerkind,nsizemax))
+  allocate(QIRsQREF(L_NSPECTI,naerkind,nsizemax))
+  allocate(omegair(L_NSPECTI,naerkind,nsizemax))
+  allocate(gir(L_NSPECTI,naerkind,nsizemax))
+  
+  allocate(lamrefir(naerkind))
+  allocate(lamrefvis(naerkind))
+  allocate(nsize(naerkind,2))
+  allocate(radiustab(naerkind,2,nsizemax))
+  
+  allocate(QREFvis(naerkind,nsizemax))
+  allocate(QREFir(naerkind,nsizemax))
+  allocate(omegaREFir(naerkind,nsizemax))
+  
+end subroutine ini_radcommon_h
+
 end module radcommon_h
Index: /trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90	(revision 2972)
@@ -4,5 +4,8 @@
 
   include "bands.h"
-  include "scatterers.h"
+
+  integer,save :: naerkind ! number of radiatively active aerosols
+                           ! set via inifis
+!$OMP THREADPRIVATE(naerkind)
 
 !======================================================================
Index: /trunk/LMDZ.GENERIC/libf/phystd/suaer_corrk.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/suaer_corrk.F90	(revision 2971)
+++ /trunk/LMDZ.GENERIC/libf/phystd/suaer_corrk.F90	(revision 2972)
@@ -1,3 +1,9 @@
-      subroutine suaer_corrk
+module suaer_corrk_mod
+
+implicit none
+
+contains
+
+subroutine suaer_corrk
 
       ! inputs
@@ -10,9 +16,16 @@
       use radcommon_h, only: radiustab,nsize,tstellar
       use radcommon_h, only: qrefvis,qrefir,omegarefir !,omegarefvis
-      use aerosol_mod
+      use aerosol_mod, only: noaero,iaero_co2,iaero_h2o,iaero_dust,iaero_h2so4
+      use aerosol_mod, only: iaero_back2lay,iaero_nh3,iaero_nlay,iaero_aurora
+      use aerosol_mod, only: iaero_venus1,iaero_venus2,iaero_venus2p
+      use aerosol_mod, only: iaero_venus3,iaero_venusUV
+      use aerosol_mod, only: iaero_generic,i_rgcs_ice
       use callkeys_mod, only: tplanet, optprop_back2lay_vis, optprop_back2lay_ir, &
                               optprop_aeronlay_vis, optprop_aeronlay_ir,          &
                               aeronlay_lamref, nlayaero,aerogeneric
       use tracer_h, only: noms
+      
+      use mod_phys_lmdz_para, only : is_master, bcast
+
       implicit none
 
@@ -48,5 +61,5 @@
 
 !     Optical properties (read in external ASCII files)
-      INTEGER,SAVE      :: nwvl  ! Number of wavelengths in
+      INTEGER      :: nwvl  ! Number of wavelengths in
                                 ! the domain (VIS or IR), read by master
 
@@ -55,10 +68,10 @@
 
       REAL, DIMENSION(:),&
-      ALLOCATABLE, SAVE :: wvl  ! Wavelength axis, read by master
+      ALLOCATABLE :: wvl  ! Wavelength axis, read by master
       REAL, DIMENSION(:),&
-      ALLOCATABLE, SAVE :: radiusdyn ! Particle size axis, read by master
+      ALLOCATABLE :: radiusdyn ! Particle size axis, read by master
 
       REAL, DIMENSION(:,:),&
-      ALLOCATABLE, SAVE :: ep,& ! Extinction coefficient Qext, read by master
+      ALLOCATABLE :: ep,& ! Extinction coefficient Qext, read by master
       omeg,&                    ! Single Scattering Albedo, read by master
       gfactor                   ! Assymetry Factor, read by master
@@ -95,6 +108,6 @@
 !     Local saved variables:
 
-      CHARACTER(LEN=50), DIMENSION(naerkind,2), SAVE :: file_id
-!$OMP THREADPRIVATE(file_id)
+      CHARACTER(LEN=50),ALLOCATABLE :: file_id(:,:)
+
 !---- Please indicate the names of the optical property files below
 !     Please also choose the reference wavelengths of each aerosol      
@@ -119,4 +132,7 @@
 
 !--------------------------------------------------------------
+      ! allocate file_id, as naerkind is a variable
+      allocate(file_id(naerkind,2))
+
       if (noaero) then
         print*, 'naerkind= 0'
@@ -344,6 +360,6 @@
       QIRsQREF(:,:,:)  = 0.0
 
-      DO iaer = 1, naerkind     ! Loop on aerosol kind
-         DO idomain = 1, 2      ! Loop on radiation domain (VIS or IR)
+  DO iaer = 1, naerkind     ! Loop on aerosol kind
+    DO idomain = 1, 2      ! Loop on radiation domain (VIS or IR)
 !==================================================================
 !     1. READ OPTICAL PROPERTIES
@@ -352,6 +368,7 @@
 !     1.1 Open the ASCII file
 
-!$OMP MASTER
-
+!!!!$OMP MASTER
+      if (is_master) then
+          
             INQUIRE(FILE=TRIM(datadir)//'/'//TRIM(aerdir)//&
                     '/'//TRIM(file_id(iaer,idomain)),&
@@ -415,4 +432,10 @@
       ENDDO
 
+      endif ! of if (is_master)
+
+      ! broadcast nwvl and nsize to all cores
+      call bcast(nwvl)
+      call bcast(nsize)
+
       ALLOCATE(wvl(nwvl))       ! wvl
       ALLOCATE(radiusdyn(nsize(iaer,idomain))) ! radiusdyn
@@ -424,4 +447,5 @@
 !     1.3 Read the data
 
+      if (is_master) then
       jfile = 1
       endwhile = .false.
@@ -504,9 +528,12 @@
       endif
 
-!$OMP END MASTER
-!$OMP BARRIER
-
-
-
+      endif ! of if (is_master)
+
+      ! broadcast arrays to all cores
+      call bcast(wvl)
+      call bcast(radiusdyn)
+      call bcast(ep)
+      call bcast(omeg)
+      call bcast(gfactor)
 
 !==================================================================
@@ -588,5 +615,5 @@
 
 
-      ENDDO                     ! isize (particle size) -------------------------------------
+         ENDDO ! isize (particle size) -------------------------------------
 
       END SELECT domain
@@ -596,21 +623,18 @@
 !========================================================================
 
-!$OMP BARRIER
-!$OMP MASTER
-      IF (ALLOCATED(wvl)) DEALLOCATE(wvl)                 ! wvl
-      IF (ALLOCATED(radiusdyn)) DEALLOCATE(radiusdyn)     ! radiusdyn
-      IF (ALLOCATED(ep)) DEALLOCATE(ep)                   ! ep 
-      IF (ALLOCATED(omeg)) DEALLOCATE(omeg)          	  ! omeg 
-      IF (ALLOCATED(gfactor)) DEALLOCATE(gfactor)         ! g
-!$OMP END MASTER
-!$OMP BARRIER
-
-      END DO                    ! Loop on iaer
-      END DO                    ! Loop on idomain
+      DEALLOCATE(wvl)             ! wvl
+      DEALLOCATE(radiusdyn)       ! radiusdyn
+      DEALLOCATE(ep)              ! ep 
+      DEALLOCATE(omeg)            ! omeg 
+      DEALLOCATE(gfactor)         ! g
+
+    END DO                    ! Loop on iaer
+  END DO                    ! Loop on idomain
 !========================================================================
-      RETURN
-
-
-
-    END subroutine suaer_corrk
+ 
+  ! cleanup
+  deallocate(file_id)
+
+end subroutine suaer_corrk
       
+end module suaer_corrk_mod
