Index: LMDZ4/trunk/libf/phylmd/ini_histhf.h
===================================================================
--- LMDZ4/trunk/libf/phylmd/ini_histhf.h	(revision 590)
+++ LMDZ4/trunk/libf/phylmd/ini_histhf.h	(revision 644)
@@ -5,8 +5,8 @@
       IF (ok_hf) THEN
 c
-        zout = dtime * REAL(NINT(86400./dtime*ecrit_hf))
-        zsto = zout
-        zsto1 = dtime
-        PRINT*, 'La frequence de sortie instant. est de ', ecrit_hf
+       zstohf = dtime * FLOAT(ecrit_hf)
+       zstophy = dtime
+       zstoday = dtime * FLOAT(ecrit_day)
+       zout = dtime * FLOAT(ecrit_hf)
 c
          idayref = day_ref
@@ -21,6 +21,4 @@
 
          CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
-
-cccIM      CALL histbeg("histhf", iim,zx_lon, jjmp1,zx_lat,
          CALL histbeg("histhf", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
      .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
@@ -28,28 +26,22 @@
 
          CALL histvert(nid_hf, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
-c
-
+     .                 klev, presnivs/100., nvert)
+c
+
+      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
+c
       IF(lev_histhf.GE.1) THEN
 c
-c        CALL histdef(nid_hf, "phis", "Surface geop. height", "-",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "once", zsto,zout)
-c
-c        CALL histdef(nid_hf, "aire", "Grid area", "-",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "once", zsto,zout)
-c
          CALL histdef(nid_hf, "aireTER","Grid area CONT","-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstohf,zout)
 c
          CALL histdef(nid_hf, "contfracATM","% sfce ter+lic ","-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstohf,zout)
 c
          CALL histdef(nid_hf, "contfracOR","% sfce terre OR", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstohf,zout)
 c
 c Champs 2D:
@@ -57,51 +49,58 @@
          CALL histdef(nid_hf, "t2m", "Temperature 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "q2m", "Specific humidity", "kg/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "psol", "Surface Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-c
-         print*,'ATTENTION METTRE AVE(X) POUR LES PRECIPS'
-
-         CALL histdef(nid_hf, "rain", "Precipitation", "kg/m^2s",
+     .                "inst(X)", zstohf,zout)
+c
+         CALL histdef(nid_hf, "precip", "Precipitation", "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto1,zout)
+     .                "ave(X)", zstophy,zout)
 c
 cIM ENSEMBLES BEG
-c
          CALL histdef(nid_hf, "tsol", "Surface Temperature", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "slp", "Sea Level Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "u10m", "Vent zonal 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "v10m", "Vent meridien 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "wind10m","10-m wind speed","m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         DO k=1, nlevENS 
-          IF(clev(k).EQ."500") THEN
-          CALL histdef(nid_hf, "phi"//clev(k),
-     .                "Geopotential"//clev(k)//"mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-          ENDIF !clev(k).EQ."500"
-         ENDDO !k=1, nlevENS
+     .                "inst(X)", zstohf,zout)
+c
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+          IF(bb2.EQ."500") THEN
+          CALL histdef(nid_hf, "phi"//bb2,
+     .                "Geopotential "//bb2//"mb", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+          ENDIF !bb2.EQ."500"
+         ENDDO !k=1, nlevSTD
 c
       ENDIF !lev_histhf.GE.1
@@ -109,24 +108,22 @@
       IF(lev_histhf.GE.2) THEN
 c
-         CALL histdef(nid_hf, "cldt", "Total cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
-c
-c -- LOOP
+         CALL histdef(nid_hf, "cldt", "Total cloudiness", "%",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_hf, "SWnetOR",
+     .                "Sfce net SW radiation OR", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
          CALL histdef(nid_hf, "SWdownOR",
-     .                "Sfce incident SW down radiation OR", "W/m^2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
-c
-         CALL histdef(nid_hf, "SWnetOR",
-     .                "Sfce incident SW net radiation OR", "W/m^2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
-c -- LOOP
+     .                "Sfce incident SW radiation OR", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_hf, "LWdownOR",
-     .                "Sfce incident LW radiation OR", "W/m^2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
+     .                "Sfce incident LW radiation OR", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
       ENDIF !lev_histhf.GE.2
 c
@@ -135,54 +132,56 @@
       IF(lev_histhf.GE.3) THEN
 c
-         DO k=1, nlevENS
-c
-          CALL histdef(nid_hf, "t"//clev(k),
-     .                 "Temperature"//clev(k)//"mb","K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-          IF(clev(k).NE."500") THEN
-          CALL histdef(nid_hf, "phi"//clev(k), 
-     .                "Geopotential"//clev(k)//"mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+         IF(bb2.EQ."850".or.bb2.EQ."700".OR.
+     $      bb2.EQ."500".or.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_hf, "t"//bb2,
+     .                 "Temperature "//bb2//"mb","K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+          IF(bb2.NE."500") THEN
+          CALL histdef(nid_hf, "phi"//bb2, 
+     .                "Geopotential "//bb2//"mb", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
           ENDIF
 c
-          CALL histdef(nid_hf, "q"//clev(k),
-     .                 "Specific humidity"//clev(k)//"mb","kg/kg",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         IF(1.EQ.0) THEN
-         CALL histdef(nid_hf, "rh"//clev(k),
-     .                 "Relative humidity"//clev(k)//"mb", "%",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-         ENDIF
-c
-          CALL histdef(nid_hf, "u"//clev(k),
-     .                 "Zonal wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-          CALL histdef(nid_hf, "v"//clev(k),
-     .                 "Meridional wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         ENDDO !nlevENS
-         IF(1.EQ.0) THEN
-         CALL histdef(nid_hf, "cdrm", " Momentum drag coef.", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         CALL histdef(nid_hf, "cdrh", "Heat drag coef.", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-         ENDIF !(1.EQ.0) THEN
+          CALL histdef(nid_hf, "q"//bb2,
+     .                 "Specific humidity "//bb2//"mb","kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+          CALL histdef(nid_hf, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+          CALL histdef(nid_hf, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+         ENDIF !IF(bb2.EQ."850".or.bb2.EQ."700".OR.
+c
+         ENDDO !nlevSTD
 c
       ENDIF !lev_histhf.GE.3
 c
       IF(lev_histhf.GE.4) THEN
+c
+cIM sorties hf 3D
+c
+#undef histhf3d
 #define histhf3d
 #ifdef histhf3d
@@ -191,10 +190,206 @@
       ENDIF !lev_histhf.GE.4
 c
-c#define histhf3d
-c#ifdef histhf3d
-c#include "ini_histhf3d.h"
-c#endif
-c
-         CALL histend(nid_hf)
-c
-      endif ! ok_hf
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+      IF(lev_histhf.GE.1) THEN
+c
+        DO k=1, nlevSTD 
+c
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+         IF(bb2.EQ."850".or.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_hf, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+         ENDIF !bb2.EQ."850".or.bb2.EQ."200"
+        ENDDO !k=1, nlevSTD
+c
+        CALL histdef(nid_hf, "topl", 
+     .       "Outgoing longwave radiation", "W/m2",
+     .       iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .       "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "precip","Total precipitation rate",
+     .       "kg/(s*m2)",iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .       "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "slp", 
+     .       "Mean sea-level pressure", "Pa",
+     .       iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .       "inst(X)", zstohf,zout)
+c
+cIM 280504 BEG
+      ENDIF !(lev_histhf.GE.1) THEN
+c
+      IF(lev_histhf.GE.2) THEN
+c
+        DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+         IF(bb2.EQ."850".OR.bb2.EQ."500") THEN
+c
+          CALL histdef(nid_hf, "t"//bb2,
+     .                 "Temperature "//bb2//"mb","K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "q"//bb2,
+     .                 "Specific humidity "//bb2//"mb","kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+         ENDIF !bb2
+c
+         IF(bb2.EQ."500") THEN
+c
+          CALL histdef(nid_hf, "phi"//bb2,
+     .                "Geopotential "//bb2//"mb", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "w"//bb2,
+     .                 "Vertical motion "//bb2//"mb","Pa/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+         ENDIF !bb2.EQ."500"
+c
+         IF(bb3.EQ."50") THEN
+c
+          CALL histdef(nid_hf, "t"//bb3,
+     .                 "Temperature "//bb3//"mb","K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "u"//bb3,
+     .                 "Zonal wind "//bb3//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "v"//bb3,
+     .                 "Meridional wind "//bb3//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+         ENDIF !bb3
+c
+        ENDDO !k=1, nlevSTD
+c
+        CALL histdef(nid_hf, "u10m", "Vent zonal 10m", "m/s",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "v10m", "Vent meridien 10m", "m/s",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "t2m", "Temperature 2m", "K",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "q2m", "Specific humidity", "kg/kg",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "psol", "Surface Pressure", "Pa",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "cldt", "Total cloudiness", "%",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "taux",
+     $         "Zonal wind stress","Pa",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "tauy",
+     $         "Meridional wind stress ", "Pa",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "prw", "Precipitable water", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+cIM 090904  .                "ave(X)", zstohf,zout)
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "sens", "Sensible heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+cIM 090904  .                "ave(X)", zstohf,zout)
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "flat", "Latent heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstohf,zout)
+c
+c       CALL histdef(nid_hf, "snow_mass", "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+c    .                "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWdnSFC", "SWdn at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWupSFC", "SWup at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf,"LWdnSFC","Down. IR rad. at surface",
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf,"LWupSFC","Upwd. IR rad. at surface",
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWdnTOA", "SWdn at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWupTOA", "SWup at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        DO k=1, nbteta
+         CALL histdef(nid_hf, "PV"//ctetaSTD(k),
+     $               "Vorticite potentielle "//ctetaSTD(k)//"K",
+     $               "1/(Pa*s)",iim,jjmp1,nhori, 1,1,1, -99,
+     $                 32, "inst(X)", zstohf,zout) 
+        ENDDO !k=1, nbteta
+c
+c planetary boundary layer height
+c
+c       ENDIF !1.EQ.0
+c
+      ENDIF !(lev_histhf.GE.2) THEN
+cIM 280504 END
+c
+      ENDIF !type_run
+c
+      CALL histend(nid_hf)
+c
+      ENDIF ! ok_hf
