!
! $Header$
!
      IF (ok_instan) THEN
c$OMP MASTER
c
          zsto = ecrit_ins
          zout = ecrit_ins
c
         idayref = day_ref
         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
c
cym         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
cym         DO i = 1, iim
cym            zx_lon(i,1) = rlon(i+1)
cym            zx_lon(i,jjmp1) = rlon(i+1)
cym         ENDDO
         DO ll=1,klev
            znivsig(ll)=float(ll)
         ENDDO
cym         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
cym         CALL histbeg("histins", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
cym     .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime,
cym     .                 nhori, nid_ins)
         CALL histbeg_phy("histins", itau_phy, zjulian, dtime,
     .                 nhori, nid_ins)
         write(*,*)'Inst ', itau_phy, zjulian
         CALL histvert(nid_ins, "presnivs", "Vertical levels", "mb",
cIM    .                 klev, presnivs, nvert)
     .                 klev, presnivs/100., nvert)
c        call histvert(nid_ins, 'sig_s', 'Niveaux sigma','-',
c    .              klev, znivsig, nvert)
c
c
         CALL histdef(nid_ins, "phis", "Surface geop. height", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "once", zsto,zout)
c
         CALL histdef(nid_ins, "aire", "Grid area", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "once", zsto,zout)
c
c Champs 2D:
c
        CALL histdef(nid_ins, "tsol", "Surface Temperature", "K",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "t2m", "Temperature 2m", "K",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "q2m", "Specific humidity 2m", "Kg/Kg",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "u10m", "Vent zonal 10m", "m/s",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "v10m", "Vent meridien 10m", "m/s",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
        CALL histdef(nid_ins, "psol", "Surface Pressure", "Pa",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "plul", "Large-scale Precip.", "mm/day",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "pluc", "Convective Precip.", "mm/day",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "cdrm", "Momentum drag coef.", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "cdrh", "Heat drag coef.", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "precip", "Precipitation Totale liq+sol", 
     .                "kg/(s*m2)",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "snow", "Snow fall", "kg/(s*m2)",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "snow_mass", "Snow Mass", "kg/m2",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "topl", "OLR", "W/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "evap", "Evaporation", "kg/(s*m2)",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "sols", "Solar rad. at surf.", "W/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "soll", "IR rad. at surface", "W/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "solldown", "Down. IR rad. at surface", 
     .                "W/m2", iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "bils", "Surf. total heat flux", "W/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "sens", "Sensible heat flux", "W/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "fder", "Heat flux derivation", "W/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
      CALL histdef(nid_ins, "dtsvdfo", "Boundary-layer dTs(o)", "K/s",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
      CALL histdef(nid_ins, "dtsvdft", "Boundary-layer dTs(t)", "K/s",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
      CALL histdef(nid_ins, "dtsvdfg", "Boundary-layer dTs(g)", "K/s",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
      CALL histdef(nid_ins, "dtsvdfi", "Boundary-layer dTs(g)", "K/s",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)

         DO nsrf = 1, nbsrf
C
           call histdef(nid_ins, "pourc_"//clnsurf(nsrf), 
     $         "% "//clnsurf(nsrf), "%",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)

           call histdef(nid_ins, "fract_"//clnsurf(nsrf), 
     $         "Fraction "//clnsurf(nsrf), "1",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)

           call histdef(nid_ins, "sens_"//clnsurf(nsrf), 
     $         "Sensible heat flux "//clnsurf(nsrf), "W/m2",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)
c
           call histdef(nid_ins, "tsol_"//clnsurf(nsrf), 
     $         "Surface Temperature"//clnsurf(nsrf), "W/m2",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)
c
           call histdef(nid_ins, "lat_"//clnsurf(nsrf), 
     $         "Latent heat flux "//clnsurf(nsrf), "W/m2",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)
C
           call histdef(nid_ins, "taux_"//clnsurf(nsrf), 
     $         "Zonal wind stress"//clnsurf(nsrf),"Pa",
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)

           call histdef(nid_ins, "tauy_"//clnsurf(nsrf), 
     $         "Meridional xind stress "//clnsurf(nsrf), "Pa",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)
c
           call histdef(nid_ins, "albe_"//clnsurf(nsrf), 
     $         "Albedo "//clnsurf(nsrf), "-",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)
c
           call histdef(nid_ins, "rugs_"//clnsurf(nsrf), 
     $         "rugosite "//clnsurf(nsrf), "-",  
     $         iim,jj_nb,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)
CXXX
         END DO 
         CALL histdef(nid_ins, "rugs", "rugosity", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)

c
         CALL histdef(nid_ins, "albs", "Surface albedo", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
         CALL histdef(nid_ins, "albslw", "Surface albedo LW", "-",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
c
cIM cf. AM 081204 BEG
c HBTM2
         CALL histdef(nid_ins, "s_pblh", "Boundary Layer Height", "m",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_pblt", "T at Boundary Layer Height", 
     .                "K",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_lcl", "Condensation level", "m",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_capCL", "Conv avlbl pot ener for 
     .                ABL", "J/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_oliqCL", "Liq Water in BL", "kg/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_cteiCL", "Instability criteria 
     .                (ABL)", "K",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_therm", "Exces du thermique", "K",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_trmb1", "deep_cape(HBTM2)", "J/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_trmb2", "inhibition (HBTM2)", "J/m2",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "s_trmb3", "Point Omega (HBTM2)", "m",
     .                iim,jj_nb,nhori, 1,1,1, -99, 32,
     .                "inst(X)", zsto,zout)
c
cIM cf. AM 081204 END
c
c Champs 3D:
c
         CALL histdef(nid_ins, "temp", "Temperature", "K",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "vitu", "Zonal wind", "m/s",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "vitv", "Merid wind", "m/s",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "geop", "Geopotential height", "m",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "pres", "Air pressure", "Pa",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "dtvdf", "Boundary-layer dT", "K/s",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "dqvdf", "Boundary-layer dQ", "Kg/Kg/s",
     .                iim,jj_nb,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c

         CALL histend(nid_ins)
c
         ndex2d = 0
         ndex3d = 0
c
c$OMP END MASTER

      ENDIF
