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

           call histdef(nid_ins, "fract_"//clnsurf(nsrf), 
     $         "Fraction "//clnsurf(nsrf), "1",  
     $         iim,jjmp1,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,jjmp1,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,jjmp1,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,jjmp1,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,jjmp1,nhori, 1,1,1, -99, 32,
     $         "inst(X)", zsto,zout)

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

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

         CALL histend(nid_ins)
c
         ndex2d = 0
         ndex3d = 0
c
      ENDIF
