!
! $Header$
!
      IF (ok_isccp) THEN
c
c pour les champs instantannes, il faut mettre la meme valeur pour
c zout et zsto.
c dtime est passe par ailleurs a histbeg
c zstophy = frequence de stockage des champs tous les pdt physiques
c zout = frequence d'ecriture des champs
        zstophy = dtime
c
c zout : frequence ecriture
c
c ecriture 8 fois par jour
c       zout = dtime * REAL(NINT(86400./dtime*ecrit_isccp))
c ecriture toutes les 2h (12 fois par jour)
c       zout = dtime * 4.
c ecriture toutes les 1/2 h (48 fois par jour)
c       zout = dtime
c
        zout = ecrit_ISCCP
c
        idayref = day_ref
        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
        write(*,*)'ISCCP ', itau_phy, zjulian
c
c definition coordonnees lon,lat en globale
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

        CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
c
         CALL histbeg("histISCCP.nc", iim,zx_lon(:,1),jjmp1,zx_lat(1,:),
     .                 1, iim, 1, jjmp1,
     .                 itau_phy, zjulian, dtime,
     .                 nhori, nid_isccp)
c
         CALL histvert(nid_isccp, "cldtopres","Cloud Top Pressure","mb",
     .                 lmaxm1, cldtopres, nvert,'down')
c
      IF(type_run.EQ."ENSP".OR.type_run.EQ."CLIM") THEN
c
c variables a ecrire
c
         DO k=1, kmaxm1
          CALL histdef(nid_isccp, "cldISCCP_"//taulev(k),
     .                "LMDZ ISCCP cld", "%",
     .                iim, jjmp1,nhori,lmaxm1,1,lmaxm1,nvert,32,
     .                "ave(X)", zstophy,zout)
         ENDDO
c
         CALL histdef(nid_isccp, "nsunlit",
     .                "Nb of calls with sunlit ", "%",
     .                iim, jjmp1,nhori,1,1,1,-99,32,
     .                "ave(X)", zstophy,zout)
c
      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
c
         DO k=1, kmaxm1
          DO l=1, lmaxm1
c
          CALL histdef(nid_isccp, pclev(l)//taulev(k),
     .                "LMDZ ISCCP cld "//cnameisccp(l,k), "%",
     .                iim, jjmp1,nhori,1,1,1,-99,32,
     .                "ave(X)", zstophy,zout)
c
          ENDDO
         ENDDO
c
         CALL histdef(nid_isccp, "nsunlit",
     .                "Nb of calls with sunlit ", "%",
     .                iim, jjmp1,nhori,1,1,1,-99,32,
     .                "ave(X)", zstophy,zout)
c
      ENDIF 
c
        CALL histend(nid_isccp)
c
      ENDIF ! ok_isccp
