Index: LMDZ.3.3/branches/rel-LF/libf/phylmd/phytrac.F
===================================================================
--- LMDZ.3.3/branches/rel-LF/libf/phylmd/phytrac.F	(revision 177)
+++ LMDZ.3.3/branches/rel-LF/libf/phylmd/phytrac.F	(revision 230)
@@ -1,4 +1,7 @@
+c
+c $Header$
+c
       SUBROUTINE phytrac (rnpb,
-     I                   debutphy,
+     I                   debutphy,lafin,
      I                   nqmax,
      I                   nlon,nlev,pdtphys,
@@ -29,6 +32,6 @@
 #include "dimphy.h"
 #include "indicesol.h"
+#include "temps.h"
 #include "control.h"
-#include "temps.h"
 c======================================================================
 
@@ -50,8 +53,9 @@
       real pplay(nlon,nlev)  ! pression pour le mileu de chaque couche (en Pa)
       real presnivs(klev) ! pressions approximat. des milieux couches ( en PA)
-      real znivsig(klev) ! niveaux sigma
       real paire(klon)
       real pphis(klon)
       logical debutphy       ! le flag de l'initialisation de la physique
+      logical lafin          ! le flag de la fin de la physique
+
       integer ll
 c
@@ -92,5 +96,8 @@
       real ftsol(nlon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
       real pctsrf(nlon,nbsrf) ! Pourcentage de sol f(nature du sol)
-
+c abder
+      real pftsol1(nlon),pftsol2(nlon),pftsol3(nlon),pftsol4(nlon)
+      real ppsrf1(nlon),ppsrf2(nlon),ppsrf3(nlon),ppsrf4(nlon)
+c fin
 cAA ----------------------------
 cAA  VARIABLES LOCALES TRACEURS
@@ -133,5 +140,6 @@
       INTEGER nid_tra
       SAVE nid_tra
-      INTEGER ndex2d(iim*(jjm+1)),ndex3d(iim*(jjm+1)*klev)
+c     REAL x(klon,klev,nbtr+2) ! traceurs 
+      INTEGER ndex(1)
       REAL zx_tmp_2d(iim,jjm+1), zx_tmp_3d(iim,jjm+1,klev)
       REAL zx_lon(iim,jjm+1), zx_lat(iim,jjm+1)
@@ -161,6 +169,6 @@
 c
 c--modif convection tiedtke
-      INTEGER i, k, it
-
+      INTEGER i, k, it,itap
+	save itap
       REAL delp(klon,klev)
 c--end modif
@@ -208,8 +216,9 @@
 c        print*,'DANS PHYTRAC debutphy=',debutphy
 
-         ecrit_tra = NINT(86400./pdtphys *ecritphy)   
-         zsto = pdtphys
-         zout = pdtphys * FLOAT(ecrit_tra)
          if (debutphy) then
+
+          print*,'dans phytrac ',pdtphys,ecritphy,ecrit_tra
+          ecrit_tra = NINT(86400./pdtphys/2.) ! tous les 12H
+c         ecrit_tra = NINT(86400./pdtphys) ! tous les 24H
 
          if(nbtr.lt.nqmax) then
@@ -223,4 +232,5 @@
          PRINT*, 'La frequence de sortie traceurs est  ', ecrit_tra
          itra=0
+	 itap=0
 C         
          CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
@@ -239,9 +249,8 @@
      .                 1,iim,1,jjm+1, 0, zjulian, pdtphys,
      .                 nhori, nid_tra)
-         call histvert(nid_tra, 'sig_s', 'Niveaux sigma','-',
-     .              klev, znivsig, nvert)
-C
-C         CALL histvert(nid_tra, "presnivs", "Vertical levels", "mb",
-C     .                 klev, presnivs, nvert)
+         CALL histvert(nid_tra, "presnivs", "Vertical levels", "mb",
+     .                 klev, presnivs, nvert)
+         zsto = pdtphys
+         zout = pdtphys * FLOAT(ecrit_tra)
 c
          CALL histdef(nid_tra, "phis", "Surface geop. height", "-",
@@ -252,4 +261,66 @@
      .                iim,jjm+1,nhori, 1,1,1, -99, 32,
      .                "once",  zsto,zout)
+
+	goto 666
+         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_u", "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, "coefh", "turbulent coef","-",
+     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+
+666	continue
 c
          DO it=1,nqmax
@@ -271,4 +342,13 @@
          ENDDO
          CALL histend(nid_tra)
+         ndex(1) = 0
+c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_tra,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex)
+C
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+         CALL histwrite(nid_tra,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
 
 c======================================================================
@@ -284,4 +364,11 @@
             enddo
          END DO
+
+         open (99,file='starttrac',status='old',
+     .         err=999,form='formatted')
+         read(99,*) (trs(i,1),i=1,klon)
+999      close(99)
+         print*, 'apres starttrac'
+
 c Initialisation de la fraction d'aerosols lessivee
 c
@@ -317,11 +404,75 @@
          inirnpb=.false.
       endif
+      if(nqmax.gt.2) aerosol(3)=.true.
+
+
+c  abder
+	goto 777
+            do i=1,nlon
+               pftsol1(i) = ftsol(i,1)
+               pftsol2(i) = ftsol(i,2)
+               pftsol3(i) = ftsol(i,3)
+               pftsol4(i) = ftsol(i,4)
+
+               ppsrf1(i) = pctsrf(i,1)
+               ppsrf2(i) = pctsrf(i,2)
+               ppsrf3(i) = pctsrf(i,3)
+               ppsrf4(i) = pctsrf(i,4)
+
+            enddo
+	 ndex(1)=0
+	 itap=itap+1
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,yu1,zx_tmp_2d)
+         CALL histwrite(nid_tra,"pyu1",itap,zx_tmp_2d,
+     s                                  iim*(jjm+1),ndex)
+         
+	 CALL gr_fi_ecrit(1,klon,iim,jjm+1,yv1,zx_tmp_2d)
+         CALL histwrite(nid_tra,"pyv1",itap,zx_tmp_2d,
+     s                                  iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pftsol1,zx_tmp_2d)
+         CALL histwrite(nid_tra,"ftsol1",itap,zx_tmp_2d,
+     s                                       iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pftsol2,zx_tmp_2d)
+         CALL histwrite(nid_tra,"ftsol2",itap,zx_tmp_2d,
+     s                                       iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pftsol3,zx_tmp_2d)
+         CALL histwrite(nid_tra,"ftsol3",itap,zx_tmp_2d,
+     s                                      iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pftsol4,zx_tmp_2d)
+         CALL histwrite(nid_tra,"ftsol4",itap,zx_tmp_2d,
+     s                                      iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,ppsrf1,zx_tmp_2d)
+         CALL histwrite(nid_tra,"psrf1",itap,zx_tmp_2d,
+     s                                     iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,ppsrf2,zx_tmp_2d)
+         CALL histwrite(nid_tra,"psrf2",itap,zx_tmp_2d, 
+     s                                     iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,ppsrf3,zx_tmp_2d)
+         CALL histwrite(nid_tra,"psrf3",itap,zx_tmp_2d,
+     s                                     iim*(jjm+1),ndex)
+
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,ppsrf4,zx_tmp_2d)
+         CALL histwrite(nid_tra,"psrf4",itap,zx_tmp_2d,
+     s                                     iim*(jjm+1),ndex)
+777	continue
 c======================================================================
 c   Calcul de l'effet de la convection
 c======================================================================
+	print*,'Avant convection'
+      do it=1,nqmax
+         WRITE(itn,'(i1)') it
+c        call diagtracphy(tr_seri(:,:,it),paprs,'Avant conv'//itn)
+      enddo
 
       if (convection) then
 
-c     print*,'Pas de temps dans phytrac : ',pdtphys
+      print*,'Pas de temps dans phytrac : ',pdtphys
       DO it=1, nqmax
       CALL nflxtr(pdtphys, pmfu, pmfd, pen_u, pde_u, pen_d, pde_d,
@@ -332,17 +483,26 @@
       ENDDO
       ENDDO
-      WRITE(itn,'(i1)') it
-      CALL minmaxqfi(tr_seri(1,1,it),0.,1.e33,'convection it='//itn)
-      ENDDO
-c     print*,'apres nflxtr'
+c      WRITE(itn,'(i1)') it
+c      CALL minmaxqfi(tr_seri(1,1,it),0.,1.e33,'convection it='//itn)
+      ENDDO
+c      print*,'apres nflxtr'
 
 
       endif ! convection
+c        print*,'Apres convection'
+c      do it=1,nqmax
+c         WRITE(itn,'(i1)') it
+c        call diagtracphy(tr_seri(:,:,it),paprs,'Avant conv'//itn)
+c      enddo
 
 c======================================================================
 c   Calcul de l'effet de la couche limite
 c======================================================================
-
-c     print*,'avant couchelimite'
+c	print *,'Avant couchelimite'
+c      do it=1,nqmax
+c         WRITE(itn,'(i1)') it
+c        call diagtracphy(tr_seri(:,:,it),paprs,'Avant CL  '//itn)
+c      enddo
+
       if (couchelimite) then
 
@@ -403,5 +563,9 @@
       endif ! couche limite
 
-c     print*,'apres couchelimite'
+c      print*,'Apres couchelimite'
+c      do it=1,nqmax
+c         WRITE(itn,'(i1)') it
+c        call diagtracphy(tr_seri(:,:,it),paprs,'Avant CL  '//itn)
+c      enddo
 
 c======================================================================
@@ -432,4 +596,5 @@
 c======================================================================
 
+      print*,'LESSIVAGE =',lessivage
       IF (lessivage) THEN
 
@@ -464,14 +629,20 @@
 c Mise a jour due a l'impaction et a la nucleation
 c
+c      call dump2d(iim,jjm-1,frac_impa(2:klon-1,10),'FRACIMPA')
+c      call dump2d(iim,jjm-1,frac_nucl(2:klon-1,10),'FRACNUCL')
+c      call dump2d(iim,jjm-1,tr_seri(2:klon-1,10,3),'TRACEUR3')
        DO it = 1, nqmax
+c         print*,'IT=',it,aerosol(it)
          IF (aerosol(it)) THEN
+c           print*,'IT=',it,' On lessive'
            DO k = 1, nlev
               DO i = 1, klon
-               tr_seri(i,k,it) = tr_seri(i,k,it) *
-     s              ( frac_impa(i,k) + frac_nucl(i,k) - 1. )    
+               tr_seri(i,k,it)=tr_seri(i,k,it)
+     s         *frac_impa(i,k)*frac_nucl(i,k)
               ENDDO
            ENDDO
          ENDIF
        ENDDO
+c      call dump2d(iim,jjm-1,tr_seri(2:klon-1,10,3),'TRACEUR3B')
 c
 c Flux lessivage total 
@@ -507,16 +678,5 @@
       ENDDO
       itra=itra+1
-
-C
-C Sorties IOIPSL
-      ndex2d = 0
-      ndex3d = 0
-c
-c     write(*,*)'sorties ioipsl phytrac',zsto,zout
-      CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-      CALL histwrite(nid_tra,"phis",itra,zx_tmp_2d,iim*(jjm+1),ndex2d)
-C
-      CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
-      CALL histwrite(nid_tra,"aire",itra,zx_tmp_2d,iim*(jjm+1),ndex2d)
+      ndex(1) = 0
       DO it=1,nqmax
       IF (it.LE.99) THEN
@@ -525,10 +685,10 @@
        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,tr_seri(1,1,it),zx_tmp_3d)
        CALL histwrite(nid_tra,"tr"//str2,itra,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex3d)
-       IF (lessivage) THEN
-       CALL gr_fi_ecrit(klev,klon,iim,jjm+1,flestottr(1,1,it),zx_tmp_3d)
-       CALL histwrite(nid_tra,"fl"//str2,itra,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex3d)
-      ENDIF
+     .                                   iim*(jjm+1)*klev,ndex)
+c      IF (lessivage) THEN
+c      CALL gr_fi_ecrit(klev,klon,iim,jjm+1,flestottr(1,1,it),zx_tmp_3d)
+c      CALL histwrite(nid_tra,"fl"//str2,itra,zx_tmp_3d,
+c    .                                   iim*(jjm+1)*klev,ndex)
+c     ENDIF
       ELSE
          PRINT*, "Trop de traceurs"
@@ -536,5 +696,55 @@
       ENDIF
       ENDDO
-      if (ok_sync) call histsync(nid_tra)
+
+	goto 888
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pplay,zx_tmp_3d)
+        CALL histwrite(nid_tra,"pplay",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,t_seri,zx_tmp_3d)
+        CALL histwrite(nid_tra,"t",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pmfu,zx_tmp_3d)
+        CALL histwrite(nid_tra,"mfu",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pmfd,zx_tmp_3d)
+        CALL histwrite(nid_tra,"mfd",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pen_u,zx_tmp_3d)
+        CALL histwrite(nid_tra,"en_u",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pen_d,zx_tmp_3d)
+        CALL histwrite(nid_tra,"en_d",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pde_d,zx_tmp_3d)
+        CALL histwrite(nid_tra,"de_d",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,pde_u,zx_tmp_3d)
+        CALL histwrite(nid_tra,"de_u",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,coefh,zx_tmp_3d)
+        CALL histwrite(nid_tra,"coefh",itra,zx_tmp_3d,
+     .                  iim*(jjm+1)*klev,ndex)
+
+888	continue
+
+c	print*,'Sortie phytrac'
+c      do it=1,nqmax
+c         WRITE(itn,'(i1)') it
+c        call diagtracphy(tr_seri(:,:,it),paprs,'Fin Phys  '//itn)
+c      enddo
+
+      if (lafin) then
+         print*, 'c est la fin de la physique'
+         open (99,file='restarttrac',  form='formatted')
+         do i=1,klon
+             write(99,*) trs(i,1)
+         enddo
+         PRINT*, 'Ecriture du fichier restarttrac'
+         close(99)
+      else
+         print*, 'physique pas fini'
+      endif
+
 
       RETURN
