Index: /LMDZ4/branches/LMDZ4V5.0-dev/arch/arch-PW6_VARGAS.fcm
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/arch/arch-PW6_VARGAS.fcm	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/arch/arch-PW6_VARGAS.fcm	(revision 1357)
@@ -5,5 +5,5 @@
 %FPP_FLAGS           -P
 %FPP_DEF             NC_DOUBLE BLAS SGEMV=DGEMV SGEMM=DGEMM
-%BASE_FFLAGS         -qautodbl=dbl4 -qxlf90=autodealloc
+%BASE_FFLAGS         -qautodbl=dbl4 -qxlf90=autodealloc -qmaxmem=-1 -qzerosize
 %PROD_FFLAGS         -O5
 %DEV_FFLAGS          -O2 -qfullpath -qinitauto=7FBFFFFF -qfloat=nans -qflttrap=overflow:zerodivide:invalid:enable -qsigtrap
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/initdynav.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/initdynav.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/initdynav.F	(revision 1357)
@@ -2,6 +2,5 @@
 ! $Id$
 !
-      subroutine initdynav(infile,day0,anne0,tstep,t_ops,t_wrt
-     .                     ,fileid)
+      subroutine initdynav(day0,anne0,tstep,t_ops,t_wrt)
 
 #ifdef CPP_IOIPSL
@@ -9,5 +8,6 @@
 #endif
        USE infotrac, ONLY : nqtot, ttext
-
+      use com_io_dyn_mod, only : histaveid,histvaveid,histuaveid,       &
+     &        dynhistave_file,dynhistvave_file,dynhistuave_file
       implicit none
 
@@ -30,6 +30,4 @@
 C      t_wrt: frequence d'ecriture sur le fichier
 C
-C   Sortie:
-C      fileid: ID du fichier netcdf cree
 C
 C   L. Fairhead, LMD, 03/99
@@ -52,8 +50,6 @@
 C   Arguments
 C
-      character*(*) infile
       integer day0, anne0
       real tstep, t_ops, t_wrt
-      integer fileid
 
 #ifdef CPP_IOIPSL
@@ -61,9 +57,9 @@
 C   Variables locales
 C
-      integer thoriid, zvertiid
       integer tau0
       real zjulian
       integer iq
       real rlong(iip1,jjp1), rlat(iip1,jjp1)
+      integer uhoriid, vhoriid, thoriid, zvertiid
       integer ii,jj
       integer zan, dayref
@@ -88,13 +84,45 @@
       enddo
        
-      call histbeg(infile, iip1, rlong(:,1), jjp1, rlat(1,:),
+! Creation de 3 fichiers pour les differentes grilles horizontales
+! Restriction de IOIPSL: seulement 2 coordonnees dans le meme fichier
+! Grille Scalaire       
+      call histbeg(dynhistave_file, iip1, rlong(:,1), jjp1, rlat(1,:),
      .             1, iip1, 1, jjp1,
-     .             tau0, zjulian, tstep, thoriid, fileid)
-
+     .             tau0, zjulian, tstep, thoriid,histaveid)
+
+C  Creation du fichier histoire pour les grilles en V et U (oblige pour l'instant,
+C  IOIPSL ne permet pas de grilles avec des nombres de point differents dans
+C  un meme fichier)
+! Grille V
+      do jj = 1, jjm
+        do ii = 1, iip1
+          rlong(ii,jj) = rlonv(ii) * 180. / pi
+          rlat(ii,jj) = rlatv(jj) * 180. / pi
+        enddo
+      enddo
+
+      call histbeg(dynhistvave_file, iip1, rlong(:,1), jjm, rlat(1,:),
+     .             1, iip1, 1, jjm,
+     .             tau0, zjulian, tstep, vhoriid,histvaveid)
+! Grille U
+      do jj = 1, jjp1
+        do ii = 1, iip1
+          rlong(ii,jj) = rlonu(ii) * 180. / pi
+          rlat(ii,jj) = rlatu(jj) * 180. / pi
+        enddo
+      enddo
+
+      call histbeg(dynhistuave_file, iip1, rlong(:,1),jjp1, rlat(1,:),
+     .             1, iip1, 1, jjp1,
+     .             tau0, zjulian, tstep, uhoriid,histuaveid)
 C
 C  Appel a histvert pour la grille verticale
 C
-      call histvert(fileid, 'sigss', 'Niveaux sigma','Pa',
-     .              llm, nivsigs, zvertiid)
+      call histvert(histaveid,'presnivs','Niveaux Pression
+     &     approximatifs','mb',llm, presnivs/100., zvertiid,'down')
+      call histvert(histuaveid,'presnivs','Niveaux Pression
+     &     approximatifs','mb',llm, presnivs/100., zvertiid,'down')
+      call histvert(histvaveid,'presnivs','Niveaux Pression
+     &     approximatifs','mb',llm, presnivs/100., zvertiid,'down')
 C
 C  Appels a histdef pour la definition des variables a sauvegarder
@@ -102,14 +130,13 @@
 C  Vents U
 C
-      write(6,*)'inithistave',tstep
-      call histdef(fileid, 'u', 'vents u scalaires moyennes',
-     .             'm/s', iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
-     .             32, 'ave(X)', t_ops, t_wrt)
-
-C
+!      write(6,*)'inithistave',tstep
+      call histdef(histuaveid, 'u', 'vent u moyen ',
+     .             'm/s', iip1, jjp1, uhoriid, llm, 1, llm, zvertiid,
+     .             32, 'ave(X)', t_ops, t_wrt)
+
 C  Vents V
 C
-      call histdef(fileid, 'v', 'vents v scalaires moyennes',
-     .             'm/s', iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+      call histdef(histvaveid, 'v', 'vent v moyen',
+     .             'm/s', iip1, jjm, vhoriid, llm, 1, llm, zvertiid,
      .             32, 'ave(X)', t_ops, t_wrt)
 
@@ -117,5 +144,5 @@
 C  Temperature
 C
-      call histdef(fileid, 'temp', 'temperature moyennee', 'K',
+      call histdef(histaveid, 'temp', 'temperature moyenne', 'K',
      .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
      .             32, 'ave(X)', t_ops, t_wrt)
@@ -123,13 +150,11 @@
 C  Temperature potentielle
 C
-      call histdef(fileid, 'theta', 'temperature potentielle', 'K',
-     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
-     .             32, 'ave(X)', t_ops, t_wrt)
-
-
+      call histdef(histaveid, 'theta', 'temperature potentielle', 'K',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+     .             32, 'ave(X)', t_ops, t_wrt)
 C
 C  Geopotentiel
 C
-      call histdef(fileid, 'phi', 'geopotentiel moyenne', '-',
+      call histdef(histaveid, 'phi', 'geopotentiel moyen', '-',
      .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
      .             32, 'ave(X)', t_ops, t_wrt)
@@ -137,31 +162,33 @@
 C  Traceurs
 C
-        DO iq=1,nqtot
-          call histdef(fileid, ttext(iq), ttext(iq), '-',
-     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
-     .             32, 'ave(X)', t_ops, t_wrt)
-        enddo
+!        DO iq=1,nqtot
+!          call histdef(histaveid, ttext(iq), ttext(iq), '-',
+!     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+!     .             32, 'ave(X)', t_ops, t_wrt)
+!        enddo
 C
 C  Masse
 C
-      call histdef(fileid, 'masse', 'masse', 'kg',
+      call histdef(histaveid, 'masse', 'masse', 'kg',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+     .             32, 'ave(X)', t_ops, t_wrt)
+C
+C  Pression au sol
+C
+      call histdef(histaveid, 'ps', 'pression naturelle au sol', 'Pa',
      .             iip1, jjp1, thoriid, 1, 1, 1, -99,
      .             32, 'ave(X)', t_ops, t_wrt)
 C
-C  Pression au sol
-C
-      call histdef(fileid, 'ps', 'pression naturelle au sol', 'Pa',
-     .             iip1, jjp1, thoriid, 1, 1, 1, -99,
-     .             32, 'ave(X)', t_ops, t_wrt)
-C
-C  Pression au sol
-C
-      call histdef(fileid, 'phis', 'geopotentiel au sol', '-',
-     .             iip1, jjp1, thoriid, 1, 1, 1, -99,
-     .             32, 'ave(X)', t_ops, t_wrt)
-C
+C  Geopotentiel au sol
+C
+!      call histdef(histaveid, 'phis', 'geopotentiel au sol', '-',
+!     .             iip1, jjp1, thoriid, 1, 1, 1, -99,
+!     .             32, 'ave(X)', t_ops, t_wrt)
+!C
 C  Fin
 C
-      call histend(fileid)
+      call histend(histaveid)
+      call histend(histuaveid)
+      call histend(histvaveid)
 #else
 ! tell the user this routine should be run with ioipsl
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/inithist.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/inithist.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/inithist.F	(revision 1357)
@@ -2,6 +2,5 @@
 ! $Id$
 !
-      subroutine inithist(infile,day0,anne0,tstep,t_ops,t_wrt,fileid,
-     .                    filevid)
+      subroutine inithist(day0,anne0,tstep,t_ops,t_wrt)
 
 #ifdef CPP_IOIPSL
@@ -9,4 +8,6 @@
 #endif
        USE infotrac, ONLY : nqtot, ttext
+       use com_io_dyn_mod, only : histid,histvid,histuid,               &
+     &                        dynhist_file,dynhistv_file,dynhistu_file
 
       implicit none
@@ -31,7 +32,4 @@
 C      nq: nombre de traceurs
 C
-C   Sortie:
-C      fileid: ID du fichier netcdf cree
-C      filevid:ID du fichier netcdf pour la grille v
 C
 C   L. Fairhead, LMD, 03/99
@@ -54,8 +52,6 @@
 C   Arguments
 C
-      character*(*) infile
       integer day0, anne0
       real tstep, t_ops, t_wrt
-      integer fileid, filevid
 
 #ifdef CPP_IOIPSL
@@ -83,4 +79,8 @@
       tau0 = itau_dyn
       
+! -------------------------------------------------------------
+! Creation des 3 fichiers pour les grilles horizontales U,V,Scal
+! -------------------------------------------------------------
+!Grille U      
       do jj = 1, jjp1
         do ii = 1, iip1
@@ -90,12 +90,9 @@
       enddo
        
-      call histbeg(infile, iip1, rlong(:,1), jjp1, rlat(1,:),
+      call histbeg(dynhistu_file, iip1, rlong(:,1), jjp1, rlat(1,:),
      .             1, iip1, 1, jjp1,
-     .             tau0, zjulian, tstep, uhoriid, fileid)
-C
-C  Creation du fichier histoire pour la grille en V (oblige pour l'instant,
-C  IOIPSL ne permet pas de grilles avec des nombres de point differents dans 
-C  un meme fichier)
+     .             tau0, zjulian, tstep, uhoriid, histuid)
 
+! Grille V
       do jj = 1, jjm
         do ii = 1, iip1
@@ -105,10 +102,9 @@
       enddo
 
-      call histbeg('dyn_histv.nc', iip1, rlong(:,1), jjm, rlat(1,:),
+      call histbeg(dynhistv_file, iip1, rlong(:,1), jjm, rlat(1,:),
      .             1, iip1, 1, jjm,
-     .             tau0, zjulian, tstep, vhoriid, filevid)
-C
-C  Appel a histhori pour rajouter les autres grilles horizontales
-C
+     .             tau0, zjulian, tstep, vhoriid, histvid)
+
+!Grille Scalaire
       do jj = 1, jjp1
         do ii = 1, iip1
@@ -118,20 +114,24 @@
       enddo
 
-      call histhori(fileid, iip1, rlong, jjp1, rlat, 'scalar',
-     .              'Grille points scalaires', thoriid)
+      call histbeg(dynhist_file, iip1, rlong(:,1), jjp1, rlat(1,:),
+     .             1, iip1, 1, jjp1,
+     .             tau0, zjulian, tstep, thoriid, histid)
+! -------------------------------------------------------------
+C  Appel a histvert pour la grille verticale
+! -------------------------------------------------------------
+      call histvert(histid, 'presnivs', 'Niveaux pression','mb',
+     .              llm, presnivs/100., zvertiid,'down')
+      call histvert(histvid, 'presnivs', 'Niveaux pression','mb',
+     .              llm, presnivs/100., zvertiid,'down')
+      call histvert(histuid, 'presnivs', 'Niveaux pression','mb',
+     .              llm, presnivs/100., zvertiid,'down')
 C
-C  Appel a histvert pour la grille verticale
-C
-      call histvert(fileid, 'sig_s', 'Niveaux sigma','-',
-     .              llm, nivsigs, zvertiid)
-C Pour le fichier V
-      call histvert(filevid, 'sig_s', 'Niveaux sigma','-',
-     .              llm, nivsigs, zvertiid)
-C
+! -------------------------------------------------------------
 C  Appels a histdef pour la definition des variables a sauvegarder
+! -------------------------------------------------------------
 C
 C  Vents U
 C
-      call histdef(fileid, 'ucov', 'vents u covariants', 'm/s',
+      call histdef(histuid, 'u', 'vent u', 'm/s',
      .             iip1, jjp1, uhoriid, llm, 1, llm, zvertiid,
      .             32, 'inst(X)', t_ops, t_wrt)
@@ -139,5 +139,5 @@
 C  Vents V
 C
-      call histdef(filevid, 'vcov', 'vents v covariants', 'm/s',
+      call histdef(histvid, 'v', 'vent v', 'm/s',
      .             iip1, jjm, vhoriid, llm, 1, llm, zvertiid,
      .             32, 'inst(X)', t_ops, t_wrt)
@@ -146,5 +146,5 @@
 C  Temperature potentielle
 C
-      call histdef(fileid, 'teta', 'temperature potentielle', '-',
+      call histdef(histid, 'teta', 'temperature potentielle', '-',
      .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
      .             32, 'inst(X)', t_ops, t_wrt)
@@ -152,5 +152,5 @@
 C  Geopotentiel
 C
-      call histdef(fileid, 'phi', 'geopotentiel instantane', '-',
+      call histdef(histid, 'phi', 'geopotentiel', '-',
      .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
      .             32, 'inst(X)', t_ops, t_wrt)
@@ -158,32 +158,34 @@
 C  Traceurs
 C
-        DO iq=1,nqtot
-          call histdef(fileid, ttext(iq),  ttext(iq), '-',
-     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
-     .             32, 'inst(X)', t_ops, t_wrt)
-        enddo
-C
+!
+!        DO iq=1,nqtot
+!          call histdef(histid, ttext(iq),  ttext(iq), '-',
+!     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+!     .             32, 'inst(X)', t_ops, t_wrt)
+!        enddo
+!C
 C  Masse
 C
-      call histdef(fileid, 'masse', 'masse', 'kg',
-     .             iip1, jjp1, thoriid, 1, 1, 1, -99,
+      call histdef(histid, 'masse', 'masse', 'kg',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
      .             32, 'inst(X)', t_ops, t_wrt)
 C
 C  Pression au sol
 C
-      call histdef(fileid, 'ps', 'pression naturelle au sol', 'Pa',
+      call histdef(histid, 'ps', 'pression naturelle au sol', 'Pa',
      .             iip1, jjp1, thoriid, 1, 1, 1, -99,
      .             32, 'inst(X)', t_ops, t_wrt)
 C
-C  Pression au sol
-C
-      call histdef(fileid, 'phis', 'geopotentiel au sol', '-',
-     .             iip1, jjp1, thoriid, 1, 1, 1, -99,
-     .             32, 'inst(X)', t_ops, t_wrt)
-C
+C  Geopotentiel au sol
+!C
+!      call histdef(histid, 'phis', 'geopotentiel au sol', '-',
+!     .             iip1, jjp1, thoriid, 1, 1, 1, -99,
+!     .             32, 'inst(X)', t_ops, t_wrt)
+!C
 C  Fin
 C
-      call histend(fileid)
-      call histend(filevid)
+      call histend(histid)
+      call histend(histuid)
+      call histend(histvid)
 #else
 ! tell the user this routine should be run with ioipsl
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/writedynav.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/writedynav.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/writedynav.F	(revision 1357)
@@ -2,6 +2,6 @@
 ! $Id$
 !
-      subroutine writedynav( histid, time, vcov, 
-     ,                          ucov,teta,ppk,phi,q,masse,ps,phis)
+      subroutine writedynav(time, vcov, 
+     ,                ucov,teta,ppk,phi,q,masse,ps,phis)
 
 #ifdef CPP_IOIPSL
@@ -9,4 +9,5 @@
 #endif
       USE infotrac, ONLY : nqtot, ttext
+      use com_io_dyn_mod, only : histaveid,histvaveid,histuaveid
       implicit none
 
@@ -17,5 +18,4 @@
 C
 C   Entree:
-C      histid: ID du fichier histoire
 C      time: temps de l'ecriture
 C      vcov: vents v covariants
@@ -29,6 +29,4 @@
 C      
 C
-C   Sortie:
-C      fileid: ID du fichier netcdf cree
 C
 C   L. Fairhead, LMD, 03/99
@@ -53,7 +51,6 @@
 C
 
-      INTEGER histid
       REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) 
-      REAL teta(ip1jmp1*llm),phi(ip1jmp1,llm),ppk(ip1jmp1*llm)                  
+      REAL teta(ip1jmp1*llm),phi(ip1jmp1,llm),ppk(ip1jmp1*llm)     
       REAL ps(ip1jmp1),masse(ip1jmp1,llm)                   
       REAL phis(ip1jmp1)                  
@@ -66,6 +63,6 @@
 C   Variables locales
 C
-      integer ndex2d(iip1*jjp1),ndex3d(iip1*jjp1*llm),iq, ii, ll
-      real us(ip1jmp1*llm), vs(ip1jmp1*llm)
+      integer ndex2d(ip1jmp1),ndexu(ip1jmp1*llm),ndexv(ip1jm*llm)
+      INTEGER iq, ii, ll
       real tm(ip1jmp1*llm)
       REAL vnat(ip1jm,llm),unat(ip1jmp1,llm) 
@@ -75,9 +72,8 @@
 C  Initialisations
 C
-      ndex3d = 0
+      ndexu = 0
+      ndexv = 0
       ndex2d = 0
       ok_sync = .TRUE.
-      us = 999.999
-      vs = 999.999
       tm = 999.999
       vnat = 999.999
@@ -91,20 +87,18 @@
 C  Appels a histwrite pour l'ecriture des variables a sauvegarder
 C
-C  Vents U scalaire
+C  Vents U 
 C
-      call gr_u_scal(llm, unat, us)
-      call histwrite(histid, 'u', itau_w, us, 
-     .               iip1*jjp1*llm, ndex3d)
+      call histwrite(histuaveid, 'u', itau_w, unat, 
+     .               iip1*jjp1*llm, ndexu)
 C
-C  Vents V scalaire
+C  Vents V
 C
-      call gr_v_scal(llm, vnat, vs)
-      call histwrite(histid, 'v', itau_w, vs, 
-     .               iip1*jjp1*llm, ndex3d)
+      call histwrite(histvaveid, 'v', itau_w, vnat, 
+     .               iip1*jjm*llm, ndexv)
 C
 C  Temperature potentielle moyennee
 C
-      call histwrite(histid, 'theta', itau_w, teta, 
-     .                iip1*jjp1*llm, ndex3d)
+      call histwrite(histaveid, 'theta', itau_w, teta, 
+     .                iip1*jjp1*llm, ndexu)
 C
 C  Temperature moyennee
@@ -113,34 +107,39 @@
         tm(ii) = teta(ii) * ppk(ii)/cpp
       enddo
-      call histwrite(histid, 'temp', itau_w, tm, 
-     .                iip1*jjp1*llm, ndex3d)
+      call histwrite(histaveid, 'temp', itau_w, tm, 
+     .                iip1*jjp1*llm, ndexu)
 C
 C  Geopotentiel
 C
-      call histwrite(histid, 'phi', itau_w, phi, 
-     .                iip1*jjp1*llm, ndex3d)
+      call histwrite(histaveid, 'phi', itau_w, phi, 
+     .                iip1*jjp1*llm, ndexu)
 C
 C  Traceurs
 C
-        DO iq=1,nqtot
-          call histwrite(histid, ttext(iq), itau_w, q(:,:,iq), 
-     .                   iip1*jjp1*llm, ndex3d)
-        enddo
+!        DO iq=1,nqtot
+!          call histwrite(histaveid, ttext(iq), itau_w, q(:,:,iq), 
+!     .                   iip1*jjp1*llm, ndexu)
+!        enddo
 C
 C  Masse
 C
-       call histwrite(histid, 'masse', itau_w, masse, iip1*jjp1, ndex2d)
+       call histwrite(histaveid, 'masse', itau_w, masse, 
+     $                   iip1*jjp1*llm, ndexu)
 C
 C  Pression au sol
 C
-       call histwrite(histid, 'ps', itau_w, ps, iip1*jjp1, ndex2d)
+       call histwrite(histaveid, 'ps', itau_w, ps, iip1*jjp1, ndex2d)
 C
 C  Geopotentiel au sol
 C
-       call histwrite(histid, 'phis', itau_w, phis, iip1*jjp1, ndex2d)
+!       call histwrite(histaveid,'phis',itau_w, phis,iip1*jjp1, ndex2d)
 C
 C  Fin
 C
-      if (ok_sync) call histsync(histid)
+      if (ok_sync) then
+          call histsync(histaveid)
+          call histsync(histvaveid)
+          call histsync(histuaveid)
+      ENDIF
 
 #else
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/writehist.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/writehist.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/bibio/writehist.F	(revision 1357)
@@ -2,6 +2,5 @@
 ! $Id$
 !
-      subroutine writehist( histid, histvid, time, vcov, 
-     ,                          ucov,teta,phi,q,masse,ps,phis)
+      subroutine writehist(time,vcov,ucov,teta,phi,q,masse,ps,phis)
 
 #ifdef CPP_IOIPSL
@@ -9,4 +8,5 @@
 #endif
       USE infotrac, ONLY : nqtot, ttext
+      use com_io_dyn_mod, only : histid,histvid,histuid
       implicit none
 
@@ -17,6 +17,4 @@
 C
 C   Entree:
-C      histid: ID du fichier histoire
-C      histvid:ID du fichier histoire pour les vents V (appele a disparaitre)
 C      time: temps de l'ecriture
 C      vcov: vents v covariants
@@ -29,7 +27,4 @@
 C      phis : geopotentiel au sol
 C      
-C
-C   Sortie:
-C      fileid: ID du fichier netcdf cree
 C
 C   L. Fairhead, LMD, 03/99
@@ -54,5 +49,4 @@
 C
 
-      INTEGER histid, histvid
       REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) 
       REAL teta(ip1jmp1,llm),phi(ip1jmp1,llm)                   
@@ -71,4 +65,6 @@
       logical ok_sync
       integer itau_w
+      REAL vnat(ip1jm,llm),unat(ip1jmp1,llm)
+
 C
 C  Initialisations
@@ -79,4 +75,6 @@
       ok_sync =.TRUE.
       itau_w = itau_dyn + time
+!  Passage aux composantes naturelles du vent
+      call covnat(llm, ucov, vcov, unat, vnat)
 C
 C  Appels a histwrite pour l'ecriture des variables a sauvegarder
@@ -84,11 +82,10 @@
 C  Vents U
 C
-      call histwrite(histid, 'ucov', itau_w, ucov, 
+      call histwrite(histuid, 'u', itau_w, unat, 
      .               iip1*jjp1*llm, ndexu)
-
 C
 C  Vents V
 C
-      call histwrite(histvid, 'vcov', itau_w, vcov, 
+      call histwrite(histvid, 'v', itau_w, vnat, 
      .               iip1*jjm*llm, ndexv)
 
@@ -106,12 +103,12 @@
 C  Traceurs
 C
-        DO iq=1,nqtot
-          call histwrite(histid, ttext(iq), itau_w, q(:,:,iq), 
-     .                   iip1*jjp1*llm, ndexu)
-        enddo
-C
+!        DO iq=1,nqtot
+!          call histwrite(histid, ttext(iq), itau_w, q(:,:,iq), 
+!     .                   iip1*jjp1*llm, ndexu)
+!        enddo
+!C
 C  Masse
 C
-      call histwrite(histid, 'masse', itau_w, masse, iip1*jjp1, ndex2d)
+      call histwrite(histid,'masse',itau_w, masse,iip1*jjp1*llm,ndexu)
 C
 C  Pression au sol
@@ -121,5 +118,5 @@
 C  Geopotentiel au sol
 C
-      call histwrite(histid, 'phis', itau_w, phis, iip1*jjp1, ndex2d)
+!      call histwrite(histid, 'phis', itau_w, phis, iip1*jjp1, ndex2d)
 C
 C  Fin
@@ -128,4 +125,5 @@
         call histsync(histid)
         call histsync(histvid)
+        call histsync(histuid)
       endif
 #else
Index: DZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/com_io_dyn.h
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/com_io_dyn.h	(revision 1356)
+++ 	(revision )
@@ -1,5 +1,0 @@
-!
-! $Header$
-!
-      integer histid, histvid, histaveid
-      common/com_io_dyn/histid, histvid, histaveid
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/com_io_dyn_mod.F90
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/com_io_dyn_mod.F90	(revision 1357)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/com_io_dyn_mod.F90	(revision 1357)
@@ -0,0 +1,31 @@
+!
+! $Id $
+!
+module com_io_dyn_mod
+
+  implicit none 
+
+! Names of various files for outputs (in the dynamics)
+  ! to store instantaneous values:
+  character(len=18),parameter :: dynhist_file="dyn_hist.nc" ! on scalar grid
+  character(len=18),parameter :: dynhistv_file="dyn_histv.nc" ! on v grid
+  character(len=18),parameter :: dynhistu_file="dyn_histu.nc" ! on u grid
+
+  ! to store averaged values:
+  character(len=18),parameter :: dynhistave_file="dyn_hist_ave.nc"
+  character(len=18),parameter :: dynhistvave_file="dyn_histv_ave.nc"
+  character(len=18),parameter :: dynhistuave_file="dyn_histu_ave.nc"
+  
+! Ids of various files for outputs (in the dynamics)
+
+  ! instantaneous (these are set by inithist.F)
+  integer :: histid
+  integer :: histvid
+  integer :: histuid
+  
+  ! averages (these are set by initdynav.F)
+  integer :: histaveid
+  integer :: histvaveid
+  integer :: histuaveid
+  
+end module com_io_dyn_mod
Index: DZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/control.h
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/control.h	(revision 1356)
+++ 	(revision )
@@ -1,29 +1,0 @@
-!
-! $Header$
-!
-!
-!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
-!                 veillez à n'utiliser que des ! pour les commentaires
-!                 et à bien positionner les & des lignes de continuation 
-!                 (les placer en colonne 6 et en colonne 73)
-!
-!-----------------------------------------------------------------------
-! INCLUDE 'control.h'
-
-      COMMON/control/nday,day_step,                                     &
-     &              iperiod,iapp_tracvl,iconser,iecri,idissip,iphysiq , &
-     &              periodav,iecrimoy,dayref,anneeref,                  &
-     &              raz_date,offline,ip_ebil_dyn,config_inca,           &
-     &              planet_type,output_grads_dyn,ok_dynzon
-
-      INTEGER   nday,day_step,iperiod,iapp_tracvl,iconser,iecri,        &
-     &          idissip,iphysiq,iecrimoy,dayref,anneeref, raz_date      &
-     &          ,ip_ebil_dyn
-      REAL periodav
-      LOGICAL offline
-      CHARACTER (len=4) :: config_inca
-      CHARACTER(len=10) :: planet_type ! planet type ('earth','mars',...)
-      LOGICAL :: output_grads_dyn ! output dynamics diagnostics in
-                                  ! binary grads file 'dyn.dat' (y/n)
-      LOGICAL :: ok_dynzon
-!-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/control_mod.F90
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/control_mod.F90	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/control_mod.F90	(revision 1357)
@@ -1,4 +1,4 @@
 !
-! $Id$
+! $Id $
 !
 
@@ -14,7 +14,14 @@
   INTEGER :: iconser,iecri,idissip,iphysiq,iecrimoy
   INTEGER :: dayref,anneeref, raz_date, ip_ebil_dyn
-  LOGICAL :: offline, output_grads_dyn, ok_dynzon
+  LOGICAL :: offline
   CHARACTER (len=4)  :: config_inca
-  CHARACTER (len=10) :: planet_type
+  CHARACTER (len=10) :: planet_type ! planet type ('earth','mars',...)
+  LOGICAL output_grads_dyn ! output dynamics diagnostics in
+                           ! binary grads file 'dyn.dat' (y/n)
+  LOGICAL ok_dynzon  ! output zonal transports in dynzon.nc file
+  LOGICAL ok_dyn_ins ! output instantaneous values of fields
+                     ! in the dynamics in NetCDF files dyn_hist*nc
+  LOGICAL ok_dyn_ave ! output averaged values of fields in the dynamics
+                     ! in NetCDF files dyn_hist*ave.nc
 
 END MODULE
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/gcm.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/gcm.F	(revision 1357)
@@ -73,9 +73,11 @@
 #include "description.h"
 #include "serre.h"
-#include "com_io_dyn.h"
+!#include "com_io_dyn.h"
 #include "iniprint.h"
 #include "tracstoke.h"
+#ifdef INCA
+! Only INCA needs these informations (from the Earth's physics)
 #include "indicesol.h"
-
+#endif
       INTEGER         longcles
       PARAMETER     ( longcles = 20 )
@@ -319,33 +321,33 @@
      .  ' restart ne correspondent pas a celles lues dans '
         write(lunout,*)' gcm.def'
-	write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
-	write(lunout,*)' day_ref=',day_ref," dayref=",dayref
-	write(lunout,*)' Pas de remise a zero'
+        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
+        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
+        write(lunout,*)' Pas de remise a zero'
       ENDIF
 
-c$$$      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
-c$$$        write(lunout,*)
-c$$$     .  'GCM: Attention les dates initiales lues dans le fichier'
-c$$$        write(lunout,*)
-c$$$     .  ' restart ne correspondent pas a celles lues dans '
-c$$$        write(lunout,*)' gcm.def'
-c$$$	write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
-c$$$	write(lunout,*)' day_ref=',day_ref," dayref=",dayref
-c$$$        if (raz_date .ne. 1) then
-c$$$          write(lunout,*)
-c$$$     .    'GCM: On garde les dates du fichier restart'
-c$$$        else
-c$$$          annee_ref = anneeref
-c$$$          day_ref = dayref
-c$$$          day_ini = dayref
-c$$$          itau_dyn = 0
-c$$$          itau_phy = 0
-c$$$          time_0 = 0.
-c$$$          write(lunout,*)
-c$$$     .   'GCM: On reinitialise a la date lue dans gcm.def'
-c$$$        endif
-c$$$      ELSE
-c$$$        raz_date = 0
-c$$$      endif
+c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
+c        write(lunout,*)
+c     .  'GCM: Attention les dates initiales lues dans le fichier'
+c        write(lunout,*)
+c     .  ' restart ne correspondent pas a celles lues dans '
+c        write(lunout,*)' gcm.def'
+c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
+c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
+c        if (raz_date .ne. 1) then
+c          write(lunout,*)
+c     .    'GCM: On garde les dates du fichier restart'
+c        else
+c          annee_ref = anneeref
+c          day_ref = dayref
+c          day_ini = dayref
+c          itau_dyn = 0
+c          itau_phy = 0
+c          time_0 = 0.
+c          write(lunout,*)
+c     .   'GCM: On reinitialise a la date lue dans gcm.def'
+c        endif
+c      ELSE
+c        raz_date = 0
+c      endif
 
 #ifdef CPP_IOIPSL
@@ -461,21 +463,22 @@
 
 #ifdef CPP_IOIPSL
-      if ( 1.eq.1) then
       time_step = zdtvr
-      t_ops = iecri * daysec
-      t_wrt = iecri * daysec
-!      CALL inithist(dynhist_file,day_ref,annee_ref,time_step,
-!    .              t_ops, t_wrt, histid, histvid)
-
-!     IF (ok_dynzon) THEN 
-!        t_ops = iperiod * time_step
-!        t_wrt = periodav * daysec
-!        CALL initdynav(dynhistave_file,day_ref,annee_ref,time_step,
-!    .        t_ops, t_wrt, histaveid)
-!     END IF
+      if (ok_dyn_ins) then
+        ! initialize output file for instantaneous outputs
+        ! t_ops = iecri * daysec ! do operations every t_ops
+        t_ops =((1.0*iecri)/day_step) * daysec  
+        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
+        CALL inithist(day_ref,annee_ref,time_step,
+     &              t_ops,t_wrt)
+      endif
+
+      IF (ok_dyn_ave) THEN 
+        ! initialize output file for averaged outputs
+        t_ops = iperiod * time_step ! do operations every t_ops
+        t_wrt = periodav * daysec   ! write output every t_wrt
+        CALL initdynav(day_ref,annee_ref,time_step,
+     &       t_ops,t_wrt)
+      END IF
       dtav = iperiod*dtvr/daysec
-      endif
-
-
 #endif
 ! #endif of #ifdef CPP_IOIPSL
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/leapfrog.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/leapfrog.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/leapfrog.F	(revision 1357)
@@ -60,5 +60,5 @@
 #include "description.h"
 #include "serre.h"
-#include "com_io_dyn.h"
+!#include "com_io_dyn.h"
 #include "iniprint.h"
 #include "academic.h"
@@ -197,10 +197,10 @@
 
       itau = 0
-c$$$      iday = day_ini+itau/day_step
-c$$$      time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
-c$$$         IF(time.GT.1.) THEN
-c$$$          time = time-1.
-c$$$          iday = iday+1
-c$$$         ENDIF
+c      iday = day_ini+itau/day_step
+c      time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
+c         IF(time.GT.1.) THEN
+c          time = time-1.
+c          iday = iday+1
+c         ENDIF
 
 
@@ -276,4 +276,5 @@
 
       IF( purmats ) THEN
+      ! Purely Matsuno time stepping
          IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
          IF( MOD(itau,idissip ).EQ.0.AND..NOT.forward ) apdiss = .TRUE.
@@ -281,8 +282,15 @@
      s          .and. iflag_phys.EQ.1                 ) apphys = .TRUE.
       ELSE
+      ! Leapfrog/Matsuno time stepping 
          IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
          IF( MOD(itau+1,idissip)  .EQ. 0              ) apdiss = .TRUE.
          IF( MOD(itau+1,iphysiq).EQ.0.AND.iflag_phys.EQ.1) apphys=.TRUE.
       END IF
+
+! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
+!          supress dissipation step
+      if (llm.eq.1) then
+        apdiss=.false.
+      endif
 
 c-----------------------------------------------------------------------
@@ -522,10 +530,10 @@
             IF(forward. OR. leapf) THEN
               itau= itau + 1
-c$$$              iday= day_ini+itau/day_step
-c$$$              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
-c$$$                IF(time.GT.1.) THEN
-c$$$                  time = time-1.
-c$$$                  iday = iday+1
-c$$$                ENDIF
+c              iday= day_ini+itau/day_step
+c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
+c                IF(time.GT.1.) THEN
+c                  time = time-1.
+c                  iday = iday+1
+c                ENDIF
             ENDIF
 
@@ -559,12 +567,16 @@
                IF (ok_dynzon) THEN
 #ifdef CPP_IOIPSL
-!                  CALL writedynav(histaveid, itau,vcov ,
-!     ,                 ucov,teta,pk,phi,q,masse,ps,phis)
-                  CALL bilan_dyn (2,dtvr*iperiod,dtvr*day_step*periodav,
-     ,                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
+                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
+     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
 #endif
                END IF
-
-            ENDIF
+               IF (ok_dyn_ave) THEN
+#ifdef CPP_IOIPSL
+                 CALL writedynav(itau,vcov,
+     &                 ucov,teta,pk,phi,q,masse,ps,phis)
+#endif
+               ENDIF
+
+            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
 
 c-----------------------------------------------------------------------
@@ -572,7 +584,7 @@
 c   ------------------------------
 
-            IF( MOD(itau,iecri         ).EQ.0) THEN
-c           IF( MOD(itau,iecri*day_step).EQ.0) THEN
-
+            IF( MOD(itau,iecri).EQ.0) THEN
+             ! Ehouarn: output only during LF or Backward Matsuno
+	     if (leapf.or.(.not.leapf.and.(.not.forward))) then
               nbetat = nbetatdem
               CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
@@ -583,12 +595,19 @@
               enddo
 #ifdef CPP_IOIPSL
-c             CALL writehist(histid,histvid,itau,vcov, 
-c     &                      ucov,teta,phi,q,masse,ps,phis)
+              if (ok_dyn_ins) then
+!               write(lunout,*) "leapfrog: call writehist, itau=",itau
+	       CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
+!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
+!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
+!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
+!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
+!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
+              endif ! of if (ok_dyn_ins)
 #endif
 ! For some Grads outputs of fields
-             if (output_grads_dyn) then
+              if (output_grads_dyn) then
 #include "write_grads_dyn.h"
-             endif
-
+              endif
+             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
             ENDIF ! of IF(MOD(itau,iecri).EQ.0)
 
@@ -645,11 +664,11 @@
 
              itau =  itau + 1
-c$$$             iday = day_ini+itau/day_step
-c$$$             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
-c$$$
-c$$$                  IF(time.GT.1.) THEN
-c$$$                   time = time-1.
-c$$$                   iday = iday+1
-c$$$                  ENDIF
+c             iday = day_ini+itau/day_step
+c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
+c
+c                  IF(time.GT.1.) THEN
+c                   time = time-1.
+c                   iday = iday+1
+c                  ENDIF
 
                forward =  .FALSE.
@@ -660,5 +679,5 @@
                GO TO 2
 
-            ELSE ! of IF(forward)
+            ELSE ! of IF(forward) i.e. backward step
 
               IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
@@ -671,10 +690,14 @@
                IF (ok_dynzon) THEN 
 #ifdef CPP_IOIPSL
-!                  CALL writedynav(histaveid, itau,vcov ,
-!     ,                 ucov,teta,pk,phi,q,masse,ps,phis)
-                  CALL bilan_dyn (2,dtvr*iperiod,dtvr*day_step*periodav,
-     ,                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
-#endif
-               END IF
+                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
+     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
+#endif
+               ENDIF
+               IF (ok_dyn_ave) THEN
+#ifdef CPP_IOIPSL
+                 CALL writedynav(itau,vcov,
+     &                 ucov,teta,pk,phi,q,masse,ps,phis)
+#endif
+               ENDIF
 
               ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
@@ -690,6 +713,9 @@
                 enddo
 #ifdef CPP_IOIPSL
-c               CALL writehist( histid, histvid, itau,vcov , 
-c    &                           ucov,teta,phi,q,masse,ps,phis)
+              if (ok_dyn_ins) then
+!                write(lunout,*) "leapfrog: call writehist (b)",
+!     &                        itau,iecri
+		CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
+              endif ! of if (ok_dyn_ins)
 #endif
 ! For some Grads outputs
Index: DZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/com_io_dyn.h
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/com_io_dyn.h	(revision 1356)
+++ 	(revision )
@@ -1,5 +1,0 @@
-!
-! $Header$
-!
-      integer histid, histvid, histaveid
-      common/com_io_dyn/histid, histvid, histaveid
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/com_io_dyn_mod.F90
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/com_io_dyn_mod.F90	(revision 1357)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/com_io_dyn_mod.F90	(revision 1357)
@@ -0,0 +1,31 @@
+!
+! $Id $
+!
+module com_io_dyn_mod
+
+  implicit none 
+
+! Names of various files for outputs (in the dynamics)
+  ! to store instantaneous values:
+  character(len=18),parameter :: dynhist_file="dyn_hist.nc" ! on scalar grid
+  character(len=18),parameter :: dynhistv_file="dyn_histv.nc" ! on v grid
+  character(len=18),parameter :: dynhistu_file="dyn_histu.nc" ! on u grid
+
+  ! to store averaged values:
+  character(len=18),parameter :: dynhistave_file="dyn_hist_ave.nc"
+  character(len=18),parameter :: dynhistvave_file="dyn_histv_ave.nc"
+  character(len=18),parameter :: dynhistuave_file="dyn_histu_ave.nc"
+  
+! Ids of various files for outputs (in the dynamics)
+
+  ! instantaneous (these are set by inithist.F)
+  integer :: histid
+  integer :: histvid
+  integer :: histuid
+  
+  ! averages (these are set by initdynav.F)
+  integer :: histaveid
+  integer :: histvaveid
+  integer :: histuaveid
+  
+end module com_io_dyn_mod
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/conf_gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/conf_gcm.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/conf_gcm.F	(revision 1357)
@@ -601,4 +601,19 @@
       CALL getin('ok_dynzon',ok_dynzon) 
 
+!Config  Key  = ok_dyn_ins
+!Config  Desc = sorties instantanees dans la dynamique
+!Config  Def  = n 
+!Config  Help = 
+!Config          
+      ok_dyn_ins = .FALSE. 
+      CALL getin('ok_dyn_ins',ok_dyn_ins) 
+
+!Config  Key  = ok_dyn_ave
+!Config  Desc = sorties moyennes dans la dynamique
+!Config  Def  = n 
+!Config  Help = 
+!Config          
+      ok_dyn_ave = .FALSE. 
+      CALL getin('ok_dyn_ave',ok_dyn_ave) 
 
       write(lunout,*)' #########################################'
@@ -641,4 +656,6 @@
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon 
+      write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
+      write(lunout,*)' ok_dyn_ave = ', ok_dyn_ave 
 
       RETURN
@@ -773,4 +790,20 @@
       ok_dynzon = .FALSE. 
       CALL getin('ok_dynzon',ok_dynzon) 
+
+!Config  Key  = ok_dyn_ins
+!Config  Desc = sorties instantanees dans la dynamique
+!Config  Def  = n 
+!Config  Help = 
+!Config          
+      ok_dyn_ins = .FALSE. 
+      CALL getin('ok_dyn_ins',ok_dyn_ins) 
+
+!Config  Key  = ok_dyn_ave
+!Config  Desc = sorties moyennes dans la dynamique
+!Config  Def  = n 
+!Config  Help = 
+!Config          
+      ok_dyn_ave = .FALSE. 
+      CALL getin('ok_dyn_ave',ok_dyn_ave) 
 
 !Config  Key  = use_filtre_fft
@@ -866,4 +899,6 @@
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon 
+      write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
+      write(lunout,*)' ok_dyn_ave = ', ok_dyn_ave 
       write(lunout,*)' use_filtre_fft = ', use_filtre_fft
       write(lunout,*)' use_mpi_alloc = ', use_mpi_alloc
Index: DZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/control.h
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/control.h	(revision 1356)
+++ 	(revision )
@@ -1,29 +1,0 @@
-!
-! $Header$
-!
-!
-!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
-!                 veillez à n'utiliser que des ! pour les commentaires
-!                 et à bien positionner les & des lignes de continuation 
-!                 (les placer en colonne 6 et en colonne 73)
-!
-!-----------------------------------------------------------------------
-! INCLUDE 'control.h'
-
-      COMMON/control/nday,day_step,                                     &
-     &              iperiod,iapp_tracvl,iconser,iecri,idissip,iphysiq , &
-     &              periodav,iecrimoy,dayref,anneeref,                  &
-     &              raz_date,offline,ip_ebil_dyn,config_inca,           &
-     &              planet_type,output_grads_dyn,ok_dynzon
-
-      INTEGER   nday,day_step,iperiod,iapp_tracvl,iconser,iecri,        &
-     &          idissip,iphysiq,iecrimoy,dayref,anneeref, raz_date      &
-     &          ,ip_ebil_dyn
-      REAL periodav
-      logical offline
-      CHARACTER (len=4) :: config_inca
-      CHARACTER(len=10) :: planet_type ! planet type ('earth','mars',...)
-      LOGICAL :: output_grads_dyn ! output dynamics diagnostics in
-                                  ! binary grads file 'dyn.dat' (y/n)
-      LOGICAL :: ok_dynzon 
-!-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/control_mod.F90
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/control_mod.F90	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/control_mod.F90	(revision 1357)
@@ -1,4 +1,4 @@
 !
-! $Id$
+! $Id $
 !
 
@@ -14,7 +14,14 @@
   INTEGER :: iconser,iecri,idissip,iphysiq,iecrimoy
   INTEGER :: dayref,anneeref, raz_date, ip_ebil_dyn
-  LOGICAL :: offline, output_grads_dyn, ok_dynzon
+  LOGICAL :: offline
   CHARACTER (len=4)  :: config_inca
-  CHARACTER (len=10) :: planet_type
+  CHARACTER (len=10) :: planet_type ! planet type ('earth','mars',...)
+  LOGICAL output_grads_dyn ! output dynamics diagnostics in
+                           ! binary grads file 'dyn.dat' (y/n)
+  LOGICAL ok_dynzon  ! output zonal transports in dynzon.nc file
+  LOGICAL ok_dyn_ins ! output instantaneous values of fields
+                     ! in the dynamics in NetCDF files dyn_hist*nc
+  LOGICAL ok_dyn_ave ! output averaged values of fields in the dynamics
+                     ! in NetCDF files dyn_hist*ave.nc
 
 END MODULE
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/covnat.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/covnat.F	(revision 1357)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/covnat.F	(revision 1357)
@@ -0,0 +1,49 @@
+!
+! $Header$
+!
+      SUBROUTINE covnat (klevel,ucov, vcov, unat, vnat )
+      IMPLICIT NONE
+
+c=======================================================================
+c
+c   Auteur:  F Hourdin Phu LeVan
+c   -------
+c
+c   Objet:
+c   ------
+c
+c  *********************************************************************
+c    calcul des compos. naturelles a partir des comp.covariantes
+c  ********************************************************************
+c
+c=======================================================================
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom.h"
+
+      INTEGER klevel
+      REAL ucov( ip1jmp1,klevel ),  vcov( ip1jm,klevel )
+      REAL unat( ip1jmp1,klevel ), vnat( ip1jm,klevel )
+      INTEGER   l,ij
+
+
+      DO l = 1,klevel
+         DO ij = 1, iip1
+            unat (ij,l) =0.
+         END DO
+
+         DO ij = iip2, ip1jm
+            unat( ij,l ) = ucov( ij,l ) / cu(ij)
+         ENDDO
+         DO ij = ip1jm+1, ip1jmp1  
+            unat (ij,l) =0.
+         END DO
+
+         DO ij = 1,ip1jm
+            vnat( ij,l ) = vcov( ij,l ) / cv(ij)
+         ENDDO
+
+      ENDDO
+      RETURN
+      END
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/gcm.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/gcm.F	(revision 1357)
@@ -70,8 +70,11 @@
 #include "description.h"
 #include "serre.h"
-#include "com_io_dyn.h"
+!#include "com_io_dyn.h"
 #include "iniprint.h"
 #include "tracstoke.h"
+#ifdef INCA
+! Only INCA needs these informations (from the Earth's physics)
 #include "indicesol.h"
+#endif
 
       INTEGER         longcles
@@ -335,32 +338,32 @@
      .  ' restart ne correspondent pas a celles lues dans '
         write(lunout,*)' gcm.def'
-	write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
-	write(lunout,*)' day_ref=',day_ref," dayref=",dayref
-	write(lunout,*)' Pas de remise a zero'
+        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
+        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
+        write(lunout,*)' Pas de remise a zero'
       ENDIF
-c$$$      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
-c$$$        write(lunout,*)
-c$$$     .  'GCM: Attention les dates initiales lues dans le fichier'
-c$$$        write(lunout,*)
-c$$$     .  ' restart ne correspondent pas a celles lues dans '
-c$$$        write(lunout,*)' gcm.def'
-c$$$	write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
-c$$$	write(lunout,*)' day_ref=',day_ref," dayref=",dayref
-c$$$        if (raz_date .ne. 1) then
-c$$$          write(lunout,*)
-c$$$     .    'GCM: On garde les dates du fichier restart'
-c$$$        else
-c$$$          annee_ref = anneeref
-c$$$          day_ref = dayref
-c$$$          day_ini = dayref
-c$$$          itau_dyn = 0
-c$$$          itau_phy = 0
-c$$$          time_0 = 0.
-c$$$          write(lunout,*)
-c$$$     .   'GCM: On reinitialise a la date lue dans gcm.def'
-c$$$        endif
-c$$$      ELSE
-c$$$        raz_date = 0
-c$$$      endif
+c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
+c        write(lunout,*)
+c     .  'GCM: Attention les dates initiales lues dans le fichier'
+c        write(lunout,*)
+c     .  ' restart ne correspondent pas a celles lues dans '
+c        write(lunout,*)' gcm.def'
+c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
+c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
+c        if (raz_date .ne. 1) then
+c          write(lunout,*)
+c     .    'GCM: On garde les dates du fichier restart'
+c        else
+c          annee_ref = anneeref
+c          day_ref = dayref
+c          day_ini = dayref
+c          itau_dyn = 0
+c          itau_phy = 0
+c          time_0 = 0.
+c          write(lunout,*)
+c     .   'GCM: On reinitialise a la date lue dans gcm.def'
+c        endif
+c      ELSE
+c        raz_date = 0
+c      endif
 
 #ifdef CPP_IOIPSL
@@ -486,21 +489,27 @@
 
 #ifdef CPP_IOIPSL
-      if ( 1.eq.1) then
       time_step = zdtvr
-      t_ops = iecri * daysec
-      t_wrt = iecri * daysec
+      if (ok_dyn_ins) then
+        ! initialize output file for instantaneous outputs
+        ! t_ops = iecri * daysec ! do operations every t_ops
+        t_ops =((1.0*iecri)/day_step) * daysec  
+        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
+        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
+        CALL inithist(day_ref,annee_ref,time_step,
+     &              t_ops,t_wrt)
 !      CALL inithist_p(dynhist_file,day_ref,annee_ref,time_step,
 !     .              t_ops, t_wrt, histid, histvid)
-
-      IF (ok_dynzon) THEN 
-         t_ops = iperiod * time_step
-         t_wrt = periodav * daysec
+      endif
+
+      IF (ok_dyn_ave) THEN 
+        ! initialize output file for averaged outputs
+        t_ops = iperiod * time_step ! do operations every t_ops
+        t_wrt = periodav * daysec   ! write output every t_wrt
+        CALL initdynav(day_ref,annee_ref,time_step,
+     &       t_ops,t_wrt)
 !         CALL initdynav_p(dynhistave_file,day_ref,annee_ref,time_step,
 !     .        t_ops, t_wrt, histaveid)
       END IF
       dtav = iperiod*dtvr/daysec
-      endif
-
-
 #endif
 ! #endif of #ifdef CPP_IOIPSL
Index: /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/leapfrog_p.F	(revision 1356)
+++ /LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3dpar/leapfrog_p.F	(revision 1357)
@@ -66,5 +66,5 @@
 #include "description.h"
 #include "serre.h"
-#include "com_io_dyn.h"
+!#include "com_io_dyn.h"
 #include "iniprint.h"
 #include "academic.h"
@@ -352,4 +352,5 @@
 c      idissip=1
       IF( purmats ) THEN
+      ! Purely Matsuno time stepping
          IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
          IF( MOD(itau,idissip ).EQ.0.AND..NOT.forward ) apdiss = .TRUE.
@@ -357,4 +358,5 @@
      s          .and. iflag_phys.EQ.1                 ) apphys = .TRUE.
       ELSE
+      ! Leapfrog/Matsuno time stepping 
          IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
          IF( MOD(itau+1,idissip)  .EQ. 0              ) apdiss = .TRUE.
@@ -362,8 +364,14 @@
       END IF
 
+! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
+!          supress dissipation step
+      if (llm.eq.1) then
+        apdiss=.false.
+      endif
+
 cym    ---> Pour le moment      
 cym      apphys = .FALSE.
       statcl = .FALSE.
-      conser = .FALSE.
+      conser = .FALSE. ! ie: no output of control variables to stdout in //
       
       if (firstCaldyn) then
@@ -974,5 +982,5 @@
 c$OMP BARRIER
        call WaitRequest(Request_Physic)     
-
+c$OMP BARRIER
        call friction_p(ucov,vcov,iphysiq*dtvr)
       ENDIF ! of IF(iflag_phys.EQ.2)
@@ -1091,5 +1099,5 @@
             enddo
 c$OMP END DO NOWAIT            
-       endif
+       endif ! of if (dissip_conservative)
 
        ijb=ij_begin
@@ -1200,5 +1208,5 @@
 c$OMP END MASTER
 c$OMP BARRIER
-      END IF
+      END IF ! of IF(apdiss)
 
 cc$OMP END PARALLEL
@@ -1339,5 +1347,26 @@
               ENDIF !ok_dynzon
 #endif
-            ENDIF
+               IF (ok_dyn_ave) THEN
+!$OMP MASTER
+#ifdef CPP_IOIPSL
+! Ehouarn: Gather fields and make master send to output
+                call Gather_Field(vcov,ip1jm,llm,0)
+                call Gather_Field(ucov,ip1jmp1,llm,0)
+                call Gather_Field(teta,ip1jmp1,llm,0)
+		call Gather_Field(phi,ip1jmp1,llm,0)
+                do iq=1,nqtot
+                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
+                enddo
+		call Gather_Field(masse,ip1jmp1,llm,0)
+                call Gather_Field(ps,ip1jmp1,1,0)
+		call Gather_Field(phis,ip1jmp1,1,0)
+                if (mpi_rank==0) then
+                 CALL writedynav(itau,vcov,
+     &                 ucov,teta,pk,phi,q,masse,ps,phis)
+		endif
+#endif
+!$OMP END MASTER
+               ENDIF ! of IF (ok_dyn_ave)
+            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
 
 c-----------------------------------------------------------------------
@@ -1345,7 +1374,7 @@
 c   ------------------------------
 
-c      IF( MOD(itau,iecri         ).EQ.0) THEN
-
-            IF( MOD(itau,iecri*day_step).EQ.0) THEN
+            IF( MOD(itau,iecri).EQ.0) THEN
+             ! Ehouarn: output only during LF or Backward Matsuno
+	     if (leapf.or.(.not.leapf.and.(.not.forward))) then
 c$OMP BARRIER
 c$OMP MASTER
@@ -1381,8 +1410,27 @@
         
 #ifdef CPP_IOIPSL
- 
+              if (ok_dyn_ins) then
+! Ehouarn: Gather fields and make master write to output
+                call Gather_Field(vcov,ip1jm,llm,0)
+                call Gather_Field(ucov,ip1jmp1,llm,0)
+                call Gather_Field(teta,ip1jmp1,llm,0)
+		call Gather_Field(phi,ip1jmp1,llm,0)
+                do iq=1,nqtot
+                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
+                enddo
+		call Gather_Field(masse,ip1jmp1,llm,0)
+                call Gather_Field(ps,ip1jmp1,1,0)
+		call Gather_Field(phis,ip1jmp1,1,0)
+                if (mpi_rank==0) then
+	         CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
+		endif
 !              CALL writehist_p(histid,histvid, itau,vcov, 
 !     &                         ucov,teta,phi,q,masse,ps,phis)
-
+! or use writefield_p
+!      call WriteField_p('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
+!      call WriteField_p('vcov',reshape(vcov,(/iip1,jjm,llm/)))
+!      call WriteField_p('teta',reshape(teta,(/iip1,jmp1,llm/)))
+!      call WriteField_p('ps',reshape(ps,(/iip1,jmp1/)))
+              endif ! of if (ok_dyn_ins)
 #endif
 ! For some Grads outputs of fields
@@ -1401,4 +1449,5 @@
               endif ! of if (output_grads_dyn)
 c$OMP END MASTER
+             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
             ENDIF ! of IF(MOD(itau,iecri).EQ.0)
 
@@ -1479,5 +1528,5 @@
                GO TO 2
 
-            ELSE ! of IF(forward)
+            ELSE ! of IF(forward) i.e. backward step
 
               IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
@@ -1490,10 +1539,8 @@
                IF (ok_dynzon) THEN
 c$OMP BARRIER
-
                call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
                call SendRequest(TestRequest)
 c$OMP BARRIER
                call WaitRequest(TestRequest)
-
 c$OMP BARRIER
 c$OMP MASTER
@@ -1505,9 +1552,31 @@
                END IF !ok_dynzon
 #endif
+               IF (ok_dyn_ave) THEN
+!$OMP MASTER
+#ifdef CPP_IOIPSL
+! Ehouarn: Gather fields and make master send to output
+                call Gather_Field(vcov,ip1jm,llm,0)
+                call Gather_Field(ucov,ip1jmp1,llm,0)
+                call Gather_Field(teta,ip1jmp1,llm,0)
+		call Gather_Field(phi,ip1jmp1,llm,0)
+                do iq=1,nqtot
+                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
+                enddo
+		call Gather_Field(masse,ip1jmp1,llm,0)
+                call Gather_Field(ps,ip1jmp1,1,0)
+		call Gather_Field(phis,ip1jmp1,1,0)
+                if (mpi_rank==0) then
+                 CALL writedynav(itau,vcov,
+     &                 ucov,teta,pk,phi,q,masse,ps,phis)
+		endif
+#endif
+!$OMP END MASTER
+               ENDIF ! of IF (ok_dyn_ave)
+
               ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
 
 
-c               IF(MOD(itau,iecri         ).EQ.0) THEN
-              IF(MOD(itau,iecri*day_step).EQ.0) THEN
+               IF(MOD(itau,iecri         ).EQ.0) THEN
+c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
 c$OMP BARRIER
 c$OMP MASTER
@@ -1542,7 +1611,22 @@
 
 #ifdef CPP_IOIPSL
-
+              if (ok_dyn_ins) then
+! Ehouarn: Gather fields and make master send to output
+                call Gather_Field(vcov,ip1jm,llm,0)
+                call Gather_Field(ucov,ip1jmp1,llm,0)
+                call Gather_Field(teta,ip1jmp1,llm,0)
+		call Gather_Field(phi,ip1jmp1,llm,0)
+                do iq=1,nqtot
+                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
+                enddo
+		call Gather_Field(masse,ip1jmp1,llm,0)
+                call Gather_Field(ps,ip1jmp1,1,0)
+		call Gather_Field(phis,ip1jmp1,1,0)
+                if (mpi_rank==0) then
+	         CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
+		endif
 !                CALL writehist_p(histid, histvid, itau,vcov , 
 !     &                           ucov,teta,phi,q,masse,ps,phis)
+              endif ! of if (ok_dyn_ins)
 #endif
 ! For some Grads output (but does it work?)
@@ -1562,5 +1646,5 @@
 
 c$OMP END MASTER
-              ENDIF ! of IF(MOD(itau,iecri*day_step).EQ.0)
+              ENDIF ! of IF(MOD(itau,iecri).EQ.0)
 
               IF(itau.EQ.itaufin) THEN
