Index: LMDZ4/trunk/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ4/trunk/libf/phylmd/phys_output_mod.F90	(revision 928)
+++ LMDZ4/trunk/libf/phylmd/phys_output_mod.F90	(revision 929)
@@ -15,8 +15,13 @@
   IMPLICIT NONE
 
-   integer, parameter                :: nfiles = 4
-   logical, dimension(nfiles), save  :: clef_files
-   integer, dimension(nfiles), save  :: lev_files
-   integer, dimension(nfiles), save  :: nid_files
+   integer, parameter                           :: nfiles = 4
+   logical, dimension(nfiles), save             :: clef_files
+   integer, dimension(nfiles), save             :: lev_files
+   integer, dimension(nfiles), save             :: nid_files
+
+   integer, dimension(nfiles), save             :: nhorim, nvertm
+   real, dimension(nfiles), save                :: zstophym, zoutm
+   CHARACTER(len=20), dimension(nfiles), save   :: type_ecri
+
 !   integer, save                     :: nid_hf3d 
 
@@ -25,7 +30,7 @@
 
   logical, dimension(nfiles), save  :: ok_reglim         = (/ .false., .true., .true., .false. /) 
-  real, dimension(nfiles), save     :: lonmin_reg        = (/ 0., 0., 0., 0. /)
-  real, dimension(nfiles), save     :: lonmax_reg        = (/ 90., 90., 90., 90. /)
-  real, dimension(nfiles), save     :: latmin_reg        = (/ 0., 0., 0., 0. /)
+  real, dimension(nfiles), save     :: lonmin_reg        = (/ 0., -45., 0., 0. /)
+  real, dimension(nfiles), save     :: lonmax_reg        = (/ 90., 45., 90., 90. /)
+  real, dimension(nfiles), save     :: latmin_reg        = (/ 0., -45., 0., 0. /)
   real, dimension(nfiles), save     :: latmax_reg        = (/ 90., 90., 90., 90. /)
 
@@ -149,7 +154,7 @@
   integer, dimension(nfiles) , save :: flag_s_pblh       = (/ 1, 10, 10, 1 /)
   integer, dimension(nfiles) , save :: flag_s_pblt       = (/ 1, 10, 10, 1 /)
-  integer, dimension(nfiles) , save :: flag_s_lclt       = (/ 1, 10, 10, 1 /)
+  integer, dimension(nfiles) , save :: flag_s_lcl       = (/ 1, 10, 10, 1 /)
   integer, dimension(nfiles) , save :: flag_s_capCL      = (/ 1, 10, 10, 1 /)
-  integer, dimension(nfiles) , save :: flag_s_oliqCLL    = (/ 1, 10, 10, 1 /)
+  integer, dimension(nfiles) , save :: flag_s_oliqCL    = (/ 1, 10, 10, 1 /)
   integer, dimension(nfiles) , save :: flag_s_cteiCL     = (/ 1, 10, 10, 1 /)
   integer, dimension(nfiles) , save :: flag_s_therm      = (/ 1, 10, 10, 1 /)
@@ -233,5 +238,9 @@
   integer, dimension(nfiles) , save :: flag_dtphy        = (/ 2, 10, 10, 10 /)
   integer, dimension(nfiles) , save :: flag_dqphy        = (/ 2, 10, 10, 10 /)
-! arevoir probleme noms (geop, ovap  a ?????)
+  integer, dimension(nfiles) , save :: flag_pr_con_l     = (/ 2, 10, 10, 10 /)
+  integer, dimension(nfiles) , save :: flag_pr_con_i     = (/ 2, 10, 10, 10 /)
+  integer, dimension(nfiles) , save :: flag_pr_lsc_l     = (/ 2, 10, 10, 10 /)
+  integer, dimension(nfiles) , save :: flag_pr_lsc_i     = (/ 2, 10, 10, 10 /)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
   integer, dimension(nfiles) , save :: flag_albe_sol     = (/ 3, 4, 10, 1 /) 
@@ -283,75 +292,69 @@
 !! histbeg, histvert et histdef
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
-
-       SUBROUTINE phys_output_open ( jj_nb, jjmp1, nqmax, &
-     &                nlevSTD, clevSTD, nbteta, ctetaSTD, &
-     &              dtime, presnivs, ok_veget, ocean, iflag_pbl, &
-     &                ok_mensuel,ok_journe,ok_hf,ok_instan, &
-     &                 rlon, rlat, nid_fil) 
-
-
-   
-       USE iophy 
-       USE dimphy
-       USE ioipsl
-
-       IMPLICIT NONE
-       include "dimensions.h"
-       include "temps.h"
-       include "indicesol.h"
-       include "advtrac.h"
-       include "clesphys.h"
-
-        integer      :: jj_nb, jjmp1, nqmax
-        integer      :: nbteta, nlevSTD, radpas
-        logical      :: ok_mensuel, ok_journe, ok_hf, ok_instan
-        real         :: dtime, zstophy, zout
-        integer      :: nhori, nvert
-        integer      :: idayref
-        real         :: zjulian
-        real, dimension(klev) :: presnivs
-        character(len=4), dimension(nlevSTD) :: clevSTD
-        integer      :: nsrf, k, iq, iiq, iff, i, j
-        logical      :: ok_veget
-        integer           :: iflag_pbl
-        CHARACTER(len=3)  :: bb2
-        CHARACTER(len=2)  :: bb3
-        character(len=6)  :: ocean
-        CHARACTER(len=3)  :: ctetaSTD(nbteta)
-        integer, dimension(nfiles) :: nid_fil
-        real, dimension(nfiles)    ::  ecrit_files
-        CHARACTER(len=20), dimension(nfiles) :: name_files
-        CHARACTER(len=20), dimension(nfiles) :: type_ecri
-        INTEGER, dimension(iim*jjmp1) ::  ndex2d
-        INTEGER, dimension(iim*jjmp1*klev) :: ndex3d
-        REAL, dimension(klon) :: rlon, rlat
-        integer               :: imin_ins, imax_ins
-        integer               :: jmin_ins, jmax_ins
-        REAL, dimension(iim,jjmp1) :: zx_lon, zx_lat
-
-        name_files(1) = 'histmth'
-        name_files(2) = 'histday'
-        name_files(3) = 'histhf'
-        name_files(4) = 'histins'
-
-        type_ecri(1) = 'ave(X)'
-        type_ecri(2) = 'ave(X)'
-        type_ecri(3) = 'ave(X)'
-        type_ecri(4) = 'inst(X)'
-
-        clef_files(1) = ok_mensuel
-        clef_files(2) = ok_journe
-        clef_files(3) = ok_hf
-        clef_files(4) = ok_instan
-
-        lev_files(1) = lev_histmth
-        lev_files(2) = lev_histday
-        lev_files(3) = lev_histhf
-        lev_files(4) = 1
-
-        ecrit_files(1) = ecrit_mth
-        ecrit_files(2) = ecrit_day
-        ecrit_files(3) = ecrit_hf
-        ecrit_files(4) = ecrit_ins
+  
+  SUBROUTINE phys_output_open(jjmp1,nqmax,nlevSTD,clevSTD,nbteta, &
+                              ctetaSTD,dtime, presnivs, ok_veget, &
+                              ocean, iflag_pbl,ok_mensuel,ok_journe, & 
+                              ok_hf,ok_instan, nid_fil)
+
+  USE iophy 
+  USE dimphy
+  USE ioipsl
+  USE mod_phys_lmdz_para
+
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "temps.h"
+  include "indicesol.h"
+  include "advtrac.h"
+  include "clesphys.h"
+
+  integer                               :: jjmp1, nqmax
+  integer                               :: nbteta, nlevSTD, radpas
+  logical                               :: ok_mensuel, ok_journe, ok_hf, ok_instan
+  real                                  :: dtime
+  integer                               :: idayref
+  real                                  :: zjulian
+  real, dimension(klev)                 :: presnivs
+  character(len=4), dimension(nlevSTD)  :: clevSTD
+  integer                               :: nsrf, k, iq, iiq, iff, i, j
+  logical                               :: ok_veget
+  integer                               :: iflag_pbl
+  CHARACTER(len=3)                      :: bb2
+  CHARACTER(len=2)                      :: bb3
+  character(len=6)                      :: ocean
+  CHARACTER(len=3)                      :: ctetaSTD(nbteta)
+  integer, dimension(nfiles)            :: nid_fil
+  real, dimension(nfiles)               :: ecrit_files
+  CHARACTER(len=20), dimension(nfiles)  :: name_files
+  INTEGER, dimension(iim*jjmp1)         ::  ndex2d
+  INTEGER, dimension(iim*jjmp1*klev)    :: ndex3d
+  integer                               :: imin_ins, imax_ins
+  integer                               :: jmin_ins, jmax_ins
+
+   name_files(1) = 'histmth'
+   name_files(2) = 'histday'
+   name_files(3) = 'histhf'
+   name_files(4) = 'histins'
+
+   type_ecri(1) = 'ave(X)'
+   type_ecri(2) = 'ave(X)'
+   type_ecri(3) = 'ave(X)'
+   type_ecri(4) = 'inst(X)'
+
+   clef_files(1) = ok_mensuel
+   clef_files(2) = ok_journe
+   clef_files(3) = ok_hf
+   clef_files(4) = ok_instan
+
+   lev_files(1) = lev_histmth
+   lev_files(2) = lev_histday
+   lev_files(3) = lev_histhf
+   lev_files(4) = 1
+
+   ecrit_files(1) = ecrit_mth
+   ecrit_files(2) = ecrit_day
+   ecrit_files(3) = ecrit_hf
+   ecrit_files(4) = ecrit_ins
  
 !!!!!!!!!!!!!!!!!!!!!!! Boucle sur les fichiers !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -360,76 +363,53 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-      DO iff=1,nfiles
-  
-       IF (clef_files(iff)) THEN
+ DO iff=1,nfiles
+
+    IF (clef_files(iff)) THEN
       
-         zstophy = dtime         ! Frequence ou l on moyenne
-         zout = ecrit_files(iff) ! Frequence ou l on ecrit
-
-          idayref = day_ref
-
-          CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-
-!         print*,'Dans hist_def, name_files(iff) ',name_files(iff)
+      zstophym(iff) = dtime         ! Frequence ou l on moyenne
+      zoutm(iff) = ecrit_files(iff) ! Frequence ou l on ecrit
+
+      idayref = day_ref
+      CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
 
 !!!!!!!!!!!!!!!!! Traitement dans le cas ou l'on veut stocker sur un domaine limite !!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-         if (ok_reglim(iff)) then
-
-! a reecrire plus simplement en appelant io_lat et io_lon de iophy
-
-           CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
-           CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
-
-           DO i = 1, iim
-              zx_lon(i,1) = rlon(i+1)
-              zx_lon(i,jjmp1) = rlon(i+1)
-           ENDDO
-
-                
-           imin_ins=1
-           imax_ins=iim
-           jmin_ins=1
-           jmax_ins=jjmp1
-
-           do i=1,iim-1
-            if (zx_lon(i,1).lt.lonmin_reg(iff)) imin_ins=i
-            if (zx_lon(i,1).le.lonmax_reg(iff)) imax_ins=i+1
-           enddo
-
-           do j=1,jjmp1-1
-            if (zx_lat(1,j).ge.latmin_reg(iff)) jmax_ins=j
-            if (zx_lat(1,j).gt.latmax_reg(iff)) jmin_ins=j
-           enddo
-
+     if (ok_reglim(iff)) then
+
+        imin_ins=1
+        imax_ins=iim
+        jmin_ins=1
+        jmax_ins=jjmp1
+
+        do i=1,iim-1
+           print*,'io_lon(i)=',io_lon(i)
+           if (io_lon(i).le.lonmin_reg(iff)) imin_ins=i
+           if (io_lon(i).le.lonmax_reg(iff)) imax_ins=i
+        enddo
+
+        do j=1,jjmp1-1
+            print*,'io_lat(j)=',io_lat(j)
+            if (io_lat(j).ge.latmin_reg(iff)) jmax_ins=j
+            if (io_lat(j).ge.latmax_reg(iff)) jmin_ins=j
+        enddo
 
          print*,'On stoke le fichier hist sur, ', &
-     &   imin_ins,imax_ins,jmin_ins,jmax_ins 
+         imin_ins,imax_ins,jmin_ins,jmax_ins
          print*,'On stoke le fichier instantanne sur, ', &
-     &   zx_lon(imin_ins,1),zx_lon(imax_ins,1), &
-     &   zx_lat(1,jmin_ins),zx_lat(1,jmax_ins)
-
-     
-         CALL histbeg(name_files(iff),iim,zx_lon(:,1), &
-     &                jjmp1,zx_lat(1,:), &
-     &            imin_ins,imax_ins-imin_ins+1, &
-     &           jmin_ins,jmax_ins-jmin_ins+1, &
-     &           itau_phy, zjulian, dtime, &
-     &          nhori, nid_fil(iff))
-
+         io_lon(imin_ins),io_lon(imax_ins), &
+         io_lat(jmin_ins),io_lat(jmax_ins)
+
+ CALL histbeg(name_files(iff),iim,io_lon,jjmp1,io_lat, &
+              imin_ins,imax_ins-imin_ins+1, &
+              jmin_ins,jmax_ins-jmin_ins+1, &
+              itau_phy,zjulian,dtime,nhorim(iff),nid_fil(iff))
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        else
-
-          CALL histbeg_phy(name_files(iff),itau_phy, & 
-     &                     zjulian, dtime, &
-     &                     nhori, nid_fil(iff))
+ CALL histbeg_phy(name_files(iff),itau_phy,zjulian,dtime,nhorim(iff),nid_fil(iff))
        endif
  
-          nid_files(iff)=nid_fil(iff)
-!         print*,'Dans hist_def, nid_files(iff) ',nid_files(iff)
-
-         CALL histvert(nid_files(iff),"presnivs", &
-     &                 "Vertical levels","mb", &
-     &                 klev, presnivs/100., nvert)
+      nid_files(iff)=nid_fil(iff)
+
+ CALL histvert(nid_files(iff),"presnivs","Vertical levels","mb",klev, presnivs/100., nvertm(iff))
 
 !!!!!!!!!!!!! Traitement des champs 3D pour histhf !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -438,761 +418,138 @@
 !          CALL histbeg_phy("histhf3d",itau_phy, &
 !     &                     zjulian, dtime, &
-!     &                     nhori, nid_hf3d)
+!     &                     nhorim, nid_hf3d)
 
 !         CALL histvert(nid_hf3d,"presnivs", &
 !     &                 "Vertical levels","mb", &
-!     &                 klev, presnivs/100., nvert)
+!     &                 klev, presnivs/100., nvertm)
 !          ENDIF
 
-
 !!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-       IF (flag_phis(iff)<=lev_files(iff)) THEN
-        CALL  histdef(nid_files(iff),"phis", &
-     &                 "Surface geop. height", "m2/s2", &
-     &	              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                 "once",  zstophy,zout)
-       ENDIF
-
-       IF (flag_aire(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "aire", "Grid area", "-", &
-     &               iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              "once",  zstophy,zout)
-       ENDIF
-
-
-       IF (flag_contfracATM(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), &
-     &               "contfracATM","% sfce ter+lic ", &
-     &               "-", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "once", zstophy,zout)
-      ENDIF
-
-       IF (flag_contfracOR(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), &
-     &                "contfracOR","% sfce terre OR", &
-     &                 "-", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "once", zstophy,zout)
-      ENDIF
-
-       IF (flag_aireTER(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), &
-     &                "aireTER","Grid area CONT","-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "once", zstophy,zout)
-      ENDIF
+ CALL histdef2d(iff,flag_phis,"phis","Surface geop.height","m2/s2") 
+ CALL histdef2d(iff,flag_aire,"aire","Grid area","-")
+ CALL histdef2d(iff,flag_contfracATM,"contfracATM","% sfce ter+lic","-")
+ CALL histdef2d(iff,flag_contfracOR,"contfracOR","% sfce terre OR","-" )
+ CALL histdef2d(iff,flag_aireTER,"aireTER","Grid area CONT","-" )
 
 !!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-       IF (flag_flat(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "flat", "Latent heat flux", &
-     &                "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_slp(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "slp", &
-     &               "Sea Level Pressure", "Pa", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_tsol(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "tsol", &
-     &                "Surface Temperature", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-       ENDIF
-
-       IF (flag_t2m(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "t2m", &
-     &                "Temperature 2m", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_t2m_min(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "t2m_min", &
-     &                "Temp 2m min", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "t_min(X)", zstophy,zout)
-      ENDIF
-
-       IF (flag_t2m_max(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "t2m_max", &
-     &                "Temp 2m max", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "t_max(X)", zstophy,zout)
-      ENDIF
-
-       IF (flag_wind10m(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff), "wind10m", &
-     &                "10-m wind speed","m/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_wind10max(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "wind10max", &
-     &                "10-m wind speed max.", "m/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "t_max(X)", zstophy,zout)
-       ENDIF
-
-       IF (flag_sicf(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "sicf", &
-     &                "Sea-ice fraction", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_q2m(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "q2m", &
-     &                "Specific humidity 2m", &
-     &                "kg/kg", iim,jj_nb,nhori, & 
-     &                1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-       ENDIF
-
-       IF (flag_u10m(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "u10m", &
-     &                "Vent zonal 10m", "m/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_v10m(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "v10m", &
-     &                "Vent meridien 10m", &
-     &                "m/s", iim,jj_nb,nhori, &
-     &                1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_psol(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"psol", &
-     &                "Surface Pressure","Pa", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_qsurf(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"qsurf", &
-     &                "Surface Air humidity", &
-     &             "kg/kg",iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-      if (.not. ok_veget) then
-       IF (flag_qsol(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "qsol", &
-     &                "Soil watter content", &
-     &                "mm", iim,jj_nb,nhori, &
-     &                 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-      endif
-
-       IF (flag_ndayrain(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ndayrain", &
-     &            "Number of day with rain (liq+sol)", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-      ENDIF
-
-       IF (flag_precip(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"precip", &
-     &         "Precip Totale liq+sol","kg/(s*m2)", &
-     &             iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &               type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_plul(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "plul", &
-     &             "Large-scale Precip.","kg/(s*m2)", &
-     &               iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                  type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_pluc(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "pluc", &
-     &              "Convective Precip.", "kg/(s*m2)", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_snow(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff),"snow", &
-     &               "Snow fall","kg/(s*m2)", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_evap(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"evap", &
-     &                "Evaporat", "kg/(s*m2)", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_tops(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff),"tops", &
-     &                "Solar rad. at TOA","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_tops0(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff),"tops0", &
-     &               "CS Solar rad. at TOA", &
-     &          "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_topl(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "topl", &
-     &               "IR rad. at TOA", &
-     &          "W/m2",iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_topl0(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"topl0", &
-     &                "IR rad. at TOA","W/m2", &
-     &                 iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWupTOA(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"SWupTOA", &
-     &                "SWup at TOA","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWupTOAclr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWupTOAclr", &
-     &                "SWup clear sky at TOA","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdnTOA(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"SWdnTOA", &
-     &                "SWdn at TOA","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdnTOAclr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWdnTOAclr", &
-     &                "SWdn clear sky at TOA","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWup200(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"SWup200", &
-     &                "SWup at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWup200clr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWup200clr", &
-     &              "SWup clear sky at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdn200(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"SWdn200", &
-     &                "SWdn at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdn200clr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWdn200clr", &
-     &                "SWdn clear sky at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWup200(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"LWup200", &
-     &                "LWup at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWup200clr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "LWup200clr", &
-     &                "LWup clear sky at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWdn200(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"LWdn200", &
-     &                "LWdn at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWdn200clr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "LWdn200clr", &
-     &                "LWdn clear sky at 200mb","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_sols(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "sols", &
-     &               "Solar rad. at surf.", &
-     &           "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_sols0(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "sols0", &
-     &                "Solar rad. at surf.", &
-     &            "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_soll(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"soll", &
-     &               "IR rad. at surface","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_radsol(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"radsol", &
-     &               "Rayonnement au sol", &
-     &          "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_soll0(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "soll0", &
-     &                "IR rad. at surface", &
-     &             "W/m2",iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWupSFC(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWupSFC", &
-     &               "SWup at surface", &
-     &                "W/m2",iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWupSFCclr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWupSFCclr", &
-     &                "SWup clear sky at surface","W/m2", &
-     &               iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdnSFC(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"SWdnSFC", &
-     &               "SWdn at surface","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdnSFCclr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWdnSFCclr", &
-     &                "SWdn clear sky at surface","W/m2", &
-     &               iim,jj_nb,nhori, 1,1,1,-99, &
-     &                32, type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWupSFC(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"LWupSFC", &
-     &               "Upwd. IR rad. at surface", "W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWdnSFC(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"LWdnSFC", &
-     &                "Down. IR rad. at surface", &
-     &            "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWupSFCclr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"LWupSFCclr", &
-     &                "CS Upwd. IR rad. at surface", &
-     &            "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWdnSFCclr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"LWdnSFCclr", &
-     &                "Down. CS IR rad. at surface", &
-     &                "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_bils(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), &
-     &                "bils","Surf. total heat flux","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_sens(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"sens", &
-     &                "Sensible heat flux","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_fder(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"fder", &
-     &                "Heat flux derivation","W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_ffonte(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff),"ffonte", &
-     &                "Thermal flux for snow melting", &
-     &                "W/m2",iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_fqcalving(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "fqcalving", &
-     &                 "Ice Calving", &
-     &            "kg/m2/s",iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_fqfonte(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "fqfonte", &
-     &                "Land ice melt", &
-     &           "kg/m2/s",iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-         DO nsrf = 1, nbsrf
-            IF (flag_pourc_sol(iff)<=lev_files(iff)) THEN
-         call histdef(nid_files(iff), "pourc_"//clnsurf(nsrf), &
-     &                "% "//clnsurf(nsrf), "%", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-            ENDIF
-
-            IF (flag_fract_sol(iff)<=lev_files(iff)) THEN
-         call histdef(nid_files(iff), "fract_"//clnsurf(nsrf), &
-     &         "Fraction "//clnsurf(nsrf), "1", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-            ENDIF
-
-           IF (flag_taux_sol(iff)<=lev_files(iff)) THEN
-             call histdef(nid_files(iff), "taux_"//clnsurf(nsrf), &
-     &         "Zonal wind stress"//clnsurf(nsrf), "Pa", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-           ENDIF
-
-           IF (flag_tauy_sol(iff)<=lev_files(iff)) THEN           
-             call histdef(nid_files(iff), "tauy_"//clnsurf(nsrf), &
-     &         "Meridional wind stress "//clnsurf(nsrf), "Pa", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-           ENDIF
-
-          IF (flag_tsol_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "tsol_"//clnsurf(nsrf), &
-     &         "Temperature "//clnsurf(nsrf), "K", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-          ENDIF
-
-          IF (flag_u10m_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "u10m_"//clnsurf(nsrf), &
-     &         "Vent Zonal 10m "//clnsurf(nsrf), "m/s", &
-     &          iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &          type_ecri(iff), zstophy,zout)
-          ENDIF
-
-          IF (flag_v10m_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "v10m_"//clnsurf(nsrf), &
-     &         "Vent meredien 10m "//clnsurf(nsrf), "m/s", &
-     &          iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &          type_ecri(iff), zstophy,zout)
-          ENDIF
- 
-          IF (flag_t2m_sol(iff)<=lev_files(iff)) THEN
-            call histdef(nid_files(iff), "t2m_"//clnsurf(nsrf), &
-     &            "Temp 2m "//clnsurf(nsrf), "K", &
-     &            iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &            type_ecri(iff), zstophy,zout)
-          ENDIF
-
-          IF (flag_sens_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "sens_"//clnsurf(nsrf), &
-     &         "Sensible heat flux "//clnsurf(nsrf), "W/m2", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-          ENDIF
-
-          IF (flag_lat_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "lat_"//clnsurf(nsrf), &
-     &         "Latent heat flux "//clnsurf(nsrf), "W/m2", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-          ENDIF
-
-          IF (flag_flw_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "flw_"//clnsurf(nsrf), &
-     &         "LW "//clnsurf(nsrf), "W/m2", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-         ENDIF
-
-          IF (flag_fsw_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "fsw_"//clnsurf(nsrf), &
-     &         "SW "//clnsurf(nsrf), "W/m2", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-         ENDIF
-
-          IF (flag_wbils_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "wbils_"//clnsurf(nsrf), &
-     &         "Bilan sol "//clnsurf(nsrf), "W/m2", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-         ENDIF
-
-          IF (flag_wbilo_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "wbilo_"//clnsurf(nsrf), &
-     &         "Bilan eau "//clnsurf(nsrf), "kg/(m2*s)", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-         ENDIF
-
-         if (iflag_pbl>1 .and. lev_files(iff).gt.10 ) then
-          IF (flag_tke_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "tke_"//clnsurf(nsrf), &
-     &         "Max Turb. Kinetic Energy "//clnsurf(nsrf), "-", &
-     &         iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &         type_ecri(iff), zstophy,zout)
-          ENDIF
-
-          IF (flag_tke_max_sol(iff)<=lev_files(iff)) THEN
-           call histdef(nid_files(iff), "tke_max_"//clnsurf(nsrf), &
-     &         "Max Turb. Kinetic Energy "//clnsurf(nsrf), "-", &
-     &         iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &         "t_max(X)", zstophy,zout)
-          ENDIF
-         endif
-
-        END DO
-
-        IF (flag_cdrm(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cdrm", &
-     &                "Momentum drag coef.", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_cdrh(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cdrh", &
-     &                "Heat drag coef.", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_cldl(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cldl", &
-     &                "Low-level cloudiness", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_cldm(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cldm", &
-     &                "Mid-level cloudiness", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_cldh(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cldh", &
-     &                "High-level cloudiness", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_cldt(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cldt", &
-     &                "Total cloudiness", "%", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_cldq(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"cldq", &
-     &                "Cloud liquid water path","kg/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_lwp(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"lwp", &
-     &                "Cloud water path","kg/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_iwp(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"iwp", &
-     &                "Cloud ice water path","kg/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_ue(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ue", &
-     &                "Zonal energy transport", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_ve(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ve", &
-     &                "Merid energy transport", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_uq(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "uq", &
-     &                "Zonal humidity transport", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_vq(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "vq", &
-     &                "Merid humidity transport", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-      IF(iflag_con.GE.3) THEN ! sb
-        IF (flag_cape(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cape", &
-     &                "Conv avlbl pot ener", "J/kg", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_pbase(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "pbase", &
-     &                "Cld base pressure", "mb", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_ptop(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ptop", &
-     &                "Cld top pressure", "mb", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_fbase(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "fbase", &
-     &                "Cld base mass flux", "kg/m2/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_prw(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "prw", &
-     &                "Precipitable water", "kg/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-      ENDIF !iflag_con .GE. 3
-
-        IF (flag_s_pblh(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_pblh", &
-     &                "Boundary Layer Height", "m", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_pblt(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_pblt", &
-     &               "t at Boundary Layer Height","K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_lclt(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_lcl", &
-     &                "Condensation level", "m", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_capCL(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_capCL", &
-     &               "Conv avlbl pot enerfor ABL", "J/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_oliqCLL(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_oliqCL", &
-     &                "Liq Water in BL", "kg/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_cteiCL(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_cteiCL", &
-     &               "Instability criteria(ABL)", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_therm(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "s_therm", &
-     &                "Exces du thermique", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_trmb1(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_trmb1", &
-     &                "deep_cape(HBTM2)", "J/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_trmb2(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_trmb2", &
-     &                "inhibition (HBTM2)", "J/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_s_trmb3(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "s_trmb3", &
-     &                "Point Omega (HBTM2)", "m", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-        ENDIF
+ CALL histdef2d(iff,flag_flat,"flat","Latent heat flux","W/m2")
+ CALL histdef2d(iff,flag_slp,"slp","Sea Level Pressure", "Pa" )
+ CALL histdef2d(iff,flag_tsol,"tsol","Surface Temperature", "K")
+ CALL histdef2d( iff,flag_t2m,"t2m","Temperature 2m", "K" )
+ CALL histdef2d(iff,flag_t2m_min,"t2m_min","Temp 2m min", "K" )
+ CALL histdef2d(iff,flag_t2m_max,"t2m_max", "Temp 2m max", "K" )
+ CALL histdef2d(iff,flag_wind10m,"wind10m","10-m wind speed","m/s")
+ CALL histdef2d(iff,flag_wind10max,"wind10max","10m wind speed max","m/s")
+ CALL histdef2d(iff,flag_sicf,"sicf","Sea-ice fraction", "-" )
+ CALL histdef2d(iff,flag_q2m,"q2m","Specific humidity 2m", "kg/kg")
+ CALL histdef2d(iff,flag_u10m,"u10m","Vent zonal 10m", "m/s" )
+ CALL histdef2d(iff,flag_v10m,"v10m","Vent meridien 10m", "m/s")
+ CALL histdef2d(iff,flag_psol,"psol","Surface Pressure","Pa" ) 
+ CALL histdef2d(iff,flag_qsurf,"qsurf","Surface Air humidity", "kg/kg")
+
+  if (.not. ok_veget) then
+ CALL histdef2d(iff,flag_qsol,"qsol","Soil watter content", "mm" )
+  endif
+
+ CALL histdef2d(iff,flag_ndayrain,"ndayrain","Number of dayrain(liq+sol)","-")
+ CALL histdef2d(iff,flag_precip,"precip","Precip Totale liq+sol","kg/(s*m2)" )
+ CALL histdef2d(iff,flag_plul,"plul","Large-scale Precip.","kg/(s*m2)") 
+ CALL histdef2d(iff,flag_pluc,"pluc","Convective Precip.","kg/(s*m2)")
+ CALL histdef2d(iff,flag_snow,"snow","Snow fall","kg/(s*m2)" )
+ CALL histdef2d(iff,flag_evap,"evap","Evaporat", "kg/(s*m2)" ) 
+ CALL histdef2d(iff,flag_tops,"tops","Solar rad. at TOA","W/m2") 
+ CALL histdef2d(iff,flag_tops0,"tops0","CS Solar rad. at TOA", "W/m2")
+ CALL histdef2d(iff,flag_topl,"topl","IR rad. at TOA", "W/m2" )
+ CALL histdef2d(iff,flag_topl0,"topl0", "IR rad. at TOA","W/m2")
+ CALL histdef2d(iff,flag_SWupTOA,"SWupTOA","SWup at TOA","W/m2") 
+ CALL histdef2d(iff,flag_SWupTOAclr,"SWupTOAclr","SWup clear sky at TOA","W/m2")
+ CALL histdef2d(iff,flag_SWdnTOA, "SWdnTOA","SWdn at TOA","W/m2" )
+ CALL histdef2d(iff,flag_SWdnTOAclr,"SWdnTOAclr","SWdn clear sky at TOA","W/m2") 
+ CALL histdef2d(iff,flag_SWup200,"SWup200","SWup at 200mb","W/m2" ) 
+ CALL histdef2d(iff,flag_SWup200clr,"SWup200clr","SWup clear sky at 200mb","W/m2")
+ CALL histdef2d(iff,flag_SWdn200,"SWdn200","SWdn at 200mb","W/m2" )
+ CALL histdef2d(iff,flag_SWdn200clr,"SWdn200clr","SWdn clear sky at 200mb","W/m2")
+ CALL histdef2d(iff,flag_LWup200,"LWup200","LWup at 200mb","W/m2") 
+ CALL histdef2d(iff,flag_LWup200clr, "LWup200clr","LWup clear sky at 200mb","W/m2")
+ CALL histdef2d(iff,flag_LWdn200,"LWdn200","LWdn at 200mb","W/m2") 
+ CALL histdef2d(iff,flag_LWdn200clr, "LWdn200clr","LWdn clear sky at 200mb","W/m2")
+ CALL histdef2d(iff,flag_sols,"sols","Solar rad. at surf.","W/m2")
+ CALL histdef2d(iff,flag_sols0,"sols0","Solar rad. at surf.","W/m2")
+ CALL histdef2d(iff,flag_soll,"soll","IR rad. at surface","W/m2")  
+ CALL histdef2d(iff,flag_radsol,"radsol","Rayonnement au sol","W/m2")
+ CALL histdef2d(iff,flag_soll0,"soll0","IR rad. at surface","W/m2") 
+ CALL histdef2d(iff,flag_SWupSFC,"SWupSFC","SWup at surface","W/m2")
+ CALL histdef2d(iff,flag_SWupSFCclr,"SWupSFCclr","SWup clear sky at surface","W/m2")
+ CALL histdef2d(iff,flag_SWdnSFC,"SWdnSFC","SWdn at surface","W/m2")
+ CALL histdef2d(iff,flag_SWdnSFCclr,"SWdnSFCclr","SWdn clear sky at surface","W/m2")
+ CALL histdef2d(iff,flag_LWupSFC,"LWupSFC","Upwd. IR rad. at surface","W/m2")
+ CALL histdef2d(iff,flag_LWdnSFC,"LWdnSFC","Down. IR rad. at surface","W/m2")
+ CALL histdef2d(iff,flag_LWupSFCclr,"LWupSFCclr","CS Upwd. IR rad. at surface","W/m2")
+ CALL histdef2d(iff,flag_LWdnSFCclr,"LWdnSFCclr","Down. CS IR rad. at surface","W/m2")
+ CALL histdef2d(iff,flag_bils,"bils","Surf. total heat flux","W/m2")
+ CALL histdef2d(iff,flag_sens,"sens","Sensible heat flux","W/m2")
+ CALL histdef2d(iff,flag_fder,"fder","Heat flux derivation","W/m2")
+ CALL histdef2d(iff,flag_ffonte,"ffonte","Thermal flux for snow melting","W/m2")
+ CALL histdef2d(iff,flag_fqcalving,"fqcalving","Ice Calving","kg/m2/s") 
+ CALL histdef2d(iff,flag_fqfonte,"fqfonte","Land ice melt","kg/m2/s") 
+
+     DO nsrf = 1, nbsrf
+ CALL histdef2d(iff,flag_pourc_sol,"pourc_"//clnsurf(nsrf),"% "//clnsurf(nsrf),"%")
+ CALL histdef2d(iff,flag_fract_sol,"fract_"//clnsurf(nsrf),"Fraction "//clnsurf(nsrf),"1")
+ CALL histdef2d(iff,flag_taux_sol,"taux_"//clnsurf(nsrf),"Zonal wind stress"//clnsurf(nsrf),"Pa")
+ CALL histdef2d(iff,flag_tauy_sol,"tauy_"//clnsurf(nsrf),"Meridional wind stress "//clnsurf(nsrf),"Pa")
+ CALL histdef2d(iff,flag_tsol_sol,"tsol_"//clnsurf(nsrf),"Temperature "//clnsurf(nsrf),"K")
+ CALL histdef2d(iff,flag_u10m_sol,"u10m_"//clnsurf(nsrf),"Vent Zonal 10m "//clnsurf(nsrf),"m/s")
+ CALL histdef2d(iff,flag_v10m_sol,"v10m_"//clnsurf(nsrf),"Vent meredien 10m "//clnsurf(nsrf),"m/s")
+ CALL histdef2d(iff,flag_t2m_sol,"t2m_"//clnsurf(nsrf),"Temp 2m "//clnsurf(nsrf),"K")
+ CALL histdef2d(iff,flag_sens_sol,"sens_"//clnsurf(nsrf),"Sensible heat flux "//clnsurf(nsrf),"W/m2")
+ CALL histdef2d(iff,flag_lat_sol,"lat_"//clnsurf(nsrf),"Latent heat flux "//clnsurf(nsrf),"W/m2")
+ CALL histdef2d(iff,flag_flw_sol,"flw_"//clnsurf(nsrf),"LW "//clnsurf(nsrf),"W/m2")
+ CALL histdef2d(iff,flag_fsw_sol,"fsw_"//clnsurf(nsrf),"SW "//clnsurf(nsrf),"W/m2")
+ CALL histdef2d(iff,flag_wbils_sol,"wbils_"//clnsurf(nsrf),"Bilan sol "//clnsurf(nsrf),"W/m2" )
+ CALL histdef2d(iff,flag_wbilo_sol,"wbilo_"//clnsurf(nsrf),"Bilan eau "//clnsurf(nsrf),"kg/(m2*s)")
+  if (iflag_pbl>1 .and. lev_files(iff).gt.10 ) then
+ CALL histdef2d(iff,flag_tke_sol,"tke_"//clnsurf(nsrf),"Max Turb. Kinetic Energy "//clnsurf(nsrf),"-")
+ CALL histdef2d(iff,flag_tke_max_sol,"tke_max_"//clnsurf(nsrf),"Max Turb. Kinetic Energy "//clnsurf(nsrf),"-")
+  endif
+ CALL histdef2d(iff,flag_albe_sol, "albe_"//clnsurf(nsrf),"Albedo surf. "//clnsurf(nsrf),"-")
+ CALL histdef2d(iff,flag_rugs_sol,"rugs_"//clnsurf(nsrf),"Latent heat flux "//clnsurf(nsrf),"W/m2")
+ CALL histdef2d(iff,flag_ages_sol,"ages_"//clnsurf(nsrf),"Snow age","day")
+     END DO
+
+ CALL histdef2d(iff,flag_albs,"albs","Surface albedo","-")
+ CALL histdef2d(iff,flag_albslw,"albslw","Surface albedo LW","-")
+ CALL histdef2d(iff,flag_cdrm,"cdrm","Momentum drag coef.", "-")
+ CALL histdef2d(iff,flag_cdrh,"cdrh","Heat drag coef.", "-" )
+ CALL histdef2d(iff,flag_cldl,"cldl","Low-level cloudiness", "-")
+ CALL histdef2d(iff,flag_cldm,"cldm","Mid-level cloudiness", "-")
+ CALL histdef2d(iff,flag_cldh,"cldh","High-level cloudiness", "-")
+ CALL histdef2d(iff,flag_cldt,"cldt","Total cloudiness","%")
+ CALL histdef2d(iff,flag_cldq,"cldq","Cloud liquid water path","kg/m2")
+ CALL histdef2d(iff,flag_lwp,"lwp","Cloud water path","kg/m2")
+ CALL histdef2d(iff,flag_iwp,"iwp","Cloud ice water path","kg/m2" )
+ CALL histdef2d(iff,flag_ue,"ue","Zonal energy transport","-")
+ CALL histdef2d(iff,flag_ve,"ve","Merid energy transport", "-")
+ CALL histdef2d(iff,flag_uq,"uq","Zonal humidity transport", "-")
+ CALL histdef2d(iff,flag_vq,"vq","Merid humidity transport", "-")
+
+     IF(iflag_con.GE.3) THEN ! sb
+ CALL histdef2d(iff,flag_cape,"cape","Conv avlbl pot ener","J/kg")
+ CALL histdef2d(iff,flag_pbase,"pbase","Cld base pressure", "mb")
+ CALL histdef2d(iff,flag_ptop,"ptop","Cld top pressure", "mb")
+ CALL histdef2d(iff,flag_fbase,"fbase","Cld base mass flux","kg/m2/s")
+ CALL histdef2d(iff,flag_prw,"prw","Precipitable water","kg/m2")
+     ENDIF !iflag_con .GE. 3
+
+ CALL histdef2d(iff,flag_s_pblh,"s_pblh","Boundary Layer Height","m")
+ CALL histdef2d(iff,flag_s_pblt,"s_pblt","t at Boundary Layer Height","K")
+ CALL histdef2d(iff,flag_s_lcl,"s_lcl","Condensation level","m")
+ CALL histdef2d(iff,flag_s_capCL,"s_capCL","Conv avlbl pot enerfor ABL", "J/m2" )
+ CALL histdef2d(iff,flag_s_oliqCL,"s_oliqCL","Liq Water in BL","kg/m2")
+ CALL histdef2d(iff,flag_s_cteiCL,"s_cteiCL","Instability criteria(ABL)","K")
+ CALL histdef2d(iff,flag_s_therm,"s_therm","Exces du thermique", "K")
+ CALL histdef2d(iff,flag_s_trmb1,"s_trmb1","deep_cape(HBTM2)","J/m2")
+ CALL histdef2d(iff,flag_s_trmb2,"s_trmb2","inhibition (HBTM2)","J/m2")
+ CALL histdef2d(iff,flag_s_trmb3,"s_trmb3","Point Omega (HBTM2)","m")
 
 ! Champs interpolles sur des niveaux de pression
@@ -1203,670 +560,129 @@
 !      on ecrit u v t q a 850 700 500 200 au niv 3
 
-       DO k=1, nlevSTD
-         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
-         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
-         IF(bb2.EQ."850".OR.bb2.EQ."700".OR. &
-     &      bb2.EQ."500".OR.bb2.EQ."200") THEN
-
-        IF (flag_ulevsSTD(iff)<=lev_files(iff)) THEN
-          CALL histdef(nid_files(iff), "u"//bb2, &
-     &                 "Zonal wind "//bb2//"mb","m/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-        ENDIF
-
-        IF (flag_vlevsSTD(iff)<=lev_files(iff)) THEN
-          CALL histdef(nid_files(iff), "v"//bb2, &
-     &                 "Meridional wind "//bb2//"mb","m/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-        ENDIF
-
-        IF (flag_wlevsSTD(iff)<=lev_files(iff)) THEN
-          CALL histdef(nid_files(iff), "w"//bb2, &
-     &                 "Vertical wind "//bb2//"mb","m/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-        ENDIF
-
-        IF (flag_philevsSTD(iff)<=lev_files(iff)) THEN
-          CALL histdef(nid_files(iff), "phi"//bb2, &
-     &                 "Geopotential "//bb2//"mb","m", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-        ENDIF
-
-        IF (flag_qlevsSTD(iff)<=lev_files(iff)) THEN
-          CALL histdef(nid_files(iff), "q"//bb2, &
-     &               "Specific humidity "//bb2//"mb","kg/kg", &
-     &               iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &               "inst(X)", zout,zout)
-        ENDIF
-
-        IF (flag_tlevsSTD(iff)<=lev_files(iff)) THEN
-          CALL histdef(nid_files(iff), "t"//bb2, &
-     &                 "Temperature "//bb2//"mb","K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-        ENDIF
-
-       ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+        DO k=1, nlevSTD
+     IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+     IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+     IF(bb2.EQ."850".OR.bb2.EQ."700".OR.bb2.EQ."500".OR.bb2.EQ."200")THEN
+ CALL histdef2d(iff,flag_ulevsSTD,"u"//bb2,"Zonal wind "//bb2//"mb","m/s")
+ CALL histdef2d(iff,flag_vlevsSTD,"v"//bb2,"Meridional wind "//bb2//"mb","m/s")
+ CALL histdef2d(iff,flag_wlevsSTD,"w"//bb2,"Vertical wind "//bb2//"mb","m/s")
+ CALL histdef2d(iff,flag_philevsSTD,"phi"//bb2,"Geopotential "//bb2//"mb","m")
+ CALL histdef2d(iff,flag_qlevsSTD,"q"//bb2,"Specific humidity "//bb2//"mb","kg/kg" )
+ CALL histdef2d(iff,flag_tlevsSTD,"t"//bb2,"Temperature "//bb2//"mb","K")
+     ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
        ENDDO
 
 !IM diagnostiques flux ocean-atm ou ocean-glace de mer
 !IM pour utilisation dans un modele de "slab" ocean
-
-      IF (flag_fluxo(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff), "fluxo", &
-     &              "Flux turbulents ocean-atmosphere", "W/m2", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-      ENDIF
-
-      IF (flag_fluxg(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff), "fluxg", &
-     &              "Flux turbulents ocean-glace de mer","W/m2", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-      ENDIF
-
-      IF (flag_t_oce_sic(iff)<=lev_files(iff)) THEN
-       CALL histdef(nid_files(iff), "t_oce_sic", &
-     &              "Temp. mixte oce-sic","K", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (OCEAN.EQ.'force ') THEN
-        IF (flag_lmt_bils(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "lmt_bils", &
-     &       "Bilan au sol atmosphere forcee", "W/m2", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-        ENDIF
-
-       ELSE IF (OCEAN.EQ.'slab  ') THEN
-
-        IF (flag_slab_bils(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "slab_bils", &
-     &       "Bilan au sol Slab", "W/m2", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_tslab(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "tslab", "Slab SST ", "K", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_seaice(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"seaice","Slab seaice","kg/m2", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-        ENDIF
-
-        IF (flag_siceh(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"siceh", &
-     &               "Slab seaice height","m", &
-     &              iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &              type_ecri(iff), zstophy,zout)
-        ENDIF
-       ENDIF
-
-      IF (flag_weakinv(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "weakinv", &
-     &            "Weak inversion", "-", &
-     &            iim,jjmp1,nhori, 1,1,1, -99, 32, &
-     &            type_ecri(iff), zstophy,zout)
-      ENDIF
-
-      IF (flag_dthmin(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dthmin", &
-     &            "dTheta mini", "K/m", &
-     &            iim,jjmp1,nhori, 1,1,1, -99, 32, &
-     &            type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_meantaucld(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"meantaucld", &
-     &                 "ISCCP mean cloud optical thickness","1", &
-     &                 iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                 type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_cldtau(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"cldtau", &
-     &                 "Cloud optical thickness","1", &
-     &                 iim,jj_nb,nhori, klev,1,klev, nvert, 32, &
-     &                 type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_cldemi(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"cldemi", &
-     &			"Cloud optical emissivity","1", &
-     &                 iim,jj_nb,nhori, klev,1,klev, nvert, 32, &
-     &                 type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_rh2m(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "rh2m", &
-     &			"Relative humidity at 2m", "%", &
-     &                 iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                 type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_qsat2m(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "qsat2m", &
-     &			"Saturant humidity at 2m", "%", &
-     &                 iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                 type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_tpot(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "tpot", &
-     &                "Surface air potential temperature", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_tpote(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "tpote", &
-     &        "Surface air equivalent potential temperature", "K", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWnetOR(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWnetOR", &
-     &                "Sfce net SW radiation OR", "W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_SWdownOR(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "SWdownOR", &
-     &                "Sfce incident SW radiation OR", "W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_LWdownOR(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "LWdownOR", &
-     &                "Sfce incident LW radiation OR", "W/m2", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_snowl(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "snowl", &
-     &              "Solid Large-scale Precip.","kg/(m2*s)", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_cape_max(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "cape_max", "CAPE max.", &
-     &                "J/kg", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                't_max(X)', zstophy,zout)
-      ENDIF
-
-       IF (flag_solldown(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "solldown", &
-     &			"Down. IR rad. at surface", &
-     &                "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtsvdfo(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "dtsvdfo", &
-     &			"Boundary-layer dTs(o)", &
-     &               "K/s", iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &               type_ecri(iff), zout,zout)
-      ENDIF
-
-       IF (flag_dtsvdft(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "dtsvdft", &
-     &			"Boundary-layer dTs(t)", "K/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zout,zout)
-      ENDIF
-
-       IF (flag_dtsvdfg(iff)<=lev_files(iff)) THEN
-      CALL histdef(nid_files(iff), "dtsvdfg", &
-     &			"Boundary-layer dTs(g)", "K/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zout,zout)
-      ENDIF
-
-       IF (flag_dtsvdfi(iff)<=lev_files(iff)) THEN
-      CALL histdef(nid_files(iff), "dtsvdfi", &
-     &			"Boundary-layer dTs(g)", "K/s", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zout,zout)
-      ENDIF
-
-       IF (flag_rugs(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "rugs", "rugosity", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                "inst(X)", zout,zout)
-      ENDIF
+ CALL histdef2d(iff,flag_fluxo,"fluxo","Flux turbulents ocean-atmosphere","W/m2")
+ CALL histdef2d(iff,flag_fluxg,"fluxg","Flux turbulents ocean-glace de mer","W/m2")
+ CALL histdef2d(iff,flag_t_oce_sic,"t_oce_sic","Temp mixte oce-sic","K")
+
+     IF (OCEAN.EQ.'force ') THEN
+ CALL histdef2d(iff,flag_lmt_bils,"lmt_bils","Bilan au sol atmosphere forcee","W/m2")
+     ELSE IF (OCEAN.EQ.'slab  ') THEN
+ CALL histdef2d(iff,flag_slab_bils,"slab_bils","Bilan au sol Slab","W/m2") 
+ CALL histdef2d(iff,flag_tslab,"tslab", "Slab SST ", "K")
+ CALL histdef2d(iff,flag_seaice,"seaice","Slab seaice","kg/m2") 
+ CALL histdef2d(iff,flag_siceh,"siceh","Slab seaice height","m")
+     ENDIF
+
+ CALL histdef2d(iff,flag_weakinv, "weakinv","Weak inversion", "-")
+ CALL histdef2d(iff,flag_dthmin,"dthmin","dTheta mini", "K/m")
+ CALL histdef2d(iff,flag_meantaucld,"meantaucld","ISCCP mean cloud optical thickness","1")
+ CALL histdef2d(iff,flag_rh2m,"rh2m","Relative humidity at 2m", "%" )
+ CALL histdef2d(iff,flag_qsat2m,"qsat2m","Saturant humidity at 2m", "%")
+ CALL histdef2d(iff,flag_tpot,"tpot","Surface air potential temperature","K")
+ CALL histdef2d(iff,flag_tpote,"tpote","Surface air equivalent potential temperature","K")
+ CALL histdef2d(iff,flag_SWnetOR,"SWnetOR","Sfce net SW radiation OR", "W/m2")
+ CALL histdef2d(iff,flag_SWdownOR,"SWdownOR","Sfce incident SW radiation OR","W/m2")
+ CALL histdef2d(iff,flag_LWdownOR,"LWdownOR","Sfce incident LW radiation OR","W/m2")
+ CALL histdef2d(iff,flag_snowl,"snowl","Solid Large-scale Precip.","kg/(m2*s)")
+ CALL histdef2d(iff,flag_cape_max,"cape_max","CAPE max.", "J/kg")
+ CALL histdef2d(iff,flag_solldown,"solldown","Down. IR rad. at surface","W/m2")
+ CALL histdef2d(iff,flag_dtsvdfo,"dtsvdfo","Boundary-layer dTs(o)","K/s")
+ CALL histdef2d(iff,flag_dtsvdft,"dtsvdft","Boundary-layer dTs(t)","K/s")
+ CALL histdef2d(iff,flag_dtsvdfg,"dtsvdfg","Boundary-layer dTs(g)","K/s")
+ CALL histdef2d(iff,flag_dtsvdfi,"dtsvdfi","Boundary-layer dTs(g)","K/s")
+ CALL histdef2d(iff,flag_rugs,"rugs","rugosity", "-" )
 
 ! Champs 3D:
-
-       IF (flag_lwcon(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"lwcon", &
-     &                 "Cloud liquid water content","kg/kg", &
-     &                iim,jj_nb,nhori, klev,1,klev, nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_iwcon(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"iwcon", &
-     &                "Cloud ice water content","kg/kg", &
-     &                iim,jj_nb,nhori, klev,1,klev, nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_temp(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"temp","Air temperature","K", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_ovap(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ovap", &
-     &			"Specific humidity","kg/kg", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-
-       IF (flag_geop(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "geop", &
-     &			"Geopotential height", "m2/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_vitu(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "vitu", "Zonal wind", "m/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_vitv(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"vitv","Meridional wind","m/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_vitw(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"vitw","Vertical wind","m/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_pres(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "pres", "Air pressure", "Pa", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_rneb(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "rneb", "Cloud fraction", "-", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_rnebcon(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "rnebcon", &
-     &		      "Convective Cloud Fraction", "-", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_rhum(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "rhum", "Relative humidity", "-", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_ozone(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ozone", &
-     &			"Ozone concentration", "ppmv", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_upwd(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "upwd", &
-     &			"saturated updraft", "kg/m2/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtphy(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtphy", "Physics dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqphy(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dqphy", &
-     &			"Physics dQ", "(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-        DO nsrf=1, nbsrf
-          IF (flag_albe_sol(iff)<=lev_files(iff)) THEN 
-           call histdef(nid_files(iff), "albe_"//clnsurf(nsrf), &
-     &          "Albedo surf. "//clnsurf(nsrf), "-", &
-     &          iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &          type_ecri(iff), zstophy,zout)
-        ENDIF
-
-          IF (flag_rugs_sol(iff)<=lev_files(iff)) THEN  
-           call histdef(nid_files(iff), "rugs_"//clnsurf(nsrf), &
-     &          "Latent heat flux "//clnsurf(nsrf), "W/m2", &
-     &         iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &         type_ecri(iff), zstophy,zout)
-       ENDIF
-
-        IF (flag_ages_sol(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), &
-     &		"ages_"//clnsurf(nsrf), "Snow age","day", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-       ENDIF
-
-         ENDDO !nsrf=1, nbsrf
-
-       IF (flag_albs(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"albs","Surface albedo","-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_albslw(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"albslw", &
-     & 			"Surface albedo LW", "-", &
-     &                iim,jj_nb,nhori, 1,1,1, -99, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
+ CALL histdef3d(iff,flag_lwcon,"lwcon","Cloud liquid water content","kg/kg")
+ CALL histdef3d(iff,flag_iwcon,"iwcon","Cloud ice water content","kg/kg")
+ CALL histdef3d(iff,flag_temp,"temp","Air temperature","K" )
+ CALL histdef3d(iff,flag_ovap,"ovap","Specific humidity","kg/kg" )
+ CALL histdef3d(iff,flag_geop,"geop","Geopotential height","m2/s2")
+ CALL histdef3d(iff,flag_vitu,"vitu","Zonal wind", "m/s" )
+ CALL histdef3d(iff,flag_vitv,"vitv","Meridional wind","m/s" )
+ CALL histdef3d(iff,flag_vitw,"vitw","Vertical wind","m/s" )
+ CALL histdef3d(iff,flag_pres,"pres","Air pressure", "Pa" )
+ CALL histdef3d(iff,flag_rneb,"rneb","Cloud fraction","-")
+ CALL histdef3d(iff,flag_rnebcon,"rnebcon","Convective Cloud Fraction","-")
+ CALL histdef3d(iff,flag_rhum,"rhum","Relative humidity","-")
+ CALL histdef3d(iff,flag_ozone,"ozone","Ozone concentration", "ppmv")
+ CALL histdef3d(iff,flag_upwd,"upwd","saturated updraft", "kg/m2/s")
+ CALL histdef3d(iff,flag_dtphy,"dtphy","Physics dT","K/s")
+ CALL histdef3d(iff,flag_dqphy,"dqphy","Physics dQ", "(kg/kg)/s")
+ CALL histdef3d(iff,flag_cldtau,"cldtau","Cloud optical thickness","1")
+ CALL histdef3d(iff,flag_cldemi,"cldemi","Cloud optical emissivity","1")
+ CALL histdef3d(iff,flag_pr_con_l,"pmflxr","Convective precipitation lic"," ")
+ CALL histdef3d(iff,flag_pr_con_i,"pmflxs","Convective precipitation ice"," ")
+ CALL histdef3d(iff,flag_pr_lsc_l,"prfl","Large scale precipitation lic"," ")
+ CALL histdef3d(iff,flag_pr_lsc_i,"psfl","Large scale precipitation ice"," ")
 
 !FH Sorties pour la couche limite
-      if (iflag_pbl>1) then
-       IF (flag_tke(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "tke","TKE","m2/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_tke_max(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "tke_max","TKE max","m2/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                "t_max(X)", zstophy,zout)
-      ENDIF
+     if (iflag_pbl>1) then
+ CALL histdef3d(iff,flag_tke,"tke","TKE","m2/s2")
+ CALL histdef3d(iff,flag_tke_max,"tke_max","TKE max","m2/s2")
+     endif
+
+ CALL histdef3d(iff,flag_kz,"kz","Kz melange","m2/s")
+ CALL histdef3d(iff,flag_kz_max,"kz_max","Kz melange max","m2/s" )
+ CALL histdef3d(iff,flag_clwcon,"clwcon","Convective Cloud Liquid water content", "kg/kg") 
+ CALL histdef3d(iff,flag_Ma,"Ma","undilute adiab updraft","kg/m2/s")
+ CALL histdef3d(iff,flag_dnwd,"dnwd","saturated downdraft","kg/m2/s")
+ CALL histdef3d(iff,flag_dnwd0,"dnwd0","unsat. downdraft", "kg/m2/s")
+ CALL histdef3d(iff,flag_dtdyn,"dtdyn","Dynamics dT","K/s")
+ CALL histdef3d(iff,flag_dqdyn,"dqdyn","Dynamics dQ", "(kg/kg)/s")
+ CALL histdef3d(iff,flag_dtcon,"dtcon","Convection dT","K/s")
+ CALL histdef3d(iff,flag_ducon,"ducon","Convection du","m/s2")
+ CALL histdef3d(iff,flag_dqcon,"dqcon","Convection dQ", "(kg/kg)/s")
+ CALL histdef3d(iff,flag_dtlsc,"dtlsc","Condensation dT", "K/s")
+ CALL histdef3d(iff,flag_dtlschr,"dtlschr","Large-scale condensational heating rate","K/s")
+ CALL histdef3d(iff,flag_dqlsc,"dqlsc","Condensation dQ","(kg/kg)/s")
+ CALL histdef3d(iff,flag_dtvdf,"dtvdf","Boundary-layer dT", "K/s")
+ CALL histdef3d(iff,flag_dqvdf,"dqvdf","Boundary-layer dQ","(kg/kg)/s") 
+ CALL histdef3d(iff,flag_dteva,"dteva","Reevaporation dT", "K/s")
+ CALL histdef3d(iff,flag_dqeva,"dqeva","Reevaporation dQ","(kg/kg)/s")
+ CALL histdef3d(iff,flag_ptconv,"ptconv","POINTS CONVECTIFS"," ")
+ CALL histdef3d(iff,flag_ratqs,"ratqs", "RATQS"," ")
+ CALL histdef3d(iff,flag_dtthe,"dtthe","Dry adjust. dT", "K/s")
+ CALL histdef3d(iff,flag_dqthe,"dqthe","Dry adjust. dQ","(kg/kg)/s")
+ CALL histdef3d(iff,flag_dtajs,"dtajs","Dry adjust. dT", "K/s")
+ CALL histdef3d(iff,flag_dqajs,"dqajs","Dry adjust. dQ","(kg/kg)/s")
+ CALL histdef3d(iff,flag_dtswr,"dtswr","SW radiation dT","K/s")
+ CALL histdef3d(iff,flag_dtsw0,"dtsw0","CS SW radiation dT","K/s")
+ CALL histdef3d(iff,flag_dtlwr,"dtlwr","LW radiation dT","K/s")
+ CALL histdef3d(iff,flag_dtlw0,"dtlw0", "CS LW radiation dT","K/s")
+ CALL histdef3d(iff,flag_dtec,"dtec","Cinetic dissip dT","K/s")
+ CALL histdef3d(iff,flag_duvdf,"duvdf","Boundary-layer dU","m/s2")
+ CALL histdef3d(iff,flag_dvvdf,"dvvdf","Boundary-layer dV", "m/s2")
+
+     IF (ok_orodr) THEN
+ CALL histdef3d(iff,flag_duoro,"duoro","Orography dU","m/s2")
+ CALL histdef3d(iff,flag_dvoro,"dvoro","Orography dV", "m/s2")
+     ENDIF
+
+     IF (ok_orolf) THEN
+ CALL histdef3d(iff,flag_dulif,"dulif","Orography dU","m/s2")
+ CALL histdef3d(iff,flag_dvlif,"dvlif","Orography dV", "m/s2")
+     ENDIF
+
+      if (nqmax>=3) THEN
+    DO iq=3,nqmax
+       iiq=niadv(iq)
+ CALL histdef3d ( iff, flag_trac, tnom(iq),ttext(iiq), "-" )
+    ENDDO
       endif
-
-       IF (flag_kz(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "kz","Kz melange","m2/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_kz_max(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "kz_max", &
-     &			"Kz melange max","m2/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                "t_max(X)", zstophy,zout)
-      ENDIF
-
-       IF (flag_clwcon(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "clwcon", &
-     &                "Convective Cloud Liquid water content", &
-     &                 "kg/kg", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_Ma(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"Ma", &
-     &			"undilute adiab updraft","kg/m2/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dnwd(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dnwd", &
-     &			"saturated downdraft","kg/m2/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dnwd0(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dnwd0", &
-     &			"unsat. downdraft", "kg/m2/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtdyn(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"dtdyn","Dynamics dT","K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqdyn(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dqdyn", &
-     &			"Dynamics dQ", "(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtcon(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"dtcon","Convection dT","K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_ducon(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff),"ducon","Convection du","m/s2", &
-     &               iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &               type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqcon(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dqcon", &
-     &			"Convection dQ", "(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtlsc(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtlsc", &
-     &			"Condensation dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtlschr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtlschr", &
-     &                "Large-scale condensational heating rate", &
-     &                "K/s",iim,jj_nb, nhori, klev,1,klev,nvert, &
-     &                 32,type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqlsc(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dqlsc", &
-     &	              "Condensation dQ", "(kg/kg)/s", &
-     &               iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtvdf(iff)<=lev_files(iff)) THEN
-        CALL histdef(nid_files(iff), "dtvdf", &
-     &                "Boundary-layer dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqvdf(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dqvdf", &
-     &                "Boundary-layer dQ","(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dteva(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dteva", &
-     &			"Reevaporation dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqeva(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dqeva", &
-     &			"Reevaporation dQ","(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_ptconv(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ptconv", &
-     &			"POINTS CONVECTIFS"," ", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_ratqs(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "ratqs", "RATQS"," ", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtthe(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtthe", &
-     &			"Dry adjust. dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqthe(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"dqthe", &
-     &                "Dry adjust. dQ","(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtajs(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtajs", &
-     &			"Dry adjust. dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dqajs(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"dqajs", &
-     &			"Dry adjust. dQ","(kg/kg)/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtswr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtswr", &
-     & 			"SW radiation dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtsw0(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtsw0", &
-     &			"CS SW radiation dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtlwr(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtlwr", &
-     &			"LW radiation dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtlw0(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff),"dtlw0", &
-     &			"CS LW radiation dT","K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dtec(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dtec", &
-     &			"Cinetic dissip dT", "K/s", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_duvdf(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "duvdf", &
-     &			"Boundary-layer dU", "m/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dvvdf(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dvvdf", &
-     & 		"Boundary-layer dV", "m/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-         IF (ok_orodr) THEN
-       IF (flag_duoro(iff)<=lev_files(iff)) THEN 
-         CALL histdef(nid_files(iff), "duoro", &
-     &			"Orography dU", "m/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-       IF (flag_dvoro(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dvoro", &
-     &			"Orography dV", "m/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-      ENDIF
-
-         ENDIF
-
-      IF (ok_orolf) THEN
-       IF (flag_dulif(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dulif", &
-     &                "Orography dU", "m/s2", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-       ENDIF
-
-       IF (flag_dvlif(iff)<=lev_files(iff)) THEN
-         CALL histdef(nid_files(iff), "dvlif", &
-     &			"Orography dV", "m/s2", &
-     &               iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-       ENDIF
-      ENDIF
-
-          IF (flag_trac(iff)<=lev_files(iff)) THEN
-           if (nqmax>=3) THEN
-             DO iq=3,nqmax
-              iiq=niadv(iq)
-         CALL histdef(nid_files(iff),tnom(iq),ttext(iiq), "-", &
-     &                iim,jj_nb,nhori, klev,1,klev,nvert, 32, &
-     &                type_ecri(iff), zstophy,zout)
-             ENDDO
-           endif
-         ENDIF
 
         CALL histend(nid_files(iff))
@@ -1880,4 +696,59 @@
       end subroutine phys_output_open
 
+      SUBROUTINE histdef2d (iff,flag_var,nomvar,titrevar,unitvar)
+      
+       use ioipsl
+       USE dimphy
+       USE mod_phys_lmdz_para
+
+       IMPLICIT NONE
+       
+       include "dimensions.h"
+       include "temps.h"
+       include "indicesol.h"
+       include "advtrac.h"
+       include "clesphys.h"
+
+       integer                          :: iff
+       integer, dimension(nfiles)       :: flag_var
+       character(len=*)                 :: nomvar
+       character(len=*)                 :: titrevar
+       character(len=*)                 :: unitvar
+       
+       if ( flag_var(iff)<=lev_files(iff) ) then
+ call histdef (nid_files(iff),nomvar,titrevar,unitvar, &
+               iim,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
+               type_ecri(iff), zstophym(iff),zoutm(iff))                
+       endif                      
+      end subroutine histdef2d
+
+      SUBROUTINE histdef3d (iff,flag_var,nomvar,titrevar,unitvar)
+
+       use ioipsl
+       USE dimphy
+       USE mod_phys_lmdz_para
+
+       IMPLICIT NONE
+
+       include "dimensions.h"
+       include "temps.h"
+       include "indicesol.h"
+       include "advtrac.h"
+       include "clesphys.h"
+
+       integer                          :: iff
+       integer, dimension(nfiles)       :: flag_var
+       character(len=*)                 :: nomvar
+       character(len=*)                 :: titrevar
+       character(len=*)                 :: unitvar
+
+       if ( flag_var(iff)<=lev_files(iff) ) then
+ call histdef (nid_files(iff),nomvar,titrevar,unitvar, &
+               iim,jj_nb,nhorim(iff), klev,1,klev,nvertm(iff), 32, &
+               type_ecri(iff), zstophym(iff),zoutm(iff))
+       endif
+      end subroutine histdef3d
+
+
 END MODULE phys_output_mod
 
Index: LMDZ4/trunk/libf/phylmd/phys_output_write.h
===================================================================
--- LMDZ4/trunk/libf/phylmd/phys_output_write.h	(revision 928)
+++ LMDZ4/trunk/libf/phylmd/phys_output_write.h	(revision 929)
@@ -519,5 +519,5 @@
         ENDIF
 
-        IF (flag_s_lclt(iff)<=lev_files(iff)) THEN
+        IF (flag_s_lcl(iff)<=lev_files(iff)) THEN
       CALL histwrite_phy(nid_files(iff),"s_lcl",itau_w,s_lcl)
         ENDIF
@@ -527,5 +527,5 @@
         ENDIF
 
-        IF (flag_s_oliqCLL(iff)<=lev_files(iff)) THEN
+        IF (flag_s_oliqCL(iff)<=lev_files(iff)) THEN
       CALL histwrite_phy(nid_files(iff),"s_oliqCL",itau_w,s_oliqCL)
         ENDIF
@@ -706,4 +706,20 @@
        IF (flag_cldemi(iff)<=lev_files(iff)) THEN
        CALL histwrite_phy(nid_files(iff),"cldemi",itau_w,cldemi)
+       ENDIF
+
+       IF (flag_pr_con_l(iff)<=lev_files(iff)) THEN
+       CALL histwrite_phy(nid_files(iff),"pmflxr",itau_w,pmflxr)
+       ENDIF
+
+       IF (flag_pr_con_i(iff)<=lev_files(iff)) THEN
+       CALL histwrite_phy(nid_files(iff),"pmflxs",itau_w,pmflxs)
+       ENDIF
+
+       IF (flag_pr_lsc_l(iff)<=lev_files(iff)) THEN
+       CALL histwrite_phy(nid_files(iff),"prfl",itau_w,prfl)
+       ENDIF
+
+       IF (flag_pr_lsc_i(iff)<=lev_files(iff)) THEN
+       CALL histwrite_phy(nid_files(iff),"psfl",itau_w,psfl)
        ENDIF
 
Index: LMDZ4/trunk/libf/phylmd/physiq.F
===================================================================
--- LMDZ4/trunk/libf/phylmd/physiq.F	(revision 928)
+++ LMDZ4/trunk/libf/phylmd/physiq.F	(revision 929)
@@ -1876,10 +1876,8 @@
 c#endif
 
-      call phys_output_open ( jj_nb, jjmp1, nqmax,
-     &               nlevSTD, clevSTD, nbteta, ctetaSTD,
-     &      dtime, presnivs, ok_veget, ocean, iflag_pbl,
-     &               ok_mensuel,ok_journe,ok_hf,ok_instan,
-     &               rlon, rlat, nid_files)
-
+       call phys_output_open(jjmp1,nqmax,nlevSTD,clevSTD,nbteta, 
+     &                        ctetaSTD,dtime,presnivs,ok_veget,
+     &                        ocean,iflag_pbl,ok_mensuel,ok_journe,
+     &                        ok_hf,ok_instan,nid_files)
 
 #ifdef histISCCP
@@ -3638,10 +3636,12 @@
 !==========================================================================
 
-      if (klon.eq.1) then
+      if (1.eq.1) then
       write(lunout,*) 'FIN DE PHYSIQ !!!!!!!!!!!!!!!!!!!!'
       write(lunout,*)
-     s 'nlon,nlev,nqmax,debut,lafin,rjourvrai,gmtime,pdtphys'
+     s 'nlon,nlev,nqmax,debut,lafin,rjourvrai,gmtime,pdtphys pct tlos'
       write(lunout,*)
-     s  nlon,nlev,nqmax,debut,lafin,rjourvrai,gmtime,pdtphys
+     s  nlon,nlev,nqmax,debut,lafin,rjourvrai,gmtime,pdtphys,
+     s  pctsrf(igout,is_ter), pctsrf(igout,is_lic), pctsrf(igout,is_oce),
+     s  pctsrf(igout,is_sic)
       write(lunout,*) 'd_t_dyn,d_t_con,d_t_lsc,d_t_ajsb,d_t_ajs,d_t_eva'
       do k=1,nlev
