!
! $Header$
!
         CALL ymds2ju(annee_ref, 1, day_ref, 0.0, zjulian)
c
         CALL gr_fi_ecrit(1,klon,iim,jjm+1,xlon,zx_lon)
         DO i = 1, iim
            zx_lon(i,1) = xlon(i+1)
            zx_lon(i,jjm+1) = xlon(i+1)
         ENDDO
         CALL gr_fi_ecrit(1,klon,iim,jjm+1,xlat,zx_lat)
         CALL histbeg("histrac", iim,zx_lon(:,1), jjm+1,zx_lat(1,:),
     .                 1,iim,1,jjm+1, itau_phy, zjulian, pdtphys,
     .                 nhori, nid_tra)
         CALL histvert(nid_tra, "presnivs", "Vertical levels", "mb",
     .                 klev, presnivs, nvert)

#ifdef INCA_AER
         CALL histbeg("histrac_aer", iim,zx_lon, jjm+1,zx_lat,
     .                 1,iim,1,jjm+1,  itau_phy, zjulian, pdtphys,
     .                 nhori, nid_tra2)

         CALL histbeg("histrac_inst", iim,zx_lon, jjm+1,zx_lat,
     .                 1,iim,1,jjm+1,  itau_phy, zjulian, pdtphys,
     .                 nhori, nid_tra3)

         call histvert(nid_tra2, "presnivs", "presnivs", "mb",
     .                 klev, presnivs, nvert)
         call histvert(nid_tra3, "presnivs", "presnivs", "mb",
     .                 klev, presnivs, nvert)
#endif

#ifdef INCA
!        call histvert(nid_tra, "ap", "Hybrid A parameter", "-",
!    .                 klev+1, ap, nverta)
!        call histvert(nid_tra, "bp", "Hybrid B parameter", "-",
!    .                 klev+1, bp, nvertb)
#endif

         zsto = pdtphys
         zout = ecrit_tra
c
c        print*,'ini_histrac: zsto zout',zsto,zout
c
         CALL histdef(nid_tra, "phis", "Surface geop. height", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "once",  zsto,zout)
c
         CALL histdef(nid_tra, "aire", "Grid area", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "once",  zsto,zout)
#ifdef INCA
         CALL histdef(nid_tra, "ps", "Surface pressure", "Pa",
     .                iim,jjm+1,nhori, 1,1,1,-99, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "ptrop", "Tropopause pressure", "Pa",
     .                iim,jjm+1,nhori, 1,1,1,-99, 32,
     .                "ave(X)", zsto,zout)

C   3d FIELDS
         CALL histdef(nid_tra, "temp", "Air temperature", "K",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "u", "zonal wind component", "m/s",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "v", "zonal wind component", "m/s",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "h2o", "Specific Humidity", "MMR",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "pmid", "Pressure", "Pa",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "pdel", "Delta Pressure", "Pa",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

! MS info
#ifdef INCA_AER
         CALL histdef(nid_tra, "airm", "Air mass", "kg",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
#endif
#ifdef INCA
#ifdef INCAINFO
         DO it=1, phtcnt
         WRITE(str2,'(i2.2)') it
         CALL histdef(nid_tra, "j"//str2,"j"//str2, "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         ENDDO
         DO it=1, hetcnt
         WRITE(str2,'(i2.2)') it
         CALL histdef(nid_tra, "w"//str2,"w"//str2, "S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         ENDDO

         DO it=1, extcnt
         WRITE(str2,'(i2.2)') it
         CALL histdef(nid_tra, "ext"//str2,"ext"//str2, "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         ENDDO

         DO it=1, nfs
         WRITE(str2,'(i2.2)') it
         CALL histdef(nid_tra, "INV"//str2, "INV"//str2, "CM-3",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         ENDDO

#else
         CALL histdef(nid_tra, "jO3","jO3", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "jNO2","jNO2", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "jH2O2","jH2O2", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "wHNO3","wHNO3", "S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "kN2O5", "kN2O5","CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "LghtNO","LghtNO", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
#endif

         DO it=1, grpcnt
         CALL histdef(nid_tra, grpsym(it), grpsym(it), "VMR",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         ENDDO
#endif

#ifdef INCA_AER

        CALL histdef(nid_tra2, "scavcoef_st","scavcoef_st", "S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
        CALL histdef(nid_tra2, "scavcoef_cv","scavcoef_cv", "S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
        CALL histdef(nid_tra2, "AngstroemComp","AngstroemComp",
     .      "angs comp", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)

        CALL histdef(nid_tra2, "TOTAERH2O", "Total aerosol water",
     .      "kg/m2", iim,jjm+1,nhori, klev,1,klev, nvert, 32,
     .      "ave(X)", zsto,zout)
#endif
#endif
         DO it=1,nqmax
C champ 2D
#ifdef INCA
         IF ( prt_flag_ts(it) == 0 ) CYCLE

         CALL histdef(nid_tra, "Emi_"//solsym(it), "Emi_"//solsym(it),
     .           "kg/m2/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "Dep_"//solsym(it), "Dep_"//solsym(it),
     .           "cm/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
#ifdef INCA_AER

         CALL histdef(nid_tra2, "Dry_"//solsym(it), "Dry_"//solsym(it),
     .           "kg/m2/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
          
        IF  ((it .ge. trmx) .and. (it .le. trnx)) then
          CALL histdef(nid_tra2, "Sed_"//solsym(it), "Sed_"//solsym(it),
     .      "kg/m2/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)
          CALL histdef(nid_tra2, "Wet_"//solsym(it), "Wet_"//solsym(it),
     .      "kg/m2/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)
          CALL histdef(nid_tra2, "WetST_"//solsym(it), "WetST_"//solsym(it),
     .      "kg/m2/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)
          CALL histdef(nid_tra2, "WetCV_"//solsym(it), "WetCV_"//solsym(it),
     .      "kg/m2/s", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)
          CALL histdef(nid_tra2, "Emi_alt_"//solsym(it), "Emi_alt_"//solsym(it),
     .      "kg/m2/s", iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .      "ave(X)", zsto,zout)
          CALL histdef(nid_tra2, "Load_"//solsym(it), "Load_"//solsym(it),
     .      "kg/m2", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)
          CALL histdef(nid_tra2, "SConc_"//solsym(it), "SConc_"//solsym(it),
     .      "kg/m3", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "ave(X)", zsto,zout)
          do la=1,las
            CALL histdef(nid_tra2, "OD"//cla(la)//"_"//solsym(it), "OD"//cla(la)//"_"//solsym(it),
     .        "opt. depth", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .        "ave(X)", zsto,zout)

            CALL histdef(nid_tra2, "OD3D"//cla(la)//"_"//solsym(it), "OD3d_"//cla(la)//"_"//solsym(it),
     .        "opt. depth 3D", iim,jjm+1,nhori, klev,1,klev, nvert, 32,
     .        "ave(X)", zsto,zout)
          enddo

          CALL histdef(nid_tra2, "CLOAD_"//solsym(it), "3D LOAD_"//solsym(it),
     .      "kg/m2 resp. #/m2", iim,jjm+1,nhori, klev,1,klev, nvert, 32,
     .      "ave(X)", zsto,zout)

          CALL histdef(nid_tra2, "MD_"//solsym(it), "MD_"//solsym(it),
     .      "median diameter [m]", iim,jjm+1,nhori, klev,1,klev, nvert, 32,
     .      "ave(X)", zsto,zout)

          CALL histdef(nid_tra2, "MDW_"//solsym(it), "MDW_"//solsym(it),
     .      "wet median diameter [m]", iim,jjm+1,nhori, klev,1,klev, nvert, 32,
     .      "ave(X)", zsto,zout)



          CALL histdef(nid_tra3, "Inst_Load_"//solsym(it), "Inst_Load_"//solsym(it),
     .      "kg/m2", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .      "inst(X)", zout,zout)

        endif

#endif
         CALL histdef(nid_tra, solsym(it), solsym(it), "VMR",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
#else
         iq=it+2
         iiq=niadv(iq)
         CALL histdef(nid_tra, tnom(iq), ttext(iiq), "U/kga",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         if (lessivage) THEN
         CALL histdef(nid_tra, "fl"//tnom(iq),"Flux "//ttext(iiq),
     .              "U/m2/s",iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
         endif

c---Ajout Olivia
         CALL histdef(nid_tra, "d_tr_th_"//tnom(iq),
     .	              "tendance thermique"// ttext(iiq), "?",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "d_tr_cv_"//tnom(iq),
     .	              "tendance convection"// ttext(iiq), "?",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "d_tr_cl_"//tnom(iq),
     .	              "tendance couche limite"// ttext(iiq), "?",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c---fin Olivia	 

#endif
         ENDDO

#ifdef INCA
         CALL histdef(nid_tra, "O3_column", "O3_column",
     .           "DU", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "CO_column", "CO_column",
     .           "10^18 CM-2", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "CH4_column", "CH4_column",
     .           "10^18 CM-2", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "NO2_column", "NO2_column",
     .           "10^15 CM-2", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "O3_ste", "O3_ste",
     .           "CM-2 S-1", iim,jjm+1,nhori, 1,1,1, -99, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "O3_prod", "O3_prod", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "O3_loss", "O3_loss", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

!        Special variables for daytime averaging
!        CALL histdef(nid_tra, "day_cnt", "day_cnt", "-",
!    .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
!    .                "t_sum(X)", zsto,zout)
!        CALL histdef(nid_tra, "NO_day", "NO_day", "VMR",
!    .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
!    .                "t_sum(X)", zsto,zout)



!! Ajout Anne
#ifdef INCA_AER
! for sulfur cycle
         CALL histdef(nid_tra, "SO2_p_dmsoh", "SO2_p_dmsoh", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "SO2_p_dmsno3", "SO2_p_dmsno3", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "SO2_p_h2soh", "SO2_p_h2soh", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "SO2_p_dmsooh", "SO2_p_dmsooh", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "DMSO_p_dmsoh", "DMSO_p_dmsoh", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "ASMSAM_p_dmsooh", "ASMSAM_p_dmsooh", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "ASSO4M_p_so2oh", "ASSO4M_p_so2oh", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "ASSO4M_p_so2h2o2", "ASSO4M_p_h2o2","CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "ASSO4M_p_so2o3", "ASSO4M_p_so2o3", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "Wet3D_SO2", "Wet3D_SO2",
     .           "kg/m2/s", iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "Wet3D_DMS", "Wet3D_DMS",
     .           "kg/m2/s", iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "Wet3D_HNO3", "Wet3D_HNO3",
     .           "kg/m2/s", iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .           "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "Wet3D_H2O2", "Wet3D_H2O2",
     .           "kg/m2/s", iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .           "ave(X)", zsto,zout)

         CALL histdef(nid_tra, "PH_HIST", "pH over physics time step", "1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
#endif

#ifdef INCA_NMHC
         CALL histdef(nid_tra, "CO2_basprod", "CO2_basprod", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "CO2_nmhcprod", "CO2_nmhcprod", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "CO2_radicalprod", "CO2_radicalprod", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "HNO3_prod", "HNO3_prod", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "HNO3_loss", "HNO3_loss", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "CO_prod", "CO_prod", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "CO_loss", "CO_loss", "CM-3 S-1",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
#endif
! Fin ajout Anne
#else
         CALL histdef(nid_tra, "pyu1", "Vent niv 1", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)

         CALL histdef(nid_tra, "pyv1", "Vent niv 1", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "psrf1", "nature sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "psrf2", "nature sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "psrf3", "nature sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "psrf4", "nature sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "ftsol1", "temper sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "ftsol2", "temper sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "ftsol3", "temper sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst",  zsto,zout)
         CALL histdef(nid_tra, "ftsol4", "temper sol", "-",
     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
     .                "inst(X)",  zsto,zout)
         CALL histdef(nid_tra, "pplay", "flux u mont","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
         CALL histdef(nid_tra, "t", "flux u mont","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "inst(X)", zsto,zout)
         CALL histdef(nid_tra, "mfu", "flux u mont","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "mfd", "flux u decen","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "en_u", "flux u mont","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "en_d", "flux u mont","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "de_d", "flux u mont","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "de_u", "flux u decen","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
         CALL histdef(nid_tra, "coefh", "turbulent coef","-",
     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)

#endif
c
         CALL histend(nid_tra)
#ifdef INCA_AER
         CALL histend(nid_tra2)
         CALL histend(nid_tra3)
#endif
         ndex2d = 0
         ndex3d = 0
         ndex = 0
