Index: LMDZ5/trunk/libf/dynlonlat_phylonlat/phylmd/iniphysiq.F90
===================================================================
--- LMDZ5/trunk/libf/dynlonlat_phylonlat/phylmd/iniphysiq.F90	(revision 2342)
+++ LMDZ5/trunk/libf/dynlonlat_phylonlat/phylmd/iniphysiq.F90	(revision 2343)
@@ -23,4 +23,5 @@
                       indnum_fn_num,index_trac,&
                       niso,ntraceurs_zone,ntraciso
+  USE control_mod, ONLY: dayref,anneeref,day_step,nday,offline
   USE comgeomphy, ONLY: initcomgeomphy, &
                         airephy, & ! physics grid area (m2)
@@ -30,5 +31,7 @@
                         rlatd ! latitudes
   USE inifis_mod, ONLY: inifis
+  USE time_phylmdz_mod, ONLY: init_time
   USE infotrac_phy, ONLY: init_infotrac_phy
+  USE phystokenc_mod, ONLY: init_phystokenc
   USE phyaqua_mod, ONLY: iniaqua
   IMPLICIT NONE
@@ -42,4 +45,6 @@
   include "comvert.h"
   include "iniprint.h"
+  include "temps.h"
+  include "tracstoke.h"
 
   REAL, INTENT (IN) :: prad ! radius of the planet (m)
@@ -134,8 +139,12 @@
   ENDIF ! of IF (klon_glo>1)
 
-!$OMP PARALLEL 
+!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/)
   ! Initialize physical constants in physics:
   CALL inifis(punjours,prad,pg,pr,pcpp)
-  
+  CALL init_time(annee_ref,day_ref,day_ini,start_time,nday,ptimestep)
+
+  ! Copy over "offline" settings
+  CALL init_phystokenc(offline,istphy)
+
   ! copy over preff , ap(), bp(), etc 
   CALL init_vertical_layers(nlayer,preff,scaleheight, &
Index: LMDZ5/trunk/libf/phylmd/fisrtilp.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/fisrtilp.F90	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/fisrtilp.F90	(revision 2343)
@@ -26,5 +26,4 @@
   !ym include "dimphy.h"
   include "YOMCST.h"
-  include "tracstoke.h"
   include "fisrtilp.h"
   include "nuage.h" ! JBM (3/14)
Index: LMDZ5/trunk/libf/phylmd/fisrtilp_tr.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/fisrtilp_tr.F90	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/fisrtilp_tr.F90	(revision 2343)
@@ -22,5 +22,4 @@
   ! ym#include "dimphy.h"
   include "YOMCST.h"
-  include "tracstoke.h"
 
   ! Arguments:
Index: LMDZ5/trunk/libf/phylmd/initphysto.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/initphysto.F90	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/initphysto.F90	(revision 2343)
@@ -8,6 +8,7 @@
   USE IOIPSL
   USE iophy
-  USE control_mod
   USE indice_sol_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
+  USE time_phylmdz_mod, ONLY: day_ref, annee_ref
   
   IMPLICIT NONE
@@ -37,14 +38,4 @@
 !
 ! =====================================================================
-!
-!   Declarations
-  INCLUDE "dimensions.h"
-  INCLUDE "paramet.h"
-  INCLUDE "comconst.h"
-  INCLUDE "comgeom.h"
-  INCLUDE "temps.h"
-  INCLUDE "logic.h"
-  INCLUDE "description.h"
-  INCLUDE "serre.h"
 
 !   Arguments
@@ -58,5 +49,5 @@
   INTEGER nhoriid, i
   INTEGER l,k
-  REAL nivsigs(llm)
+  REAL nivsigs(nbp_lev)
   INTEGER tau0
   REAL zjulian
@@ -66,10 +57,9 @@
   INTEGER zan, idayref
   LOGICAL ok_sync
-  REAL zx_lon(iim,jjm+1), zx_lat(iim,jjm+1)
+  REAL zx_lon(nbp_lon,nbp_lat), zx_lat(nbp_lon,nbp_lat)
   CHARACTER(len=12) :: nvar
 
 !  Initialisations
 !
-  pi = 4. * ATAN (1.)
   ok_sync= .TRUE.
 !
@@ -88,5 +78,5 @@
 !  Appel a histvert pour la grille verticale
 !
-  DO l=1,llm
+  DO l=1,nbp_lev
      nivsigs(l)=REAL(l)
   ENDDO
@@ -94,107 +84,107 @@
   CALL histvert(fileid, 'sig_s', 'Niveaux sigma', &
        'sigma_level', &
-       llm, nivsigs, zvertiid)
+       nbp_lev, nivsigs, zvertiid)
 !
 !  Appels a histdef pour la definition des variables a sauvegarder
 !
   CALL histdef(fileid, "phis", "Surface geop. height", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
   
   CALL histdef(fileid, "aire", "Grid area", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
 
   CALL histdef(fileid, "longitudes", "longitudes", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
 
   CALL histdef(fileid, "latitudes", "latitudes", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
 ! T 
-  CALL histdef(fileid, 't', 'Temperature', 'K', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 't', 'Temperature', 'K', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! mfu 
-  CALL histdef(fileid, 'mfu', 'flx m. pan. mt', 'kg m/s',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'mfu', 'flx m. pan. mt', 'kg m/s',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! mfd 
-  CALL histdef(fileid, 'mfd', 'flx m. pan. des', 'kg m/s',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'mfd', 'flx m. pan. des', 'kg m/s',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! en_u 
-  CALL histdef(fileid, 'en_u', 'flx ent pan mt', 'kg m/s', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'en_u', 'flx ent pan mt', 'kg m/s', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! de_u 
-  CALL histdef(fileid, 'de_u', 'flx det pan mt', 'kg m/s',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'de_u', 'flx det pan mt', 'kg m/s',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! en_d 
-  CALL histdef(fileid, 'en_d', 'flx ent pan dt', 'kg m/s', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'en_d', 'flx ent pan dt', 'kg m/s', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! de_d 
-  CALL histdef(fileid, 'de_d', 'flx det pan dt', 'kg m/s', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'de_d', 'flx det pan dt', 'kg m/s', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! coefh
-  CALL histdef(fileid, "coefh", " ", " ", iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, "inst(X)", t_ops, t_wrt)
+  CALL histdef(fileid, "coefh", " ", " ", nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, "inst(X)", t_ops, t_wrt)
 ! fm_th
-  CALL histdef(fileid, "fm_th", " ", " ",iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, "inst(X)", t_ops, t_wrt)
+  CALL histdef(fileid, "fm_th", " ", " ",nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, "inst(X)", t_ops, t_wrt)
 ! en_th
-  CALL histdef(fileid, "en_th", " ", " ",iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, "inst(X)", t_ops, t_wrt)
+  CALL histdef(fileid, "en_th", " ", " ",nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, "inst(X)", t_ops, t_wrt)
 ! frac_impa
-  CALL histdef(fileid, 'frac_impa', ' ', ' ',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'frac_impa', ' ', ' ',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! frac_nucl
-  CALL histdef(fileid, 'frac_nucl', ' ', ' ',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'frac_nucl', ' ', ' ',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! pyu1
-  CALL histdef(fileid, "pyu1", " ", " ", iim,jj_nb,nhoriid, &
+  CALL histdef(fileid, "pyu1", " ", " ", nbp_lon,jj_nb,nhoriid, &
        1,1,1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! pyv1
-  CALL histdef(fileid, "pyv1", " ", " ", iim,jj_nb,nhoriid, &
+  CALL histdef(fileid, "pyv1", " ", " ", nbp_lon,jj_nb,nhoriid, &
        1,1,1, -99, 32,"inst(X)", t_ops, t_wrt)    
 ! ftsol1
-  CALL histdef(fileid, "ftsol1", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol1", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99,32, "inst(X)", t_ops, t_wrt)
 ! ftsol2
-  CALL histdef(fileid, "ftsol2", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol2", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99,32, "inst(X)", t_ops, t_wrt)
 ! ftsol3
-  CALL histdef(fileid, "ftsol3", " ", " ", iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol3", " ", " ", nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99,32, "inst(X)", t_ops, t_wrt)
 ! ftsol4
-  CALL histdef(fileid, "ftsol4", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol4", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! psrf1
-  CALL histdef(fileid, "psrf1", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf1", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99,32, "inst(X)", t_ops, t_wrt)
 ! psrf2
-  CALL histdef(fileid, "psrf2", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf2", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! psrf3
-  CALL histdef(fileid, "psrf3", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf3", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! psrf4
-  CALL histdef(fileid, "psrf4", " ", " ", iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf4", " ", " ", nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99,32, "inst(X)", t_ops, t_wrt)
 ! sh
-  CALL histdef(fileid, 'sh', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'sh', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! da
-  CALL histdef(fileid, 'da', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'da', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! mp
-  CALL histdef(fileid, 'mp', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'mp', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! upwd
-  CALL histdef(fileid, 'upwd', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'upwd', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! dnwd
-  CALL histdef(fileid, 'dnwd', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'dnwd', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 
 ! phi
-  DO k=1,llm
+  DO k=1,nbp_lev
      IF (k<10) THEN
         WRITE(nvar,'(i1)') k
@@ -206,6 +196,6 @@
      nvar='phi_lev'//trim(nvar)
      
-     CALL histdef(fileid, nvar, '', '', iim, jj_nb, nhoriid, &
-          llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+     CALL histdef(fileid, nvar, '', '', nbp_lon, jj_nb, nhoriid, &
+          nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
   END DO
 
Index: LMDZ5/trunk/libf/phylmd/physiq.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/physiq.F90	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/physiq.F90	(revision 2343)
@@ -22,4 +22,6 @@
   USE iophy
   USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
+  USE phystokenc_mod, ONLY: offline, phystokenc
+  USE time_phylmdz_mod, only: raz_date, day_step_phy
   USE vampir
   USE pbl_surface_mod, ONLY : pbl_surface
@@ -46,5 +48,5 @@
   use radlwsw_m, only: radlwsw
   use phyaqua_mod, only: zenang_an
-  USE control_mod
+  USE control_mod, ONLY: config_inca
 #ifdef CPP_XIOS
   USE wxios, ONLY: missing_val, missing_val_omp
Index: LMDZ5/trunk/libf/phylmd/phystokenc.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/phystokenc.F90	(revision 2342)
+++ 	(revision )
@@ -1,363 +1,0 @@
-SUBROUTINE phystokenc (nlon,nlev,pdtphys,rlon,rlat, &
-     pt,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d, &
-     pfm_therm,pentr_therm, &
-     cdragh, pcoefh,yu1,yv1,ftsol,pctsrf, &
-     frac_impa,frac_nucl, &
-     pphis,paire,dtime,itap, &
-     psh, pda, pphi, pmp, pupwd, pdnwd)
-  
-  USE ioipsl
-  USE dimphy
-  USE infotrac_phy, ONLY : nqtot
-  USE iophy
-  USE control_mod
-  USE indice_sol_mod
-  USE print_control_mod, ONLY: lunout
-  
-  IMPLICIT NONE
-  
-!======================================================================
-! Auteur(s) FH
-! Objet: Ecriture des variables pour transport offline
-!
-!======================================================================
-  INCLUDE "dimensions.h"
-  INCLUDE "tracstoke.h"
-!======================================================================
-
-! Arguments:
-!
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: psh   ! humidite specifique
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pda
-  REAL,DIMENSION(klon,klev,klev), INTENT(IN):: pphi
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pmp
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pupwd ! saturated updraft mass flux
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pdnwd ! saturated downdraft mass flux
-
-!   EN ENTREE:
-!   ==========
-!
-!   divers:
-!   -------
-!
-  INTEGER nlon ! nombre de points horizontaux
-  INTEGER nlev ! nombre de couches verticales
-  REAL pdtphys ! pas d'integration pour la physique (seconde)
-  INTEGER itap
-  INTEGER, SAVE :: physid
-!$OMP THREADPRIVATE(physid)
-
-!   convection:
-!   -----------
-!
-  REAL pmfu(klon,klev)  ! flux de masse dans le panache montant
-  REAL pmfd(klon,klev)  ! flux de masse dans le panache descendant
-  REAL pen_u(klon,klev) ! flux entraine dans le panache montant
-  REAL pde_u(klon,klev) ! flux detraine dans le panache montant
-  REAL pen_d(klon,klev) ! flux entraine dans le panache descendant
-  REAL pde_d(klon,klev) ! flux detraine dans le panache descendant
-  REAL pt(klon,klev)
-  REAL,ALLOCATABLE,SAVE :: t(:,:)
-!$OMP THREADPRIVATE(t)
-!
-  REAL rlon(klon), rlat(klon), dtime
-  REAL zx_tmp_3d(iim,jjm+1,klev),zx_tmp_2d(iim,jjm+1)
-
-!   Couche limite:
-!   --------------
-!
-  REAL cdragh(klon)          ! cdrag
-  REAL pcoefh(klon,klev)     ! coeff melange CL
-  REAL pcoefh_buf(klon,klev) ! coeff melange CL + cdrag
-  REAL yv1(klon)
-  REAL yu1(klon),pphis(klon),paire(klon)
-
-!   Les Thermiques : (Abderr 25 11 02)
-!   ---------------
-  REAL, INTENT(IN) ::  pfm_therm(klon,klev+1)
-  REAL pentr_therm(klon,klev)
-  
-  REAL,ALLOCATABLE,SAVE :: entr_therm(:,:)
-  REAL,ALLOCATABLE,SAVE :: fm_therm(:,:)
-!$OMP THREADPRIVATE(entr_therm)
-!$OMP THREADPRIVATE(fm_therm)
-!
-!   Lessivage:
-!   ----------
-!
-  REAL frac_impa(klon,klev)
-  REAL frac_nucl(klon,klev)
-!
-! Arguments necessaires pour les sources et puits de traceur
-!
-  REAL ftsol(klon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
-  REAL pctsrf(klon,nbsrf) ! Pourcentage de sol f(nature du sol)
-!======================================================================
-!
-  INTEGER i, k, kk
-  REAL,ALLOCATABLE,SAVE :: mfu(:,:)  ! flux de masse dans le panache montant
-  REAL,ALLOCATABLE,SAVE :: mfd(:,:)  ! flux de masse dans le panache descendant
-  REAL,ALLOCATABLE,SAVE :: en_u(:,:) ! flux entraine dans le panache montant
-  REAL,ALLOCATABLE,SAVE :: de_u(:,:) ! flux detraine dans le panache montant
-  REAL,ALLOCATABLE,SAVE :: en_d(:,:) ! flux entraine dans le panache descendant
-  REAL,ALLOCATABLE,SAVE :: de_d(:,:) ! flux detraine dans le panache descendant
-  REAL,ALLOCATABLE,SAVE :: coefh(:,:) ! flux detraine dans le panache descendant
-  
-  REAL,ALLOCATABLE,SAVE :: pyu1(:)
-  REAL,ALLOCATABLE,SAVE :: pyv1(:)
-  REAL,ALLOCATABLE,SAVE :: pftsol(:,:)
-  REAL,ALLOCATABLE,SAVE :: ppsrf(:,:)
-!$OMP THREADPRIVATE(mfu,mfd,en_u,de_u,en_d,de_d,coefh)
-!$OMP THREADPRIVATE(pyu1,pyv1,pftsol,ppsrf)
-
-
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: sh  
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: da
-  REAL,DIMENSION(:,:,:), ALLOCATABLE,SAVE   :: phi
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: mp
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: upwd
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: dnwd
-  
-  REAL, SAVE :: dtcum
-  INTEGER, SAVE:: iadvtr=0
-!$OMP THREADPRIVATE(dtcum,iadvtr)
-  REAL zmin,zmax
-  LOGICAL ok_sync
-  CHARACTER(len=12) :: nvar
-  logical, parameter :: lstokenc=.FALSE.
-!
-!======================================================================
-
-  iadvtr=iadvtr+1
-
-! Dans le meme vecteur on recombine le drag et les coeff d'echange
-  pcoefh_buf(:,1)      = cdragh(:)
-  pcoefh_buf(:,2:klev) = pcoefh(:,2:klev)
-  
-  ok_sync = .TRUE.
-
-! Initialization done only once
-!======================================================================
-  IF (iadvtr==1) THEN
-     ALLOCATE( t(klon,klev))
-     ALLOCATE( mfu(klon,klev))  
-     ALLOCATE( mfd(klon,klev))  
-     ALLOCATE( en_u(klon,klev)) 
-     ALLOCATE( de_u(klon,klev)) 
-     ALLOCATE( en_d(klon,klev)) 
-     ALLOCATE( de_d(klon,klev)) 
-     ALLOCATE( coefh(klon,klev)) 
-     ALLOCATE( entr_therm(klon,klev))
-     ALLOCATE( fm_therm(klon,klev))
-     ALLOCATE( pyu1(klon))
-     ALLOCATE( pyv1(klon))
-     ALLOCATE( pftsol(klon,nbsrf))
-     ALLOCATE( ppsrf(klon,nbsrf))
-     
-     ALLOCATE(sh(klon,klev)) 
-     ALLOCATE(da(klon,klev)) 
-     ALLOCATE(phi(klon,klev,klev)) 
-     ALLOCATE(mp(klon,klev)) 
-     ALLOCATE(upwd(klon,klev)) 
-     ALLOCATE(dnwd(klon,klev)) 
-
-     CALL initphysto('phystoke', dtime, dtime*istphy,dtime*istphy,physid)
-     
-     ! Write field phis and aire only once
-     CALL histwrite_phy(physid,lstokenc,"phis",itap,pphis)
-     CALL histwrite_phy(physid,lstokenc,"aire",itap,paire)
-     CALL histwrite_phy(physid,lstokenc,"longitudes",itap,rlon)
-     CALL histwrite_phy(physid,lstokenc,"latitudes",itap,rlat)
-
-  END IF
-  
-  
-! Set to zero cumulating fields
-!======================================================================
-  IF (MOD(iadvtr,istphy)==1.OR.istphy==1) THEN
-     WRITE(lunout,*)'reinitialisation des champs cumules a iadvtr=',iadvtr
-     mfu(:,:)=0.
-     mfd(:,:)=0.
-     en_u(:,:)=0.
-     de_u(:,:)=0.
-     en_d(:,:)=0.
-     de_d(:,:)=0.
-     coefh(:,:)=0.
-     t(:,:)=0.
-     fm_therm(:,:)=0.
-     entr_therm(:,:)=0.
-     pyv1(:)=0.
-     pyu1(:)=0.
-     pftsol(:,:)=0.
-     ppsrf(:,:)=0.
-     sh(:,:)=0.
-     da(:,:)=0.
-     phi(:,:,:)=0.
-     mp(:,:)=0.
-     upwd(:,:)=0.
-     dnwd(:,:)=0.
-     dtcum=0.
-  ENDIF
-  
-
-! Cumulate fields at each time step
-!======================================================================
-  DO k=1,klev
-     DO i=1,klon
-        mfu(i,k)=mfu(i,k)+pmfu(i,k)*pdtphys
-        mfd(i,k)=mfd(i,k)+pmfd(i,k)*pdtphys
-        en_u(i,k)=en_u(i,k)+pen_u(i,k)*pdtphys
-        de_u(i,k)=de_u(i,k)+pde_u(i,k)*pdtphys
-        en_d(i,k)=en_d(i,k)+pen_d(i,k)*pdtphys
-        de_d(i,k)=de_d(i,k)+pde_d(i,k)*pdtphys
-        coefh(i,k)=coefh(i,k)+pcoefh_buf(i,k)*pdtphys
-        t(i,k)=t(i,k)+pt(i,k)*pdtphys
-        fm_therm(i,k)=fm_therm(i,k)+pfm_therm(i,k)*pdtphys
-        entr_therm(i,k)=entr_therm(i,k)+pentr_therm(i,k)*pdtphys
-        sh(i,k) = sh(i,k) + psh(i,k)*pdtphys
-        da(i,k) = da(i,k) + pda(i,k)*pdtphys
-        mp(i,k) = mp(i,k) + pmp(i,k)*pdtphys
-        upwd(i,k) = upwd(i,k) + pupwd(i,k)*pdtphys
-        dnwd(i,k) = dnwd(i,k) + pdnwd(i,k)*pdtphys
-     ENDDO
-  ENDDO
-
-  DO kk=1,klev
-     DO k=1,klev
-        DO i=1,klon
-           phi(i,k,kk) = phi(i,k,kk) + pphi(i,k,kk)*pdtphys
-        END DO
-     END DO
-  END DO
-
-  DO i=1,klon
-     pyv1(i)=pyv1(i)+yv1(i)*pdtphys
-     pyu1(i)=pyu1(i)+yu1(i)*pdtphys
-  END DO
-  DO k=1,nbsrf
-     DO i=1,klon
-        pftsol(i,k)=pftsol(i,k)+ftsol(i,k)*pdtphys
-        ppsrf(i,k)=ppsrf(i,k)+pctsrf(i,k)*pdtphys
-     ENDDO
-  ENDDO
-  
-! Add time step to cumulated time
-  dtcum=dtcum+pdtphys
-  
-
-! Write fields to file, if it is time to do so
-!======================================================================
-  IF(MOD(iadvtr,istphy)==0) THEN 
-
-     ! normalize with time period
-     DO k=1,klev
-        DO i=1,klon
-           mfu(i,k)=mfu(i,k)/dtcum
-           mfd(i,k)=mfd(i,k)/dtcum
-           en_u(i,k)=en_u(i,k)/dtcum
-           de_u(i,k)=de_u(i,k)/dtcum
-           en_d(i,k)=en_d(i,k)/dtcum
-           de_d(i,k)=de_d(i,k)/dtcum
-           coefh(i,k)=coefh(i,k)/dtcum
-           t(i,k)=t(i,k)/dtcum	
-           fm_therm(i,k)=fm_therm(i,k)/dtcum
-           entr_therm(i,k)=entr_therm(i,k)/dtcum
-           sh(i,k)=sh(i,k)/dtcum
-           da(i,k)=da(i,k)/dtcum
-           mp(i,k)=mp(i,k)/dtcum
-           upwd(i,k)=upwd(i,k)/dtcum
-           dnwd(i,k)=dnwd(i,k)/dtcum
-        ENDDO
-     ENDDO
-     DO kk=1,klev
-        DO k=1,klev
-           DO i=1,klon
-              phi(i,k,kk) = phi(i,k,kk)/dtcum
-           END DO
-        END DO
-     END DO
-     DO i=1,klon
-        pyv1(i)=pyv1(i)/dtcum
-        pyu1(i)=pyu1(i)/dtcum
-     END DO
-     DO k=1,nbsrf
-        DO i=1,klon
-           pftsol(i,k)=pftsol(i,k)/dtcum
-           ppsrf(i,k)=ppsrf(i,k)/dtcum
-        ENDDO
-     ENDDO
-
-     ! write fields
-     CALL histwrite_phy(physid,lstokenc,"t",itap,t)
-     CALL histwrite_phy(physid,lstokenc,"mfu",itap,mfu)
-     CALL histwrite_phy(physid,lstokenc,"mfd",itap,mfd)
-     CALL histwrite_phy(physid,lstokenc,"en_u",itap,en_u)
-     CALL histwrite_phy(physid,lstokenc,"de_u",itap,de_u)
-     CALL histwrite_phy(physid,lstokenc,"en_d",itap,en_d)
-     CALL histwrite_phy(physid,lstokenc,"de_d",itap,de_d)
-     CALL histwrite_phy(physid,lstokenc,"coefh",itap,coefh)	
-     CALL histwrite_phy(physid,lstokenc,"fm_th",itap,fm_therm)
-     CALL histwrite_phy(physid,lstokenc,"en_th",itap,entr_therm)
-     CALL histwrite_phy(physid,lstokenc,"frac_impa",itap,frac_impa)
-     CALL histwrite_phy(physid,lstokenc,"frac_nucl",itap,frac_nucl)
-     CALL histwrite_phy(physid,lstokenc,"pyu1",itap,pyu1)
-     CALL histwrite_phy(physid,lstokenc,"pyv1",itap,pyv1)
-     CALL histwrite_phy(physid,lstokenc,"ftsol1",itap,pftsol(:,1))
-     CALL histwrite_phy(physid,lstokenc,"ftsol2",itap,pftsol(:,2))
-     CALL histwrite_phy(physid,lstokenc,"ftsol3",itap,pftsol(:,3))
-     CALL histwrite_phy(physid,lstokenc,"ftsol4",itap,pftsol(:,4))
-     CALL histwrite_phy(physid,lstokenc,"psrf1",itap,ppsrf(:,1))
-     CALL histwrite_phy(physid,lstokenc,"psrf2",itap,ppsrf(:,2))
-     CALL histwrite_phy(physid,lstokenc,"psrf3",itap,ppsrf(:,3))
-     CALL histwrite_phy(physid,lstokenc,"psrf4",itap,ppsrf(:,4))
-     CALL histwrite_phy(physid,lstokenc,"sh",itap,sh)
-     CALL histwrite_phy(physid,lstokenc,"da",itap,da)
-     CALL histwrite_phy(physid,lstokenc,"mp",itap,mp)
-     CALL histwrite_phy(physid,lstokenc,"upwd",itap,upwd)
-     CALL histwrite_phy(physid,lstokenc,"dnwd",itap,dnwd)
-
-
-! phi
-     DO k=1,klev
-        IF (k<10) THEN
-           WRITE(nvar,'(i1)') k
-        ELSE IF (k<100) THEN
-           WRITE(nvar,'(i2)') k
-        ELSE
-           WRITE(nvar,'(i3)') k
-        END IF
-        nvar='phi_lev'//trim(nvar)
-        
-        CALL histwrite_phy(physid,lstokenc,nvar,itap,phi(:,:,k))
-     END DO
-     
-     ! Syncronize file
-!$OMP MASTER
-     IF (ok_sync) CALL histsync(physid)
-!$OMP END MASTER
-     
-     
-     ! Calculate min and max values for some fields (coefficients de lessivage)
-     zmin=1e33
-     zmax=-1e33
-     DO k=1,klev
-        DO i=1,klon
-           zmax=MAX(zmax,frac_nucl(i,k))
-           zmin=MIN(zmin,frac_nucl(i,k))
-        ENDDO
-     ENDDO
-     WRITE(lunout,*)'------ coefs de lessivage (min et max) --------'
-     WRITE(lunout,*)'facteur de nucleation ',zmin,zmax
-     zmin=1e33
-     zmax=-1e33
-     DO k=1,klev
-        DO i=1,klon
-           zmax=MAX(zmax,frac_impa(i,k))
-           zmin=MIN(zmin,frac_impa(i,k))
-        ENDDO
-     ENDDO
-     WRITE(lunout,*)'facteur d impaction ',zmin,zmax
-     
-  ENDIF ! IF(MOD(iadvtr,istphy)==0)
-
-END SUBROUTINE phystokenc
Index: LMDZ5/trunk/libf/phylmd/phystokenc_mod.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/phystokenc_mod.F90	(revision 2343)
+++ LMDZ5/trunk/libf/phylmd/phystokenc_mod.F90	(revision 2343)
@@ -0,0 +1,387 @@
+!
+! $Id$
+!
+MODULE phystokenc_mod
+
+  IMPLICIT NONE
+
+  LOGICAL,SAVE :: offline
+!$OMP THREADPRIVATE(offline)
+  INTEGER,SAVE :: istphy
+!$OMP THREADPRIVATE(istphy)
+
+
+CONTAINS
+
+  SUBROUTINE init_phystokenc(offline_dyn,istphy_dyn)
+    IMPLICIT NONE
+    LOGICAL,INTENT(IN) :: offline_dyn
+    INTEGER,INTENT(IN) :: istphy_dyn
+
+    offline=offline_dyn
+    istphy=istphy_dyn
+
+  END SUBROUTINE init_phystokenc
+
+SUBROUTINE phystokenc (nlon,nlev,pdtphys,rlon,rlat, &
+     pt,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d, &
+     pfm_therm,pentr_therm, &
+     cdragh, pcoefh,yu1,yv1,ftsol,pctsrf, &
+     frac_impa,frac_nucl, &
+     pphis,paire,dtime,itap, &
+     psh, pda, pphi, pmp, pupwd, pdnwd)
+  
+  USE ioipsl
+  USE dimphy
+  USE infotrac_phy, ONLY : nqtot
+  USE iophy
+  USE indice_sol_mod
+  USE print_control_mod, ONLY: lunout
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+  
+  IMPLICIT NONE
+  
+!======================================================================
+! Auteur(s) FH
+! Objet: Ecriture des variables pour transport offline
+!
+!======================================================================
+
+! Arguments:
+!
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: psh   ! humidite specifique
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pda
+  REAL,DIMENSION(klon,klev,klev), INTENT(IN):: pphi
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pmp
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pupwd ! saturated updraft mass flux
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pdnwd ! saturated downdraft mass flux
+
+!   EN ENTREE:
+!   ==========
+!
+!   divers:
+!   -------
+!
+  INTEGER nlon ! nombre de points horizontaux
+  INTEGER nlev ! nombre de couches verticales
+  REAL pdtphys ! pas d'integration pour la physique (seconde)
+  INTEGER itap
+  INTEGER, SAVE :: physid
+!$OMP THREADPRIVATE(physid)
+
+!   convection:
+!   -----------
+!
+  REAL pmfu(klon,klev)  ! flux de masse dans le panache montant
+  REAL pmfd(klon,klev)  ! flux de masse dans le panache descendant
+  REAL pen_u(klon,klev) ! flux entraine dans le panache montant
+  REAL pde_u(klon,klev) ! flux detraine dans le panache montant
+  REAL pen_d(klon,klev) ! flux entraine dans le panache descendant
+  REAL pde_d(klon,klev) ! flux detraine dans le panache descendant
+  REAL pt(klon,klev)
+  REAL,ALLOCATABLE,SAVE :: t(:,:)
+!$OMP THREADPRIVATE(t)
+!
+  REAL rlon(klon), rlat(klon), dtime
+  REAL zx_tmp_3d(nbp_lon,nbp_lat,klev),zx_tmp_2d(nbp_lon,nbp_lat)
+
+!   Couche limite:
+!   --------------
+!
+  REAL cdragh(klon)          ! cdrag
+  REAL pcoefh(klon,klev)     ! coeff melange CL
+  REAL pcoefh_buf(klon,klev) ! coeff melange CL + cdrag
+  REAL yv1(klon)
+  REAL yu1(klon),pphis(klon),paire(klon)
+
+!   Les Thermiques : (Abderr 25 11 02)
+!   ---------------
+  REAL, INTENT(IN) ::  pfm_therm(klon,klev+1)
+  REAL pentr_therm(klon,klev)
+  
+  REAL,ALLOCATABLE,SAVE :: entr_therm(:,:)
+  REAL,ALLOCATABLE,SAVE :: fm_therm(:,:)
+!$OMP THREADPRIVATE(entr_therm)
+!$OMP THREADPRIVATE(fm_therm)
+!
+!   Lessivage:
+!   ----------
+!
+  REAL frac_impa(klon,klev)
+  REAL frac_nucl(klon,klev)
+!
+! Arguments necessaires pour les sources et puits de traceur
+!
+  REAL ftsol(klon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
+  REAL pctsrf(klon,nbsrf) ! Pourcentage de sol f(nature du sol)
+!======================================================================
+!
+  INTEGER i, k, kk
+  REAL,ALLOCATABLE,SAVE :: mfu(:,:)  ! flux de masse dans le panache montant
+  REAL,ALLOCATABLE,SAVE :: mfd(:,:)  ! flux de masse dans le panache descendant
+  REAL,ALLOCATABLE,SAVE :: en_u(:,:) ! flux entraine dans le panache montant
+  REAL,ALLOCATABLE,SAVE :: de_u(:,:) ! flux detraine dans le panache montant
+  REAL,ALLOCATABLE,SAVE :: en_d(:,:) ! flux entraine dans le panache descendant
+  REAL,ALLOCATABLE,SAVE :: de_d(:,:) ! flux detraine dans le panache descendant
+  REAL,ALLOCATABLE,SAVE :: coefh(:,:) ! flux detraine dans le panache descendant
+  
+  REAL,ALLOCATABLE,SAVE :: pyu1(:)
+  REAL,ALLOCATABLE,SAVE :: pyv1(:)
+  REAL,ALLOCATABLE,SAVE :: pftsol(:,:)
+  REAL,ALLOCATABLE,SAVE :: ppsrf(:,:)
+!$OMP THREADPRIVATE(mfu,mfd,en_u,de_u,en_d,de_d,coefh)
+!$OMP THREADPRIVATE(pyu1,pyv1,pftsol,ppsrf)
+
+
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: sh  
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: da
+  REAL,DIMENSION(:,:,:), ALLOCATABLE,SAVE   :: phi
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: mp
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: upwd
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: dnwd
+  
+  REAL, SAVE :: dtcum
+  INTEGER, SAVE:: iadvtr=0
+!$OMP THREADPRIVATE(dtcum,iadvtr)
+  REAL zmin,zmax
+  LOGICAL ok_sync
+  CHARACTER(len=12) :: nvar
+  logical, parameter :: lstokenc=.FALSE.
+!
+!======================================================================
+
+  iadvtr=iadvtr+1
+
+! Dans le meme vecteur on recombine le drag et les coeff d'echange
+  pcoefh_buf(:,1)      = cdragh(:)
+  pcoefh_buf(:,2:klev) = pcoefh(:,2:klev)
+  
+  ok_sync = .TRUE.
+
+! Initialization done only once
+!======================================================================
+  IF (iadvtr==1) THEN
+     ALLOCATE( t(klon,klev))
+     ALLOCATE( mfu(klon,klev))  
+     ALLOCATE( mfd(klon,klev))  
+     ALLOCATE( en_u(klon,klev)) 
+     ALLOCATE( de_u(klon,klev)) 
+     ALLOCATE( en_d(klon,klev)) 
+     ALLOCATE( de_d(klon,klev)) 
+     ALLOCATE( coefh(klon,klev)) 
+     ALLOCATE( entr_therm(klon,klev))
+     ALLOCATE( fm_therm(klon,klev))
+     ALLOCATE( pyu1(klon))
+     ALLOCATE( pyv1(klon))
+     ALLOCATE( pftsol(klon,nbsrf))
+     ALLOCATE( ppsrf(klon,nbsrf))
+     
+     ALLOCATE(sh(klon,klev)) 
+     ALLOCATE(da(klon,klev)) 
+     ALLOCATE(phi(klon,klev,klev)) 
+     ALLOCATE(mp(klon,klev)) 
+     ALLOCATE(upwd(klon,klev)) 
+     ALLOCATE(dnwd(klon,klev)) 
+
+     CALL initphysto('phystoke', dtime, dtime*istphy,dtime*istphy,physid)
+     
+     ! Write field phis and aire only once
+     CALL histwrite_phy(physid,lstokenc,"phis",itap,pphis)
+     CALL histwrite_phy(physid,lstokenc,"aire",itap,paire)
+     CALL histwrite_phy(physid,lstokenc,"longitudes",itap,rlon)
+     CALL histwrite_phy(physid,lstokenc,"latitudes",itap,rlat)
+
+  END IF
+  
+  
+! Set to zero cumulating fields
+!======================================================================
+  IF (MOD(iadvtr,istphy)==1.OR.istphy==1) THEN
+     WRITE(lunout,*)'reinitialisation des champs cumules a iadvtr=',iadvtr
+     mfu(:,:)=0.
+     mfd(:,:)=0.
+     en_u(:,:)=0.
+     de_u(:,:)=0.
+     en_d(:,:)=0.
+     de_d(:,:)=0.
+     coefh(:,:)=0.
+     t(:,:)=0.
+     fm_therm(:,:)=0.
+     entr_therm(:,:)=0.
+     pyv1(:)=0.
+     pyu1(:)=0.
+     pftsol(:,:)=0.
+     ppsrf(:,:)=0.
+     sh(:,:)=0.
+     da(:,:)=0.
+     phi(:,:,:)=0.
+     mp(:,:)=0.
+     upwd(:,:)=0.
+     dnwd(:,:)=0.
+     dtcum=0.
+  ENDIF
+  
+
+! Cumulate fields at each time step
+!======================================================================
+  DO k=1,klev
+     DO i=1,klon
+        mfu(i,k)=mfu(i,k)+pmfu(i,k)*pdtphys
+        mfd(i,k)=mfd(i,k)+pmfd(i,k)*pdtphys
+        en_u(i,k)=en_u(i,k)+pen_u(i,k)*pdtphys
+        de_u(i,k)=de_u(i,k)+pde_u(i,k)*pdtphys
+        en_d(i,k)=en_d(i,k)+pen_d(i,k)*pdtphys
+        de_d(i,k)=de_d(i,k)+pde_d(i,k)*pdtphys
+        coefh(i,k)=coefh(i,k)+pcoefh_buf(i,k)*pdtphys
+        t(i,k)=t(i,k)+pt(i,k)*pdtphys
+        fm_therm(i,k)=fm_therm(i,k)+pfm_therm(i,k)*pdtphys
+        entr_therm(i,k)=entr_therm(i,k)+pentr_therm(i,k)*pdtphys
+        sh(i,k) = sh(i,k) + psh(i,k)*pdtphys
+        da(i,k) = da(i,k) + pda(i,k)*pdtphys
+        mp(i,k) = mp(i,k) + pmp(i,k)*pdtphys
+        upwd(i,k) = upwd(i,k) + pupwd(i,k)*pdtphys
+        dnwd(i,k) = dnwd(i,k) + pdnwd(i,k)*pdtphys
+     ENDDO
+  ENDDO
+
+  DO kk=1,klev
+     DO k=1,klev
+        DO i=1,klon
+           phi(i,k,kk) = phi(i,k,kk) + pphi(i,k,kk)*pdtphys
+        END DO
+     END DO
+  END DO
+
+  DO i=1,klon
+     pyv1(i)=pyv1(i)+yv1(i)*pdtphys
+     pyu1(i)=pyu1(i)+yu1(i)*pdtphys
+  END DO
+  DO k=1,nbsrf
+     DO i=1,klon
+        pftsol(i,k)=pftsol(i,k)+ftsol(i,k)*pdtphys
+        ppsrf(i,k)=ppsrf(i,k)+pctsrf(i,k)*pdtphys
+     ENDDO
+  ENDDO
+  
+! Add time step to cumulated time
+  dtcum=dtcum+pdtphys
+  
+
+! Write fields to file, if it is time to do so
+!======================================================================
+  IF(MOD(iadvtr,istphy)==0) THEN 
+
+     ! normalize with time period
+     DO k=1,klev
+        DO i=1,klon
+           mfu(i,k)=mfu(i,k)/dtcum
+           mfd(i,k)=mfd(i,k)/dtcum
+           en_u(i,k)=en_u(i,k)/dtcum
+           de_u(i,k)=de_u(i,k)/dtcum
+           en_d(i,k)=en_d(i,k)/dtcum
+           de_d(i,k)=de_d(i,k)/dtcum
+           coefh(i,k)=coefh(i,k)/dtcum
+           t(i,k)=t(i,k)/dtcum	
+           fm_therm(i,k)=fm_therm(i,k)/dtcum
+           entr_therm(i,k)=entr_therm(i,k)/dtcum
+           sh(i,k)=sh(i,k)/dtcum
+           da(i,k)=da(i,k)/dtcum
+           mp(i,k)=mp(i,k)/dtcum
+           upwd(i,k)=upwd(i,k)/dtcum
+           dnwd(i,k)=dnwd(i,k)/dtcum
+        ENDDO
+     ENDDO
+     DO kk=1,klev
+        DO k=1,klev
+           DO i=1,klon
+              phi(i,k,kk) = phi(i,k,kk)/dtcum
+           END DO
+        END DO
+     END DO
+     DO i=1,klon
+        pyv1(i)=pyv1(i)/dtcum
+        pyu1(i)=pyu1(i)/dtcum
+     END DO
+     DO k=1,nbsrf
+        DO i=1,klon
+           pftsol(i,k)=pftsol(i,k)/dtcum
+           ppsrf(i,k)=ppsrf(i,k)/dtcum
+        ENDDO
+     ENDDO
+
+     ! write fields
+     CALL histwrite_phy(physid,lstokenc,"t",itap,t)
+     CALL histwrite_phy(physid,lstokenc,"mfu",itap,mfu)
+     CALL histwrite_phy(physid,lstokenc,"mfd",itap,mfd)
+     CALL histwrite_phy(physid,lstokenc,"en_u",itap,en_u)
+     CALL histwrite_phy(physid,lstokenc,"de_u",itap,de_u)
+     CALL histwrite_phy(physid,lstokenc,"en_d",itap,en_d)
+     CALL histwrite_phy(physid,lstokenc,"de_d",itap,de_d)
+     CALL histwrite_phy(physid,lstokenc,"coefh",itap,coefh)	
+     CALL histwrite_phy(physid,lstokenc,"fm_th",itap,fm_therm)
+     CALL histwrite_phy(physid,lstokenc,"en_th",itap,entr_therm)
+     CALL histwrite_phy(physid,lstokenc,"frac_impa",itap,frac_impa)
+     CALL histwrite_phy(physid,lstokenc,"frac_nucl",itap,frac_nucl)
+     CALL histwrite_phy(physid,lstokenc,"pyu1",itap,pyu1)
+     CALL histwrite_phy(physid,lstokenc,"pyv1",itap,pyv1)
+     CALL histwrite_phy(physid,lstokenc,"ftsol1",itap,pftsol(:,1))
+     CALL histwrite_phy(physid,lstokenc,"ftsol2",itap,pftsol(:,2))
+     CALL histwrite_phy(physid,lstokenc,"ftsol3",itap,pftsol(:,3))
+     CALL histwrite_phy(physid,lstokenc,"ftsol4",itap,pftsol(:,4))
+     CALL histwrite_phy(physid,lstokenc,"psrf1",itap,ppsrf(:,1))
+     CALL histwrite_phy(physid,lstokenc,"psrf2",itap,ppsrf(:,2))
+     CALL histwrite_phy(physid,lstokenc,"psrf3",itap,ppsrf(:,3))
+     CALL histwrite_phy(physid,lstokenc,"psrf4",itap,ppsrf(:,4))
+     CALL histwrite_phy(physid,lstokenc,"sh",itap,sh)
+     CALL histwrite_phy(physid,lstokenc,"da",itap,da)
+     CALL histwrite_phy(physid,lstokenc,"mp",itap,mp)
+     CALL histwrite_phy(physid,lstokenc,"upwd",itap,upwd)
+     CALL histwrite_phy(physid,lstokenc,"dnwd",itap,dnwd)
+
+
+! phi
+     DO k=1,klev
+        IF (k<10) THEN
+           WRITE(nvar,'(i1)') k
+        ELSE IF (k<100) THEN
+           WRITE(nvar,'(i2)') k
+        ELSE
+           WRITE(nvar,'(i3)') k
+        END IF
+        nvar='phi_lev'//trim(nvar)
+        
+        CALL histwrite_phy(physid,lstokenc,nvar,itap,phi(:,:,k))
+     END DO
+     
+     ! Syncronize file
+!$OMP MASTER
+     IF (ok_sync) CALL histsync(physid)
+!$OMP END MASTER
+     
+     
+     ! Calculate min and max values for some fields (coefficients de lessivage)
+     zmin=1e33
+     zmax=-1e33
+     DO k=1,klev
+        DO i=1,klon
+           zmax=MAX(zmax,frac_nucl(i,k))
+           zmin=MIN(zmin,frac_nucl(i,k))
+        ENDDO
+     ENDDO
+     WRITE(lunout,*)'------ coefs de lessivage (min et max) --------'
+     WRITE(lunout,*)'facteur de nucleation ',zmin,zmax
+     zmin=1e33
+     zmax=-1e33
+     DO k=1,klev
+        DO i=1,klon
+           zmax=MAX(zmax,frac_impa(i,k))
+           zmin=MIN(zmin,frac_impa(i,k))
+        ENDDO
+     ENDDO
+     WRITE(lunout,*)'facteur d impaction ',zmin,zmax
+     
+  ENDIF ! IF(MOD(iadvtr,istphy)==0)
+
+END SUBROUTINE phystokenc
+
+END MODULE phystokenc_mod
Index: LMDZ5/trunk/libf/phylmd/read_pstoke.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/read_pstoke.F90	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/read_pstoke.F90	(revision 2343)
@@ -21,39 +21,38 @@
   USE control_mod
   USE indice_sol_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
 
   IMPLICIT NONE
 
   include "netcdf.inc"
-  include "dimensions.h"
-  include "paramet.h"
-  include "comconst.h"
-  include "comgeom.h"
-  include "temps.h"
-  include "ener.h"
-  include "logic.h"
-  include "description.h"
-  include "serre.h"
-  ! ccc#include "dimphy.h"
 
   INTEGER klono, klevo, imo, jmo
-  PARAMETER (imo=iim/2, jmo=(jjm+1)/2)
-  PARAMETER (klono=(jmo-1)*imo+2, klevo=llm)
-  REAL phisfi(klono)
-  REAL phisfi2(imo, jmo+1), airefi2(imo, jmo+1)
-
-  REAL mfu(klono, klevo), mfd(klono, klevo)
-  REAL en_u(klono, klevo), de_u(klono, klevo)
-  REAL en_d(klono, klevo), de_d(klono, klevo)
-  REAL coefh(klono, klevo)
-  REAL fm_therm(klono, klevo), en_therm(klono, klevo)
-
-  REAL mfu2(imo, jmo+1, klevo), mfd2(imo, jmo+1, klevo)
-  REAL en_u2(imo, jmo+1, klevo), de_u2(imo, jmo+1, klevo)
-  REAL en_d2(imo, jmo+1, klevo), de_d2(imo, jmo+1, klevo)
-  REAL coefh2(imo, jmo+1, klevo)
-  REAL fm_therm2(imo, jmo+1, klevo)
-  REAL en_therm2(imo, jmo+1, klevo)
-
-  REAL pl(klevo)
+!  PARAMETER (imo=iim/2, jmo=(jjm+1)/2)
+!  PARAMETER (klono=(jmo-1)*imo+2, klevo=llm)
+  REAL :: phisfi(((nbp_lat/2)-1)*(nbp_lon/2)+2) !phisfi(klono)
+  REAL,ALLOCATABLE :: phisfi2(:,:) !phisfi2(imo,jmo+1)
+  REAL,ALLOCATABLE :: airefi2(:,:) !airefi2(imo, jmo+1)
+
+  REAL :: mfu(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) ! mfu(klono, klevo)
+  REAL :: mfd(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) ! mfd(klono, klevo)
+  REAL :: en_u(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !en_u(klono, klevo)
+  REAL :: de_u(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !de_u(klono, klevo)
+  REAL :: en_d(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !en_d(klono, klevo)
+  REAL :: de_d(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !de_d(klono, klevo)
+  REAL :: coefh(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !coefh(klono, klevo)
+  REAL :: fm_therm(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !fm_therm(klono, klevo)
+  REAL :: en_therm(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !en_therm(klono, klevo)
+
+  REAL,ALLOCATABLE :: mfu2(:,:,:) !mfu2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: mfd2(:,:,:) !mfd2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: en_u2(:,:,:) !en_u2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: de_u2(:,:,:) !de_u2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: en_d2(:,:,:) !en_d2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: de_d2(:,:,:) !de_d2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: coefh2(:,:,:) !coefh2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: fm_therm2(:,:,:) !fm_therm2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: en_therm2(:,:,:) !en_therm2(imo, jmo+1, klevo)
+
+  REAL,ALLOCATABLE :: pl(:) !pl(klevo)
   INTEGER irec
   INTEGER xid, yid, zid, tid
@@ -61,5 +60,5 @@
   INTEGER ncrec, ncklono, ncklevo, ncim, ncjm
 
-  REAL airefi(klono)
+  REAL :: airefi(((nbp_lat/2)-1)*(nbp_lon/2)+2) !airefi(klono)
   CHARACTER *20 namedim
 
@@ -69,43 +68,75 @@
 
 
-  REAL frac_impa(klono, klevo), frac_nucl(klono, klevo)
-  REAL frac_impa2(imo, jmo+1, klevo), frac_nucl2(imo, jmo+1, klevo)
-  REAL pyu1(klono), pyv1(klono)
-  REAL pyu12(imo, jmo+1), pyv12(imo, jmo+1)
-  REAL ftsol(klono, nbsrf)
-  REAL psrf(klono, nbsrf)
-  REAL ftsol1(klono), ftsol2(klono), ftsol3(klono), ftsol4(klono)
-  REAL psrf1(klono), psrf2(klono), psrf3(klono), psrf4(klono)
-  REAL ftsol12(imo, jmo+1), ftsol22(imo, jmo+1), ftsol32(imo, jmo+1), &
-    ftsol42(imo, jmo+1)
-  REAL psrf12(imo, jmo+1), psrf22(imo, jmo+1), psrf32(imo, jmo+1), &
-    psrf42(imo, jmo+1)
-  REAL t(klono, klevo)
-  REAL t2(imo, jmo+1, klevo)
-  INTEGER ncidp
-  SAVE ncidp
-  INTEGER varidt
-  INTEGER varidmfu, varidmfd, varidps, varidenu, variddeu
-  INTEGER varidend, varidded, varidch, varidfi, varidfn
-  INTEGER varidfmth, varidenth
-  INTEGER varidyu1, varidyv1, varidpl, varidai, varididvt
-  INTEGER varidfts1, varidfts2, varidfts3, varidfts4
-  INTEGER varidpsr1, varidpsr2, varidpsr3, varidpsr4
-  SAVE varidmfu, varidmfd, varidps, varidenu, variddeu
-  SAVE varidend, varidded, varidch, varidfi, varidfn
-  SAVE varidfmth, varidenth
-  SAVE varidyu1, varidyv1, varidpl, varidai, varididvt
-  SAVE varidfts1, varidfts2, varidfts3, varidfts4
-  SAVE varidpsr1, varidpsr2, varidpsr3, varidpsr4
-  SAVE varidt
+  REAL :: frac_impa(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !frac_impa(klono, klevo)
+  REAL :: frac_nucl(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !frac_nucl(klono, klevo)
+  REAL,ALLOCATABLE :: frac_impa2(:,:,:) !frac_impa2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: frac_nucl2(:,:,:) !frac_nucl2(imo, jmo+1, klevo)
+  REAL :: pyu1(((nbp_lat/2)-1)*(nbp_lon/2)+2) !pyu1(klono)
+  REAL :: pyv1(((nbp_lat/2)-1)*(nbp_lon/2)+2) !pyv1(klono)
+  REAL,ALLOCATABLE :: pyu12(:,:), pyv12(:,:) !pyu12(imo, jmo+1), pyv12(imo, jmo+1)
+  REAL :: ftsol(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !ftsol(klono, nbsrf)
+  REAL :: psrf(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !psrf(klono, nbsrf)
+  REAL,ALLOCATABLE :: ftsol1(:),ftsol2(:) !ftsol1(klono), ftsol2(klono)
+  REAL,ALLOCATABLE :: ftsol3(:),ftsol4(:) !ftsol3(klono), ftsol4(klono)
+  REAL,ALLOCATABLE :: psrf1(:), psrf2(:) !psrf1(klono), psrf2(klono)
+  REAL,ALLOCATABLE :: psrf3(:), psrf4(:) !psrf3(klono), psrf4(klono)
+  REAL,ALLOCATABLE :: ftsol12(:,:) !ftsol12(imo, jmo+1)
+  REAL,ALLOCATABLE :: ftsol22(:,:) !ftsol22(imo, jmo+1)
+  REAL,ALLOCATABLE :: ftsol32(:,:) !ftsol32(imo, jmo+1)
+  REAL,ALLOCATABLE :: ftsol42(:,:) !ftsol42(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf12(:,:) !psrf12(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf22(:,:) !psrf22(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf32(:,:) !psrf32(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf42(:,:) !psrf42(imo, jmo+1)
+  REAL :: t(((nbp_lon/2)-1)*(nbp_lat/2)+2,nbp_lev) !t(klono, klevo)
+  REAL,ALLOCATABLE :: t2(:,:,:) !t2(imo, jmo+1, klevo)
+  INTEGER,SAVE :: ncidp
+  INTEGER,SAVE :: varidt
+  INTEGER,SAVE :: varidmfu, varidmfd, varidps, varidenu, variddeu
+  INTEGER,SAVE :: varidend, varidded, varidch, varidfi, varidfn
+  INTEGER,SAVE :: varidfmth, varidenth
+  INTEGER,SAVE :: varidyu1, varidyv1, varidpl, varidai, varididvt
+  INTEGER,SAVE :: varidfts1, varidfts2, varidfts3, varidfts4
+  INTEGER,SAVE :: varidpsr1, varidpsr2, varidpsr3, varidpsr4
 
   INTEGER l, i
   INTEGER start(4), count(4), status
   REAL rcode
-  LOGICAL first
-  SAVE first
-  DATA first/.TRUE./
-
-
+  LOGICAL,SAVE :: first=.TRUE.
+
+  ! Allocate arrays
+  imo=nbp_lon/2
+  jmo=nbp_lat/2
+  klono=(jmo-1)*imo+2
+  klevo=nbp_lev
+  
+  ALLOCATE(phisfi2(imo,jmo+1))
+  ALLOCATE(airefi2(imo, jmo+1))
+  ALLOCATE(mfu2(imo, jmo+1, klevo))
+  ALLOCATE(mfd2(imo, jmo+1, klevo))
+  ALLOCATE(en_u2(imo, jmo+1, klevo))
+  ALLOCATE(de_u2(imo, jmo+1, klevo))
+  ALLOCATE(en_d2(imo, jmo+1, klevo))
+  ALLOCATE(de_d2(imo, jmo+1, klevo))
+  ALLOCATE(coefh2(imo, jmo+1, klevo))
+  ALLOCATE(fm_therm2(imo, jmo+1, klevo))
+  ALLOCATE(en_therm2(imo, jmo+1, klevo))
+  ALLOCATE(pl(klevo))
+  ALLOCATE(frac_impa2(imo, jmo+1, klevo))
+  ALLOCATE(frac_nucl2(imo, jmo+1, klevo))
+  ALLOCATE(pyu12(imo, jmo+1), pyv12(imo, jmo+1))
+  ALLOCATE(ftsol1(klono), ftsol2(klono))
+  ALLOCATE(ftsol3(klono), ftsol4(klono))
+  ALLOCATE(psrf1(klono), psrf2(klono))
+  ALLOCATE(psrf3(klono), psrf4(klono))
+  ALLOCATE(ftsol12(imo, jmo+1))
+  ALLOCATE(ftsol22(imo, jmo+1))
+  ALLOCATE(ftsol32(imo, jmo+1))
+  ALLOCATE(ftsol42(imo, jmo+1))
+  ALLOCATE(psrf12(imo, jmo+1))
+  ALLOCATE(psrf22(imo, jmo+1))
+  ALLOCATE(psrf32(imo, jmo+1))
+  ALLOCATE(psrf42(imo, jmo+1))
+  ALLOCATE(t2(imo, jmo+1, klevo))
 
   ! ---------------------------------------------
Index: LMDZ5/trunk/libf/phylmd/read_pstoke0.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/read_pstoke0.F90	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/read_pstoke0.F90	(revision 2343)
@@ -20,44 +20,43 @@
   USE control_mod
   USE indice_sol_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
 
   IMPLICIT NONE
 
   include "netcdf.inc"
-  include "dimensions.h"
-  include "paramet.h"
-  include "comconst.h"
-  include "comgeom.h"
-  include "temps.h"
-  include "ener.h"
-  include "logic.h"
-  include "description.h"
-  include "serre.h"
-  ! ccc#include "dimphy.h"
 
   INTEGER kon, kev, zkon, zkev
-  PARAMETER (kon=iim*(jjm-1)+2, kev=llm)
-  REAL phisfi(kon)
-  REAL phisfi2(iim, jjm+1), airefi2(iim, jjm+1)
-
-  REAL mfu(kon, kev), mfd(kon, kev)
-  REAL en_u(kon, kev), de_u(kon, kev)
-  REAL en_d(kon, kev), de_d(kon, kev)
-  REAL coefh(kon, kev)
+!  PARAMETER (kon=iim*(jjm-1)+2, kev=llm)
+  REAL :: phisfi(nbp_lon*(nbp_lat-2)+2) !phisfi(kon)
+  REAL,ALLOCATABLE :: phisfi2(:,:) !phisfi2(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: airefi2(:,:) !airefi2(nbp_lon, nbp_lat)
+
+  REAL :: mfu(nbp_lon*(nbp_lat-2)+2,nbp_lev) !mfu(kon, kev)
+  REAL :: mfd(nbp_lon*(nbp_lat-2)+2,nbp_lev) !mfd(kon, kev)
+  REAL :: en_u(nbp_lon*(nbp_lat-2)+2,nbp_lev) !en_u(kon, kev)
+  REAL :: de_u(nbp_lon*(nbp_lat-2)+2,nbp_lev) !de_u(kon, kev)
+  REAL :: en_d(nbp_lon*(nbp_lat-2)+2,nbp_lev) !en_d(kon, kev)
+  REAL :: de_d(nbp_lon*(nbp_lat-2)+2,nbp_lev) !de_d(kon, kev)
+  REAL :: coefh(nbp_lon*(nbp_lat-2)+2,nbp_lev) !coefh(kon, kev)
 
   ! abd 25 11 02
   ! Thermiques
-  REAL fm_therm(kon, kev), en_therm(kon, kev)
-  REAL t(kon, kev)
-
-  REAL mfu2(iim, jjm+1, kev), mfd2(iim, jjm+1, kev)
-  REAL en_u2(iim, jjm+1, kev), de_u2(iim, jjm+1, kev)
-  REAL en_d2(iim, jjm+1, kev), de_d2(iim, jjm+1, kev)
-  REAL coefh2(iim, jjm+1, kev)
-  REAL t2(iim, jjm+1, kev)
+  REAL :: fm_therm(nbp_lon*(nbp_lat-2)+2,nbp_lev) !fm_therm(kon, kev)
+  REAL :: en_therm(nbp_lon*(nbp_lat-2)+2,nbp_lev) !en_therm(kon, kev)
+  REAL :: t(nbp_lon*(nbp_lat-2)+2,nbp_lev) !t(kon, kev)
+
+  REAL,ALLOCATABLE :: mfu2(:,:,:) !mfu2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: mfd2(:,:,:) !mfd2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: en_u2(:,:,:) !en_u2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: de_u2(:,:,:) !de_u2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: en_d2(:,:,:) !en_d2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: de_d2(:,:,:) !de_d2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: coefh2(:,:,:) !coefh2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: t2(:,:,:) !t2(nbp_lon, nbp_lat, kev)
   ! Thermiques
-  REAL fm_therm2(iim, jjm+1, kev)
-  REAL en_therm2(iim, jjm+1, kev)
-
-  REAL pl(kev)
+  REAL,ALLOCATABLE :: fm_therm2(:,:,:) !fm_therm2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: en_therm2(:,:,:) !en_therm2(nbp_lon, nbp_lat, kev)
+
+  REAL,ALLOCATABLE :: pl(:) !pl(kev)
   INTEGER irec
   INTEGER xid, yid, zid, tid
@@ -65,5 +64,5 @@
   INTEGER ncrec, nckon, nckev, ncim, ncjm
 
-  REAL airefi(kon)
+  REAL :: airefi(nbp_lon*(nbp_lat-2)+2) !airefi(kon)
   CHARACTER *20 namedim
 
@@ -72,44 +71,73 @@
   ! dim de phis??
 
-  REAL frac_impa(kon, kev), frac_nucl(kon, kev)
-  REAL frac_impa2(iim, jjm+1, kev), frac_nucl2(iim, jjm+1, kev)
-  REAL pyu1(kon), pyv1(kon)
-  REAL pyu12(iim, jjm+1), pyv12(iim, jjm+1)
-  REAL ftsol(kon, nbsrf)
-  REAL psrf(kon, nbsrf)
-  REAL ftsol1(kon), ftsol2(kon), ftsol3(kon), ftsol4(kon)
-  REAL psrf1(kon), psrf2(kon), psrf3(kon), psrf4(kon)
-  REAL ftsol12(iim, jjm+1), ftsol22(iim, jjm+1), ftsol32(iim, jjm+1), &
-    ftsol42(iim, jjm+1)
-  REAL psrf12(iim, jjm+1), psrf22(iim, jjm+1), psrf32(iim, jjm+1), &
-    psrf42(iim, jjm+1)
-
-  INTEGER ncidp
-  SAVE ncidp
-  INTEGER varidmfu, varidmfd, varidps, varidenu, variddeu
-  INTEGER varidt
-  INTEGER varidend, varidded, varidch, varidfi, varidfn
+  REAL :: frac_impa(nbp_lon*(nbp_lat-2)+2,nbp_lev) !frac_impa(kon, kev)
+  REAL :: frac_nucl(nbp_lon*(nbp_lat-2)+2,nbp_lev) !frac_nucl(kon, kev)
+  REAL,ALLOCATABLE :: frac_impa2(:,:,:) !frac_impa2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: frac_nucl2(:,:,:) !frac_nucl2(nbp_lon, nbp_lat, kev)
+  REAL :: pyu1(nbp_lon*(nbp_lat-2)+2) !pyu1(kon)
+  REAL :: pyv1(nbp_lon*(nbp_lat-2)+2) !pyv1(kon)
+  REAL,ALLOCATABLE :: pyu12(:,:), pyv12(:,:) !pyu12(nbp_lon, nbp_lat), pyv12(nbp_lon, nbp_lat)
+  REAL :: ftsol(nbp_lon*(nbp_lat-2)+2,nbp_lev) !ftsol(kon, nbsrf)
+  REAL :: psrf(nbp_lon*(nbp_lat-2)+2,nbp_lev) !psrf(kon, nbsrf)
+  REAL,ALLOCATABLE :: ftsol1(:),ftsol2(:) !ftsol1(kon), ftsol2(kon)
+  REAL,ALLOCATABLE :: ftsol3(:),ftsol4(:) !ftsol3(kon), ftsol4(kon)
+  REAL,ALLOCATABLE :: psrf1(:), psrf2(:) !psrf1(kon), psrf2(kon)
+  REAL,ALLOCATABLE :: psrf3(:), psrf4(:) !psrf3(kon), psrf4(kon)
+  REAL,ALLOCATABLE :: ftsol12(:,:) !ftsol12(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: ftsol22(:,:) !ftsol22(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: ftsol32(:,:) !ftsol32(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: ftsol42(:,:) !ftsol42(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf12(:,:) !psrf12(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf22(:,:) !psrf22(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf32(:,:) !psrf32(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf42(:,:) !psrf42(nbp_lon, nbp_lat)
+
+  INTEGER,SAVE :: ncidp
+  INTEGER,SAVE :: varidmfu, varidmfd, varidps, varidenu, variddeu
+  INTEGER,SAVE :: varidt
+  INTEGER,SAVE :: varidend, varidded, varidch, varidfi, varidfn
   ! therm
-  INTEGER varidfmth, varidenth
-  INTEGER varidyu1, varidyv1, varidpl, varidai, varididvt
-  INTEGER varidfts1, varidfts2, varidfts3, varidfts4
-  INTEGER varidpsr1, varidpsr2, varidpsr3, varidpsr4
-  SAVE varidmfu, varidmfd, varidps, varidenu, variddeu
-  SAVE varidt
-  SAVE varidend, varidded, varidch, varidfi, varidfn
-  ! therm
-  SAVE varidfmth, varidenth
-  SAVE varidyu1, varidyv1, varidpl, varidai, varididvt
-  SAVE varidfts1, varidfts2, varidfts3, varidfts4
-  SAVE varidpsr1, varidpsr2, varidpsr3, varidpsr4
+  INTEGER,SAVE :: varidfmth, varidenth
+  INTEGER,SAVE :: varidyu1, varidyv1, varidpl, varidai, varididvt
+  INTEGER,SAVE :: varidfts1, varidfts2, varidfts3, varidfts4
+  INTEGER,SAVE :: varidpsr1, varidpsr2, varidpsr3, varidpsr4
 
   INTEGER l, i
   INTEGER start(4), count(4), status
   REAL rcode
-  LOGICAL first
-  SAVE first
-  DATA first/.TRUE./
-
-
+  LOGICAL,SAVE :: first=.TRUE.
+
+  ! Allocate arrays
+  kon=nbp_lon*(nbp_lat-2)+2
+  kev=nbp_lev
+
+  ALLOCATE(phisfi2(nbp_lon, nbp_lat))
+  ALLOCATE(airefi2(nbp_lon, nbp_lat))
+  ALLOCATE(mfu2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(mfd2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(en_u2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(de_u2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(en_d2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(de_d2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(coefh2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(t2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(fm_therm2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(en_therm2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(pl(kev))
+  ALLOCATE(frac_impa2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(frac_nucl2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(pyu12(nbp_lon, nbp_lat), pyv12(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol1(kon), ftsol2(kon))
+  ALLOCATE(ftsol3(kon), ftsol4(kon))
+  ALLOCATE(psrf1(kon), psrf2(kon))
+  ALLOCATE(psrf3(kon), psrf4(kon))
+  ALLOCATE(ftsol12(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol22(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol32(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol42(nbp_lon, nbp_lat))
+  ALLOCATE(psrf12(nbp_lon, nbp_lat))
+  ALLOCATE(psrf22(nbp_lon, nbp_lat))
+  ALLOCATE(psrf32(nbp_lon, nbp_lat))
+  ALLOCATE(psrf42(nbp_lon, nbp_lat))
 
   ! ---------------------------------------------
@@ -248,5 +276,5 @@
     status = nf_get_vara_real(ncidp, varidps, start, count, phisfi2)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, phisfi2, phisfi)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, phisfi2, phisfi)
 
     ! **** Aires des mails aux sol ************************************
@@ -257,5 +285,5 @@
     status = nf_get_vara_real(ncidp, varidai, start, count, airefi2)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, airefi2, airefi)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, airefi2, airefi)
   ELSE
 
@@ -288,5 +316,5 @@
     status = nf_get_vara_real(ncidp, varidt, start, count, t2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, t2, t)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, t2, t)
 
     ! **** Flux pour la convection (Tiedtk)
@@ -298,5 +326,5 @@
     status = nf_get_vara_real(ncidp, varidmfu, start, count, mfu2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, mfu2, mfu)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, mfu2, mfu)
 
     ! mfd
@@ -306,5 +334,5 @@
     status = nf_get_vara_real(ncidp, varidmfd, start, count, mfd2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, mfd2, mfd)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, mfd2, mfd)
 
     ! en_u
@@ -314,5 +342,5 @@
     status = nf_get_vara_real(ncidp, varidenu, start, count, en_u2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, en_u2, en_u)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, en_u2, en_u)
 
     ! de_u
@@ -322,5 +350,5 @@
     status = nf_get_vara_real(ncidp, variddeu, start, count, de_u2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, de_u2, de_u)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, de_u2, de_u)
 
     ! en_d
@@ -330,5 +358,5 @@
     status = nf_get_vara_real(ncidp, varidend, start, count, en_d2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, en_d2, en_d)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, en_d2, en_d)
 
     ! de_d
@@ -338,5 +366,5 @@
     status = nf_get_vara_real(ncidp, varidded, start, count, de_d2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, de_d2, de_d)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, de_d2, de_d)
 
     ! **** Coefficient de mellange turbulent
@@ -349,5 +377,5 @@
     status = nf_get_vara_real(ncidp, varidch, start, count, coefh2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, coefh2, coefh)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, coefh2, coefh)
     ! call dump2d(iip1,jjp1,coefh2(1,2),'COEFH2READ   ')
     ! call dump2d(iim ,jjm ,coefh (2,2),'COEFH2READ   ')
@@ -362,5 +390,5 @@
     status = nf_get_vara_real(ncidp, varidfmth, start, count, fm_therm2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, fm_therm2, fm_therm)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, fm_therm2, fm_therm)
     PRINT *, 'LECTURE de en_therm a irec =', irec
 #ifdef NC_DOUBLE
@@ -369,5 +397,5 @@
     status = nf_get_vara_real(ncidp, varidenth, start, count, en_therm2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, en_therm2, en_therm)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, en_therm2, en_therm)
 
     ! **** Coefficients de lessivage
@@ -379,5 +407,5 @@
     status = nf_get_vara_real(ncidp, varidfi, start, count, frac_impa2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, frac_impa2, frac_impa)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, frac_impa2, frac_impa)
 
     ! frac_nucl
@@ -388,5 +416,5 @@
     status = nf_get_vara_real(ncidp, varidfn, start, count, frac_nucl2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, frac_nucl2, frac_nucl)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, frac_nucl2, frac_nucl)
 
     ! **** Vents aux sol ********************************************
@@ -404,5 +432,5 @@
     status = nf_get_vara_real(ncidp, varidyu1, start, count, pyu12)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, pyu12, pyu1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, pyu12, pyu1)
 
     ! pyv1
@@ -413,5 +441,5 @@
     status = nf_get_vara_real(ncidp, varidyv1, start, count, pyv12)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, pyv12, pyv1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, pyv12, pyv1)
 
     ! **** Temerature au sol ********************************************
@@ -423,5 +451,5 @@
     status = nf_get_vara_real(ncidp, varidfts1, start, count, ftsol12)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol12, ftsol1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol12, ftsol1)
 
     ! ftsol2
@@ -432,5 +460,5 @@
     status = nf_get_vara_real(ncidp, varidfts2, start, count, ftsol22)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol22, ftsol2)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol22, ftsol2)
 
     ! ftsol3
@@ -441,5 +469,5 @@
     status = nf_get_vara_real(ncidp, varidfts3, start, count, ftsol32)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol32, ftsol3)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol32, ftsol3)
 
     ! ftsol4
@@ -449,5 +477,5 @@
     status = nf_get_vara_real(ncidp, varidfts4, start, count, ftsol42)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol42, ftsol4)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol42, ftsol4)
 
     ! **** Nature sol ********************************************
@@ -459,5 +487,5 @@
 #endif
     ! call dump2d(iip1-1,jjm+1,psrf12,'PSRF1NC')
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf12, psrf1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf12, psrf1)
 
     ! psrf2
@@ -468,5 +496,5 @@
 #endif
     ! call dump2d(iip1-1,jjm+1,psrf22,'PSRF2NC')
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf22, psrf2)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf22, psrf2)
 
     ! psrf3
@@ -476,5 +504,5 @@
     status = nf_get_vara_real(ncidp, varidpsr3, start, count, psrf32)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf32, psrf3)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf32, psrf3)
 
     ! psrf4
@@ -484,5 +512,5 @@
     status = nf_get_vara_real(ncidp, varidpsr4, start, count, psrf42)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf42, psrf4)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf42, psrf4)
 
     DO i = 1, kon
Index: LMDZ5/trunk/libf/phylmd/time_phylmdz_mod.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/time_phylmdz_mod.F90	(revision 2343)
+++ LMDZ5/trunk/libf/phylmd/time_phylmdz_mod.F90	(revision 2343)
@@ -0,0 +1,69 @@
+!
+! $Id: $
+!
+MODULE time_phylmdz_mod
+
+    IMPLICIT NONE
+    REAL,SAVE    :: pdtphys     ! physics time step (s)
+!$OMP THREADPRIVATE(pdtphys)
+    INTEGER,SAVE :: day_step_phy    ! number of physical steps per day
+!$OMP THREADPRIVATE(day_step_phy)
+    INTEGER,SAVE :: ndays       ! number of days to run
+!$OMP THREADPRIVATE(ndays)
+    INTEGER,SAVE :: annee_ref   ! reference year from the origin
+!$OMP THREADPRIVATE(annee_ref)
+    INTEGER,SAVE :: day_ref     ! reference year of the origin
+!$OMP THREADPRIVATE(day_ref)
+    INTEGER,SAVE :: day_ini     ! initial day of the run starting from 1st january of annee_ref
+!$OMP THREADPRIVATE(day_ini)
+    INTEGER,SAVE :: day_end     ! final day of the run starting from 1st january of annee_ref
+!$OMP THREADPRIVATE(day_end)
+    REAL,SAVE    :: start_time  ! starting time from the begining of the initial day
+!$OMP THREADPRIVATE(start_time)
+    INTEGER,SAVE :: raz_date
+!$OMP THREADPRIVATE(raz_date)
+
+    INTEGER,SAVE :: itau_phy     ! number of physiq iteration from origin
+!$OMP THREADPRIVATE(itau_phy)
+    INTEGER,SAVE :: itaufin      ! final iteration 
+!$OMP THREADPRIVATE(itaufin)
+    REAL,SAVE    :: current_time ! current elapsed time (s) from the begining of the run
+!$OMP THREADPRIVATE(current_time)
+    
+
+CONTAINS
+
+  SUBROUTINE init_time(annee_ref_, day_ref_, day_ini_, start_time_, &
+                       ndays_, pdtphys_)
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+  IMPLICIT NONE
+  INCLUDE 'YOMCST.h'
+    INTEGER, INTENT(IN) :: annee_ref_  
+    INTEGER, INTENT(IN) :: day_ref_    
+    INTEGER, INTENT(IN) :: day_ini_    
+    REAL,    INTENT(IN) :: start_time_ 
+    INTEGER, INTENT(IN) :: ndays_      
+    REAL,    INTENT(IN) :: pdtphys_    
+    
+    annee_ref    = annee_ref_
+    day_ref      = day_ref_
+    day_ini      = day_ini_
+    start_time   = start_time_
+    ndays        = ndays_
+    pdtphys      = pdtphys_
+    
+    ! Initialize module variable not inherited from dynamics
+    day_step_phy = NINT(rday/pdtphys)
+    day_end  = day_ini + ndays
+  
+    raz_date = 0
+    CALL getin_p('raz_date', raz_date)
+
+    current_time=0
+    
+!    CALL phys_cal_init(annee_ref,day_ref)
+    
+  END SUBROUTINE init_time
+
+END MODULE time_phylmdz_mod      
+
Index: LMDZ5/trunk/libf/phylmd/write_histday_seri.h
===================================================================
--- LMDZ5/trunk/libf/phylmd/write_histday_seri.h	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/write_histday_seri.h	(revision 2343)
@@ -7,5 +7,5 @@
 !
       ndex2d = 0
-      itau_w = itau_phy + itap + start_time * day_step / iphysiq
+      itau_w = itau_phy + itap + start_time * day_step_phy
 !
 ! Champs 2D:
Index: LMDZ5/trunk/libf/phylmd/write_paramLMDZ_phy.h
===================================================================
--- LMDZ5/trunk/libf/phylmd/write_paramLMDZ_phy.h	(revision 2342)
+++ LMDZ5/trunk/libf/phylmd/write_paramLMDZ_phy.h	(revision 2343)
@@ -27,5 +27,5 @@
 !
       ndex2d = 0
-      itau_w = itau_phy + itap + int(start_time * day_step / iphysiq)
+      itau_w = itau_phy + itap + int(start_time * day_step_phy)
 !
 ! Variables globales
