Index: trunk/LMDZ.GENERIC/libf/dyn3d/calfis.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/dyn3d/calfis.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/dyn3d/calfis.F	(revision 787)
@@ -72,4 +72,7 @@
 #include "comgeom2.h"
 #include "control.h"
+
+#include "advtrac.h"
+!! this is to get tnom (tracers name)
 
 c    Arguments :
@@ -422,4 +425,5 @@
 
       CALL physiq (ngridmx,llm,nq,
+     .     tnom,
      ,     debut,lafin,
      ,     rday_ecri,heure,dtphys,
Index: trunk/LMDZ.GENERIC/libf/dyn3d/ini_archive.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/dyn3d/ini_archive.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/dyn3d/ini_archive.F	(revision 787)
@@ -34,4 +34,6 @@
 
 c=======================================================================
+
+      USE comsoil_h
  
       implicit none
@@ -49,5 +51,4 @@
 #include "serre.h"
 #include "control.h"
-#include"comsoil.h"
 
 #include "netcdf.inc"
Index: trunk/LMDZ.GENERIC/libf/dyn3d/lect_start_archive.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/dyn3d/lect_start_archive.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/dyn3d/lect_start_archive.F	(revision 787)
@@ -3,4 +3,8 @@
      &     q,qsurf,surfith,nid)
 
+      USE surfdat_h
+      USE comsoil_h
+      USE tracer_h
+
 c=======================================================================
 c
@@ -22,6 +26,4 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "surfdat.h"
-#include "comsoil.h"
 #include "planete.h"
 #include "paramet.h"
@@ -36,5 +38,4 @@
 #include "lmdstd.h"
 #include "netcdf.inc"
-#include "tracer.h"
 #include"advtrac.h"
 c=======================================================================
Index: trunk/LMDZ.GENERIC/libf/dyn3d/newstart.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/dyn3d/newstart.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/dyn3d/newstart.F	(revision 787)
@@ -15,10 +15,13 @@
 c=======================================================================
 
+      USE tracer_h
+      USE comsoil_h
+      USE surfdat_h
+      USE comgeomfi_h
+
       implicit none
 
 #include "dimensions.h"
 #include "dimphys.h"
-#include "surfdat.h"
-#include "comsoil.h"
 #include "planete.h"
 #include "paramet.h"
@@ -37,5 +40,4 @@
 #include "netcdf.inc"
 #include "advtrac.h"
-#include "tracer.h"
 c=======================================================================
 c   Declarations
@@ -243,4 +245,9 @@
       ! tnom(:) now contains tracer names
 ! JL12 we will need the tracer names to read start in dyneta0
+
+! Initialize global tracer indexes (stored in tracer.h)
+! ... this has to be done before phyetat0
+      call initracer(ngridmx,nqmx,tnom)
+
 
 c-----------------------------------------------------------------------
@@ -293,7 +300,14 @@
      .       ps,phis,time)
 
+
+        ! ALLOCATE ARRAYS IN comgeomfi_h (done in inifis usually)
+        IF (.not. ALLOCATED(lati)) ALLOCATE(lati(ngridmx))
+        IF (.not. ALLOCATED(long)) ALLOCATE(long(ngridmx))
+        IF (.not. ALLOCATED(area)) ALLOCATE(area(ngridmx))
+        cursor = 1 ! added by AS in dimphys. 1 for sequential runs.
+
         write(*,*) 'Reading file STARTFI'
         fichnom = 'startfi.nc'
-        CALL phyetat0 (fichnom,tab0,Lmodif,nsoilmx,nqmx,
+        CALL phyetat0 (ngridmx,fichnom,tab0,Lmodif,nsoilmx,nqmx,
      .        day_ini,time,
      .        tsurf,tsoil,emis,q2,qsurf,   !) ! temporary modif by RDW
@@ -352,9 +366,9 @@
 c-----------------------------------------------------------------------
       if (choix_1.eq.0) then
-         call tabfi (nid,Lmodif,tab0,day_ini,lllm,p_rad,
+         call tabfi (ngridmx,nid,Lmodif,tab0,day_ini,lllm,p_rad,
      .            p_omeg,p_g,p_cpp,p_mugaz,p_daysec,time)
       else if (choix_1.eq.1) then
          Lmodif=1 ! Lmodif set to 1 to allow modifications in phyeta0                           
-         call tabfi (nid_fi,Lmodif,tab0,day_ini,lllm,p_rad,
+         call tabfi (ngridmx,nid_fi,Lmodif,tab0,day_ini,lllm,p_rad,
      .            p_omeg,p_g,p_cpp,p_mugaz,p_daysec,time)
       endif
@@ -369,10 +383,7 @@
       kappa = 8.314*1000./(p_mugaz*p_cpp) ! added by RDW
 
-
 c=======================================================================
 c  INITIALISATIONS DIVERSES
 c=======================================================================
-! Initialize global tracer indexes (stored in tracer.h)
-      call initracer()
 ! Load parameters from run.def file
       CALL defrun_new( 99, .TRUE. )
@@ -1413,9 +1424,9 @@
 
 
-      call physdem1("restartfi.nc",lonfi,latfi,nsoilmx,nqmx,
+      call physdem1(ngridmx,"restartfi.nc",lonfi,latfi,nsoilmx,nqmx,
      .              dtphys,float(day_ini),
      .              time,tsurf,tsoil,emis,q2,qsurf,
      .              airefi,albfi,ithfi,zmea,zstd,zsig,zgam,zthe,
-     .              cloudfrac,totalfrac,hice)
+     .              cloudfrac,totalfrac,hice,tnom)
 
 c=======================================================================
Index: trunk/LMDZ.GENERIC/libf/dyn3d/start2archive.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/dyn3d/start2archive.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/dyn3d/start2archive.F	(revision 787)
@@ -18,4 +18,6 @@
 c
 c=======================================================================
+
+      USE comsoil_h
 
       implicit none
@@ -34,5 +36,4 @@
 
 #include "dimphys.h"
-#include "comsoil.h"
 #include "planete.h"
 #include"advtrac.h"
@@ -162,5 +163,6 @@
       Lmodif=0
 
-      CALL phyetat0 (fichnom,0,Lmodif,nsoilmx,nqmx,day_ini_fi,timefi,
+      CALL phyetat0 (ngridmx,fichnom,0,Lmodif,nsoilmx,nqmx,day_ini_fi,
+     .      timefi,
      .      tsurf,tsoil,emis,q2,qsurf,
 !       change FF 05/2011
Index: trunk/LMDZ.GENERIC/libf/phystd/aeropacity.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/aeropacity.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/aeropacity.F90	(revision 787)
@@ -4,4 +4,6 @@
        use radinc_h, only : L_TAUMAX,naerkind
        use aerosol_mod
+       USE comgeomfi_h
+       USE tracer_h
                   
        implicit none
@@ -28,6 +30,6 @@
 !     pq                Aerosol mixing ratio
 !     reffrad(ngrid,nlayer,naerkind)         Aerosol effective radius
-!     QREFvis3d(ngridmx,nlayermx,naerkind) \ 3d extinction coefficients
-!     QREFir3d(ngridmx,nlayermx,naerkind)  / at reference wavelengths
+!     QREFvis3d(ngrid,nlayermx,naerkind) \ 3d extinction coefficients
+!     QREFir3d(ngrid,nlayermx,naerkind)  / at reference wavelengths
 !
 !     Output
@@ -42,6 +44,4 @@
 #include "callkeys.h"
 #include "comcstfi.h"
-#include "comgeomfi.h"
-#include "tracer.h"
 #include "comvert.h"
 
@@ -53,11 +53,11 @@
       REAL aerosol(ngrid,nlayer,naerkind)
       REAL reffrad(ngrid,nlayer,naerkind)
-      REAL QREFvis3d(ngridmx,nlayermx,naerkind)
-      REAL QREFir3d(ngridmx,nlayermx,naerkind)
+      REAL QREFvis3d(ngrid,nlayermx,naerkind)
+      REAL QREFir3d(ngrid,nlayermx,naerkind)
 
       REAL tau_col(ngrid)
 !      REAL tauref(ngrid), tau_col(ngrid)
 
-      real cloudfrac(ngridmx,nlayermx)
+      real cloudfrac(ngrid,nlayermx)
       real aerosol0
 
@@ -77,9 +77,9 @@
       ! for fixed dust profiles
       real topdust, expfactor, zp
-      REAL taudusttmp(ngridmx) ! Temporary dust opacity used before scaling
-      REAL tauh2so4tmp(ngridmx) ! Temporary h2so4 opacity used before scaling
+      REAL taudusttmp(ngrid) ! Temporary dust opacity used before scaling
+      REAL tauh2so4tmp(ngrid) ! Temporary h2so4 opacity used before scaling
       ! BENJAMIN MODIFS
       real CLFtot
-      real totcloudfrac(ngridmx)
+      real totcloudfrac(ngrid)
       logical clearsky
 
@@ -87,21 +87,6 @@
       IF (firstcall) THEN
 
-         ! are these tests of any real use ?
-        IF(ngrid.NE.ngridmx) THEN
-            PRINT*,'STOP in aeropacity!'
-            PRINT*,'problem of dimensions:'
-            PRINT*,'ngrid  =',ngrid
-            PRINT*,'ngridmx  =',ngridmx
-            STOP
-        ENDIF
-
-        if (nq.gt.nqmx) then
-           write(*,*) 'STOP in aeropacity: (nq .gt. nqmx)!'
-           write(*,*) 'nq=',nq,' nqmx=',nqmx
-           stop
-        endif
-
         write(*,*) "Tracers found in aeropacity:"
-        do iq=1,nqmx
+        do iq=1,nq
           tracername=noms(iq)
           if (tracername.eq."co2_ice") then
@@ -150,11 +135,11 @@
            iaer=iaero_co2
 !       1. Initialization
-            aerosol(1:ngridmx,1:nlayermx,iaer)=0.0
+            aerosol(1:ngrid,1:nlayermx,iaer)=0.0
 !       2. Opacity calculation
             if (noaero) then ! aerosol set to a very low value
-             aerosol(1:ngridmx,1:nlayermx,iaer)=1.e-9
+             aerosol(1:ngrid,1:nlayermx,iaer)=1.e-9
             elseif (aerofixco2.or.(i_co2ice.eq.0)) then !  CO2 ice cloud prescribed
-               aerosol(1:ngridmx,1:nlayermx,iaer)=1.e-9
-               !aerosol(1:ngridmx,12,iaer)=4.0 ! single cloud layer option
+               aerosol(1:ngrid,1:nlayermx,iaer)=1.e-9
+               !aerosol(1:ngrid,12,iaer)=4.0 ! single cloud layer option
             else
                DO ig=1, ngrid
@@ -187,8 +172,8 @@
            iaer=iaero_h2o
 !       1. Initialization
-            aerosol(1:ngridmx,1:nlayermx,iaer)=0.0
+            aerosol(1:ngrid,1:nlayermx,iaer)=0.0
 !       2. Opacity calculation
             if (aerofixh2o.or.(i_h2oice.eq.0).or.clearsky) then
-               aerosol(1:ngridmx,1:nlayermx,iaer) =1.e-9
+               aerosol(1:ngrid,1:nlayermx,iaer) =1.e-9
 
                ! put cloud at cloudlvl
@@ -241,5 +226,5 @@
 
                if(CLFvarying)then
-                  call totalcloudfrac(cloudfrac,totcloudfrac,pplev,pq,aerosol(1:ngridmx,1:nlayermx,iaer))
+                  call totalcloudfrac(ngrid,nq,cloudfrac,totcloudfrac,pplev,pq,aerosol(1:ngrid,1:nlayermx,iaer))
                   do ig=1, ngrid
                      do l=1,nlayer-1 ! to stop the rad tran bug
@@ -268,5 +253,5 @@
           iaer=iaero_dust
 !         1. Initialization 
-          aerosol(1:ngridmx,1:nlayermx,iaer)=0.0
+          aerosol(1:ngrid,1:nlayermx,iaer)=0.0
           
           topdust=30.0 ! km  (used to be 10.0 km) LK
@@ -322,5 +307,5 @@
 
 !       1. Initialization
-         aerosol(1:ngridmx,1:nlayermx,iaer)=0.0
+         aerosol(1:ngrid,1:nlayermx,iaer)=0.0
 
 
@@ -386,5 +371,5 @@
       end do
 
-      do ig=1, ngrid
+      do ig=1,ngrid
          do l=1,nlayer
             do iaer = 1, naerkind
@@ -399,5 +384,5 @@
       end do
 
-      do ig=1, ngrid
+      do ig=1,ngrid
          if(tau_col(ig).gt.1.e3)then
             print*,'WARNING: tau_col=',tau_col(ig)
Index: trunk/LMDZ.GENERIC/libf/phystd/aeroptproperties.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/aeroptproperties.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/aeroptproperties.F90	(revision 787)
@@ -60,5 +60,5 @@
       INTEGER :: grid_i,grid_j
 !     Intermediate variable
-      REAL :: var_tmp,var3d_tmp(ngridmx,nlayermx)
+      REAL :: var_tmp,var3d_tmp(ngrid,nlayermx)
 !     Bilinear interpolation factors
       REAL :: kx,ky,k1,k2,k3,k4
@@ -161,24 +161,24 @@
       INTEGER :: ngrid,nlayer
 !     Aerosol effective radius used for radiative transfer (meter)
-      REAL :: reffrad(ngridmx,nlayermx,naerkind)
+      REAL :: reffrad(ngrid,nlayermx,naerkind)
 !     Aerosol effective variance used for radiative transfer (n.u.)
-      REAL :: nueffrad(ngridmx,nlayermx,naerkind)
+      REAL :: nueffrad(ngrid,nlayermx,naerkind)
 
 !     Outputs
 !     -------
 
-      REAL :: QVISsQREF3d(ngridmx,nlayermx,L_NSPECTV,naerkind)
-      REAL :: omegaVIS3d(ngridmx,nlayermx,L_NSPECTV,naerkind)
-      REAL :: gVIS3d(ngridmx,nlayermx,L_NSPECTV,naerkind)
-
-      REAL :: QIRsQREF3d(ngridmx,nlayermx,L_NSPECTI,naerkind)
-      REAL :: omegaIR3d(ngridmx,nlayermx,L_NSPECTI,naerkind)
-      REAL :: gIR3d(ngridmx,nlayermx,L_NSPECTI,naerkind)
-
-      REAL :: QREFvis3d(ngridmx,nlayermx,naerkind)
-      REAL :: QREFir3d(ngridmx,nlayermx,naerkind)
-
-      REAL :: omegaREFvis3d(ngridmx,nlayermx,naerkind)
-      REAL :: omegaREFir3d(ngridmx,nlayermx,naerkind)
+      REAL :: QVISsQREF3d(ngrid,nlayermx,L_NSPECTV,naerkind)
+      REAL :: omegaVIS3d(ngrid,nlayermx,L_NSPECTV,naerkind)
+      REAL :: gVIS3d(ngrid,nlayermx,L_NSPECTV,naerkind)
+
+      REAL :: QIRsQREF3d(ngrid,nlayermx,L_NSPECTI,naerkind)
+      REAL :: omegaIR3d(ngrid,nlayermx,L_NSPECTI,naerkind)
+      REAL :: gIR3d(ngrid,nlayermx,L_NSPECTI,naerkind)
+
+      REAL :: QREFvis3d(ngrid,nlayermx,naerkind)
+      REAL :: QREFir3d(ngrid,nlayermx,naerkind)
+
+      REAL :: omegaREFvis3d(ngrid,nlayermx,naerkind)
+      REAL :: omegaREFir3d(ngrid,nlayermx,naerkind)
 
       DO iaer = 1, naerkind ! Loop on aerosol kind
@@ -380,5 +380,5 @@
 
       DO lg = 1,nlayer
-        DO ig = 1,ngrid
+        DO ig = 1, ngrid
 !         2.1 Effective radius index and kx calculation
           var_tmp=reffrad(ig,lg,iaer)/refftabmin
@@ -725,5 +725,5 @@
           ENDIF                  ! --------------------------------
         ENDDO !nlayermx
-      ENDDO !ngridmx
+      ENDDO !ngrid
 
 !==================================================================
Index: trunk/LMDZ.GENERIC/libf/phystd/calcenergy_kcm.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/calcenergy_kcm.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/calcenergy_kcm.F90	(revision 787)
@@ -22,5 +22,5 @@
   real Play(1:nlayermx),Plev(1:nlayermx+1)
   real Qsurf,Q(1:nlayermx)
-  real muvar(ngridmx,nlayermx+1)
+  real muvar(1,nlayermx+1)
 
   ! internal
Index: trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 787)
@@ -5,5 +5,5 @@
           fluxsurf_sw,fluxtop_lw,fluxabs_sw,fluxtop_dn,        &
           OLR_nu,OSR_nu,                                       &
-          reffrad,tau_col,cloudfrac,totcloudfrac,              &
+          reffrad,nueffrad,tau_col,cloudfrac,totcloudfrac,     &
           clearsky,firstcall,lastcall)
 
@@ -16,4 +16,6 @@
       use radii_mod, only : su_aer_radii,co2_reffrad,h2o_reffrad,dust_reffrad,h2so4_reffrad
       use aerosol_mod
+
+      USE tracer_h
 
       implicit none
@@ -37,5 +39,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "tracer.h"
 
 !-----------------------------------------------------------------------
@@ -60,31 +61,30 @@
 !     Globally varying aerosol optical properties on GCM grid
 !     Not needed everywhere so not in radcommon_h
-      REAL :: QVISsQREF3d(ngridmx,nlayermx,L_NSPECTV,naerkind)
-      REAL :: omegaVIS3d(ngridmx,nlayermx,L_NSPECTV,naerkind)
-      REAL :: gVIS3d(ngridmx,nlayermx,L_NSPECTV,naerkind)
-
-      REAL :: QIRsQREF3d(ngridmx,nlayermx,L_NSPECTI,naerkind)
-      REAL :: omegaIR3d(ngridmx,nlayermx,L_NSPECTI,naerkind)
-      REAL :: gIR3d(ngridmx,nlayermx,L_NSPECTI,naerkind)
-
-      REAL :: QREFvis3d(ngridmx,nlayermx,naerkind)
-      REAL :: QREFir3d(ngridmx,nlayermx,naerkind)
-
-!      REAL :: omegaREFvis3d(ngridmx,nlayermx,naerkind)
-!      REAL :: omegaREFir3d(ngridmx,nlayermx,naerkind) ! not sure of the point of these...
-
-      REAL reffrad(ngrid,nlayer,naerkind)
-      REAL, SAVE :: nueffrad(ngridmx,nlayermx,naerkind)
-
-!     OUTPUT
-      REAL dtsw(ngridmx,nlayermx) ! heating rate (K/s) due to SW
-      REAL dtlw(ngridmx,nlayermx) ! heating rate (K/s) due to LW
-      REAL fluxsurf_lw(ngridmx)   ! incident LW flux to surf (W/m2)
-      REAL fluxtop_lw(ngridmx)    ! outgoing LW flux to space (W/m2)
-      REAL fluxsurf_sw(ngridmx)   ! incident SW flux to surf (W/m2)
-      REAL fluxabs_sw(ngridmx)    ! SW flux absorbed by planet (W/m2)
-      REAL fluxtop_dn(ngridmx)    ! incident top of atmosphere SW flux (W/m2)
+      REAL :: QVISsQREF3d(ngrid,nlayermx,L_NSPECTV,naerkind)
+      REAL :: omegaVIS3d(ngrid,nlayermx,L_NSPECTV,naerkind)
+      REAL :: gVIS3d(ngrid,nlayermx,L_NSPECTV,naerkind)
+
+      REAL :: QIRsQREF3d(ngrid,nlayermx,L_NSPECTI,naerkind)
+      REAL :: omegaIR3d(ngrid,nlayermx,L_NSPECTI,naerkind)
+      REAL :: gIR3d(ngrid,nlayermx,L_NSPECTI,naerkind)
+
+!      REAL :: omegaREFvis3d(ngrid,nlayermx,naerkind)
+!      REAL :: omegaREFir3d(ngrid,nlayermx,naerkind) ! not sure of the point of these...
+
+      !!! this is a local instance of a variable saved in physiq.F and being an argument
+      REAL, INTENT(INOUT) :: reffrad(ngrid,nlayer,naerkind)
+      REAL, INTENT(INOUT) :: nueffrad(ngrid,nlayermx,naerkind)
+
+!!     OUTPUT
+      REAL dtsw(ngrid,nlayermx) ! heating rate (K/s) due to SW
+      REAL dtlw(ngrid,nlayermx) ! heating rate (K/s) due to LW
+      REAL fluxsurf_lw(ngrid)   ! incident LW flux to surf (W/m2)
+      REAL fluxtop_lw(ngrid)    ! outgoing LW flux to space (W/m2)
+      REAL fluxsurf_sw(ngrid)   ! incident SW flux to surf (W/m2)
+      REAL fluxabs_sw(ngrid)    ! SW flux absorbed by planet (W/m2)
+      REAL fluxtop_dn(ngrid)    ! incident top of atmosphere SW flux (W/m2)
       REAL OLR_nu(ngrid,L_NSPECTI)! Outgoing LW radition in each band (Normalized to the band width (W/m2/cm-1)
       REAL OSR_nu(ngrid,L_NSPECTV)! Outgoing SW radition in each band (Normalized to the band width (W/m2/cm-1)
+
 !-----------------------------------------------------------------------
 !     Declaration of the variables required by correlated-k subroutines
@@ -126,6 +126,6 @@
 
       real*8 qvar(L_LEVELS)          ! mixing ratio of variable component (mol/mol)
-      REAL pq(ngridmx,nlayer,nq)
-      REAL qsurf(ngridmx,nqmx)       ! tracer on surface (e.g. kg.m-2)
+      REAL pq(ngrid,nlayer,nq)
+      REAL qsurf(ngrid,nq)       ! tracer on surface (e.g. kg.m-2)
       integer nq
 
@@ -140,5 +140,10 @@
       save qxvaer, qsvaer, gvaer
       save qxiaer, qsiaer, giaer
-      save QREFvis3d, QREFir3d 
+
+      !REAL :: QREFvis3d(ngrid,nlayermx,naerkind)
+      !REAL :: QREFir3d(ngrid,nlayermx,naerkind)
+      !save QREFvis3d, QREFir3d 
+      real, dimension(:,:,:), save, allocatable :: QREFvis3d
+      real, dimension(:,:,:), save, allocatable :: QREFir3d
 
       REAL tau_col(ngrid) ! diagnostic from aeropacity
@@ -165,10 +170,10 @@
 
 !     for H2O cloud fraction in aeropacity
-      real cloudfrac(ngridmx,nlayermx)
-      real totcloudfrac(ngridmx)
+      real cloudfrac(ngrid,nlayermx)
+      real totcloudfrac(ngrid)
       logical clearsky
 
       ! for weird cloud test
-      real pqtest(ngridmx,nlayer,nq)
+      real pqtest(ngrid,nlayer,nq)
 
       real maxrad, minrad
@@ -178,5 +183,5 @@
 
 !     included by RW for runaway greenhouse 1D study
-      real muvar(ngridmx,nlayermx+1)
+      real muvar(ngrid,nlayermx+1)
       real vtmp(nlayermx)
       REAL*8 muvarrad(L_LEVELS)
@@ -195,4 +200,7 @@
 
       if(firstcall) then
+
+         ALLOCATE(QREFvis3d(ngrid,nlayermx,naerkind))
+         ALLOCATE(QREFir3d(ngrid,nlayermx,naerkind))
 
          call system('rm -f surf_vals_long.out')
@@ -204,5 +212,5 @@
             call abort
          endif
-         call su_aer_radii(reffrad,nueffrad)
+         call su_aer_radii(ngrid,reffrad,nueffrad)
 	 
 	 
@@ -233,5 +241,5 @@
          OSR_nu(:,:) = 0.
 
-         if (ngridmx.eq.1) then
+         if (ngrid.eq.1) then
            PRINT*, 'Simulate global averaged conditions ?'
            global1d = .false. ! default value
@@ -266,19 +274,19 @@
 
          if ((iaer.eq.iaero_co2).and.tracer.and.(igcm_co2_ice.gt.0)) then ! treat condensed co2 particles.
-	    call co2_reffrad(pq,reffrad)
-            print*,'Max. CO2 ice particle size = ',maxval(reffrad(1:ngridmx,1:nlayermx,iaer))/1.e-6,' um'
-            print*,'Min. CO2 ice particle size = ',minval(reffrad(1:ngridmx,1:nlayermx,iaer))/1.e-6,' um'
+	    call co2_reffrad(ngrid,nq,pq,reffrad)
+            print*,'Max. CO2 ice particle size = ',maxval(reffrad(1:ngrid,1:nlayermx,iaer))/1.e-6,' um'
+            print*,'Min. CO2 ice particle size = ',minval(reffrad(1:ngrid,1:nlayermx,iaer))/1.e-6,' um'
 	 end if
          if ((iaer.eq.iaero_h2o).and.water) then ! treat condensed water particles. to be generalized for other aerosols
-	    call h2o_reffrad(pq,pt,reffrad,nueffrad)
-            print*,'Max. H2O cloud particle size = ',maxval(reffrad(1:ngridmx,1:nlayermx,iaer))/1.e-6,' um'
-            print*,'Min. H2O cloud particle size = ',minval(reffrad(1:ngridmx,1:nlayermx,iaer))/1.e-6,' um'
+	    call h2o_reffrad(ngrid,nq,pq,pt,reffrad,nueffrad)
+            print*,'Max. H2O cloud particle size = ',maxval(reffrad(1:ngrid,1:nlayermx,iaer))/1.e-6,' um'
+            print*,'Min. H2O cloud particle size = ',minval(reffrad(1:ngrid,1:nlayermx,iaer))/1.e-6,' um'
          endif
          if(iaer.eq.iaero_dust)then
-	    call dust_reffrad(reffrad)
+	    call dust_reffrad(ngrid,reffrad)
             print*,'Dust particle size = ',reffrad(1,1,iaer)/1.e-6,' um'
          endif
          if(iaer.eq.iaero_h2so4)then
-	    call h2so4_reffrad(reffrad)
+	    call h2so4_reffrad(ngrid,reffrad)
             print*,'H2SO4 particle size =',reffrad(1,1,iaer)/1.e-6,' um'
          endif
@@ -304,5 +312,5 @@
 !-----------------------------------------------------------------------
 !     Starting Big Loop over every GCM column
-      do ig=1,ngridmx
+      do ig=1,ngrid
 
 !=======================================================================
@@ -452,5 +460,5 @@
       endif
 
-      if ((ngridmx.eq.1).and.(global1d)) then       ! fixed zenith angle 'szangle' in 1D simulations w/ globally-averaged sunlight
+      if ((ngrid.eq.1).and.(global1d)) then       ! fixed zenith angle 'szangle' in 1D simulations w/ globally-averaged sunlight
          acosz = cos(pi*szangle/180.0)
          print*,'acosz=',acosz,', szangle=',szangle
@@ -550,5 +558,5 @@
          !i_var=igcm_h2o_vap
          i_var=1
-         if(nqmx.gt.1)then
+         if(nq.gt.1)then
             print*,'Need 1 tracer only to run kcm1d.e' 
             stop
@@ -653,5 +661,5 @@
             fluxtoplanet=0.
 
-            if((ngridmx.eq.1).and.(global1d))then
+            if((ngrid.eq.1).and.(global1d))then
                do nw=1,L_NSPECTV
                   stel_fract(nw)= stel(nw) * 0.25 / acosz
Index: trunk/LMDZ.GENERIC/libf/phystd/callsedim.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/callsedim.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/callsedim.F	(revision 787)
@@ -2,4 +2,7 @@
      $                pplev,zlev, pt,
      &                pq, pdqfi, pdqsed,pdqs_sed,nq,rfall)
+
+      USE tracer_h
+
       IMPLICIT NONE
 
@@ -25,8 +28,5 @@
 #include "dimphys.h"
 #include "comcstfi.h"
-#include "tracer.h"
 #include "callkeys.h"
-
-#include "fisice.h"
 
 c   arguments:
@@ -53,10 +53,10 @@
       INTEGER l,ig, iq
 
-      real zqi(ngridmx,nlayermx,nqmx) ! to locally store tracers
-      real masse (ngridmx,nlayermx) ! Layer mass (kg.m-2)
-      real epaisseur (ngridmx,nlayermx) ! Layer thickness (m)
-      real wq(ngridmx,nlayermx+1) ! displaced tracer mass (kg.m-2)
-c      real dens(ngridmx,nlayermx) ! Mean density of the ice part. accounting for dust core
-      real rfall(ngridmx,nlayermx)
+      real zqi(ngrid,nlayermx,nq) ! to locally store tracers
+      real masse (ngrid,nlayermx) ! Layer mass (kg.m-2)
+      real epaisseur (ngrid,nlayermx) ! Layer thickness (m)
+      real wq(ngrid,nlayermx+1) ! displaced tracer mass (kg.m-2)
+c      real dens(ngrid,nlayermx) ! Mean density of the ice part. accounting for dust core
+      real rfall(ngrid,nlayermx)
 
 
@@ -69,12 +69,4 @@
 
       IF (firstcall) THEN
-         IF(ngrid.NE.ngridmx) THEN
-            PRINT*,'STOP dans callsedim'
-            PRINT*,'probleme de dimensions :'
-            PRINT*,'ngrid  =',ngrid
-            PRINT*,'ngridmx  =',ngridmx
-            STOP
-         ENDIF
-      
         firstcall=.false.
       ENDIF ! of IF (firstcall)
@@ -96,5 +88,5 @@
 !  of general tracers.]
  
-      zqi(1:ngrid,1:nlay,1:nqmx) = 0.
+      zqi(1:ngrid,1:nlay,1:nq) = 0.
       do iq=1,nq
        if((radius(iq).gt.1.e-9).and.(iq.ne.igcm_co2_ice)) then   
@@ -104,5 +96,5 @@
 
           do l=1,nlay 
-            do ig=1,ngrid
+            do ig=1, ngrid
               zqi(ig,l,iq)=pq(ig,l,iq)+pdqfi(ig,l,iq)*ptimestep
             enddo
@@ -128,5 +120,5 @@
 !======================================================================
 
-          do ig=1,ngrid 
+          do ig=1,ngrid
 !     Ehouarn: with new way of tracking tracers by name, this is simply
             pdqs_sed(ig,iq) = wq(ig,1)/ptimestep
Index: trunk/LMDZ.GENERIC/libf/phystd/comdiurn.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comdiurn.h	(revision 786)
+++ 	(revision )
@@ -1,6 +1,0 @@
-      COMMON/comdiurn/ldiurn,                                           &
-     &     sinlon(ngridmx),coslon(ngridmx),                             &
-     &     sinlat(ngridmx),coslat(ngridmx)
-      
-      real sinlon,coslon,sinlat,coslat
-      logical ldiurn
Index: trunk/LMDZ.GENERIC/libf/phystd/comdiurn_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comdiurn_h.F90	(revision 787)
+++ trunk/LMDZ.GENERIC/libf/phystd/comdiurn_h.F90	(revision 787)
@@ -0,0 +1,10 @@
+
+       module comdiurn_h
+
+       implicit none
+
+       real, allocatable, dimension(:) :: sinlon, coslon, sinlat, coslat
+       logical :: ldiurn
+
+       end module comdiurn_h
+
Index: trunk/LMDZ.GENERIC/libf/phystd/comgeomfi.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comgeomfi.h	(revision 786)
+++ 	(revision )
@@ -1,4 +1,0 @@
-      COMMON/comgeomfi1/long(ngridmx),lati(ngridmx),area(ngridmx)
-      COMMON/comgeomfi2/ totarea
-
-      REAL long,lati,area,totarea
Index: trunk/LMDZ.GENERIC/libf/phystd/comgeomfi_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comgeomfi_h.F90	(revision 787)
+++ trunk/LMDZ.GENERIC/libf/phystd/comgeomfi_h.F90	(revision 787)
@@ -0,0 +1,10 @@
+
+       module comgeomfi_h
+
+       implicit none
+
+       REAL,ALLOCATABLE,DIMENSION(:) :: long,lati,area
+       REAL :: totarea
+
+       end module comgeomfi_h
+
Index: trunk/LMDZ.GENERIC/libf/phystd/comsaison.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comsaison.h	(revision 786)
+++ 	(revision )
@@ -1,11 +1,0 @@
-!-----------------------------------------------------------------------
-!   INCLUDE saison.h
-
-      COMMON/saison/callsais,isaison,dist_star,declin,                   &
-     &             mu0(ngridmx),fract(ngridmx)
-
-      integer isaison
-      logical callsais
-      real dist_star,declin,mu0,fract
-
-!-----------------------------------------------------------------------
Index: trunk/LMDZ.GENERIC/libf/phystd/comsaison_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comsaison_h.F90	(revision 787)
+++ trunk/LMDZ.GENERIC/libf/phystd/comsaison_h.F90	(revision 787)
@@ -0,0 +1,12 @@
+
+       module comsaison_h
+
+       implicit none 
+
+       integer isaison
+       logical callsais
+       real dist_star,declin
+
+       real, allocatable, dimension(:) :: mu0,fract
+
+       end module comsaison_h
Index: trunk/LMDZ.GENERIC/libf/phystd/comsoil.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comsoil.h	(revision 786)
+++ 	(revision )
@@ -1,7 +1,0 @@
-      common/comsoil1/layer(nsoilmx),mlayer(0:nsoilmx-1)
-      common/comsoil2/inertiedat(ngridmx,nsoilmx),volcapa
-
-      real layer      ! soil layer depths
-      real mlayer     ! soil mid-layer depths
-      real inertiedat ! soil thermal inertia
-      real volcapa    ! soil volumetric heat capacity
Index: trunk/LMDZ.GENERIC/libf/phystd/comsoil_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comsoil_h.F90	(revision 787)
+++ trunk/LMDZ.GENERIC/libf/phystd/comsoil_h.F90	(revision 787)
@@ -0,0 +1,12 @@
+
+       module comsoil_h
+
+       implicit none
+
+       real,allocatable,dimension(:) :: layer      ! soil layer depths
+       real,allocatable,dimension(:) :: mlayer     ! soil mid-layer depths
+       real,allocatable,dimension(:,:) :: inertiedat ! soil thermal inertia
+       real volcapa    ! soil volumetric heat capacitya
+
+       end module comsoil_h
+
Index: trunk/LMDZ.GENERIC/libf/phystd/condense_cloud.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/condense_cloud.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/condense_cloud.F90	(revision 787)
@@ -10,4 +10,8 @@
       use radii_mod, only : co2_reffrad
       use aerosol_mod, only : iaero_co2
+      USE surfdat_h
+      USE comgeomfi_h
+      USE tracer_h
+
 
       implicit none
@@ -55,9 +59,6 @@
 #include "dimphys.h"
 #include "comcstfi.h"
-#include "surfdat.h"
-#include "comgeomfi.h"
 #include "comvert.h"
 #include "callkeys.h"
-#include "tracer.h"
 
 !-----------------------------------------------------------------------
@@ -80,5 +81,5 @@
       REAL pdu(ngrid,nlayer) , pdv(ngrid,nlayer)
       REAL pduc(ngrid,nlayer) , pdvc(ngrid,nlayer)
-      REAL pq(ngridmx,nlayer,nq),pdq(ngrid,nlayer,nq)
+      REAL pq(ngrid,nlayer,nq),pdq(ngrid,nlayer,nq)
       REAL pdqc(ngrid,nlayer,nq), pdqsc(ngrid,nq)
 
@@ -92,39 +93,39 @@
       INTEGER l,ig,icap,ilay,it,iq
 
-      REAL*8 zt(ngridmx,nlayermx)
-      REAL zq(ngridmx,nlayermx,nqmx)
+      REAL*8 zt(ngrid,nlayermx)
+      REAL zq(ngrid,nlayermx,nq)
       REAL zcpi
-      REAL ztcond (ngridmx,nlayermx)
-      REAL ztnuc (ngridmx,nlayermx)
-      REAL ztcondsol(ngridmx) 
-      REAL zdiceco2(ngridmx)
-      REAL zcondicea(ngridmx,nlayermx), zcondices(ngridmx)
-      REAL zfallice(ngridmx), Mfallice(ngridmx) 
+      REAL ztcond (ngrid,nlayermx)
+      REAL ztnuc (ngrid,nlayermx)
+      REAL ztcondsol(ngrid) 
+      REAL zdiceco2(ngrid)
+      REAL zcondicea(ngrid,nlayermx), zcondices(ngrid)
+      REAL zfallice(ngrid), Mfallice(ngrid) 
       REAL zmflux(nlayermx+1)
       REAL zu(nlayermx),zv(nlayermx)
-      REAL ztsrf(ngridmx)
+      REAL ztsrf(ngrid)
       REAL ztc(nlayermx), ztm(nlayermx+1) 
       REAL zum(nlayermx+1) , zvm(nlayermx+1)
-      LOGICAL condsub(ngridmx)
+      LOGICAL condsub(ngrid)
       REAL subptimestep
       Integer Ntime
-      real masse (ngridmx,nlayermx), w(ngridmx,nlayermx,nqmx)
-      real wq(ngridmx,nlayermx+1)
+      real masse (ngrid,nlayermx), w(ngrid,nlayermx,nq)
+      real wq(ngrid,nlayermx+1)
       real vstokes,reff
 
 !     Special diagnostic variables
-      real tconda1(ngridmx,nlayermx)
-      real tconda2(ngridmx,nlayermx)
-      real zdtsig (ngridmx,nlayermx)
-      real zdt (ngridmx,nlayermx)
+      real tconda1(ngrid,nlayermx)
+      real tconda2(ngrid,nlayermx)
+      real zdtsig (ngrid,nlayermx)
+      real zdt (ngrid,nlayermx)
 
 !-----------------------------------------------------------------------
 !     Saved local variables
 
-      REAL emisref(ngridmx)
       REAL latcond
       REAL ccond
       REAL cpice
-      SAVE emisref, cpice
+      REAL,SAVE,ALLOCATABLE,DIMENSION(:) :: emisref
+      SAVE cpice
       SAVE latcond,ccond
 
@@ -155,12 +156,14 @@
       call zerophys(ngrid*nlayer*nq,pdqc)
       call zerophys(ngrid*nlayer*nq,pdtc)
-      call zerophys(ngridmx*nlayermx*nqmx,zq)
-      call zerophys(ngridmx*nlayermx,zt)
+      call zerophys(ngrid*nlayermx*nq,zq)
+      call zerophys(ngrid*nlayermx,zt)
 
 !     Initialisation
       IF (firstcall) THEN
 
+         ALLOCATE(emisref(ngrid)) !! this should be deallocated in lastcall...
+
          ! find CO2 ice tracer
-         do iq=1,nqmx
+         do iq=1,nq
             tracername=noms(iq)
             if (tracername.eq."co2_ice") then
@@ -287,5 +290,5 @@
 !     Calculate the mass of each atmospheric layer (kg.m-2)
       do  ilay=1,nlayer
-         do ig=1, ngrid
+         DO ig=1,ngrid
             masse(ig,ilay)=(pplev(ig,ilay) - pplev(ig,ilay+1)) /g
          end do
@@ -312,8 +315,8 @@
             
 !     sedimentation computed from radius computed from q in module radii_mod
-	 call co2_reffrad(zq,reffrad)
+	 call co2_reffrad(ngrid,nq,zq,reffrad)
 	 
          do  ilay=1,nlayer
-            do ig=1, ngrid
+            DO ig=1,ngrid
 
                reff = reffrad(ig,ilay,iaero_co2)
@@ -337,5 +340,5 @@
 !     Progressively accumulating the flux to the ground
 !     Mfallice is the total amount of ice fallen to the ground
-         do ig=1,ngrid
+         DO ig=1,ngrid
             Mfallice(ig) =  Mfallice(ig) + wq(ig,i_co2ice)
          end do
@@ -463,5 +466,5 @@
 !     Surface albedo and emissivity of the ground below the snow (emisref)
 !     --------------------------------------------------------------------
-      do ig =1,ngrid
+      DO ig=1,ngrid
          IF(ig.GT.ngrid/2+1) THEN
             icap=2
Index: trunk/LMDZ.GENERIC/libf/phystd/convadj.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/convadj.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/convadj.F	(revision 787)
@@ -5,4 +5,6 @@
      &                   pduadj,pdvadj,pdhadj,
      &                   pdqadj)
+
+      USE tracer_h
 
       implicit none
@@ -31,5 +33,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "tracer.h"
 
 
@@ -54,11 +55,11 @@
 
       INTEGER ig,i,l,l1,l2,jj
-      INTEGER jcnt, jadrs(ngridmx)
+      INTEGER jcnt, jadrs(ngrid)
 
       REAL sig(nlayermx+1),sdsig(nlayermx),dsig(nlayermx)
-      REAL zu(ngridmx,nlayermx),zv(ngridmx,nlayermx)
-      REAL zh(ngridmx,nlayermx)
-      REAL zu2(ngridmx,nlayermx),zv2(ngridmx,nlayermx)
-      REAL zh2(ngridmx,nlayermx), zhc(ngridmx,nlayermx)
+      REAL zu(ngrid,nlayermx),zv(ngrid,nlayermx)
+      REAL zh(ngrid,nlayermx)
+      REAL zu2(ngrid,nlayermx),zv2(ngrid,nlayermx)
+      REAL zh2(ngrid,nlayermx), zhc(ngrid,nlayermx)
       REAL zhm,zsm,zdsm,zum,zvm,zalpha,zhmc
 
@@ -66,6 +67,6 @@
       INTEGER iq,ico2
       save ico2
-      REAL zq(ngridmx,nlayermx,nqmx), zq2(ngridmx,nlayermx,nqmx)
-      REAL zqm(nqmx),zqco2m
+      REAL zq(ngrid,nlayermx,nq), zq2(ngrid,nlayermx,nq)
+      REAL zqm(nq),zqco2m
       real m_co2, m_noco2, A , B
       save A, B
@@ -73,5 +74,5 @@
       real mtot1, mtot2 , mm1, mm2
        integer l1ref, l2ref
-      LOGICAL vtest(ngridmx),down,firstcall
+      LOGICAL vtest(ngrid),down,firstcall
       save firstcall
       data firstcall/.true./
@@ -87,14 +88,8 @@
 
       IF (firstcall) THEN 
-        IF(ngrid.NE.ngridmx) THEN
-           PRINT*
-           PRINT*,'STOP in convadj'
-           PRINT*,'ngrid    =',ngrid
-           PRINT*,'ngridmx  =',ngridmx
-        ENDIF
         ico2=0
         if (tracer) then
 !     Prepare Special treatment if one of the tracers is CO2 gas
-           do iq=1,nqmx
+           do iq=1,nq
              if (noms(iq).eq."co2") then
                 print*,'dont go there'
@@ -401,5 +396,5 @@
         do iq=1, nq
           do  l=1,nlay
-            do ig=1, ngrid
+            DO ig=1,ngrid
               pdqadj(ig,l,iq)=(zq2(ig,l,iq)-zq(ig,l,iq))/ptimestep 
             end do 
Index: trunk/LMDZ.GENERIC/libf/phystd/datareadnc.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/datareadnc.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/datareadnc.F	(revision 787)
@@ -85,6 +85,6 @@
       INTEGER    i,j,k
 
-      INTEGER klatdat,ngridmxgdat
-      PARAMETER (klatdat=180,ngridmxgdat=360)
+      INTEGER klatdat,ngridmixgdat
+      PARAMETER (klatdat=180,ngridmixgdat=360)
 
 c    on passe une grille en rlonu rlatv et im+1 jm a interp_horiz)
@@ -245,7 +245,7 @@
       do j=1,jmdp1
           do i=1,imd
-              zdataS(i+imdp1*(j-1)) = zdata(i+ngridmxgdat*(j-1))
+              zdataS(i+imdp1*(j-1)) = zdata(i+ngridmixgdat*(j-1))
           enddo
-          zdataS(imdp1+imdp1*(j-1)) = zdata(1+ngridmxgdat*(j-1))
+          zdataS(imdp1+imdp1*(j-1)) = zdata(1+ngridmixgdat*(j-1))
       enddo
 
Index: trunk/LMDZ.GENERIC/libf/phystd/dimphys.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/dimphys.h	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/dimphys.h	(revision 787)
@@ -12,2 +12,9 @@
       !integer, parameter :: nsoilmx = 13 ! for z1=0.03 cm, depth = 104.8 m => earth case
 !-----------------------------------------------------------------------
+
+      common/dimphys/cursor
+      integer cursor  !! this is the position of point 1 on the globe
+                      !! it is 1 obviously for sequential runs
+                      !! but might differ for paraller runs
+                      !! it is used in phyetat0 mostly
+
Index: trunk/LMDZ.GENERIC/libf/phystd/evap.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/evap.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/evap.F	(revision 787)
@@ -1,6 +1,7 @@
-      subroutine evap(dtime,pt, pq, pdq, pdt,  
+      subroutine evap(ngrid,nq,dtime,pt, pq, pdq, pdt,  
      $     dqevap,dtevap, qevap, tevap) 
         
       use watercommon_h 
+      USE tracer_h
 
       implicit none
@@ -8,5 +9,4 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "tracer.h"
 #include "comcstfi.h"
 
@@ -24,16 +24,18 @@
 !==================================================================
 
+      INTEGER ngrid,nq
+
 ! Arguments:
-      REAL pt(ngridmx,nlayermx) 
-      REAL pq(ngridmx,nlayermx,nqmx) 
-      REAL pdt(ngridmx,nlayermx) 
-      REAL pdq(ngridmx,nlayermx,nqmx) 
-      REAL dqevap(ngridmx,nlayermx)
-      REAL dtevap(ngridmx,nlayermx)
-      REAL qevap(ngridmx,nlayermx,nqmx)
+      REAL pt(ngrid,nlayermx) 
+      REAL pq(ngrid,nlayermx,nq) 
+      REAL pdt(ngrid,nlayermx) 
+      REAL pdq(ngrid,nlayermx,nq) 
+      REAL dqevap(ngrid,nlayermx)
+      REAL dtevap(ngrid,nlayermx)
+      REAL qevap(ngrid,nlayermx,nq)
       REAL dtime
  
 ! Local:
-      REAL tevap(ngridmx,nlayermx) 
+      REAL tevap(ngrid,nlayermx) 
       REAL zlvdcp
       REAL zlsdcp
@@ -46,5 +48,5 @@
 
       DO l=1,nlayermx
-        DO ig=1,ngridmx
+        DO ig=1,ngrid
          qevap(ig,l,igcm_h2o_vap)=pq(ig,l,igcm_h2o_vap)	
      s          	          +pdq(ig,l,igcm_h2o_vap)*dtime
@@ -56,5 +58,5 @@
 
       DO l = 1, nlayermx  
-      	DO ig = 1, ngridmx
+      	DO ig = 1, ngrid
          zlvdcp=RLVTT/RCPD!/(1.0+RVTMP2*qevap(ig,l,igcm_h2o_vap))
          zlsdcp=RLSTT/RCPD!/(1.0+RVTMP2*qevap(ig,l,igcm_h2o_vap))
Index: trunk/LMDZ.GENERIC/libf/phystd/fisice.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/fisice.h	(revision 786)
+++ 	(revision )
@@ -1,14 +1,0 @@
-!-----------------------------------------------------------------------
-! INCLUDE fisice.h
-
-      COMMON/fisice/dqsf,rice,nuice,rdust,zcondicea
-
-      REAL dqsf(nqmx)       ! tendance of tracer on surface (e.g. kg.m-2)
-      REAL rice(ngridmx,nlayermx) ! Estimated ice crystal radius (m)
-      REAL nuice(ngridmx,nlayermx) ! Estimated effective variance
-                                   !   of the size distribution
-                                   !   MODIF_JBM_08W45
-      REAL rdust(ngridmx,nlayermx) ! Prescribed dust radius in each layer (m) 
-! Variables used to define water ice scavenging by atmos. CO2 condensing
-      REAL zcondicea(ngridmx,nlayermx)
-!-----------------------------------------------------------------------
Index: trunk/LMDZ.GENERIC/libf/phystd/forceWCfn.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/forceWCfn.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/forceWCfn.F	(revision 787)
@@ -1,3 +1,5 @@
-      subroutine forceWCfn(pplev,pt,dq,dqs)
+      subroutine forceWCfn(ngrid,nq,pplev,pt,dq,dqs)
+
+      USE tracer_h
 
       implicit none
@@ -19,18 +21,19 @@
 #include "dimphys.h"
 #include "comcstfi.h"
-#include "tracer.h"
+
+      INTEGER ngrid,nq
 
       real masse, Wtot, Wdiff
 
-      real pplev(ngridmx,nlayermx+1)
-      real pt(ngridmx)
+      real pplev(ngrid,nlayermx+1)
+      real pt(ngrid)
 
-      real dqs(ngridmx,nqmx) 
-      real dq(ngridmx,nlayermx,nqmx)
+      real dqs(ngrid,nq) 
+      real dq(ngrid,nlayermx,nq)
 
       integer iq, ig, ilay
 
-      do iq=1,nqmx 
-        do ig=1,ngridmx
+      do iq=1,nq 
+        do ig=1,ngrid
            Wtot = 0.0
            do ilay=1,nlayermx
Index: trunk/LMDZ.GENERIC/libf/phystd/hydrol.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/hydrol.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/hydrol.F90	(revision 787)
@@ -1,7 +1,11 @@
-subroutine hydrol(ptimestep,rnat,tsurf,          &
+subroutine hydrol(ngrid,nq,ptimestep,rnat,tsurf,          &
      qsurf,dqsurf,dqs_hyd,pcapcal,                &
      albedo0,albedo,mu0,pdtsurf,pdtsurf_hyd,hice)
 
   use watercommon_h, only: T_h2O_ice_liq, RLFTT, rhowater, mx_eau_sol
+  USE surfdat_h
+  use comdiurn_h
+  USE comgeomfi_h
+  USE tracer_h
 
   implicit none
@@ -36,9 +40,6 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "tracer.h"
-#include "fisice.h"
-#include "comgeomfi.h"
-#include "comdiurn.h"
-#include "surfdat.h"
+
+      integer ngrid,nq
 
 !     Inputs
@@ -60,16 +61,15 @@
 !     Arguments
 !     ---------
-      integer rnat(ngridmx) ! I changed this to integer (RW)
-      real runoff(ngridmx)
-      save runoff
+      integer rnat(ngrid) ! I changed this to integer (RW)
+      real,dimension(:),allocatable,save :: runoff
       real totalrunoff, tsea, oceanarea
       save oceanarea
 
       real ptimestep
-      real mu0(ngridmx)
-      real qsurf(ngridmx,nqmx), tsurf(ngridmx)
-      real dqsurf(ngridmx,nqmx), pdtsurf(ngridmx)
-      real hice(ngridmx)
-      real albedo0(ngridmx), albedo(ngridmx)
+      real mu0(ngrid)
+      real qsurf(ngrid,nq), tsurf(ngrid)
+      real dqsurf(ngrid,nq), pdtsurf(ngrid)
+      real hice(ngrid)
+      real albedo0(ngrid), albedo(ngrid)
 
       real oceanarea2
@@ -77,6 +77,6 @@
 !     Output
 !     ------
-      real dqs_hyd(ngridmx,nqmx)
-      real pdtsurf_hyd(ngridmx)
+      real dqs_hyd(ngrid,nq)
+      real pdtsurf_hyd(ngrid)
 
 !     Local
@@ -85,9 +85,9 @@
       integer ig,iq, icap ! wld like to remove icap
       real fsnoi, subli, fauxo
-      real twater(ngridmx)
-      real pcapcal(ngridmx)
-      real hicebis(ngridmx)
-      real zqsurf(ngridmx,nqmx)
-      real ztsurf(ngridmx)
+      real twater(ngrid)
+      real pcapcal(ngrid)
+      real hicebis(ngrid)
+      real zqsurf(ngrid,nq)
+      real ztsurf(ngrid)
 
       integer ivap, iliq, iice
@@ -104,4 +104,6 @@
 
       if(firstcall)then
+
+         ALLOCATE(runoff(ngrid))
 
          ivap=igcm_h2o_vap
@@ -126,5 +128,5 @@
 !     Total ocean surface area
          oceanarea=0.
-         do ig=1,ngridmx
+         do ig=1,ngrid
             if(rnat(ig).eq.0)then
                oceanarea=oceanarea+area(ig)
@@ -150,19 +152,19 @@
 !     ------------------------------------------
 
-      do ig=1,ngridmx
+      do ig=1,ngrid
          ztsurf(ig) = tsurf(ig) + ptimestep*pdtsurf(ig)
          pdtsurf_hyd(ig)=0.0
-         do iq=1,nqmx
+         do iq=1,nq
             zqsurf(ig,iq) = qsurf(ig,iq) + ptimestep*dqsurf(ig,iq)
          enddo    
       enddo
  
-      do ig=1,ngridmx
-         do iq=1,nqmx
+      do ig=1,ngrid
+         do iq=1,nq
             dqs_hyd(ig,iq) = 0.0
          enddo
       enddo
 
-      do ig = 1, ngridmx
+      do ig = 1, ngrid
 
 !     Ocean
@@ -257,5 +259,5 @@
 
                runoff(ig) = max(zqsurf(ig,iliq) - mx_eau_sol, 0.0)
-               if(ngridmx.gt.1)then ! runoff only exists in 3D
+               if(ngrid.gt.1)then ! runoff only exists in 3D
                   if(runoff(ig).ne.0.0)then
                      zqsurf(ig,iliq) = mx_eau_sol
@@ -283,5 +285,5 @@
          endif
 
-      end do ! ig=1,ngridmx
+      end do ! ig=1,ngrid
 
 !     perform crude bulk averaging of temperature in ocean
@@ -290,5 +292,5 @@
 
          oceanarea2=0.       
-         DO ig=1,ngridmx
+         DO ig=1,ngrid
             if((rnat(ig).eq.0).and.(hice(ig).eq.0.))then
                oceanarea2=oceanarea2+area(ig)*pcapcal(ig)
@@ -297,5 +299,5 @@
        
          tsea=0.
-         DO ig=1,ngridmx
+         DO ig=1,ngrid
             if((rnat(ig).eq.0).and.(hice(ig).eq.0.))then       
                tsea=tsea+ztsurf(ig)*area(ig)*pcapcal(ig)/oceanarea2
@@ -303,5 +305,5 @@
          END DO
 
-         DO ig=1,ngridmx
+         DO ig=1,ngrid
             if((rnat(ig).eq.0).and.(hice(ig).eq.0))then
                pdtsurf_hyd(ig) = pdtsurf_hyd(ig) + (tsea-ztsurf(ig))/oceantime
@@ -318,5 +320,5 @@
 
          totalrunoff=0.
-         do ig=1,ngridmx
+         do ig=1,ngrid
             if (rnat(ig).eq.1) then
                totalrunoff = totalrunoff + area(ig)*runoff(ig)
@@ -324,5 +326,5 @@
          enddo
          
-         do ig=1,ngridmx
+         do ig=1,ngrid
             if (rnat(ig).eq.0) then
                zqsurf(ig,iliq) = zqsurf(ig,iliq) + &
@@ -338,5 +340,5 @@
 
          icap=1
-         do ig=1,ngridmx
+         do ig=1,ngrid
             if (qsurf(ig,igcm_co2_ice).gt.0) then
                albedo(ig) = albedice(icap)
@@ -347,10 +349,10 @@
 
 
-      do ig=1,ngridmx
+      do ig=1,ngrid
          dqs_hyd(ig,iliq)=(zqsurf(ig,iliq) - qsurf(ig,iliq))/ptimestep
          dqs_hyd(ig,iice)=(zqsurf(ig,iice) - qsurf(ig,iice))/ptimestep
       enddo
 
-      call writediagfi(ngridmx,'runoff','Runoff amount',' ',2,runoff)
+      call writediagfi(ngrid,'runoff','Runoff amount',' ',2,runoff)
 
       return
Index: trunk/LMDZ.GENERIC/libf/phystd/inifis.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/inifis.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/inifis.F	(revision 787)
@@ -6,4 +6,11 @@
       use radinc_h, only : naerkind
       use datafile_mod, only: datadir
+      use comdiurn_h
+
+      !! to be conservative, but why this include here?
+      use surfdat_h
+      use comsaison_h
+
+      USE comgeomfi_h
 
 !=======================================================================
@@ -50,9 +57,5 @@
 #include "planete.h"
 #include "comcstfi.h"
-#include "comsaison.h"
-#include "comdiurn.h"
-#include "comgeomfi.h"
 #include "callkeys.h"
-#include "surfdat.h"
 
 
@@ -61,5 +64,5 @@
  
       INTEGER ngrid,nlayer
-      REAL plat(ngrid),plon(ngrid),parea(ngridmx)
+      REAL plat(ngrid),plon(ngrid),parea(ngrid)
       integer day_ini
       INTEGER ig,ierr
@@ -87,4 +90,6 @@
       avocado = 6.02214179e23   ! added by RW
 
+      cursor = 1 ! added by AS in dimphys. 1 for sequential runs.
+
 ! --------------------------------------------------------
 !     The usual Tests
@@ -95,12 +100,4 @@
          PRINT*,'nlayer     = ',nlayer
          PRINT*,'nlayermx   = ',nlayermx
-         STOP
-      ENDIF
-
-      IF (ngrid.NE.ngridmx) THEN
-         PRINT*,'STOP in inifis'
-         PRINT*,'Probleme de dimensions :'
-         PRINT*,'ngrid     = ',ngrid
-         PRINT*,'ngridmx   = ',ngridmx
          STOP
       ENDIF
@@ -299,5 +296,5 @@
 ! Test of incompatibility:
 ! if kastprof used, we must be in 1D
-         if (kastprof.and.(ngridmx.gt.1)) then
+         if (kastprof.and.(ngrid.gt.1)) then
            print*,'kastprof can only be used in 1D!'
            call abort
@@ -350,5 +347,5 @@
 ! Test of incompatibility:
 ! if testradtimes used, we must be in 1D
-         if (testradtimes.and.(ngridmx.gt.1)) then
+         if (testradtimes.and.(ngrid.gt.1)) then
            print*,'testradtimes can only be used in 1D!'
            call abort
@@ -595,8 +592,19 @@
 !     ------------------------
 
+      ! ALLOCATE ARRAYS IN comgeomfi_h
+      IF (.not. ALLOCATED(lati)) ALLOCATE(lati(ngrid))
+      IF (.not. ALLOCATED(long)) ALLOCATE(long(ngrid))
+      IF (.not. ALLOCATED(area)) ALLOCATE(area(ngrid))
+
       CALL SCOPY(ngrid,plon,1,long,1)
       CALL SCOPY(ngrid,plat,1,lati,1)
       CALL SCOPY(ngrid,parea,1,area,1)
-      totarea=SSUM(ngridmx,area,1)
+      totarea=SSUM(ngrid,area,1)
+
+      !! those are defined in comdiurn_h.F90
+      IF (.not.ALLOCATED(sinlat)) ALLOCATE(sinlat(ngrid))
+      IF (.not.ALLOCATED(coslat)) ALLOCATE(coslat(ngrid))
+      IF (.not.ALLOCATED(sinlon)) ALLOCATE(sinlon(ngrid))
+      IF (.not.ALLOCATED(coslon)) ALLOCATE(coslon(ngrid))
 
       DO ig=1,ngrid
Index: trunk/LMDZ.GENERIC/libf/phystd/initracer.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/initracer.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/initracer.F	(revision 787)
@@ -1,5 +1,7 @@
-      SUBROUTINE initracer()
-
-
+      SUBROUTINE initracer(ngrid,nq,nametrac)
+
+      use surfdat_h
+      USE comgeomfi_h
+      USE tracer_h
       IMPLICIT NONE
 c=======================================================================
@@ -13,5 +15,5 @@
 c   Test of dimension :
 c   Initialize COMMON tracer in tracer.h, using tracer names provided
-c   by the dynamics in "advtrac.h"
+c   by the argument nametrac
 c
 c   author: F.Forget
@@ -25,12 +27,9 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "tracer.h"
-#include "advtrac.h"
-#include "comgeomfi.h"
-#include "watercap.h"
-#include "fisice.h"
-
-!      real qsurf(ngridmx,nqmx)       ! tracer on surface (e.g.  kg.m-2)
-!      real co2ice(ngridmx)           ! co2 ice mass on surface (e.g.  kg.m-2)
+
+      integer :: ngrid,nq
+
+!      real qsurf(ngrid,nq)       ! tracer on surface (e.g.  kg.m-2)
+!      real co2ice(ngrid)           ! co2 ice mass on surface (e.g.  kg.m-2)
       character(len=20) :: txt ! to store some text
       integer iq,ig,count
@@ -38,11 +37,13 @@
 !      logical :: oldnames ! =.true. if old tracer naming convention (q01,...)
 
+      character*20 nametrac(nq)   ! name of the tracer from dynamics
+
 
 c-----------------------------------------------------------------------
-c  radius(nqmx)      ! aerosol particle radius (m)
-c  rho_q(nqmx)       ! tracer densities (kg.m-3)
-c  qext(nqmx)        ! Single Scat. Extinction coeff at 0.67 um
-c  alpha_lift(nqmx)  ! saltation vertical flux/horiz flux ratio (m-1)
-c  alpha_devil(nqmx) ! lifting coeeficient by dust devil
+c  radius(nq)      ! aerosol particle radius (m)
+c  rho_q(nq)       ! tracer densities (kg.m-3)
+c  qext(nq)        ! Single Scat. Extinction coeff at 0.67 um
+c  alpha_lift(nq)  ! saltation vertical flux/horiz flux ratio (m-1)
+c  alpha_devil(nq) ! lifting coeeficient by dust devil
 c  rho_dust          ! Mars dust density
 c  rho_ice           ! Water ice density
@@ -51,4 +52,19 @@
 c-----------------------------------------------------------------------
 
+       !! we allocate once for all arrays in common in tracer_h.F90
+       !! (supposedly those are not used before call to initracer)
+       ALLOCATE(noms(nq))
+       ALLOCATE(mmol(nq))
+       ALLOCATE(radius(nq))
+       ALLOCATE(rho_q(nq))
+       ALLOCATE(qext(nq))
+       ALLOCATE(alpha_lift(nq))
+       ALLOCATE(alpha_devil(nq))
+       ALLOCATE(qextrhor(nq))
+       ALLOCATE(igcm_dustbin(nq))
+       !! initialization
+       alpha_lift(:)=0.
+       alpha_devil(:)=0.
+
 ! Initialization: get tracer names from the dynamics and check if we are
 !                 using 'old' tracer convention ('q01',q02',...)
@@ -57,6 +73,6 @@
 
 ! copy tracer names from dynamics
-        do iq=1,nqmx
-          noms(iq)=tnom(iq)
+        do iq=1,nq
+          noms(iq)=nametrac(iq)
         enddo
 
@@ -65,5 +81,5 @@
       ! 0. initialize tracer indexes to zero:
       ! NB: igcm_* indexes are commons in 'tracer.h'
-      do iq=1,nqmx
+      do iq=1,nq
         igcm_dustbin(iq)=0
       enddo
@@ -97,5 +113,5 @@
       count=0
 !      if (dustbin.gt.0) then
-!        do iq=1,nqmx
+!        do iq=1,nq
 !          txt=" "
 !          write(txt,'(a4,i2.2)')'dust',count+1   
@@ -105,10 +121,10 @@
 !            mmol(iq)=100.
 !          endif
-!        enddo !do iq=1,nqmx
+!        enddo !do iq=1,nq
 !      endif ! of if (dustbin.gt.0)
 
 
 !      if (doubleq) then
-!        do iq=1,nqmx
+!        do iq=1,nq
 !          if (noms(iq).eq."dust_mass") then
 !            igcm_dust_mass=iq
@@ -122,5 +138,5 @@
 !      endif ! of if (doubleq)
       ! 2. find chemistry and water tracers
-      do iq=1,nqmx
+      do iq=1,nq
         if (noms(iq).eq."co2") then
           igcm_co2=iq
@@ -147,10 +163,10 @@
 !          write(*,*) 'h2o_ice: count=',count
         endif
-      enddo ! of do iq=1,nqmx
+      enddo ! of do iq=1,nq
       
       ! check that we identified all tracers:
-      if (count.ne.nqmx) then
+      if (count.ne.nq) then
         write(*,*) "initracer: found only ",count," tracers"
-        write(*,*) "               expected ",nqmx
+        write(*,*) "               expected ",nq
         do iq=1,count
           write(*,*)'      ',iq,' ',trim(noms(iq))
@@ -159,5 +175,5 @@
       else
         write(*,*) "initracer: found all expected tracers, namely:"
-        do iq=1,nqmx
+        do iq=1,nq
           write(*,*)'      ',iq,' ',trim(noms(iq))
         enddo
@@ -168,5 +184,5 @@
 c     Initialisation tracers ....
 c------------------------------------------------------------
-      call zerophys(nqmx,rho_q)
+      call zerophys(nq,rho_q)
 
       rho_dust=2500.  ! Mars dust density (kg.m-3)
@@ -182,6 +198,6 @@
 c$$$c       iq=1: Q mass mixing ratio, iq=2: N number mixing ratio
 c$$$
-c$$$        if( (nqmx.lt.2).or.(water.and.(nqmx.lt.3)) ) then
-c$$$          write(*,*)'initracer: nqmx is too low : nqmx=', nqmx
+c$$$        if( (nq.lt.2).or.(water.and.(nq.lt.3)) ) then
+c$$$          write(*,*)'initracer: nq is too low : nq=', nq
 c$$$          write(*,*)'water= ',water,' doubleq= ',doubleq   
 c$$$        end if
@@ -259,10 +275,15 @@
 
 
-!         if(ngridmx.eq.1)
+!         if(ngrid.eq.1)
 
 
 !     to be modified for BC+ version?
-         do ig=1,ngridmx
-           if (ngridmx.ne.1) watercaptag(ig)=.false.
+
+         !! this is defined in surfdat_h.F90
+         IF (.not.ALLOCATED(dryness)) ALLOCATE(dryness(ngrid))
+         IF (.not.ALLOCATED(watercaptag)) ALLOCATE(watercaptag(ngrid))
+
+         do ig=1,ngrid
+           if (ngrid.ne.1) watercaptag(ig)=.false.
            dryness(ig) = 1.
          enddo
@@ -274,22 +295,22 @@
 c Perennial H20 north cap defined by watercaptag=true (allows surface to be
 c hollowed by sublimation in vdifc).
-!         do ig=1,ngridmx
+!         do ig=1,ngrid
 !           if (lati(ig)*180./pi.gt.84) then
-!             if (ngridmx.ne.1) watercaptag(ig)=.true.
+!             if (ngrid.ne.1) watercaptag(ig)=.true.
 !             dryness(ig) = 1.
 c Use the following cap definition for high spatial resolution (latitudinal bin <= 5 deg)
 c	      if (lati(ig)*180./pi.lt.85.and.long(ig).ge.0) then
-c	        if (ngridmx.ne.1) watercaptag(ig)=.true.
+c	        if (ngrid.ne.1) watercaptag(ig)=.true.
 c               dryness(ig) = 1.
 c	      endif
 c             if (lati(ig)*180./pi.ge.85) then
-c               if (ngridmx.ne.1) watercaptag(ig)=.true.
+c               if (ngrid.ne.1) watercaptag(ig)=.true.
 c               dryness(ig) = 1.
 c	      endif
 !           endif  ! (lati>80 deg)
-!         end do ! (ngridmx)
+!         end do ! (ngrid)
 !        ENDIF ! (caps)
 
-!         if(iceparty.and.(nqmx.ge.2)) then
+!         if(iceparty.and.(nq.ge.2)) then
 
            radius(igcm_h2o_ice)=3.e-6
@@ -303,6 +324,6 @@
 
 
-!         elseif(iceparty.and.(nqmx.lt.2)) then
-!            write(*,*) 'nqmx is too low : nqmx=', nqmx
+!         elseif(iceparty.and.(nq.lt.2)) then
+!            write(*,*) 'nq is too low : nq=', nq
 !            write(*,*) 'water= ',water,' iceparty= ',iceparty
 !         endif
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwrite.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwrite.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwrite.F	(revision 787)
@@ -1,3 +1,6 @@
       SUBROUTINE iniwrite(nid,idayref,phis)
+
+      USE comsoil_h
+
       IMPLICIT NONE
 
@@ -31,5 +34,4 @@
 #include "serre.h"
 #include"dimphys.h"
-#include"comsoil.h"
 
 c   Arguments:
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F	(revision 787)
@@ -3,4 +3,5 @@
       use radinc_h, only: L_NSPECTI
       use radcommon_h, only: WNOI,DWNI
+      use comsoil_h
 
       implicit none
@@ -35,5 +36,4 @@
 #include "serre.h"
 #include"dimphys.h"
-#include"comsoil.h"
 
 c   Arguments:
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F	(revision 787)
@@ -3,4 +3,5 @@
       use radinc_h, only: L_NSPECTV
       use radcommon_h, only: WNOV,DWNV
+      use comsoil_h
 
       implicit none
@@ -35,5 +36,4 @@
 #include "serre.h"
 #include"dimphys.h"
-#include"comsoil.h"
 
 c   Arguments:
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90	(revision 787)
@@ -1,3 +1,5 @@
-subroutine iniwritesoil(nid)
+subroutine iniwritesoil(nid,ngrid)
+
+use comsoil_h
 
 ! initialization routine for 'writediagoil'. Here we create/define
@@ -12,8 +14,8 @@
 #include"comcstfi.h"
 #include"comgeom.h"
-#include"comsoil.h"
 #include"netcdf.inc"
 
 ! Arguments:
+integer,intent(in) :: ngrid
 integer,intent(in) :: nid ! NetCDF output file ID
 
@@ -246,6 +248,7 @@
   do i=1,iip1
     data3(i,1,l)=inertiedat(1,l)
-    data3(i,jjp1,l)=inertiedat(ngridmx,l)
+    data3(i,jjp1,l)=inertiedat(ngrid,l)
   enddo
+  !!! THIS WILL NOT WORK IN PARALLEL !!!!
   ! rest of the grid
   do j=2,jjm
Index: trunk/LMDZ.GENERIC/libf/phystd/kcm1d.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/kcm1d.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/kcm1d.F90	(revision 787)
@@ -5,4 +5,5 @@
   use watercommon_h, only: mH2O
   use ioipsl_getincom 
+  use comsaison_h
 
   implicit none
@@ -31,7 +32,5 @@
 #include "comcstfi.h"
 #include "planete.h"
-#include "comsaison.h"
 #include "control.h"
-#include "advtrac.h"
 
   ! --------------------------------------------------------------
@@ -71,10 +70,12 @@
   real dTstrat
   real aerosol(nlayermx,naerkind) ! aerosol tau (kg/kg)
-  real OLR_nu(ngridmx,L_NSPECTI)
-  real OSR_nu(ngridmx,L_NSPECTV)
+  real OLR_nu(1,L_NSPECTI)
+  real OSR_nu(1,L_NSPECTV)
   real Eatmtot
 
   integer ierr
   logical firstcall,lastcall,global1d
+
+  character*20 nametrac(nqmx)   ! name of the tracer (no need for adv trac common)
 
   ! --------------
@@ -92,4 +93,9 @@
   nlayer=nlayermx
   nlevel=nlayer+1
+
+  !! this is defined in comsaison_h
+  ALLOCATE(mu0(1))
+  ALLOCATE(fract(1))
+
 
 
@@ -224,5 +230,5 @@
         do iq=1,nq
            ! minimal version, just read in the tracer names, 1 per line
-           read(90,*,iostat=ierr) tnom(iq)
+           read(90,*,iostat=ierr) nametrac(iq)
            if (ierr.ne.0) then
               write(*,*) 'kcm1d: error reading tracer names...'
@@ -232,10 +238,10 @@
      endif
 
-     call initracer()
+     call initracer(1,nq,nametrac)
 
   endif
 
 
-  do iq=1,nqmx
+  do iq=1,nq
      do ilay=1,nlayer
         q(ilay,iq) = 0.
@@ -243,5 +249,5 @@
   enddo
 
-  do iq=1,nqmx
+  do iq=1,nq
      qsurf(iq) = 0.
   enddo
@@ -265,9 +271,9 @@
 
      !    Run radiative transfer
-     call callcorrk(ngridmx,nlayer,q,nqmx,qsurf,      &
+     call callcorrk(1,nlayer,q,nq,qsurf,      &
           albedo,emis,mu0,plev,play,temp,                    &
           tsurf,fract,dist_star,aerosol,muvar,         &
           dtlw,dtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,    &
-          fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,reffrad,tau_col,  &
+          fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,reffrad,nueffrad,tau_col,  &
           cloudfrac,totcloudfrac,.false.,firstcall,lastcall)
 
@@ -298,10 +304,10 @@
   firstcall=.false.
   lastcall=.true.
-  call callcorrk(ngridmx,nlayer,q,nqmx,qsurf,      &
+  call callcorrk(1,nlayer,q,nq,qsurf,      &
        albedo,emis,mu0,plev,play,temp,                    &
        tsurf,fract,dist_star,aerosol,muvar,         &
        dtlw,dtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,    &
        fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,             &
-       reffrad,tau_col,  &
+       reffrad,nueffrad,tau_col,  &
        cloudfrac,totcloudfrac,.false.,firstcall,lastcall)
 
Index: trunk/LMDZ.GENERIC/libf/phystd/largescale.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/largescale.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/largescale.F90	(revision 787)
@@ -1,7 +1,8 @@
-      subroutine largescale(ptimestep, pplev, pplay, pt, pq,   &
+      subroutine largescale(ngrid,nq,ptimestep, pplev, pplay, pt, pq,   &
                         pdt, pdq, pdtlsc, pdqvaplsc, pdqliqlsc, rneb)
 
       use watercommon_h, only : RLVTT, RCPD, RVTMP2,  &
           T_h2O_ice_clouds,T_h2O_ice_liq,Psat_water,Lcpdqsat_water
+      USE tracer_h
       IMPLICIT none
 
@@ -23,22 +24,20 @@
 #include "comcstfi.h"
 
-#include "fisice.h"
 #include "callkeys.h"
-#include "tracer.h"
 
-
+      INTEGER ngrid,nq
 
 !     Arguments
       REAL ptimestep                 ! intervalle du temps (s)
-      REAL pplev(ngridmx,nlayermx+1) ! pression a inter-couche
-      REAL pplay(ngridmx,nlayermx)   ! pression au milieu de couche
-      REAL pt(ngridmx,nlayermx)      ! temperature (K)
-      real pq(ngridmx,nlayermx,nqmx) ! tracer mixing ratio (kg/kg)
-      REAL pdt(ngridmx,nlayermx)     ! physical temperature tenedency (K/s)
-      REAL pdq(ngridmx,nlayermx,nqmx)! physical tracer tenedency (K/s)
-      REAL pdtlsc(ngridmx,nlayermx)  ! incrementation de la temperature (K)
-      REAL pdqvaplsc(ngridmx,nlayermx) ! incrementation de la vapeur d'eau
-      REAL pdqliqlsc(ngridmx,nlayermx) ! incrementation de l'eau liquide
-      REAL rneb(ngridmx,nlayermx)    ! fraction nuageuse
+      REAL pplev(ngrid,nlayermx+1) ! pression a inter-couche
+      REAL pplay(ngrid,nlayermx)   ! pression au milieu de couche
+      REAL pt(ngrid,nlayermx)      ! temperature (K)
+      real pq(ngrid,nlayermx,nq) ! tracer mixing ratio (kg/kg)
+      REAL pdt(ngrid,nlayermx)     ! physical temperature tenedency (K/s)
+      REAL pdq(ngrid,nlayermx,nq)! physical tracer tenedency (K/s)
+      REAL pdtlsc(ngrid,nlayermx)  ! incrementation de la temperature (K)
+      REAL pdqvaplsc(ngrid,nlayermx) ! incrementation de la vapeur d'eau
+      REAL pdqliqlsc(ngrid,nlayermx) ! incrementation de l'eau liquide
+      REAL rneb(ngrid,nlayermx)    ! fraction nuageuse
 
 
@@ -53,29 +52,29 @@
       INTEGER,PARAMETER :: nitermax=1000
       REAL,PARAMETER :: alpha=.5,qthreshold=1.e-6
-      REAL zt(ngridmx), zq(ngridmx)
-      REAL zcond(ngridmx),zcond_iter
-      REAL zdelq(ngridmx)
-      REAL zqs(ngridmx), zdqs(ngridmx)
+      REAL zt(ngrid), zq(ngrid)
+      REAL zcond(ngrid),zcond_iter
+      REAL zdelq(ngrid)
+      REAL zqs(ngrid), zdqs(ngrid)
       REAL psat_tmp
       
 ! evaporation calculations
-      REAL dqevap(ngridmx,nlayermx),dtevap(ngridmx,nlayermx)     
-      REAL qevap(ngridmx,nlayermx,nqmx)
-      REAL tevap(ngridmx,nlayermx)
+      REAL dqevap(ngrid,nlayermx),dtevap(ngrid,nlayermx)     
+      REAL qevap(ngrid,nlayermx,nq)
+      REAL tevap(ngrid,nlayermx)
 
-      REAL zcor(ngridmx), zdelta(ngridmx), zcvm5(ngridmx)
-      REAL zx_q(ngridmx)
+      REAL zcor(ngrid), zdelta(ngrid), zcvm5(ngrid)
+      REAL zx_q(ngrid)
       REAL Nmix_local,zfice
 
 !     GCM -----> subroutine variables, initialisation of outputs
 
-      pdtlsc(1:ngridmx,1:nlayermx)  = 0.0
-      pdqvaplsc(1:ngridmx,1:nlayermx)  = 0.0
-      pdqliqlsc(1:ngridmx,1:nlayermx) = 0.0
-      rneb(1:ngridmx,1:nlayermx) = 0.0
+      pdtlsc(1:ngrid,1:nlayermx)  = 0.0
+      pdqvaplsc(1:ngrid,1:nlayermx)  = 0.0
+      pdqliqlsc(1:ngrid,1:nlayermx) = 0.0
+      rneb(1:ngrid,1:nlayermx) = 0.0
 
 
       ! Evaporate cloud water/ice
-      call evap(ptimestep,pt,pq,pdq,pdt,dqevap,dtevap,qevap,tevap)
+      call evap(ngrid,nq,ptimestep,pt,pq,pdq,pdt,dqevap,dtevap,qevap,tevap)
       ! note: we use qevap but not tevap in largescale/moistadj
             ! otherwise is a big mess
@@ -85,10 +84,10 @@
    DO k = nlayermx, 1, -1
 
-      zt(1:ngridmx)=pt(1:ngridmx,k)+(pdt(1:ngridmx,k)+dtevap(1:ngridmx,k))*ptimestep
-      zq(1:ngridmx)=qevap(1:ngridmx,k,igcm_h2o_vap) !liquid water is included in qevap
+      zt(1:ngrid)=pt(1:ngrid,k)+(pdt(1:ngrid,k)+dtevap(1:ngrid,k))*ptimestep
+      zq(1:ngrid)=qevap(1:ngrid,k,igcm_h2o_vap) !liquid water is included in qevap
 
 !     Calculer la vapeur d'eau saturante et 
 !     determiner la condensation partielle
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
 
          if(zt(i).le.15.) then
@@ -150,7 +149,7 @@
 
 !     Tendances de t et q
-         pdqvaplsc(1:ngridmx,k)  = dqevap(1:ngridmx,k) - zcond(1:ngridmx)
-         pdqliqlsc(1:ngridmx,k) = - pdqvaplsc(1:ngridmx,k)
-         pdtlsc(1:ngridmx,k)  = pdqliqlsc(1:ngridmx,k)*RLVTT/RCPD
+         pdqvaplsc(1:ngrid,k)  = dqevap(1:ngrid,k) - zcond(1:ngrid)
+         pdqliqlsc(1:ngrid,k) = - pdqvaplsc(1:ngrid,k)
+         pdtlsc(1:ngrid,k)  = pdqliqlsc(1:ngrid,k)*RLVTT/RCPD
 
    Enddo ! k= nlayermx, 1, -1
Index: trunk/LMDZ.GENERIC/libf/phystd/mass_redistribution.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/mass_redistribution.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/mass_redistribution.F90	(revision 787)
@@ -5,4 +5,7 @@
                                                    
        USE watercommon_h, Only: Tsat_water,RLVTT
+       use surfdat_h
+       USE comgeomfi_h
+       USE tracer_h
 
        IMPLICIT NONE
@@ -49,10 +52,7 @@
 #include "dimphys.h"
 #include "comcstfi.h"
-#include "surfdat.h"
-#include "comgeomfi.h"
 #include "comvert.h"
 #include "paramet.h"
 #include "callkeys.h"
-#include "tracer.h"
 
 !-----------------------------------------------------------------------
@@ -61,6 +61,6 @@
       INTEGER ngrid, nlayer, nq   
       REAL ptimestep
-      REAL pcapcal(ngridmx)
-      INTEGER rnat(ngridmx)      
+      REAL pcapcal(ngrid)
+      INTEGER rnat(ngrid)      
       REAL pplay(ngrid,nlayer),pplev(ngrid,nlayer+1)
       REAL pt(ngrid,nlayer),pdt(ngrid,nlayer)
@@ -71,6 +71,6 @@
       REAL pdmassmr(ngrid,nlayer)
       REAL pdumr(ngrid,nlayer) , pdvmr(ngrid,nlayer)
-      REAL pq(ngridmx,nlayer,nq),pdq(ngrid,nlayer,nq)
-      REAL pqs(ngridmx,nq)
+      REAL pq(ngrid,nlayer,nq),pdq(ngrid,nlayer,nq)
+      REAL pqs(ngrid,nq)
       REAL pdqmr(ngrid,nlayer,nq),pdqsmr(ngrid,nq)
       REAL pdpsrfmr(ngrid),pdtsrfmr(ngrid)
@@ -80,5 +80,5 @@
 
 !    Boiling/sublimation
-      REAL Tsat(ngridmx),zmassboil(ngridmx)
+      REAL Tsat(ngrid),zmassboil(ngrid)
 
 !    vertical reorganization of sigma levels
@@ -87,13 +87,13 @@
 !    Dummy variables      
       INTEGER n,l,ig,iq
-      REAL zdtsig(ngridmx,nlayermx)
-      REAL zmass(ngridmx,nlayermx),zzmass(nlayermx),w(nlayermx+1)
-      REAL zdmass_sum(ngridmx,nlayermx+1)
+      REAL zdtsig(ngrid,nlayermx)
+      REAL zmass(ngrid,nlayermx),zzmass(nlayermx),w(nlayermx+1)
+      REAL zdmass_sum(ngrid,nlayermx+1)
       REAL zmflux(nlayermx+1)
       REAL zq1(nlayermx)
-      REAL ztsrf(ngridmx)
+      REAL ztsrf(ngrid)
       REAL ztm(nlayermx+1) 
       REAL zum(nlayermx+1) , zvm(nlayermx+1)
-      REAL zqm(nlayermx+1,nqmx),zqm1(nlayermx+1)
+      REAL zqm(nlayermx+1,nq),zqm1(nlayermx+1)
 
 !   local saved variables
@@ -120,7 +120,7 @@
 !     Surface tracer Tendencies set to 0
 !     -------------------------------------
-      pdqsmr(1:ngridmx,1:nqmx)=0.
-
-      ztsrf(1:ngridmx) = ptsrf(1:ngridmx) + pdtsrf(1:ngridmx)*ptimestep
+      pdqsmr(1:ngrid,1:nq)=0.
+
+      ztsrf(1:ngrid) = ptsrf(1:ngrid) + pdtsrf(1:ngrid)*ptimestep
 
 
@@ -135,10 +135,10 @@
 
       if (water) then
-         do ig=1,ngridmx
+         do ig=1,ngrid
 	    call Tsat_water(pplev(ig,1)+zdmass_sum(ig,1)*g*ptimestep,Tsat(ig))
 	 enddo
                call writediagfi(ngrid,'Tsat','saturation temperature at surface','',2,Tsat)
 	 
-         do ig=1,ngridmx
+         do ig=1,ngrid
 	    if (ztsrf(ig).gt.Tsat(ig)) then
 	       zmassboil(ig)=(ptsrf(ig)-Tsat(ig))*pcapcal(ig)/RLVTT/ptimestep
@@ -163,7 +163,7 @@
 !    """"""""""""""""""""""""""""""""""""
          
-      pdpsrfmr(1:ngridmx) = (zdmass_sum(1:ngridmx,1)+zmassboil(1:ngridmx))*g
-
-      do ig = 1, ngridmx
+      pdpsrfmr(1:ngrid) = (zdmass_sum(1:ngrid,1)+zmassboil(1:ngrid))*g
+
+      do ig = 1, ngrid
         IF(ABS(pdpsrfmr(ig)*ptimestep).GT.pplev(ig,1)) THEN
          PRINT*,'STOP in condens'
@@ -187,5 +187,5 @@
          zzu(1:nlayermx)  = pu(ig,1:nlayermx) + pdu(ig,1:nlayermx) * ptimestep
          zzv(1:nlayermx)  = pv(ig,1:nlayermx) + pdv(ig,1:nlayermx) * ptimestep
-         zzq(1:nlayermx,1:nqmx)=pq(ig,1:nlayermx,1:nqmx)+pdq(ig,1:nlayermx,1:nqmx)*ptimestep ! must add the water that has fallen???
+         zzq(1:nlayermx,1:nq)=pq(ig,1:nlayermx,1:nq)+pdq(ig,1:nlayermx,1:nq)*ptimestep ! must add the water that has fallen???
 
 !  Mass fluxes of air through the sigma levels (kg.m-2.s-1)  (>0 when up)
@@ -214,5 +214,5 @@
          zum(1) = 0.  
          zvm(1) = 0.  
-         zqm(1,1:nqmx)=0. ! most tracer do not condense !
+         zqm(1,1:nq)=0. ! most tracer do not condense !
          if (water) zqm(1,igcm_h2o_vap)=1. ! flux is 100% h2o at surface
 	 
@@ -222,5 +222,5 @@
          call vl1d(zzu ,2.,zzmass,w,zum) 
          call vl1d(zzv ,2.,zzmass,w,zvm) 
-         do iq=1,nqmx
+         do iq=1,nq
            zq1(1:nlayermx)=zzq(1:nlayermx,iq)
            zqm1(1)=zqm(1,iq)
@@ -247,5 +247,5 @@
          zum(nlayer+1)= zzu(nlayer)  ! should not be used, but...
          zvm(nlayer+1)= zzv(nlayer)  ! should not be used, but...
-         zqm(nlayer+1,1:nqmx)= zzq(nlayer,1:nqmx)
+         zqm(nlayer+1,1:nq)= zzq(nlayer,1:nq)
  
 !        Tendencies on T, U, V, Q 
@@ -267,5 +267,5 @@
 
 !        Tendencies on Q
-         do iq=1,nqmx
+         do iq=1,nq
             DO l=1,nlayer
                pdqmr(ig,l,iq)= (1/zzmass(l)) *   &
Index: trunk/LMDZ.GENERIC/libf/phystd/moistadj.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/moistadj.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/moistadj.F90	(revision 787)
@@ -1,5 +1,6 @@
-subroutine moistadj(pt, pq, pdq, pplev, pplay, pdtmana, pdqmana, ptimestep, rneb)
+subroutine moistadj(ngrid, nq, pt, pq, pdq, pplev, pplay, pdtmana, pdqmana, ptimestep, rneb)
 
   use watercommon_h, only: T_h2O_ice_liq, RLVTT, RCPD, Psat_water, Lcpdqsat_water
+  USE tracer_h
 
   implicit none
@@ -21,24 +22,25 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "tracer.h"
 #include "comcstfi.h"
 
-      REAL pt(ngridmx,nlayermx)            ! temperature (K)
-      REAL pq(ngridmx,nlayermx,nqmx)       ! tracer (kg/kg)
-      REAL pdq(ngridmx,nlayermx,nqmx)
-
-      REAL pdqmana(ngridmx,nlayermx,nqmx)  ! tendency of tracers (kg/kg.s-1)
-      REAL pdtmana(ngridmx,nlayermx)       ! temperature increment
+      INTEGER ngrid, nq
+
+      REAL pt(ngrid,nlayermx)            ! temperature (K)
+      REAL pq(ngrid,nlayermx,nq)       ! tracer (kg/kg)
+      REAL pdq(ngrid,nlayermx,nq)
+
+      REAL pdqmana(ngrid,nlayermx,nq)  ! tendency of tracers (kg/kg.s-1)
+      REAL pdtmana(ngrid,nlayermx)       ! temperature increment
 
 !     local variables
-      REAL zt(ngridmx,nlayermx)      ! temperature (K)
-      REAL zq(ngridmx,nlayermx)      ! humidite specifique (kg/kg)
-      REAL pplev(ngridmx,nlayermx+1) ! pression a inter-couche (Pa)
-      REAL pplay(ngridmx,nlayermx)   ! pression au milieu de couche (Pa)
-
-      REAL d_t(ngridmx,nlayermx)     ! temperature increment
-      REAL d_q(ngridmx,nlayermx)     ! incrementation pour vapeur d'eau
-      REAL d_ql(ngridmx,nlayermx)    ! incrementation pour l'eau liquide
-      REAL rneb(ngridmx,nlayermx) ! cloud fraction 
+      REAL zt(ngrid,nlayermx)      ! temperature (K)
+      REAL zq(ngrid,nlayermx)      ! humidite specifique (kg/kg)
+      REAL pplev(ngrid,nlayermx+1) ! pression a inter-couche (Pa)
+      REAL pplay(ngrid,nlayermx)   ! pression au milieu de couche (Pa)
+
+      REAL d_t(ngrid,nlayermx)     ! temperature increment
+      REAL d_q(ngrid,nlayermx)     ! incrementation pour vapeur d'eau
+      REAL d_ql(ngrid,nlayermx)    ! incrementation pour l'eau liquide
+      REAL rneb(ngrid,nlayermx) ! cloud fraction 
       REAL ptimestep
 
@@ -52,13 +54,13 @@
       INTEGER, PARAMETER :: niter = 1
       INTEGER k1, k1p, k2, k2p
-      LOGICAL itest(ngridmx)
-      REAL delta_q(ngridmx, nlayermx)
+      LOGICAL itest(ngrid)
+      REAL delta_q(ngrid, nlayermx)
       REAL cp_new_t(nlayermx)
       REAL cp_delta_t(nlayermx)
       REAL v_cptj(nlayermx), v_cptjk1, v_ssig
-      REAL v_cptt(ngridmx,nlayermx), v_p, v_t, zpsat
-      REAL zqs(ngridmx,nlayermx), zdqs(ngridmx,nlayermx)
-      REAL zq1(ngridmx), zq2(ngridmx)
-      REAL gamcpdz(ngridmx,2:nlayermx)
+      REAL v_cptt(ngrid,nlayermx), v_p, v_t, zpsat
+      REAL zqs(ngrid,nlayermx), zdqs(ngrid,nlayermx)
+      REAL zq1(ngrid), zq2(ngrid)
+      REAL gamcpdz(ngrid,2:nlayermx)
       REAL zdp, zdpm
 
@@ -66,5 +68,5 @@
       REAL zflo ! flotabilite
 
-      REAL local_q(ngridmx,nlayermx),local_t(ngridmx,nlayermx)
+      REAL local_q(ngrid,nlayermx),local_t(ngrid,nlayermx)
 
       REAL zdelta, zcor, zcvm5
@@ -94,10 +96,10 @@
 
 !     GCM -----> subroutine variables
-      zq(1:ngridmx,1:nlayermx)    = pq(1:ngridmx,1:nlayermx,i_h2o)+ pdq(1:ngridmx,1:nlayermx,i_h2o)*ptimestep
-      zt(1:ngridmx,1:nlayermx)    = pt(1:ngridmx,1:nlayermx)
-      pdqmana(1:ngridmx,1:nlayermx,1:nqmx)=0.0
-
-      DO k = 1, nlayermx
-       DO i = 1, ngridmx
+      zq(1:ngrid,1:nlayermx)    = pq(1:ngrid,1:nlayermx,i_h2o)+ pdq(1:ngrid,1:nlayermx,i_h2o)*ptimestep
+      zt(1:ngrid,1:nlayermx)    = pt(1:ngrid,1:nlayermx)
+      pdqmana(1:ngrid,1:nlayermx,1:nq)=0.0
+
+      DO k = 1, nlayermx
+       DO i = 1, ngrid
          if(zq(i,k).lt.0.)then
             zq(i,k)=0.0
@@ -106,14 +108,14 @@
       ENDDO
       
-      local_q(1:ngridmx,1:nlayermx) = zq(1:ngridmx,1:nlayermx)
-      local_t(1:ngridmx,1:nlayermx) = zt(1:ngridmx,1:nlayermx)
-      rneb(1:ngridmx,1:nlayermx) = 0.0
-      d_ql(1:ngridmx,1:nlayermx) = 0.0
-      d_t(1:ngridmx,1:nlayermx)  = 0.0
-      d_q(1:ngridmx,1:nlayermx)  = 0.0
+      local_q(1:ngrid,1:nlayermx) = zq(1:ngrid,1:nlayermx)
+      local_t(1:ngrid,1:nlayermx) = zt(1:ngrid,1:nlayermx)
+      rneb(1:ngrid,1:nlayermx) = 0.0
+      d_ql(1:ngrid,1:nlayermx) = 0.0
+      d_t(1:ngrid,1:nlayermx)  = 0.0
+      d_q(1:ngrid,1:nlayermx)  = 0.0
 
 !     Calculate v_cptt
       DO k = 1, nlayermx
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             v_cptt(i,k) = RCPD * local_t(i,k)
             v_t = MAX(local_t(i,k),15.)
@@ -127,5 +129,5 @@
 !     Calculate Gamma * Cp * dz: (gamma is the critical gradient)
       DO k = 2, nlayermx
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             zdp = pplev(i,k)-pplev(i,k+1)
             zdpm = pplev(i,k-1)-pplev(i,k)
@@ -138,5 +140,6 @@
 
 !------------------------------------ modification of unstable profile
-      DO 9999 i = 1, ngridmx
+      DO 9999 i = 1, ngrid
+
       itest(i) = .FALSE.
 
@@ -266,5 +269,5 @@
 
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          IF (itest(i)) THEN
          delta_q(i,k) = local_q(i,k) - zq(i,k)
@@ -278,5 +281,5 @@
 ! diminue et d'une maniere proportionnelle a cet diminution):
 
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          IF (itest(i)) THEN
          zq1(i) = 0.0
@@ -285,5 +288,5 @@
       ENDDO
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          IF (itest(i)) THEN
          zdp = pplev(i,k)-pplev(i,k+1)
@@ -294,5 +297,5 @@
       ENDDO
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          IF (itest(i)) THEN
            IF (zq2(i).NE.0.0) d_ql(i,k) = - MIN(0.0,delta_q(i,k))*zq1(i)/zq2(i)
@@ -304,5 +307,5 @@
 
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
           local_q(i, k) = MAX(local_q(i, k), seuil_vap)
       ENDDO
@@ -310,5 +313,5 @@
 
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          d_t(i,k) = local_t(i,k) - zt(i,k)
          d_q(i,k) = local_q(i,k) - zq(i,k)
@@ -318,5 +321,5 @@
 !     now subroutine -----> GCM variables
       DO k = 1, nlayermx
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             
             pdtmana(i,k)       = d_t(i,k)/ptimestep
Index: trunk/LMDZ.GENERIC/libf/phystd/newsedim.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/newsedim.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/newsedim.F	(revision 787)
@@ -35,5 +35,5 @@
 c    Traceurs :
       real pqi(ngrid,nlay)  ! traceur   (e.g. ?/kg)
-      real wq(ngridmx,nlay+1)  ! flux de traceur durant timestep (?/m-2)
+      real wq(ngrid,nlay+1)  ! flux de traceur durant timestep (?/m-2)
       
 c   local:
@@ -48,7 +48,7 @@
 c    Traceurs :
 c    ~~~~~~~~ 
-      real traversee (ngridmx,nlayermx)
-      real vstokes(ngridmx,nlayermx)
-      real w(ngridmx,nlayermx)
+      real traversee (ngrid,nlayermx)
+      real vstokes(ngrid,nlayermx)
+      real w(ngrid,nlayermx)
       real ptop, dztop, Ep, Stra
 
@@ -74,11 +74,4 @@
 
       IF (firstcall) THEN
-         IF(ngrid.NE.ngridmx) THEN
-            PRINT*,'STOP dans newsedim'
-            PRINT*,'probleme de dimensions :'
-            PRINT*,'ngrid  =',ngrid
-            PRINT*,'ngridmx  =',ngridmx
-            STOP 
-         ENDIF
          firstcall=.false.
 
Index: trunk/LMDZ.GENERIC/libf/phystd/newtrelax.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/newtrelax.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/newtrelax.F90	(revision 787)
@@ -1,3 +1,3 @@
-subroutine newtrelax(mu0,sinlat,popsk,temp,pplay,pplev,dtrad,firstcall) 
+subroutine newtrelax(ngrid,mu0,sinlat,popsk,temp,pplay,pplev,dtrad,firstcall) 
         
   implicit none
@@ -20,19 +20,21 @@
 !     
 !==================================================================
-  
+ 
+  integer ngrid
+ 
   ! Input
-  real mu0(ngridmx)                    ! cosine of sun incident angle
-  real sinlat(ngridmx)                 ! sine of latitude
-  real temp(ngridmx,nlayermx)          ! temperature at each layer (K)
-  real pplay(ngridmx,nlayermx)         ! pressure at each layer (Pa)
-  real pplev(ngridmx,nlayermx+1)       ! pressure at each level (Pa)
-  real popsk(ngridmx,nlayermx)         ! pot. T to T converter
+  real mu0(ngrid)                    ! cosine of sun incident angle
+  real sinlat(ngrid)                 ! sine of latitude
+  real temp(ngrid,nlayermx)          ! temperature at each layer (K)
+  real pplay(ngrid,nlayermx)         ! pressure at each layer (Pa)
+  real pplev(ngrid,nlayermx+1)       ! pressure at each level (Pa)
+  real popsk(ngrid,nlayermx)         ! pot. T to T converter
 
   ! Output
-  real dtrad(ngridmx,nlayermx) 
+  real dtrad(ngrid,nlayermx) 
 
   ! Internal
-  real Trelax(ngridmx,nlayermx), Trelax_V, Trelax_H
-  save Trelax
+  real Trelax_V, Trelax_H
+  real,allocatable,dimension(:,:),save :: Trelax
 
   real T_trop ! relaxation temperature at tropopause (K)
@@ -51,4 +53,6 @@
   if(firstcall) then
 
+     ALLOCATE(Trelax(ngrid,nlayermx))
+
      print*,'-----------------------------------------------------'
      print*,'| ATTENTION: You are using a Newtonian cooling scheme'
@@ -58,5 +62,5 @@
 
      if(tidallocked)then
-        do ig=1,ngridmx
+        do ig=1,ngrid
 
            T_surf = 126. + 239.*mu0(ig)
@@ -83,5 +87,5 @@
 
         do l=1,nlayermx
-           do ig=1,ngridmx
+           do ig=1,ngrid
 
               ! vertically varying component
@@ -111,5 +115,5 @@
   ! Calculate radiative forcing
   do l=1,nlayermx
-     do ig=1,ngridmx
+     do ig=1,ngrid
         dtrad(ig,l) = -(temp(ig,l) - Trelax(ig,l)) / tau_relax
         if(temp(ig,l).gt.500.)then ! Trelax(ig,l))then
@@ -122,6 +126,6 @@
   enddo
 
-  call writediagfi(ngridmx,'Tref','rad forc temp','K',3,Trelax)
-  !call writediagfi(ngridmx,'ThetaZ','stellar zenith angle','deg',2,mu0)
+  call writediagfi(ngrid,'Tref','rad forc temp','K',3,Trelax)
+  !call writediagfi(ngrid,'ThetaZ','stellar zenith angle','deg',2,mu0)
 
   return
Index: trunk/LMDZ.GENERIC/libf/phystd/phyetat0.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/phyetat0.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/phyetat0.F	(revision 787)
@@ -1,6 +1,12 @@
-      SUBROUTINE phyetat0 (fichnom,tab0,Lmodif,nsoil,nq,
+      SUBROUTINE phyetat0 (ngrid,fichnom,tab0,Lmodif,nsoil,nq,
      .           day_ini,time,
      .           tsurf,tsoil,emis,q2,qsurf,cloudfrac,totcloudfrac,hice)
+
+      USE surfdat_h
+      USE comgeomfi_h
+      USE tracer_h
+
       implicit none
+
 c======================================================================
 c Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
@@ -11,10 +17,8 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "comgeomfi.h"
-#include "surfdat.h"
 #include "planete.h"
 #include "comcstfi.h"
-#include"advtrac.h"
-
+
+      INTEGER ngrid
 c======================================================================
       INTEGER nbsrf !Mars nbsrf a 1 au lieu de 4
@@ -33,13 +37,12 @@
 
 !  outputs:
-      real tsurf(ngridmx,nbsrf) ! surface temperature
-      real tsoil(ngridmx,nsoil,nbsrf) ! soil temperature
-      real emis(ngridmx) ! surface emissivity
-      real q2(ngridmx, llm+1) ! 
-      real qsurf(ngridmx,nq) ! tracers on surface
-!      real co2ice(ngridmx) ! co2 ice cover
-      real cloudfrac(ngridmx,nlayermx)
-      real hice(ngridmx), totcloudfrac(ngridmx)
-
+      real tsurf(ngrid,nbsrf) ! surface temperature
+      real tsoil(ngrid,nsoil,nbsrf) ! soil temperature
+      real emis(ngrid) ! surface emissivity
+      real q2(ngrid, llm+1) ! 
+      real qsurf(ngrid,nq) ! tracers on surface
+!      real co2ice(ngrid) ! co2 ice cover
+      real cloudfrac(ngrid,nlayermx)
+      real hice(ngrid), totcloudfrac(ngrid)
 
 
@@ -71,5 +74,25 @@
       character(len=30) :: txt ! to store some text
 
- 
+!! added variables by AS to allow to read only slices of startfi
+      real :: toto(ngrid)
+      integer :: sta   !! subscript in starti where we start to read
+      integer, dimension(2) :: sta2d
+      integer, dimension(2) :: siz2d
+
+c AS: get the cursor that is stored in dimphys.h
+c ... this allows to read only a part of startfi horiz grid
+      sta = cursor
+
+c
+c ALLOCATE ARRAYS IN surfdat_h
+c
+      IF (.not. ALLOCATED(albedodat)) ALLOCATE(albedodat(ngrid))
+      IF (.not. ALLOCATED(phisfi)) ALLOCATE(phisfi(ngrid))
+      IF (.not. ALLOCATED(zmea)) ALLOCATE(zmea(ngrid))
+      IF (.not. ALLOCATED(zstd)) ALLOCATE(zstd(ngrid))
+      IF (.not. ALLOCATED(zsig)) ALLOCATE(zsig(ngrid))
+      IF (.not. ALLOCATED(zgam)) ALLOCATE(zgam(ngrid))
+      IF (.not. ALLOCATED(zthe)) ALLOCATE(zthe(ngrid))
+
 c
 c Ouvrir le fichier contenant l etat initial:
@@ -85,5 +108,5 @@
 !                    qsurf02, ...)
       count=0
-      do iq=1,nqmx
+      do iq=1,nq
         txt= " "
         write(txt,'(a5,i2.2)')'qsurf',iq
@@ -97,5 +120,5 @@
         endif
       enddo
-      if (count.eq.nqmx) then
+      if (count.eq.nq) then
         write(*,*) "phyetat0:tracers seem to follow old naming ",
      &             "convention (qsurf01,qsurf02,...)"
@@ -106,8 +129,8 @@
 
 c modifications possibles des variables de tab_cntrl
-      PRINT*
       write(*,*) 'TABFI de phyeta0',Lmodif,tab0
-      call tabfi (nid,Lmodif,tab0,day_ini,lmax,p_rad,
+      call tabfi (ngrid,nid,Lmodif,tab0,day_ini,lmax,p_rad,
      .              p_omeg,p_g,p_cpp,p_mugaz,p_daysec,time)
+
 c
 c Lecture des latitudes (coordonnees):
@@ -119,7 +142,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, lati)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, lati)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,lati)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,lati)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -136,7 +159,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, long)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, long)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,long)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,long)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -153,7 +176,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, area)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, area)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,area)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,area)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -175,7 +198,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, phisfi)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, phisfi)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,phisfi)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,phisfi)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -197,7 +220,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, albedodat)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, albedodat)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,albedodat)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,albedodat)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -211,26 +234,4 @@
       PRINT*,'Albedo du sol nu <albedodat>:', xmin, xmax
 c
-c Lecture de l''inertie thermique du sol:
-c
-!      ierr = NF_INQ_VARID (nid, "inertiedat", nvarid)
-!      IF (ierr.NE.NF_NOERR) THEN
-!         PRINT*, 'phyetat0: Le champ <inertiedat> est absent'
-!         CALL abort
-!      ENDIF
-!#ifdef NC_DOUBLE
-!      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, inertiedat)
-!#else
-!      ierr = NF_GET_VAR_REAL(nid, nvarid, inertiedat)
-!#endif
-!      IF (ierr.NE.NF_NOERR) THEN
-!         PRINT*, 'phyetat0: Lecture echouee pour <inertiedat>'
-!         CALL abort
-!      ENDIF
-!      xmin = 1.0E+20
-!      xmax = -1.0E+20
-!      xmin = MINVAL(inertiedat)
-!      xmax = MAXVAL(inertiedat)
-!      PRINT*,'Inertie thermique du sol <inertiedat>:', xmin, xmax
-c
 c ZMEA
 c
@@ -241,7 +242,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zmea)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, zmea)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,zmea)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,zmea)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -251,5 +252,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          xmin = MIN(zmea(i),xmin)
          xmax = MAX(zmea(i),xmax)
@@ -265,7 +266,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zstd)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, zstd)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,zstd)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,zstd)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -275,5 +276,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          xmin = MIN(zstd(i),xmin)
          xmax = MAX(zstd(i),xmax)
@@ -289,7 +290,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zsig)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, zsig)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,zsig)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,zsig)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -299,5 +300,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          xmin = MIN(zsig(i),xmin)
          xmax = MAX(zsig(i),xmax)
@@ -313,7 +314,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zgam)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, zgam)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,zgam)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,zgam)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -323,5 +324,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          xmin = MIN(zgam(i),xmin)
          xmax = MAX(zgam(i),xmax)
@@ -337,7 +338,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zthe)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, zthe)
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,zthe)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,zthe)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -347,5 +348,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          xmin = MIN(zthe(i),xmin)
          xmax = MAX(zthe(i),xmax)
@@ -413,7 +414,7 @@
          PRINT*, '          J ignore donc les autres temperatures TS**'
 #ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tsurf(1,1))
-#else
-         ierr = NF_GET_VAR_REAL(nid, nvarid, tsurf(1,1))
+         ierr = NF_GET_VARA_DOUBLE(nid, nvarid, sta, ngrid, tsurf)
+#else
+         ierr = NF_GET_VARA_REAL(nid, nvarid, sta, ngrid, tsurf)
 #endif
          IF (ierr.NE.NF_NOERR) THEN
@@ -428,5 +429,5 @@
          IF (nbsrf >= 2) THEN
             DO nsrf = 2, nbsrf
-               DO i = 1, ngridmx
+               DO i = 1, ngrid
                   tsurf(i,nsrf) = tsurf(i,1)
                ENDDO
@@ -448,5 +449,5 @@
 !               PRINT*, "phyetat0: Le champ <tsoil> est absent"
 !               PRINT*, "          Il prend donc la valeur de surface"
-!               DO i=1, ngridmx
+!               DO i=1, ngrid
 !                  tsoil(i,isoil,nsrf)=tsurf(i,nsrf)
 !               ENDDO
@@ -478,7 +479,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, emis)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, emis)
+      ierr = NF_GET_VARA_DOUBLE(nid, nvarid, sta,ngrid, emis)
+#else
+      ierr = NF_GET_VARA_REAL(nid, nvarid,sta,ngrid, emis)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -501,8 +502,10 @@
 !         CALL abort
       ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, cloudfrac)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, cloudfrac)
+      sta2d = (/sta,1/)
+      siz2d = (/ngrid, nlayermx/)
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta2d,siz2d,cloudfrac)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta2d,siz2d,cloudfrac)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -528,7 +531,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, totcloudfrac)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, totcloudfrac)
+      ierr = NF_GET_VARA_DOUBLE(nid, nvarid,sta,ngrid, totcloudfrac)
+#else
+      ierr = NF_GET_VARA_REAL(nid, nvarid,sta,ngrid, totcloudfrac)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -553,7 +556,7 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, hice)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, hice)
+      ierr = NF_GET_VARA_DOUBLE(nid, nvarid,sta,ngrid, hice)
+#else
+      ierr = NF_GET_VARA_REAL(nid, nvarid,sta,ngrid, hice)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -576,8 +579,10 @@
          CALL abort
       ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, q2)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, q2)
+      sta2d = (/sta,1/)
+      siz2d = (/ngrid, llm+1/)
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta2d,siz2d,q2)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,sta2d,siz2d,q2)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
@@ -604,5 +609,5 @@
              write(txt,'(a5,i2.2)')'qsurf',iq
            ELSE
-             txt=tnom(iq)
+             txt=noms(iq)
 !             if (txt.eq."h2o_vap") then
                ! There is no surface tracer for h2o_vap;
@@ -618,13 +623,14 @@
      &                  ' not found in file'
              write(*,*) trim(txt), ' set to 0'
-             do ig=1,ngridmx
+             do ig=1,ngrid
                qsurf(ig,iq)=0.
              end do
              nqold=min(iq-1,nqold)
            ELSE
-#ifdef NC_DOUBLE
-             ierr = NF_GET_VAR_DOUBLE(nid, nvarid,qsurf(1,iq))
-#else
-             ierr = NF_GET_VAR_REAL(nid, nvarid,qsurf(1,iq))
+           toto(:) = 0.
+#ifdef NC_DOUBLE
+           ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta,ngrid,toto)
+#else
+           ierr = NF_GET_VARA_REAL(nid,nvarid,sta,ngrid,toto)
 #endif
              IF (ierr.NE.NF_NOERR) THEN
@@ -632,9 +638,10 @@
                CALL abort
              ENDIF
+             qsurf(1:ngrid,iq) = toto(1:ngrid)
            ENDIF
            xmin = 1.0E+20
            xmax = -1.0E+20
-           xmin = MINVAL(qsurf(1:ngridmx,iq))
-           xmax = MAXVAL(qsurf(1:ngridmx,iq))
+           xmin = MINVAL(qsurf(1:ngrid,iq))
+           xmax = MAXVAL(qsurf(1:ngrid,iq))
            PRINT*,'tracer on surface <',trim(txt),'>:',xmin,xmax
          ENDDO
@@ -642,20 +649,20 @@
 c        case when new tracer are added in addition to old ones
              write(*,*)'qsurf 1 to ', nqold,'were already present'
-             write(*,*)'qsurf ', nqold+1,' to ', nqmx,'are new'
+             write(*,*)'qsurf ', nqold+1,' to ', nq,'are new'
              write(*,*)' and initialized to zero'
-             qsurf(:,nqold+1:nqmx)=0.0
+             qsurf(:,nqold+1:nq)=0.0
 !            yes=' '
 !            do while ((yes.ne.'y').and.(yes.ne.'n'))
 !             write(*,*) 'Would you like to reindex qsurf # 1 ->',nqold
-!             write(*,*) 'to #',nqmx-nqold+1,'->', nqmx,'   (y or n) ?'
+!             write(*,*) 'to #',nq-nqold+1,'->', nq,'   (y or n) ?'
 !             read(*,fmt='(a)') yes
 !            end do
 !            if (yes.eq.'y') then
 !              write(*,*) 'OK, let s reindex qsurf'
-!                 do ig=1,ngridmx
-!                    do iq=nqmx,nqmx-nqold+1,-1
-!                       qsurf(ig,iq)=qsurf(ig,iq-nqmx+nqold)
+!                 do ig=1,ngrid
+!                    do iq=nq,nq-nqold+1,-1
+!                       qsurf(ig,iq)=qsurf(ig,iq-nq+nqold)
 !                    end do
-!                    do iq=nqmx-nqold,1,-1
+!                    do iq=nq-nqold,1,-1
 !                       qsurf(ig,iq)= 0.
 !                    end do
@@ -668,5 +675,6 @@
 ! as well as thermal inertia and volumetric heat capacity
 
-      call soil_settings(nid,ngridmx,nsoil,tsurf,tsoil)
+      PRINT*,'SOIL INIT'
+      call soil_settings(nid,ngrid,nsoil,tsurf,tsoil)
 c
 c Fermer le fichier:
@@ -674,4 +682,5 @@
       ierr = NF_CLOSE(nid)
 c
+
       RETURN
       END
Index: trunk/LMDZ.GENERIC/libf/phystd/physdem1.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/physdem1.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/physdem1.F	(revision 787)
@@ -1,8 +1,11 @@
-      subroutine physdem1(filename,lonfi,latfi,nsoil,nq,
+      subroutine physdem1(ngrid,filename,lonfi,latfi,nsoil,nq,
      .                   phystep,day_ini,
      .                   time,tsurf,tsoil,emis,q2,qsurf,
      .                   airefi,alb,ith,pzmea,pzstd,pzsig,pzgam,pzthe,
-     .                   cloudfrac,totcloudfrac,hice)
-
+     .                   cloudfrac,totcloudfrac,hice,nametrac)
+
+      use surfdat_h
+      use comsoil_h
+      USE comgeomfi_h
  
       implicit none
@@ -36,6 +39,7 @@
 #include "netcdf.inc"
 #include "dimphys.h"
-#include"advtrac.h"
 #include"callkeys.h"
+
+      INTEGER :: ngrid
 
       INTEGER nid,iq
@@ -50,7 +54,7 @@
 
       REAL phystep,time
-      REAL latfi(ngridmx), lonfi(ngridmx)
-!      REAL champhys(ngridmx)
-      REAL tsurf(ngridmx)
+      REAL latfi(ngrid), lonfi(ngrid)
+!      REAL champhys(ngrid)
+      REAL tsurf(ngrid)
       INTEGER length
       PARAMETER (length=100)
@@ -58,6 +62,10 @@
 
 !     added by BC
-      REAL hice(ngridmx),cloudfrac(ngridmx,nlayermx)
-      REAL totcloudfrac(ngridmx)
+      REAL hice(ngrid),cloudfrac(ngrid,nlayermx)
+      REAL totcloudfrac(ngrid)
+
+!     AS: name of tracers added as an argument to avoid using nqmx in commons (i.e. adv trac)
+!       nota: physdem1 is used both in physiq and newstart.
+      character*20 nametrac(nq)   ! name of the tracer
 
 
@@ -68,16 +76,13 @@
 #include "clesph0.h"
 #include "fxyprim.h"
-#include "comgeomfi.h"
-#include "surfdat.h"
-#include "comsoil.h"
 #include "planete.h"
 #include "comcstfi.h"
 
-      real tsoil(ngridmx,nsoil),emis(ngridmx)
-      real q2(ngridmx, llm+1),qsurf(ngridmx,nq)
-      real airefi(ngridmx)
-      real alb(ngridmx),ith(ngridmx,nsoil)
-      real pzmea(ngridmx),pzstd(ngridmx)
-      real pzsig(ngridmx),pzgam(ngridmx),pzthe(ngridmx)
+      real tsoil(ngrid,nsoil),emis(ngrid)
+      real q2(ngrid, llm+1),qsurf(ngrid,nq)
+      real airefi(ngrid)
+      real alb(ngrid),ith(ngrid,nsoil)
+      real pzmea(ngrid),pzstd(ngrid)
+      real pzsig(ngrid),pzgam(ngrid),pzthe(ngrid)
       integer ig
 
@@ -92,8 +97,8 @@
 
       ! copy airefi(:) to area(:)
-      CALL SCOPY(ngridmx,airefi,1,area,1)
+      CALL SCOPY(ngrid,airefi,1,area,1)
       ! note: area() is defined in comgeomfi.h
 
-      DO ig=1,ngridmx
+      DO ig=1,ngrid
          albedodat(ig)=alb(ig) ! note: albedodat() is defined in surfdat.h
          zmea(ig)=pzmea(ig) ! note: zmea() is defined in surfdat.h
@@ -127,5 +132,5 @@
       endif
 c
-      ierr = NF_DEF_DIM (nid,"physical_points",ngridmx,idim2)
+      ierr = NF_DEF_DIM (nid,"physical_points",ngrid,idim2)
       if (ierr.ne.NF_NOERR) then
         WRITE(6,*)'physdem1: Problem defining physical_points dimension'
@@ -169,5 +174,5 @@
       ENDDO
 
-      write(*,*) "physdem1: ngridmx: ",ngridmx
+      write(*,*) "physdem1: ngrid: ",ngrid
 
 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
@@ -175,5 +180,5 @@
 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
 c Informations on the physics grid
-      tab_cntrl(1) = float(ngridmx)  ! number of nodes on physics grid
+      tab_cntrl(1) = float(ngrid)  ! number of nodes on physics grid
       tab_cntrl(2) = float(nlayermx) ! number of atmospheric layers
       tab_cntrl(3) = day_ini + int(time)         ! initial day 
@@ -618,8 +623,8 @@
 !                    qsurf02, ...)
       count=0
-      do iq=1,nqmx
+      do iq=1,nq
         txt= " "
         write(txt,'(a1,i2.2)')'q',iq
-        if (txt.ne.tnom(iq)) then ! use tracer names stored in dynamics
+        if (txt.ne.nametrac(iq)) then ! use tracer names stored in dynamics
           ! did not find old tracer name
           exit ! might as well stop here
@@ -629,5 +634,5 @@
         endif
       enddo
-      if (count.eq.nqmx) then
+      if (count.eq.nq) then
         write(*,*) "physdem1:tracers seem to follow old naming ",
      &             "convention (qsurf01,qsurf02,...)"
@@ -638,11 +643,11 @@
         !oldtracernames=.true.
         ! Moreover, if computing water cycle with ice, move surface ice
-        ! back to qsurf(nqmx)
+        ! back to qsurf(nq)
         !IF (iceparty) THEN
-        !  write(*,*)'physdem1: moving surface water ice to index ',nqmx
-        !  qsurf(1:ngridmx,nqmx)=qsurf(1:ngridmx,nqmx-1)
-        !  qsurf(1:ngridmx,nqmx-1)=0
+        !  write(*,*)'physdem1: moving surface water ice to index ',nq
+        !  qsurf(1:ngrid,nq)=qsurf(1:ngrid,nq-1)
+        !  qsurf(1:ngrid,nq-1)=0
         !ENDIF
-      endif ! of if (count.eq.nqmx)
+      endif ! of if (count.eq.nq)
 
       IF(nq.GE.1) THEN
@@ -650,8 +655,8 @@
         if (.not.oldtracernames) then
          do iq=1,nq
-           if (tnom(iq).eq."h2o_vap") then
+           if (nametrac(iq).eq."h2o_vap") then
              i_h2o_vap=iq
            endif
-           if (tnom(iq).eq."h2o_ice") then
+           if (nametrac(iq).eq."h2o_ice") then
              i_h2o_ice=iq
            endif
@@ -671,5 +676,5 @@
              write(txt,'(a5,i2.2)')'qsurf',iq
            ELSE
-             txt=tnom(iq)
+             txt=nametrac(iq)
 
 
Index: trunk/LMDZ.GENERIC/libf/phystd/physiq.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 787)
@@ -1,3 +1,4 @@
       subroutine physiq(ngrid,nlayer,nq,   &
+                  nametrac,                & 
                   firstcall,lastcall,      &
                   pday,ptime,ptimestep,    &
@@ -13,4 +14,11 @@
       use radii_mod, only: h2o_reffrad, co2_reffrad
       use aerosol_mod
+      use surfdat_h
+      use comdiurn_h
+      use comsaison_h
+      use comsoil_h
+      USE comgeomfi_h
+      USE tracer_h
+
       implicit none
 
@@ -103,4 +111,5 @@
 !           New turbulent diffusion scheme: J. Leconte (2012)
 !           Loops converted to F90 matrix format: J. Leconte (2012)
+!           No more ngridmx/nqmx, F90 commons and adaptation to parallel: A. Spiga (2012)
 !     
 !==================================================================
@@ -112,15 +121,8 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "comgeomfi.h"
-#include "surfdat.h"
-#include "comsoil.h"
-#include "comdiurn.h"
 #include "callkeys.h"
 #include "comcstfi.h"
 #include "planete.h"
-#include "comsaison.h"
 #include "control.h"
-#include "tracer.h"
-#include "watercap.h"
 #include "netcdf.inc"
 
@@ -132,10 +134,10 @@
       integer ngrid,nlayer,nq
       real ptimestep
-      real pplev(ngridmx,nlayer+1),pplay(ngridmx,nlayer)
-      real pphi(ngridmx,nlayer)
-      real pu(ngridmx,nlayer),pv(ngridmx,nlayer)
-      real pt(ngridmx,nlayer),pq(ngridmx,nlayer,nq)
-      real pw(ngridmx,nlayer)        ! pvervel transmitted by dyn3d
-      real zh(ngridmx,nlayermx)      ! potential temperature (K)
+      real pplev(ngrid,nlayer+1),pplay(ngrid,nlayer)
+      real pphi(ngrid,nlayer)
+      real pu(ngrid,nlayer),pv(ngrid,nlayer)
+      real pt(ngrid,nlayer),pq(ngrid,nlayer,nq)
+      real pw(ngrid,nlayer)        ! pvervel transmitted by dyn3d
+      real zh(ngrid,nlayermx)      ! potential temperature (K)
       logical firstcall,lastcall
 
@@ -144,10 +146,12 @@
       logical tracerdyn
 
+      character*20 nametrac(nq)   ! name of the tracer from dynamics
+
 !   outputs:
 !   --------
 !     physical tendencies
-      real pdu(ngridmx,nlayer),pdv(ngridmx,nlayer)
-      real pdt(ngridmx,nlayer),pdq(ngridmx,nlayer,nq)
-      real pdpsrf(ngridmx) ! surface pressure tendency
+      real pdu(ngrid,nlayer),pdv(ngrid,nlayer)
+      real pdt(ngrid,nlayer),pdq(ngrid,nlayer,nq)
+      real pdpsrf(ngrid) ! surface pressure tendency
 
 
@@ -157,30 +161,26 @@
 !     "longrefvis" set in dimradmars.h , for one of the "naerkind"  kind of
 !      aerosol optical properties:
-!      real aerosol(ngridmx,nlayermx,naerkind) 
+!      real aerosol(ngrid,nlayermx,naerkind) 
 !     this is now internal to callcorrk and hence no longer needed here
 
       integer day_ini                ! Initial date of the run (sol since Ls=0) 
       integer icount                 ! counter of calls to physiq during the run.
-      real tsurf(ngridmx)            ! Surface temperature (K)
-      real tsoil(ngridmx,nsoilmx)    ! sub-surface temperatures (K)
-      real albedo(ngridmx)           ! Surface albedo
-
-      real albedo0(ngridmx)          ! Surface albedo
-      integer rnat(ngridmx)          ! added by BC
-      save rnat
-
-      real emis(ngridmx)             ! Thermal IR surface emissivity
-      real dtrad(ngridmx,nlayermx)   ! Net atm. radiative heating rate (K.s-1)
-      real fluxrad_sky(ngridmx)      ! rad. flux from sky absorbed by surface (W.m-2)
-      real fluxrad(ngridmx)          ! Net radiative surface flux (W.m-2)
-      real capcal(ngridmx)           ! surface heat capacity (J m-2 K-1)
-      real fluxgrd(ngridmx)          ! surface conduction flux (W.m-2)
-      real qsurf(ngridmx,nqmx)       ! tracer on surface (e.g. kg.m-2)
-      real q2(ngridmx,nlayermx+1)    ! Turbulent Kinetic Energy 
+      real, dimension(:),allocatable,save ::  tsurf  ! Surface temperature (K)
+      real, dimension(:,:),allocatable,save ::  tsoil  ! sub-surface temperatures (K)
+      real, dimension(:),allocatable,save :: albedo ! Surface albedo
+
+      real,dimension(:),allocatable,save :: albedo0 ! Surface albedo
+      integer,dimension(:),allocatable,save :: rnat ! added by BC
+
+      real,dimension(:),allocatable,save :: emis ! Thermal IR surface emissivity
+      real,dimension(:,:),allocatable,save :: dtrad ! Net atm. radiative heating rate (K.s-1)
+      real,dimension(:),allocatable,save :: fluxrad_sky ! rad. flux from sky absorbed by surface (W.m-2)
+      real,dimension(:),allocatable,save :: fluxrad ! Net radiative surface flux (W.m-2)
+      real,dimension(:),allocatable,save :: capcal ! surface heat capacity (J m-2 K-1)
+      real,dimension(:),allocatable,save :: fluxgrd ! surface conduction flux (W.m-2)
+      real,dimension(:,:),allocatable,save :: qsurf ! tracer on surface (e.g. kg.m-2)
+      real,dimension(:,:),allocatable,save :: q2 ! Turbulent Kinetic Energy 
 
       save day_ini, icount
-      save tsurf,tsoil
-      save albedo0,albedo,emis,q2
-      save capcal,fluxgrd,dtrad,fluxrad,fluxrad_sky,qsurf
 
 ! Local variables :
@@ -189,80 +189,75 @@
 !     aerosol (dust or ice) extinction optical depth  at reference wavelength 
 !     for the "naerkind" optically active aerosols:
-      real aerosol(ngridmx,nlayermx,naerkind) 
+      real aerosol(ngrid,nlayermx,naerkind) 
 
       character*80 fichier 
       integer l,ig,ierr,iq,iaer
 
-      real fluxsurf_lw(ngridmx)      ! incident LW (IR) surface flux (W.m-2)
-      real fluxsurf_sw(ngridmx)      ! incident SW (stellar) surface flux (W.m-2)
-      real fluxtop_lw(ngridmx)       ! Outgoing LW (IR) flux to space (W.m-2)
-      real fluxabs_sw(ngridmx)       ! Absorbed SW (stellar) flux (W.m-2)
-
-      real fluxtop_dn(ngridmx)
-      real fluxdyn(ngridmx)          ! horizontal heat transport by dynamics      
-      real OLR_nu(ngridmx,L_NSPECTI)! Outgoing LW radition in each band (Normalized to the band width (W/m2/cm-1)
-      real OSR_nu(ngridmx,L_NSPECTV)! Outgoing SW radition in each band (Normalized to the band width (W/m2/cm-1)
- 
-      real,save :: sensibFlux(ngridmx)   ! turbulent flux given by the atm to the surface
- 
-      save fluxsurf_lw,fluxsurf_sw,fluxtop_lw,fluxabs_sw,fluxtop_dn,fluxdyn,OLR_nu,OSR_nu
-
+      !!! this is saved for diagnostic
+      real,dimension(:),allocatable,save :: fluxsurf_lw ! incident LW (IR) surface flux (W.m-2)
+      real,dimension(:),allocatable,save :: fluxsurf_sw ! incident SW (stellar) surface flux (W.m-2)
+      real,dimension(:),allocatable,save :: fluxtop_lw ! Outgoing LW (IR) flux to space (W.m-2)
+      real,dimension(:),allocatable,save :: fluxabs_sw ! Absorbed SW (stellar) flux (W.m-2)
+      real,dimension(:),allocatable,save :: fluxtop_dn
+      real,dimension(:),allocatable,save :: fluxdyn ! horizontal heat transport by dynamics  
+      real,dimension(:,:),allocatable,save :: OLR_nu ! Outgoing LW radition in each band (Normalized to the band width (W/m2/cm-1)
+      real,dimension(:,:),allocatable,save :: OSR_nu ! Outgoing SW radition in each band (Normalized to the band width (W/m2/cm-1)
+      real,dimension(:,:),allocatable,save :: zdtlw ! (K/s)
+      real,dimension(:,:),allocatable,save :: zdtsw ! (K/s)
+      real,dimension(:),allocatable,save :: sensibFlux ! turbulent flux given by the atm to the surface
 
       real zls                       ! solar longitude (rad)
       real zday                      ! date (time since Ls=0, in martian days)
-      real zzlay(ngridmx,nlayermx)   ! altitude at the middle of the layers
-      real zzlev(ngridmx,nlayermx+1) ! altitude at layer boundaries
+      real zzlay(ngrid,nlayermx)   ! altitude at the middle of the layers
+      real zzlev(ngrid,nlayermx+1) ! altitude at layer boundaries
       real latvl1,lonvl1             ! Viking Lander 1 point (for diagnostic)
 
 !     Tendencies due to various processes:
-      real dqsurf(ngridmx,nqmx)
-      real,save :: zdtlw(ngridmx,nlayermx)                    ! (K/s)
-      real,save :: zdtsw(ngridmx,nlayermx)                    ! (K/s)
-
-      real cldtlw(ngridmx,nlayermx)                           ! (K/s) LW heating rate for clear areas
-      real cldtsw(ngridmx,nlayermx)                           ! (K/s) SW heating rate for clear areas
-      real zdtsurf(ngridmx)                                   ! (K/s)
-      real dtlscale(ngridmx,nlayermx)
-      real zdvdif(ngridmx,nlayermx),zdudif(ngridmx,nlayermx)  ! (m.s-2)
-      real zdhdif(ngridmx,nlayermx), zdtsdif(ngridmx)         ! (K/s)
-      real zdtdif(ngridmx,nlayermx)			      ! (K/s)
-      real zdvadj(ngridmx,nlayermx),zduadj(ngridmx,nlayermx)  ! (m.s-2)
-      real zdhadj(ngridmx,nlayermx)                           ! (K/s)
-      real zdtgw(ngridmx,nlayermx)                            ! (K/s)
-      real zdtmr(ngridmx,nlayermx)
-      real zdugw(ngridmx,nlayermx),zdvgw(ngridmx,nlayermx)    ! (m.s-2)
-      real zdtc(ngridmx,nlayermx),zdtsurfc(ngridmx)
-      real zdvc(ngridmx,nlayermx),zduc(ngridmx,nlayermx)
-      real zdumr(ngridmx,nlayermx),zdvmr(ngridmx,nlayermx)
-      real zdtsurfmr(ngridmx)
+      real dqsurf(ngrid,nq)
+      real cldtlw(ngrid,nlayermx)                           ! (K/s) LW heating rate for clear areas
+      real cldtsw(ngrid,nlayermx)                           ! (K/s) SW heating rate for clear areas
+      real zdtsurf(ngrid)                                   ! (K/s)
+      real dtlscale(ngrid,nlayermx)
+      real zdvdif(ngrid,nlayermx),zdudif(ngrid,nlayermx)  ! (m.s-2)
+      real zdhdif(ngrid,nlayermx), zdtsdif(ngrid)         ! (K/s)
+      real zdtdif(ngrid,nlayermx)			      ! (K/s)
+      real zdvadj(ngrid,nlayermx),zduadj(ngrid,nlayermx)  ! (m.s-2)
+      real zdhadj(ngrid,nlayermx)                           ! (K/s)
+      real zdtgw(ngrid,nlayermx)                            ! (K/s)
+      real zdtmr(ngrid,nlayermx)
+      real zdugw(ngrid,nlayermx),zdvgw(ngrid,nlayermx)    ! (m.s-2)
+      real zdtc(ngrid,nlayermx),zdtsurfc(ngrid)
+      real zdvc(ngrid,nlayermx),zduc(ngrid,nlayermx)
+      real zdumr(ngrid,nlayermx),zdvmr(ngrid,nlayermx)
+      real zdtsurfmr(ngrid)
       
-      real zdmassmr(ngridmx,nlayermx),zdpsrfmr(ngridmx)
-
-      real zdqdif(ngridmx,nlayermx,nqmx), zdqsdif(ngridmx,nqmx)
-      real zdqevap(ngridmx,nlayermx)
-      real zdqsed(ngridmx,nlayermx,nqmx), zdqssed(ngridmx,nqmx)
-      real zdqdev(ngridmx,nlayermx,nqmx), zdqsdev(ngridmx,nqmx)
-      real zdqadj(ngridmx,nlayermx,nqmx)
-      real zdqc(ngridmx,nlayermx,nqmx)
-      real zdqmr(ngridmx,nlayermx,nqmx),zdqsurfmr(ngridmx,nqmx)
-      real zdqlscale(ngridmx,nlayermx,nqmx)
-      real zdqslscale(ngridmx,nqmx)
-      real zdqchim(ngridmx,nlayermx,nqmx)
-      real zdqschim(ngridmx,nqmx)
-
-      real zdteuv(ngridmx,nlayermx)    ! (K/s)
-      real zdtconduc(ngridmx,nlayermx) ! (K/s)
-      real zdumolvis(ngridmx,nlayermx)
-      real zdvmolvis(ngridmx,nlayermx)
-      real zdqmoldiff(ngridmx,nlayermx,nqmx)
+      real zdmassmr(ngrid,nlayermx),zdpsrfmr(ngrid)
+
+      real zdqdif(ngrid,nlayermx,nq), zdqsdif(ngrid,nq)
+      real zdqevap(ngrid,nlayermx)
+      real zdqsed(ngrid,nlayermx,nq), zdqssed(ngrid,nq)
+      real zdqdev(ngrid,nlayermx,nq), zdqsdev(ngrid,nq)
+      real zdqadj(ngrid,nlayermx,nq)
+      real zdqc(ngrid,nlayermx,nq)
+      real zdqmr(ngrid,nlayermx,nq),zdqsurfmr(ngrid,nq)
+      real zdqlscale(ngrid,nlayermx,nq)
+      real zdqslscale(ngrid,nq)
+      real zdqchim(ngrid,nlayermx,nq)
+      real zdqschim(ngrid,nq)
+
+      real zdteuv(ngrid,nlayermx)    ! (K/s)
+      real zdtconduc(ngrid,nlayermx) ! (K/s)
+      real zdumolvis(ngrid,nlayermx)
+      real zdvmolvis(ngrid,nlayermx)
+      real zdqmoldiff(ngrid,nlayermx,nq)
 
 !     Local variables for local calculations:
-      real zflubid(ngridmx)
-      real zplanck(ngridmx),zpopsk(ngridmx,nlayermx)
-      real zdum1(ngridmx,nlayermx)
-      real zdum2(ngridmx,nlayermx)
+      real zflubid(ngrid)
+      real zplanck(ngrid),zpopsk(ngrid,nlayermx)
+      real zdum1(ngrid,nlayermx)
+      real zdum2(ngrid,nlayermx)
       real ztim1,ztim2,ztim3, z1,z2
       real ztime_fin
-      real zdh(ngridmx,nlayermx)
+      real zdh(ngrid,nlayermx)
       integer length
       parameter (length=100)
@@ -270,13 +265,13 @@
 ! local variables only used for diagnostics (output in file "diagfi" or "stats")
 ! ------------------------------------------------------------------------------
-      real ps(ngridmx), zt(ngridmx,nlayermx)
-      real zu(ngridmx,nlayermx),zv(ngridmx,nlayermx)
-      real zq(ngridmx,nlayermx,nqmx)
+      real ps(ngrid), zt(ngrid,nlayermx)
+      real zu(ngrid,nlayermx),zv(ngrid,nlayermx)
+      real zq(ngrid,nlayermx,nq)
       character*2 str2
       character*5 str5
-      real zdtadj(ngridmx,nlayermx)
-      real zdtdyn(ngridmx,nlayermx),ztprevious(ngridmx,nlayermx)
-      save ztprevious 
-      real reff(ngridmx,nlayermx) ! effective dust radius (used if doubleq=T)
+      real zdtadj(ngrid,nlayermx)
+      real zdtdyn(ngrid,nlayermx)
+      real,allocatable,dimension(:,:),save :: ztprevious
+      real reff(ngrid,nlayermx) ! effective dust radius (used if doubleq=T)
       real qtot1,qtot2            ! total aerosol mass
       integer igmin, lmin
@@ -285,12 +280,11 @@
       real zplev(ngrid,nlayermx+1),zplay(ngrid,nlayermx)
       real zstress(ngrid), cd
-      real hco2(nqmx), tmean, zlocal(nlayermx)
-      real vmr(ngridmx,nlayermx) ! volume mixing ratio
+      real hco2(nq), tmean, zlocal(nlayermx)
+      real vmr(ngrid,nlayermx) ! volume mixing ratio
 
       real time_phys
 
 !     reinstated by RW for diagnostic
-      real tau_col(ngridmx)
-      save tau_col
+      real,allocatable,dimension(:),save :: tau_col
       
 !     included by RW to reduce insanity of code
@@ -298,34 +292,34 @@
 
 !     included by RW to compute tracer column densities
-      real qcol(ngridmx,nqmx)
+      real qcol(ngrid,nq)
 
 !     included by RW for H2O precipitation
-      real zdtrain(ngridmx,nlayermx)
-      real zdqrain(ngridmx,nlayermx,nqmx)
-      real zdqsrain(ngridmx)
-      real zdqssnow(ngridmx)
-      real rainout(ngridmx)
+      real zdtrain(ngrid,nlayermx)
+      real zdqrain(ngrid,nlayermx,nq)
+      real zdqsrain(ngrid)
+      real zdqssnow(ngrid)
+      real rainout(ngrid)
 
 !     included by RW for H2O Manabe scheme
-      real dtmoist(ngridmx,nlayermx)
-      real dqmoist(ngridmx,nlayermx,nqmx)
-
-      real qvap(ngridmx,nlayermx)
-      real dqvaplscale(ngridmx,nlayermx)
-      real dqcldlscale(ngridmx,nlayermx)
-      real rneb_man(ngridmx,nlayermx)
-      real rneb_lsc(ngridmx,nlayermx)
+      real dtmoist(ngrid,nlayermx)
+      real dqmoist(ngrid,nlayermx,nq)
+
+      real qvap(ngrid,nlayermx)
+      real dqvaplscale(ngrid,nlayermx)
+      real dqcldlscale(ngrid,nlayermx)
+      real rneb_man(ngrid,nlayermx)
+      real rneb_lsc(ngrid,nlayermx)
 
 !     included by RW to account for surface cooling by evaporation
-      real dtsurfh2olat(ngridmx)
+      real dtsurfh2olat(ngrid)
 
 
 !     to test energy conservation (RW+JL)
-      real mass(ngridmx,nlayermx),massarea(ngridmx,nlayermx)
+      real mass(ngrid,nlayermx),massarea(ngrid,nlayermx)
       real dEtot, dEtots, AtmToSurf_TurbFlux
       real dEtotSW, dEtotsSW, dEtotLW, dEtotsLW
-      real dEzRadsw(ngridmx,nlayermx),dEzRadlw(ngridmx,nlayermx),dEzdiff(ngridmx,nlayermx)
-      real dEdiffs(ngridmx),dEdiff(ngridmx)
-      real madjdE(ngridmx), lscaledE(ngridmx)
+      real dEzRadsw(ngrid,nlayermx),dEzRadlw(ngrid,nlayermx),dEzdiff(ngrid,nlayermx)
+      real dEdiffs(ngrid),dEdiff(ngrid)
+      real madjdE(ngrid), lscaledE(ngrid)
 !JL12 conservation test for mean flow kinetic energy has been disabled temporarily
       
@@ -333,11 +327,11 @@
 
 !     included by BC for evaporation     
-      real qevap(ngridmx,nlayermx,nqmx)
-      real tevap(ngridmx,nlayermx)
-      real dqevap1(ngridmx,nlayermx)
-      real dtevap1(ngridmx,nlayermx)
+      real qevap(ngrid,nlayermx,nq)
+      real tevap(ngrid,nlayermx)
+      real dqevap1(ngrid,nlayermx)
+      real dtevap1(ngrid,nlayermx)
 
 !     included by BC for hydrology
-      real hice(ngridmx)
+      real hice(ngrid)
 
 !     included by RW to test water conservation (by routine)
@@ -349,9 +343,9 @@
 
 !     included by RW for RH diagnostic
-      real qsat(ngridmx,nlayermx), RH(ngridmx,nlayermx), H2Omaxcol(ngridmx),psat_tmp
+      real qsat(ngrid,nlayermx), RH(ngrid,nlayermx), H2Omaxcol(ngrid),psat_tmp
 
 !     included by RW for hydrology
-      real dqs_hyd(ngridmx,nqmx)
-      real zdtsurf_hyd(ngridmx)
+      real dqs_hyd(ngrid,nq)
+      real zdtsurf_hyd(ngrid)
 
 !     included by RW for water cycle conservation tests
@@ -360,10 +354,10 @@
 !     included by BC for double radiative transfer call
       logical clearsky
-      real zdtsw1(ngridmx,nlayermx)
-      real zdtlw1(ngridmx,nlayermx)
-      real fluxsurf_lw1(ngridmx)     
-      real fluxsurf_sw1(ngridmx)  
-      real fluxtop_lw1(ngridmx)    
-      real fluxabs_sw1(ngridmx)  
+      real zdtsw1(ngrid,nlayermx)
+      real zdtlw1(ngrid,nlayermx)
+      real fluxsurf_lw1(ngrid)     
+      real fluxsurf_sw1(ngrid)  
+      real fluxtop_lw1(ngrid)    
+      real fluxabs_sw1(ngrid)  
       real tau_col1(ngrid)
       real OLR_nu1(ngrid,L_NSPECTI)
@@ -372,15 +366,14 @@
 
 !     included by BC for cloud fraction computations
-      real,save :: cloudfrac(ngridmx,nlayermx)
-      real,save :: totcloudfrac(ngridmx)
+      real,allocatable,dimension(:,:),save :: cloudfrac
+      real,allocatable,dimension(:),save :: totcloudfrac
 
 !     included by RW for vdifc water conservation test
       real nconsMAX
-      real vdifcncons(ngridmx)
-      real cadjncons(ngridmx)
-
-!      double precision qsurf_hist(ngridmx,nqmx)
-      real qsurf_hist(ngridmx,nqmx)
-      save qsurf_hist
+      real vdifcncons(ngrid)
+      real cadjncons(ngrid)
+
+!      double precision qsurf_hist(ngrid,nq)
+      real,allocatable,dimension(:,:),save :: qsurf_hist
 
 !     included by RW for temp convadj conservation test
@@ -392,18 +385,19 @@
 
 !     included by RW for runway greenhouse 1D study
-      real muvar(ngridmx,nlayermx+1)
+      real muvar(ngrid,nlayermx+1)
 
 !     included by RW for variable H2O particle sizes
-      real,save :: reffrad(ngridmx,nlayermx,naerkind) ! aerosol effective radius (m)
-      real,save :: nueffrad(ngridmx,nlayermx,naerkind) ! aerosol effective radius variance
-      real :: reffh2oliq(ngridmx,nlayermx) ! liquid water particles effective radius (m)
-      real :: reffh2oice(ngridmx,nlayermx) ! water ice particles effective radius (m)
-      real reffH2O(ngridmx,nlayermx)
-      real reffcol(ngridmx,naerkind)
+      real,allocatable,dimension(:,:,:),save :: reffrad ! aerosol effective radius (m)
+      real,allocatable,dimension(:,:,:),save :: nueffrad ! aerosol effective radius variance
+      real :: nueffrad_dummy(ngrid,nlayermx,naerkind) !! AS. This is temporary. Check below why.
+      real :: reffh2oliq(ngrid,nlayermx) ! liquid water particles effective radius (m)
+      real :: reffh2oice(ngrid,nlayermx) ! water ice particles effective radius (m)
+      real reffH2O(ngrid,nlayermx)
+      real reffcol(ngrid,naerkind)
 
 !     included by RW for sourceevol
-      real, save :: ice_initial(ngridmx)!, isoil
+      real,allocatable,dimension(:),save :: ice_initial
       real delta_ice,ice_tot
-      real, save :: ice_min(ngridmx)
+      real,allocatable,dimension(:),save :: ice_min
       
       integer num_run
@@ -411,5 +405,42 @@
       
 !=======================================================================
-      
+
+      !!! ALLOCATE SAVED ARRAYS
+      IF (.not. ALLOCATED(tsurf)) ALLOCATE(tsurf(ngrid))
+      IF (.not. ALLOCATED(tsoil)) ALLOCATE(tsoil(ngrid,nsoilmx))    
+      IF (.not. ALLOCATED(albedo)) ALLOCATE(albedo(ngrid))          
+      IF (.not. ALLOCATED(albedo0)) ALLOCATE(albedo0(ngrid))          
+      IF (.not. ALLOCATED(rnat)) ALLOCATE(rnat(ngrid))         
+      IF (.not. ALLOCATED(emis)) ALLOCATE(emis(ngrid))   
+      IF (.not. ALLOCATED(dtrad)) ALLOCATE(dtrad(ngrid,nlayermx))
+      IF (.not. ALLOCATED(fluxrad_sky)) ALLOCATE(fluxrad_sky(ngrid))
+      IF (.not. ALLOCATED(fluxrad)) ALLOCATE(fluxrad(ngrid))    
+      IF (.not. ALLOCATED(capcal)) ALLOCATE(capcal(ngrid))    
+      IF (.not. ALLOCATED(fluxgrd)) ALLOCATE(fluxgrd(ngrid))  
+      IF (.not. ALLOCATED(qsurf)) ALLOCATE(qsurf(ngrid,nq))  
+      IF (.not. ALLOCATED(q2)) ALLOCATE(q2(ngrid,nlayermx+1)) 
+      IF (.not. ALLOCATED(ztprevious)) ALLOCATE(ztprevious(ngrid,nlayermx))
+      IF (.not. ALLOCATED(cloudfrac)) ALLOCATE(cloudfrac(ngrid,nlayermx))
+      IF (.not. ALLOCATED(totcloudfrac)) ALLOCATE(totcloudfrac(ngrid))
+      IF (.not. ALLOCATED(qsurf_hist)) ALLOCATE(qsurf_hist(ngrid,nq))
+      IF (.not. ALLOCATED(reffrad)) ALLOCATE(reffrad(ngrid,nlayermx,naerkind))
+      IF (.not. ALLOCATED(nueffrad)) ALLOCATE(nueffrad(ngrid,nlayermx,naerkind))
+      IF (.not. ALLOCATED(ice_initial)) ALLOCATE(ice_initial(ngrid))
+      IF (.not. ALLOCATED(ice_min)) ALLOCATE(ice_min(ngrid)) 
+
+      IF (.not. ALLOCATED(fluxsurf_lw)) ALLOCATE(fluxsurf_lw(ngrid))
+      IF (.not. ALLOCATED(fluxsurf_sw)) ALLOCATE(fluxsurf_sw(ngrid))
+      IF (.not. ALLOCATED(fluxtop_lw)) ALLOCATE(fluxtop_lw(ngrid))
+      IF (.not. ALLOCATED(fluxabs_sw)) ALLOCATE(fluxabs_sw(ngrid))
+      IF (.not. ALLOCATED(fluxtop_dn)) ALLOCATE(fluxtop_dn(ngrid))
+      IF (.not. ALLOCATED(fluxdyn)) ALLOCATE(fluxdyn(ngrid))
+      IF (.not. ALLOCATED(OLR_nu)) ALLOCATE(OLR_nu(ngrid,L_NSPECTI))
+      IF (.not. ALLOCATED(OSR_nu)) ALLOCATE(OSR_nu(ngrid,L_NSPECTV))
+      IF (.not. ALLOCATED(sensibFlux)) ALLOCATE(sensibFlux(ngrid))
+      IF (.not. ALLOCATED(zdtlw)) ALLOCATE(zdtlw(ngrid,nlayermx))
+      IF (.not. ALLOCATED(zdtsw)) ALLOCATE(zdtsw(ngrid,nlayermx))
+      IF (.not. ALLOCATED(tau_col)) ALLOCATE(tau_col(ngrid))
+
+!=======================================================================
 
 ! 1. Initialisation
@@ -420,4 +451,9 @@
       if (firstcall) then
 
+         print*,'FIRSTCALL INITIALIZATION'
+
+         !! this is defined in comsaison_h
+         ALLOCATE(mu0(ngrid))
+         ALLOCATE(fract(ngrid))
 
 !        variables set to 0
@@ -438,5 +474,5 @@
          tracerdyn=tracer
          if (tracer) then
-            call initracer()
+            call initracer(ngrid,nq,nametrac)
          endif ! end tracer
 
@@ -445,5 +481,5 @@
 !        read startfi (initial parameters)
 !        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         call phyetat0("startfi.nc",0,0,nsoilmx,nq,           &
+         call phyetat0(ngrid,"startfi.nc",0,0,nsoilmx,nq,   &
                day_ini,time_phys,tsurf,tsoil,emis,q2,qsurf,   &
                cloudfrac,totcloudfrac,hice)
@@ -461,5 +497,5 @@
 !        Initialize albedo and orbital calculation
 !        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         call surfini(ngrid,qsurf,albedo0)
+         call surfini(ngrid,nq,qsurf,albedo0)
          call iniorbit(apoastr,periastr,year_day,peri_day,obliquit)
 
@@ -474,5 +510,5 @@
 !        ~~~~~~~~~~~~~~~
          if (callsoil) then
-            call soil(ngrid,nsoilmx,firstcall,inertiedat,     &
+            call soil(ngrid,nsoilmx,firstcall,lastcall,inertiedat, &
                 ptimestep,tsurf,tsoil,capcal,fluxgrd)
          else
@@ -506,5 +542,5 @@
 !        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          rnat(:)=1
-         do ig=1,ngridmx
+         do ig=1,ngrid
 !            if(iceball.or.oceanball.or.(inertiedat(ig,1).gt.1.E4))then
             if(inertiedat(ig,1).gt.1.E4)then
@@ -562,4 +598,6 @@
                             ! need epsi for the wvp definitions in callcorrk.F
 
+         print*,'end FIRSTCALL INITIALIZATION'
+
       endif        !  (end of "if firstcall")
 
@@ -568,25 +606,19 @@
 ! ---------------------------------------------------
 
-      if (ngrid.NE.ngridmx) then
-         print*,'STOP in PHYSIQ'
-         print*,'Probleme de dimensions :'
-         print*,'ngrid     = ',ngrid
-         print*,'ngridmx   = ',ngridmx
-         stop
-      endif
+      print*,'ALL INITIALIZATION'
 
 !     Initialize various variables
 !     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-      pdu(1:ngridmx,1:nlayermx) = 0.0
-      pdv(1:ngridmx,1:nlayermx) = 0.0
+      pdu(1:ngrid,1:nlayermx) = 0.0
+      pdv(1:ngrid,1:nlayermx) = 0.0
       if ( .not.nearco2cond ) then
-         pdt(1:ngridmx,1:nlayermx) = 0.0
+         pdt(1:ngrid,1:nlayermx) = 0.0
       endif
-      pdq(1:ngridmx,1:nlayermx,1:nqmx) = 0.0
-      pdpsrf(1:ngridmx)       = 0.0
-      zflubid(1:ngridmx)      = 0.0
-      zdtsurf(1:ngridmx)      = 0.0
-      dqsurf(1:ngridmx,1:nqmx)= 0.0
+      pdq(1:ngrid,1:nlayermx,1:nq) = 0.0
+      pdpsrf(1:ngrid)       = 0.0
+      zflubid(1:ngrid)      = 0.0
+      zdtsurf(1:ngrid)      = 0.0
+      dqsurf(1:ngrid,1:nq)= 0.0
 
       zday=pday+ptime ! compute time, in sols (and fraction thereof)
@@ -603,8 +635,8 @@
 !     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-      zzlay(1:ngridmx,1:nlayermx)=pphi(1:ngridmx,1:nlayermx)/g
-
-      zzlev(1:ngridmx,1)=0.
-      zzlev(1:ngridmx,nlayer+1)=1.e7    ! dummy top of last layer above 10000 km...
+      zzlay(1:ngrid,1:nlayermx)=pphi(1:ngrid,1:nlayermx)/g
+
+      zzlev(1:ngrid,1)=0.
+      zzlev(1:ngrid,nlayer+1)=1.e7    ! dummy top of last layer above 10000 km...
 
       do l=2,nlayer
@@ -621,5 +653,5 @@
 
       do l=1,nlayer         
-         do ig=1,ngrid 
+         do ig=1,ngrid
             zpopsk(ig,l)=(pplay(ig,l)/pplev(ig,1))**rcp
             zh(ig,l)=pt(ig,l)/zpopsk(ig,l)
@@ -628,4 +660,6 @@
          enddo
       enddo
+
+      print*,'end ALL INITIALIZATION'
 
 !-----------------------------------------------------------------------
@@ -684,5 +718,5 @@
                       zdtlw,zdtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,    &
                       fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,               &
-                      reffrad,tau_col,cloudfrac,totcloudfrac,            &
+                      reffrad,nueffrad,tau_col,cloudfrac,totcloudfrac,   &
                       clearsky,firstcall,lastcall)      
 
@@ -698,5 +732,5 @@
                       zdtlw1,zdtsw1,fluxsurf_lw1,fluxsurf_sw1,fluxtop_lw1, &
                       fluxabs_sw1,fluxtop_dn,OLR_nu1,OSR_nu1,              &
-                      reffrad,tau_col1,cloudfrac,totcloudfrac,             &
+                      reffrad,nueffrad,tau_col1,cloudfrac,totcloudfrac,    &
                       clearsky,firstcall,lastcall)
                  clearsky = .false.  ! just in case.     
@@ -725,14 +759,14 @@
 !             Radiative flux from the sky absorbed by the surface (W.m-2)
               GSR=0.0
-              fluxrad_sky(1:ngridmx)=emis(1:ngridmx)*fluxsurf_lw(1:ngridmx)+fluxsurf_sw(1:ngridmx)*(1.-albedo(1:ngridmx))
+              fluxrad_sky(1:ngrid)=emis(1:ngrid)*fluxsurf_lw(1:ngrid)+fluxsurf_sw(1:ngrid)*(1.-albedo(1:ngrid))
 
               if(noradsurf)then ! no lower surface; SW flux just disappears
-                 GSR = SUM(fluxsurf_sw(1:ngridmx)*area(1:ngridmx))/totarea
-                 fluxrad_sky(1:ngridmx)=emis(1:ngridmx)*fluxsurf_lw(1:ngridmx)
+                 GSR = SUM(fluxsurf_sw(1:ngrid)*area(1:ngrid))/totarea
+                 fluxrad_sky(1:ngrid)=emis(1:ngrid)*fluxsurf_lw(1:ngrid)
                  print*,'SW lost in deep atmosphere = ',GSR,' W m^-2'
               endif
 
 !             Net atmospheric radiative heating rate (K.s-1)
-              dtrad(1:ngridmx,1:nlayermx)=zdtsw(1:ngridmx,1:nlayermx)+zdtlw(1:ngridmx,1:nlayermx)
+              dtrad(1:ngrid,1:nlayermx)=zdtsw(1:ngrid,1:nlayermx)+zdtlw(1:ngrid,1:nlayermx)
 
            elseif(newtonian)then
@@ -740,7 +774,7 @@
 !          b) Call Newtonian cooling scheme
 !          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-              call newtrelax(mu0,sinlat,zpopsk,pt,pplay,pplev,dtrad,firstcall)
-
-              zdtsurf(1:ngridmx) = +(pt(1:ngridmx,1)-tsurf(1:ngridmx))/ptimestep
+              call newtrelax(ngrid,mu0,sinlat,zpopsk,pt,pplay,pplev,dtrad,firstcall)
+
+              zdtsurf(1:ngrid) = +(pt(1:ngrid,1)-tsurf(1:ngrid))/ptimestep
               ! e.g. surface becomes proxy for 1st atmospheric layer ?
 
@@ -749,15 +783,15 @@
 !          c) Atmosphere has no radiative effect
 !          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-              fluxtop_dn(1:ngridmx)  = fract(1:ngridmx)*mu0(1:ngridmx)*Fat1AU/dist_star**2
+              fluxtop_dn(1:ngrid)  = fract(1:ngrid)*mu0(1:ngrid)*Fat1AU/dist_star**2
               if(ngrid.eq.1)then ! / by 4 globally in 1D case...
                  fluxtop_dn(1)  = fract(1)*Fat1AU/dist_star**2/2.0
               endif
-              fluxsurf_sw(1:ngridmx) = fluxtop_dn(1:ngridmx)
-              fluxrad_sky(1:ngridmx) = fluxtop_dn(1:ngridmx)*(1.-albedo(1:ngridmx))
-              fluxtop_lw(1:ngridmx)  = emis(1:ngridmx)*sigma*tsurf(1:ngridmx)**4
+              fluxsurf_sw(1:ngrid) = fluxtop_dn(1:ngrid)
+              fluxrad_sky(1:ngrid) = fluxtop_dn(1:ngrid)*(1.-albedo(1:ngrid))
+              fluxtop_lw(1:ngrid)  = emis(1:ngrid)*sigma*tsurf(1:ngrid)**4
               ! radiation skips the atmosphere entirely
 
 
-              dtrad(1:ngridmx,1:nlayermx)=0.0
+              dtrad(1:ngrid,1:nlayermx)=0.0
               ! hence no atmospheric radiative heating
 
@@ -765,13 +799,13 @@
 
         endif ! of if(mod(icount-1,iradia).eq.0)
-
+       
 
 !    Transformation of the radiative tendencies
 !    ------------------------------------------
 
-        zplanck(1:ngridmx)=tsurf(1:ngridmx)*tsurf(1:ngridmx)
-        zplanck(1:ngridmx)=emis(1:ngridmx)*sigma*zplanck(1:ngridmx)*zplanck(1:ngridmx)
-        fluxrad(1:ngridmx)=fluxrad_sky(1:ngridmx)-zplanck(1:ngridmx)
-        pdt(1:ngridmx,1:nlayermx)=pdt(1:ngridmx,1:nlayermx)+dtrad(1:ngridmx,1:nlayermx)
+        zplanck(1:ngrid)=tsurf(1:ngrid)*tsurf(1:ngrid)
+        zplanck(1:ngrid)=emis(1:ngrid)*sigma*zplanck(1:ngrid)*zplanck(1:ngrid)
+        fluxrad(1:ngrid)=fluxrad_sky(1:ngrid)-zplanck(1:ngrid)
+        pdt(1:ngrid,1:nlayermx)=pdt(1:ngrid,1:nlayermx)+dtrad(1:ngrid,1:nlayermx)
 
 !-------------------------
@@ -794,4 +828,5 @@
 !-------------------------
 
+      print*,'end RADIATIVE TRANSFER'
       endif ! of if (callrad)
 
@@ -802,8 +837,8 @@
       if (calldifv) then
       
-         zflubid(1:ngridmx)=fluxrad(1:ngridmx)+fluxgrd(1:ngridmx)
-
-         zdum1(1:ngridmx,1:nlayermx)=0.0
-         zdum2(1:ngridmx,1:nlayermx)=0.0
+         zflubid(1:ngrid)=fluxrad(1:ngrid)+fluxgrd(1:ngrid)
+
+         zdum1(1:ngrid,1:nlayermx)=0.0
+         zdum2(1:ngrid,1:nlayermx)=0.0
 
 
@@ -821,5 +856,5 @@
 	 else
 	 
-           zdh(1:ngridmx,1:nlayermx)=pdt(1:ngridmx,1:nlayermx)/zpopsk(1:ngridmx,1:nlayermx)
+           zdh(1:ngrid,1:nlayermx)=pdt(1:ngrid,1:nlayermx)/zpopsk(1:ngrid,1:nlayermx)
  
            call vdifc(ngrid,nlayer,nq,rnat,zpopsk,   &
@@ -831,16 +866,16 @@
 	      sensibFlux,q2,zdqdif,zdqsdif,lastcall)
 
-           zdtdif(1:ngridmx,1:nlayermx)=zdhdif(1:ngridmx,1:nlayermx)*zpopsk(1:ngridmx,1:nlayermx) ! for diagnostic only
-	   zdqevap(1:ngridmx,1:nlayermx)=0.
+           zdtdif(1:ngrid,1:nlayermx)=zdhdif(1:ngrid,1:nlayermx)*zpopsk(1:ngrid,1:nlayermx) ! for diagnostic only
+	   zdqevap(1:ngrid,1:nlayermx)=0.
 
          end if !turbdiff
 
-         pdv(1:ngridmx,1:nlayermx)=pdv(1:ngridmx,1:nlayermx)+zdvdif(1:ngridmx,1:nlayermx)
-         pdu(1:ngridmx,1:nlayermx)=pdu(1:ngridmx,1:nlayermx)+zdudif(1:ngridmx,1:nlayermx)
-         pdt(1:ngridmx,1:nlayermx)=pdt(1:ngridmx,1:nlayermx)+zdtdif(1:ngridmx,1:nlayermx)
-         zdtsurf(1:ngridmx)=zdtsurf(1:ngridmx)+zdtsdif(1:ngridmx)
+         pdv(1:ngrid,1:nlayermx)=pdv(1:ngrid,1:nlayermx)+zdvdif(1:ngrid,1:nlayermx)
+         pdu(1:ngrid,1:nlayermx)=pdu(1:ngrid,1:nlayermx)+zdudif(1:ngrid,1:nlayermx)
+         pdt(1:ngrid,1:nlayermx)=pdt(1:ngrid,1:nlayermx)+zdtdif(1:ngrid,1:nlayermx)
+         zdtsurf(1:ngrid)=zdtsurf(1:ngrid)+zdtsdif(1:ngrid)
          if (tracer) then 
-           pdq(1:ngridmx,1:nlayermx,1:nqmx)=pdq(1:ngridmx,1:nlayermx,1:nqmx)+ zdqdif(1:ngridmx,1:nlayermx,1:nqmx) 
-           dqsurf(1:ngridmx,1:nqmx)=dqsurf(1:ngridmx,1:nqmx) + zdqsdif(1:ngridmx,1:nqmx)
+           pdq(1:ngrid,1:nlayermx,1:nq)=pdq(1:ngrid,1:nlayermx,1:nq)+ zdqdif(1:ngrid,1:nlayermx,1:nq) 
+           dqsurf(1:ngrid,1:nq)=dqsurf(1:ngrid,1:nq) + zdqsdif(1:ngrid,1:nq)
          end if ! of if (tracer)
 
@@ -899,8 +934,9 @@
          if(.not.newtonian)then
 
-            zdtsurf(1:ngridmx) = zdtsurf(1:ngridmx) + (fluxrad(1:ngridmx) + fluxgrd(1:ngridmx))/capcal(1:ngridmx)
-
-         endif
-
+            zdtsurf(1:ngrid) = zdtsurf(1:ngrid) + (fluxrad(1:ngrid) + fluxgrd(1:ngrid))/capcal(1:ngrid)
+
+         endif
+
+      print*,'end TURBULENCE'
       endif ! of if (calldifv)
 
@@ -912,8 +948,8 @@
       if(calladj) then
 
-         zdh(1:ngridmx,1:nlayermx) = pdt(1:ngridmx,1:nlayermx)/zpopsk(1:ngridmx,1:nlayermx)
-         zduadj(1:ngridmx,1:nlayermx)=0.0
-         zdvadj(1:ngridmx,1:nlayermx)=0.0
-         zdhadj(1:ngridmx,1:nlayermx)=0.0
+         zdh(1:ngrid,1:nlayermx) = pdt(1:ngrid,1:nlayermx)/zpopsk(1:ngrid,1:nlayermx)
+         zduadj(1:ngrid,1:nlayermx)=0.0
+         zdvadj(1:ngrid,1:nlayermx)=0.0
+         zdhadj(1:ngrid,1:nlayermx)=0.0
 
 
@@ -925,11 +961,11 @@
               zdqadj)
 
-         pdu(1:ngridmx,1:nlayermx) = pdu(1:ngridmx,1:nlayermx) + zduadj(1:ngridmx,1:nlayermx)
-         pdv(1:ngridmx,1:nlayermx) = pdv(1:ngridmx,1:nlayermx) + zdvadj(1:ngridmx,1:nlayermx)
-         pdt(1:ngridmx,1:nlayermx)    = pdt(1:ngridmx,1:nlayermx) + zdhadj(1:ngridmx,1:nlayermx)*zpopsk(1:ngridmx,1:nlayermx)
-         zdtadj(1:ngridmx,1:nlayermx) = zdhadj(1:ngridmx,1:nlayermx)*zpopsk(1:ngridmx,1:nlayermx) ! for diagnostic only
+         pdu(1:ngrid,1:nlayermx) = pdu(1:ngrid,1:nlayermx) + zduadj(1:ngrid,1:nlayermx)
+         pdv(1:ngrid,1:nlayermx) = pdv(1:ngrid,1:nlayermx) + zdvadj(1:ngrid,1:nlayermx)
+         pdt(1:ngrid,1:nlayermx)    = pdt(1:ngrid,1:nlayermx) + zdhadj(1:ngrid,1:nlayermx)*zpopsk(1:ngrid,1:nlayermx)
+         zdtadj(1:ngrid,1:nlayermx) = zdhadj(1:ngrid,1:nlayermx)*zpopsk(1:ngrid,1:nlayermx) ! for diagnostic only
  
          if(tracer) then 
-            pdq(1:ngridmx,1:nlayermx,1:nqmx) = pdq(1:ngridmx,1:nlayermx,1:nqmx) + zdqadj(1:ngridmx,1:nlayermx,1:nqmx) 
+            pdq(1:ngrid,1:nlayermx,1:nq) = pdq(1:ngrid,1:nlayermx,1:nq) + zdqadj(1:ngrid,1:nlayermx,1:nq) 
          end if
 
@@ -959,5 +995,6 @@
          endif
          !-------------------------
-               
+         
+      print*,'end CONVADJ'
       endif ! of if(calladj)
 
@@ -980,10 +1017,10 @@
 
 
-         pdt(1:ngridmx,1:nlayermx)=pdt(1:ngridmx,1:nlayermx)+zdtc(1:ngridmx,1:nlayermx)
-         pdv(1:ngridmx,1:nlayermx)=pdv(1:ngridmx,1:nlayermx)+zdvc(1:ngridmx,1:nlayermx)
-         pdu(1:ngridmx,1:nlayermx)=pdu(1:ngridmx,1:nlayermx)+zduc(1:ngridmx,1:nlayermx)
-         zdtsurf(1:ngridmx) = zdtsurf(1:ngridmx) + zdtsurfc(1:ngridmx)
-
-         pdq(1:ngridmx,1:nlayermx,1:nqmx)=pdq(1:ngridmx,1:nlayermx,1:nqmx)+ zdqc(1:ngridmx,1:nlayermx,1:nqmx) 
+         pdt(1:ngrid,1:nlayermx)=pdt(1:ngrid,1:nlayermx)+zdtc(1:ngrid,1:nlayermx)
+         pdv(1:ngrid,1:nlayermx)=pdv(1:ngrid,1:nlayermx)+zdvc(1:ngrid,1:nlayermx)
+         pdu(1:ngrid,1:nlayermx)=pdu(1:ngrid,1:nlayermx)+zduc(1:ngrid,1:nlayermx)
+         zdtsurf(1:ngrid) = zdtsurf(1:ngrid) + zdtsurfc(1:ngrid)
+
+         pdq(1:ngrid,1:nlayermx,1:nq)=pdq(1:ngrid,1:nlayermx,1:nq)+ zdqc(1:ngrid,1:nlayermx,1:nq) 
          ! Note: we do not add surface co2ice tendency
          ! because qsurf(:,igcm_co2_ice) is updated in condens_co2cloud
@@ -1021,14 +1058,14 @@
 !             ----------------
 
-	       dqmoist(1:ngridmx,1:nlayermx,1:nqmx)=0.
-	       dtmoist(1:ngridmx,1:nlayermx)=0.
-
-               call moistadj(pt,pq,pdq,pplev,pplay,dtmoist,dqmoist,ptimestep,rneb_man)
-
-               pdq(1:ngridmx,1:nlayermx,igcm_h2o_vap) = pdq(1:ngridmx,1:nlayermx,igcm_h2o_vap)   &
-	                  +dqmoist(1:ngridmx,1:nlayermx,igcm_h2o_vap)
-               pdq(1:ngridmx,1:nlayermx,igcm_h2o_ice) =pdq(1:ngridmx,1:nlayermx,igcm_h2o_ice)     &
-                          +dqmoist(1:ngridmx,1:nlayermx,igcm_h2o_ice)
-               pdt(1:ngridmx,1:nlayermx) = pdt(1:ngridmx,1:nlayermx)+dtmoist(1:ngridmx,1:nlayermx)
+	       dqmoist(1:ngrid,1:nlayermx,1:nq)=0.
+	       dtmoist(1:ngrid,1:nlayermx)=0.
+
+               call moistadj(ngrid,nq,pt,pq,pdq,pplev,pplay,dtmoist,dqmoist,ptimestep,rneb_man)
+
+               pdq(1:ngrid,1:nlayermx,igcm_h2o_vap) = pdq(1:ngrid,1:nlayermx,igcm_h2o_vap)   &
+	                  +dqmoist(1:ngrid,1:nlayermx,igcm_h2o_vap)
+               pdq(1:ngrid,1:nlayermx,igcm_h2o_ice) =pdq(1:ngrid,1:nlayermx,igcm_h2o_ice)     &
+                          +dqmoist(1:ngrid,1:nlayermx,igcm_h2o_ice)
+               pdt(1:ngrid,1:nlayermx) = pdt(1:ngrid,1:nlayermx)+dtmoist(1:ngrid,1:nlayermx)
 
                !-------------------------
@@ -1036,5 +1073,5 @@
                if(enertest)then
                   dEtot=cpp*SUM(massarea(:,:)*dtmoist(:,:))/totarea
-                  do ig = 1, ngrid
+                  do ig=1,ngrid
                      madjdE(ig) = cpp*SUM(mass(:,:)*dtmoist(:,:))
                   enddo
@@ -1055,14 +1092,14 @@
 !        --------------------------------
 
-               call largescale(ptimestep,pplev,pplay,pt,pq,pdt,pdq,dtlscale,dqvaplscale,dqcldlscale,rneb_lsc)
-
-               pdt(1:ngridmx,1:nlayermx) = pdt(1:ngridmx,1:nlayermx)+dtlscale(1:ngridmx,1:nlayermx)
-               pdq(1:ngridmx,1:nlayermx,igcm_h2o_vap) = pdq(1:ngridmx,1:nlayermx,igcm_h2o_vap)+dqvaplscale(1:ngridmx,1:nlayermx)
-               pdq(1:ngridmx,1:nlayermx,igcm_h2o_ice) = pdq(1:ngridmx,1:nlayermx,igcm_h2o_ice)+dqcldlscale(1:ngridmx,1:nlayermx)
+               call largescale(ngrid,nq,ptimestep,pplev,pplay,pt,pq,pdt,pdq,dtlscale,dqvaplscale,dqcldlscale,rneb_lsc)
+
+               pdt(1:ngrid,1:nlayermx) = pdt(1:ngrid,1:nlayermx)+dtlscale(1:ngrid,1:nlayermx)
+               pdq(1:ngrid,1:nlayermx,igcm_h2o_vap) = pdq(1:ngrid,1:nlayermx,igcm_h2o_vap)+dqvaplscale(1:ngrid,1:nlayermx)
+               pdq(1:ngrid,1:nlayermx,igcm_h2o_ice) = pdq(1:ngrid,1:nlayermx,igcm_h2o_ice)+dqcldlscale(1:ngrid,1:nlayermx)
 
                !-------------------------
                ! test energy conservation
                if(enertest)then
-                  do ig = 1, ngrid
+                  do ig=1,ngrid
                      lscaledE(ig) = cpp*SUM(mass(:,:)*dtlscale(:,:))
                   enddo
@@ -1083,5 +1120,5 @@
                ! compute cloud fraction
                do l = 1, nlayer
-                  do ig = 1,ngrid
+                  do ig=1,ngrid
                      cloudfrac(ig,l)=MAX(rneb_lsc(ig,l),rneb_man(ig,l)) 
                   enddo
@@ -1096,19 +1133,19 @@
             if(waterrain)then
 
-               zdqrain(1:ngridmx,1:nlayermx,1:nqmx) = 0.0
-               zdqsrain(1:ngridmx)    = 0.0
-               zdqssnow(1:ngridmx)    = 0.0
-
-               call rain(ptimestep,pplev,pplay,pt,pdt,pq,pdq,            &
+               zdqrain(1:ngrid,1:nlayermx,1:nq) = 0.0
+               zdqsrain(1:ngrid)    = 0.0
+               zdqssnow(1:ngrid)    = 0.0
+
+               call rain(ngrid,nq,ptimestep,pplev,pplay,pt,pdt,pq,pdq,            &
                    zdtrain,zdqrain,zdqsrain,zdqssnow,cloudfrac)
 
-               pdq(1:ngridmx,1:nlayermx,igcm_h2o_vap) = pdq(1:ngridmx,1:nlayermx,igcm_h2o_vap) &
-	             +zdqrain(1:ngridmx,1:nlayermx,igcm_h2o_vap)
-               pdq(1:ngridmx,1:nlayermx,igcm_h2o_ice) = pdq(1:ngridmx,1:nlayermx,igcm_h2o_ice) &
-	             +zdqrain(1:ngridmx,1:nlayermx,igcm_h2o_ice)
-               pdt(1:ngridmx,1:nlayermx) = pdt(1:ngridmx,1:nlayermx)+zdtrain(1:ngridmx,1:nlayermx)
-               dqsurf(1:ngridmx,igcm_h2o_vap) = dqsurf(1:ngridmx,igcm_h2o_vap)+zdqsrain(1:ngridmx) ! a bug was here
-               dqsurf(1:ngridmx,igcm_h2o_ice) = dqsurf(1:ngridmx,igcm_h2o_ice)+zdqssnow(1:ngridmx)
-               rainout(1:ngridmx)             = zdqsrain(1:ngridmx)+zdqssnow(1:ngridmx) ! diagnostic   
+               pdq(1:ngrid,1:nlayermx,igcm_h2o_vap) = pdq(1:ngrid,1:nlayermx,igcm_h2o_vap) &
+	             +zdqrain(1:ngrid,1:nlayermx,igcm_h2o_vap)
+               pdq(1:ngrid,1:nlayermx,igcm_h2o_ice) = pdq(1:ngrid,1:nlayermx,igcm_h2o_ice) &
+	             +zdqrain(1:ngrid,1:nlayermx,igcm_h2o_ice)
+               pdt(1:ngrid,1:nlayermx) = pdt(1:ngrid,1:nlayermx)+zdtrain(1:ngrid,1:nlayermx)
+               dqsurf(1:ngrid,igcm_h2o_vap) = dqsurf(1:ngrid,igcm_h2o_vap)+zdqsrain(1:ngrid) ! a bug was here
+               dqsurf(1:ngrid,igcm_h2o_ice) = dqsurf(1:ngrid,igcm_h2o_ice)+zdqssnow(1:ngrid)
+               rainout(1:ngrid)             = zdqsrain(1:ngrid)+zdqssnow(1:ngrid) ! diagnostic   
 
 
@@ -1147,6 +1184,6 @@
 !        ------------- 
         if (sedimentation) then 
-           zdqsed(1:ngridmx,1:nlayermx,1:nqmx) = 0.0
-           zdqssed(1:ngridmx,1:nqmx)  = 0.0
+           zdqsed(1:ngrid,1:nlayermx,1:nq) = 0.0
+           zdqssed(1:ngrid,1:nq)  = 0.0
 
 
@@ -1179,6 +1216,6 @@
               ! and as in rain.F90, whether it falls as rain or snow depends
               ! only on the surface temperature
-           pdq(1:ngridmx,1:nlayermx,1:nqmx) = pdq(1:ngridmx,1:nlayermx,1:nqmx) + zdqsed(1:ngridmx,1:nlayermx,1:nqmx)
-           dqsurf(1:ngridmx,1:nqmx) = dqsurf(1:ngridmx,1:nqmx) + zdqssed(1:ngridmx,1:nqmx)
+           pdq(1:ngrid,1:nlayermx,1:nq) = pdq(1:ngrid,1:nlayermx,1:nq) + zdqsed(1:ngrid,1:nlayermx,1:nq)
+           dqsurf(1:ngrid,1:nq) = dqsurf(1:ngrid,1:nq) + zdqssed(1:ngrid,1:nq)
 
            !-------------------------
@@ -1205,13 +1242,13 @@
          if(mass_redistrib) then
 
-            zdmassmr(1:ngridmx,1:nlayermx) = mass(1:ngridmx,1:nlayermx) * &
-	       (   zdqevap(1:ngridmx,1:nlayermx)                          &
-	         + zdqrain(1:ngridmx,1:nlayermx,igcm_h2o_vap)             &
-		 + dqmoist(1:ngridmx,1:nlayermx,igcm_h2o_vap)             &
-		 + dqvaplscale(1:ngridmx,1:nlayermx) )
+            zdmassmr(1:ngrid,1:nlayermx) = mass(1:ngrid,1:nlayermx) * &
+	       (   zdqevap(1:ngrid,1:nlayermx)                          &
+	         + zdqrain(1:ngrid,1:nlayermx,igcm_h2o_vap)             &
+		 + dqmoist(1:ngrid,1:nlayermx,igcm_h2o_vap)             &
+		 + dqvaplscale(1:ngrid,1:nlayermx) )
 		 
             
-	    call writediagfi(ngridmx,"mass_evap","mass gain"," ",3,zdmassmr)
-	    call writediagfi(ngridmx,"mass","mass"," ",3,mass)
+	    call writediagfi(ngrid,"mass_evap","mass gain"," ",3,zdmassmr)
+	    call writediagfi(ngrid,"mass","mass"," ",3,mass)
 
 	    call mass_redistribution(ngrid,nlayer,nq,ptimestep,   &
@@ -1221,11 +1258,11 @@
 	 
 
-            pdq(1:ngridmx,1:nlayermx,1:nqmx) = pdq(1:ngridmx,1:nlayermx,1:nqmx) + zdqmr(1:ngridmx,1:nlayermx,1:nqmx)
-            dqsurf(1:ngridmx,1:nqmx)         = dqsurf(1:ngridmx,1:nqmx) + zdqsurfmr(1:ngridmx,1:nqmx)
-            pdt(1:ngridmx,1:nlayermx)        = pdt(1:ngridmx,1:nlayermx) + zdtmr(1:ngridmx,1:nlayermx)
-            pdu(1:ngridmx,1:nlayermx)        = pdu(1:ngridmx,1:nlayermx) + zdumr(1:ngridmx,1:nlayermx)
-            pdv(1:ngridmx,1:nlayermx)        = pdv(1:ngridmx,1:nlayermx) + zdvmr(1:ngridmx,1:nlayermx)
-	    pdpsrf(1:ngridmx)                = pdpsrf(1:ngridmx) + zdpsrfmr(1:ngridmx)
-            zdtsurf(1:ngridmx)               = zdtsurf(1:ngridmx) + zdtsurfmr(1:ngridmx)
+            pdq(1:ngrid,1:nlayermx,1:nq) = pdq(1:ngrid,1:nlayermx,1:nq) + zdqmr(1:ngrid,1:nlayermx,1:nq)
+            dqsurf(1:ngrid,1:nq)         = dqsurf(1:ngrid,1:nq) + zdqsurfmr(1:ngrid,1:nq)
+            pdt(1:ngrid,1:nlayermx)        = pdt(1:ngrid,1:nlayermx) + zdtmr(1:ngrid,1:nlayermx)
+            pdu(1:ngrid,1:nlayermx)        = pdu(1:ngrid,1:nlayermx) + zdumr(1:ngrid,1:nlayermx)
+            pdv(1:ngrid,1:nlayermx)        = pdv(1:ngrid,1:nlayermx) + zdvmr(1:ngrid,1:nlayermx)
+	    pdpsrf(1:ngrid)                = pdpsrf(1:ngrid) + zdpsrfmr(1:ngrid)
+            zdtsurf(1:ngrid)               = zdtsurf(1:ngrid) + zdtsurfmr(1:ngrid)
 	    
 !	    print*,'after mass redistrib, q=',pq(211,1:nlayermx,igcm_h2o_vap)+ptimestep*pdq(211,1:nlayermx,igcm_h2o_vap) 
@@ -1240,10 +1277,10 @@
          if(hydrology)then
 
-            call hydrol(ptimestep,rnat,tsurf,qsurf,dqsurf,dqs_hyd,    &
+            call hydrol(ngrid,nq,ptimestep,rnat,tsurf,qsurf,dqsurf,dqs_hyd,    &
                capcal,albedo0,albedo,mu0,zdtsurf,zdtsurf_hyd,hice)
             ! note: for now, also changes albedo in the subroutine
 
-            zdtsurf(1:ngridmx) = zdtsurf(1:ngridmx) + zdtsurf_hyd(1:ngridmx)
-            qsurf(1:ngridmx,1:nqmx) = qsurf(1:ngridmx,1:nqmx) + ptimestep*dqs_hyd(1:ngridmx,1:nqmx)
+            zdtsurf(1:ngrid) = zdtsurf(1:ngrid) + zdtsurf_hyd(1:ngrid)
+            qsurf(1:ngrid,1:nq) = qsurf(1:ngrid,1:nq) + ptimestep*dqs_hyd(1:ngrid,1:nq)
             ! when hydrology is used, other dqsurf tendencies are all added to dqs_hyd inside
 
@@ -1269,5 +1306,5 @@
          ELSE     ! of if (hydrology)
 
-            qsurf(1:ngridmx,1:nqmx)=qsurf(1:ngridmx,1:nqmx)+ptimestep*dqsurf(1:ngridmx,1:nqmx)
+            qsurf(1:ngrid,1:nq)=qsurf(1:ngrid,1:nq)+ptimestep*dqsurf(1:ngrid,1:nq)
 
          END IF   ! of if (hydrology)
@@ -1280,5 +1317,5 @@
 
          if(ice_update)then
-            ice_min(1:ngridmx)=min(ice_min(1:ngridmx),qsurf(1:ngridmx,igcm_h2o_ice))
+            ice_min(1:ngrid)=min(ice_min(1:ngrid),qsurf(1:ngrid,igcm_h2o_ice))
          endif
 
@@ -1291,9 +1328,9 @@
 
 !     Increment surface temperature
-      tsurf(1:ngridmx)=tsurf(1:ngridmx)+ptimestep*zdtsurf(1:ngridmx) 
+      tsurf(1:ngrid)=tsurf(1:ngrid)+ptimestep*zdtsurf(1:ngrid) 
 
 !     Compute soil temperatures and subsurface heat flux
       if (callsoil) then
-         call soil(ngrid,nsoilmx,.false.,inertiedat,        &
+         call soil(ngrid,nsoilmx,.false.,lastcall,inertiedat,   &
                 ptimestep,tsurf,tsoil,capcal,fluxgrd)
       endif
@@ -1317,14 +1354,14 @@
  
       ! temperature, zonal and meridional wind
-      zt(1:ngridmx,1:nlayermx) = pt(1:ngridmx,1:nlayermx) + pdt(1:ngridmx,1:nlayermx)*ptimestep
-      zu(1:ngridmx,1:nlayermx) = pu(1:ngridmx,1:nlayermx) + pdu(1:ngridmx,1:nlayermx)*ptimestep
-      zv(1:ngridmx,1:nlayermx) = pv(1:ngridmx,1:nlayermx) + pdv(1:ngridmx,1:nlayermx)*ptimestep
+      zt(1:ngrid,1:nlayermx) = pt(1:ngrid,1:nlayermx) + pdt(1:ngrid,1:nlayermx)*ptimestep
+      zu(1:ngrid,1:nlayermx) = pu(1:ngrid,1:nlayermx) + pdu(1:ngrid,1:nlayermx)*ptimestep
+      zv(1:ngrid,1:nlayermx) = pv(1:ngrid,1:nlayermx) + pdv(1:ngrid,1:nlayermx)*ptimestep
 
       ! diagnostic
-      zdtdyn(1:ngridmx,1:nlayermx)     = pt(1:ngridmx,1:nlayermx)-ztprevious(1:ngridmx,1:nlayermx)
-      ztprevious(1:ngridmx,1:nlayermx) = zt(1:ngridmx,1:nlayermx)
+      zdtdyn(1:ngrid,1:nlayermx)     = pt(1:ngrid,1:nlayermx)-ztprevious(1:ngrid,1:nlayermx)
+      ztprevious(1:ngrid,1:nlayermx) = zt(1:ngrid,1:nlayermx)
 
       if(firstcall)then
-         zdtdyn(1:ngridmx,1:nlayermx)=0.0
+         zdtdyn(1:ngrid,1:nlayermx)=0.0
       endif
 
@@ -1335,13 +1372,13 @@
 
       ! tracers
-      zq(1:ngridmx,1:nlayermx,1:nqmx) = pq(1:ngridmx,1:nlayermx,1:nqmx) + pdq(1:ngridmx,1:nlayermx,1:nqmx)*ptimestep
+      zq(1:ngrid,1:nlayermx,1:nq) = pq(1:ngrid,1:nlayermx,1:nq) + pdq(1:ngrid,1:nlayermx,1:nq)*ptimestep
 
       ! surface pressure
-      ps(1:ngridmx) = pplev(1:ngridmx,1) + pdpsrf(1:ngridmx)*ptimestep
+      ps(1:ngrid) = pplev(1:ngrid,1) + pdpsrf(1:ngrid)*ptimestep
 
       ! pressure
       do l=1,nlayer
-          zplev(1:ngridmx,l) = pplev(1:ngridmx,l)/pplev(1:ngridmx,1)*ps(:)
-          zplay(1:ngridmx,l) = pplay(1:ngridmx,l)/pplev(1:ngridmx,1)*ps(1:ngridmx)
+          zplev(1:ngrid,l) = pplev(1:ngrid,l)/pplev(1:ngrid,1)*ps(:)
+          zplay(1:ngrid,l) = pplay(1:ngrid,l)/pplev(1:ngrid,1)*ps(1:ngrid)
       enddo
 
@@ -1373,5 +1410,5 @@
          GND = SUM(area(:)*fluxgrd(:))/totarea
          DYN = SUM(area(:)*fluxdyn(:))/totarea
-         do ig=1,ngrid             
+         do ig=1,ngrid
             if(fluxtop_dn(ig).lt.0.0)then
                print*,'fluxtop_dn has gone crazy'
@@ -1385,5 +1422,5 @@
          end do
                      
-         if(ngridmx.eq.1)then
+         if(ngrid.eq.1)then
             DYN=0.0
          endif
@@ -1399,5 +1436,5 @@
 
          if(meanOLR)then
-            if((ngridmx.gt.1) .or. (mod(icount-1,nint(ecritphy)).eq.0))then
+            if((ngrid.gt.1) .or. (mod(icount-1,nint(ecritphy)).eq.0))then
                ! to record global radiative balance
                open(92,file="rad_bal.out",form='formatted',position='append')
@@ -1432,7 +1469,7 @@
 !     ---------------------------------------------------------
       if(tracer)then
-         qcol(1:ngridmx,1:nqmx)=0.0
+         qcol(1:ngrid,1:nq)=0.0
          do iq=1,nq
-           do ig=1,ngridmx
+           do ig=1,ngrid
               qcol(ig,iq) = SUM( zq(ig,1:nlayermx,iq) * mass(ig,1:nlayermx))
            enddo
@@ -1440,14 +1477,20 @@
 
          ! Generalised for arbitrary aerosols now. (LK)
-         reffcol(1:ngridmx,1:naerkind)=0.0
+         reffcol(1:ngrid,1:naerkind)=0.0
          if(co2cond.and.(iaero_co2.ne.0))then
-            call co2_reffrad(zq,reffrad)
-            do ig=1,ngridmx
+            call co2_reffrad(ngrid,nq,zq,reffrad)
+            do ig=1,ngrid
                reffcol(ig,iaero_co2) = SUM(zq(ig,1:nlayermx,igcm_co2_ice)*reffrad(ig,1:nlayermx,iaero_co2)*mass(ig,1:nlayermx))
             enddo
          endif
          if(water.and.(iaero_h2o.ne.0))then
-            call h2o_reffrad(zq,zt,reffrad,nueffrad)
-            do ig=1,ngridmx
+
+            !! AS: This modifies reffrad and nueffrad
+            !!     ... and those are saved in physiq
+            !!     To be conservative with previous versions,
+            !!     ... I put nueffrad_dummy so that nueffrad
+            !!     ... is not modified, but shouldn't it be modified actually?
+            call h2o_reffrad(ngrid,nq,zq,zt,reffrad,nueffrad_dummy)
+            do ig=1,ngrid
                reffcol(ig,iaero_h2o) = SUM(zq(ig,1:nlayermx,igcm_h2o_ice)*reffrad(ig,1:nlayermx,iaero_h2o)*mass(ig,1:nlayermx))
             enddo
@@ -1474,5 +1517,5 @@
 
          if(meanOLR)then
-            if((ngridmx.gt.1) .or. (mod(icount-1,nint(ecritphy)).eq.0))then
+            if((ngrid.gt.1) .or. (mod(icount-1,nint(ecritphy)).eq.0))then
                ! to record global water balance
                open(98,file="h2o_bal.out",form='formatted',position='append')
@@ -1490,5 +1533,5 @@
       if(water)then
          do l = 1, nlayer
-            do ig = 1, ngrid
+            do ig=1,ngrid
 !               call watersat(pt(ig,l),pplay(ig,l),qsat(ig,l))
                call Psat_water(zt(ig,l),pplay(ig,l),psat_tmp,qsat(ig,l))
@@ -1524,5 +1567,5 @@
             if(ice_update)then
 
-               do ig = 1, ngrid
+               do ig=1,ngrid
 
                   delta_ice = (qsurf(ig,igcm_h2o_ice)-ice_initial(ig))
@@ -1550,8 +1593,8 @@
 
             write(*,*)'PHYSIQ: for physdem ztime_fin =',ztime_fin
-            call physdem1("restartfi.nc",long,lati,nsoilmx,nq,            &
+            call physdem1(ngrid,"restartfi.nc",long,lati,nsoilmx,nq,            &
                     ptimestep,pday,ztime_fin,tsurf,tsoil,emis,q2,qsurf_hist, &
                     area,albedodat,inertiedat,zmea,zstd,zsig,zgam,zthe,      &
-                    cloudfrac,totcloudfrac,hice)
+                    cloudfrac,totcloudfrac,hice,noms)
          endif
 
@@ -1594,15 +1637,15 @@
              do iq=1,nq
                 call wstats(ngrid,noms(iq),noms(iq),'kg/kg',3,zq(1,1,iq))
-                call wstats(ngridmx,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  & 
+                call wstats(ngrid,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  & 
                           'kg m^-2',2,qsurf(1,iq) )
 
-                call wstats(ngridmx,trim(noms(iq))//'_col',trim(noms(iq))//'_col',    & 
+                call wstats(ngrid,trim(noms(iq))//'_col',trim(noms(iq))//'_col',    & 
                           'kg m^-2',2,qcol(1,iq) )
-!                call wstats(ngridmx,trim(noms(iq))//'_reff',                          & 
+!                call wstats(ngrid,trim(noms(iq))//'_reff',                          & 
 !                          trim(noms(iq))//'_reff',                                   & 
 !                          'm',3,reffrad(1,1,iq))
               end do
             if (water) then
-               vmr=zq(1:ngridmx,1:nlayermx,igcm_h2o_vap)*mugaz/mmol(igcm_h2o_vap)
+               vmr=zq(1:ngrid,1:nlayermx,igcm_h2o_vap)*mugaz/mmol(igcm_h2o_vap)
                call wstats(ngrid,"vmr_h2ovapor",                           &
                           "H2O vapour volume mixing ratio","mol/mol",       & 
@@ -1647,20 +1690,20 @@
 	if(enertest) then
 	  if (calldifv) then
-	     call writediagfi(ngridmx,"q2","turbulent kinetic energy","J.kg^-1",3,q2)
-!	     call writediagfi(ngridmx,"dEzdiff","turbulent diffusion heating (-sensible flux)","w.m^-2",3,dEzdiff)
-!	     call writediagfi(ngridmx,"dEdiff","integrated turbulent diffusion heating (-sensible flux)","w.m^-2",2,dEdiff)
-!	     call writediagfi(ngridmx,"dEdiffs","In TurbDiff (correc rad+latent heat) surf nrj change","w.m^-2",2,dEdiffs)
-	     call writediagfi(ngridmx,"sensibFlux","sensible heat flux","w.m^-2",2,sensibFlux)
+	     call writediagfi(ngrid,"q2","turbulent kinetic energy","J.kg^-1",3,q2)
+!	     call writediagfi(ngrid,"dEzdiff","turbulent diffusion heating (-sensible flux)","w.m^-2",3,dEzdiff)
+!	     call writediagfi(ngrid,"dEdiff","integrated turbulent diffusion heating (-sensible flux)","w.m^-2",2,dEdiff)
+!	     call writediagfi(ngrid,"dEdiffs","In TurbDiff (correc rad+latent heat) surf nrj change","w.m^-2",2,dEdiffs)
+	     call writediagfi(ngrid,"sensibFlux","sensible heat flux","w.m^-2",2,sensibFlux)
 	  endif
 	  if (corrk) then
-!	     call writediagfi(ngridmx,"dEzradsw","radiative heating","w.m^-2",3,dEzradsw)
-!	     call writediagfi(ngridmx,"dEzradlw","radiative heating","w.m^-2",3,dEzradlw)
+!	     call writediagfi(ngrid,"dEzradsw","radiative heating","w.m^-2",3,dEzradsw)
+!	     call writediagfi(ngrid,"dEzradlw","radiative heating","w.m^-2",3,dEzradlw)
 	  endif 
           if(watercond) then
 	     call writediagfi(ngrid,"lscaledE","heat from largescale","W m-2",2,lscaledE) 
 	     call writediagfi(ngrid,"madjdE","heat from moistadj","W m-2",2,madjdE)
-	     call writediagfi(ngridmx,"RH","relative humidity"," ",3,RH)
-!	     call writediagfi(ngridmx,"qsatatm","atm qsat"," ",3,qsat)
-!	     call writediagfi(ngridmx,"h2o_max_col","maximum H2O column amount","kg.m^-2",2,H2Omaxcol)
+	     call writediagfi(ngrid,"RH","relative humidity"," ",3,RH)
+!	     call writediagfi(ngrid,"qsatatm","atm qsat"," ",3,qsat)
+!	     call writediagfi(ngrid,"h2o_max_col","maximum H2O column amount","kg.m^-2",2,H2Omaxcol)
           endif 
         endif
@@ -1678,11 +1721,11 @@
 !     Output aerosols
         if (igcm_co2_ice.ne.0.and.iaero_co2.ne.0) &
-	  call writediagfi(ngridmx,'CO2ice_reff','CO2ice_reff','m',3,reffrad(1,1,iaero_co2))
+	  call writediagfi(ngrid,'CO2ice_reff','CO2ice_reff','m',3,reffrad(1,1,iaero_co2))
         if (igcm_h2o_ice.ne.0.and.iaero_h2o.ne.0) &
-	  call writediagfi(ngridmx,'H2Oice_reff','H2Oice_reff','m',3,reffrad(:,:,iaero_h2o))
+	  call writediagfi(ngrid,'H2Oice_reff','H2Oice_reff','m',3,reffrad(:,:,iaero_h2o))
         if (igcm_co2_ice.ne.0.and.iaero_co2.ne.0) &
-	  call writediagfi(ngridmx,'CO2ice_reffcol','CO2ice_reffcol','um kg m^-2',2,reffcol(1,iaero_co2))
+	  call writediagfi(ngrid,'CO2ice_reffcol','CO2ice_reffcol','um kg m^-2',2,reffcol(1,iaero_co2))
         if (igcm_h2o_ice.ne.0.and.iaero_h2o.ne.0) &
-	  call writediagfi(ngridmx,'H2Oice_reffcol','H2Oice_reffcol','um kg m^-2',2,reffcol(1,iaero_h2o))
+	  call writediagfi(ngrid,'H2Oice_reffcol','H2Oice_reffcol','um kg m^-2',2,reffcol(1,iaero_h2o))
 
 !     Output tracers
@@ -1690,9 +1733,9 @@
         do iq=1,nq
           call writediagfi(ngrid,noms(iq),noms(iq),'kg/kg',3,zq(1,1,iq))
-!          call writediagfi(ngridmx,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  & 
+!          call writediagfi(ngrid,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  & 
 !                          'kg m^-2',2,qsurf(1,iq) )
-          call writediagfi(ngridmx,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  & 
+          call writediagfi(ngrid,trim(noms(iq))//'_surf',trim(noms(iq))//'_surf',  & 
                           'kg m^-2',2,qsurf_hist(1,iq) )
-          call writediagfi(ngridmx,trim(noms(iq))//'_col',trim(noms(iq))//'_col',    & 
+          call writediagfi(ngrid,trim(noms(iq))//'_col',trim(noms(iq))//'_col',    & 
                           'kg m^-2',2,qcol(1,iq) )
 
@@ -1705,15 +1748,15 @@
 
           if(waterrain)then
-             call writediagfi(ngridmx,"rain","rainfall","kg m-2 s-1",2,zdqsrain)
-             call writediagfi(ngridmx,"snow","snowfall","kg m-2 s-1",2,zdqssnow)
+             call writediagfi(ngrid,"rain","rainfall","kg m-2 s-1",2,zdqsrain)
+             call writediagfi(ngrid,"snow","snowfall","kg m-2 s-1",2,zdqssnow)
           endif
 
           if(hydrology)then
-             call writediagfi(ngridmx,"hice","oceanic ice height","m",2,hice)
+             call writediagfi(ngrid,"hice","oceanic ice height","m",2,hice)
           endif
 
           if(ice_update)then
-             call writediagfi(ngridmx,"ice_min","min annual ice","m",2,ice_min)
-             call writediagfi(ngridmx,"ice_ini","initial annual ice","m",2,ice_initial)
+             call writediagfi(ngrid,"ice_min","min annual ice","m",2,ice_min)
+             call writediagfi(ngrid,"ice_ini","initial annual ice","m",2,ice_initial)
           endif
 
@@ -1725,5 +1768,5 @@
           end do
 
-          call writediagfi(ngridmx,"tau_col","Total aerosol optical depth","[]",2,tau_col)
+          call writediagfi(ngrid,"tau_col","Total aerosol optical depth","[]",2,tau_col)
 
         enddo
@@ -1739,10 +1782,89 @@
       icount=icount+1
 
-      ! deallocate gas variables
       if (lastcall) then
+
+        ! deallocate gas variables
         IF ( ALLOCATED( gnom ) ) DEALLOCATE( gnom )
         IF ( ALLOCATED( gfrac ) ) DEALLOCATE( gfrac )  ! both allocated in su_gases.F90
+
+        ! deallocate saved arrays
+        ! this is probably not that necessary
+        ! ... but probably a good idea to clean the place before we leave
+        IF ( ALLOCATED(tsurf)) DEALLOCATE(tsurf)
+        IF ( ALLOCATED(tsoil)) DEALLOCATE(tsoil)
+        IF ( ALLOCATED(albedo)) DEALLOCATE(albedo)
+        IF ( ALLOCATED(albedo0)) DEALLOCATE(albedo0)
+        IF ( ALLOCATED(rnat)) DEALLOCATE(rnat)
+        IF ( ALLOCATED(emis)) DEALLOCATE(emis)
+        IF ( ALLOCATED(dtrad)) DEALLOCATE(dtrad)
+        IF ( ALLOCATED(fluxrad_sky)) DEALLOCATE(fluxrad_sky)
+        IF ( ALLOCATED(fluxrad)) DEALLOCATE(fluxrad)
+        IF ( ALLOCATED(capcal)) DEALLOCATE(capcal)
+        IF ( ALLOCATED(fluxgrd)) DEALLOCATE(fluxgrd)
+        IF ( ALLOCATED(qsurf)) DEALLOCATE(qsurf)
+        IF ( ALLOCATED(q2)) DEALLOCATE(q2)
+        IF ( ALLOCATED(ztprevious)) DEALLOCATE(ztprevious)
+        IF ( ALLOCATED(cloudfrac)) DEALLOCATE(cloudfrac)
+        IF ( ALLOCATED(totcloudfrac)) DEALLOCATE(totcloudfrac)
+        IF ( ALLOCATED(qsurf_hist)) DEALLOCATE(qsurf_hist)
+        IF ( ALLOCATED(reffrad)) DEALLOCATE(reffrad)
+        IF ( ALLOCATED(nueffrad)) DEALLOCATE(nueffrad)
+        IF ( ALLOCATED(ice_initial)) DEALLOCATE(ice_initial)
+        IF ( ALLOCATED(ice_min)) DEALLOCATE(ice_min)
+
+        IF ( ALLOCATED(fluxsurf_lw)) DEALLOCATE(fluxsurf_lw)
+        IF ( ALLOCATED(fluxsurf_sw)) DEALLOCATE(fluxsurf_sw)
+        IF ( ALLOCATED(fluxtop_lw)) DEALLOCATE(fluxtop_lw)
+        IF ( ALLOCATED(fluxabs_sw)) DEALLOCATE(fluxabs_sw)
+        IF ( ALLOCATED(fluxtop_dn)) DEALLOCATE(fluxtop_dn)
+        IF ( ALLOCATED(fluxdyn)) DEALLOCATE(fluxdyn)
+        IF ( ALLOCATED(OLR_nu)) DEALLOCATE(OLR_nu)
+        IF ( ALLOCATED(OSR_nu)) DEALLOCATE(OSR_nu)
+        IF ( ALLOCATED(sensibFlux)) DEALLOCATE(sensibFlux)
+        IF ( ALLOCATED(zdtlw)) DEALLOCATE(zdtlw)
+        IF ( ALLOCATED(zdtsw)) DEALLOCATE(zdtsw)
+        IF ( ALLOCATED(tau_col)) DEALLOCATE(tau_col)
+
+        !! this is defined in comsaison_h
+        IF ( ALLOCATED(mu0)) DEALLOCATE(mu0)
+        IF ( ALLOCATED(fract)) DEALLOCATE(fract)
+
+        !! this is defined in comsoil_h
+        IF ( ALLOCATED(layer)) DEALLOCATE(layer)
+        IF ( ALLOCATED(mlayer)) DEALLOCATE(mlayer)
+        IF ( ALLOCATED(inertiedat)) DEALLOCATE(inertiedat)
+
+        !! this is defined in surfdat_h
+        IF ( ALLOCATED(albedodat)) DEALLOCATE(albedodat)
+        IF ( ALLOCATED(phisfi)) DEALLOCATE(phisfi)
+        IF ( ALLOCATED(zmea)) DEALLOCATE(zmea)
+        IF ( ALLOCATED(zstd)) DEALLOCATE(zstd)
+        IF ( ALLOCATED(zsig)) DEALLOCATE(zsig)
+        IF ( ALLOCATED(zgam)) DEALLOCATE(zgam)
+        IF ( ALLOCATED(zthe)) DEALLOCATE(zthe)
+        IF ( ALLOCATED(dryness)) DEALLOCATE(dryness)
+        IF ( ALLOCATED(watercaptag)) DEALLOCATE(watercaptag)
+ 
+        !! this is defined in tracer_h
+        IF ( ALLOCATED(noms)) DEALLOCATE(noms)
+        IF ( ALLOCATED(mmol)) DEALLOCATE(mmol)
+        IF ( ALLOCATED(radius)) DEALLOCATE(radius)
+        IF ( ALLOCATED(rho_q)) DEALLOCATE(rho_q)
+        IF ( ALLOCATED(qext)) DEALLOCATE(qext)
+        IF ( ALLOCATED(alpha_lift)) DEALLOCATE(alpha_lift)
+        IF ( ALLOCATED(alpha_devil)) DEALLOCATE(alpha_devil)
+        IF ( ALLOCATED(qextrhor)) DEALLOCATE(qextrhor)
+        IF ( ALLOCATED(igcm_dustbin)) DEALLOCATE(igcm_dustbin)
+
+        !! this is defined in comgeomfi_h
+        IF ( ALLOCATED(lati)) DEALLOCATE(lati)
+        IF ( ALLOCATED(long)) DEALLOCATE(long)
+        IF ( ALLOCATED(area)) DEALLOCATE(area)
+        IF ( ALLOCATED(sinlat)) DEALLOCATE(sinlat)
+        IF ( ALLOCATED(coslat)) DEALLOCATE(coslat)
+        IF ( ALLOCATED(sinlon)) DEALLOCATE(sinlon)
+        IF ( ALLOCATED(coslon)) DEALLOCATE(coslon)
+
       endif
-
 
       return
Index: trunk/LMDZ.GENERIC/libf/phystd/radii_mod.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/radii_mod.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/radii_mod.F90	(revision 787)
@@ -20,5 +20,5 @@
 
 !==================================================================
-   subroutine su_aer_radii(reffrad,nueffrad)
+   subroutine su_aer_radii(ngrid,reffrad,nueffrad)
 !==================================================================
 !     Purpose
@@ -35,13 +35,15 @@
       use radinc_h, only: naerkind
       use aerosol_mod
-      Implicit none
-
-#include "callkeys.h"
-#include "dimensions.h"
-#include "dimphys.h"
-#include "tracer.h"
-
-      real, intent(inout) :: reffrad(ngridmx,nlayermx,naerkind)      !aerosols radii (K)
-      real, intent(inout) :: nueffrad(ngridmx,nlayermx,naerkind)     !variance     
+      USE tracer_h
+      Implicit none
+
+#include "callkeys.h"
+#include "dimensions.h"
+#include "dimphys.h"
+
+      integer :: ngrid
+
+      real, intent(inout) :: reffrad(ngrid,nlayermx,naerkind)      !aerosols radii (K)
+      real, intent(inout) :: nueffrad(ngrid,nlayermx,naerkind)     !variance     
 
       logical, save :: firstcall=.true.
@@ -56,21 +58,21 @@
 
             if(iaer.eq.iaero_co2)then ! CO2 ice
-               reffrad(1:ngridmx,1:nlayermx,iaer) = 1.e-4
-               nueffrad(1:ngridmx,1:nlayermx,iaer) = 0.1 
+               reffrad(1:ngrid,1:nlayermx,iaer) = 1.e-4
+               nueffrad(1:ngrid,1:nlayermx,iaer) = 0.1 
             endif
 
             if(iaer.eq.iaero_h2o)then ! H2O ice
-               reffrad(1:ngridmx,1:nlayermx,iaer) = 1.e-5
-               nueffrad(1:ngridmx,1:nlayermx,iaer) = 0.1 
+               reffrad(1:ngrid,1:nlayermx,iaer) = 1.e-5
+               nueffrad(1:ngrid,1:nlayermx,iaer) = 0.1 
             endif
 
             if(iaer.eq.iaero_dust)then ! dust
-               reffrad(1:ngridmx,1:nlayermx,iaer) = 1.e-5
-               nueffrad(1:ngridmx,1:nlayermx,iaer) = 0.1 
+               reffrad(1:ngrid,1:nlayermx,iaer) = 1.e-5
+               nueffrad(1:ngrid,1:nlayermx,iaer) = 0.1 
             endif
  
             if(iaer.eq.iaero_h2so4)then ! H2O ice
-               reffrad(1:ngridmx,1:nlayermx,iaer) = 1.e-6
-               nueffrad(1:ngridmx,1:nlayermx,iaer) = 0.1 
+               reffrad(1:ngrid,1:nlayermx,iaer) = 1.e-6
+               nueffrad(1:ngrid,1:nlayermx,iaer) = 0.1 
             endif
 
@@ -117,5 +119,5 @@
 
 !==================================================================
-   subroutine h2o_reffrad(pq,pt,reffrad,nueffrad)
+   subroutine h2o_reffrad(ngrid,nq,pq,pt,reffrad,nueffrad)
 !==================================================================
 !     Purpose
@@ -131,16 +133,18 @@
       use watercommon_h, Only: T_h2O_ice_liq,T_h2O_ice_clouds,rhowater,rhowaterice
       use aerosol_mod, only : iaero_h2o
-      Implicit none
-
-#include "callkeys.h"
-#include "dimensions.h"
-#include "dimphys.h"
-#include "tracer.h"
+      USE tracer_h
+      Implicit none
+
+#include "callkeys.h"
+#include "dimensions.h"
+#include "dimphys.h"
 #include "comcstfi.h"
 
-      real, intent(in) :: pq(ngridmx,nlayermx,nqmx) !tracer mixing ratios (kg/kg)
-      real, intent(in) :: pt(ngridmx,nlayermx)      !temperature (K)
-      real, intent(inout) :: reffrad(ngridmx,nlayermx,naerkind)      !aerosols radii (K)
-      real, intent(inout) :: nueffrad(ngridmx,nlayermx,naerkind) ! dispersion      
+      integer :: ngrid,nq
+
+      real, intent(in) :: pq(ngrid,nlayermx,nq) !tracer mixing ratios (kg/kg)
+      real, intent(in) :: pt(ngrid,nlayermx)      !temperature (K)
+      real, intent(inout) :: reffrad(ngrid,nlayermx,naerkind)      !aerosols radii (K)
+      real, intent(inout) :: nueffrad(ngrid,nlayermx,naerkind) ! dispersion      
 
       integer :: ig,l
@@ -151,5 +155,5 @@
       if (radfixed) then
          do l=1,nlayermx
-            do ig=1,ngridmx
+            do ig=1,ngrid
                zfice = 1.0 - (pt(ig,l)-T_h2O_ice_clouds) / (T_h2O_ice_liq-T_h2O_ice_clouds)
                zfice = MIN(MAX(zfice,0.0),1.0)
@@ -160,5 +164,5 @@
       else
          do l=1,nlayermx
-            do ig=1,ngridmx
+            do ig=1,ngrid
                zfice = 1.0 - (pt(ig,l)-T_h2O_ice_clouds) / (T_h2O_ice_liq-T_h2O_ice_clouds)
                zfice = MIN(MAX(zfice,0.0),1.0)
@@ -177,5 +181,5 @@
 
 !==================================================================
-   subroutine h2o_cloudrad(pql,reffliq,reffice)
+   subroutine h2o_cloudrad(ngrid,pql,reffliq,reffice)
 !==================================================================
 !     Purpose
@@ -189,14 +193,16 @@
 !==================================================================
       use watercommon_h, Only: rhowater,rhowaterice
-      Implicit none
-
-#include "callkeys.h"
-#include "dimensions.h"
-#include "dimphys.h"
-#include "tracer.h"
+      USE tracer_h
+      Implicit none
+
+#include "callkeys.h"
+#include "dimensions.h"
+#include "dimphys.h"
 #include "comcstfi.h"
 
-      real, intent(in) :: pql(ngridmx,nlayermx) !condensed water mixing ratios (kg/kg)
-      real, intent(out) :: reffliq(ngridmx,nlayermx),reffice(ngridmx,nlayermx)     !liquid and ice water particle radii (K)
+      integer :: ngrid
+
+      real, intent(in) :: pql(ngrid,nlayermx) !condensed water mixing ratios (kg/kg)
+      real, intent(out) :: reffliq(ngrid,nlayermx),reffice(ngrid,nlayermx)     !liquid and ice water particle radii (K)
 
       real,external :: CBRT            
@@ -204,11 +210,11 @@
 
       if (radfixed) then
-	 reffliq(1:ngridmx,1:nlayermx)= rad_h2o
-	 reffice(1:ngridmx,1:nlayermx)= rad_h2o_ice
+	 reffliq(1:ngrid,1:nlayermx)= rad_h2o
+	 reffice(1:ngrid,1:nlayermx)= rad_h2o_ice
       else
-	 reffliq(1:ngridmx,1:nlayermx)  = CBRT( 3*pql(1:ngridmx,1:nlayermx)/(4*Nmix_h2o*pi*rhowater) )
-	 reffliq(1:ngridmx,1:nlayermx)  = min(max(reffliq(1:ngridmx,1:nlayermx),1.e-6),100.e-6)
-	 reffice(1:ngridmx,1:nlayermx)  = CBRT( 3*pql(1:ngridmx,1:nlayermx)/(4*Nmix_h2o_ice*pi*rhowaterice) )
-	 reffice(1:ngridmx,1:nlayermx)  = min(max(reffice(1:ngridmx,1:nlayermx),1.e-6),100.e-6)
+	 reffliq(1:ngrid,1:nlayermx)  = CBRT( 3*pql(1:ngrid,1:nlayermx)/(4*Nmix_h2o*pi*rhowater) )
+	 reffliq(1:ngrid,1:nlayermx)  = min(max(reffliq(1:ngrid,1:nlayermx),1.e-6),100.e-6)
+	 reffice(1:ngrid,1:nlayermx)  = CBRT( 3*pql(1:ngrid,1:nlayermx)/(4*Nmix_h2o_ice*pi*rhowaterice) )
+	 reffice(1:ngrid,1:nlayermx)  = min(max(reffice(1:ngrid,1:nlayermx),1.e-6),100.e-6)
       end if
 
@@ -219,5 +225,5 @@
 
 !==================================================================
-   subroutine co2_reffrad(pq,reffrad)
+   subroutine co2_reffrad(ngrid,nq,pq,reffrad)
 !==================================================================
 !     Purpose
@@ -232,14 +238,16 @@
       use radinc_h, only: naerkind
       use aerosol_mod, only : iaero_co2
-      Implicit none
-
-#include "callkeys.h"
-#include "dimensions.h"
-#include "dimphys.h"
-#include "tracer.h"
+      USE tracer_h
+      Implicit none
+
+#include "callkeys.h"
+#include "dimensions.h"
+#include "dimphys.h"
 #include "comcstfi.h"
 
-      real, intent(in) :: pq(ngridmx,nlayermx,nqmx) !tracer mixing ratios (kg/kg)
-      real, intent(inout) :: reffrad(ngridmx,nlayermx,naerkind)      !aerosols radii (K)
+      integer :: ngrid,nq
+
+      real, intent(in) :: pq(ngrid,nlayermx,nq) !tracer mixing ratios (kg/kg)
+      real, intent(inout) :: reffrad(ngrid,nlayermx,naerkind)      !aerosols radii (K)
 
       integer :: ig,l
@@ -250,8 +258,8 @@
 
       if (radfixed) then
-         reffrad(1:ngridmx,1:nlayermx,iaero_co2) = 5.e-5 ! CO2 ice
+         reffrad(1:ngrid,1:nlayermx,iaero_co2) = 5.e-5 ! CO2 ice
       else
          do l=1,nlayermx
-            do ig=1,ngridmx
+            do ig=1,ngrid
                zrad = CBRT( 3*pq(ig,l,igcm_co2_ice)/(4*Nmix_co2*pi*rho_co2) )
                reffrad(ig,l,iaero_co2) = min(max(zrad,1.e-6),100.e-6)
@@ -266,5 +274,5 @@
 
 !==================================================================
-   subroutine dust_reffrad(reffrad)
+   subroutine dust_reffrad(ngrid,reffrad)
 !==================================================================
 !     Purpose
@@ -285,7 +293,9 @@
 #include "dimphys.h"
 
-      real, intent(inout) :: reffrad(ngridmx,nlayermx,naerkind)      !aerosols radii (K)
+      integer :: ngrid
+
+      real, intent(inout) :: reffrad(ngrid,nlayermx,naerkind)      !aerosols radii (K)
             
-      reffrad(1:ngridmx,1:nlayermx,iaero_dust) = 2.e-6 ! dust
+      reffrad(1:ngrid,1:nlayermx,iaero_dust) = 2.e-6 ! dust
 
    end subroutine dust_reffrad
@@ -294,5 +304,5 @@
 
 !==================================================================
-   subroutine h2so4_reffrad(reffrad)
+   subroutine h2so4_reffrad(ngrid,reffrad)
 !==================================================================
 !     Purpose
@@ -313,7 +323,9 @@
 #include "dimphys.h"
 
-      real, intent(inout) :: reffrad(ngridmx,nlayermx,naerkind)      !aerosols radii (K)
+      integer :: ngrid
+
+      real, intent(inout) :: reffrad(ngrid,nlayermx,naerkind)      !aerosols radii (K)
                 
-      reffrad(1:ngridmx,1:nlayermx,iaero_h2so4) = 1.e-6 ! h2so4
+      reffrad(1:ngrid,1:nlayermx,iaero_h2so4) = 1.e-6 ! h2so4
 
    end subroutine h2so4_reffrad
Index: trunk/LMDZ.GENERIC/libf/phystd/rain.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/rain.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/rain.F90	(revision 787)
@@ -1,3 +1,3 @@
-subroutine rain(ptimestep,pplev,pplay,t,pdt,pq,pdq,d_t,dqrain,dqsrain,dqssnow,rneb)
+subroutine rain(ngrid,nq,ptimestep,pplev,pplay,t,pdt,pq,pdq,d_t,dqrain,dqsrain,dqssnow,rneb)
 
 
@@ -6,4 +6,5 @@
   use watercommon_h, only: T_h2O_ice_liq,T_h2O_ice_clouds, RLVTT, RCPD, RCPV, RV, RVTMP2,Psat_water,Tsat_water,rhowater
   use radii_mod, only: h2o_cloudrad
+  USE tracer_h
   implicit none
 
@@ -24,29 +25,30 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "tracer.h"
 #include "comcstfi.h"
 #include "callkeys.h"
 
+      integer ngrid,nq
+
 !     Pre-arguments (for universal model)
-      real pq(ngridmx,nlayermx,nqmx)       ! tracer (kg/kg)
-      real qsurf(ngridmx,nqmx)             ! tracer at the surface (kg.m-2)
-      REAL pdt(ngridmx,nlayermx),pdq(ngridmx,nlayermx,nqmx)
-
-      real dqrain(ngridmx,nlayermx,nqmx)   ! tendency of H2O precipitation (kg/kg.s-1)
-      real dqsrain(ngridmx)                ! rain flux at the surface (kg.m-2.s-1)
-      real dqssnow(ngridmx)                ! snow flux at the surface (kg.m-2.s-1)
-      REAL d_t(ngridmx,nlayermx)           ! temperature increment
+      real pq(ngrid,nlayermx,nq)       ! tracer (kg/kg)
+      real qsurf(ngrid,nq)             ! tracer at the surface (kg.m-2)
+      REAL pdt(ngrid,nlayermx),pdq(ngrid,nlayermx,nq)
+
+      real dqrain(ngrid,nlayermx,nq)   ! tendency of H2O precipitation (kg/kg.s-1)
+      real dqsrain(ngrid)                ! rain flux at the surface (kg.m-2.s-1)
+      real dqssnow(ngrid)                ! snow flux at the surface (kg.m-2.s-1)
+      REAL d_t(ngrid,nlayermx)           ! temperature increment
 
 !     Arguments
       REAL ptimestep                    ! time interval
-      REAL pplev(ngridmx,nlayermx+1)    ! inter-layer pressure
-      REAL pplay(ngridmx,nlayermx)      ! mid-layer pressure
-      REAL t(ngridmx,nlayermx)          ! input temperature (K)
-      REAL zt(ngridmx,nlayermx)         ! working temperature (K)
-      REAL ql(ngridmx,nlayermx)         ! liquid water (Kg/Kg)
-      REAL q(ngridmx,nlayermx)          ! specific humidity (Kg/Kg)
-      REAL rneb(ngridmx,nlayermx)       ! cloud fraction
-      REAL d_q(ngridmx,nlayermx)        ! water vapor increment
-      REAL d_ql(ngridmx,nlayermx)       ! liquid water / ice increment
+      REAL pplev(ngrid,nlayermx+1)    ! inter-layer pressure
+      REAL pplay(ngrid,nlayermx)      ! mid-layer pressure
+      REAL t(ngrid,nlayermx)          ! input temperature (K)
+      REAL zt(ngrid,nlayermx)         ! working temperature (K)
+      REAL ql(ngrid,nlayermx)         ! liquid water (Kg/Kg)
+      REAL q(ngrid,nlayermx)          ! specific humidity (Kg/Kg)
+      REAL rneb(ngrid,nlayermx)       ! cloud fraction
+      REAL d_q(ngrid,nlayermx)        ! water vapor increment
+      REAL d_ql(ngrid,nlayermx)       ! liquid water / ice increment
 
 !     Subroutine options
@@ -78,17 +80,17 @@
 !     Local variables
       INTEGER i, k, n
-      REAL zqs(ngridmx,nlayermx),Tsat(ngridmx,nlayermx), zdelta, zcor
-      REAL zrfl(ngridmx), zrfln(ngridmx), zqev, zqevt
-
-      REAL zoliq(ngridmx)
-      REAL zdz(ngridmx),zrho(ngridmx),ztot(ngridmx), zrhol(ngridmx)
-      REAL zchau(ngridmx),zfroi(ngridmx),zfrac(ngridmx),zneb(ngridmx)
-
-      real reffh2oliq(ngridmx,nlayermx),reffh2oice(ngridmx,nlayermx)
+      REAL zqs(ngrid,nlayermx),Tsat(ngrid,nlayermx), zdelta, zcor
+      REAL zrfl(ngrid), zrfln(ngrid), zqev, zqevt
+
+      REAL zoliq(ngrid)
+      REAL zdz(ngrid),zrho(ngrid),ztot(ngrid), zrhol(ngrid)
+      REAL zchau(ngrid),zfroi(ngrid),zfrac(ngrid),zneb(ngrid)
+
+      real reffh2oliq(ngrid,nlayermx),reffh2oice(ngrid,nlayermx)
   
       real ttemp, ptemp, psat_tmp
-      real tnext(ngridmx,nlayermx)
-
-      real l2c(ngridmx,nlayermx)
+      real tnext(ngrid,nlayermx)
+
+      real l2c(ngrid,nlayermx)
       real dWtot
 
@@ -154,5 +156,5 @@
 !     GCM -----> subroutine variables
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
 
 	 zt(i,k)   = t(i,k)+pdt(i,k)*ptimestep ! a big fat bug was here
@@ -175,5 +177,5 @@
 !     Initialise the outputs
       DO k = 1, nlayermx
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          d_t(i,k) = 0.0
          d_q(i,k) = 0.0
@@ -181,5 +183,5 @@
       ENDDO
       ENDDO
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          zrfl(i)  = 0.0
          zrfln(i) = 0.0
@@ -188,5 +190,5 @@
       ! calculate saturation mixing ratio
       DO k = 1, nlayermx
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             ttemp = zt(i,k) 
             ptemp = pplay(i,k)
@@ -199,5 +201,5 @@
       ! get column / layer conversion factor
       DO k = 1, nlayermx
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             l2c(i,k)=(pplev(i,k)-pplev(i,k+1))/g
          ENDDO
@@ -211,5 +213,5 @@
 
          IF (evap_prec) THEN ! note no rneb dependence!
-            DO i = 1, ngridmx
+            DO i = 1, ngrid
                IF (zrfl(i) .GT.0.) THEN
 
@@ -241,5 +243,5 @@
          ENDIF
 
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             zoliq(i) = 0.0
          ENDDO
@@ -248,5 +250,5 @@
          if(precip_scheme.eq.1)then
 
-            DO i = 1, ngridmx
+            DO i = 1, ngrid
                ttemp = zt(i,k)
                IF (ttemp .ge. T_h2O_ice_liq) THEN
@@ -271,5 +273,5 @@
          elseif (precip_scheme.ge.2) then
           
-           DO i = 1, ngridmx
+           DO i = 1, ngrid
                IF (rneb(i,k).GT.0.0) THEN
                   zoliq(i) = ql(i,k)
@@ -284,5 +286,5 @@
 
  !recalculate liquid water particle radii
-	   call h2o_cloudrad(ql,reffh2oliq,reffh2oice)
+	   call h2o_cloudrad(ngrid,ql,reffh2oliq,reffh2oice)
 
            SELECT CASE(precip_scheme)
@@ -291,5 +293,5 @@
 
             DO n = 1, ninter
-               DO i = 1, ngridmx
+               DO i = 1, ngrid
                   IF (rneb(i,k).GT.0.0) THEN
                      ! this is the ONLY place where zneb, precip_timescale and cloud_sat are used
@@ -314,5 +316,5 @@
 	    
             DO n = 1, ninter
-               DO i = 1, ngridmx
+               DO i = 1, ngrid
                   IF (rneb(i,k).GT.0.0) THEN
                      ! this is the ONLY place where zneb, precip_timescale and cloud_sat are used
@@ -336,5 +338,5 @@
 
             DO n = 1, ninter
-               DO i = 1, ngridmx
+               DO i = 1, ngrid
                   IF (rneb(i,k).GT.0.0) THEN
                      ! this is the ONLY place where zneb and c1 are used
@@ -358,5 +360,5 @@
 
             ! Change in cloud density and surface H2O values
-            DO i = 1, ngridmx
+            DO i = 1, ngrid
                IF (rneb(i,k).GT.0.0) THEN
                   d_ql(i,k) = (zoliq(i) - ql(i,k))!/ptimestep
@@ -371,5 +373,5 @@
 
 !     Rain or snow on the ground
-      DO i = 1, ngridmx
+      DO i = 1, ngrid
          if(zrfl(i).lt.0.0)then
             print*,'Droplets of negative rain are falling...'
@@ -387,5 +389,5 @@
 !     now subroutine -----> GCM variables
       DO k = 1, nlayermx
-         DO i = 1, ngridmx
+         DO i = 1, ngrid
             
             if(evap_prec)then
Index: trunk/LMDZ.GENERIC/libf/phystd/rcm1d.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/rcm1d.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/rcm1d.F	(revision 787)
@@ -3,4 +3,9 @@
 ! to use  'getin'
       use ioipsl_getincom 
+      use surfdat_h
+      use comdiurn_h
+      use comsaison_h
+      use comsoil_h
+      USE comgeomfi_h
 
       implicit none
@@ -33,19 +38,11 @@
 #include "paramet.h"
 #include "dimphys.h"
-#include "comgeomfi.h"
-#include "surfdat.h"
-#include "comsoil.h"
-#include "comdiurn.h"
 #include "callkeys.h"
 #include "comcstfi.h"
 #include "planete.h"
-#include "comsaison.h"
 #include "control.h"
 #include "comvert.h"
 #include "netcdf.inc"
-#include "watercap.h" 
-#include "fisice.h"
 #include "logic.h"
-#include "advtrac.h"
 #include "comgeom.h"
 
@@ -95,5 +92,5 @@
       REAL tmp1(0:nlayermx),tmp2(0:nlayermx)
       Logical  tracerdyn
-      integer :: nq=1 ! number of tracers
+      integer :: nq !=1 ! number of tracers
  
       character*2 str2
@@ -110,11 +107,40 @@
 
 !     added by BC
-      REAL cloudfrac(ngridmx,nlayermx)
-      REAL hice(ngridmx),totcloudfrac(ngridmx)
+      REAL cloudfrac(1,nlayermx)
+      REAL hice(1),totcloudfrac(1)
       REAL qzero1D   !initial water amount on the ground
+
+!     added by AS to avoid the use of adv trac common
+      character*20 nametrac(nqmx)   ! name of the tracer (no need for adv trac common)
+
 
 c=======================================================================
 c INITIALISATION
 c=======================================================================
+
+      !! those are defined in surfdat_h.F90
+      IF (.not. ALLOCATED(albedodat)) ALLOCATE(albedodat(1))
+      IF (.not. ALLOCATED(phisfi)) ALLOCATE(phisfi(1))
+      IF (.not. ALLOCATED(zmea)) ALLOCATE(zmea(1))
+      IF (.not. ALLOCATED(zstd)) ALLOCATE(zstd(1))
+      IF (.not. ALLOCATED(zsig)) ALLOCATE(zsig(1))
+      IF (.not. ALLOCATED(zgam)) ALLOCATE(zgam(1))
+      IF (.not. ALLOCATED(zthe)) ALLOCATE(zthe(1))
+      IF (.not. ALLOCATED(dryness)) ALLOCATE(dryness(1))
+      IF (.not. ALLOCATED(watercaptag)) ALLOCATE(watercaptag(1))
+      !! those are defined in comdiurn_h.F90
+      IF (.not.ALLOCATED(sinlat)) ALLOCATE(sinlat(1))
+      IF (.not.ALLOCATED(coslat)) ALLOCATE(coslat(1))
+      IF (.not.ALLOCATED(sinlon)) ALLOCATE(sinlon(1))
+      IF (.not.ALLOCATED(coslon)) ALLOCATE(coslon(1))
+      !! those are defined in comsoil_h.F90
+      IF (.not.ALLOCATED(layer)) ALLOCATE(layer(nsoilmx))
+      IF (.not.ALLOCATED(mlayer)) ALLOCATE(mlayer(0:nsoilmx-1))
+      IF (.not.ALLOCATED(inertiedat)) ALLOCATE(inertiedat(1,nsoilmx))
+      !! those are defined in comgeomfi_h
+      IF (.not. ALLOCATED(lati)) ALLOCATE(lati(1))
+      IF (.not. ALLOCATED(long)) ALLOCATE(long(1))
+      IF (.not. ALLOCATED(area)) ALLOCATE(area(1))
+
 
       saveprofile=.false.
@@ -214,12 +240,7 @@
           endif
         
-          ! initialize advection schemes to Van-Leer for all tracers
-          do iq=1,nq
-            iadv(iq)=3 ! Van-Leer
-          enddo
-        
           do iq=1,nq
           ! minimal version, just read in the tracer names, 1 per line
-            read(90,*,iostat=ierr) tnom(iq)
+            read(90,*,iostat=ierr) nametrac(iq)
             if (ierr.ne.0) then
               write(*,*) 'rcm1d: error reading tracer names...'
@@ -232,9 +253,9 @@
          i_h2o_vap=0
          do iq=1,nq
-           if (tnom(iq)=="co2_ice") then
+           if (nametrac(iq)=="co2_ice") then
              i_co2_ice=iq
-           elseif (tnom(iq)=="h2o_ice") then
+           elseif (nametrac(iq)=="h2o_ice") then
              i_h2o_ice=iq
-           elseif (tnom(iq)=="h2o_vap") then
+           elseif (nametrac(iq)=="h2o_vap") then
              i_h2o_vap=iq
            endif
@@ -258,9 +279,9 @@
         do iq=1,nq
           write(str7,'(a1,i2.2)')'q',iq
-          tnom(iq)=str7
+          nametrac(iq)=str7
         enddo
         ! actually, we'll need at least one "co2_ice" tracer
         ! (for surface CO2 ice)
-        tnom(1)="co2_ice"
+        nametrac(1)="co2_ice"
         i_co2_ice=1
       endif ! of if (tracer)
@@ -482,5 +503,5 @@
 c    ---------------------------
 
-      DO iq=1,nqmx
+      DO iq=1,nq
         DO ilayer=1,nlayer
            q(ilayer,iq) = 0.
@@ -488,5 +509,5 @@
       ENDDO
      
-      DO iq=1,nqmx
+      DO iq=1,nq
         qsurf(iq) = 0.
       ENDDO
@@ -683,9 +704,9 @@
 c   les variables purement physiques a "physiq"...
 
-      call physdem1("startfi.nc",long,lati,nsoilmx,nqmx,
+      call physdem1(1,"startfi.nc",long,lati,nsoilmx,nq,
      &              dtphys,float(day0),
      &              time,tsurf,tsoil,emis,q2,qsurf,
      &              area,albedodat,inertiedat,zmea,zstd,zsig,zgam,zthe,
-     &              cloudfrac,totcloudfrac,hice)
+     &              cloudfrac,totcloudfrac,hice,nametrac)
 
 c=======================================================================
@@ -740,5 +761,6 @@
 
 
-      CALL physiq (1,llm,nqmx,
+      CALL physiq (1,llm,nq,
+     .     nametrac,
      ,     firstcall,lastcall,
      ,     day,time,dtphys,
@@ -802,5 +824,5 @@
 c       --------------------------------------
 
-        DO iq = 1, nqmx
+        DO iq = 1, nq
           DO ilayer=1,nlayer
              q(ilayer,iq)=q(ilayer,iq)+dtphys*dq(ilayer,iq)
Index: trunk/LMDZ.GENERIC/libf/phystd/soil.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/soil.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/soil.F	(revision 787)
@@ -1,6 +1,9 @@
-      subroutine soil(ngrid,nsoil,firstcall,
+      subroutine soil(ngrid,nsoil,firstcall,lastcall,
      &          therm_i,
      &          timestep,tsurf,tsoil,
      &          capcal,fluxgrd)
+
+      use comsoil_h
+
       implicit none
 
@@ -17,5 +20,4 @@
 #include "dimphys.h"
 
-#include"comsoil.h"
 
 c-----------------------------------------------------------------------
@@ -26,4 +28,5 @@
       integer nsoil	! number of soil layers 
       logical firstcall ! identifier for initialization call 
+      logical lastcall
       real therm_i(ngrid,nsoil) ! thermal inertia
       real timestep	    ! time step
@@ -35,22 +38,12 @@
 
 ! local saved variables:
-      !real,save :: mthermdiff(ngridmx,0:nsoilmx-1) ! mid-layer thermal diffusivity
-      !real,save :: thermdiff(ngridmx,nsoilmx-1) ! inter-layer thermal diffusivity
-      !real,save :: coefq(0:nsoilmx-1)		! q_{k+1/2} coefficients
-      !real,save :: coefd(ngridmx,nsoilmx-1)	! d_k coefficients
-      !real,save :: alph(ngridmx,nsoilmx-1)	! alpha_k coefficients
-      !real,save :: beta(ngridmx,nsoilmx-1)	! beta_k coefficients
-      !real,save :: mu
-
-      real mthermdiff(ngridmx,0:nsoilmx-1) ! mid-layer thermal diffusivity
-      real thermdiff(ngridmx,nsoilmx-1)    ! inter-layer thermal diffusivity
-      real coefq(0:nsoilmx-1)		   ! q_{k+1/2} coefficients
-      real coefd(ngridmx,nsoilmx-1)	   ! d_k coefficients
-      real alph(ngridmx,nsoilmx-1)	   ! alpha_k coefficients
-      real beta(ngridmx,nsoilmx-1)	   ! beta_k coefficients
-      real mu
+      real,dimension(:,:),save,allocatable :: mthermdiff ! mid-layer thermal diffusivity
+      real,dimension(:,:),save,allocatable :: thermdiff ! inter-layer thermal diffusivity
+      real,dimension(:),save,allocatable :: coefq ! q_{k+1/2} coefficients
+      real,dimension(:,:),save,allocatable :: coefd ! d_k coefficients
+      real,dimension(:,:),save,allocatable :: alph ! alpha_k coefficients
+      real,dimension(:,:),save,allocatable :: beta ! beta_k coefficients
+      real,save :: mu
             
-      save mthermdiff,thermdiff,coefq,coefd,alph,beta,mu
-
 ! local variables:
       integer ig,ik
@@ -64,4 +57,12 @@
       ! note: firstcall is set to .true. or .false. by the caller
       !       and not changed by soil.F 
+
+      ALLOCATE(mthermdiff(ngrid,0:nsoilmx-1)) ! mid-layer thermal diffusivity
+      ALLOCATE(thermdiff(ngrid,nsoilmx-1))    ! inter-layer thermal diffusivity
+      ALLOCATE(coefq(0:nsoilmx-1))              ! q_{k+1/2} coefficients
+      ALLOCATE(coefd(ngrid,nsoilmx-1))        ! d_k coefficients
+      ALLOCATE(alph(ngrid,nsoilmx-1))         ! alpha_k coefficients
+      ALLOCATE(beta(ngrid,nsoilmx-1))         ! beta_k coefficients
+
 ! 0.1 Build mthermdiff(:), the mid-layer thermal diffusivities
       do ig=1,ngrid
@@ -186,4 +187,12 @@
       enddo
 
+      if (lastcall) then
+        IF ( ALLOCATED(mthermdiff)) DEALLOCATE(mthermdiff)
+        IF ( ALLOCATED(thermdiff)) DEALLOCATE(thermdiff)
+        IF ( ALLOCATED(coefq)) DEALLOCATE(coefq)
+        IF ( ALLOCATED(coefd)) DEALLOCATE(coefd)
+        IF ( ALLOCATED(alph)) DEALLOCATE(alph)
+        IF ( ALLOCATED(beta)) DEALLOCATE(beta)
+      endif
 
       end
Index: trunk/LMDZ.GENERIC/libf/phystd/soil_settings.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/soil_settings.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/soil_settings.F	(revision 787)
@@ -1,3 +1,6 @@
       subroutine soil_settings(nid,ngrid,nsoil,tsurf,tsoil)
+
+      use comsoil_h
+
       implicit none
 
@@ -26,5 +29,4 @@
 #include "dimphys.h"
 
-#include "comsoil.h"
 #include "netcdf.inc"
 !======================================================================
@@ -35,7 +37,8 @@
       integer ngrid	! # of horizontal grid points
       integer nsoil	! # of soil layers
+      integer sta       ! # at which reading starts
       real tsurf(ngrid) ! surface temperature
 !  output:
-      real tsoil(ngridmx,nsoilmx)	! soil temperature
+      real tsoil(ngrid,nsoilmx)	! soil temperature
 
 !======================================================================
@@ -67,5 +70,19 @@
       real,parameter :: default_volcapa=1.e6
 
+      integer, dimension(2) :: sta2d
+      integer, dimension(2) :: siz2d
+
 !======================================================================
+
+      !! this is defined in comsoil_h
+      IF (.not.ALLOCATED(layer)) 
+     . ALLOCATE(layer(nsoilmx))
+      IF (.not.ALLOCATED(mlayer)) 
+     . ALLOCATE(mlayer(0:nsoilmx-1))
+      IF (.not.ALLOCATED(inertiedat)) 
+     . ALLOCATE(inertiedat(ngrid,nsoilmx))
+
+      !! this is defined in dimphys.h
+      sta = cursor
 
 ! 1. Depth coordinate
@@ -94,4 +111,8 @@
 	  interpol=.true.
 	endif
+
+      sta2d = (/sta,1/)
+      siz2d = (/ngrid,dimlen/)
+
 
 ! 1.2 Find out the # of dimensions <inertiedat> was defined as using
@@ -231,7 +252,7 @@
        allocate(surfinertia(ngrid))
 #ifdef NC_DOUBLE
-       ierr = NF_GET_VAR_DOUBLE(nid, nvarid, surfinertia)
-#else
-       ierr = NF_GET_VAR_REAL(nid, nvarid, surfinertia)
+       ierr = NF_GET_VARA_DOUBLE(nid, nvarid, sta, ngrid, surfinertia)
+#else
+       ierr = NF_GET_VARA_REAL(nid, nvarid, sta, ngrid, surfinertia)
 #endif
         if (ierr.NE.NF_NOERR) then
@@ -258,7 +279,7 @@
          endif
 #ifdef NC_DOUBLE
-        ierr = NF_GET_VAR_DOUBLE(nid,nvarid,oldinertiedat)
-#else
-        ierr = NF_GET_VAR_REAL(nid,nvarid,oldinertiedat)
+        ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta2d,siz2d,oldinertiedat)
+#else
+        ierr = NF_GET_VARA_REAL(nid,nvarid,sta2d,siz2d,oldinertiedat)
 #endif
         if (ierr.NE.NF_NOERR) then
@@ -268,7 +289,7 @@
        else ! put values in therm_i
 #ifdef NC_DOUBLE
-        ierr = NF_GET_VAR_DOUBLE(nid,nvarid,inertiedat)
-#else
-        ierr = NF_GET_VAR_REAL(nid,nvarid,inertiedat)
+        ierr = NF_GET_VARA_DOUBLE(nid,nvarid,sta2d,siz2d,inertiedat)
+#else
+        ierr = NF_GET_VARA_REAL(nid,nvarid,sta2d,siz2d,inertiedat)
 #endif
         if (ierr.NE.NF_NOERR) then
@@ -300,7 +321,7 @@
          endif
 #ifdef NC_DOUBLE
-        ierr=NF_GET_VAR_DOUBLE(nid,nvarid,oldtsoil)
-#else
-        ierr=NF_GET_VAR_REAL(nid,nvarid,oldtsoil)
+        ierr=NF_GET_VARA_DOUBLE(nid,nvarid,sta2d,siz2d,oldtsoil)
+#else
+        ierr=NF_GET_VARA_REAL(nid,nvarid,sta2d,siz2d,oldtsoil)
 #endif
         if (ierr.ne.NF_NOERR) then
@@ -310,7 +331,7 @@
        else ! put values in tsoil
 #ifdef NC_DOUBLE
-        ierr=NF_GET_VAR_DOUBLE(nid,nvarid,tsoil)
-#else
-        ierr=NF_GET_VAR_REAL(nid,nvarid,tsoil)
+        ierr=NF_GET_VARA_DOUBLE(nid,nvarid,sta2d,siz2d,tsoil)
+#else
+        ierr=NF_GET_VARA_REAL(nid,nvarid,sta2d,siz2d,tsoil)
 #endif
         if (ierr.ne.NF_NOERR) then
Index: trunk/LMDZ.GENERIC/libf/phystd/surface_nature.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/surface_nature.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/surface_nature.F	(revision 787)
@@ -1,4 +1,10 @@
-      SUBROUTINE surface_nature(obliquit,qsurf,qsurfliquid
+      SUBROUTINE surface_nature(ngrid,nq,obliquit,qsurf,qsurfliquid
      &   ,qsurfsnow,rnat,oceanarea)
+
+      USE surfdat_h
+      USE comsoil_h
+      USE comgeomfi_h
+      USE tracer_h
+
       IMPLICIT none
 
@@ -31,19 +37,16 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "tracer.h"
-#include "fisice.h"
-#include "comgeomfi.h"
-#include "surfdat.h"
-#include "comsoil.h"
 
-	REAL qsurf(ngridmx,nqmx),ps(ngridmx)
-	REAL qsurfliquid(ngridmx)
-	REAL qsurfsnow(ngridmx)
+        integer ngrid,nq
+
+	REAL qsurf(ngrid,nq),ps(ngrid)
+	REAL qsurfliquid(ngrid)
+	REAL qsurfsnow(ngrid)
 	INTEGER iq, ig
-	INTEGER rnat(ngridmx)
+	INTEGER rnat(ngrid)
  	REAL oceanarea
 	REAL obliquit
 
-	do ig=1,ngridmx
+	do ig=1,ngrid
            rnat(ig)=1
            dryness(ig)=1        !(coefficient for evaporation)
@@ -56,5 +59,5 @@
         
         oceanarea=0.
-	do ig=1,ngridmx
+	do ig=1,ngrid
            if (rnat(ig).eq.0)then
               oceanarea=oceanarea+area(ig)
Index: trunk/LMDZ.GENERIC/libf/phystd/surfdat.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/surfdat.h	(revision 786)
+++ 	(revision )
@@ -1,15 +1,0 @@
-      COMMON/surfdat/albedodat(ngridmx),                                &
-     &   phisfi(ngridmx),albedice(2),emisice(2),emissiv,                &
-     &   iceradius(2) , dtemisice(2),                                   &
-     &   zmea(ngridmx),zstd(ngridmx),                                   &
-     &   zsig(ngridmx),zgam(ngridmx),zthe(ngridmx)
-
-      real albedodat ! albedo of bare ground
-! Ehouarn: moved inertiedat to comsoil.h
-!      real inertiedat, ! thermal inertia
-      real phisfi ! geopotential at ground level
-      real albedice
-      real emisice ! ice emissivity; 1:Northern hemisphere 2:Southern hemisphere
-      real emissiv
-      real iceradius , dtemisice
-      real zmea,zstd,zsig,zgam,zthe
Index: trunk/LMDZ.GENERIC/libf/phystd/surfdat_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/surfdat_h.F90	(revision 787)
+++ trunk/LMDZ.GENERIC/libf/phystd/surfdat_h.F90	(revision 787)
@@ -0,0 +1,22 @@
+
+       module surfdat_h
+
+       implicit none
+
+       real,allocatable,dimension(:) :: albedodat ! albedo of bare ground
+       ! Ehouarn: moved inertiedat to comsoil.h
+       !      real inertiedat, ! thermal inertia
+       real,allocatable,dimension(:) :: phisfi ! geopotential at ground level
+       real,dimension(2) :: albedice
+       real,dimension(2) :: emisice ! ice emissivity; 1:Northern hemisphere 2:Southern hemisphere
+       real emissiv
+       real,dimension(2) :: iceradius, dtemisice
+       real,allocatable,dimension(:) :: zmea,zstd,zsig,zgam,zthe
+
+       real,allocatable,dimension(:) :: dryness  !"Dryness coefficient" for grnd water ice sublimation
+                                                 ! AS: previously in tracer.h. it is more logical here.
+
+       logical,allocatable,dimension(:) :: watercaptag !! was in watercap.h
+
+       end module surfdat_h
+
Index: trunk/LMDZ.GENERIC/libf/phystd/surfini.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/surfini.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/surfini.F	(revision 787)
@@ -1,3 +1,7 @@
-      SUBROUTINE surfini(ngrid,qsurf,psolaralb)
+      SUBROUTINE surfini(ngrid,nq,qsurf,psolaralb)
+
+      USE surfdat_h
+      USE tracer_h
+
       IMPLICIT NONE
 c=======================================================================
@@ -11,11 +15,10 @@
 #include "dimensions.h"
 #include "dimphys.h"
-#include "surfdat.h"
 #include "callkeys.h"
-#include "tracer.h"
 c
       INTEGER ngrid,ig,icap
+      INTEGER nq
       REAL  piceco2(ngrid),psolaralb(ngrid)
-      REAL qsurf(ngrid,nqmx) !tracer on surface (kg/m2)
+      REAL qsurf(ngrid,nq) !tracer on surface (kg/m2)
 
       EXTERNAL ISMIN,ISMAX
@@ -42,5 +45,5 @@
 !      DO ig=1,ngrid
 c	 IF (water) THEN 
-c	   if (qsurf(ig,nqmx).gt.0.005) then
+c	   if (qsurf(ig,nq).gt.0.005) then
 c             psolaralb(ig,1) = 0.4
 c             psolaralb(ig,2) = 0.4 
Index: trunk/LMDZ.GENERIC/libf/phystd/tabfi.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/tabfi.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/tabfi.F	(revision 787)
@@ -1,4 +1,4 @@
 c=======================================================================
-      SUBROUTINE tabfi(nid,Lmodif,tab0,day_ini,lmax,p_rad,
+      SUBROUTINE tabfi(ngrid,nid,Lmodif,tab0,day_ini,lmax,p_rad,
      .                 p_omeg,p_g,p_cpp,p_mugaz,p_daysec,time)
 c=======================================================================
@@ -46,4 +46,8 @@
       use ioipsl_getincom 
 
+      USE surfdat_h
+      use comsoil_h
+      USE comgeomfi_h
+
       implicit none
  
@@ -51,8 +55,5 @@
 #include "dimphys.h"
 #include "comcstfi.h"
-#include "comgeomfi.h"
 #include "planete.h"
-#include "surfdat.h"
-#include "comsoil.h"
 #include "netcdf.inc"
 #include "callkeys.h"
@@ -61,4 +62,6 @@
 c   Declarations
 c-----------------------------------------------------------------------
+
+      INTEGER ngrid
 
 c Arguments
@@ -104,7 +107,7 @@
 c  Initialization of some physical constants
 c informations on physics grid
-      if(ngridmx.ne.tab_cntrl(tab0+1)) then
-         print*,'tabfi: WARNING !!! tab_cntrl(tab0+1).ne.ngridmx'
-         print*,tab_cntrl(tab0+1),ngridmx
+      if(ngrid.ne.tab_cntrl(tab0+1)) then
+         print*,'tabfi: WARNING !!! tab_cntrl(tab0+1).ne.ngrid'
+         print*,tab_cntrl(tab0+1),ngrid
       endif
       lmax = nint(tab_cntrl(tab0+2))
@@ -168,5 +171,5 @@
       write(*,*) 'Reading tab_cntrl when calling tabfi before changes'
       write(*,*) '*****************************************************'
-      write(*,5) '(1)      = ngridmx?',tab_cntrl(tab0+1),float(ngridmx)
+      write(*,5) '(1)        = ngrid?',tab_cntrl(tab0+1),float(ngrid)
       write(*,5) '(2)            lmax',tab_cntrl(tab0+2),float(lmax)
       write(*,5) '(3)         day_ini',tab_cntrl(tab0+3),float(day_ini)
@@ -490,5 +493,5 @@
       write(*,*) 'Reading tab_cntrl when calling tabfi AFTER changes'
       write(*,*) '*****************************************************'
-      write(*,5) '(1)      = ngridmx?',tab_cntrl(tab0+1),float(ngridmx)
+      write(*,5) '(1)        = ngrid?',tab_cntrl(tab0+1),float(ngrid)
       write(*,5) '(2)            lmax',tab_cntrl(tab0+2),float(lmax)
       write(*,5) '(3)         day_ini',tab_cntrl(tab0+3),float(day_ini)
Index: trunk/LMDZ.GENERIC/libf/phystd/totalcloudfrac.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/totalcloudfrac.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/totalcloudfrac.F90	(revision 787)
@@ -1,5 +1,8 @@
-      subroutine totalcloudfrac(rneb,totalrneb,pplev,pq,tau)
+      subroutine totalcloudfrac(ngrid,nq,rneb,totalrneb,pplev,pq,tau)
 
       use watercommon_h
+      use comdiurn_h
+      USE comgeomfi_h
+      USE tracer_h
       implicit none
 
@@ -19,17 +22,14 @@
 #include "dimphys.h"
 #include "comcstfi.h"
-#include "tracer.h"
-#include "fisice.h"
-#include "comgeomfi.h"
-#include "comdiurn.h"
 #include "callkeys.h"
 
+      integer ngrid, nq
 
-      real rneb(ngridmx,nlayermx)             ! cloud fraction     
-      real pplev(ngridmx,nlayermx+1)
-      real pq(ngridmx,nlayermx,nqmx)
-      real tau(ngridmx,nlayermx)
+      real rneb(ngrid,nlayermx)             ! cloud fraction     
+      real pplev(ngrid,nlayermx+1)
+      real pq(ngrid,nlayermx,nq)
+      real tau(ngrid,nlayermx)
 
-      real totalrneb(ngridmx)                 ! total cloud fraction 
+      real totalrneb(ngrid)                 ! total cloud fraction 
       real, dimension(nlayermx+1) :: masse
       integer, parameter          :: recovery=7
@@ -50,5 +50,5 @@
 
 
-      do ig=1,ngridmx
+      do ig=1,ngrid
          totalrneb(ig) = 0.
 
Index: trunk/LMDZ.GENERIC/libf/phystd/tracer.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/tracer.h	(revision 786)
+++ 	(revision )
@@ -1,58 +1,0 @@
-!-----------------------------------------------------------------------
-! INCLUDE 'tracer.h'
-
-      character*20  noms(nqmx)  ! name of the tracer
-      real mmol(nqmx)           ! mole mass of tracer (g/mol-1) 
-      real radius(nqmx)   ! dust and ice particle radius (m)
-      real rho_q(nqmx)    ! tracer densities (kg.m-3)
-      real qext(nqmx)     ! Single Scat. Extinction coeff at 0.67 um
-      real alpha_lift(nqmx) ! saltation vertical flux/horiz flux ratio (m-1)
-      real alpha_devil(nqmx) ! lifting coeeficient by dust devil
-
-      real varian      ! Characteristic variance of log-normal distribution
-      real r3n_q     ! used to compute r0 from number and mass mixing ratio
-      real qextrhor(nqmx) ! Intermediate for computing opt. depth from q
-      real rho_dust     ! Mars dust density (kg.m-3)
-      real rho_ice     ! Water ice density (kg.m-3)
-      real rho_co2     ! CO2 ice density (kg.m-3)
-      real ref_r0        ! for computing reff=ref_r0*r0 (in log.n. distribution)
-
-      real dryness(ngridmx)!"Dryness coefficient" for grnd water ice sublimation
-      
-! tracer indexes: these are initialized in initracer and should be 0 if the
-!                 corresponding tracer does not exist
-      ! dust
-      integer :: igcm_dustbin(nqmx) ! for dustbin 'dust' tracers
-      ! dust, special doubleq case
-      integer :: igcm_dust_mass   ! dust mass mixing ratio (for transported dust)
-      integer :: igcm_dust_number ! dust number mixing ratio (transported dust)
-      ! water
-      integer :: igcm_h2o_vap ! water vapour
-      integer :: igcm_h2o_ice ! water ice
-      ! chemistry:
-      integer :: igcm_co2
-      integer :: igcm_co
-      integer :: igcm_o
-      integer :: igcm_o1d
-      integer :: igcm_o2
-      integer :: igcm_o3
-      integer :: igcm_h
-      integer :: igcm_h2
-      integer :: igcm_oh
-      integer :: igcm_ho2
-      integer :: igcm_h2o2
-      integer :: igcm_n2
-      integer :: igcm_ar
-      ! other tracers
-      integer :: igcm_ar_n2 ! for simulations using co2 +neutral gaz
-      integer :: igcm_co2_ice ! CO2 ice 
-
-      COMMON/tracer/radius,rho_q,qext,alpha_lift,alpha_devil,noms,mmol, &
-     & varian,r3n_q,qextrhor,rho_dust,rho_ice,rho_co2,ref_r0,dryness
-
-      COMMON/tracer2/igcm_dustbin,igcm_dust_mass,igcm_dust_number,      &
-     & igcm_h2o_vap,igcm_h2o_ice,igcm_co2,igcm_co,igcm_o,igcm_o1d,      &
-     & igcm_o2,igcm_o3,igcm_h,igcm_h2,igcm_oh,igcm_ho2,igcm_h2o2,       &
-     & igcm_n2,igcm_ar,igcm_ar_n2,igcm_co2_ice
-
-!-----------------------------------------------------------------------
Index: trunk/LMDZ.GENERIC/libf/phystd/tracer_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/tracer_h.F90	(revision 787)
+++ trunk/LMDZ.GENERIC/libf/phystd/tracer_h.F90	(revision 787)
@@ -0,0 +1,51 @@
+
+       module tracer_h
+
+       implicit none
+
+       character*20, DIMENSION(:), ALLOCATABLE :: noms   ! name of the tracer
+       real, DIMENSION(:), ALLOCATABLE :: mmol     ! mole mass of tracer (g/mol-1) 
+       real, DIMENSION(:), ALLOCATABLE :: radius   ! dust and ice particle radius (m)
+       real, DIMENSION(:), ALLOCATABLE :: rho_q    ! tracer densities (kg.m-3)
+       real, DIMENSION(:), ALLOCATABLE :: qext     ! Single Scat. Extinction coeff at 0.67 um
+       real, DIMENSION(:), ALLOCATABLE :: alpha_lift  ! saltation vertical flux/horiz flux ratio (m-1)
+       real, DIMENSION(:), ALLOCATABLE :: alpha_devil ! lifting coeeficient by dust devil
+       real, DIMENSION(:), ALLOCATABLE :: qextrhor ! Intermediate for computing opt. depth from q
+
+      real varian      ! Characteristic variance of log-normal distribution
+      real r3n_q     ! used to compute r0 from number and mass mixing ratio
+      real rho_dust     ! Mars dust density (kg.m-3)
+      real rho_ice     ! Water ice density (kg.m-3)
+      real rho_co2     ! CO2 ice density (kg.m-3)
+      real ref_r0        ! for computing reff=ref_r0*r0 (in log.n. distribution)
+
+! tracer indexes: these are initialized in initracer and should be 0 if the
+!                 corresponding tracer does not exist
+      ! dust
+      integer, DIMENSION(:), ALLOCATABLE :: igcm_dustbin ! for dustbin 'dust' tracers
+      ! dust, special doubleq case
+      integer :: igcm_dust_mass   ! dust mass mixing ratio (for transported dust)
+      integer :: igcm_dust_number ! dust number mixing ratio (transported dust)
+      ! water
+      integer :: igcm_h2o_vap ! water vapour
+      integer :: igcm_h2o_ice ! water ice
+      ! chemistry:
+      integer :: igcm_co2
+      integer :: igcm_co
+      integer :: igcm_o
+      integer :: igcm_o1d
+      integer :: igcm_o2
+      integer :: igcm_o3
+      integer :: igcm_h
+      integer :: igcm_h2
+      integer :: igcm_oh
+      integer :: igcm_ho2
+      integer :: igcm_h2o2
+      integer :: igcm_n2
+      integer :: igcm_ar
+      ! other tracers
+      integer :: igcm_ar_n2 ! for simulations using co2 +neutral gaz
+      integer :: igcm_co2_ice ! CO2 ice 
+
+       end module tracer_h
+
Index: trunk/LMDZ.GENERIC/libf/phystd/turbdiff.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/turbdiff.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/turbdiff.F90	(revision 787)
@@ -9,4 +9,7 @@
       use watercommon_h, only : RLVTT, T_h2O_ice_liq, RCPD, mx_eau_sol,Psat_water
       use radcommon_h, only : sigma
+      USE surfdat_h
+      USE comgeomfi_h
+      USE tracer_h
 
       implicit none
@@ -43,9 +46,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "surfdat.h"
-#include "comgeomfi.h"
-#include "tracer.h"
-
-#include "watercap.h"
 
 !     arguments
@@ -84,23 +82,23 @@
       integer ilev,ig,ilay,nlev
 
-      REAL z4st,zdplanck(ngridmx)
-      REAL zkv(ngridmx,nlayermx+1),zkh(ngridmx,nlayermx+1)
-      REAL zcdv(ngridmx),zcdh(ngridmx)
-      REAL zcdv_true(ngridmx),zcdh_true(ngridmx)
-      REAL zu(ngridmx,nlayermx),zv(ngridmx,nlayermx)
-      REAL zh(ngridmx,nlayermx),zt(ngridmx,nlayermx)
-      REAL ztsrf(ngridmx)
-      REAL z1(ngridmx),z2(ngridmx)
-      REAL zmass(ngridmx,nlayermx)
-      REAL zfluxv(ngridmx,nlayermx),zfluxt(ngridmx,nlayermx),zfluxq(ngridmx,nlayermx)
-      REAL zb0(ngridmx,nlayermx)
-      REAL zExner(ngridmx,nlayermx),zovExner(ngridmx,nlayermx)
-      REAL zcv(ngridmx,nlayermx),zdv(ngridmx,nlayermx)  !inversion coefficient for winds
-      REAL zct(ngridmx,nlayermx),zdt(ngridmx,nlayermx)  !inversion coefficient for temperature
-      REAL zcq(ngridmx,nlayermx),zdq(ngridmx,nlayermx)  !inversion coefficient for tracers
+      REAL z4st,zdplanck(ngrid)
+      REAL zkv(ngrid,nlayermx+1),zkh(ngrid,nlayermx+1)
+      REAL zcdv(ngrid),zcdh(ngrid)
+      REAL zcdv_true(ngrid),zcdh_true(ngrid)
+      REAL zu(ngrid,nlayermx),zv(ngrid,nlayermx)
+      REAL zh(ngrid,nlayermx),zt(ngrid,nlayermx)
+      REAL ztsrf(ngrid)
+      REAL z1(ngrid),z2(ngrid)
+      REAL zmass(ngrid,nlayermx)
+      REAL zfluxv(ngrid,nlayermx),zfluxt(ngrid,nlayermx),zfluxq(ngrid,nlayermx)
+      REAL zb0(ngrid,nlayermx)
+      REAL zExner(ngrid,nlayermx),zovExner(ngrid,nlayermx)
+      REAL zcv(ngrid,nlayermx),zdv(ngrid,nlayermx)  !inversion coefficient for winds
+      REAL zct(ngrid,nlayermx),zdt(ngrid,nlayermx)  !inversion coefficient for temperature
+      REAL zcq(ngrid,nlayermx),zdq(ngrid,nlayermx)  !inversion coefficient for tracers
       REAL zcst1
       REAL zu2!, a
-      REAL zcq0(ngridmx),zdq0(ngridmx)
-      REAL zx_alf1(ngridmx),zx_alf2(ngridmx)
+      REAL zcq0(ngrid),zdq0(ngrid)
+      REAL zx_alf1(ngrid),zx_alf2(ngrid)
 
       LOGICAL firstcall
@@ -111,10 +109,10 @@
 !     -------
       INTEGER iq
-      REAL zq(ngridmx,nlayermx,nqmx)
-      REAL zqnoevap(ngridmx,nlayermx) !special for water case to compute where evaporated water goes.
-      REAL pdqevap(ngridmx,nlayermx) !special for water case to compute where evaporated water goes.
-      REAL zdmassevap(ngridmx)
-      REAL rho(ngridmx)         ! near-surface air density
-      REAL qsat(ngridmx),psat(ngridmx)
+      REAL zq(ngrid,nlayermx,nq)
+      REAL zqnoevap(ngrid,nlayermx) !special for water case to compute where evaporated water goes.
+      REAL pdqevap(ngrid,nlayermx) !special for water case to compute where evaporated water goes.
+      REAL zdmassevap(ngrid)
+      REAL rho(ngrid)         ! near-surface air density
+      REAL qsat(ngrid),psat(ngrid)
       DATA firstcall/.true./
       REAL kmixmin
@@ -122,5 +120,5 @@
 !     Variables added for implicit latent heat inclusion
 !     --------------------------------------------------
-      real dqsat(ngridmx), qsat_temp1, qsat_temp2,psat_temp
+      real dqsat(ngrid), qsat_temp1, qsat_temp2,psat_temp
 
       integer, save :: ivap, iliq, iliq_surf,iice_surf ! also make liq for clarity on surface...
@@ -241,5 +239,5 @@
 !     ------------------------------------------------------ 
 
-      call vdif_kc(ptimestep,g,pzlev,pzlay,pu,pv,zh,zcdv_true,pq2,zkv,zkh) !JL12 why not call vdif_kc with updated winds and temperature 
+      call vdif_kc(ngrid,ptimestep,g,pzlev,pzlay,pu,pv,zh,zcdv_true,pq2,zkv,zkh) !JL12 why not call vdif_kc with updated winds and temperature 
 
 !     Adding eddy mixing to mimic 3D general circulation in 1D
@@ -262,5 +260,5 @@
  
 !JL12 calculate the flux coefficients (tables multiplied elements by elements)
-      zfluxv(1:ngridmx,1:nlayermx)=zkv(1:ngridmx,1:nlayermx)*zb0(1:ngridmx,1:nlayermx)
+      zfluxv(1:ngrid,1:nlayermx)=zkv(1:ngrid,1:nlayermx)*zb0(1:ngrid,1:nlayermx)
       
 !-----------------------------------------------------------------------
@@ -358,7 +356,6 @@
 !     JL12 calculate the flux coefficients (tables multiplied elements by elements)
 !     ---------------------------------------------------------------
-      zfluxq(1:ngridmx,1:nlayermx)=zkh(1:ngridmx,1:nlayermx)*zb0(1:ngridmx,1:nlayermx) !JL12 we save zfluxq which doesn't need the Exner factor
-      zfluxt(1:ngridmx,1:nlayermx)=zfluxq(1:ngridmx,1:nlayermx)*zExner(1:ngridmx,1:nlayermx)
-
+      zfluxq(1:ngrid,1:nlayermx)=zkh(1:ngrid,1:nlayermx)*zb0(1:ngrid,1:nlayermx) !JL12 we save zfluxq which doesn't need the Exner factor
+      zfluxt(1:ngrid,1:nlayermx)=zfluxq(1:ngrid,1:nlayermx)*zExner(1:ngrid,1:nlayermx)
 
       DO ig=1,ngrid
@@ -404,5 +401,4 @@
 
          DO ig=1,ngrid
-
             z1(ig)=pcapcal(ig)*ptsrf(ig)+cpp*zfluxt(ig,1)*zct(ig,1)*zovExner(ig,1) &
                 + pfluxsrf(ig)*ptimestep + zdplanck(ig)*ptsrf(ig) 
@@ -434,5 +430,5 @@
 !     Calculate vertical flux from the bottom to the first layer (dust)
 !     -----------------------------------------------------------------
-         do ig=1,ngridmx  
+         do ig=1,ngrid
             rho(ig) = zb0(ig,1) /ptimestep
          end do
@@ -470,5 +466,5 @@
                   ENDDO
                else             ! general case
-                  DO ig=1,ngrid
+                  do ig=1,ngrid
                      z1(ig)=1./(zmass(ig,1)+zfluxq(ig,2)*(1.-zdq(ig,2)))
                      zcq(ig,1)=(zmass(ig,1)*zq(ig,1,iq)+zfluxq(ig,2)*zcq(ig,2)+(-pdqsdif(ig,iq))*ptimestep)*z1(ig)
@@ -500,5 +496,5 @@
             
                ! compute evaporation efficiency
-               do ig = 1, ngrid
+               do ig=1,ngrid
                   if(rnat(ig).eq.1)then
                      dryness(ig)=pqsurf(ig,iliq_surf)+pqsurf(ig,iice_surf) 
@@ -509,5 +505,4 @@
 
                do ig=1,ngrid
-
                 ! Calculate the value of qsat at the surface (water)
                 call Psat_water(ptsrf(ig),pplev(ig,1),psat(ig),qsat(ig))
@@ -526,5 +521,5 @@
                   zdq(ig,nlay)=zfluxq(ig,nlay)*z1(ig)
                enddo 
-            
+          
                do ilay=nlay-1,2,-1
                   do ig=1,ngrid
@@ -658,5 +653,5 @@
             ENDDO
 
-            DO ig=1,ngrid
+            do ig=1,ngrid
                z1(ig)=1./(zmass(ig,1)+zfluxq(ig,2)*(1.-zdq(ig,2)))
                zcq(ig,1)=(zmass(ig,1)*zqnoevap(ig,1)+zfluxq(ig,2)*zcq(ig,2))*z1(ig)
@@ -692,5 +687,5 @@
       enddo
       
-      DO ig=1,ngrid  ! computing sensible heat flux (atm => surface)
+      DO ig=1,ngrid ! computing sensible heat flux (atm => surface)
 	 sensibFlux(ig)=cpp*zfluxt(ig,1)/ptimestep*(zt(ig,1)*zovExner(ig,1)-ztsrf(ig))
       ENDDO
@@ -710,5 +705,5 @@
                enddo
             enddo
-	    do ig=1,ngrid
+            do ig=1,ngrid
 	       zdmassevap(ig)=SUM(pdqevap(ig,:)*zmass(ig,:))*ptimestep
 	    end do	    
Index: trunk/LMDZ.GENERIC/libf/phystd/vdif_kc.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/vdif_kc.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/vdif_kc.F	(revision 787)
@@ -1,3 +1,3 @@
-      SUBROUTINE vdif_kc(dt,g,zlev,zlay,u,v,teta,cd,q2,km,kn)
+      SUBROUTINE vdif_kc(ngrid,dt,g,zlev,zlay,u,v,teta,cd,q2,km,kn)
       IMPLICIT NONE
 c.......................................................................
@@ -27,14 +27,15 @@
 c 
 c.......................................................................
+      INTEGER ngrid
       REAL dt,g
-      REAL zlev(ngridmx,nlayermx+1)
-      REAL zlay(ngridmx,nlayermx)
-      REAL u(ngridmx,nlayermx)
-      REAL v(ngridmx,nlayermx)
-      REAL teta(ngridmx,nlayermx)
-      REAL cd(ngridmx)
-      REAL q2(ngridmx,nlayermx+1)
-      REAL km(ngridmx,nlayermx+1)
-      REAL kn(ngridmx,nlayermx+1)
+      REAL zlev(ngrid,nlayermx+1)
+      REAL zlay(ngrid,nlayermx)
+      REAL u(ngrid,nlayermx)
+      REAL v(ngrid,nlayermx)
+      REAL teta(ngrid,nlayermx)
+      REAL cd(ngrid)
+      REAL q2(ngrid,nlayermx+1)
+      REAL km(ngrid,nlayermx+1)
+      REAL kn(ngrid,nlayermx+1)
 c.......................................................................
 c
@@ -49,8 +50,8 @@
 c
 c.......................................................................
-      INTEGER nlay,nlev,ngrid
-      REAL unsdz(ngridmx,nlayermx)
-      REAL unsdzdec(ngridmx,nlayermx+1)
-      REAL q(ngridmx,nlayermx+1)
+      INTEGER nlay,nlev
+      REAL unsdz(ngrid,nlayermx)
+      REAL unsdzdec(ngrid,nlayermx+1)
+      REAL q(ngrid,nlayermx+1)
 c.......................................................................
 c
@@ -62,5 +63,5 @@
 c
 c.......................................................................
-      REAL kmpre(ngridmx,nlayermx+1)
+      REAL kmpre(ngrid,nlayermx+1)
       REAL qcstat
       REAL q2cstat
@@ -70,5 +71,5 @@
 c
 c.......................................................................
-      REAL long(ngridmx,nlayermx+1)
+      REAL long(ngrid,nlayermx+1)
 c.......................................................................
 c
@@ -93,8 +94,8 @@
       REAL mcstat
       REAL m2cstat
-      REAL m(ngridmx,nlayermx+1)
-      REAL mpre(ngridmx,nlayermx+1)
-      REAL m2(ngridmx,nlayermx+1)
-      REAL n2(ngridmx,nlayermx+1)
+      REAL m(ngrid,nlayermx+1)
+      REAL mpre(ngrid,nlayermx+1)
+      REAL m2(ngrid,nlayermx+1)
+      REAL n2(ngrid,nlayermx+1)
 c.......................................................................
 c
@@ -118,9 +119,9 @@
       LOGICAL gnsup
       REAL gm
-c      REAL ri(ngridmx,nlayermx+1)
-      REAL sn(ngridmx,nlayermx+1)
-      REAL snq2(ngridmx,nlayermx+1)
-      REAL sm(ngridmx,nlayermx+1)
-      REAL smq2(ngridmx,nlayermx+1)
+c      REAL ri(ngrid,nlayermx+1)
+      REAL sn(ngrid,nlayermx+1)
+      REAL snq2(ngrid,nlayermx+1)
+      REAL sm(ngrid,nlayermx+1)
+      REAL smq2(ngrid,nlayermx+1)
 c.......................................................................
 c
@@ -183,5 +184,4 @@
       PARAMETER (nlay=nlayermx)
       PARAMETER (nlev=nlayermx+1)
-      PARAMETER (ngrid=ngridmx)
 c
       PARAMETER (
@@ -209,16 +209,16 @@
 c
       DO ilev=1,nlev
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid 
         q2(igrid,ilev)=amax1(q2(igrid,ilev),q2min)
         q(igrid,ilev)=sqrt(q2(igrid,ilev))
-                                                      ENDDO
+                                                 ENDDO
       ENDDO
 c
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       tmp1=cd(igrid)*(u(igrid,1)**2+v(igrid,1)**2)
       q2(igrid,1)=b1**(2.E+0/3.E+0)*tmp1
       q2(igrid,1)=amax1(q2(igrid,1),q2min)
       q(igrid,1)=sqrt(q2(igrid,1))
-                                                      ENDDO
+                                                 ENDDO
 c
 c.......................................................................
@@ -237,19 +237,19 @@
 c
       DO ilay=1,nlay
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
         unsdz(igrid,ilay)=1.E+0/(zlev(igrid,ilay+1)-zlev(igrid,ilay))
-                                                      ENDDO
+                                                 ENDDO
       ENDDO
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       unsdzdec(igrid,1)=1.E+0/(zlay(igrid,1)-zlev(igrid,1))
-                                                      ENDDO
+                                                 ENDDO
       DO ilay=2,nlay
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
         unsdzdec(igrid,ilay)=1.E+0/(zlay(igrid,ilay)-zlay(igrid,ilay-1))
-                                                      ENDDO
+                                                 ENDDO
       ENDDO
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       unsdzdec(igrid,nlay+1)=1.E+0/(zlev(igrid,nlay+1)-zlay(igrid,nlay))
-                                                      ENDDO
+                                                 ENDDO
 c
 c.......................................................................
@@ -257,5 +257,5 @@
 c.......................................................................
 c
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       m2(igrid,1)=(unsdzdec(igrid,1)
      &                   *u(igrid,1))**2
@@ -264,9 +264,9 @@
       m(igrid,1)=sqrt(m2(igrid,1))
       mpre(igrid,1)=m(igrid,1)
-                                                      ENDDO
+                                                 ENDDO
 c
 c-----------------------------------------------------------------------
       DO ilev=2,nlev-1
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
 c-----------------------------------------------------------------------
 c
@@ -295,13 +295,13 @@
 c
 c-----------------------------------------------------------------------
-                                                      ENDDO
+                                                 ENDDO
       ENDDO
 c-----------------------------------------------------------------------
 c
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       m2(igrid,nlev)=m2(igrid,nlev-1)
       m(igrid,nlev)=m(igrid,nlev-1)
       mpre(igrid,nlev)=m(igrid,nlev)
-                                                      ENDDO
+                                                 ENDDO
 c
 c.......................................................................
@@ -311,5 +311,5 @@
 c-----------------------------------------------------------------------
       DO ilev=2,nlev-1
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
 c-----------------------------------------------------------------------
 c
@@ -375,5 +375,5 @@
 c
 c-----------------------------------------------------------------------
-                                                      ENDDO
+                                                  ENDDO
       ENDDO
 c-----------------------------------------------------------------------
@@ -383,13 +383,13 @@
 c.......................................................................
 c
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       kn(igrid,1)=knmin
       km(igrid,1)=kmmin
       kmpre(igrid,1)=km(igrid,1)
-                                                      ENDDO
+                                                 ENDDO
 c
 c-----------------------------------------------------------------------
       DO ilev=2,nlev-1
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
 c-----------------------------------------------------------------------
 c
@@ -401,13 +401,13 @@
 c
 c-----------------------------------------------------------------------
-                                                      ENDDO
+                                                 ENDDO
       ENDDO
 c-----------------------------------------------------------------------
 c
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       kn(igrid,nlev)=kn(igrid,nlev-1)
       km(igrid,nlev)=km(igrid,nlev-1)
       kmpre(igrid,nlev)=km(igrid,nlev)
-                                                      ENDDO
+                                                 ENDDO
 c
 c.......................................................................
@@ -418,5 +418,5 @@
       DO 10001 ilev=2,nlev-1
 c---->
-      DO 10002 igrid=1,ngrid 
+      DO 10002 igrid=1,ngrid
 c
 c.......................................................................
@@ -539,5 +539,5 @@
 c
 c
-                                                      DO igrid=1,ngrid 
+                                                 DO igrid=1,ngrid
       kn(igrid,1)=knmin
       km(igrid,1)=kmmin
@@ -546,5 +546,5 @@
       kn(igrid,nlev)=kn(igrid,nlev-1)
       km(igrid,nlev)=km(igrid,nlev-1)
-                                                      ENDDO
+                                                 ENDDO
 
 c
Index: trunk/LMDZ.GENERIC/libf/phystd/vdifc.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/vdifc.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/vdifc.F	(revision 787)
@@ -9,4 +9,7 @@
       use watercommon_h, only : RLVTT, T_h2O_ice_liq, RCPD, mx_eau_sol
       use radcommon_h, only : sigma
+      USE surfdat_h
+      USE comgeomfi_h
+      USE tracer_h
 
       implicit none
@@ -39,9 +42,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "surfdat.h"
-#include "comgeomfi.h"
-#include "tracer.h"
-
-#include "watercap.h"
 
 !     arguments
@@ -78,21 +76,21 @@
       integer ilev,ig,ilay,nlev
 
-      REAL z4st,zdplanck(ngridmx)
-      REAL zkv(ngridmx,nlayermx+1),zkh(ngridmx,nlayermx+1)
-      REAL zcdv(ngridmx),zcdh(ngridmx)
-      REAL zcdv_true(ngridmx),zcdh_true(ngridmx)
-      REAL zu(ngridmx,nlayermx),zv(ngridmx,nlayermx)
-      REAL zh(ngridmx,nlayermx)
-      REAL ztsrf2(ngridmx)
-      REAL z1(ngridmx),z2(ngridmx)
-      REAL za(ngridmx,nlayermx),zb(ngridmx,nlayermx)
-      REAL zb0(ngridmx,nlayermx)
-      REAL zc(ngridmx,nlayermx),zd(ngridmx,nlayermx)
+      REAL z4st,zdplanck(ngrid)
+      REAL zkv(ngrid,nlayermx+1),zkh(ngrid,nlayermx+1)
+      REAL zcdv(ngrid),zcdh(ngrid)
+      REAL zcdv_true(ngrid),zcdh_true(ngrid)
+      REAL zu(ngrid,nlayermx),zv(ngrid,nlayermx)
+      REAL zh(ngrid,nlayermx)
+      REAL ztsrf2(ngrid)
+      REAL z1(ngrid),z2(ngrid)
+      REAL za(ngrid,nlayermx),zb(ngrid,nlayermx)
+      REAL zb0(ngrid,nlayermx)
+      REAL zc(ngrid,nlayermx),zd(ngrid,nlayermx)
       REAL zcst1
       REAL zu2!, a
-      REAL zcq(ngridmx,nlayermx),zdq(ngridmx,nlayermx)
-      REAL evap(ngridmx)
-      REAL zcq0(ngridmx),zdq0(ngridmx)
-      REAL zx_alf1(ngridmx),zx_alf2(ngridmx)
+      REAL zcq(ngrid,nlayermx),zdq(ngrid,nlayermx)
+      REAL evap(ngrid)
+      REAL zcq0(ngrid),zdq0(ngrid)
+      REAL zx_alf1(ngrid),zx_alf2(ngrid)
 
       LOGICAL firstcall
@@ -103,5 +101,5 @@
 !     variables added for CO2 condensation
 !     ------------------------------------
-      REAL hh                   !, zhcond(ngridmx,nlayermx)
+      REAL hh                   !, zhcond(ngrid,nlayermx)
 !     REAL latcond,tcond1mb
 !     REAL acond,bcond
@@ -112,8 +110,8 @@
 !     -------
       INTEGER iq
-      REAL zq(ngridmx,nlayermx,nqmx)
-      REAL zq1temp(ngridmx)
-      REAL rho(ngridmx)         ! near-surface air density
-      REAL qsat(ngridmx)
+      REAL zq(ngrid,nlayermx,nq)
+      REAL zq1temp(ngrid)
+      REAL rho(ngrid)         ! near-surface air density
+      REAL qsat(ngrid)
       DATA firstcall/.true./
       REAL kmixmin
@@ -121,11 +119,11 @@
 !     Variables added for implicit latent heat inclusion
 !     --------------------------------------------------
-      real latconst, dqsat(ngridmx), qsat_temp1, qsat_temp2
-      real z1_Tdry(ngridmx), z2_Tdry(ngridmx)
-      real z1_T(ngridmx), z2_T(ngridmx)
-      real zb_T(ngridmx)
-      real zc_T(ngridmx,nlayermx)
-      real zd_T(ngridmx,nlayermx)
-      real lat1(ngridmx), lat2(ngridmx)
+      real latconst, dqsat(ngrid), qsat_temp1, qsat_temp2
+      real z1_Tdry(ngrid), z2_Tdry(ngrid)
+      real z1_T(ngrid), z2_T(ngrid)
+      real zb_T(ngrid)
+      real zc_T(ngrid,nlayermx)
+      real zd_T(ngrid,nlayermx)
+      real lat1(ngrid), lat2(ngrid)
       real surfh2otot
       logical surffluxdiag
@@ -152,11 +150,4 @@
 
       IF (firstcall) THEN
-!         IF(ngrid.NE.ngridmx) THEN
-!            PRINT*,'STOP dans vdifc'
-!            PRINT*,'probleme de dimensions :'
-!            PRINT*,'ngrid  =',ngrid
-!            PRINT*,'ngridmx  =',ngridmx
-!            STOP
-!         ENDIF
 !     To compute: Tcond= 1./(bcond-acond*log(.0095*p)) (p in pascal)
 !     bcond=1./tcond1mb
@@ -254,5 +245,5 @@
 !     ------------------------------------------------------ 
 
-      call vdif_kc(ptimestep,g,pzlev,pzlay
+      call vdif_kc(ngrid,ptimestep,g,pzlev,pzlay
      &     ,pu,pv,ph,zcdv_true
      &     ,pq2,zkv,zkh)
@@ -442,5 +433,5 @@
 !     Calculate vertical flux from the bottom to the first layer (dust)
 !     -----------------------------------------------------------------
-         do ig=1,ngridmx  
+         do ig=1,ngrid  
             rho(ig) = zb0(ig,1) /ptimestep
          end do
Index: trunk/LMDZ.GENERIC/libf/phystd/vlz_fi.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/vlz_fi.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/vlz_fi.F	(revision 787)
@@ -35,5 +35,5 @@
 c
 
-      real dzq(ngridmx,llm),dzqw(ngridmx,llm),adzqw(ngridmx,llm),dzqmax
+      real dzq(ngrid,llm),dzqw(ngrid,llm),adzqw(ngrid,llm),dzqmax
       real newmasse
       real sigw, Mtot, MQtot
@@ -90,5 +90,5 @@
 
        do l = 1,llm          ! loop different than when w<0
-        do  ij = 1,ngrid
+        do ij=1,ngrid
 
          if(w(ij,l).gt.0.)then
@@ -133,10 +133,10 @@
 
 c      Surface flux up:
-       do  ij = 1,ngrid
+       do ij=1,ngrid
          if(w(ij,1).lt.0.) wq(ij,1)=0. ! warning : not always valid
        end do
 
        do l = 1,llm-1  ! loop different than when w>0
-        do  ij = 1,ngrid
+        do ij=1,ngrid
          if(w(ij,l+1).le.0)then
 
Index: trunk/LMDZ.GENERIC/libf/phystd/watercap.h
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/watercap.h	(revision 786)
+++ 	(revision )
@@ -1,6 +1,0 @@
-!-----------------------------------------------------------------------
-! INCLUDE 'watercap.h'
-
-      logical watercaptag(ngridmx)
-
-      common/permcap/watercaptag
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F	(revision 787)
@@ -39,4 +39,6 @@
 !
 !=================================================================
+
+      USE surfdat_h
  
       implicit none
@@ -52,5 +54,4 @@
 #include "netcdf.inc"
 #include "temps.h"
-#include "surfdat.h"
 
 ! Arguments on input:
@@ -95,6 +96,5 @@
       character(len=20),save :: nom_def(n_nom_def_max)
       logical,save :: firstcall=.true.
-      
-#ifndef MESOSCALE
+
 !***************************************************************
 !Sortie des variables au rythme voulu
@@ -108,4 +108,6 @@
 !***************************************************************
 
+#ifndef NOWRITEDIAGFI
+
 ! At very first call, check if there is a "diagfi.def" to use and read it
 ! -----------------------------------------------------------------------
@@ -113,5 +115,5 @@
          firstcall=.false.
 
-  !      Open diagfi.def definition file if there is one:
+!      Open diagfi.def definition file if there is one:
          open(99,file="diagfi.def",status='old',form='formatted',
      s   iostat=ierr2)
@@ -192,5 +194,5 @@
       endif ! if (firstnom.eq.'1234567890')
 
-      if (ngridmx.eq.1) then
+      if (ngrid.eq.1) then
         ! in testphys1d, for the 1d version of the GCM, iphysiq and irythme
         ! are undefined; so set them to 1
@@ -448,3 +450,4 @@
 
 #endif
+
       end
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90	(revision 787)
@@ -10,4 +10,6 @@
 ! (yielding the sought time series of the variable)
 
+use comsoil_h
+
 implicit none
 
@@ -16,5 +18,4 @@
 #include"paramet.h"
 #include"control.h"
-#include"comsoil.h"
 #include"netcdf.inc"
 
@@ -78,5 +79,5 @@
   
   ! Define dimensions and axis attributes
-  call iniwritesoil(nid)
+  call iniwritesoil(nid,ngrid)
   
   ! set zitau to -1 to be compatible with zitau incrementation step below
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F	(revision 787)
@@ -43,4 +43,5 @@
 ! Addition by RW (2010) to allow OLR to be saved in .nc format
       use radinc_h, only : L_NSPECTI
+      USE surfdat_h
 
       implicit none
@@ -56,5 +57,4 @@
 #include "netcdf.inc"
 #include "temps.h"
-#include "surfdat.h"
 #include "callkeys.h"
 
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F	(revision 786)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F	(revision 787)
@@ -43,4 +43,5 @@
 ! Addition by RW (2010) to allow OSR to be saved in .nc format
       use radinc_h, only : L_NSPECTV
+      USE surfdat_h
 
       implicit none
@@ -56,5 +57,4 @@
 #include "netcdf.inc"
 #include "temps.h"
-#include "surfdat.h"
 #include "callkeys.h"
 
