Index: trunk/LMDZ.TITAN/libf/phytitan/write_histins.h
===================================================================
--- trunk/LMDZ.TITAN/libf/phytitan/write_histins.h	(revision 808)
+++ trunk/LMDZ.TITAN/libf/phytitan/write_histins.h	(revision 1056)
@@ -3,144 +3,85 @@
 !
       IF (ok_instan) THEN
-c
-      ndex2d = 0
-      ndex3d = 0
-      zx_tmp_2d = 0.
-      zx_tmp_3d = 0.
-      zx_tmp_fi2d=0.
-      zx_tmp_fi3d=0.
-c
-          zsto = dtime * FLOAT(ecrit_ins)
-          zout = dtime * FLOAT(ecrit_ins)
+
+         zsto = dtime * REAL(ecrit_ins)
+         zout = dtime * REAL(ecrit_ins)
          itau_w = itau_phy + itap
 
-c
 c-------------------------------------------------------
       IF(lev_histday.GE.1) THEN
-c
+
 ccccccccccccc 2D fields, invariables
-c
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
-      CALL histwrite(nid_ins,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-C
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
-      CALL histwrite(nid_ins,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
+
+      call histwrite_phy(nid_ins,.false.,"phis",itau_w,pphis)
+      call histwrite_phy(nid_ins,.false.,"aire",itau_w,airephy)
+
 ccccccc axe Ls ... Faudrait le reduire a axe temporel seulement...
-      do j=1,jjmp1
-       do i=1,iim
-        zx_tmp_2d(i,j)=zls*180./RPI      ! zls est en radians !!
-       enddo
+      do i=1,klon
+        tmpout(i,1) = zls*180./RPI
       enddo
-      CALL histwrite(nid_ins,"ls",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
+      call histwrite_phy(nid_ins,.false.,"ls",itau_w,tmpout(:,1))
+
 ccccccccccccc 2D fields, variables
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ftsol,zx_tmp_2d)
-      CALL histwrite(nid_ins,"tsol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      DO i = 1, klon
-         zx_tmp_fi2d(i) = paprs(i,1)
-      ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_ins,"psol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
-c     CALL histwrite(nid_ins,"ue",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
-c     CALL histwrite(nid_ins,"ve",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
+
+      call histwrite_phy(nid_ins,.false.,"tsol",itau_w,ftsol)
+      call histwrite_phy(nid_ins,.false.,"psol",itau_w,paprs(:,1))
+
+c     call histwrite_phy(nid_ins,.false.,"ue",itau_w,ue)
+c     call histwrite_phy(nid_ins,.false.,"ve",itau_w,ve)
+
       ENDIF !lev_histday.GE.1
-c
+
 c-------------------------------------------------------
       IF(lev_histday.GE.2) THEN
-c
+
 ccccccccccccc 3D fields, basics
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
-      CALL histwrite(nid_ins,"temp",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
-      CALL histwrite(nid_ins,"pres",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
-      CALL histwrite(nid_ins,"geop",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
-      CALL histwrite(nid_ins,"vitu",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
-      CALL histwrite(nid_ins,"vitv",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
-      CALL histwrite(nid_ins,"vitw",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
-      CALL histwrite(nid_ins,"tops",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_vdf, zx_tmp_3d)
-c     CALL histwrite(nid_ins,"duvdf",itau_w,zx_tmp_3d,
-c    .                                   iim*jjmp1*klev,ndex3d)
-c
-c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_dyn, zx_tmp_3d)
-c     CALL histwrite(nid_ins,"dudyn",itau_w,zx_tmp_3d,
-c    .                                   iim*jjmp1*klev,ndex3d)
-c
+
+      call histwrite_phy(nid_ins,.false.,"temp",itau_w,t_seri)
+      call histwrite_phy(nid_ins,.false.,"pres",itau_w,pplay)
+      call histwrite_phy(nid_ins,.false.,"geop",itau_w,zphi)
+      call histwrite_phy(nid_ins,.false.,"vitu",itau_w,u_seri)
+      call histwrite_phy(nid_ins,.false.,"vitv",itau_w,v_seri)
+      call histwrite_phy(nid_ins,.false.,"vitw",itau_w,omega)
+      call histwrite_phy(nid_ins,.false.,"tops",itau_w,topsw)
+c      call histwrite_phy(nid_ins,.false.,"duvdf",itau_w,d_u_vdf)
+c      call histwrite_phy(nid_ins,.false.,"dudyn",itau_w,d_u_dyn)
+
       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.eq.1) then
            DO iq=1,nmicro
-       CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qaer(1,1,iq), zx_tmp_3d)
-       CALL histwrite(nid_ins,tname(iq),itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+       call histwrite_phy(nid_ins,.false.,tname(iq),
+     .                    itau_w,qaer(1:klon,1:klev,iq))
            ENDDO
 	  endif
 	  if (nmicro.lt.nqmax) then
            DO iq=nmicro+1,nqmax
-       CALL gr_fi_ecrit(klev,klon,iim,jjmp1,tr_seri(1,1,iq),zx_tmp_3d)
-       CALL histwrite(nid_ins,tname(iq),itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+       call histwrite_phy(nid_ins,.false.,tname(iq),
+     .                    itau_w,tr_seri(1:klon,1:klev,iq))
            ENDDO
 	  endif
          endif
-c
+
 cccccccccccccccccc  Radiative transfer
-c
+
 c 2D
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_ins,"topl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
-      CALL histwrite(nid_ins,"sols",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
-      CALL histwrite(nid_ins,"soll",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
+
+      call histwrite_phy(nid_ins,.false.,"topl",itau_w,toplw)
+      call histwrite_phy(nid_ins,.false.,"sols",itau_w,solsw)
+      call histwrite_phy(nid_ins,.false.,"soll",itau_w,sollw)
+
 c 3D
-c
-      zx_tmp_fi3d(1:klon,1:klev)=swnet(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"SWnet",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      zx_tmp_fi3d(1:klon,1:klev)=lwnet(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"LWnet",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
+
+      call histwrite_phy(nid_ins,.false.,"SWnet",
+     .          itau_w,swnet(1:klon,1:klev))
+      call histwrite_phy(nid_ins,.false.,"LWnet",
+     .          itau_w,lwnet(1:klon,1:klev))
+
 c --------------
 c ----- OPACITE BRUME
@@ -151,9 +92,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_tauhvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"thv"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"thv"//str2,itau_w,t_tauhvd)
        enddo      ! fin boucle NSPECV 
 
@@ -164,9 +102,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_tauhvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"thi"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"thi"//str2,itau_w,t_tauhvd)
        enddo      ! fin boucle NSPECI 
 c --------------
@@ -178,5 +113,4 @@
      s     t_khvd(i,l)=TAUHVD(i,klev-l+1,k)
      s                -TAUHVD(i,klev-l+1-1,k)
-
           if(l.eq.klev)
      s     t_khvd(i,l)=TAUHVD(i,klev-l+1,k)
@@ -185,9 +119,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_khvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"khv"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"khv"//str2,itau_w,t_khvd)
        enddo      ! fin boucle NSPECV 
 
@@ -198,5 +129,4 @@
      s     t_khvd(i,l)=TAUHID(i,klev-l+1,k)
      s                -TAUHID(i,klev-l+1-1,k)
-
           if(l.eq.klev)
      s     t_khvd(i,l)=TAUHID(i,klev-l+1,k)
@@ -205,9 +135,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_khvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"khi"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"khi"//str2,itau_w,t_khvd)
        enddo      ! fin boucle NSPECI 
 c --------------
@@ -219,9 +146,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_tauhvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"tgv"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"tgv"//str2,itau_w,t_tauhvd)
        enddo      ! fin boucle NSPECV 
 
@@ -232,9 +156,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_tauhvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"tgi"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"tgi"//str2,itau_w,t_tauhvd)
        enddo      ! fin boucle NSPECI 
 c --------------
@@ -246,5 +167,4 @@
      s     t_khvd(i,l)=TAUGVD(i,klev-l+1,k)
      s                -TAUGVD(i,klev-l+1-1,k)
-
           if(l.eq.klev)
      s     t_khvd(i,l)=TAUGVD(i,klev-l+1,k)
@@ -253,9 +173,6 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_khvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"kgv"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"kgv"//str2,itau_w,t_khvd)
        enddo      ! fin boucle NSPECV 
 
@@ -273,79 +190,40 @@
          enddo
          enddo
-         write(str1,'(i2.2)') k
-      zx_tmp_fi3d(1:klon,1:klev)=t_khvd(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"kgi"//str1,itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
+         write(str2,'(i2.2)') k
+       call histwrite_phy(nid_ins,.false.,"kgi"//str2,itau_w,t_khvd)
        enddo      ! fin boucle NSPECI 
 
       ENDIF !lev_histday.GE.3
-c
+
 c-------------------------------------------------------
       IF(lev_histday.GE.4) THEN
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
-      CALL histwrite(nid_ins,"dtdyn",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
-      CALL histwrite(nid_ins,"dtphy",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c K/s
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"dtvdf",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-c K/s
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"dtajs",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-c K/s
-      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"dtswr",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
+
+      call histwrite_phy(nid_ins,.false.,"dtdyn",itau_w,d_t_dyn)
+      call histwrite_phy(nid_ins,.false.,"dtphy",itau_w,d_t)
+c K/s
+      call histwrite_phy(nid_ins,.false.,"dtvdf",itau_w,d_t_vdf)
+c K/s
+      call histwrite_phy(nid_ins,.false.,"dtajs",itau_w,d_t_ajs)
+c K/s
+      call histwrite_phy(nid_ins,.false.,"dtswr",itau_w,heat)
+c K/s
+      call histwrite_phy(nid_ins,.false.,"dtlwr",itau_w,-1.*cool)
 c K/s      
-      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-      CALL histwrite(nid_ins,"dtlwr",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c K/s      
-c     zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
-c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
-c     CALL histwrite(nid_ins,"dtec",itau_w,zx_tmp_3d,
-c    .                                   iim*jjmp1*klev,ndex3d)
-c
-c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_vdf, zx_tmp_3d)
-c     CALL histwrite(nid_ins,"dvvdf",itau_w,zx_tmp_3d,
-c    .                                   iim*jjmp1*klev,ndex3d)
-c
+c      call histwrite_phy(nid_ins,.false.,"dtec",itau_w,d_t_ec)
+c      call histwrite_phy(nid_ins,.false.,"dvvdf",itau_w,d_v_vdf)
+
       ENDIF !lev_histday.GE.4
-c
+
 c-------------------------------------------------------
       IF(lev_histday.GE.5) THEN
-c
-c
-c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fluxu , zx_tmp_2d)
-c      CALL histwrite(nid_ins,"taux_",itau_w,
-c    $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c      
-c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fluxv , zx_tmp_2d)
-c      CALL histwrite(nid_ins,"tauy_",itau_w,
-c    $      zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
-c     CALL histwrite(nid_ins,"cdrm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
-c     CALL histwrite(nid_ins,"cdrh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
+
+c      call histwrite_phy(nid_ins,.false.,"taux",itau_w,fluxu)
+c      call histwrite_phy(nid_ins,.false.,"tauy",itau_w,fluxv)
+c      call histwrite_phy(nid_ins,.false.,"cdrm",itau_w,cdragm)
+c      call histwrite_phy(nid_ins,.false.,"cdrh",itau_w,cdragh)
+
       ENDIF !lev_histday.GE.5
 c-------------------------------------------------------
-c
+
       if (ok_sync) then
         call histsync(nid_ins)
