      IF (ok_instan) THEN
c
          zsto = dtime * FLOAT(ecrit_ins)
          zout = dtime * FLOAT(ecrit_ins)
c
         idayref = day_ref
         CALL ymds2ju(annee_ref, 1, idayref, zero, zjulian)
c
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlond,zx_lon)
         DO i = 1, iim
            zx_lon(i,1) = rlond(i+jjmp1-jjm)
            zx_lon(i,jjmp1) = rlond(i+jjmp1-jjm)
         ENDDO
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlatd,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, nvert)

c-------------------------------------------------------

      IF(lev_histday.GE.1) THEN
c
ccccccccccccc 2D fields, invariables
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
ccccccc axe Ls
         CALL histdef(nid_ins, "ls", "Solar longitude", "degrees",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
ccccccccccccc 2D fields, variables
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, "psol", "Surface Pressure", "Pa",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "ue", "Zonal energy transport", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "ve", "Merid energy transport", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "inst(X)", zsto,zout)
c
      ENDIF !lev_histday.GE.1
c
c-------------------------------------------------------
      IF(lev_histday.GE.2) THEN
c
ccccccccccccc 3D fields, basics
c
         CALL histdef(nid_ins, "temp", "Air temperature", "K",
     .                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, "geop", "Geopotential height", "m",
     .                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", "Meridional wind", "m/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "vitw", "Vertical wind", "Pa/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "tops", "Solar rad. at TOA", "W/m2",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "duvdf", "Boundary-layer dU", "m/s2",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "dudyn", "Dynamics dU", "m/s2",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "inst(X)", zsto,zout)
c
      ENDIF !lev_histday.GE.2
c
c-------------------------------------------------------
      IF(lev_histday.GE.3) THEN
c
cccccccccccccccccc  Tracers
c
         if (iflag_trac.eq.1) THEN
          if (microfi.ge.1) then
           DO iq=1,nmicro
         CALL histdef(nid_ins, tname(iq), ttext(iq), "n/m2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
           ENDDO
	  endif
	  if (nmicro.lt.nqmax) then
           DO iq=nmicro+1,nqmax
         CALL histdef(nid_ins, tname(iq), ttext(iq), "ppm",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
           ENDDO
	  endif
         endif
c
cccccccccccccccccc  Radiative transfer
c
c 2D
c
         CALL histdef(nid_ins, "topl", "IR rad. at TOA", "W/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
c 3D
c
         CALL histdef(nid_ins, "SWnet", "Net SW flux","W/m2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert,
     .                32, "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "LWnet", "Net LW flux","W/m2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert,
     .                32, "inst(X)", zsto,zout)
c
c --------------
c ----- OPACITE BRUME
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"thv"//str1,"Haze Opa Vis",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"thi"//str1,"Haze Opa IR",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
c --------------
c ----- EXTINCTION BRUME
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"khv"//str1,"Haze ext Vis ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"khi"//str1,"Haze ext IR ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
c --------------
c ----- OPACITE GAZ
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"tgv"//str1,"Haze Opa Vis",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"tgi"//str1,"Haze Opa IR",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
c --------------
c ----- EXTINCTION GAZ
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"kgv"//str1,"Haze ext Vis ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_ins,"kgi"//str1,"Haze ext IR ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ins(X)",zsto,zout)
         ENDDO
c
      ENDIF !lev_histday.GE.3
c
c-------------------------------------------------------
      IF(lev_histday.GE.4) THEN
c
         CALL histdef(nid_ins, "dtdyn", "Dynamics dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "dtphy", "Physics dT", "K/s",
     .                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, "dtajs", "Dry adjust. dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "dtswr", "SW radiation dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
         CALL histdef(nid_ins, "dtlwr", "LW radiation dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "dtec", "Cinetic dissip dT", "K/s",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "dvvdf", "Boundary-layer dV", "m/s2",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "inst(X)", zsto,zout)
c
      ENDIF !lev_histday.GE.4
c
c-------------------------------------------------------
      IF(lev_histday.GE.5) THEN
c
c
c        call histdef(nid_ins, "taux", 
c    $         "Zonal wind stress", "Pa",  
c    $         iim,jjmp1,nhori, 1,1,1, -99, 32,
c    $         "inst(X)", zsto,zout)
c
c        call histdef(nid_ins, "tauy", 
c    $         "Meridional xind stress", "Pa",  
c    $         iim,jjmp1,nhori, 1,1,1, -99, 32,
c    $         "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "cdrm", "Momentum drag coef.", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "inst(X)", zsto,zout)
c
c        CALL histdef(nid_ins, "cdrh", "Heat drag coef.", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "inst(X)", zsto,zout)
c
      ENDIF !lev_histday.GE.5
c-------------------------------------------------------

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