Index: LMDZ.3.3/trunk/libf/phylmd/physiq.F
===================================================================
--- LMDZ.3.3/trunk/libf/phylmd/physiq.F	(revision 27)
+++ LMDZ.3.3/trunk/libf/phylmd/physiq.F	(revision 29)
@@ -506,5 +506,5 @@
       REAL tabcntr0( length       )
 c
-      INTEGER ndex(1)
+      INTEGER ndex2d(iim*(jjm+1)),ndex3d(iim*(jjm+1)*klev)
       REAL zx_tmp_fi2d(klon)
       REAL zx_tmp_2d(iim,jjm+1), zx_tmp_3d(iim,jjm+1,klev)
@@ -810,13 +810,14 @@
          CALL histend(nid_day)
 c
-         ndex(1) = 0
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-         CALL histwrite(nid_day,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
-         CALL histwrite(nid_day,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+         ndex2d = 0
+         ndex3d = 0
+c
+Cess         i = NINT(zout/zsto)
+Cess         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+Cess        CALL histwrite(nid_day,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+c
+Cess         i = NINT(zout/zsto)
+Cess         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+Cess        CALL histwrite(nid_day,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       ENDIF ! fin de test sur ok_journe
@@ -1157,13 +1158,14 @@
          CALL histend(nid_mth)
 c
-         ndex(1) = 0
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-         CALL histwrite(nid_mth,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex)
+         ndex2d = 0
+         ndex3d = 0
+c
+Cess         i = NINT(zout/zsto)
+Cess         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+Cess        CALL histwrite(nid_mth,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
 C
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
-         CALL histwrite(nid_mth,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+Cess         i = NINT(zout/zsto)
+Cess         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+Cess        CALL histwrite(nid_mth,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       ENDIF ! fin de test sur ok_mensuel
@@ -1238,13 +1240,14 @@
          CALL histend(nid_ins)
 c
-         ndex(1) = 0
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-         CALL histwrite(nid_ins,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
-         CALL histwrite(nid_ins,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+         ndex2d = 0
+         ndex3d = 0
+c
+Cess         i = NINT(zout/zsto)
+Cess         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+Cess        CALL histwrite(nid_ins,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+c
+Cess         i = NINT(zout/zsto)
+Cess         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+Cess        CALL histwrite(nid_ins,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       ENDIF
@@ -1797,4 +1800,5 @@
 C la physique s'applique
 C
+       write(*,*) 'Phytrac= '
       call phytrac (rnpb,
      I                   debut,
@@ -1808,5 +1812,7 @@
      O                   tr_seri)
 
+       write(*,*) 'OFFLINE= ', offline
       IF (offline) THEN
+       write(*,*) 'OFFLINE= ', offline
       call phystoke (
      I                   nlon,nlev,pdtphys,
@@ -1845,10 +1851,19 @@
       IF (ok_journe) THEN
 c
-      ndex(1) = 0
+      ndex2d = 0
+      ndex3d = 0
 c
 c Champs 2D:
 c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_day,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+         CALL histwrite(nid_day,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+C
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zxtsol,zx_tmp_2d)
-      CALL histwrite(nid_day,"tsol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"tsol",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1856,5 +1871,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1862,35 +1877,35 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"rain",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"rain",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, snow_fall,zx_tmp_2d)
-      CALL histwrite(nid_day,"snow",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"snow",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, evap,zx_tmp_2d)
-      CALL histwrite(nid_day,"evap",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"evap",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, topsw,zx_tmp_2d)
-      CALL histwrite(nid_day,"tops",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"tops",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_day,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, solsw,zx_tmp_2d)
-      CALL histwrite(nid_day,"sols",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"sols",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, sollw,zx_tmp_2d)
-      CALL histwrite(nid_day,"soll",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"soll",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, bils,zx_tmp_2d)
-      CALL histwrite(nid_day,"bils",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"bils",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, sens,zx_tmp_2d)
-      CALL histwrite(nid_day,"sens",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"sens",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, fder,zx_tmp_2d)
-      CALL histwrite(nid_day,"fder",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"fder",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, ruis,zx_tmp_2d)
-      CALL histwrite(nid_day,"ruis",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"ruis",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1898,5 +1913,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"frtu",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"frtu",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1904,5 +1919,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"frtv",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"frtv",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1910,20 +1925,20 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"sicf",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"sicf",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldl,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"cldl",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldm,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldm",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"cldm",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldh,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldh",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"cldh",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldt,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldt",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"cldt",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldq,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_day,"cldq",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
 c Champs 3D:
@@ -1931,41 +1946,52 @@
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t_seri, zx_tmp_3d)
       CALL histwrite(nid_day,"temp",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, qx(1,1,ivap), zx_tmp_3d)
       CALL histwrite(nid_day,"ovap",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zphi, zx_tmp_3d)
       CALL histwrite(nid_day,"geop",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, u_seri, zx_tmp_3d)
       CALL histwrite(nid_day,"vitu",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, v_seri, zx_tmp_3d)
       CALL histwrite(nid_day,"vitv",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, omega, zx_tmp_3d)
       CALL histwrite(nid_day,"vitw",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, pplay, zx_tmp_3d)
       CALL histwrite(nid_day,"pres",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      if (ok_sync) call histsync
+     .                                   iim*(jjm+1)*klev,ndex3d)
+c
+      if (ok_sync) then
+        call histsync(nid_day)
+      endif
       ENDIF
 C
       IF (ok_mensuel) THEN
 c
-      ndex(1) = 0
+      ndex2d = 0
+      ndex3d = 0
 c
 c Champs 2D:
 c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_mth,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+C
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+         CALL histwrite(nid_mth,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zxtsol,zx_tmp_2d)
-      CALL histwrite(nid_mth,"tsol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"tsol",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1973,8 +1999,8 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zxqsol,zx_tmp_2d)
-      CALL histwrite(nid_mth,"qsol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"qsol",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1982,5 +2008,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"rain",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"rain",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1988,5 +2014,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"plul",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"plul",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -1994,50 +2020,50 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"pluc",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"pluc",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, snow_fall,zx_tmp_2d)
-      CALL histwrite(nid_mth,"snow",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"snow",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, agesno,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ages",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"ages",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, evap,zx_tmp_2d)
-      CALL histwrite(nid_mth,"evap",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"evap",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, topsw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"tops",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"tops",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, solsw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sols",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"sols",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, sollw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"soll",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"soll",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, topsw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"tops0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"tops0",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"topl0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"topl0",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, solsw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sols0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"sols0",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, sollw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"soll0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"soll0",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, bils,zx_tmp_2d)
-      CALL histwrite(nid_mth,"bils",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"bils",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, sens,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sens",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"sens",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, fder,zx_tmp_2d)
-      CALL histwrite(nid_mth,"fder",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"fder",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, ruis,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ruis",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"ruis",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -2045,5 +2071,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"frtu",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"frtu",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -2051,5 +2077,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"frtv",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"frtv",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       DO i = 1, klon
@@ -2057,41 +2083,41 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sicf",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"sicf",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, albsol,zx_tmp_2d)
-      CALL histwrite(nid_mth,"albs",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"albs",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cdragm,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cdrm",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cdrm",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cdragh,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cdrh",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cdrh",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldl,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cldl",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldm,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldm",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cldm",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldh,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldh",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cldh",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldt,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldt",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cldt",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldq,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"cldq",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, ue,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ue",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"ue",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, ve,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ve",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"ve",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, uq,zx_tmp_2d)
-      CALL histwrite(nid_mth,"uq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"uq",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, vq,zx_tmp_2d)
-      CALL histwrite(nid_mth,"vq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_mth,"vq",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
 c Champs 3D:
@@ -2099,123 +2125,123 @@
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t_seri, zx_tmp_3d)
       CALL histwrite(nid_mth,"temp",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, qx(1,1,ivap), zx_tmp_3d)
       CALL histwrite(nid_mth,"ovap",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zphi, zx_tmp_3d)
       CALL histwrite(nid_mth,"geop",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, u_seri, zx_tmp_3d)
       CALL histwrite(nid_mth,"vitu",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, v_seri, zx_tmp_3d)
       CALL histwrite(nid_mth,"vitv",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, omega, zx_tmp_3d)
       CALL histwrite(nid_mth,"vitw",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, pplay, zx_tmp_3d)
       CALL histwrite(nid_mth,"pres",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cldfra, zx_tmp_3d)
       CALL histwrite(nid_mth,"rneb",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zx_rh, zx_tmp_3d)
       CALL histwrite(nid_mth,"rhum",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cldliq, zx_tmp_3d)
       CALL histwrite(nid_mth,"oliq",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_dyn, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtdyn",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_qx_dyn(1,1,ivap),
      .                 zx_tmp_3d)
       CALL histwrite(nid_mth,"dqdyn",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_con, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtcon",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_con, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqcon",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_lsc, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtlsc",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_lsc, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqlsc",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_eva, zx_tmp_3d)
       CALL histwrite(nid_mth,"dteva",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_eva, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqeva",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
 C      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_ajs, zx_tmp_3d)
 C      CALL histwrite(nid_mth,"dtajs",itap,zx_tmp_3d,
-C    .                                   iim*(jjm+1)*klev,ndex)
+C    .                                   iim*(jjm+1)*klev,ndex3d)
 c
 C      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_ajs, zx_tmp_3d)
 C      CALL histwrite(nid_mth,"dqajs",itap,zx_tmp_3d,
-C     .                                   iim*(jjm+1)*klev,ndex)
+C     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, heat, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtswr",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, heat0, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtsw0",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cool, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtlwr",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cool0, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtlw0",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_u_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"duvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_v_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"dvvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       IF (ok_orodr) THEN
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_u_oro, zx_tmp_3d)
       CALL histwrite(nid_mth,"duoro",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_v_oro, zx_tmp_3d)
       CALL histwrite(nid_mth,"dvoro",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       ENDIF
@@ -2224,14 +2250,14 @@
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_u_lif, zx_tmp_3d)
       CALL histwrite(nid_mth,"dulif",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_v_lif, zx_tmp_3d)
       CALL histwrite(nid_mth,"dvlif",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
       ENDIF
 C
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, wo, zx_tmp_3d)
       CALL histwrite(nid_mth,"ozone",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       IF (nqmax.GE.3) THEN
@@ -2241,5 +2267,5 @@
          WRITE(str2,'(i2.2)') iq
          CALL histwrite(nid_mth,"trac"//str2,itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
       ELSE
          PRINT*, "Trop de traceurs"
@@ -2249,21 +2275,32 @@
       ENDIF
 c
-      if (ok_sync) call histsync
+      if (ok_sync) then
+        call histsync(nid_mth)
+      endif
       ENDIF
 c
       IF (ok_instan) THEN
 c
-      ndex(1) = 0
+      ndex2d = 0
+      ndex3d = 0
 c
 c Champs 2D:
 c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_ins,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+         CALL histwrite(nid_ins,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex2d)
+
       DO i = 1, klon
          zx_tmp_fi2d(i) = paprs(i,1)
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_ins,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_ins,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_ins,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL histwrite(nid_ins,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex2d)
 c
 c Champs 3D:
@@ -2271,23 +2308,25 @@
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t_seri, zx_tmp_3d)
       CALL histwrite(nid_ins,"temp",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, u_seri, zx_tmp_3d)
       CALL histwrite(nid_ins,"vitu",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, v_seri, zx_tmp_3d)
       CALL histwrite(nid_ins,"vitv",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zphi, zx_tmp_3d)
       CALL histwrite(nid_ins,"geop",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, pplay, zx_tmp_3d)
       CALL histwrite(nid_ins,"pres",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      if (ok_sync) call histsync
+     .                                   iim*(jjm+1)*klev,ndex3d)
+c
+      if (ok_sync) then
+        call histsync(nid_ins)
+      endif
       ENDIF
 c
