Index: LMDZ.3.3/branches/rel-1-0-patch/create_make_gcm
===================================================================
--- LMDZ.3.3/branches/LF/create_make_gcm	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/create_make_gcm	(revision 253)
@@ -10,4 +10,12 @@
   CRAY=1
 fi
+XNEC=0
+if [ "$machine" = "rhodes" ] ; then
+  XNEC=1
+fi
+VPP=0
+if [ "$machine" = "nymphea0" ] ; then
+  VPP=1
+fi
 #
 echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
@@ -43,12 +51,23 @@
 echo '# Les differentes librairies pour l"edition des liens:'
 echo
-echo 'dyn3d      = $(LIBO)/libdyn3d.a $(LIBO)/lib$(FILTRE).a'
-echo 'dyn2d      = $(LIBO)/libdyn2d.a'
-echo 'dyn1d      = $(LIBO)/libdyn1d.a'
-echo 'L_DYN      = -ldyn$(DIM)d'
-echo 'L_FILTRE   = -l$(FILTRE)'
-echo 'L_PHY = -lphy$(PHYS) '
-echo 'L_BIBIO    = -lbibio'
-echo 'L_ADJNT    ='
+if [ "$XNEC" = '1' ] ; then
+  echo 'dyn3d      = $(LIBO)/libsxdyn3d.a $(LIBO)/libsx$(FILTRE).a'
+  echo 'dyn2d      = $(LIBO)/libsxdyn2d.a'
+  echo 'dyn1d      = $(LIBO)/libsxdyn1d.a'
+  echo 'L_DYN      = -lsxdyn$(DIM)d'
+  echo 'L_FILTRE   = -lsx$(FILTRE)'
+  echo 'L_PHY = -lsxphy$(PHYS) '
+  echo 'L_BIBIO    = -lsxbibio'
+  echo 'L_ADJNT    ='
+else
+  echo 'dyn3d      = $(LIBO)/libdyn3d.a $(LIBO)/lib$(FILTRE).a'
+  echo 'dyn2d      = $(LIBO)/libdyn2d.a'
+  echo 'dyn1d      = $(LIBO)/libdyn1d.a'
+  echo 'L_DYN      = -ldyn$(DIM)d'
+  echo 'L_FILTRE   = -l$(FILTRE)'
+  echo 'L_PHY = -lphy$(PHYS) '
+  echo 'L_BIBIO    = -lbibio'
+  echo 'L_ADJNT    ='
+fi
 echo
 echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
@@ -58,6 +77,7 @@
    echo 'COMPILE = $(F77) $(OPTIM) $(INCLUDE) -c'
    echo 'COMPILE90 = $(F90) $(OPTIM90) $(INCLUDE) -c'
-   echo 'LINK    = f90'
-   echo "AR      = ar"
+   echo 'COMPTRU90 = $(F90) $(OPTIMTRU90) $(INCLUDE) -c'
+   echo "LINK    = $LINK"
+   echo "AR      = $AR"
 echo
 echo
@@ -73,10 +93,9 @@
 echo 'main : $(DYN) bibio phys $(OPTION_DEP) '
 echo '	cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\'
-if [ "$CRAY" = '0' ] ; then
 echo '	cd $(LOCAL_DIR); \'
-#echo '	$(COMPILE90) $(LIBF)/$(DIRMAIN)/$(PROG).F -o $(PROG).o ; \'
-echo '	$(COMPILE) $(LIBF)/$(DIRMAIN)/$(PROG).F -o $(PROG).o ; \'
-else
-echo '	$(COMPILE90) $(LIBF)/$(DIRMAIN)/$(PROG).F ; \'
+if [ "$CRAY" = '1' -o "$VPP" = '1' ] ; then
+  echo '	$(COMPILE90) $(LIBF)/$(DIRMAIN)/$(PROG).F -o $(PROG).o ; \'
+else
+  echo '	$(COMPILE) $(LIBF)/$(DIRMAIN)/$(PROG).F -o $(PROG).o ; \'
 fi
 if [ "$CRAY" = '0' ] ; then
@@ -109,5 +128,5 @@
 do
    if [ -d $diri ] ; then
-   if [ "`ls $diri/*.F`" != "" ] ; then 
+   if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.F90`" != "" ]  ; then 
       cd $diri >/dev/null 2>&1
       echo
@@ -121,4 +140,12 @@
          fi
       done
+      for i in `ls *.F90`
+      do
+         fili=`basename $i .F90`
+         test=` (  head $i | grep '      PROGRAM' ) `
+         if [ "$test" = "" ] ; then
+            listlib=$listlib" "$fili
+         fi 
+      done
 #
       echo
@@ -140,15 +167,21 @@
       for fili in $listlib
       do
-         F90=0 ; egrep -i '^ *use ' $fili.F > /dev/null 2>&1 && F90=1
-                 egrep -i '^ *module ' $fili.F > /dev/null 2>&1 && F90=1
-         str1='$(LIBO)/lib'$diri'.a('$fili'.o) : $(LIBF)/'$diri/$fili.F
+         if [ -f $fili.F90 ] ; then
+           trufile=$fili.F90
+         else
+           trufile=$fili.F
+         fi
+         F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1
+                 egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1
+         str1='$(LIBO)/lib'$diri'.a('$fili'.o) : $(LIBF)/'$diri/$trufile
          [ "$fili" = "chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F
-         for stri in ` ( sed -n "/\#include/s/\#include//p" $fili.F | sed 's/\"//g' ; egrep -i '^ *use ' $fili.F | awk ' { print $2 } ' ) `
+         for stri in ` ( sed -n "/\#include/s/\#include//p" $trufile | sed 's/\"//g' ; egrep -i '^ *use ' $trufile | awk ' { print $2 } ' ) `
          do
+            stri=`echo $stri | tr [A-Z] [a-z]`
             if [ -f $stri ] ; then
                echo $str1 \\
                str1='$(LIBF)/'$diri'/'$stri
             else
-               if [ -f $stri.F ] ; then
+               if [ -f $stri.F ] || [ -f $stri.F90 ] ; then
                   str1='$(LIBO)/lib'$diri'.a('$stri'.o)'
                else
@@ -165,10 +198,14 @@
          echo $str1
 	 if [ "$F90" -eq '0' ] ; then
-            echo '	cd $(LOCAL_DIR); \'
-	    echo '	$(COMPILE) $(LIBF)/'$diri'/'$fili'.F ; \'
+           echo '	cd $(LOCAL_DIR); \'
+	   echo '	$(COMPILE) $(LIBF)/'$diri'/'$trufile' ; \'
 	 else
-            echo '	cd $(LOCAL_DIR); \'
-	    echo '	$(COMPILE90) $(LIBF)/'$diri'/'$fili'.F ; \'
-            MODU=0; egrep -i ' *module ' $fili.F> /dev/null 2>&1 && MODU=1
+           echo '	cd $(LOCAL_DIR); \'
+           if [ -f $fili.F90 ] ; then
+	      echo '	$(COMPTRU90) $(LIBF)/'$diri'/'$trufile' ; \'
+           else
+	      echo '	$(COMPILE90) $(LIBF)/'$diri'/'$trufile' ; \'
+           fi
+           MODU=0; egrep -i ' *module ' $trufile> /dev/null 2>&1 && MODU=1
             if [ "$MODU" -eq '1' -a "$CRAY" != '1' ] ; then
               if [ "$os" = 'UNIX_System_V' ] ; then
@@ -179,4 +216,7 @@
             fi
 	 fi
+         if [ "$XNEC" -eq '1' ] ; then
+           echo '	sxar r $(LIBO)/libsx'$diri'.a '$fili'.o ; \'
+         fi
          echo '	$(AR) r $(LIBO)/lib'$diri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
          echo '	cd $(GCM)'
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/formcoord.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/formcoord.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/formcoord.F	(revision 253)
@@ -0,0 +1,51 @@
+      subroutine formcoord(unit,n,x,a,rev,text)
+      implicit none
+      integer n,unit,ndec
+      logical rev
+      real x(n),a
+      character*4 text
+
+      integer i,id,i1,i2,in
+      real dx,dxmin
+
+      if(rev) then
+         id=-1
+         i1=n
+         i2=n-1
+         in=1
+         write(unit,3000) text(1:1)
+      else
+         id=1
+         i1=1
+         i2=2
+         in=n
+      endif
+
+      if (n.lt.2) then
+         ndec=1
+         write(unit,1000) text,n,x(1)*a
+      else
+         dxmin=abs(x(2)-x(1))
+         do i=2,n-1
+            dx=abs(x(i+1)-x(i))
+            if (dx.lt.dxmin) dxmin=dx
+         enddo
+
+         ndec=-log10(dxmin)+2
+         if(mod(n,6).eq.1) then
+            write(unit,1000) text,n,x(i1)*a
+            write(unit,2000) (x(i)*a,i=i2,in,id)
+         else
+            write(unit,1000) text,n
+            write(unit,2000) (x(i)*a,i=i1,in,id)
+         endif
+      endif
+
+1000  format(a4,2x,i4,' LEVELS',43x,f12.2)
+2000  format(6f12.2)
+c1000  format(a4,2x,i4,' LEVELS',43x,f12.<ndec>)
+c2000  format(6f12.<ndec>)
+3000  format('FORMAT ',a1,'REV')
+      return
+
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/initfluxsto.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/initfluxsto.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/initfluxsto.F	(revision 253)
@@ -0,0 +1,223 @@
+      subroutine initfluxsto
+     .  (infile,tstep,t_ops,t_wrt,nq,
+     .                    fileid,filevid,filedid)
+
+       USE IOIPSL
+
+      implicit none
+
+C
+C   Routine d'initialisation des ecritures des fichiers histoires LMDZ
+C   au format IOIPSL
+C
+C   Appels succesifs des routines: histbeg
+C                                  histhori
+C                                  histver
+C                                  histdef
+C                                  histend
+C
+C   Entree:
+C
+C      infile: nom du fichier histoire a creer
+C      day0,anne0: date de reference
+C      tstep: duree du pas de temps en seconde
+C      t_ops: frequence de l'operation pour IOIPSL
+C      t_wrt: frequence d'ecriture sur le fichier
+C      nq: nombre de traceurs
+C
+C   Sortie:
+C      fileid: ID du fichier netcdf cree
+C      filevid:ID du fichier netcdf pour la grille v
+C
+C   L. Fairhead, LMD, 03/99
+C
+C =====================================================================
+C
+C   Declarations
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comvert.h"
+#include "comgeom.h"
+#include "temps.h"
+#include "ener.h"
+#include "logic.h"
+#include "description.h"
+#include "serre.h"
+
+C   Arguments
+C
+      character*(*) infile
+      integer*4 itau
+      real tstep, t_ops, t_wrt
+      integer fileid, filevid,filedid
+      integer nq,ndex(1)
+      real nivd(1)
+
+C   Variables locales
+C
+      integer tau0
+      real zjulian
+      character*3 str
+      character*10 ctrac
+      integer iq
+      real rlong(iip1,jjp1), rlat(iip1,jjp1),rl(1,1)
+      integer uhoriid, vhoriid, thoriid, zvertiid,dhoriid,dvertiid
+      integer ii,jj
+      integer zan
+      logical ok_sync
+C
+C  Initialisations
+C
+      pi = 4. * atan (1.)
+      str='q  '
+      ctrac = 'traceur   '
+      ok_sync = .true.
+C
+C  Appel a histbeg: creation du fichier netcdf et initialisations diverses
+C         
+
+      zan = anne_ini
+      CALL ymds2ju(zan, 1, 1, 0.0, zjulian)
+      zjulian = zjulian + day_ini
+      tau0 = 0
+	
+	do jj = 1, jjp1
+        do ii = 1, iip1
+          rlong(ii,jj) = rlonu(ii) * 180. / pi
+          rlat(ii,jj) = rlatu(jj) * 180. / pi
+        enddo
+      enddo
+ 
+      call histbeg(infile, iip1, rlong, jjp1, rlat,
+     .             1, iip1, 1, jjp1,
+     .             tau0, zjulian, tstep, uhoriid, fileid)
+C
+C  Creation du fichier histoire pour la grille en V (oblige pour l'instant,
+C  IOIPSL ne permet pas de grilles avec des nombres de point differents dans 
+C  un meme fichier)
+
+
+      do jj = 1, jjm
+        do ii = 1, iip1
+          rlong(ii,jj) = rlonv(ii) * 180. / pi
+          rlat(ii,jj) = rlatv(jj) * 180. / pi
+        enddo
+      enddo
+
+      call histbeg('fluxstokev.nc', iip1, rlong, jjm, rlat,
+     .             1, iip1, 1, jjm,
+     .             tau0, zjulian, tstep, vhoriid, filevid)
+	
+	rl(1,1) = 1.	
+      call histbeg('defstoke.nc', 1, rl, 1, rl,
+     .             1, 1, 1, 1,
+     .             tau0, zjulian, tstep, dhoriid, filedid)
+
+C
+C  Appel a histhori pour rajouter les autres grilles horizontales
+C
+      do jj = 1, jjp1
+        do ii = 1, iip1
+          rlong(ii,jj) = rlonv(ii) * 180. / pi
+          rlat(ii,jj) = rlatu(jj) * 180. / pi
+        enddo
+      enddo
+
+      call histhori(fileid, iip1, rlong, jjp1, rlat, 'scalar',
+     .              'Grille points scalaires', thoriid)
+	
+C
+C  Appel a histvert pour la grille verticale
+C
+      call histvert(fileid, 'sig_s', 'Niveaux sigma',
+     . 'sigma_level',
+     .              llm, nivsigs, zvertiid)
+C Pour le fichier V
+      call histvert(filevid, 'sig_s', 'Niveaux sigma',
+     .  'sigma_level',
+     .              llm, nivsigs, zvertiid)
+c pour le fichier def
+      nivd(1) = 1
+      call histvert(filedid, 'sig_s', 'Niveaux sigma',
+     .  'sigma_level',
+     .              1, nivd, dvertiid)
+
+C
+C  Appels a histdef pour la definition des variables a sauvegarder
+	
+	CALL histdef(fileid, "phis", "Surface geop. height", "-",
+     .                iip1,jjp1,thoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+
+         CALL histdef(fileid, "aire", "Grid area", "-",
+     .                iip1,jjp1,thoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+	
+	CALL histdef(filedid, "dtvr", "tps dyn", "s",
+     .                1,1,dhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+        
+         CALL histdef(filedid, "istdyn", "tps stock", "s",
+     .                1,1,dhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+         
+         CALL histdef(filedid, "istphy", "tps stock phy", "s",
+     .                1,1,dhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+
+
+C
+C Masse 
+C
+      call histdef(fileid, 'masse', 'Masse', 'kg',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+C
+C  Pbaru 
+C
+      call histdef(fileid, 'pbaru', 'flx de masse zonal', 'kg m/s',
+     .             iip1, jjp1, uhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+
+C
+C  Pbarv 
+C
+      call histdef(filevid, 'pbarv', 'flx de masse mer', 'kg m/s',
+     .             iip1, jjm, vhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+C
+C  w 
+C
+      call histdef(fileid, 'w', 'flx de masse vert', 'kg m/s',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+
+C
+C  Temperature potentielle
+C
+      call histdef(fileid, 'teta', 'temperature potentielle', '-',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+C
+
+C
+C Geopotentiel 
+C
+      call histdef(fileid, 'phi', 'geopotentiel instantane', '-',
+     .             iip1, jjp1, thoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+C
+C  Fin
+C
+      call histend(fileid)
+      call histend(filevid)
+      call histend(filedid)
+      if (ok_sync) then
+        call histsync(fileid)
+        call histsync(filevid)
+        call histsync(filedid)
+      endif
+	
+      return
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/writedynav.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/bibio/writedynav.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/writedynav.F	(revision 253)
@@ -58,5 +58,5 @@
 C   Variables locales
 C
-      integer ndex(1),iq, ii, ll
+      integer ndex2d(iip1*jjp1),ndex3d(iip1*jjp1*llm),iq, ii, ll
       character*3 str
       real us(ip1jmp1*llm), vs(ip1jmp1*llm)
@@ -68,5 +68,6 @@
 C
       str='q  '
-      ndex(1) = 0
+      ndex3d = 0
+      ndex2d = 0
       ok_sync = .TRUE.
 
@@ -81,5 +82,5 @@
       call gr_u_scal(llm, unat, us)
       call histwrite(histid, 'u', time, us, 
-     .               iip1*jjp1*llm, ndex)
+     .               iip1*jjp1*llm, ndex3d)
 C
 C  Vents V scalaire
@@ -87,5 +88,5 @@
       call gr_v_scal(llm, vnat, vs)
       call histwrite(histid, 'v', time, vs, 
-     .               iip1*jjp1*llm, ndex)
+     .               iip1*jjp1*llm, ndex3d)
 C
 C  Temperature moyennee
@@ -95,10 +96,10 @@
       enddo
       call histwrite(histid, 'temp', time, tm, 
-     .                iip1*jjp1*llm, ndex)
+     .                iip1*jjp1*llm, ndex3d)
 C
 C  Geopotentiel
 C
       call histwrite(histid, 'phi', time, phi, 
-     .                iip1*jjp1*llm, ndex)
+     .                iip1*jjp1*llm, ndex3d)
 C
 C  Traceurs
@@ -112,5 +113,5 @@
           ENDIF
           call histwrite(histid, str, time, q(:,:,iq), 
-     .                   iip1*jjp1*llm, ndex)
+     .                   iip1*jjp1*llm, ndex3d)
         enddo
       endif
@@ -118,17 +119,17 @@
 C  Masse
 C
-       call histwrite(histid, 'masse', time, masse, iip1*jjp1, ndex)
+       call histwrite(histid, 'masse', time, masse, iip1*jjp1, ndex2d)
 C
 C  Pression au sol
 C
-       call histwrite(histid, 'ps', time, ps, iip1*jjp1, ndex)
+       call histwrite(histid, 'ps', time, ps, iip1*jjp1, ndex2d)
 C
 C  Geopotentiel au sol
 C
-       call histwrite(histid, 'phis', time, phis, iip1*jjp1, ndex)
+       call histwrite(histid, 'phis', time, phis, iip1*jjp1, ndex2d)
 C
 C  Fin
 C
-      if (ok_sync) call histsync
+      if (ok_sync) call histsync(histid)
       return
       end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/writehist.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/bibio/writehist.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/bibio/writehist.F	(revision 253)
@@ -59,5 +59,6 @@
 C   Variables locales
 C
-      integer ndex(1),iq, ii, ll
+      integer iq, ii, ll
+      integer ndexu(ip1jmp1*llm),ndexv(ip1jm*llm),ndex2d(ip1jmp1)
       character*3 str
       logical ok_sync
@@ -66,5 +67,7 @@
 C
       str='q  '
-      ndex(1) = 0
+      ndexu = 0
+      ndexv = 0
+      ndex2d = 0
       ok_sync =.TRUE.
 C
@@ -74,5 +77,5 @@
 C
       call histwrite(histid, 'ucov', time, ucov, 
-     .               iip1*jjp1*llm, ndex)
+     .               iip1*jjp1*llm, ndexu)
 
 C
@@ -80,5 +83,5 @@
 C
       call histwrite(histvid, 'vcov', time, vcov, 
-     .               iip1*jjm*llm, ndex)
+     .               iip1*jjm*llm, ndexv)
 
 C
@@ -86,10 +89,10 @@
 C
       call histwrite(histid, 'teta', time, teta, 
-     .                iip1*jjp1*llm, ndex)
+     .                iip1*jjp1*llm, ndexu)
 C
 C  Geopotentiel
 C
       call histwrite(histid, 'phi', time, phi, 
-     .                iip1*jjp1*llm, ndex)
+     .                iip1*jjp1*llm, ndexu)
 C
 C  Traceurs
@@ -103,5 +106,5 @@
           ENDIF
           call histwrite(histid, str, time, q(:,:,iq), 
-     .                   iip1*jjp1*llm, ndex)
+     .                   iip1*jjp1*llm, ndexu)
         enddo
       endif
@@ -109,17 +112,20 @@
 C  Masse
 C
-      call histwrite(histid, 'masse', time, masse, iip1*jjp1, ndex)
+      call histwrite(histid, 'masse', time, masse, iip1*jjp1, ndex2d)
 C
 C  Pression au sol
 C
-      call histwrite(histid, 'ps', time, ps, iip1*jjp1, ndex)
+      call histwrite(histid, 'ps', time, ps, iip1*jjp1, ndex2d)
 C
 C  Geopotentiel au sol
 C
-      call histwrite(histid, 'phis', time, phis, iip1*jjp1, ndex)
+      call histwrite(histid, 'phis', time, phis, iip1*jjp1, ndex2d)
 C
 C  Fin
 C
-      if (ok_sync) call histsync
+      if (ok_sync) then
+        call histsync(histid)
+        call histsync(histvid)
+      endif
       return
       end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/addfi.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/addfi.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/addfi.F	(revision 253)
@@ -67,6 +67,7 @@
       REAL xpn(iim),xps(iim),tpn,tps
       INTEGER j,k,iq,ij
-      REAL qtest
-      PARAMETER ( qtest = 1.0e-30 )
+      REAL qtestw, qtestt
+      PARAMETER ( qtestw = 1.0e-15 )
+      PARAMETER ( qtestt = 1.0e-40 )
 
       REAL SSUM
@@ -81,19 +82,17 @@
       ENDDO
 
-      IF( alphax.NE.0. )   THEN
-        DO  k    = 1, llm
-         DO  ij   = 1, iim
-          xpn(ij) = aire(   ij   ) * pteta(  ij    ,k)
-          xps(ij) = aire(ij+ip1jm) * pteta(ij+ip1jm,k)
-         ENDDO
-          tpn      = SSUM(iim,xpn,1)/ apoln
-          tps      = SSUM(iim,xps,1)/ apols
+      DO  k    = 1, llm
+       DO  ij   = 1, iim
+         xpn(ij) = aire(   ij   ) * pteta(  ij    ,k)
+         xps(ij) = aire(ij+ip1jm) * pteta(ij+ip1jm,k)
+       ENDDO
+       tpn      = SSUM(iim,xpn,1)/ apoln
+       tps      = SSUM(iim,xps,1)/ apols
 
-         DO ij   = 1, iip1
-          pteta(   ij   ,k)  = tpn
-          pteta(ij+ip1jm,k)  = tps
-         ENDDO
-        ENDDO
-      ENDIF
+       DO ij   = 1, iip1
+         pteta(   ij   ,k)  = tpn
+         pteta(ij+ip1jm,k)  = tps
+       ENDDO
+      ENDDO
 c
 
@@ -114,13 +113,19 @@
          pps(j) = pps(j) + pdpfi(j) * pdt
       ENDDO
-
-c
-
-      DO iq = 1, nq
+ 
+      DO iq = 1, 2
          DO k = 1,llm
             DO j = 1,ip1jmp1
                pq(j,k,iq)= pq(j,k,iq) + pdqfi(j,k,iq) * pdt
-               pq(j,k,iq)= AMAX1( pq(j,k,iq), qtest )
-ccc              pq(j,k,iq)=qtest
+               pq(j,k,iq)= AMAX1( pq(j,k,iq), qtestw )
+            ENDDO
+         ENDDO
+      ENDDO
+
+      DO iq = 3, nq
+         DO k = 1,llm
+            DO j = 1,ip1jmp1
+               pq(j,k,iq)= pq(j,k,iq) + pdqfi(j,k,iq) * pdt
+               pq(j,k,iq)= AMAX1( pq(j,k,iq), qtestt )
             ENDDO
          ENDDO
@@ -128,37 +133,32 @@
 
 
-      IF( alphax.NE.0. )   THEN
+      DO  ij   = 1, iim
+        xpn(ij) = aire(   ij   ) * pps(  ij     )
+        xps(ij) = aire(ij+ip1jm) * pps(ij+ip1jm )
+      ENDDO
+      tpn      = SSUM(iim,xpn,1)/apoln
+      tps      = SSUM(iim,xps,1)/apols
 
-         DO  ij   = 1, iim
-          xpn(ij) = aire(   ij   ) * pps(  ij     )
-          xps(ij) = aire(ij+ip1jm) * pps(ij+ip1jm )
-         ENDDO
+      DO ij   = 1, iip1
+        pps (   ij     )  = tpn
+        pps ( ij+ip1jm )  = tps
+      ENDDO
+
+
+      DO iq = 1, nq
+        DO  k    = 1, llm
+          DO  ij   = 1, iim
+            xpn(ij) = aire(   ij   ) * pq(  ij    ,k,iq)
+            xps(ij) = aire(ij+ip1jm) * pq(ij+ip1jm,k,iq)
+          ENDDO
           tpn      = SSUM(iim,xpn,1)/apoln
           tps      = SSUM(iim,xps,1)/apols
 
-         DO ij   = 1, iip1
-          pps (   ij     )  = tpn
-          pps ( ij+ip1jm )  = tps
-         ENDDO
-
-
-       DO iq = 1, nq
-         DO  k    = 1, llm
-           DO  ij   = 1, iim
-            xpn(ij) = aire(   ij   ) * pq(  ij    ,k,iq)
-            xps(ij) = aire(ij+ip1jm) * pq(ij+ip1jm,k,iq)
-           ENDDO
-            tpn      = SSUM(iim,xpn,1)/apoln
-            tps      = SSUM(iim,xps,1)/apols
-
-           DO ij   = 1, iip1
+          DO ij   = 1, iip1
             pq (   ij   ,k,iq)  = tpn
             pq (ij+ip1jm,k,iq)  = tps
-           ENDDO
-         ENDDO
-       ENDDO
-
-      ENDIF
-
+          ENDDO
+        ENDDO
+      ENDDO
 
       RETURN
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/calfis.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/calfis.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/calfis.F	(revision 253)
@@ -141,4 +141,5 @@
       REAL latfi(ngridmx),lonfi(ngridmx)
       REAL airefi(ngridmx)
+      SAVE latfi, lonfi, airefi
 
       LOGICAL firstcal, debut
@@ -311,13 +312,13 @@
 c
       DO l=1,llm
-        pvervel(1,l)=pw(1,1,l)/apoln
+        pvervel(1,l)=pw(1,1,l) * g /apoln
         ig0=2
        DO j=2,jjm
            DO i = 1, iim
-              pvervel(ig0,l) = pw(i,j,l) * unsaire(i,j)
+              pvervel(ig0,l) = pw(i,j,l) * g * unsaire(i,j)
               ig0 = ig0 + 1
            ENDDO
        ENDDO
-        pvervel(ig0,l)=pw(1,jjp1,l)/apols
+        pvervel(ig0,l)=pw(1,jjp1,l) * g /apols
       ENDDO
 
@@ -428,5 +429,6 @@
      ,   rdayvrai,rday_ecri,heure,dtphys,zplev,zplay,zphi,zphis,airefi,
      ,             presnivs,clesphy0,  zufi, zvfi,ztfi, zqfi,  
-     ,             pcvgu, pcvgv, pcvgt, pcvgq, pvervel,
+ccc     ,             pcvgu, pcvgv, pcvgt, pcvgq, 
+     ,             pvervel,
 C - sorties
      s             zdufi, zdvfi, zdtfi, zdqfi,zdpsrf              )
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/coefpoly.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/coefpoly.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/coefpoly.F	(revision 253)
@@ -0,0 +1,38 @@
+c $Header$
+      SUBROUTINE coefpoly ( Xf1, Xf2, Xprim1, Xprim2, xtild1,xtild2 ,
+     ,                                          a0,a1,a2,a3         )
+      IMPLICIT NONE
+c
+c   ...  Auteur :   P. Le Van  ...
+c
+c
+c    Calcul des coefficients a0, a1, a2, a3 du polynome de degre 3 qui
+c      satisfait aux 4 equations  suivantes :
+
+c    a0 + a1*xtild1 + a2*xtild1*xtild1 + a3*xtild1*xtild1*xtild1 = Xf1
+c    a0 + a1*xtild2 + a2*xtild2*xtild2 + a3*xtild2*xtild2*xtild2 = Xf2
+c               a1  +     2.*a2*xtild1 +     3.*a3*xtild1*xtild1 = Xprim1
+c               a1  +     2.*a2*xtild2 +     3.*a3*xtild2*xtild2 = Xprim2
+
+c  On en revient a resoudre un systeme de 4 equat.a 4 inconnues a0,a1,a2,a3
+
+      REAL*8 Xf1, Xf2,Xprim1,Xprim2, xtild1,xtild2, xi 
+      REAL*8 Xfout, Xprim
+      REAL*8 a1,a2,a3,a0, xtil1car, xtil2car,derr,x1x2car
+
+      xtil1car = xtild1 * xtild1
+      xtil2car = xtild2 * xtild2 
+
+      derr= 2. *(Xf2-Xf1)/( xtild1-xtild2)
+
+      x1x2car = ( xtild1-xtild2)*(xtild1-xtild2)
+
+      a3 = (derr + Xprim1+Xprim2 )/x1x2car
+      a2     = ( Xprim1 - Xprim2 + 3.* a3 * ( xtil2car-xtil1car ) )    /
+     /           (  2.* ( xtild1 - xtild2 )  )
+
+      a1     = Xprim1 -3.* a3 * xtil1car     -2.* a2 * xtild1
+      a0     =  Xf1 - a3 * xtild1* xtil1car -a2 * xtil1car - a1 *xtild1
+
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/comvert.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/comvert.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/comvert.h	(revision 253)
@@ -3,5 +3,5 @@
 
       COMMON/comvert/ap(llm+1),bp(llm+1),presnivs(llm),dpres(llm) ,
-     ,               pa,preff,nivsigs(llm),nivsig(llmp1)
+     ,               pa,preff,nivsigs(llm),nivsig(llm+1)
 
       REAL ap,bp,presnivs,dpres,pa,preff,nivsigs,nivsig
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/create_limit.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/create_limit.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/create_limit.F	(revision 253)
@@ -137,5 +137,11 @@
         STOP
       ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_msk)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_msk)
+#endif
+
+c
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -153,10 +159,20 @@
         STOP
       ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_msk)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_msk)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
+#endif
+c
+      if (ierr.ne.0) then
+        print *, NF_STRERROR(ierr)
+        STOP
+      ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,varid,champ_msk)
+#else
       ierr = NF_GET_VAR_REAL(ncid,varid,champ_msk)
+#endif
+c
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -211,5 +227,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlon)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -227,5 +247,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlat)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -243,5 +267,9 @@
         STOP
       ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -260,5 +288,9 @@
          PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
          print*,dimfirst,dimlast
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
+#else
          ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
+#endif
          if (ierr.ne.0) then
            print *, NF_STRERROR(ierr)
@@ -343,5 +375,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlon)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -359,5 +395,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlat)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -375,5 +415,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -391,5 +435,9 @@
 c
          PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
+#else
          ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
+#endif
          if (ierr.ne.0) then
            print *, NF_STRERROR(ierr)
@@ -480,5 +528,10 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlon)
+#endif
+
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -496,5 +549,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlat)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -512,5 +569,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -528,5 +589,9 @@
 c
          PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
+#else
          ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
+#endif
          if (ierr.ne.0) then
            print *, NF_STRERROR(ierr)
@@ -606,5 +671,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlon)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -622,5 +691,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,dlat)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -638,5 +711,9 @@
         STOP
       ENDIF 
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
+#else
       ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
+#endif
       if (ierr.ne.0) then
         print *, NF_STRERROR(ierr)
@@ -654,5 +731,9 @@
 c
          PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
+#else
          ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
+#endif
          if (ierr.ne.0) then
            print *, NF_STRERROR(ierr)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/defrun_new.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/defrun_new.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/defrun_new.F	(revision 253)
@@ -1,2 +1,5 @@
+c
+c $Header$
+c
       SUBROUTINE defrun_new( tapedef, etatinit, clesphy0 )
 c
@@ -36,5 +39,5 @@
       INTEGER   tapeout
       REAL clonn,clatt,grossismxx,grossismyy
-      REAL dzoomxx,dzoomyy
+      REAL dzoomxx,dzoomyy,tauxx,tauyy
       LOGICAL  fxyhypbb, ysinuss
       INTEGER i
@@ -258,9 +261,8 @@
       WRITE(tapeout,*)    clonn
       IF( ABS(clon - clonn).GE. 0.001 )  THEN
-        PRINT *,' La valeur de clon passee par run.def est differente de 
-     *  celle lue sur le fichier  start '
+       WRITE(tapeout,*) ' La valeur de clon passee par run.def est diffe
+     *rente de  celle lue sur le fichier  start '
         STOP
       ENDIF
-c
 c
       READ (tapedef,9001) ch1,ch4
@@ -270,6 +272,6 @@
 
       IF( ABS(clat - clatt).GE. 0.001 )  THEN
-        PRINT *,' La valeur de clat passee par run.def est differente de 
-     *  celle lue sur le fichier  start '
+       WRITE(tapeout,*) ' La valeur de clat passee par run.def est diffe
+     *rente de  celle lue sur le fichier  start '
         STOP
       ENDIF
@@ -281,6 +283,6 @@
 
       IF( ABS(grossismx - grossismxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de grossismx passee par run.def est differente  
-     *  de celle lue sur le fichier  start '
+       WRITE(tapeout,*) ' La valeur de grossismx passee par run.def est
+     , differente de celle lue sur le fichier  start '
         STOP
       ENDIF
@@ -292,11 +294,11 @@
 
       IF( ABS(grossismy - grossismyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de grossismy passee par run.def est differen
-     * te de celle lue sur le fichier  start '
+       WRITE(tapeout,*) ' La valeur de grossismy passee par run.def est
+     , differente de celle lue sur le fichier  start '
         STOP
       ENDIF
       
       IF( grossismx.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismx < 1 .   *** '
+        WRITE(tapeout,*) ' ***  ATTENTION !! grossismx < 1 .   *** '
          STOP
       ELSE
@@ -306,5 +308,5 @@
 
       IF( grossismy.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismy < 1 .   *** '
+        WRITE(tapeout,*) ' ***  ATTENTION !! grossismy < 1 .   *** '
          STOP
       ELSE
@@ -312,5 +314,4 @@
       ENDIF
 
-      PRINT *,' alphax alphay defrun ',alphax,alphay
 c
 c    alphax et alphay sont les anciennes formulat. des grossissements
@@ -324,14 +325,14 @@
       IF( .NOT.fxyhypb )  THEN
            IF( fxyhypbb )     THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' *** fxyhypb lu sur le fichier start est F ',
-     *       'alors  qu il est  T  sur  run.def  ***'
+            WRITE(tapeout,*) ' ********  PBS DANS  DEFRUN  ******** '
+            WRITE(tapeout,*)' *** fxyhypb lu sur le fichier start est F'
+     *,      '                   alors  qu il est  T  sur  run.def  ***'
               STOP
            ENDIF
       ELSE
            IF( .NOT.fxyhypbb )   THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' ***  fxyhypb lu sur le fichier start est T ',
-     *        'alors  qu il est  F  sur  run.def  ****  '
+            WRITE(tapeout,*) ' ********  PBS DANS  DEFRUN  ******** '
+            WRITE(tapeout,*)' *** fxyhypb lu sur le fichier start est t'
+     *,      '                   alors  qu il est  F  sur  run.def  ***'
               STOP
            ENDIF
@@ -343,12 +344,4 @@
       WRITE(tapeout,*)    dzoomxx
 
-      IF( fxyhypb )  THEN
-       IF( ABS(dzoomx - dzoomxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de dzoomx passee par run.def est differente 
-     *  de celle lue sur le fichier  start '
-        STOP
-       ENDIF
-      ENDIF
-
       READ (tapedef,9001) ch1,ch4
       READ (tapedef,*)    dzoomyy
@@ -356,10 +349,40 @@
       WRITE(tapeout,*)    dzoomyy
 
+      READ (tapedef,9001) ch1,ch4
+      READ (tapedef,*)    tauxx
+      WRITE(tapeout,9001) ch1,'taux'
+      WRITE(tapeout,*)    tauxx
+
+      READ (tapedef,9001) ch1,ch4
+      READ (tapedef,*)    tauyy
+      WRITE(tapeout,9001) ch1,'tauy'
+      WRITE(tapeout,*)    tauyy
+
       IF( fxyhypb )  THEN
+
+       IF( ABS(dzoomx - dzoomxx).GE. 0.001 )  THEN
+        WRITE(tapeout,*)' La valeur de dzoomx passee par run.def est dif
+     *ferente de celle lue sur le fichier  start '
+        CALL ABORT
+       ENDIF
+
        IF( ABS(dzoomy - dzoomyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de dzoomy passee par run.def est differente 
-     * de celle lue sur le fichier  start '
-        STOP
+        WRITE(tapeout,*)' La valeur de dzoomy passee par run.def est dif
+     *ferente de celle lue sur le fichier  start '
+        CALL ABORT
        ENDIF
+
+       IF( ABS(taux - tauxx).GE. 0.001 )  THEN
+        WRITE(6,*)' La valeur de taux passee par run.def est differente
+     *  de celle lue sur le fichier  start '
+        CALL ABORT
+       ENDIF
+
+       IF( ABS(tauy - tauyy).GE. 0.001 )  THEN
+        WRITE(6,*)' La valeur de tauy passee par run.def est differente
+     *  de celle lue sur le fichier  start '
+        CALL ABORT
+       ENDIF
+
       ENDIF
       
@@ -374,14 +397,14 @@
         IF( .NOT.ysinus )  THEN
            IF( ysinuss )     THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' *** ysinus lu sur le fichier start est F ',
-     *       'alors  qu il est  T  sur  run.def  ***'
+              WRITE(6,*) ' ********  PBS DANS  DEFRUN  ******** '
+              WRITE(tapeout,*)'** ysinus lu sur le fichier start est F',
+     *       ' alors  qu il est  T  sur  run.def  ***'
               STOP
            ENDIF
         ELSE
            IF( .NOT.ysinuss )   THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' ***  ysinus lu sur le fichier start est T ',
-     *        'alors  qu il est  F  sur  run.def  ****  '
+              WRITE(6,*) ' ********  PBS DANS  DEFRUN  ******** '
+              WRITE(tapeout,*)'** ysinus lu sur le fichier start est T',
+     *       ' alors  qu il est  F  sur  run.def  ***'
               STOP
            ENDIF
@@ -389,5 +412,8 @@
       ENDIF
 c
-      close(tapedef)
+      WRITE(6,*) ' alphax alphay defrun ',alphax,alphay
+
+      CLOSE(tapedef)
+
       RETURN
 c   ...............................................
@@ -416,5 +442,5 @@
 
       IF( grossismx.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismx < 1 .   *** '
+        WRITE(tapeout,*) '***  ATTENTION !! grossismx < 1 .   *** '
          STOP
       ELSE
@@ -423,5 +449,5 @@
 
       IF( grossismy.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismy < 1 .   *** '
+        WRITE(tapeout,*) ' ***  ATTENTION !! grossismy < 1 .   *** '
          STOP
       ELSE
@@ -429,6 +455,4 @@
       ENDIF
 
-      PRINT *,' alphax alphay defrun ',alphax,alphay
-
 c
       READ (tapedef,9001) ch1,ch4
@@ -446,5 +470,15 @@
       WRITE(tapeout,9001) ch1,'dzoomy'
       WRITE(tapeout,*)    dzoomy
-c
+
+      READ (tapedef,9001) ch1,ch4
+      READ (tapedef,*)    taux
+      WRITE(tapeout,9001) ch1,'taux'
+      WRITE(tapeout,*)    taux
+c
+      READ (tapedef,9001) ch1,ch4
+      READ (tapedef,*)    tauy
+      WRITE(tapeout,9001) ch1,'tauy'
+      WRITE(tapeout,*)    tauy
+
       READ (tapedef,9001) ch1,ch4
       READ (tapedef,*)    ysinus
@@ -452,9 +486,11 @@
       WRITE(tapeout,*)    ysinus
        
+      WRITE(tapeout,*) ' alphax alphay defrun ',alphax,alphay
 c
 9000  FORMAT(3(/,a72))
 9001  FORMAT(/,a72,/,a12)
 cc
-      close(tapedef)
+      CLOSE(tapedef)
+
       RETURN
       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/dynetat0.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/dynetat0.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/dynetat0.F	(revision 253)
@@ -1,2 +1,5 @@
+c
+c $Header$
+c
       SUBROUTINE dynetat0(fichnom,nq,vcov,ucov,
      .                    teta,q,masse,ps,phis,time)
@@ -105,4 +108,6 @@
         dzoomx   = tab_cntrl(25)
         dzoomy   = tab_cntrl(26)
+        taux     = tab_cntrl(28)
+        tauy     = tab_cntrl(29)
       ELSE
         fxyhypb = . FALSE .
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/dynredem.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/dynredem.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/dynredem.F	(revision 253)
@@ -1,3 +1,7 @@
+c
+c $Header$
+c
       SUBROUTINE dynredem0(fichnom,idayref,anneeref,phis,nq)
+      USE IOIPSL
       IMPLICIT NONE
 c=======================================================================
@@ -44,6 +48,16 @@
       INTEGER idim_tim
       INTEGER nid,nvarid
+
+      REAL zan0,zjulian,hours
+      INTEGER yyears0,jjour0, mmois0
+      character*30 unites
+
+
 c-----------------------------------------------------------------------
       modname='dynredem'
+
+      call ymds2ju(anneeref,1,idayref,0.0, zjulian)
+      call ju2ymds(zjulian, yyears0,mmois0,jjour0,hours)
+        
 
       DO l=1,length
@@ -81,4 +95,7 @@
        tab_cntrl(25) = dzoomx
        tab_cntrl(26) = dzoomy
+       tab_cntrl(27) = 0.
+       tab_cntrl(28) = taux
+       tab_cntrl(29) = tauy
       ELSE
        tab_cntrl(24) = 0.
@@ -86,5 +103,7 @@
        tab_cntrl(26) = dzoomy
        tab_cntrl(27) = 0.
-       IF( ysinus )  tab_cntrl(27) = 1. 
+       tab_cntrl(28) = 0.
+       tab_cntrl(29) = 0.
+       IF( ysinus )  tab_cntrl(27) = 1.
       ENDIF
 c
@@ -353,4 +372,9 @@
       ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 19,
      .                       "Temps de simulation")
+      write(unites,200)yyears0,mmois0,jjour0
+200   format('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')
+      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "units", 30,
+     .                         unites)
+
 c
       dims4(1) = idim_rlonu
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/etat0_netcdf.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/etat0_netcdf.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/etat0_netcdf.F	(revision 253)
@@ -2,5 +2,5 @@
     
       USE startvar
-      USE IOIPSL
+      USE ioipsl
       !
       IMPLICIT NONE
@@ -20,14 +20,15 @@
       REAL :: orog(iip1,jjp1), rugo(iip1,jjp1), masque(iip1,jjp1),
      . psol(iip1, jjp1), phis(iip1, jjp1)
-      REAL :: p3d(iip1, jjp1, llmp1)
-      REAL :: uvent(iip1, jjp1, llmp1)
-      REAL :: vvent(iip1, jjm, llmp1)
-      REAL :: t3d(iip1, jjp1, llmp1), tpot(iip1, jjp1, llmp1)
-      REAL :: q3d(iip1, jjp1, llmp1,nqmx), qsat(iip1, jjp1, llmp1)
+      REAL :: p3d(iip1, jjp1, llm+1)
+      REAL :: uvent(iip1, jjp1, llm)
+      REAL :: vvent(iip1, jjm, llm)
+      REAL :: t3d(iip1, jjp1, llm), tpot(iip1, jjp1, llm)
+      REAL :: q3d(iip1, jjp1, llm,nqmx), qsat(iip1, jjp1, llm)
       REAL :: tsol(klon), qsol(klon), sn(klon), radsol(klon)
-      REAL :: deltat(klon), rugmer(klon), agesno(klon), zmea(klon)
-      REAL :: zstd(klon), zsig(klon), zgam(klon), zthe(klon)
-      REAL :: zpic(klon), zval(klon), rugsrel(klon)
-      REAL :: qd(iip1, jjp1, llmp1)
+      REAL :: deltat(klon), rugmer(klon), agesno(klon)
+      REAL :: zmea(iip1*jjp1), zstd(iip1*jjp1)
+      REAL :: zsig(iip1*jjp1), zgam(iip1*jjp1), zthe(iip1*jjp1)
+      REAL :: zpic(iip1*jjp1), zval(iip1*jjp1), rugsrel(iip1*jjp1)
+      REAL :: qd(iip1, jjp1, llm)
       !
       CHARACTER*80 :: varname
@@ -54,5 +55,5 @@
       PARAMETER      ( longcles  = 20 )
       REAL :: clesphy0 ( longcles       )
-      REAL :: p(iip1,jjp1,llmp1)
+      REAL :: p(iip1,jjp1,llm)
       INTEGER :: itau, iday
       REAL :: masse(iip1,jjp1,llm)
@@ -62,5 +63,6 @@
       REAL :: pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
       REAL :: w(ip1jmp1,llm)
-      REAL ::phystep,radpas,co2_ppm,solaire
+      REAL ::phystep,co2_ppm,solaire
+      INTEGER :: radpas
 
       CHARACTER*80 :: visu_file
@@ -135,5 +137,5 @@
       varname = 'masque'
       ! This line needs to be replaced by a call to restget to get the values in the restart file
-      rugo(:,:) = 0.0
+      masque(:,:) = 0.0
        CALL startget(varname, iip1, jjp1, rlonv, rlatu, masque, 0.0)
       !
@@ -173,5 +175,4 @@
       phis(:,:) = 0.0
       CALL startget(varname, iip1, jjp1, rlonv, rlatu, phis, 0.0)
-      phis = phis * 9.81
       !
       varname = 'u'
@@ -216,4 +217,5 @@
       varname = 'q'
       qd(:,:,:) = 0.0
+      q3d(:,:,:,:) = 0.0
       WRITE(*,*) 'QSAT min,max:',minval(qsat(:,:,:)),
      .                           maxval(qsat(:,:,:))
@@ -283,18 +285,16 @@
       print *,' ALPHAX ',alphax
 
-      IF( alphax.NE.0. )   THEN
-       DO  l = 1, llm
-         DO  i    = 1, iim
+      DO  l = 1, llm
+        DO  i    = 1, iim
           xppn(i) = aire( i, 1   ) * masse(  i     ,  1   , l )
           xpps(i) = aire( i,jjp1 ) * masse(  i     , jjp1 , l )
-         ENDDO
+        ENDDO
           xpn      = SUM(xppn)/apoln
           xps      = SUM(xpps)/apols
-         DO i   = 1, iip1
+        DO i   = 1, iip1
           masse(   i   ,   1     ,  l )   = xpn
           masse(   i   ,   jjp1  ,  l )   = xps
-         ENDDO
-       ENDDO
-      ENDIF
+        ENDDO
+      ENDDO
       q3d(iip1,:,:,:) = q3d(1,:,:,:)
       phis(iip1,:) = phis(1,:)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/exner_hyb.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/exner_hyb.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/exner_hyb.F	(revision 253)
@@ -53,20 +53,18 @@
 c
       DO   ij  = 1, ngrid
-       pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
+        pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
       ENDDO
 
-      IF( alphax.NE.0. )   THEN
-        DO  ij   = 1, iim
-         ppn(ij) = aire(   ij   ) * pks(  ij     )
-         pps(ij) = aire(ij+ip1jm) * pks(ij+ip1jm )
-        ENDDO
-         xpn      = SSUM(iim,ppn,1) /apoln
-         xps      = SSUM(iim,pps,1) /apols
+      DO  ij   = 1, iim
+        ppn(ij) = aire(   ij   ) * pks(  ij     )
+        pps(ij) = aire(ij+ip1jm) * pks(ij+ip1jm )
+      ENDDO
+      xpn      = SSUM(iim,ppn,1) /apoln
+      xps      = SSUM(iim,pps,1) /apols
 
-        DO ij   = 1, iip1
-         pks(   ij     )  =  xpn
-         pks( ij+ip1jm )  =  xps
-        ENDDO
-      ENDIF
+      DO ij   = 1, iip1
+        pks(   ij     )  =  xpn
+        pks( ij+ip1jm )  =  xps
+      ENDDO
 c
 c
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fluxstoke.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/fluxstoke.F	(revision 3)
+++ 	(revision )
@@ -1,149 +1,0 @@
-      SUBROUTINE fluxstoke(pbaru,pbarv,masse,teta,phi,phis)
-c
-c     Auteur :  F. Hourdin
-c
-c
-ccc   ..   Modif. P. Le Van  ( 20/12/97 )  ...
-c
-      IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "tracstoke.h"
-
-
-      REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
-      REAL masse(ip1jmp1,llm),teta(ip1jmp1,llm),phi(ip1jmp1,llm)
-      REAL phis(ip1jmp1)
-
-      REAL pbaruc(ip1jmp1,llm),pbarvc(ip1jm,llm)
-      REAL massem(ip1jmp1,llm),tetac(ip1jmp1,llm),phic(ip1jmp1,llm)
-
-      REAL pbarug(ip1jmp1,llm),pbarvg(iip1,jjm,llm),wg(ip1jmp1,llm)
-
-      REAL pbarvst(iip1,jjp1,llm)
-
-
-      INTEGER iadvtr 
-      INTEGER ij,l,irec,i,j
- 
-      SAVE iadvtr, massem,pbaruc,pbarvc,irec
-      SAVE phic,tetac
-      logical first
-      save first
-      data first/.true./
-      DATA iadvtr/0/
-
-      if(first) then
-#ifdef CRAY
-         CALL ASSIGN("assign -N ieee -F null f:fluxmass")
-#endif
-         open(47,file='fluxmass',form='unformatted',
-     s        access='direct',recl=4*(6*ijp1llm))
-         irec=1
-         first=.false.
-
-         open(77,file='fluxmass.ctl',status='unknown',form='formatted')
-
-      endif
-
-
-      IF(iadvtr.EQ.0) THEN
-         CALL initial0(ijp1llm,phic)
-         CALL initial0(ijp1llm,tetac)
-         CALL initial0(ijp1llm,pbaruc)
-         CALL initial0(ijmllm,pbarvc)
-      ENDIF
-
-c   accumulation des flux de masse horizontaux
-      DO l=1,llm
-         DO ij = 1,ip1jmp1
-            pbaruc(ij,l) = pbaruc(ij,l) + pbaru(ij,l)
-            tetac(ij,l) = tetac(ij,l) + teta(ij,l)
-            phic(ij,l) = phic(ij,l) + phi(ij,l)
-         ENDDO
-         DO ij = 1,ip1jm
-            pbarvc(ij,l) = pbarvc(ij,l) + pbarv(ij,l)
-         ENDDO
-      ENDDO
-
-c   selection de la masse instantannee des mailles avant le transport.
-      IF(iadvtr.EQ.0) THEN
-         CALL SCOPY(ip1jmp1*llm,masse,1,massem,1)
-      ENDIF
-
-      iadvtr   = iadvtr+1
-
-
-c   Test pour savoir si on advecte a ce pas de temps
-      IF ( iadvtr.EQ.istdyn ) THEN
-
-c    normalisation
-      DO l=1,llm
-         DO ij = 1,ip1jmp1
-            pbaruc(ij,l) = pbaruc(ij,l)/float(istdyn)
-            tetac(ij,l) = tetac(ij,l)/float(istdyn)
-            phic(ij,l) = phic(ij,l)/float(istdyn)
-         ENDDO
-         DO ij = 1,ip1jm
-            pbarvc(ij,l) = pbarvc(ij,l)/float(istdyn)
-         ENDDO
-      ENDDO
-
-c   traitement des flux de masse avant advection.
-c     1. calcul de w
-c     2. groupement des mailles pres du pole.
-
-        CALL groupe( massem, pbaruc,pbarvc, pbarug,pbarvg,wg )
-
-        do l=1,llm
-           do j=1,jjm
-              do i=1,iip1
-                 pbarvst(i,j,l)=pbarvg(i,j,l)
-              enddo
-           enddo
-           do i=1,iip1
-              pbarvst(i,jjp1,l)=0.
-           enddo
-        enddo
-
-         iadvtr=0
-
-         irec=irec+1
-         write(47,rec=1) float(irec),dtvr,float(istdyn),
-     s    float(iim),float(jjm),float(llm),rlonu,rlonv,rlatu,rlatv
-     s    ,aire,phis
-         write(47,rec=irec) massem,pbarug,pbarvst,wg,tetac,phic
-
-c   on reinitialise a zero les flux de masse cumules.
-
-      write(77,'(a4,2x,a40)')
-     &       'DSET ','^fluxmass'
-
-      write(77,'(a12)') 'UNDEF 1.0E30'
-      write(77,'(a5,1x,a40)') 'TITLE ','Titre a voir'
-      call formcoord(77,iip1,rlonv,180./pi,.false.,'XDEF')
-      call formcoord(77,jjp1,rlatu,180./pi,.true.,'YDEF')
-      call formcoord(77,llm,presnivs,1.,.false.,'ZDEF')
-      write(77,'(a4,i10,a30)')
-     &       'TDEF ',irec,' LINEAR 02JAN1987 1DY '
-      write(77,'(a4,2x,i5)') 'VARS',6
-      write(77,1000) 'masse',llm,99,'masse    '
-      write(77,1000) 'pbaru',llm,99,'pbaru    '
-      write(77,1000) 'pbarv',llm,99,'pbarv    '
-      write(77,1000) 'w    ',llm,99,'w        '
-      write(77,1000) 'teta ',llm,99,'teta     '
-      write(77,1000) 'phi  ',llm,99,'phi      '
-      write(77,'(a7)') 'ENDVARS'
-
-1000  format(a5,3x,i4,i3,1x,a39)
-
-
-
-      ENDIF ! if iadvtr.EQ.istdyn
-
-      RETURN
-      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fluxstokenc.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fluxstokenc.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fluxstokenc.F	(revision 253)
@@ -0,0 +1,155 @@
+      SUBROUTINE fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
+     . time_step,itau )
+
+       USE IOIPSL
+c
+c     Auteur :  F. Hourdin
+c
+c
+ccc   ..   Modif. P. Le Van  ( 20/12/97 )  ...
+c
+      IMPLICIT NONE
+c
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comvert.h"
+#include "comgeom.h"
+#include "tracstoke.h"
+#include "temps.h"
+
+      REAL time_step,t_wrt, t_ops
+      REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
+      REAL masse(ip1jmp1,llm),teta(ip1jmp1,llm),phi(ip1jmp1,llm)
+      REAL phis(ip1jmp1)
+
+      REAL pbaruc(ip1jmp1,llm),pbarvc(ip1jm,llm)
+      REAL massem(ip1jmp1,llm),tetac(ip1jmp1,llm),phic(ip1jmp1,llm)
+
+      REAL pbarug(ip1jmp1,llm),pbarvg(iip1,jjm,llm),wg(ip1jmp1,llm)
+
+      REAL pbarvst(iip1,jjp1,llm),zistdyn
+	real dtcum
+
+      INTEGER iadvtr,ndex(1) 
+      integer nscal
+      real tst(1),ist(1),istp(1)
+      INTEGER ij,l,irec,i,j,itau
+      INTEGER fluxid, fluxvid,fluxdid
+ 
+      SAVE iadvtr, massem,pbaruc,pbarvc,irec
+      SAVE phic,tetac
+      logical first
+      save first
+      data first/.true./
+      DATA iadvtr/0/
+
+      if(first) then
+
+	CALL initfluxsto( 'fluxstoke',
+     .  time_step,istdyn* time_step,istdyn* time_step,
+     . nqmx, fluxid,fluxvid,fluxdid) 
+	
+	ndex(1) = 0
+        call histwrite(fluxid, 'phis', 1, phis, iip1*jjp1, ndex)
+        call histwrite(fluxid, 'aire', 1, aire, iip1*jjp1, ndex)
+	
+	ndex(1) = 0
+        nscal = 1
+        tst(1) = time_step
+        call histwrite(fluxdid, 'dtvr', 1, tst, nscal, ndex)
+        ist(1)=istdyn
+        call histwrite(fluxdid, 'istdyn', 1, ist, nscal, ndex)
+        istp(1)= istphy
+        call histwrite(fluxdid, 'istphy', 1, istp, nscal, ndex)
+	
+	first = .false.
+
+      endif
+
+
+      IF(iadvtr.EQ.0) THEN
+         CALL initial0(ijp1llm,phic)
+         CALL initial0(ijp1llm,tetac)
+         CALL initial0(ijp1llm,pbaruc)
+         CALL initial0(ijmllm,pbarvc)
+      ENDIF
+
+c   accumulation des flux de masse horizontaux
+      DO l=1,llm
+         DO ij = 1,ip1jmp1
+            pbaruc(ij,l) = pbaruc(ij,l) + pbaru(ij,l)
+            tetac(ij,l) = tetac(ij,l) + teta(ij,l)
+            phic(ij,l) = phic(ij,l) + phi(ij,l)
+         ENDDO
+         DO ij = 1,ip1jm
+            pbarvc(ij,l) = pbarvc(ij,l) + pbarv(ij,l)
+         ENDDO
+      ENDDO
+
+c   selection de la masse instantannee des mailles avant le transport.
+      IF(iadvtr.EQ.0) THEN
+         CALL SCOPY(ip1jmp1*llm,masse,1,massem,1)
+      ENDIF
+
+      iadvtr   = iadvtr+1
+
+
+c   Test pour savoir si on advecte a ce pas de temps
+      IF ( iadvtr.EQ.istdyn ) THEN
+c    normalisation
+      DO l=1,llm
+         DO ij = 1,ip1jmp1
+            pbaruc(ij,l) = pbaruc(ij,l)/float(istdyn)
+            tetac(ij,l) = tetac(ij,l)/float(istdyn)
+            phic(ij,l) = phic(ij,l)/float(istdyn)
+         ENDDO
+         DO ij = 1,ip1jm
+            pbarvc(ij,l) = pbarvc(ij,l)/float(istdyn)
+         ENDDO
+      ENDDO
+
+c   traitement des flux de masse avant advection.
+c     1. calcul de w
+c     2. groupement des mailles pres du pole.
+
+        CALL groupe( massem, pbaruc,pbarvc, pbarug,pbarvg,wg )
+
+        do l=1,llm
+           do j=1,jjm
+              do i=1,iip1
+                 pbarvst(i,j,l)=pbarvg(i,j,l)
+              enddo
+           enddo
+           do i=1,iip1
+              pbarvst(i,jjp1,l)=0.
+           enddo
+        enddo
+
+         iadvtr=0
+	Print*,'ITAU auqel on stoke les fluxmasses',itau
+	
+	call histwrite(fluxid, 'masse', itau, massem,
+     .               iip1*jjp1*llm, ndex)
+	
+	call histwrite(fluxid, 'pbaru', itau, pbarug,
+     .               iip1*jjp1*llm, ndex)
+	
+	call histwrite(fluxvid, 'pbarv', itau, pbarvg,
+     .               iip1*jjm*llm, ndex)
+	
+        call histwrite(fluxid, 'w' ,itau, wg, 
+     .             iip1*jjp1*llm, ndex) 
+	
+	call histwrite(fluxid, 'teta' ,itau, tetac, 
+     .             iip1*jjp1*llm, ndex) 
+	
+	call histwrite(fluxid, 'phi' ,itau, phic, 
+     .             iip1*jjp1*llm, ndex) 
+	
+C
+
+      ENDIF ! if iadvtr.EQ.istdyn
+
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fxhyp.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/fxhyp.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fxhyp.F	(revision 253)
@@ -1,4 +1,5 @@
        SUBROUTINE fxhyp ( xzoomdeg,grossism,dzoom,tau ,
-     , rlonm025,xprimm025,rlonv,xprimv,rlonu,xprimu,rlonp025,xprimp025)
+     , rlonm025,xprimm025,rlonv,xprimv,rlonu,xprimu,rlonp025,xprimp025,
+     , champmin,champmax                                               )
 
 c      Auteur :  P. Le Van 
@@ -11,9 +12,12 @@
 c     grossism etant le grossissement ( = 2 si 2 fois, = 3 si 3 fois,etc.)
 c     dzoom  etant  la distance totale de la zone du zoom
-c     tau  la transition ,   normalement  = 1  .
-c
+c     tau  la raideur de la transition de l'interieur a l'exterieur du zoom
+c
+c    On doit avoir grossism x dzoom <  pi ( radians )   , en longitude.
+c   ********************************************************************
+
 
        INTEGER nmax, nmax2
-       PARAMETER (  nmax = 50000, nmax2 = 2*nmax )
+       PARAMETER (  nmax = 30000, nmax2 = 2*nmax )
 
 #include "dimensions.h"
@@ -23,63 +27,114 @@
 c
        REAL xzoomdeg,dzoom,tau,grossism
+
+c    ......   arguments  de  sortie  ......
+
        REAL rlonm025(iip1),xprimm025(iip1),rlonv(iip1),xprimv(iip1),
      ,  rlonu(iip1),xprimu(iip1),rlonp025(iip1),xprimp025(iip1)
 
-c    ......   arguments  de  sortie  ......
-c
-       REAL xlon(iip1),xprimm(iip1),xuv
-       REAL xtild(0:nmax2)
-       REAL fhyp(0:nmax),ffdx(0:nmax),beta,Xprimt(0:nmax2)
-       REAL Xf(0:nmax2),xxpr(0:nmax2)
-       REAL xvrai(iip1),xxprim(iip1) 
-       REAL pi,depi,epsilon,xzoom
+c     .... variables locales  ....
+c
+       REAL*8 xlon(iip1),xprimm(iip1),xuv
+       REAL*8 xtild(0:nmax2)
+       REAL*8 fhyp(0:nmax2),ffdx,beta,Xprimt(0:nmax2)
+       REAL*8 Xf(0:nmax2),xxpr(0:nmax2)
+       REAL*8 xvrai(iip1),xxprim(iip1) 
+       REAL*8 pi,depi,epsilon,xzoom,fa,fb
+       REAL*8 Xf1, Xfi , a0,a1,a2,a3,xi2
        INTEGER i,it,ik,iter,ii,idif
-       REAL xi,xo1,xint,xmoy,xlon2,fxm,Xprimin
-       REAL champmin,champmax
+       REAL*8 xi,xo1,xmoy,xlon2,fxm,Xprimin
+       REAL*8 champmin,champmax
        INTEGER is2
        SAVE is2
-       REAL dlon1(iip1),dlon2(iip1),dlon3(iip1)
+
+       REAL*8 heavyside
+       EXTERNAL coefpoly,heavyside
 
        pi       = 2. * ASIN(1.)
        depi     = 2. * pi
-       epsilon  = 1.e-6
+       epsilon  = 1.e-3
        xzoom    = xzoomdeg * pi/180. 
 
-
+       IF( dzoom.LT.1.)  THEN
+         dzoom = dzoom * depi
+       ELSEIF( dzoom.LT. 25. ) THEN
+         WRITE(6,*) ' Le param. dzoomy pour fxhyp est trop petit ! L aug
+     ,menter et relancer ! '
+         STOP 1
+       ELSE
+         dzoom = dzoom * pi/180.
+       ENDIF
+
+       WRITE(6,*) ' xzoom( rad.),grossism,tau,dzoom (radians)'
+       WRITE(6,24) xzoom,grossism,tau,dzoom
 
        DO i = 0, nmax2 
-         xtild(i) = FLOAT(i) /nmax2
-        IF( xtild(i).EQ. 0.5 )  xtild(i) = xtild(i) + 1.e-6
-       ENDDO
-
-       DO i = 1, nmax
-        fhyp(i) = TANH ( ( xtild(i) - 0.5*(1.- dzoom) )          /
-     ,                 ( tau * xtild(i) * ( 0.5 -xtild(i))) )
-       ENDDO
-
-        fhyp(   0  ) = - 1.
-        fhyp( nmax ) =   1.
+        xtild(i) = - pi + FLOAT(i) * depi /nmax2
+       ENDDO
+
+       DO i = 0, nmax2
+
+       fa  = tau*  ( dzoom/2.  - xtild(i) )
+       fb  = xtild(i) *  ( pi - xtild(i) )
+
+
+       if ( xtild(i) .ne. 0. .and. xtild(i) .ne. pi) then
+         IF( 200.* fb .LT. - fa )   THEN
+           fhyp ( i) = - 1.
+         ELSEIF( 200. * fb .LT. fa ) THEN
+           fhyp ( i) =   1.
+         ELSE
+           fhyp(i) =  TANH ( fa/fb )
+         ENDIF
+       endif
+
+       IF ( xtild(i).EQ. 0. )  fhyp(i) =  1.
+       IF ( xtild(i).EQ. pi )  fhyp(i) = -1.
+
+       ENDDO
 
 cc  ....  Calcul  de  beta  ....
-c
-       ffdx( 0 ) = 0.
-
-       DO i = 1, nmax
-        xmoy    = 0.5 * ( xtild(i-1) + xtild( i ) )
-        fxm     = TANH ( ( xmoy - 0.5 * ( 1. - dzoom ) )    /
-     ,                 ( tau * xmoy * ( 0.5 -xmoy)) )
-        ffdx(i) = ffdx(i-1) + fxm * ( xtild(i) - xtild(i-1) )
-       ENDDO
-
-        beta  = ( grossism * ffdx(nmax) - 0.5 ) / ( ffdx(nmax) - 0.5 )
+c   ............................
+
+       ffdx = 0.
+
+       DO i = nmax +1,nmax2
+
+       xmoy    = 0.5 * ( xtild(i-1) + xtild( i ) )
+       fa  = tau*  ( dzoom/2.  - xmoy )
+       fb  = xmoy *  ( pi - xmoy )
+
+       IF( 200.* fb .LT. - fa )   THEN
+         fxm = - 1.
+       ELSEIF( 200. * fb .LT. fa ) THEN
+         fxm =   1.
+       ELSE
+         fxm =  TANH ( fa/fb )
+       ENDIF
+
+       IF ( xmoy.EQ. 0. )  fhyp(i) =  1.
+       IF ( xmoy.EQ. pi )  fhyp(i) = -1.
+       ffdx = ffdx + fxm * ( xtild(i) - xtild(i-1) )
+
+       ENDDO
+
+        beta  = ( grossism * ffdx - pi ) / ( ffdx - pi )
+
+       IF( 2.*beta - grossism.LE. 0.)  THEN
+        WRITE(6,*) ' **  Attention ! La valeur beta calculee dans la rou
+     ,tine fxhyp est mauvaise ! '
+        WRITE(6,*)'Modifier les valeurs de  grossismx ,tau ou dzoomx ',
+     , ' et relancer ! ***  '
+        CALL ABORT
+       ENDIF
 c
 c   .....  calcul  de  Xprimt   .....
 c
        
-       DO i = 0, nmax
+       DO i = nmax, nmax2
         Xprimt(i) = beta  + ( grossism - beta ) * fhyp(i)
        ENDDO
 c   
-       DO i = 0, nmax
+       DO i =  nmax+1, nmax2
         Xprimt( nmax2 - i ) = Xprimt( i )
        ENDDO
@@ -88,14 +143,28 @@
 c   .....  Calcul  de  Xf     ........
 
-        Xf(0) = 0.
-       DO i = 1, nmax
-        xmoy    = 0.5 * ( xtild(i-1) + xtild( i ) )
-        fxm     = TANH ( ( xmoy - 0.5 * ( 1. - dzoom ) )    /
-     ,                 ( tau * xmoy * ( 0.5 -xmoy)) )
-        xxpr(i)    = beta + ( grossism - beta ) * fxm
-       ENDDO
-
-       DO i = 1,nmax
-         xxpr(nmax2-i+1) = xxpr(i)
+       Xf(0) = - pi
+
+       DO i =  nmax +1, nmax2
+
+       xmoy    = 0.5 * ( xtild(i-1) + xtild( i ) )
+       fa  = tau*  ( dzoom/2.  - xmoy )
+       fb  = xmoy *  ( pi - xmoy )
+
+       IF( 200.* fb .LT. - fa )   THEN
+         fxm = - 1.
+       ELSEIF( 200. * fb .LT. fa ) THEN
+         fxm =   1.
+       ELSE
+         fxm =  TANH ( fa/fb )
+       ENDIF
+
+       IF ( xmoy.EQ. 0. )  fxm =  1.
+       IF ( xmoy.EQ. pi )  fxm = -1.
+       xxpr(i)    = beta + ( grossism - beta ) * fxm
+
+       ENDDO
+
+       DO i = nmax+1, nmax2
+        xxpr(nmax2-i+1) = xxpr(i)
        ENDDO
 
@@ -103,10 +172,4 @@
          Xf(i)   = Xf(i-1) + xxpr(i) * ( xtild(i) - xtild(i-1) )
         ENDDO
-        do i=1,nmax2
-        xf(i)=xf(i)/xf(nmax2)
-        enddo
-
-
-       PRINT *,' XF ',xf(0),xf(nmax),xf(nmax2)
 
 
@@ -117,4 +180,5 @@
 c     .....  xuv = 0.5  si  calcul  aux pts      U        ........
 c
+      WRITE(6,18)
 c
       DO 5000  ik = 1, 4
@@ -130,66 +194,68 @@
        ENDIF
 
+      xo1   = 0.
 
       DO 1500 i = 1, iim
 
-      xlon2 = (  FLOAT(i) + xuv - 0.75) / FLOAT(iim) 
-
-      xo1   = 0.
-      xi    = xlon2
-c
-      DO 500 iter = 1,300
-
+      xlon2 = - pi + (FLOAT(i) + xuv - 0.75) * depi / FLOAT(iim) 
+
+      Xfi    = xlon2
+c
       DO 250 it =  nmax2,0,-1
-      IF( xi.GE.xtild(it))  GO TO 350
+      IF( Xfi.GE.Xf(it))  GO TO 350
 250   CONTINUE
 
       it = 0
-      xi = xtild(it)
 
 350   CONTINUE
-       IF(it.EQ.nmax2)  THEN
-        it       = nmax2 -1
-        xf(it+1) = 1.
-       ENDIF
-c  .................................................................
-c  ....  Interpolation entre  xi(it) et xi(it+1)   pour avoir X(xi)  
-c      .....           et   X'(xi)                             .....
-c  .................................................................
-
-       xint   = ( Xf(it+1)-Xf(it) ) / ( xtild(it+1)-xtild(it) )      * 
-     +                    ( xi-xtild(it) )  +  Xf(it)
-      Xprimin = ( Xprimt(it+1)-Xprimt(it) )/ ( xtild(it+1)-xtild(it) ) *
-     +                    ( xi-xtild(it) )  +  Xprimt(it)
-
-       xi = xi - (xint-xlon2)/Xprimin
-
-      IF( ABS(xi-xo1).LE.epsilon) GO TO 550
-      xo1 = xi
-c
+
+c    ......  Calcul de   Xf(xi)    ...... 
+c
+      xi  = xtild(it)
+
+      IF(it.EQ.nmax2)  THEN
+       it       = nmax2 -1
+       Xf(it+1) = pi
+      ENDIF
+c  .....................................................................
+c
+c   Appel de la routine qui calcule les coefficients a0,a1,a2,a3 d'un
+c   polynome de degre 3  qui passe  par les points (Xf(it),xtild(it) )
+c          et (Xf(it+1),xtild(it+1) )
+
+       CALL coefpoly ( Xf(it),Xf(it+1),Xprimt(it),Xprimt(it+1),
+     ,                xtild(it),xtild(it+1),  a0, a1, a2, a3  )
+
+       Xf1     = Xf(it)
+       Xprimin = a1 + 2.* a2 * xi + 3.*a3 * xi *xi
+
+       DO 500 iter = 1,300
+        xi = xi - ( Xf1 - Xfi )/ Xprimin
+
+        IF( ABS(xi-xo1).LE.epsilon)  GO TO 550
+         xo1      = xi
+         xi2      = xi * xi
+         Xf1      = a0 +  a1 * xi +     a2 * xi2  +     a3 * xi2 * xi
+         Xprimin  =       a1      + 2.* a2 *  xi  + 3.* a3 * xi2
 500   CONTINUE
-      PRINT *,' ***   PAS DE SOLUTION  ****  ',i,xlon2
-        STOP 4
+        WRITE(6,*) ' Pas de solution ***** ',i,xlon2,iter
+          STOP 6
 550   CONTINUE
 
-       xxprim(i)   = depi/( FLOAT(iim) * Xprimin)
-       xvrai(i)    = depi *  (xi - 0.5) + xzoom
-
+       xxprim(i) = depi/ ( FLOAT(iim) * Xprimin )
+       xvrai(i)  =  xi + xzoom
 
 1500   CONTINUE
 
        DO i = 1 , iim
-        xlon  (i)   = xvrai(i)
+        xlon(i)     = xvrai(i)
         xprimm(i)   = xxprim(i)
-cc        xxlon(i) = xlon(i)*180./pi
        ENDDO
         
-cc      PRINT *,' XLON avant '
-cc      PRINT 68,(xxlon(i),i=1,iim)
-       
        DO i = 1, iim -1
         IF( xvrai(i+1). LT. xvrai(i) )  THEN
-         PRINT *,' PBS.  avec  rlonu(',i+1,' plus petit que rlonu(',i,
-     ,   ')'
-         STOP
+         WRITE(6,*) ' PBS. avec rlonu(',i+1,') plus petit que rlonu(',i,
+     ,  ')'
+        STOP 7
         ENDIF
        ENDDO
@@ -205,12 +271,9 @@
        ENDDO
 
-       PRINT *,' LONGITUDES  min max ',champmin,champmax
-
       IF(champmin .GE. - pi .AND. champmax.LE. pi )  THEN
                 GO TO 1600
       ELSE
-        PRINT 18
-        PRINT *,'Reorganisation des longitudes pour avoir entre - pi ',
-     ,  ' et  pi '
+       WRITE(6,*) 'Reorganisation des longitudes pour avoir entre - pi',
+     ,  ' et pi '
 c
         IF( xzoom.LE.0.)  THEN
@@ -219,6 +282,6 @@
            IF( xvrai(i).GE. - pi )  GO TO 80
           ENDDO
-            PRINT *, ' PBS. 1 '
-            STOP
+            WRITE(6,*)  ' PBS. 1 !  Xvrai plus petit que  - pi ! '
+            STOP 8
  80       CONTINUE
           is2 = i
@@ -240,10 +303,9 @@
             IF( xvrai(i).LE. pi )  GO TO 90
            ENDDO
-             PRINT *,' PBS.  2 '
-              STOP
+             WRITE(6,*) ' PBS.  2 ! Xvrai plus grand  que   pi ! '
+              STOP 9
  90        CONTINUE
             is2 = i
           ENDIF
-cc           PRINT *,' IS2 ',is2
            idif = iim -is2
            DO ii = 1, is2
@@ -270,84 +332,76 @@
          ENDDO
 
-
          IF( ik.EQ.1 )  THEN
-         PRINT *, ' XLON aux pts. V-0.25   apres ( en  deg. ) '
-         PRINT 18
-         PRINT 68,xvrai
-         PRINT *,' XPRIM '
-         PRINT 68, xprimm
+c          WRITE(6,*)  ' XLON aux pts. V-0.25   apres ( en  deg. ) '
+c          WRITE(6,18) 
+c          WRITE(6,68) xvrai
+ccc          WRITE(6,*) ' XPRIM k ',ik
+ccc          WRITE(6,566)  xprimm
+
            DO i = 1,iim + 1
              rlonm025(i) = xlon( i )
             xprimm025(i) = xprimm(i)
            ENDDO
+
          ELSE IF( ik.EQ.2 )  THEN
-         PRINT 18
-         PRINT *, ' XLON aux pts. V   apres ( en  deg. ) '
-         PRINT 68,xvrai
-         PRINT *,' XPRIM '
-         PRINT 68, xprimm
+c          WRITE(6,18) 
+c          WRITE(6,*)  ' XLON aux pts. V   apres ( en  deg. ) '
+c          WRITE(6,68) xvrai
+ccc          WRITE(6,*) ' XPRIM k ',ik
+ccc          WRITE(6,566)  xprimm
+
            DO i = 1,iim + 1
              rlonv(i) = xlon( i )
             xprimv(i) = xprimm(i)
            ENDDO
-         ELSE IF( ik.EQ.3 )  THEN
-         PRINT 18
-         PRINT *, ' XLON aux pts. U   apres ( en  deg. ) '
-         PRINT 68,xvrai
-         PRINT *,' XPRIM '
-         PRINT 68, xprimm
+
+         ELSE IF( ik.EQ.3)   THEN
+c          WRITE(6,18) 
+c          WRITE(6,*)  ' XLON aux pts. U   apres ( en  deg. ) '
+c          WRITE(6,68) xvrai
+ccc          WRITE(6,*) ' XPRIM ik ',ik
+ccc          WRITE(6,566)  xprimm
+
            DO i = 1,iim + 1
              rlonu(i) = xlon( i )
             xprimu(i) = xprimm(i)
            ENDDO
+
          ELSE IF( ik.EQ.4 )  THEN
-         PRINT 18
-         PRINT *, ' XLON aux pts. V+0.25   apres ( en  deg. ) '
-         PRINT 68,xvrai
-         PRINT *,' XPRIM '
-         PRINT 68, xprimm
+c          WRITE(6,18) 
+c          WRITE(6,*)  ' XLON aux pts. V+0.25   apres ( en  deg. ) '
+c          WRITE(6,68) xvrai
+ccc          WRITE(6,*) ' XPRIM ik ',ik
+ccc          WRITE(6,566)  xprimm
+
            DO i = 1,iim + 1
              rlonp025(i) = xlon( i )
             xprimp025(i) = xprimm(i)
            ENDDO
+
          ENDIF
 
 5000    CONTINUE
 c
-c       ...........  fin  de la boucle  do 5000      ............
-
-c
-        DO i = 1, iim + 1
-         dlon1(i) = rlonm025(i) - rlonv(i)
-         dlon2(i) = rlonm025(i) - rlonp025(i)
-         dlon3(i) = rlonm025(i) - rlonu(i)
+       WRITE(6,18)
+c
+c    ...........  fin  de la boucle  do 5000      ............
+
+        DO i = 1, iim
+         xlon(i) = rlonv(i+1) - rlonv(i)
         ENDDO
-
-        DO i = 1, iim + 1
-         rlonm025(i) = rlonm025(i) + dlon1(i)
+        champmin =  1.e12
+        champmax = -1.e12
+        DO i = 1, iim
+         champmin = MIN( champmin, xlon(i) )
+         champmax = MAX( champmax, xlon(i) )
         ENDDO
-
-        DO i = 1, iim + 1
-         rlonv(i)    = rlonm025(i) - dlon1(i)
-         rlonp025(i) = rlonm025(i) - dlon2(i)
-         rlonu(i)    = rlonm025(i) - dlon3(i)
-        ENDDO
-
-        DO i = 1, iim
-         xprimu   (i) = rlonu(i+1) - rlonu(i)
-         xprimv   (i) = rlonv(i+1) - rlonv(i)
-         xprimm025(i) = rlonm025(i+1) - rlonm025(i)
-         xprimp025(i) = rlonp025(i+1) - rlonp025(i)
-        ENDDO
-         xprimu   (iip1) = xprimu   (1)
-         xprimv   (iip1) = xprimv   (1)
-         xprimm025(iip1) = xprimm025(1)
-         xprimp025(iip1) = xprimp025(1)
-
-
-18       FORMAT(/)
-68       FORMAT(1x,7f9.2)
-
-
-         RETURN
-         END
+         champmin = champmin * 180./pi
+         champmax = champmax * 180./pi
+
+18     FORMAT(/)
+24     FORMAT(2x,'Parametres xzoom,gross,tau ,dzoom pour fxhyp ',4f8.3)
+68     FORMAT(1x,7f9.2)
+
+       RETURN
+       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fxyhyper.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/fxyhyper.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fxyhyper.F	(revision 253)
@@ -1,4 +1,7 @@
-       SUBROUTINE fxyhyper ( yzoom, grossy, dzoomy,tauy,deltay  , 
-     ,                      xzoom, grossx, dzoomx,taux,
+c
+c $Header$
+c
+       SUBROUTINE fxyhyper ( yzoom, grossy, dzoomy,tauy  ,   
+     ,                       xzoom, grossx, dzoomx,taux  ,
      , rlatu,yprimu,rlatv,yprimv,rlatu1,  yprimu1,  rlatu2,  yprimu2  , 
      , rlonu,xprimu,rlonv,xprimv,rlonm025,xprimm025,rlonp025,xprimp025)
@@ -19,13 +22,9 @@
 c     a) le grossissement du zoom  :  grossy  ( en y ) et grossx ( en x )
 c     b) l' extension     du zoom  :  dzoomy  ( en y ) et dzoomx ( en x )
-c     c) la raideur       du zoom  :   tau   , ici  =  1.
+c     c) la raideur de la transition du zoom  :   taux et tauy   
 c
-c     N.B :   le produit ( grossissement * extension )  doit etre <  1.
-c    *******
-c     En plus , il y a un autre parametre , moins important mais quand
-c     meme utile , c'est  deltay , deplacement de la zone du zoom en
-c     latitude   :  Si  on deplace  de 10. degres vers le nord  ( deltay
-c      = 10.  dans inigeom ) .
-c
+c  N.B : Il vaut mieux avoir   :   grossx * dzoomx <  pi    ( radians )
+c ******
+c                  et              grossy * dzoomy <  pi/2  ( radians )
 c
 #include "dimensions.h"
@@ -40,5 +39,5 @@
        REAL rlonu(iip1),xprimu(iip1),rlonv(iip1),xprimv(iip1),
      , rlonm025(iip1),xprimm025(iip1), rlonp025(iip1),xprimp025(iip1)
-       REAL deltay
+       REAL*8  dxmin, dxmax , dymin, dymax
 
 c   ....   var. locales   .....
@@ -47,30 +46,30 @@
 c
 
-       CALL fyhyp ( yzoom, grossy, dzoomy,tauy, deltay , 
-     ,  rlatu, yprimu,rlatv,yprimv,rlatu2,yprimu2,rlatu1,yprimu1 )
+       CALL fyhyp ( yzoom, grossy, dzoomy,tauy  , 
+     ,  rlatu, yprimu,rlatv,yprimv,rlatu2,yprimu2,rlatu1,yprimu1 ,
+     ,  dymin,dymax                                               )
+
+       CALL fxhyp(xzoom,grossx,dzoomx,taux,rlonm025,xprimm025,rlonv,
+     , xprimv,rlonu,xprimu,rlonp025,xprimp025 , dxmin,dxmax         )
 
 
-       CALL fxhyp(xzoom,grossx,dzoomx,taux,rlonm025,xprimm025,rlonv,
-     , xprimv,rlonu,xprimu,rlonp025,xprimp025 )
-
-
-        DO i = 1, iim
+        DO i = 1, iip1
           IF(rlonp025(i).LT.rlonv(i))  THEN
-           PRINT *,' Attention !  rlonp025 < rlonv',i
+           WRITE(6,*) ' Attention !  rlonp025 < rlonv',i
             STOP
           ENDIF
 
           IF(rlonv(i).LT.rlonm025(i))  THEN 
-           PRINT *,' Attention !  rlonm025 > rlonv',i
+           WRITE(6,*) ' Attention !  rlonm025 > rlonv',i
             STOP
           ENDIF
 
           IF(rlonp025(i).GT.rlonu(i))  THEN
-           PRINT *,' Attention !  rlonp025 > rlonu',i
+           WRITE(6,*) ' Attention !  rlonp025 > rlonu',i
             STOP
           ENDIF
         ENDDO
 
-        PRINT *,'  *** TEST DE COHERENCE  OK    POUR   FX **** '
+        WRITE(6,*) '  *** TEST DE COHERENCE  OK    POUR   FX **** '
 
 c
@@ -78,30 +77,30 @@
 c
        IF(rlatu1(j).LE.rlatu2(j))   THEN
-         PRINT *,' Attention ! rlatu1 < rlatu2 ',rlatu1(j), rlatu2(j),j
+         WRITE(6,*)'Attention ! rlatu1 < rlatu2 ',rlatu1(j), rlatu2(j),j
          STOP 13
        ENDIF
 c
        IF(rlatu2(j).LE.rlatu(j+1))  THEN
-        PRINT *,' Attention ! rlatu2 < rlatup1 ',rlatu2(j),rlatu(j+1),j
+        WRITE(6,*)'Attention ! rlatu2 < rlatup1 ',rlatu2(j),rlatu(j+1),j
         STOP 14
        ENDIF
 c
        IF(rlatu(j).LE.rlatu1(j))    THEN
-        PRINT *,' Attention ! rlatu < rlatu1 ',rlatu(j),rlatu1(j),j
+        WRITE(6,*)' Attention ! rlatu < rlatu1 ',rlatu(j),rlatu1(j),j
         STOP 15
        ENDIF
 c
        IF(rlatv(j).LE.rlatu2(j))    THEN
-        PRINT *,' Attention ! rlatv < rlatu2 ',rlatv(j),rlatu2(j),j
+        WRITE(6,*)' Attention ! rlatv < rlatu2 ',rlatv(j),rlatu2(j),j
         STOP 16
        ENDIF
 c
        IF(rlatv(j).ge.rlatu1(j))    THEN
-        PRINT *,' Attention ! rlatv > rlatu1 ',rlatv(j),rlatu1(j),j
+        WRITE(6,*)' Attention ! rlatv > rlatu1 ',rlatv(j),rlatu1(j),j
         STOP 17
        ENDIF
 c
        IF(rlatv(j).ge.rlatu(j))     THEN
-        PRINT *,'Attention ! rlatv > rlatu ',rlatv(j),rlatu(j),j
+        WRITE(6,*) ' Attention ! rlatv > rlatu ',rlatv(j),rlatu(j),j
         STOP 18
        ENDIF
@@ -109,7 +108,28 @@
        ENDDO
 c
-       PRINT *,'  *** TEST DE COHERENCE  OK    POUR   FY **** '
-
+       WRITE(6,*) '  *** TEST DE COHERENCE  OK    POUR   FY **** '
 c
+        WRITE(6,18)
+        WRITE(6,*) '  Latitudes  '
+        WRITE(6,*) ' *********** '
+        WRITE(6,18)
+        WRITE(6,3)  dymin, dymax
+        WRITE(6,*) ' Si cette derniere est trop lache , modifiez les par
+     ,ametres  grossism , tau , dzoom pour Y et repasser ! '
+c
+        WRITE(6,18)
+        WRITE(6,*) '  Longitudes  '
+        WRITE(6,*) ' ************ '
+        WRITE(6,18)
+        WRITE(6,3)  dxmin, dxmax
+        WRITE(6,*) ' Si cette derniere est trop lache , modifiez les par
+     ,ametres  grossism , tau , dzoom pour Y et repasser ! '
+        WRITE(6,18)
+c
+3      Format(1x, ' Au centre du zoom , la longueur de la maille est',
+     ,  ' d environ ',f8.2 ,' degres  ',
+     , ' alors que la maille en dehors de la zone du zoom est d environ
+     , ', f8.2,' degres ' )
+18      FORMAT(/)
 
        RETURN
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fyhyp.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/fyhyp.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/fyhyp.F	(revision 253)
@@ -1,5 +1,10 @@
-       SUBROUTINE fyhyp ( yzoomdeg, grossism, dzoom,tau,deltay ,  
-     ,  rrlatu,yyprimu,rrlatv,yyprimv,rlatu2,yprimu2,rlatu1,yprimu1 ) 
-
+C
+c $Header$
+c
+       SUBROUTINE fyhyp ( yzoomdeg, grossism, dzoom,tau  ,  
+     ,  rrlatu,yyprimu,rrlatv,yyprimv,rlatu2,yprimu2,rlatu1,yprimu1 ,
+     ,  champmin,champmax                                            ) 
+
+cc    ...  Version du 01/04/2001 ....
 
        IMPLICIT NONE
@@ -13,14 +18,10 @@
 c
 c     grossism etant le grossissement ( = 2 si 2 fois, = 3 si 3 fois , etc)
-c     dzoom  etant  la distance totale de la zone du zoom
-c     tau  la transition ,   normalement  = 1  .
-
-c  N.B :  on doit avoir :  grossism * dzoom  <   1 .
-c         **************
-c
-c    Pour Indoex , on a pris :
-c         *******
-c    grossism = 2.5 , dzoom = 7/24  en x et  y  , pour iim = 128 et jjm=64
-c    yzoomdeg = 0.  , tau = 1.  et delaty = 10.
+c     dzoom  etant  la distance totale de la zone du zoom ( en radians )
+c     tau  la raideur de la transition de l'interieur a l'exterieur du zoom   
+c
+c
+c N.B : Il vaut mieux avoir : grossism * dzoom  <  pi/2  (radians) ,en lati.
+c      ********************************************************************
 c
 c
@@ -29,10 +30,11 @@
 
        INTEGER      nmax , nmax2
-       PARAMETER (  nmax = 50000, nmax2 = 2*nmax )
+       PARAMETER (  nmax = 30000, nmax2 = 2*nmax )
 c
 c
 c     .......  arguments  d'entree    .......
 c
-       REAL yzoomdeg, grossism,dzoom,tau , deltay
+       REAL yzoomdeg, grossism,dzoom,tau 
+c         ( rentres  par  run.def )
 
 c     .......  arguments  de sortie   .......
@@ -42,17 +44,18 @@
 
 c
-c    ..... Champs  locaux    .....
+c     .....     champs  locaux    .....
 c
      
-       REAl ylat(jjp1), yprim(jjp1)
-       REAL yuv
-       REAL ytild(0:nmax2)
-       REAL fhyp(0:nmax),ffdx(0:nmax),beta,Ytprim(0:nmax2)
-       SAVE Ytprim, ytild,Yf
-       REAL Yf(0:nmax2),yypr(0:nmax2)
-       REAL yvrai(jjp1), yprimm(jjp1),ylatt(jjp1)
-       REAL pi,depi,pis2,epsilon,yzoom
-       REAL yo1,yi,ylon2,fxm,ymoy,yint,Yprimin
-       REAL ypn,deply,y00
+       REAL*8 ylat(jjp1), yprim(jjp1)
+       REAL*8 yuv
+       REAL*8 yt(0:nmax2)
+       REAL*8 fhyp(0:nmax2),beta,Ytprim(0:nmax2),fxm(0:nmax2)
+       SAVE Ytprim, yt,Yf
+       REAL*8 Yf(0:nmax2),yypr(0:nmax2)
+       REAL*8 yvrai(jjp1), yprimm(jjp1),ylatt(jjp1)
+       REAL*8 pi,depi,pis2,epsilon,y0,pisjm
+       REAL*8 yo1,yi,ylon2,ymoy,Yprimin,champmin,champmax
+       REAL*8 yfi,Yf1,ffdy
+       REAL*8 ypn,deply,y00
        SAVE y00, deply
 
@@ -60,71 +63,122 @@
        INTEGER jpn,jjpn
        SAVE jpn
-
+       REAL*8 a0,a1,a2,a3,yi2,heavyy0,heavyy0m
+       REAL*8 fa(0:nmax2),fb(0:nmax2)
+       REAL y0min,y0max
+
+       REAL*8     heavyside
+       EXTERNAL   heavyside
 
        pi       = 2. * ASIN(1.)
        depi     = 2. * pi
        pis2     = pi/2.
-       epsilon  = 1.e-6
-       yzoom    = yzoomdeg * pi/180. 
-
-
+       pisjm    = pi/ FLOAT(jjm)
+       epsilon  = 1.e-3
+       y0       =  yzoomdeg * pi/180. 
+
+       IF( dzoom.LT.1.)  THEN
+         dzoom = dzoom * pi
+       ELSEIF( dzoom.LT. 12. ) THEN
+         WRITE(6,*) ' Le param. dzoomy pour fyhyp est trop petit ! L aug
+     ,menter et relancer ! '
+         STOP 1
+       ELSE
+         dzoom = dzoom * pi/180.
+       ENDIF
+
+       WRITE(6,18)
+       WRITE(6,*) ' yzoom( rad.),grossism,tau,dzoom (radians)'
+       WRITE(6,24) y0,grossism,tau,dzoom
 
        DO i = 0, nmax2 
-        ytild(i) = FLOAT(i) /nmax2
-       IF( ytild(i).EQ.0.5 )  ytild(i) = ytild(i) + 1.e-6
-       ENDDO
-
-       DO i = 1, nmax
-        fhyp(i) = TANH ( ( ytild(i) - 0.5*(1.- dzoom) )          /
-     ,                 ( tau * ytild(i) * ( 0.5 -ytild(i))) )
-       ENDDO
-
-       fhyp(   0  ) = - 1.
-       fhyp( nmax ) =   1.
+        yt(i) = - pis2  + FLOAT(i)* pi /nmax2
+       ENDDO
+
+       heavyy0m = heavyside( -y0 )
+       heavyy0  = heavyside(  y0 )
+       y0min    = 2.*y0*heavyy0m - pis2
+       y0max    = 2.*y0*heavyy0  + pis2
+
+       fa = 999.999
+       fb = 999.999
+
+       DO i = 0, nmax2 
+        IF( yt(i).LT.y0 )  THEN
+         fa (i) = tau*  (yt(i)-y0+dzoom/2. )
+         fb(i) =   (yt(i)-2.*y0*heavyy0m +pis2) * ( y0 - yt(i) )
+        ELSEIF ( yt(i).GT.y0 )  THEN
+         fa(i) =   tau *(y0-yt(i)+dzoom/2. )
+         fb(i) = (2.*y0*heavyy0 -yt(i)+pis2) * ( yt(i) - y0 ) 
+       ENDIF
+        
+       IF( 200.* fb(i) .LT. - fa(i) )   THEN
+         fhyp ( i) = - 1.
+       ELSEIF( 200. * fb(i) .LT. fa(i) ) THEN
+         fhyp ( i) =   1.
+       ELSE  
+         fhyp(i) =  TANH ( fa(i)/fb(i) )
+       ENDIF
+
+       IF( yt(i).EQ.y0 )  fhyp(i) = 1.
+       IF(yt(i).EQ. y0min. OR.yt(i).EQ. y0max ) fhyp(i) = -1.
+
+       ENDDO
 
 cc  ....  Calcul  de  beta  ....
 c
-       ffdx( 0 ) = 0.
-
-       DO i = 1, nmax
-        ymoy    = 0.5 * ( ytild(i-1) + ytild( i ) )
-        fxm     = TANH ( ( ymoy - 0.5 * ( 1. - dzoom ) )    /
-     ,                 ( tau * ymoy * ( 0.5 -ymoy)) )
-        ffdx(i) = ffdx(i-1) + fxm * ( ytild(i) - ytild(i-1) )
-       ENDDO
-
-        beta  = ( grossism * ffdx(nmax) - 0.5 ) / ( ffdx(nmax) - 0.5 )
+       ffdy   = 0.
+
+       DO i = 1, nmax2
+        ymoy    = 0.5 * ( yt(i-1) + yt( i ) )
+        IF( ymoy.LT.y0 )  THEN
+         fa(i)= tau * ( ymoy-y0+dzoom/2.) 
+         fb(i) = (ymoy-2.*y0*heavyy0m +pis2) * ( y0 - ymoy )
+        ELSEIF ( ymoy.GT.y0 )  THEN
+         fa(i)= tau * ( y0-ymoy+dzoom/2. ) 
+         fb(i) = (2.*y0*heavyy0 -ymoy+pis2) * ( ymoy - y0 )
+        ENDIF
+
+        IF( 200.* fb(i) .LT. - fa(i) )    THEN
+         fxm ( i) = - 1.
+        ELSEIF( 200. * fb(i) .LT. fa(i) ) THEN
+         fxm ( i) =   1.
+        ELSE
+         fxm(i) =  TANH ( fa(i)/fb(i) )
+        ENDIF
+         IF( ymoy.EQ.y0 )  fxm(i) = 1.
+         IF (ymoy.EQ. y0min. OR.yt(i).EQ. y0max ) fxm(i) = -1.
+         ffdy = ffdy + fxm(i) * ( yt(i) - yt(i-1) )
+
+        ENDDO
+
+        beta  = ( grossism * ffdy - pi ) / ( ffdy - pi )
+
+       IF( 2.*beta - grossism.LE. 0.)  THEN
+
+        WRITE(6,*) ' **  Attention ! La valeur beta calculee dans la rou
+     ,tine fyhyp est mauvaise ! '
+        WRITE(6,*)'Modifier les valeurs de  grossismy ,tauy ou dzoomy',
+     , ' et relancer ! ***  '
+        CALL ABORT
+
+       ENDIF
 c
 c   .....  calcul  de  Ytprim   .....
 c
        
-       DO i = 0, nmax
+       DO i = 0, nmax2
         Ytprim(i) = beta  + ( grossism - beta ) * fhyp(i)
        ENDDO
-c   
-       DO i = 0, nmax
-        Ytprim( nmax2 - i ) = Ytprim( i )
-       ENDDO
-c
 
 c   .....  Calcul  de  Yf     ........
 
-        Yf(0) = 0.
-       DO i = 1, nmax
-        ymoy    = 0.5 * ( ytild(i-1) + ytild( i ) )
-        fxm     = TANH ( ( ymoy - 0.5 * ( 1. - dzoom ) )    /
-     ,                 ( tau * ymoy * ( 0.5 -ymoy)) )
-        yypr(i)    = beta + ( grossism - beta ) * fxm
-       ENDDO
-
-       DO i = 1,nmax
-         yypr(nmax2-i+1) = yypr(i)
-       ENDDO
-
-        DO i=1,nmax2
-         Yf(i)   = Yf(i-1) + yypr(i) * ( ytild(i) - ytild(i-1) )
-        ENDDO
-c
-c
+       Yf(0) = - pis2
+       DO i = 1, nmax2
+        yypr(i)    = beta + ( grossism - beta ) * fxm(i)
+       ENDDO
+
+       DO i=1,nmax2
+        Yf(i)   = Yf(i-1) + yypr(i) * ( yt(i) - yt(i-1) )
+       ENDDO
 
 c    ****************************************************************
@@ -133,4 +187,5 @@
 c   .....   yuv  = 0.5  si calcul des latitudes  aux pts.  V  .....
 c
+      WRITE(6,18)
 c
       DO 5000  ik = 1,4
@@ -149,28 +204,21 @@
          jlat = jjm 
        ENDIF
-        
-c
+c
+       yo1   = 0.
        DO 1500 j =  1,jlat
-
-        ylon2 =  ( FLOAT(j)  + yuv  -1.) / FLOAT(jjm) 
-
         yo1   = 0.
-        yi    = ylon2
-
-c
-       DO 500 iter = 1,300
-
+        ylon2 =  - pis2 + pisjm * ( FLOAT(j)  + yuv  -1.)  
+        yfi    = ylon2
+c
        DO 250 it =  nmax2,0,-1
-        IF( yi.GE.ytild(it))  GO TO 350
+        IF( yfi.GE.Yf(it))  GO TO 350
 250    CONTINUE
-
        it = 0
-       yi = ytild(it)
-
 350    CONTINUE
 
+       yi = yt(it)
        IF(it.EQ.nmax2)  THEN
         it       = nmax2 -1
-        Yf(it+1) = 1.
+        Yf(it+1) = pis2
        ENDIF
 c  .................................................................
@@ -179,41 +227,42 @@
 c  .................................................................
 
-       yint   = ( Yf(it+1)-Yf(it) ) / ( ytild(it+1)-ytild(it) )      * 
-     +                    ( yi-ytild(it) )  +  Yf(it)
-      Yprimin = ( Ytprim(it+1)-Ytprim(it) )/ ( ytild(it+1)-ytild(it) ) *
-     +                    ( yi-ytild(it) )  +  Ytprim(it)
-       yi = yi - (yint-ylon2)/Yprimin
-
-      IF( ABS(yi-yo1).LE.epsilon) GO TO 550
-      yo1 = yi
-c
+       CALL coefpoly ( Yf(it),Yf(it+1),Ytprim(it), Ytprim(it+1),   
+     ,                  yt(it),yt(it+1) ,   a0,a1,a2,a3   )      
+
+       Yf1     = Yf(it)
+       Yprimin = a1 + 2.* a2 * yi + 3.*a3 * yi *yi
+
+       DO 500 iter = 1,300
+         yi = yi - ( Yf1 - yfi )/ Yprimin
+
+        IF( ABS(yi-yo1).LE.epsilon)  GO TO 550
+         yo1      = yi
+         yi2      = yi * yi
+         Yf1      = a0 +  a1 * yi +     a2 * yi2  +     a3 * yi2 * yi
+         Yprimin  =       a1      + 2.* a2 *  yi  + 3.* a3 * yi2
 500   CONTINUE
-      PRINT *,' ***   PAS DE SOLUTION  ****  ',j,ylon2,iter
-        STOP 4
+        WRITE(6,*) ' Pas de solution ***** ',j,ylon2,iter
+         STOP 2
 550   CONTINUE
-
-       yprim(j)    = pi /( FLOAT(jjm) *  Yprimin)
-       yvrai(j)    = pi *  (yi - 0.5) + yzoom
+c
+       Yprimin   = a1  + 2.* a2 *  yi   + 3.* a3 * yi* yi
+       yprim(j)  = pi / ( jjm * Yprimin )
+       yvrai(j)  = yi 
 
 1500    CONTINUE
-
-cc          print *,' LAT avant reorgan '
-cc         print 68,(yyvrai(j),j=1,jlat)
 
        DO j = 1, jlat -1
         IF( yvrai(j+1). LT. yvrai(j) )  THEN
-         PRINT *,' PBS.  avec  rlat(',j+1,' plus petit que rlat(',j,
-     ,   ')'
-         STOP
-        ENDIF
-       ENDDO
-
-        PRINT 18
-        PRINT *,'Reorganisation des latitudes pour avoir entre - pi/2 ',
-     ,  ' et  pi/2 '
-c
-           
+         WRITE(6,*) ' PBS. avec  rlat(',j+1,') plus petit que rlat(',j,
+     ,  ')'
+         STOP 3
+        ENDIF
+       ENDDO
+
+       WRITE(6,*) 'Reorganisation des latitudes pour avoir entre - pi/2'
+     , ,' et  pi/2 '
+c
         IF( ik.EQ.1 )   THEN
-           ypn = pis2 - deltay * pi/180.
+           ypn = pis2 
           DO j = jlat,1,-1
            IF( yvrai(j).LE. ypn ) GO TO 1502
@@ -239,11 +288,7 @@
          ENDDO
 
-
-
 c      ***********   Fin de la reorganisation     *************
 c
  1600   CONTINUE
-
-
 
        DO j = 1, jlat
@@ -256,33 +301,35 @@
         ENDDO
 
-
         IF( ik.EQ.1 )  THEN
-        PRINT 18
-        PRINT *, ' YLAT  en U   apres ( en  deg. ) '
-        PRINT 68,(yvrai(j),j=1,jlat)
-        PRINT *,' YPRIM '
-        PRINT 68,( yprim(j),j=1,jlat)
+c         WRITE(6,18) 
+c         WRITE(6,*)  ' YLAT  en U   apres ( en  deg. ) '
+c         WRITE(6,68) (yvrai(j),j=1,jlat)
+cc         WRITE(6,*) ' YPRIM '
+cc         WRITE(6,445) ( yprim(j),j=1,jlat)
+
           DO j = 1, jlat
             rrlatu(j) =  ylat( j )
            yyprimu(j) = yprim( j )
           ENDDO
-c
+
         ELSE IF ( ik.EQ. 2 )  THEN
-        PRINT 18
-        PRINT *, ' YLAT   en V  apres ( en  deg. ) '
-        PRINT 68,(yvrai(j),j=1,jlat)
-        PRINT *,' YPRIM '
-        PRINT 68,( yprim(j),j=1,jlat)
+c         WRITE(6,18) 
+c         WRITE(6,*) ' YLAT   en V  apres ( en  deg. ) '
+c         WRITE(6,68) (yvrai(j),j=1,jlat)
+cc         WRITE(6,*)' YPRIM '
+cc         WRITE(6,445) ( yprim(j),j=1,jlat)
+
           DO j = 1, jlat
             rrlatv(j) =  ylat( j )
            yyprimv(j) = yprim( j )
           ENDDO
-c
+
         ELSE IF ( ik.EQ. 3 )  THEN
-        PRINT 18
-        PRINT *, ' YLAT  en U + 0.75  apres ( en  deg. ) '
-        PRINT 68,(yvrai(j),j=1,jlat)
-        PRINT *,' YPRIM '
-        PRINT 68,( yprim(j),j=1,jlat)
+c         WRITE(6,18) 
+c         WRITE(6,*)  ' YLAT  en U + 0.75  apres ( en  deg. ) '
+c         WRITE(6,68) (yvrai(j),j=1,jlat)
+cc         WRITE(6,*) ' YPRIM '
+cc         WRITE(6,445) ( yprim(j),j=1,jlat)
+
           DO j = 1, jlat
             rlatu2(j) =  ylat( j )
@@ -291,19 +338,36 @@
 
         ELSE IF ( ik.EQ. 4 )  THEN
-        PRINT 18
-        PRINT *, ' YLAT en U + 0.25  apres ( en  deg. ) '
-        PRINT 68,(yvrai(j),j=1,jlat)
-        PRINT *,' YPRIM '
-        PRINT 68,( yprim(j),j=1,jlat)
+c         WRITE(6,18) 
+c         WRITE(6,*)  ' YLAT en U + 0.25  apres ( en  deg. ) '
+c         WRITE(6,68)(yvrai(j),j=1,jlat)
+cc         WRITE(6,*) ' YPRIM '
+cc         WRITE(6,68) ( yprim(j),j=1,jlat)
+
           DO j = 1, jlat
             rlatu1(j) =  ylat( j )
            yprimu1(j) = yprim( j )
           ENDDO
+
         ENDIF
 
 5000   CONTINUE
 c
+        WRITE(6,18)
+c
 c  .....     fin de la boucle  do 5000 .....
 
+        DO j = 1, jjm
+         ylat(j) = rrlatu(j) - rrlatu(j+1)
+        ENDDO
+        champmin =  1.e12
+        champmax = -1.e12
+        DO j = 1, jjm
+         champmin = MIN( champmin, ylat(j) )
+         champmax = MAX( champmax, ylat(j) )
+        ENDDO
+         champmin = champmin * 180./pi
+         champmax = champmax * 180./pi
+
+24     FORMAT(2x,'Parametres yzoom,gross,tau ,dzoom pour fyhyp ',4f8.3)
 18      FORMAT(/)
 68      FORMAT(1x,7f9.2)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/gcm.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/gcm.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/gcm.F	(revision 253)
@@ -1,4 +1,6 @@
 
       PROGRAM gcm
+
+      USE IOIPSL
 
       IMPLICIT NONE
@@ -20,11 +22,13 @@
 c
 c=======================================================================
-
-c   ...  Dans inigeom , nouveaux calculs pour les elongations  cu , cv 
-c        et possibilite d'appeler une fonction f(y)  a derivee tangente 
-c        hyperbolique a la  place de la fonction a derivee sinusoidale.         
-
-c   ...  Possibilite de choisir le shema de Van-leer pour l'advection de
-c         q  , en faisant iadv = 3  dans   traceur  (29/04/97) .
+c
+c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
+c      et possibilite d'appeler une fonction f(y)  a derivee tangente
+c      hyperbolique a la  place de la fonction a derivee sinusoidale.
+
+c  ... Possibilite de choisir le shema de Van-leer pour l'advection de
+c        q  , en faisant iadv = 3  dans   traceur  (29/04/97) .
+c
+c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
 c
 c-----------------------------------------------------------------------
@@ -115,4 +119,5 @@
 
 
+      INTEGER fluxid, fluxvid,fluxdid
       integer histid, histvid, histaveid
       real time_step, t_wrt, t_ops
@@ -123,9 +128,16 @@
 
       LOGICAL offline  ! Controle du stockage ds "fluxmass"
-      PARAMETER (offline=.false.)
+      PARAMETER (offline=.true.)
 
       character*80 dynhist_file, dynhistave_file
       character*20 modname
       character*80 abort_message
+
+C Calendrier
+      LOGICAL true_calendar
+      PARAMETER (true_calendar = .false.)
+C Run nudge
+      LOGICAL ok_nudge
+      PARAMETER (ok_nudge = .false.)
 
 c-----------------------------------------------------------------------
@@ -138,4 +150,10 @@
       dynhist_file = 'dyn_hist.nc'
       dynhistave_file = 'dyn_hist_ave.nc'
+
+      if (true_calendar) then
+        call ioconf_calendar('gregorian')
+      else
+        call ioconf_calendar('360d')
+      endif
 c-----------------------------------------------------------------------
 c
@@ -146,4 +164,6 @@
 c     iadv = 2    shema   amont
 c     iadv = 3    shema  Van-leer
+c     iadv = 4    schema  Van-leer + humidite specifique
+c                        Modif F.Codron
 c 
 c     dans le tableau q(ij,l,iq) , iq = 1  pour l'eau vapeur
@@ -157,5 +177,20 @@
       ENDDO
 c
-      DO  iq = 1, nqmx
+       IF( iadv(1).EQ.1 ) PRINT *,' Choix du shema humidite specifique'
+     * ,' pour la vapeur d''eau'
+       IF( iadv(1).EQ.2 ) PRINT *,' Choix du shema  amont',' pour la'
+     * ,' vapeur d''eau '
+       IF( iadv(1).EQ.3 ) PRINT *,' Choix du shema  Van-Leer ',' pour'
+     * ,'la vapeur d''eau'
+       IF( iadv(1).EQ.4 ) PRINT *,' Choix du shema  Van-Leer + humidite'
+     * ,' specifique pour la vapeur d''eau'
+c
+       IF( iadv(1).LE.0.OR.iadv(1).GT.4 )   THEN
+        PRINT *,' Erreur dans le choix de iadv (1).Corriger et repasser
+     * ,  car  iadv(1) = ', iadv(1)
+         CALL ABORT
+       ENDIF
+
+      DO  iq = 2, nqmx
        IF( iadv(iq).EQ.1 ) PRINT *,' Choix du shema humidite specifique'
      * ,' pour le traceur no ', iq
@@ -164,8 +199,16 @@
        IF( iadv(iq).EQ.3 ) PRINT *,' Choix du shema  Van-Leer ',' pour'
      * ,'le traceur no ', iq
-       IF( iadv(iq).LE.0.OR.iadv(iq).GT.3 )   THEN
+
+       IF( iadv(iq).EQ.4 )  THEN
+         PRINT *,' Le shema  Van-Leer + humidite specifique ',
+     * ' est  uniquement pour la vapeur d eau .'
+         PRINT *,' Corriger iadv( ',iq, ')  et repasser ! '
+         CALL ABORT
+       ENDIF
+
+       IF( iadv(iq).LE.0.OR.iadv(iq).GT.4 )   THEN
        PRINT *,' Erreur dans le  choix de  iadv . Corriger et repasser
      * . '
-         STOP 
+         CALL ABORT 
        ENDIF
       ENDDO
@@ -174,5 +217,5 @@
       numvanle = nqmx + 1
       DO  iq = 1, nqmx
-        IF( iadv(iq).EQ.3.AND.first ) THEN
+        IF((iadv(iq).EQ.3.OR.iadv(iq).EQ.4).AND.first ) THEN
           numvanle = iq
           first    = .FALSE.
@@ -181,10 +224,10 @@
 c
       DO  iq = 1, nqmx
-        IF( iadv(iq).NE.3.AND.iq.GT.numvanle )   THEN
+      IF( (iadv(iq).NE.3.AND.iadv(iq).NE.4).AND.iq.GT.numvanle )  THEN
           PRINT *,' Il y a discontinuite dans le choix du shema de ',
      *    'Van-leer pour les traceurs . Corriger et repasser . '
-           STOP
-        ENDIF
-        IF( iadv(iq).LT.1.OR.iadv(iq).GT.3 )    THEN
+           CALL ABORT
+      ENDIF
+        IF( iadv(iq).LT.1.OR.iadv(iq).GT.4 )    THEN
           PRINT *,' Le choix de  iadv  est errone pour le traceur ',
      *    iq
@@ -282,5 +325,8 @@
 
    1  CONTINUE
-c     call nudge(itau,ucov,vcov,teta,masse,ps)
+
+      if (ok_nudge) then
+        call nudge(itau,ucov,vcov,teta,masse,ps)
+      endif
 c
 c     IF( MOD( itau, 10* day_step ).EQ.0 )  THEN
@@ -364,5 +410,7 @@
 c
             CALL vanleer(numvanle,iapp_tracvl,nqmx,q,pbaru,pbarv,
-     *                             p,  masse, dq                  )
+     *                      p, masse, dq,  iadv(1), teta, pk     )
+c
+c                   ...  Modif  F.Codron  ....
 c
          ENDIF
@@ -372,5 +420,9 @@
          IF (offline) THEN
 Cmaf stokage du flux de masse pour traceurs OFF-LINE
-           CALL fluxstoke(pbaru,pbarv,masse,teta,phi,phis)
+
+            CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
+     .   time_step, itau)
+
+
          ENDIF
 c
@@ -451,5 +503,4 @@
 c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
 c
-      IF( alphax.NE. 0. ) THEN
 
         DO l  =  1, llm
@@ -467,5 +518,16 @@
         ENDDO
 
-      ENDIF
+        DO ij =  1,iim
+          tppn(ij)  = aire(  ij    ) * ps (  ij    )
+          tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
+        ENDDO
+          tpn  = SSUM(iim,tppn,1)/apoln
+          tps  = SSUM(iim,tpps,1)/apols
+
+        DO ij = 1, iip1
+          ps(  ij    ) = tpn
+          ps(ij+ip1jm) = tps
+        ENDDO
+
 
       END IF
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/gr_ecrit_fi.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/gr_ecrit_fi.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/gr_ecrit_fi.F	(revision 253)
@@ -0,0 +1,29 @@
+	SUBROUTINE gr_ecrit_fi(nfield,nlon,iim,jjmp1,ecrit,fi)
+
+	IMPLICIT none
+
+c Transformer une variable de la grille d'ecriture a la grille physique
+	
+	INTEGER nfield,nlon,iim,jjmp1, jjm
+      REAL fi(nlon,nfield), ecrit(iim,jjmp1,nfield)
+c
+      INTEGER i, j, n, ig
+c
+c	print*,'iim jjm ',iim,jjm
+
+c modif par abd 21 02 01
+
+        jjm = jjmp1 - 1
+	do n = 1, nfield
+	    fi(1,n) = ecrit(1,1,n)
+            fi(nlon,n) = ecrit(1,jjm+1,n)
+         DO j = 2, jjm
+            ig = 2+(j-2)*iim
+            DO i = 1, iim
+	     fi(ig-1+i,n) = ecrit(i,j,n)
+            ENDDO
+         ENDDO
+      ENDDO
+      RETURN
+      END
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/grid_noro.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/grid_noro.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/grid_noro.F	(revision 253)
@@ -355,4 +355,5 @@
       DO jj=1,jmar
       zmea(imar+1,jj)=zmea(1,jj)
+      zphi(imar+1,jj)=zphi(1,jj)
       zpic(imar+1,jj)=zpic(1,jj)
       zval(imar+1,jj)=zval(1,jj)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/grilles_gcm_netcdf.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/grilles_gcm_netcdf.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/grilles_gcm_netcdf.F	(revision 253)
@@ -0,0 +1,286 @@
+c
+c $Header$
+c
+
+      PROGRAM create_fausse_var
+C
+      IMPLICIT NONE
+C
+C
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "comvert.h"
+
+      real temp(iim+1,jjm+1)
+#include "netcdf.inc"
+
+c Attributs netcdf sortie
+        character*64 fich_out
+        integer*4 ncid_out,rcode_out
+        integer*4 out_lonuid,out_lonvid,out_latuid,out_latvid
+        integer*4 out_varid
+        integer*4 out_lonudim,out_lonvdim
+        integer*4 out_latudim,out_latvdim,out_dim(3)
+
+      INTEGER         longcles
+      PARAMETER     ( longcles = 20 )
+      REAL  clesphy0( longcles )
+
+      integer start(4),count(4)
+
+	integer status,i,j
+        real rlatudeg(jjp1),rlatvdeg(jjm)
+        real rlonudeg(iip1),rlonvdeg(iip1)
+
+      real dlon1(iip1),dlon2(iip1),dlat1(jjp1),dlat2(jjp1)
+      real acoslat,dxkm,dykm,resol(iip1,jjp1)
+
+#include "serre.h"
+#include "fxyprim.h"
+
+      print*,'OK0'
+
+      rad = 6400000
+      omeg = 7.272205e-05
+      g = 9.8
+      kappa = 0.285716
+      daysec = 86400
+      cpp = 1004.70885
+
+      preff = 101325.
+      pa= 50000.
+
+      open(99,file='run.def',status='old',form='formatted')
+      CALL defrun_new( 99, .TRUE.,clesphy0 )
+      close(99)
+      CALL iniconst
+      CALL inigeom
+
+
+      print*,'OK1'
+      do j=1,jjp1
+         rlatudeg(j)=rlatu(j)*180./pi
+      enddo
+      do j=1,jjm
+         rlatvdeg(j)=rlatv(j)*180./pi
+      enddo
+
+      do i=1,iip1
+         rlonudeg(i)=rlonu(i)*180./pi
+         rlonvdeg(i)=rlonv(i)*180./pi
+      enddo
+
+
+      print*,'OK2'
+c  2 ----- OUVERTURE DE LA SORTIE NETCDF
+c ---------------------------------------------------
+c CREATION OUTPUT
+c ouverture fichier netcdf de sortie out
+        fich_out='grilles_gcm.nc'
+
+        status=NF_CREATE(fich_out,NF_NOCLOBBER,ncid_out)
+        status=NF_DEF_DIM(ncid_out,'lonu',iim+1,out_lonudim)
+        status=NF_DEF_DIM(ncid_out,'lonv',iim+1,out_lonvdim)
+        status=NF_DEF_DIM(ncid_out,'latu',jjm+1,out_latudim)
+        status=NF_DEF_DIM(ncid_out,'latv',jjm,out_latvdim)
+
+
+      print*,'OK3'
+c   Longitudes en u
+        print *,'OUTID: ',ncid_out
+        status=NF_DEF_VAR(ncid_out,'lonu',NF_FLOAT,1,out_lonudim,
+     %  out_lonuid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'units',
+     %  12,'degrees_east')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',
+     %  9,'Longitude en u')
+
+c   Longitudes en v
+        print *,'OUTID: ',ncid_out
+        status=NF_DEF_VAR(ncid_out,'lonv',NF_FLOAT,1,out_lonvdim,
+     %  out_lonvid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'units',
+     %  12,'degrees_east')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name',
+     %  9,'Longitude en v')
+
+c   Latitude en u
+        status=NF_DEF_VAR(ncid_out,'latu',NF_FLOAT,1,out_latudim,
+     %  out_latuid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'units',
+     %  13,'degrees_north')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name',
+     %  8,'Latitude en u')
+
+c  Latitude en v
+        status=NF_DEF_VAR(ncid_out,'latv',NF_FLOAT,1,out_latvdim,
+     %  out_latvid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'units',
+     %  13,'degrees_north')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name',
+     %  8,'Latitude en v')
+
+c   ecriture de la grille u
+        out_dim(1)=out_lonudim
+        out_dim(2)=out_latudim
+        status=NF_DEF_VAR(ncid_out,'grille_u',NF_FLOAT,2,out_dim,
+     %  out_varid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units',
+     %  6,'Kelvin')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',
+     %  16,'Grille aux point u')
+
+c   ecriture de la grille v
+        out_dim(1)=out_lonvdim
+        out_dim(2)=out_latvdim
+        status=NF_DEF_VAR(ncid_out,'grille_v',NF_FLOAT,2,out_dim,
+     %  out_varid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units',
+     %  6,'Kelvin')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',
+     %  16,'Grille aux point v')
+
+c   ecriture de la grille u
+        out_dim(1)=out_lonvdim
+        out_dim(2)=out_latudim
+        status=NF_DEF_VAR(ncid_out,'grille_s',NF_FLOAT,2,out_dim,
+     %  out_varid)
+        call handle_err(status)
+        status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units',
+     %  6,'Kelvin')
+        status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',
+     %  16,'Grille aux point u')
+
+
+      print*,'OK4'
+        status=NF_ENDDEF(ncid_out)
+c 5) ----- FERMETURE DES FICHIERS NETCDF------------------
+c --------------------------------------------------------
+c 3-b- Ecriture de la grille pour la sortie
+c rajoute l'ecriture de la grille
+
+#ifdef NC_DOUBLE
+      status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonuid,1,iim+1,rlonudeg)
+      status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
+      status=NF_PUT_VARA_DOUBLE(ncid_out,out_latuid,1,jjm+1,rlatudeg)
+      status=NF_PUT_VARA_DOUBLE(ncid_out,out_latvid,1,jjm,rlatvdeg)
+#else
+      status=NF_PUT_VARA_REAL(ncid_out,out_lonuid,1,iim+1,rlonudeg)
+      status=NF_PUT_VARA_REAL(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
+      status=NF_PUT_VARA_REAL(ncid_out,out_latuid,1,jjm+1,rlatudeg)
+      status=NF_PUT_VARA_REAL(ncid_out,out_latvid,1,jjm,rlatvdeg)
+#endif
+
+        start(1)=1
+        start(2)=1
+        start(3)=1
+        start(4)=1
+
+        count(1)=iim+1
+        count(2)=jjm+1
+        count(3)=1
+        count(4)=1
+
+        do j=1,jjm+1
+           do i=1,iim+1
+              temp(i,j)=mod(i,2)+mod(j,2)
+           enddo
+        enddo
+
+#ifdef NC_DOUBLE
+        status=NF_PUT_VARA_DOUBLE(ncid_out,out_varid,start,
+     s  count,temp)
+#else
+        status=NF_PUT_VARA_REAL(ncid_out,out_varid,start,
+     s  count,temp)
+#endif
+
+
+c fermeture du fichier netcdf
+        call ncclos(ncid_out,rcode_out)
+        write(*,*) 'Fermeture: ',fich_out
+
+
+      print*,'OK5'
+c   Ecriture grads
+      open (20,file='grille.dat',form='unformatted',access='direct'
+     s      ,recl=4*ip1jmp1)
+      write(20,rec=1) ((float(mod(i,2)+mod(j,2)),i=1,iip1),j=1,jjp1)
+      write(20,rec=2) ((float(mod(i,2)*mod(j,2)),i=1,iip1),j=1,jjp1)
+      do j=2,jjm
+         dlat1(j)=180.*(rlatv(j)-rlatv(j-1))/pi
+c        dlat2(j)=180.*fyprim(float(j))/pi
+      enddo
+      do i=2,iip1
+         dlon1(i)=180.*(rlonu(i)-rlonu(i-1))/pi
+c        dlon2(i)=180.*fxprim(float(i))/pi
+      enddo
+      do j=2,jjm
+         dykm=(rlatv(j)-rlatv(j-1))*6400.
+         acoslat=6400.*cos(rlatu(j))
+         do i=2,iip1
+            dxkm=acoslat*(rlonu(i)-rlonu(i-1))
+            resol(i,j)=sqrt(dykm*dykm+dxkm*dxkm)
+         enddo
+         resol(1,j)=resol(iip1,j)
+      enddo
+      write(20,rec=3) resol
+      dlon1(1)=dlon1(iip1)
+      dlon2(1)=dlon2(iip1)
+      write(20,rec=4) ((dlon1(i),i=1,iip1),j=1,jjp1)
+      write(20,rec=5) ((dlon2(i),i=1,iip1),j=1,jjp1)
+      write(20,rec=6) ((dlat1(j),i=1,iip1),j=1,jjp1)
+      write(20,rec=7) ((dlat2(j),i=1,iip1),j=1,jjp1)
+        
+      open (21,file='grille.ctl',form='formatted')
+
+c   WARNING! on reecrase le fichier .ctl a chaque ecriture
+      write(21,'(a5,1x,a40)')
+     &       'DSET ','^grille.dat'
+
+      write(21,'(a12)') 'UNDEF 1.0E30'
+      write(21,'(a5,1x,a40)') 'TITLE ','grille'
+      call formcoord(21,iip1,rlonv,180./pi,.false.,'XDEF')
+      call formcoord(21,jjp1,rlatu,180./pi,.true.,'YDEF')
+      call formcoord(21,1,0.,1.,.false.,'ZDEF')
+      write(21,'(a4,i10,a30)')
+     &       'TDEF ',1,' LINEAR 23OCT1994 3hr '
+      write(21,'(a4,2x,i5)') 'VARS',7
+      write(21,'(a18)') 'grille 0 99 grille'
+      write(21,'(a18)') 'gril   0 99 gril  '
+      write(21,'(a29)') 'resol   0 99 resolution (km)  '
+      write(21,'(a18)') 'dlon1  0 99 dlon1 '
+      write(21,'(a18)') 'dlon2  0 99 dlon2 '
+      write(21,'(a18)') 'dlat1  0 99 dlat1 '
+      write(21,'(a18)') 'dlat2  0 99 dlat2 '
+      write(21,'(a7)') 'ENDVARS'
+
+
+
+
+
+      print*,'OK6'
+	end
+
+
+
+        subroutine handle_err(status)
+#include "netcdf.inc"
+
+
+        integer status
+        print *,'handle code err: ',NF_NOERR
+        IF (status.NE.nf_noerr) THEN
+                print *,NF_STRERROR(status)
+                stop 'stopped'
+        ENDIF
+        END
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/heavyside.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/heavyside.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/heavyside.F	(revision 253)
@@ -0,0 +1,21 @@
+c
+c $Header$
+c
+       FUNCTION heavyside(a)
+
+c      ...   P. Le Van  ....
+c
+       IMPLICIT NONE
+
+       REAL*8 heavyside , a
+
+       IF ( a.LE.0. )  THEN
+         heavyside = 0.
+       ELSE
+         heavyside = 1.
+       ENDIF
+
+       RETURN
+       END
+
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/inigeom.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/inigeom.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/inigeom.F	(revision 253)
@@ -1,22 +1,18 @@
+c
+c $Header$
+c
       SUBROUTINE inigeom
 c
 c     Auteur :  P. Le Van
-c    .....................
-c
-c   ............      Version  du 20/12/98     ........................
+c
+c   ............      Version  du 01/04/2001     ........................
 c
 c  Calcul des elongations cuij1,.cuij4 , cvij1,..cvij4  aux memes en-
 c     endroits que les aires aireij1,..aireij4 .
+
 c  Choix entre f(y) a derivee sinusoid. ou a derivee tangente hyperbol.
 c
 c
       IMPLICIT NONE
-c
-      REAL        deltay, tauy, taux
-      PARAMETER ( deltay =  0. , tauy = 1. , taux = 1. )
-c
-c     deltay  est ( en degres ) le deplacement eventuel en Y du zoom
-cc    taux  et  tauy  sont  les raideurs   du  zoom
-c
 c
 #include "dimensions.h"
@@ -50,10 +46,6 @@
       SAVE rlonm025,xprimm025,rlonp025,xprimp025
 
-
-
-c----------------------------------------------------------------------
       REAL      SSUM
       EXTERNAL  SSUM
-c
 c
 c
@@ -62,5 +54,4 @@
 c   -    calcul des coeff. ( cu, cv , 1./cu**2,  1./cv**2  )         -
 c   -                                                                -
-c   ------------------------------------------------------------------
 c   ------------------------------------------------------------------
 c
@@ -168,5 +159,5 @@
 c
 c
-      PRINT 3
+      WRITE(6,3) 
  3    FORMAT( // 10x,' ....  INIGEOM  date du 01/06/98   ..... ',
      * //5x,'   Calcul des elongations cu et cv  comme sommes des 4 ' /
@@ -191,10 +182,10 @@
       ENDIF
 
-      PRINT *,' gamdi_gd ',gamdi_gdiv,gamdi_grot,gamdi_h,coefdis,
+      WRITE(6,*) ' gamdi_gd ',gamdi_gdiv,gamdi_grot,gamdi_h,coefdis,
      *  nitergdiv,nitergrot,niterh
 c
       pi    = 2.* ASIN(1.)
 c
-      PRINT 990
+      WRITE(6,990) 
 
 c     ----------------------------------------------------------------
@@ -205,5 +196,5 @@
        IF( ysinus )  THEN
 c
-        PRINT *,' ***  Inigeom ,  Y = Sinus ( Latitude ) *** '
+        WRITE(6,*) ' ***  Inigeom ,  Y = Sinus ( Latitude ) *** '
 c
 c   .... utilisation de f(x,y )  avec  y  =  sinus de la latitude  .....
@@ -215,5 +206,5 @@
        ELSE
 c
-        PRINT *,' *** Inigeom ,  Y = Latitude  , der. sinusoid . ***'
+        WRITE(6,*) '*** Inigeom ,  Y = Latitude  , der. sinusoid . ***'
 
 c  .... utilisation  de f(x,y) a tangente sinusoidale , y etant la latit. ...
@@ -267,11 +258,11 @@
       ELSE
 c
-c   ....  utilisation  de fxyhyper , f(x,y) a derivee tangente hyperbol.
+c   ....  Utilisation  de fxyhyper , f(x,y) a derivee tangente hyperbol.
 c   .....................................................................
 
-       PRINT *,'*** Inigeom , Y = Latitude  , der.tg. hyperbolique ***'
-
-       CALL fxyhyper( clat, grossismy, dzoomy, tauy, deltay  ,
-     ,               clon, grossismx, dzoomx, taux          ,
+      WRITE(6,*)'*** Inigeom , Y = Latitude  , der.tg. hyperbolique ***'
+ 
+       CALL fxyhyper( clat, grossismy, dzoomy, tauy    , 
+     ,                clon, grossismx, dzoomx, taux    ,
      , rlatu,yprimu,rlatv, yprimv,rlatu1, yprimu1,rlatu2,yprimu2  ,
      , rlonu,xprimu,rlonv,xprimv,rlonm025,xprimm025,rlonp025,xprimp025 )
@@ -387,9 +378,8 @@
 c
       IF ( j. eq. jjp1 )  THEN
-
        yprp               = yprimu2(j-1)
        rlatp              = rlatu2 (j-1)
-cc       yprp             = fyprim( FLOAT(j) - 0.25 )
-cc       rlatp            = fy    ( FLOAT(j) - 0.25 )
+ccc       yprp             = fyprim( FLOAT(j) - 0.25 )
+ccc       rlatp            = fy    ( FLOAT(j) - 0.25 )
 c
       coslatp             = COS( rlatp )
@@ -425,8 +415,8 @@
         rlatm    = rlatu1 (  j  )
         yprm     = yprimu1(  j  )
-c         rlatp    = fy    ( FLOAT(j) - 0.25 )
-c         yprp     = fyprim( FLOAT(j) - 0.25 )
-c         rlatm    = fy    ( FLOAT(j) + 0.25 )
-c         yprm     = fyprim( FLOAT(j) + 0.25 )
+cc         rlatp    = fy    ( FLOAT(j) - 0.25 )
+cc         yprp     = fyprim( FLOAT(j) - 0.25 )
+cc         rlatm    = fy    ( FLOAT(j) + 0.25 )
+cc         yprm     = fyprim( FLOAT(j) + 0.25 )
 
          coslatm  = COS( rlatm )
@@ -490,5 +480,4 @@
   36  CONTINUE
 c
-c   ....  Modif  P. Le Van  ( 4/07/96 )  .....
 c
       aire    (iip1,j) = aire    (1,j)
@@ -620,5 +609,5 @@
          aiuscv2gam(iip1,j)  = aiuscv2gam(1,j)
       ENDDO
-c
+
 c
 c   calcul des aires aux  poles :
@@ -666,30 +655,43 @@
 c-----------------------------------------------------------------------
 c
-       PRINT *,' INIGEOM  RLONV '
+       WRITE(6,*) '   ***  Coordonnees de la grille  *** '
+       WRITE(6,995)
+c
+       WRITE(6,*) '   LONGITUDES  aux pts.   V  ( degres )  '
+       WRITE(6,995)
         DO i=1,iip1
          rlonvv(i) = rlonv(i)*180./pi
         ENDDO
-       PRINT 400,rlonvv
-c
-       PRINT *,' RLATV '
+       WRITE(6,400) rlonvv
+c
+       WRITE(6,995)
+       WRITE(6,*) '   LATITUDES   aux pts.   V  ( degres )  '
+       WRITE(6,995)
         DO i=1,jjm
          rlatuu(i)=rlatv(i)*180./pi
         ENDDO
-       PRINT 400,(rlatuu(i),i=1,jjm)
+       WRITE(6,400) (rlatuu(i),i=1,jjm)
 c
         DO i=1,iip1
           rlonvv(i)=rlonu(i)*180./pi
         ENDDO
-       PRINT *,' RLONU '
-       PRINT 400,rlonvv
-c
-       PRINT *,' RLATU '
+       WRITE(6,995)
+       WRITE(6,*) '   LONGITUDES  aux pts.   U  ( degres )  '
+       WRITE(6,995)
+       WRITE(6,400) rlonvv
+       WRITE(6,995)
+
+       WRITE(6,*) '   LATITUDES   aux pts.   U  ( degres )  '
+       WRITE(6,995)
         DO i=1,jjp1
          rlatuu(i)=rlatu(i)*180./pi
         ENDDO
-       PRINT 400,(rlatuu(i),i=1,jjp1)
-c
+       WRITE(6,400) (rlatuu(i),i=1,jjp1)
+       WRITE(6,995)
+c
+444    format(f10.3,f6.0)
 400    FORMAT(1x,8f8.2)
 990    FORMAT(//)
+995    FORMAT(/)
 c
       RETURN
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/integrd.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/integrd.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/integrd.F	(revision 253)
@@ -91,16 +91,14 @@
       ENDDO
 c
-      IF( alphax.NE.0. )   THEN
-        DO  ij    = 1, iim
-         tppn(ij) = aire(   ij   ) * ps(  ij    )
-         tpps(ij) = aire(ij+ip1jm) * ps(ij+ip1jm)
-        ENDDO
-         tpn      = SSUM(iim,tppn,1)/apoln
-         tps      = SSUM(iim,tpps,1)/apols
-        DO ij   = 1, iip1
-         ps(   ij   )  = tpn
-         ps(ij+ip1jm)  = tps
-        ENDDO
-      ENDIF
+      DO  ij    = 1, iim
+       tppn(ij) = aire(   ij   ) * ps(  ij    )
+       tpps(ij) = aire(ij+ip1jm) * ps(ij+ip1jm)
+      ENDDO
+       tpn      = SSUM(iim,tppn,1)/apoln
+       tps      = SSUM(iim,tpps,1)/apols
+      DO ij   = 1, iip1
+       ps(   ij   )  = tpn
+       ps(ij+ip1jm)  = tps
+      ENDDO
 c
 c  ... Calcul  de la nouvelle masse d'air au dernier temps integre t+1 ...
@@ -136,17 +134,15 @@
 c
 c
-      IF( alphax.NE.0. )   THEN
-        DO  ij   = 1, iim
+      DO  ij   = 1, iim
         tppn(ij) = aire(   ij   ) * teta(  ij    ,l)
         tpps(ij) = aire(ij+ip1jm) * teta(ij+ip1jm,l)
-        ENDDO
+      ENDDO
         tpn      = SSUM(iim,tppn,1)/apoln
         tps      = SSUM(iim,tpps,1)/apols
 
-        DO ij   = 1, iip1
+      DO ij   = 1, iip1
         teta(   ij   ,l)  = tpn
         teta(ij+ip1jm,l)  = tps
-        ENDDO
-      ENDIF
+      ENDDO
 c
 
@@ -197,25 +193,23 @@
 c    .....  Calcul de la valeur moyenne, unique  aux poles pour  q .....
 c
-      IF( alphax.NE.0. )   THEN
-
-        DO iq = 1, nq
-          DO l = 1, llm
-
-             DO ij = 1, iim
+
+      DO iq = 1, nq
+        DO l = 1, llm
+
+           DO ij = 1, iim
              qppn(ij) = aire(   ij   ) * q(   ij   ,l,iq)
              qpps(ij) = aire(ij+ip1jm) * q(ij+ip1jm,l,iq)
-             ENDDO
+           ENDDO
              qpn  =  SSUM(iim,qppn,1)/apoln
              qps  =  SSUM(iim,qpps,1)/apols
 
-             DO ij = 1, iip1
+           DO ij = 1, iip1
              q(   ij   ,l,iq)  = qpn
              q(ij+ip1jm,l,iq)  = qps
-             ENDDO
-
-          ENDDO
-        ENDDO
-
-      ENDIF
+           ENDDO
+
+        ENDDO
+      ENDDO
+
 
          CALL  SCOPY( ijp1llm , finvmasse, 1, finvmaold, 1 )
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/lectflux.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/lectflux.F	(revision 3)
+++ 	(revision )
@@ -1,233 +1,0 @@
-      SUBROUTINE lectflux(irec,massem,pbarun,pbarvn,wn,tetan,phin,
-     s     nrec,avant,airefi,
-     s     zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
-     s     yu1,yv1,ftsol,pctsrf,
-     s     frac_impa,frac_nucl,phis)
-
-      IMPLICIT NONE
-
-#include "dimensions.h"
-#include "paramet.h"
-
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom2.h"
-
-#include "tracstoke.h"
-
-      integer irec,nrec,i,j
-
-      integer ngridmx,ig,l
-      parameter (ngridmx=iim*(jjm-1)+2)
-      INTEGER nbsrf
-      PARAMETER (nbsrf=4) ! nombre de sous-fractions pour une maille
-
-      real zmfd(ngridmx,llm),zde_d(ngridmx,llm),zen_d(ngridmx,llm)
-      real zmfu(ngridmx,llm),zde_u(ngridmx,llm),zen_u(ngridmx,llm)
-      real coefkz(ngridmx,llm)
-      real frac_impa(ngridmx,llm),frac_nucl(ngridmx,llm)
-      real yu1(ngridmx), yv1(ngridmx)
-      real ftsol(ngridmx,nbsrf),pctsrf(ngridmx,nbsrf)
-      integer imfu,imfd,ien_u,ide_u,
-     s      ien_d,ide_d,
-     s      icoefkz,izu1,izv1,
-     s      itsol,ipsf,
-     s      ilei, ilec
-      parameter(imfu=1,imfd=llm+1,ien_u=2*llm+1,ide_u=3*llm+1,
-     s      ien_d=4*llm+1,ide_d=5*llm+1,
-     s      icoefkz=6*llm+1,
-     s      ilei=7*llm+1,ilec=8*llm+1,
-     s      izu1=9*llm+1,izv1=9*llm+2,
-     s      itsol=9*llm+3,ipsf=9*llm+3+nbsrf)
-      logical avant
-
-      real massefi(ngridmx,llm)
-
-      real massem(ip1jmp1,llm),tetan(ip1jmp1,llm)
-      real pbarun(iip1,jjp1,llm),pbarvn(iip1,jjm,llm)
-      real pbarvst(iip1,jjp1,llm)
-      real wn(iip1,jjp1,llm),phin(iip1,jjp1,llm)
-      real phis(iip1,jjp1)
-
-      real airefi(ngridmx)
-
-      real xlecn(ngridmx,9*llm+2+2*nbsrf)
-
-      real zcontrole(ngridmx),zmass,tmpdyn(iip1,jjp1),zflux
-
-      real ziadvtrac,zrec,ziadvtrac2,zrec2
-      real zim,zjm,zlm,zklon,zklev
-
-      real zpi
-
-      zpi=2.*asin(1.)
-
-
-c==================================================================
-c   Si le numero du record est 0 alors: INITIALISATION
-c==================================================================
-c
-      print*,'ENTREE DANS LECTFLUX'
-        print*,'IREC=',IREC
-      if(irec.eq.0) then
-
-        print*,'IREC==',0
-
-C test         call inigeom
-
-c==================================================================
-c   ouverture des fichiers
-c==================================================================
-
-c   Fichier fluxmass
-#ifdef CRAY
-         CALL ASSIGN("assign -N ieee -F null f:fluxmass")
-#endif
-      open(47,file='fluxmass',form='unformatted',
-     s     access='direct'
-     s     ,recl=4*(6*ijp1llm))
-      read(47,rec=1) zrec,dtvr,ziadvtrac,zim,zjm,zlm,
-     s   rlonu,rlonv,rlatu,rlatv,aire
-     s    ,phis
-      print*,'zrec,dtvr,ziadvtrac,zim,zjm,zlm'
-      print*,zrec,dtvr,ziadvtrac,zim,zjm,zlm
-      print*,rlonv
-
-
-
-c  Fichier physique
-c  Fichier lessivage (supprime les donnees utiles sont dans "physique")
-#ifdef CRAY
-         CALL ASSIGN("assign -N ieee -F null f:physique")
-#endif
-      open(49,file='physique',form='unformatted',
-     s     access='direct'
-     s     ,recl=4*ngridmx*(9*llm+2+2*nbsrf))
-      read(49,rec=1) zrec2,ziadvtrac2,zklon,zklev
-      print*,'Entete du fichier physique'
-      print*,zrec2,ziadvtrac2,zklon,zklev
-
-      nrec=zrec
-      print*,'nrec=',nrec
-
-      istdyn=ziadvtrac
-      istphy=ziadvtrac2
-
-c==================================================================
-c   Fin des initialisations
-      else ! irec=0
-c==================================================================
-
-
-c-----------------------------------------------------------------------
-c   Lecture des fichiers fluxmass et  physique:
-c   -----------------------------------------------------
-
-c  Variables dynamiques
-         read(47,rec=irec) massem,pbarun,pbarvst,wn,tetan,phin
-        do l=1,llm
-           do j=1,jjm
-              do i=1,iip1
-                 pbarvn(i,j,l)=pbarvst(i,j,l)
-              enddo
-           enddo
-        enddo
-
-c  Variables physiques
-         read(49,rec=irec) ((xlecn(ig,l),ig=1,ngridmx),
-     s                                    l=1,9*llm+2+2*nbsrf)
-
-       do l=1,llm
-          do ig=1,ngridmx
-             coefkz(ig,l)=xlecn(ig,icoefkz+l-1)
-             frac_impa(ig,l)=xlecn(ig,ilei+l-1)
-             frac_nucl(ig,l)=xlecn(ig,ilec+l-1)
-          enddo
-       enddo
-       do l=1,nbsrf
-          do ig=1,ngridmx
-             ftsol(ig,l)=xlecn(ig,itsol+l-1)
-             pctsrf(ig,l)=xlecn(ig,ipsf+l-1)
-          enddo
-       enddo
-       do ig=1,ngridmx
-          yv1(ig)=xlecn(ig,izv1)
-          yu1(ig)=xlecn(ig,izu1)
-       enddo
-C
-      if(avant) then
-c   Simu directe
-       do l=1,llm
-          do ig=1,ngridmx
-             zmfu(ig,l)=xlecn(ig,imfu+l-1)
-             zmfd(ig,l)=xlecn(ig,imfd+l-1)
-             zde_u(ig,l)=xlecn(ig,ide_u+l-1)
-             zen_u(ig,l)=xlecn(ig,ien_u+l-1)
-             zde_d(ig,l)=xlecn(ig,ide_d+l-1)
-             zen_d(ig,l)=xlecn(ig,ien_d+l-1)
-          enddo
-       enddo
-      else
-c   Simu retro
-       do l=1,llm
-          do ig=1,ngridmx
-             zmfd(ig,l)=-xlecn(ig,imfu+l-1)
-             zmfu(ig,l)=-xlecn(ig,imfd+l-1)
-             zen_d(ig,l)=xlecn(ig,ide_u+l-1)
-             zde_d(ig,l)=xlecn(ig,ien_u+l-1)
-             zen_u(ig,l)=xlecn(ig,ide_d+l-1)
-             zde_u(ig,l)=xlecn(ig,ien_d+l-1)
-          enddo
-       enddo
-      endif
-
-c-----------------------------------------------------------------------
-c   PETIT CONTROLE SUR LES FLUX CONVECTIFS...
-c-----------------------------------------------------------------------
-
-      print*,'Ap redec irec'
-
-         call gr_dyn_fi(llm,iip1,jjp1,ngridmx,massem,massefi)
-
-         do ig=1,ngridmx
-            zcontrole(ig)=1.
-         enddo
-c   zmass=(max(massem(ig,l),massem(ig,l-1))/airefi(ig)
-         do l=2,llm
-            do ig=1,ngridmx
-               zmass=max(massefi(ig,l),massefi(ig,l-1))/airefi(ig)
-               zflux=max(abs(zmfu(ig,l)),abs(zmfd(ig,l)))*dtphys
-               if(zflux.gt.0.9*zmass) then
-                 zcontrole(ig)=min(zcontrole(ig),0.9*zmass/zflux)
-               endif
-            enddo
-         enddo
-
-         do ig=1,ngridmx
-            if(zcontrole(ig).lt.0.99999) then
-               print*,'ATTENTION !!! on reduit les flux de masse '
-               print*,'convectifs au point ig=',ig
-            endif
-         enddo
-
-         call gr_fi_dyn(1,ngridmx,iip1,jjp1,zcontrole,tmpdyn)
-
-         do l=1,llm
-            do ig=1,ngridmx
-               zmfu(ig,l)=zmfu(ig,l)*zcontrole(ig)
-               zmfd(ig,l)=zmfd(ig,l)*zcontrole(ig)
-               zen_u(ig,l)=zen_u(ig,l)*zcontrole(ig)
-               zde_u(ig,l)=zde_u(ig,l)*zcontrole(ig)
-               zen_d(ig,l)=zen_d(ig,l)*zcontrole(ig)
-               zde_d(ig,l)=zde_d(ig,l)*zcontrole(ig)
-            enddo
-         enddo
-
-
-      endif ! irec=0
-
-
-      RETURN
-      END
-
-
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/lectfluxnc.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/lectfluxnc.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/lectfluxnc.F	(revision 253)
@@ -0,0 +1,218 @@
+c
+c $Header$
+c
+      SUBROUTINE lectfluxnc(irec,massem,pbarun,pbarvn,wn,tetan,phin,
+     s     nrec,avant,airefi,phisfi,
+     s     t,zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
+     s     yu1,yv1,ftsol,pctsrf,
+     s     frac_impa,frac_nucl,phis)
+
+      IMPLICIT NONE
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "logic.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "comgeom2.h"
+
+#include "tracstoke.h"
+
+      integer irec,nrec,i,j
+
+      integer klon,ig,l
+      parameter (klon=iim*(jjm-1)+2)
+      INTEGER nbsrf
+      PARAMETER (nbsrf=4) ! nombre de sous-fractions pour une maille
+
+c Convection
+      real*4 zmfd(klon,llm),zde_d(klon,llm),zen_d(klon,llm)
+      real*4 zmfu(klon,llm),zde_u(klon,llm),zen_u(klon,llm)
+      real*4 mfd(klon,llm),de_d(klon,llm),en_d(klon,llm)
+      real*4 mfu(klon,llm),de_u(klon,llm),en_u(klon,llm)
+	real*4 t(klon,llm)
+      real zdtvr
+	
+	real*4 airedy(iip1,jjp1)
+      real*4 rlonu_dy(iip1,jjp1),rlonv_dy(iip1,jjm),
+     . rlatu_dy(iip1,jjp1),rlatv_dy(iip1,jjm)
+
+      real*4 coefkz(klon,llm)
+      real*4 frac_impa(klon,llm),frac_nucl(klon,llm)
+      real*4 yu1(klon), yv1(klon)
+      real*4 ftsol(klon,nbsrf),pctsrf(klon,nbsrf)
+
+      logical avant
+
+      real massefi(klon,llm)
+
+c   Flux masse
+      real*4 massem(iip1,jjp1,llm),tetan(iip1,jjp1,llm)
+      real*4 pbarun(iip1,jjp1,llm),pbarvn(iip1,jjm,llm)
+      real*4 pbarvst(iip1,jjp1,llm)
+      real*4 wn(iip1,jjp1,llm),phin(iip1,jjp1,llm)
+      real*4 phis(iip1,jjp1)
+
+      real*4 airefi(klon),phisfi(klon)
+
+      real zcontrole(klon),zmass,tmpdyn(iip1,jjp1),zflux
+
+      real ziadvtrac,ziadvtrac2,zrec2
+      integer zim,zjm,zlm,zklon,zklev,zrec
+
+      real zpi
+
+      zpi=2.*asin(1.)
+
+
+c==================================================================
+c   Si le numero du record est 0 alors: INITIALISATION
+c==================================================================
+c
+      print*,'ENTREE DANS LECTFLUXNC'
+        print*,'IREC=',IREC
+
+      if(irec.eq.0) then
+
+        print*,'IREC==',0
+
+C test         call inigeom
+
+c==================================================================
+c   ouverture des fichiers
+c==================================================================
+	
+	CALL read_dstoke(0,zdtvr,ziadvtrac,ziadvtrac2)
+	
+	CALL read_fstoke0(0,
+     .  zrec,zim,zjm,zlm,
+     .   rlonu_dy,rlonv_dy,rlatu_dy,rlatv_dy,airedy,phis,
+     .   massem,pbarun,pbarvn,wn,tetan,phin)
+c 
+	if(physic)then	
+	CALL read_pstoke0(0,
+     .   zrec,zklon,zklev,airefi,phisfi,
+     .   t,mfu,mfd,en_u,de_u,en_d,de_d,coefkz,
+     .   frac_impa,frac_nucl,yu1,yv1,ftsol,pctsrf)
+	endif
+	
+	dtvr=zdtvr	
+	nrec=zrec
+        print*,'nrec=',nrec
+	
+	print*, 'Lecture de defstoke.nc'
+	print*, 'Ds lectfluxnc dtvr = ', dtvr
+	print*, 'Ds lectfluxnc istdyn= ',ziadvtrac
+        print*, 'Ds lectfluxnc istphy= ',ziadvtrac2
+
+      istdyn=ziadvtrac
+      istphy=ziadvtrac2
+	
+c	pause
+
+c==================================================================
+c   Fin des initialisations
+      else ! irec=0
+c==================================================================
+
+
+c-----------------------------------------------------------------------
+c   Lecture des fichiers fluxmass et  physique:
+c   -----------------------------------------------------
+
+	 CALL read_fstoke0(irec,
+     .   zrec,zim,zjm,zlm,
+     .   rlonu_dy,rlonv_dy,rlatu_dy,rlatv_dy,airedy,phis,
+     .   massem,pbarun,pbarvn,wn,tetan,phin)
+	
+	write(*,*) 'lectfluxnc aps read_fstoke irec',irec
+	if(physic)then
+        CALL read_pstoke0(irec,
+     .   zrec,zklon,zklev,airefi,phisfi,
+     .   t,mfu,mfd,en_u,de_u,en_d,de_d,coefkz,
+     .   frac_impa,frac_nucl,yu1,yv1,ftsol,pctsrf)
+	
+	write(*,*) 'lectfluxnc aps read_pstoke irec',irec
+	
+	if (avant) then
+c Simu directe
+       do l=1,llm
+          do ig=1,klon
+             zmfu(ig,l)=mfu(ig,l)
+             zmfd(ig,l)=mfd(ig,l)
+             zde_u(ig,l)=de_u(ig,l)
+             zen_u(ig,l)=en_u(ig,l)
+             zde_d(ig,l)=de_d(ig,l)
+             zen_d(ig,l)=en_d(ig,l)
+          enddo
+       enddo
+      else
+c   Simu retro
+       do l=1,llm
+          do ig=1,klon
+             zmfd(ig,l)=-mfu(ig,l)
+             zmfu(ig,l)=-mfd(ig,l)
+             zen_d(ig,l)=de_u(ig,l)
+             zde_d(ig,l)=en_u(ig,l)
+             zen_u(ig,l)=de_d(ig,l)
+             zde_u(ig,l)=en_d(ig,l)
+          enddo
+       enddo
+      endif
+
+c-----------------------------------------------------------------------
+c   PETIT CONTROLE SUR LES FLUX CONVECTIFS...
+c-----------------------------------------------------------------------
+
+      print*,'Ap redec irec'
+	write(*,*) 'dtphys = ', dtphys
+
+         call gr_dyn_fi(llm,iip1,jjp1,klon,massem,massefi)
+
+         do ig=1,klon
+            zcontrole(ig)=1.
+         enddo
+c   zmass=(max(massem(ig,l),massem(ig,l-1))/airefi(ig)
+         do l=2,llm
+            do ig=1,klon
+               zmass=max(massefi(ig,l),massefi(ig,l-1))/airefi(ig)
+               zflux=max(abs(zmfu(ig,l)),abs(zmfd(ig,l)))*dtphys
+               if(zflux.gt.0.9*zmass) then
+                 zcontrole(ig)=min(zcontrole(ig),0.9*zmass/zflux)
+               endif
+            enddo
+         enddo
+
+         do ig=1,klon
+            if(zcontrole(ig).lt.0.99999) then
+               print*,'ATTENTION !!! on reduit les flux de masse '
+               print*,'convectifs au point ig=',ig
+            endif
+         enddo
+	
+	write(*,*) 'lectfluxnc avt gr_fi_dyn'
+
+         call gr_fi_dyn(1,klon,iip1,jjp1,zcontrole,tmpdyn)
+	
+	write(*,*) 'lectfluxnc aps gr_fi_dyn'
+        
+         do l=1,llm
+            do ig=1,klon
+               zmfu(ig,l)=zmfu(ig,l)*zcontrole(ig)
+               zmfd(ig,l)=zmfd(ig,l)*zcontrole(ig)
+               zen_u(ig,l)=zen_u(ig,l)*zcontrole(ig)
+               zde_u(ig,l)=zde_u(ig,l)*zcontrole(ig)
+               zen_d(ig,l)=zen_d(ig,l)*zcontrole(ig)
+               zde_d(ig,l)=zde_d(ig,l)*zcontrole(ig)
+            enddo
+         enddo
+	 endif
+	
+	write(*,*) 'lectfluxnc fin de boucle if'
+
+      endif ! irec=0
+
+      RETURN
+      END
+
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/minmax2.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/minmax2.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/minmax2.F	(revision 253)
@@ -0,0 +1,17 @@
+       SUBROUTINE minmax2(imax, jmax, lmax, xi, zmin, zmax )
+c
+       INTEGER lmax,jmax,imax
+       REAL xi(imax*jmax*lmax) 
+       REAL zmin,zmax
+       INTEGER i
+    
+       zmin = xi(1)
+       zmax = xi(1)
+
+       DO i = 2, imax*jmax*lmax
+         zmin = MIN( zmin,xi(i) )
+         zmax = MAX( zmax,xi(i) )
+       ENDDO
+
+       RETURN
+       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/minmax2F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/minmax2F	(revision 3)
+++ 	(revision )
@@ -1,17 +1,0 @@
-       SUBROUTINE minmax2(imax, jmax, lmax, xi, zmin, zmax )
-c
-       INTEGER lmax,jmax,imax
-       REAL xi(imax*jmax*lmax) 
-       REAL zmin,zmax
-       INTEGER i
-    
-       zmin = xi(1)
-       zmax = xi(1)
-
-       DO i = 2, imax*jmax*lmax
-         zmin = MIN( zmin,xi(i) )
-         zmax = MAX( zmax,xi(i) )
-       ENDDO
-
-       RETURN
-       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/modif_etat0.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/modif_etat0.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/modif_etat0.F	(revision 253)
@@ -0,0 +1,259 @@
+      PROGRAM modif_etat0
+      
+      USE startvar
+      USE ioipsl
+      !
+      IMPLICIT NONE
+      !
+#include "dimensions.h"
+#include "paramet.h"
+      !
+      !
+#include "dimphy.h"
+      !
+#include "comgeom2.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "indicesol.h"
+#include "dimsoil.h"
+      !
+      REAL :: latfi(klon), lonfi(klon)
+      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1), masque(iip1,jjp1),
+     . psol(iip1, jjp1), phis(iip1, jjp1)
+      REAL :: tsol(klon,nbsrf), qsol(klon,nbsrf), sn(klon,nbsrf)
+      REAL :: evap(klon,nbsrf), albe(klon,nbsrf)
+      real :: rain_fall(klon), snow_fall(klon)
+      real :: sollw(klon), solsw(klon)
+      REAL :: radsol(klon),deltat(klon), rugmer(klon), agesno(klon)
+      REAL :: zmea(iip1*jjp1), zstd(iip1*jjp1)
+      REAL :: zsig(iip1*jjp1), zgam(iip1*jjp1), zthe(iip1*jjp1)
+      REAL :: zpic(iip1*jjp1), zval(iip1*jjp1), rugsrel(iip1*jjp1)
+      REAL :: pctsrf(klon, nbsrf)
+      REAL :: tsoil(klon, nsoilmx, nbsrf)
+      REAL :: t_ancien(klon, klev), q_ancien(klon, klev)
+      REAL :: tabcntrl0(100)
+      LOGICAL :: ancien_ok
+      ! declarations pour lecture glace de mer
+      INTEGER :: iml_lic, jml_lic, llm_tmp, ttm_tmp, iret
+      INTEGER :: itau(1), fid
+      REAL :: lev(1), date, dt
+      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_lic, lat_lic
+      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_lic, dlat_lic
+      REAL, ALLOCATABLE, DIMENSION (:,:) :: fraclic
+      REAL :: flic_tmp(iip1, jjp1)
+      REAL :: champint(iim, jjp1)
+      !
+      CHARACTER*80 :: varname
+      !
+#include "comdissnew.h"
+#include "control.h"
+#include "serre.h"
+#include "clesph0.h"
+
+      INTEGER  ::        longcles
+      PARAMETER      ( longcles  = 20 )
+      REAL :: clesphy0 ( longcles       )
+      REAL ::phystep,co2_ppm,solaire
+      REAL :: unskap
+      INTEGER :: radpas
+
+      CHARACTER*80 :: visu_file
+      INTEGER :: visuid
+      !
+      ! indices de boucle 
+      INTEGER :: ji
+      !   Constantes 
+      !
+      pi     = 4. * ATAN(1.)
+      rad    = 6371229.
+      omeg   = 4.* ASIN(1.)/(24.*3600.)
+      g      = 9.8
+      daysec = 86400.
+      kappa  = 0.2857143
+      cpp    = 1004.70885
+      !
+      preff     = 101325.
+      unskap = 1./kappa
+      !
+      jmp1    = jjm + 1
+      !
+      !    Construct a grid
+      !
+
+      CALL defrun_new(99,.TRUE.,clesphy0)
+
+      dtvr   = daysec/FLOAT(day_step)
+      print*,'dtvr',dtvr
+
+      CALL inicons0()
+      CALL inigeom()
+      !
+      CALL inifilr()
+      !
+      !
+      !! 1. READ orography 
+      !
+      varname = 'relief'
+      ! This line needs to be replaced by a call to restget to get the values in the restart file
+      orog(:,:) = 0.0
+       CALL startget(varname, iip1, jjp1, rlonv, rlatu, orog, 0.0)
+      !
+      WRITE(*,*) 'OUT OF GET VARIABLE : Relief'
+      WRITE(*,'(49I1)') INT(orog(:,:))
+      !
+      varname = 'rugosite'
+      ! This line needs to be replaced by a call to restget to get the values in the restart file
+      rugo(:,:) = 0.0
+       CALL startget(varname, iip1, jjp1, rlonv, rlatu, rugo, 0.0)
+      !
+      WRITE(*,*) 'OUT OF GET VARIABLE : Rugosite' 
+      WRITE(*,'(49I1)') INT(rugo(:,:)*10)
+      !
+      varname = 'masque'
+      ! This line needs to be replaced by a call to restget to get the values in the restart file
+      masque(:,:) = 0.0
+       CALL startget(varname, iip1, jjp1, rlonv, rlatu, masque, 0.0)
+      !
+      WRITE(*,*) 'MASQUE construit : Masque'
+      WRITE(*,*) masque(:,:)
+      WRITE(*,*) 'orographie'
+      WRITE(*,*) orog(:,:)
+      !
+      !! 2. create masque and READ land iice fraction
+      !!
+      ! lit bande startphy a modifier
+      !
+     
+      CALL phyetat0("startphy.nc", phystep, co2_ppm, solaire, latfi,  
+     $    lonfi, pctsrf, tsol, tsoil, deltat, qsol, sn, 
+     $    albe, evap, rain_fall, snow_fall, solsw, sollw,
+     $    radsol, rugmer, agesno, clesphy0, 
+     $    zmea, zstd, zsig, zgam, zthe, zpic, zval, 
+     $    rugsrel, tabcntrl0, t_ancien, q_ancien, ancien_ok)
+C
+C on initialise les sous surfaces
+C
+      pctsrf=0.
+      !cree le masque a partir du fichier relief
+      varname = 'zmasq'
+      zmasq(:) = 0.
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zmasq,0.0)
+      WHERE (zmasq(1 : klon) .LE. EPSFRA)
+          zmasq(1 : klon) = 0.
+      END WHERE 
+      WRITE(*,*)zmasq
+      varname = 'zmea'
+      zmea(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0)
+      varname = 'zstd'
+      zstd(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0)
+      varname = 'zsig'
+      zsig(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0)
+      varname = 'zgam'
+      zgam(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0)
+      varname = 'zthe'
+      zthe(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0)
+      varname = 'zpic'
+      zpic(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0)
+      varname = 'zval'
+      zval(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zval,0.0)
+      rugsrel(:) = 0.0
+C
+C lecture du fichier glace de terre pour fixer la fraction de terre 
+C et de glace de terre
+C
+      CALL flininfo("landiceref.nc", iml_lic, jml_lic,llm_tmp, ttm_tmp
+     $    , fid)
+      ALLOCATE(lat_lic(iml_lic, jml_lic), stat=iret)
+      ALLOCATE(lon_lic(iml_lic, jml_lic), stat=iret)
+      ALLOCATE(dlon_lic(iml_lic), stat=iret)
+      ALLOCATE(dlat_lic(jml_lic), stat=iret)
+      ALLOCATE(fraclic(iml_lic, jml_lic), stat=iret)
+      CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp
+     $    , lon_lic, lat_lic, lev, ttm_tmp, itau, date, dt, fid)
+      CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp
+     $    , 1, 1, fraclic)
+      CALL flinclo(fid)
+C
+C interpolation sur la grille T du modele
+C
+      WRITE(*,*) 'dimensions de landice iml_lic, jml_lic : ', 
+     $    iml_lic, jml_lic
+c
+C sil les coordonnees sont en degres, on les transforme
+C
+      IF( MAXVAL( lon_lic(:,:) ) .GT. 2.0 * asin(1.0) )  THEN
+          lon_lic(:,:) = lon_lic(:,:) * 2.0* ASIN(1.0) / 180.
+      ENDIF 
+      IF( maxval( lat_lic(:,:) ) .GT. 2.0 * asin(1.0)) THEN 
+          lat_lic(:,:) = lat_lic(:,:) * 2.0 * asin(1.0) / 180.
+      ENDIF 
+
+      dlon_lic(1 : iml_lic) = lon_lic(1 : iml_lic, 1)
+      dlat_lic(1 : jml_lic) = lat_lic(1 , 1 : jml_lic) 
+C
+      CALL grille_m(iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic
+     $    ,iim, jjp1,
+     $    rlonv, rlatu, flic_tmp(1 : iim, 1 : jjp1))
+c$$$      flic_tmp(1 : iim, 1 : jjp1) = champint(1: iim, 1 : jjp1)
+      flic_tmp(iip1, 1 : jjp1) = flic_tmp(1 , 1 : jjp1)
+C
+C passage sur la grille physique
+C
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp,
+     $    pctsrf(1:klon, is_lic))
+C adequation avec le maque terre/mer
+      WHERE (pctsrf(1 : klon, is_lic) .LE. EPSFRA ) 
+          pctsrf(1 : klon, is_lic) = 0. 
+      END WHERE
+      WHERE (zmasq( 1 : klon) .LE. EPSFRA) 
+          pctsrf(1 : klon, is_lic) = 0.
+      END WHERE 
+      pctsrf(1 : klon, is_ter) = zmasq(1 : klon)
+      DO ji = 1, klon
+        IF (zmasq(ji) .GT. EPSFRA) THEN 
+            IF ( pctsrf(ji, is_lic) .GE. zmasq(ji)) THEN
+                pctsrf(ji, is_lic) = zmasq(ji)
+                pctsrf(ji, is_ter) = 0.
+            ELSE 
+                pctsrf(ji,is_ter) = zmasq(ji) - pctsrf(ji, is_lic)
+            ENDIF 
+        ENDIF 
+      END DO 
+C
+C sous surface ocean et glace de mer (pour demarrer on met glace de mer a 0)
+C
+      pctsrf(1 : klon, is_oce) = (1. - zmasq(1 : klon))
+      WHERE (pctsrf(1 : klon, is_oce) .LT. EPSFRA)
+          pctsrf(1 : klon, is_oce) = 0.
+      END WHERE 
+C
+C verif que somme des sous surface = 1
+C
+      ji=count( (abs( sum(pctsrf(1 : klon, 1 : nbsrf), dim = 2)) - 1.0 ) 
+     $    .GT. EPSFRA)
+      IF (ji .NE. 0) THEN
+          WRITE(*,*) 'pb repartition sous maille pour ',ji,' points'
+      ENDIF 
+C
+C Ecriture etat initial physique
+C
+      WRITE(*,*) 'zmasq avant phyredem'
+      WRITE(*,*) zmasq
+
+      call phyredem("restartphy.nc",phystep,radpas, co2_ppm, solaire,
+     $    latfi, lonfi, pctsrf, tsol, tsoil, deltat, qsol, sn, 
+     $    albe, evap, rain_fall, snow_fall, solsw, sollw, 
+     $    radsol, rugmer,  agesno, 
+     $    zmea, zstd, zsig, zgam, zthe, zpic, zval, rugsrel, 
+     $    t_ancien, q_ancien)
+
+      CALL histclo
+      !
+      END  
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/nudge.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/nudge.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/nudge.F	(revision 253)
@@ -0,0 +1,228 @@
+c $Header$
+      subroutine nudge(itau,ucov,vcov,teta,masse,ps)
+
+      IMPLICIT NONE
+
+c      ......   Version  du 10/01/98    ..........
+
+c             avec  coordonnees  verticales hybrides 
+c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
+
+c=======================================================================
+c
+c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
+c   -------
+c
+c   Objet:
+c   ------
+c
+c   GCM LMD nouvelle grille
+c
+c=======================================================================
+
+c   ...  Dans inigeom , nouveaux calculs pour les elongations  cu , cv 
+c        et possibilite d'appeler une fonction f(y)  a derivee tangente 
+c        hyperbolique a la  place de la fonction a derivee sinusoidale.         
+
+c   ...  Possibilite de choisir le shema de Van-leer pour l'advection de
+c         q  , en faisant iadv = 3  dans   traceur  (29/04/97) .
+c
+c-----------------------------------------------------------------------
+c   Declarations:
+c   -------------
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comdissnew.h"
+#include "comvert.h"
+#include "comgeom.h"
+#include "logic.h"
+#include "temps.h"
+#include "control.h"
+#include "ener.h"
+#include "netcdf.inc"
+#include "description.h"
+#include "serre.h"
+#include "tracstoke.h"
+
+
+c   variables dynamiques
+      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
+      REAL teta(ip1jmp1,llm)                 ! temperature potentielle 
+      REAL ps(ip1jmp1)                       ! pression  au sol
+      REAL masse(ip1jmp1,llm)                ! masse d'air
+
+c   variables dynamiques pour les reanalyses.
+      REAL ucovrea1(ip1jmp1,llm),vcovrea1(ip1jm,llm) !vts cov reas
+      REAL tetarea1(ip1jmp1,llm)             ! temp pot  reales
+      REAL masserea1(ip1jmp1,llm)             ! masse
+      REAL psrea1(ip1jmp1)             ! ps
+      REAL ucovrea2(ip1jmp1,llm),vcovrea2(ip1jm,llm) !vts cov reas
+      REAL tetarea2(ip1jmp1,llm)             ! temp pot  reales
+      REAL masserea2(ip1jmp1,llm)             ! masse
+      REAL psrea2(ip1jmp1)             ! ps
+      real alphaT,alphaP,alphau,alphav
+      real dday_step,toto,reste,itau_test
+      INTEGER step_rea,count_no_rea
+
+
+c
+      INTEGER itau,ij,l
+      real ditau,tau,a
+
+      LOGICAL first
+      integer online
+      save first,online
+      data first,online/.true.,1/
+
+      save ucovrea1,vcovrea1,tetarea1,masserea1,psrea1
+      save ucovrea2,vcovrea2,tetarea2,masserea2,psrea2
+
+      save alphaT,alphau,alphav,alphaP,itau_test
+      save step_rea,count_no_rea
+
+c-----------------------------------------------------------------------
+c   initialisations pour la lecture des reanalyses.
+c    alpha determine la part des injections de donnees a chaque etape
+c    alpha=1 signifie pas d'injection
+c    alpha=0 signifie injection totale
+c-----------------------------------------------------------------------
+
+      print*,'ONLINE=',online
+      if(online.eq.-1) then
+          return
+      endif
+
+      if (first) then
+         print*
+     s   ,'1: en-ligne, 0: hors-ligne (x=x_rea), -1: climat (x=x_gcm)'
+cnec         read(*,*) online
+cnec      online=-1
+cnec     print*,'Entrer les constantes de temps de rappel en jours'
+cnec         read(*,*)alphaT
+cnec         read(*,*)alphau
+cnec         read(*,*)alphav
+cnec         read(*,*)alphaP
+             alphaT=0.1
+             alphau=0.1
+             alphav=0.1
+             alphaP=1.e10
+         print*,'alphaT,alphau,alphav,alphaP'
+     s          ,alphaT,alphau,alphav,alphaP
+         if(online.eq.-1) return
+         print*,'alpha rappel pour T, u, v, P ',
+     s    alphaT,alphau,alphav,alphaP
+c   En fait, le coef alpha qu'on utilise est
+c   x_gcm = a * x_gcm + ( 1 - a ) * x_reanalys
+c   on a alors a=1-dt/tau
+c   ou dt est la frequence a laquelle on corrige (ici iperiod*dtvr)
+c   et tau la constante de temps lue. D'ou:
+         if (online.eq.1) then
+            alphaT=1.-iperiod*dtvr/(daysec*alphaT)
+            alphau=1.-iperiod*dtvr/(daysec*alphau)
+            alphav=1.-iperiod*dtvr/(daysec*alphav)
+            alphaP=1.-iperiod*dtvr/(daysec*alphaP)
+         else
+            alphaT=0.
+            alphau=0.
+            alphav=0.
+            alphaP=0.
+c           physic=.false.
+         endif
+         print*,'alpha rappel pour T, u, v, P ',
+     s    alphaT,alphau,alphav,alphaP
+
+         itau_test=1001
+         step_rea=1
+         count_no_rea=0
+
+c    itau_test    montre si l'importation a deja ete faite au rang itau
+
+
+c   Lecture du premier etat des reanalyses.
+         call read_reanalyse(1
+     s   ,ucovrea2,vcovrea2,tetarea2,masserea2,ps,1)
+
+c-----------------------------------------------------------------------
+c   Debut de l'integration temporelle:
+c   ----------------------------------
+
+         first=.false.
+      endif ! first
+c
+C-----------------------------------------------------------------------
+C----- IMPORTATION DES VENTS,PRESSION ET TEMPERATURE REELS:
+C-----------------------------------------------------------------------
+
+      ditau=real(itau)
+      dday_step=real(day_step)
+      write(*,*)'ditau,dday_step'
+      write(*,*)ditau,dday_step
+      toto=4*ditau/dday_step
+      reste=toto-aint(toto)
+c     write(*,*)'toto,reste',toto,reste
+
+      if (reste.eq.0.) then
+        if (itau_test.eq.itau) then
+          write(*,*)'deuxieme passage de advreel a itau=',itau
+          stop
+        else
+           CALL SCOPY( ijmllm ,vcovrea2, 1, vcovrea1 , 1 )
+           CALL SCOPY( ijp1llm,ucovrea2, 1, ucovrea1 , 1 )
+           CALL SCOPY( ijp1llm,tetarea2,1,tetarea1   , 1 )
+c          CALL SCOPY( ijp1llm,masserea2,1,masserea1   , 1 )
+c          CALL SCOPY( ip1jmp1,psrea2, 1,  psrea1, 1 )
+
+          print*,'LECTURE REANALYSES, pas ',step_rea
+     s         ,'apres ',count_no_rea,' non lectures'
+           step_rea=step_rea+1
+           itau_test=itau
+           call read_reanalyse(step_rea
+     s     ,ucovrea2,vcovrea2,tetarea2,masserea2,ps,1)
+        endif
+      else
+        count_no_rea=count_no_rea+1
+      endif
+ 
+C-----------------------------------------------------------------------
+c   Corrrections
+c
+c    x_gcm = a * x_gcm + (1-a) * x_reanalyses
+C-----------------------------------------------------------------------
+
+      ditau=real(itau)
+      dday_step=real(day_step)
+
+c     print*,'alpha1',alphaT,alphaP,alphau,alphav
+
+      tau=4*ditau/dday_step
+      tau=tau-aint(tau)
+
+      do l=1,llm
+         do ij=1,ip1jmp1
+            a=(1.-tau)*ucovrea1(ij,l)+tau*ucovrea2(ij,l)
+            ucov(ij,l)=alphau*ucov(ij,l)+(1-alphau)*a
+            a=(1.-tau)*tetarea1(ij,l)+tau*tetarea2(ij,l)
+            teta(ij,l)=alphaT*teta(ij,l)+(1-alphaT)*a
+c           a=(1.-tau)*masserea1(ij,l)+tau*masserea2(ij,l)
+c           masse(ij,l)=alphaP*masse(ij,l)+(1-alphaP)*a
+         enddo
+         do ij=1,ip1jm
+            a=(1.-tau)*vcovrea1(ij,l)+tau*vcovrea2(ij,l)
+            vcov(ij,l)=alphav*vcov(ij,l)+(1-alphav)*a
+         enddo
+      enddo
+
+c     call dump2d(iip1,jjp1,tetarea1,'TETA REA 1     ')
+c     call dump2d(iip1,jjp1,tetarea2,'TETA REA 2     ')
+c     call dump2d(iip1,jjp1,teta,'TETA           ')
+Cmaf  on ne nudge pas sur la pression de surface
+c      do ij=1,ip1jmp1
+c         a=(1.-tau)*psrea1(ij)+tau*psrea2(ij)
+c         ps(ij)=alphaP*ps(ij)+(1-alphaP)*a
+c      enddo
+
+
+      return
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/offline.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/offline.F	(revision 3)
+++ 	(revision )
@@ -1,640 +1,0 @@
-      PROGRAM offline
-      USE ioipsl
-      IMPLICIT NONE
-
-c      ......   Version  du 17/04/96    ..........
-c=======================================================================
-c
-c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
-c   -------
-c   Modif special traceur F.Forget 05/94
-c
-c   Modifs M-A Filiberti 07/99
-C
-c   Objet:
-c   ------
-c
-c   GCM LMD nouvelle grille
-c
-c=======================================================================
-
-c   ...      modification de l'integration de q ( 26/04/94 )      ....
-
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comdissnew.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "logic.h"
-#include "temps.h"
-#include "control.h"
-#include "ener.h"
-#include "description.h"
-#include "serre.h"
-#include "tracstoke.h"
-      integer ngridmx,nbsrf
-      PARAMETER (ngridmx=iim*(jjm-1)+2,nbsrf=4)
-c-----------------------------------------------------------------------
-
-      INTEGER*4  iday ! jour julien
-      REAL       time ! Heure de la journee en fraction d'1 jour
-      REAL dtdyn,dtav
-      INTEGER iday_step
-
-      INTEGER         longcles
-      PARAMETER     ( longcles = 20 )
-      REAL  clesphy0( longcles )
-      logical clefinit
-
-
-c   variables dynamiques
-      REAL vcov(iip1,jjm,llm),ucov(iip1,jjp1,llm) ! vents covariants
-      REAL q(iip1,jjp1,llm,nqmx)               ! champs advectes
-      REAL pks(iip1,jjp1)                      ! exner (f pour filtre)
-      REAL phis(iip1,jjp1)                     ! geopotentiel au sol
-      REAL phi(iip1,jjp1,llm)                  ! geopotentiel
-      REAL w(iip1,jjp1,llm)                    ! vitesse verticale
-C
-C   variables physiques
-      real zmfd(ngridmx,llm),zde_d(ngridmx,llm),zen_d(ngridmx,llm)
-      REAL qfi(ngridmx,llm,nqmx)               ! champs advectes
-      real zmfu(ngridmx,llm),zde_u(ngridmx,llm),zen_u(ngridmx,llm)
-      real coefkz(ngridmx,llm)
-      real frac_impa(ngridmx,llm),frac_nucl(ngridmx,llm)
-      real pphis (ngridmx)
-      REAL airefi(ngridmx)
-      REAL latfi(ngridmx),lonfi(ngridmx) ! latitude et long pour chaque point
-      real yu1(ngridmx), yv1(ngridmx)
-      real ftsol(ngridmx,nbsrf),pctsrf(ngridmx,nbsrf)
-
-C
-      character*10 file
-
-c variables dynamiques intermediaire pour le transport
-      REAL pbaru(iip1,jjp1,llm),pbarv(iip1,jjm,llm) !flux de masse
-
-      REAL masse(iip1,jjp1,llm)
-      REAL massebx(iip1,jjp1,llm),masseby(iip1,jjm,llm)
-      REAL teta(iip1,jjp1,llm)
-
-      INTEGER itau,irec,nrec,ldec,itauav
-      integer recmin,recmax,recstkmin,recstkmax
-      character*1 injecte,stoke
-      character*10 nom
-
-      integer jour0,isplit,nsplit_dyn,nsplit_phy,nsplit
-      logical debut,lectstart,rnpb
-
-      EXTERNAL inidissip,iniconst,inifilr
-      EXTERNAL inigeom
-      EXTERNAL exner_hyb,pression
-      EXTERNAL defrun_new
-
-      REAL time_0 ! temps de debut de simulation (% journee)
-
-      character*2 str2
-      INTEGER iq,j,i,l,nq,mode
-
-      real paprs(ngridmx,llm+1),pplay(ngridmx,llm),tempfi(ngridmx,llm)
-      real p(iip1,jjp1,llmp1),pk(iip1,jjp1,llm)
-
-      real lon_stat(nqmx),lat_stat(nqmx),zlon,zlat
-      integer i_stat(nqmx),j_stat(nqmx)
-      real intensite(nqmx)
-
-      integer iqmin,iqmax
-      integer npasinject
-      data npasinject/1/
-
-      integer histid, histvid, histaveid
-      real time_step, t_wrt, t_ops
-      integer itime_step
-      character*80 dynhist_file, dynhistave_file
-
-
-      logical avant
-
-      logical debutphy,redecoupage
-      DATA debutphy/.true./
-      
-      real unskap,pksurcp,smass(iip1,jjp1)
-      integer ig0,ii,jj,iii,ij
-
-     
-      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
-      REAL ps(iip1,jjp1),pkf(ip1jmp1,llm) 
-
-
-c-----------------------------------------------------------------------
-c   Initialisations:
-c   ----------------
-
-      descript = 'Run GCM LMDZ'
-
-c-----------------------------------------------------------------------
-
-
-      rad = 6400000
-      omeg = 7.272205e-05
-      g = 9.8
-      kappa = 0.285716
-      daysec = 86400
-      cpp = 1004.70885
-Cmaf a verifier....
-      preff = 101325.
-      pa= 50000.
-C
-
-      print*,'Nombre effectif de traceurs'
-      read(*,*) nq
-      write(*,*) nq
-      print*,'Splitting du pas de temps dynamique'
-      read(*,*) nsplit_dyn
-      write(*,*) nsplit_dyn
-      print*,'Splitting du pas de temps physique'
-      read(*,*) nsplit_phy
-      write(*,*) nsplit_phy
-      print*,'jour0, par rapport au debut du fichier fluxmass'
-      read(*,*) jour0
-      write(*,*) jour0
-      print*,'redecoupage (T) ou standard (F)'
-      read(*,'(l1)') redecoupage
-      write(*,*) redecoupage
-      print*,'Lecture fichier start (T)?'
-      read(*,'(l1)') lectstart
-      write(*,'(l1)') lectstart
-      print*,'Traceurs 1 et 2 = Rn222 et Pb'
-      read(*,'(l1)') rnpb
-      write(*,'(l1)') rnpb
-      print*,'Avant T ou arriere F?'
-      read(*,'(l1)') avant
-      write(*,'(l1)') avant
-      print*,'Index min et max des traceurs a initaliser'
-      read(*,*) iqmin,iqmax
-      write(*,*) iqmin,iqmax
-      print*,'localisation (lon, lat, intensite)'
-      if(iqmax.le.0) then
-         iqmin=iqmax+1
-      endif
-      do iq=iqmin,iqmax
-         read(*,*) lon_stat(iq),lat_stat(iq),intensite(iq)
-         write(*,*) lon_stat(iq),lat_stat(iq),intensite(iq)
-      enddo
-      print*,'Injection sur combien de pas de temps'
-      read(*,*) npasinject
-      write(*,*) npasinject
-      print*,'Records min et max pour le stokage et couche '
-     s    ,'verticale (specifique reseaux), def 0 0 1'
-      read(*,*) recstkmin,recstkmax,ldec
-      write(*,*) recstkmin,recstkmax,ldec
-
-c   redefinition du splitting
-      if(mod(nsplit_dyn,nsplit_phy).eq.0) then
-         nsplit=nsplit_phy
-      elseif (mod(nsplit_phy,nsplit_dyn).eq.0) then
-         nsplit=nsplit_dyn
-      else
-         stop'prendre un des deux nsplit doit diviser l autre'
-      endif
-      nsplit_dyn=nsplit_dyn/nsplit
-      nsplit_phy=nsplit_phy/nsplit
-      print*,'nsplit,nsplit_dyn,nsplit_phy'
-     s       ,nsplit,nsplit_dyn,nsplit_phy
-c   Lecture eventuelle 
-      time_0=0.
-
-      if(nq.gt.nqmx) stop'surdimensioner nqmx'
-
-      print*,'av initial0'
-      call initial0(nq*ijp1llm,q)
-
-      print*,'av lectstart'
-      if(lectstart) then
-         CALL dynetat0("start.nc",nq,vcov,ucov,
-     .              teta,q,masse,ps,phis, time_0)
-         print*,'Lecture du start'
-      else
-         day_ini=0
-         anne_ini=0
-      endif
-      day_end=day_ini+nday
-
-
-      print*,'av defrun'
-c     open (99,file='run.def',status='old',form='formatted')
-      clefinit=.true.
-      CALL defrun_new( 99, clefinit, clesphy0 )
-c     close(99)
-
-      print*,'av iniconst'
-c   lecture du jour de demarrage
-c    premiere initialisation, eventuellement bidon
-      CALL iniconst
-      CALL inigeom
-
-C
-c  Lecture des entetes des fichiers de flux
-      if(redecoupage) then
-         call redecoupe(0,masse,pbaru,pbarv,w,teta,phi,
-     s     nrec,avant,airefi,
-     s     zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
-     s     yu1,yv1,ftsol,pctsrf,
-     s     frac_impa,frac_nucl)
-      else
-         call lectflux(0,masse,pbaru,pbarv,w,teta,phi,
-     s     nrec,avant,airefi,
-     s     zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
-     s     yu1,yv1,ftsol,pctsrf,
-     s     frac_impa,frac_nucl,phis)
-         call inigeom
-      endif
-
-c   controle sur les records
-      if(avant) then
-         recmin=2+(jour0-1)*iday_step
-         recmax=1+(jour0+nday-1)*iday_step
-      else
-         recmin=(jour0-nday)*iday_step+2
-         recmax=jour0*iday_step+1
-      endif
-      if(recmin.le.1.or.recmax.ge.nrec) then
-         print*,'Probleme de lecture '
-         print*,'recmin,recmax,nrec',recmin,recmax,nrec
-         stop
-      endif
-
-C on recalcule le nombre de pas de temps dans une journee
-c   istdyn est la frequence de stokage en "pas de temps dynamique" dans
-c   le modele on-line. dtvr est le pas de temps du meme modele en s.
-c iday-step est le nombre de lectures par jour (grand pas de temps). 
-      iday_step=daysec/(istdyn*dtvr)
-C
-      CALL iniconst
-c  on calcule le pas de temps 
-      dtvr    = daysec/FLOAT(iday_step)
-      dtphys=dtvr/(nsplit*nsplit_phy) ! a mettre apres iniconst!
-      print*,'Pas de temps physique ',dtphys
-
-
-C
-
-      call gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
-
-      print *,'Pas de temps dynamique', dtvr
-      print*,'Pas de temps physique ',dtphys
-
-c-----------------------------------------------------------------------
-C maf est ce utile ?
-
-      call suphec
-
-      CALL inifilr
-      print*,'Pas de temps physique ',dtphys
-      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
-     *                tetagdiv, tetagrot , tetatemp              )
-      print*,'Pas de temps physique ',dtphys
-
-c-----------------------------------------------------------------------
-c   temps de depart et de fin:
-c   --------------------------
-
-      itau = 0
-      iday = dayref
-      time = time_0
-         IF(time.GT.1.) THEN
-          time = time-1.
-          iday = iday+1
-         ENDIF
-      print*,'Pas de temps physique ',dtphys
-
-c=======================================================================
-c   Initialisation des fichiers de sortie
-c=======================================================================
-
-      print*,'Initialisation de wrgras'
-      file='sol'
-      call inigrads(1,iip1
-     s  ,rlonv,180./pi,-190.,190.,jjp1,rlatu,-90.,90.,180./pi
-     s  ,llm,presnivs,1.
-     s  ,dtphys,file,'gcmq2 ')
-      file='atm'
-      print*,'Pas de temps physique ',dtphys
-      call inigrads(2,iip1
-     s  ,rlonv,180./pi,-190.,190.,jjp1,rlatu,-90.,90.,180./pi
-     s  ,llm,presnivs,1.
-     s  ,dtphys,file,'gcmq2 ')
-
-      print*,'dtphys ap inigrads ',dtphys
-
-      print*,'Ecriture du fichier de conditions aux limites'
-      open (98,file='limit',form='unformatted')
-      write(98) float(im),float(jm),float(nq),float(nday)
-      write(98) (rlonv(i)*180./pi,i=1,iip1)
-      write(98) (rlatu(j)*180./pi,j=1,jjp1)
-      write(98) ((phis(i,j)/g,i=1,iip1),j=1,jjp1)
-      close(98)
-
-      CALL dynredem0("restart.nc",day_end,anne_ini,phis,nq)
-
-c-----------------------------------------------------------------------
-c   Debut de la boucle en temps:
-c   ----------------------------
-
-      do itau=1,nday*iday_step
-
-          print*,'ITAU ITAU ITAU =',itau
-         injecte='.'
-         stoke='.'
-
-c Gestion du temps
-         if (avant) then
-            dtdyn=dtvr/float(nsplit*nsplit_dyn)
-            irec=1+(jour0-1)*iday_step+itau
-         else
-            dtdyn=-dtvr/float(nsplit*nsplit_dyn)
-            irec=1+jour0*iday_step-itau+1
-         endif
-
-         debut=itau.eq.1
-
-c-----------------------------------------------------------------------
-c   Lecture des fichiers fluxmass et physique:
-c   -----------------------------------------------------
-
-         print*,'CCCCC Appel a redecoupe au pas itau=',itau
-      if(redecoupage) then
-         call redecoupe(irec,masse,pbaru,pbarv,w,teta,phi,
-     s     nrec,avant,airefi,
-     s     zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
-     s     yu1,yv1,ftsol,pctsrf, 
-     s     frac_impa,frac_nucl)
-      else
-         call lectflux(irec,masse,pbaru,pbarv,w,teta,phi,
-     s     nrec,avant,airefi,
-     s     zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
-     s     yu1,yv1,ftsol,pctsrf, 
-     s     frac_impa,frac_nucl,phis)
-      endif
-
-c    ...  ouverture du fichier de stockage netcdf ...
-C
-      IF (debut) then
-         dynhistave_file = 'dyn_hist_ave.nc'
-         day_ini=0
-         anne_ini=0
-         t_ops = periodav * daysec
-         t_wrt = periodav * daysec
-         dtav=dtvr/float(nsplit)
-         mode=1
-         CALL initdynav(dynhistave_file,day_ini,anne_ini,dtav,
-     .              t_ops, t_wrt, nq, histaveid)
-         pi=2.*asin(1.)
-         do iq=iqmin,iqmax
-            do l=1,llm
-               do j=1,jjp1
-                  do i=1,iip1
-                     q(i,j,l,iq)=0.
-                  enddo
-               enddo
-            enddo
-            zlon=lon_stat(iq)*pi/180.
-            zlat=lat_stat(iq)*pi/180.
-            CALL coordij(zlon,zlat,i_stat(iq),j_stat(iq))
-         enddo
-      ENDIF
-
-C calcul de la pression de surface.
-      do j=1,jjp1
-         do i=1,iip1
-            smass(i,j)=0.
-         enddo
-      enddo
-      do l=1,llm
-        do j=1,jjp1
-          do i=1,iip1
-             smass(i,j)=smass(i,j)+masse(i,j,l)
-          enddo
-       enddo
-      enddo
-      do j=1,jjp1
-         do i=1,iip1
-            ps (i,j)=smass(i,j)/aire(i,j)*g
-         end do
-      end do
-C
-C calcul de la pression et de pk (fonction d'Exner)
-C
-      CALL pression ( ip1jmp1, ap, bp, ps, p       )
-      CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
-c
-C
-      do jj=1,jjp1
-         do ii=1,iip1
-           phis(ii,jj)= phi(ii,jj,1)-teta(ii,jj,1)*
-     s                             (pks(ii,jj)-pk(ii,jj,1))
-         end do
-      end do
-
-c=======================================================================
-c   TERMES SOURCES OU PUITS
-c=======================================================================
-c   terme source reparti sur npasinject pas
-c   On injecte tous les traceurs de la meme facon
-      if (itau.le.npasinject) then
-        injecte='X'
-         do iq=iqmin,iqmax
-            print*,'INJECTION AU POINT ',lon_stat(iq),lat_stat(iq)
-     s      ,'     I,J=',i_stat(iq),j_stat(iq),jjp1-j_stat(iq)+1
-            q(i_stat(iq),j_stat(iq),1,iq)=
-     s      q(i_stat(iq),j_stat(iq),1,iq)
-     s      +intensite(iq)/masse(i_stat(iq),j_stat(iq),1)/npasinject
-         enddo
-         print*,'fin des injections'
-      endif
-c=======================================================================
-c   FIN DE LA PARTIE TERMES SOURCES
-c=======================================================================
-c-----------------------------------------------------------------------
-c   Advection
-c   ----------
-
-c=======================================================================
-         do isplit=1,nsplit
-c=======================================================================
-CC MAF dans le cas du offline on ne fait pas la difference masse et massem
-            do iii=1,nsplit_dyn
-               do iq=1,nq
-                  CALL vlsplt(q(:,:,:,iq),2.,masse,w,pbaru,pbarv,dtdyn)
-               enddo
-
-c   mise à jour du champd de masse tenant compte de l'advection sur
-c   le pas de temps considere.
-
-            enddo
-
-            do iq=1,nq
-               write(str2,'(i2.2)') iq
-               if(mod(itau,1).eq.0) 
-     s         call diagadv(q(:,:,:,iq),masse,'Traceur '//str2)
-            enddo
-
-
-c-----------------------------------------------------------------------
-c   Physique  (lessivage dans phytrac maintenant) MAF
-c   ---------------------------------------------------------
-
-        if(physic) then
-         if(debut) then
-         latfi(1)=rlatu(1)*180./pi
-         lonfi(1)=0.
-         DO j=2,jjm
-            DO i=1,iim
-               latfi((j-2)*iim+1+i)= rlatu(j)*180./pi
-               lonfi((j-2)*iim+1+i)= rlonv(i)*180./pi
-            ENDDO
-         ENDDO
-         latfi(ngridmx)= rlatu(jjp1)*180./pi
-         lonfi(ngridmx)= 0.
-         endif
-
-c
-C Calcul de paprs et pplay et de temp
-c   -----------------------------------------------------------------
-c     .... paprs  definis aux (llm +1) interfaces des couches  ....
-c     .... pplay  definis aux (  llm )    milieux des couches  ....
-c   -----------------------------------------------------------------
-C
-      DO l = 1, llmp1
-        paprs( 1,l ) = p(1,1,l)
-        ig0 = 2
-          DO j = 2, jjm
-             DO i =1, iim
-              paprs( ig0,l ) = p(i,j,l)
-              ig0 = ig0 +1
-             ENDDO
-          ENDDO
-        paprs( ngridmx,l ) = p(1,jjp1,l)
-      ENDDO
-c
-      unskap   = 1./ kappa
-      DO l=1,llm
-
-         pksurcp     =  pk(1,1,l) / cpp
-         pplay(1,l)  =  preff * pksurcp ** unskap
-         tempfi(1,l)   =  teta(1,1,l) *  pksurcp
-         ig0         = 2
-
-         DO j = 2, jjm
-            DO i = 1, iim
-              pksurcp        = pk(i,j,l) / cpp
-              pplay(ig0,l)   = preff * pksurcp ** unskap
-              tempfi(ig0,l)    = teta(i,j,l)  * pksurcp
-              ig0            = ig0 + 1
-            ENDDO
-         ENDDO
-
-         pksurcp       = pk(1,jjp1,l) / cpp
-         pplay(ig0,l)  = preff * pksurcp ** unskap
-         tempfi (ig0,l)  = teta(1,jjp1,l)  * pksurcp
-      ENDDO
-c On passe le traceur et le geopot de surf  sur la grille physique
-             call gr_dyn_fi(llm*nq,iip1,jjp1,ngridmx,q,qfi)
-             call gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,pphis)
-
-             do iii=1,nsplit_phy
-C
-      print*,'dtphys avant phytrac ',dtphys
-             call phytrac(rnpb,
-     I                   ecritphy, debutphy,
-     I                   nq,
-     I                   ngridmx,llm,dtphys,
-     I                   tempfi,paprs,pplay,
-     I                   zmfu, zmfd, zen_u, zde_u, zen_d, zde_d,
-     I                   coefkz,yu1,yv1,ftsol,pctsrf,latfi,
-     I                   frac_impa, frac_nucl,
-     I                   lonfi,presnivs,airefi,pphis,
-     O                   qfi)
-C
-             debutphy= .FALSE.
-C
-             enddo ! nsplit_phy
-C
-c   On passe le traceur sur la grille dynamique.
-             call gr_fi_dyn(llm*nq,ngridmx,iip1,jjp1,qfi,q)
-
-             endif
-
-             itauav=(itau-1)*nsplit+isplit
-             CALL writedynav(histaveid, nq, itauav,vcov ,
-     ,                   ucov,teta,pk,phi,q,masse,ps,phis)
-
-         enddo ! isplit=1,nsplit
-
-         call histsync
-
-c-----------------------------------------------------------------------
-c    Calcul de ucov et vcov pour les sorties
-c   -------------------------------------
-
-         call massbar(masse, massebx, masseby )
-         do l=1,llm
-            do j=1,jjp1
-               do i=1,iip1
-               ucov(i,j,l)=pbaru(i,j,l)/massebx(i,j,l)*cu(i,j)*cu(i,j)
-     s         /istdyn
-               enddo
-            enddo
-            do j=1,jjm
-               do i=1,iip1
-               vcov(i,j,l)=pbarv(i,j,l)/masseby(i,j,l)*cv(i,j)*cv(i,j)
-     s         /istdyn
-               enddo
-            enddo
-         enddo
-
-         iday= dayref+itau/iday_step
-         time=
-     s   float(itau-(iday-dayref)*iday_step)/iday_step+time_0
-         IF(time.GT.1.) THEN
-            time = time-1.
-            iday = iday+1
-         ENDIF
-
-
-
-C
-c=======================================================================
-         if(irec.ge.recstkmin.and.irec.le.recstkmax) then
-            if (mod(itau,4).eq.0) then
-            stoke='X'
-               do iq=1,nq
-                  write(str2,'(i2.2)') iq
-                  nom='q'//str2
-                  call wrgrads(1,1,q(:,:,:,iq),nom,nom)
-                  call wrgrads(2,1,q(:,:,ldec,iq),nom,nom)
-               enddo
-            endif
-         endif
-
-         print*,'Record=',irec,'   stoke=',stoke,
-     s      '      injecte=',injecte
-
-      enddo ! itau
-
-      CALL dynredem1("restart.nc",0.0,
-     .          vcov,ucov,teta,q,nq,masse,ps)
-
-c=======================================================================
-C fermeture des fichiers netcdf
-          CALL histclo
-C
- 300  FORMAT('1',/,15x,'run du pas',i7,2x,'au pas',i7,2x,
-     s 'c"est a dire dujour',i7,3x,'au jour',i7,/,/)
-
-      end
-C----------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/offlinenc.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/offlinenc.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/offlinenc.F	(revision 253)
@@ -0,0 +1,948 @@
+c
+c $Header$
+c
+      PROGRAM offlinenc
+      USE ioipsl
+      IMPLICIT NONE
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comdissnew.h"
+#include "comvert.h"
+#include "comgeom2.h"
+#include "logic.h"
+#include "temps.h"
+#include "control.h"
+#include "ener.h"
+#include "description.h"
+#include "serre.h"
+#include "tracstoke.h"
+      integer ngridmx,nbsrf
+      PARAMETER (ngridmx=iim*(jjm-1)+2,nbsrf=4)
+c-----------------------------------------------------------------------
+
+      INTEGER*4  iday ! jour julien
+      REAL       time ! Heure de la journee en fraction d'1 jour
+      REAL dtdyn,dtav
+      INTEGER iday_step
+
+      INTEGER         longcles
+      PARAMETER     ( longcles = 20 )
+      REAL  clesphy0( longcles )
+      logical clefinit
+
+c   variables dynamiques
+      REAL vcov(iip1,jjm,llm),ucov(iip1,jjp1,llm) ! vents covariants
+      REAL q(iip1,jjp1,llm,nqmx)               ! champs advectes
+	real qmoy(iip1,jjp1,nqmx)
+      REAL pks(iip1,jjp1)                      ! exner (f pour filtre)
+      REAL phis(iip1,jjp1)                     ! geopotentiel au sol
+      REAL phi(iip1,jjp1,llm)                  ! geopotentiel
+      REAL w(iip1,jjp1,llm)                    ! vitesse verticale
+C
+C   variables physiques
+      real zmfd(ngridmx,llm),zde_d(ngridmx,llm),zen_d(ngridmx,llm)
+      REAL qfi(ngridmx,llm,nqmx)               ! champs advectes
+      real zmfu(ngridmx,llm),zde_u(ngridmx,llm),zen_u(ngridmx,llm)
+	real t(ngridmx,llm)
+      real coefkz(ngridmx,llm)
+      real frac_impa(ngridmx,llm),frac_nucl(ngridmx,llm)
+      real pphis (ngridmx)
+      REAL airefi(ngridmx)
+      REAL latfi(ngridmx),lonfi(ngridmx) ! latitude et long pour chaque point
+      real yu1(ngridmx), yv1(ngridmx)
+      real ftsol(ngridmx,nbsrf),pctsrf(ngridmx,nbsrf)
+C
+      character*10 file
+c variables dynamiques intermediaire pour le transport
+      REAL pbaru(iip1,jjp1,llm),pbarv(iip1,jjm,llm) !flux de masse
+      REAL masse(iip1,jjp1,llm)
+      REAL massebx(iip1,jjp1,llm),masseby(iip1,jjm,llm)
+      REAL teta(iip1,jjp1,llm)
+      INTEGER itau,irec,nrec,ldec,itauav
+      integer recmin,recmax,recstkmin,recstkmax
+      character*1 injecte,stoke
+      character*10 nom
+
+	real tinj2,tinj1
+	integer iiinj
+      integer jour0,isplit,nsplit_dyn,nsplit_phy,nsplit
+      logical debut,lectstart,rnpb,lafin
+
+      EXTERNAL inidissip,iniconst,inifilr
+      EXTERNAL inigeom
+      EXTERNAL exner_hyb,pression
+      EXTERNAL defrun_new
+
+      REAL time_0 ! temps de debut de simulation (% journee)
+
+      character*2 str2
+      INTEGER iq,j,i,l,nq,mode
+      real paprs(ngridmx,llm+1),pplay(ngridmx,llm),tempfi(ngridmx,llm)
+      real p(iip1,jjp1,llmp1),pk(iip1,jjp1,llm)
+      real lon_stat(nqmx),lat_stat(nqmx),zlon,zlat
+      integer i_stat(nqmx),j_stat(nqmx)
+      real intensite(nqmx)
+      integer iqmin,iqmax
+      integer npasinject
+      data npasinject/1/
+      integer histid, histvid, histaveid
+      real time_step, t_wrt, t_ops
+      integer itime_step
+      character*80 dynhist_file, dynhistave_file
+
+      logical avant
+      logical debutphy,redecoupage
+      DATA debutphy/.true./
+
+      real unskap,pksurcp,smass(iip1,jjp1)
+      integer ig0,ii,jj,iii,ij
+
+      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
+      REAL ps(iip1,jjp1),pkf(ip1jmp1,llm) 
+
+	integer ntau, iinjec2,iij
+	real zttt
+c-----------------------------------------------------------------------
+c   Initialisations:
+c   ----------------
+      descript = 'Run GCM LMDZ'
+	tinj1=0.
+	tinj2=0.
+      rad = 6400000
+      omeg = 7.272205e-05
+      g = 9.8
+      kappa = 0.285716
+      daysec = 86400
+      cpp = 1004.70885
+
+Cmaf a verifier....
+      preff = 101325.
+      pa= 50000.
+C
+      print*,'PARAMETRES A ENTRER DANS offline.def'
+      print*,'Nombre effectif de traceurs'
+      read(*,*) nq
+      write(*,*) nq
+      print*,'Splitting du pas de temps dynamique'
+      read(*,*) nsplit_dyn
+      write(*,*) nsplit_dyn
+      print*,'Splitting du pas de temps physique'
+      read(*,*) nsplit_phy
+      write(*,*) nsplit_phy
+      print*,'jour0, par rapport au debut du fichier fluxmass'
+      read(*,*) jour0
+      write(*,*) jour0
+      print*,'redecoupage (T) ou standard (F)'
+      read(*,'(l1)') redecoupage
+      write(*,*) redecoupage
+      print*,'Lecture fichier start (T)?'
+      read(*,'(l1)') lectstart
+      write(*,'(l1)') lectstart
+      print*,'Traceurs 1 et 2 = Rn222 et Pb'
+      read(*,'(l1)') rnpb
+      write(*,'(l1)') rnpb
+      print*,'Avant T ou arriere F?'
+      read(*,'(l1)') avant
+      write(*,'(l1)') avant
+      print*,'Index min et max des traceurs a initaliser'
+      read(*,*) iqmin,iqmax
+      write(*,*) iqmin,iqmax
+      print*,'localisation (lon, lat, intensite)'
+
+      if(iqmax.le.0) then
+         iqmin=iqmax+1
+      endif
+
+      do iq=iqmin,iqmax
+         read(*,*) lon_stat(iq),lat_stat(iq),intensite(iq)
+         write(*,*) lon_stat(iq),lat_stat(iq),intensite(iq)
+      enddo
+
+      print*,'Records min et max pour le stokage et couche '
+     s    ,'verticale (specifique reseaux), def 0 0 1'
+      read(*,*) recstkmin,recstkmax,ldec
+      write(*,*) recstkmin,recstkmax,ldec
+
+c   redefinition du splitting
+
+      if(mod(nsplit_dyn,nsplit_phy).eq.0) then
+         nsplit=nsplit_phy
+      elseif (mod(nsplit_phy,nsplit_dyn).eq.0) then
+         nsplit=nsplit_dyn
+      else
+         stop'prendre un des deux nsplit doit diviser l autre'
+      endif
+
+      nsplit_dyn=nsplit_dyn/nsplit
+      nsplit_phy=nsplit_phy/nsplit
+
+      print*,'nsplit,nsplit_dyn,nsplit_phy'
+     s       ,nsplit,nsplit_dyn,nsplit_phy
+
+c   Lecture eventuelle 
+      time_0=0.
+      if(nq.gt.nqmx) stop'surdimensioner nqmx'
+      print*,'av initial0'
+      call initial0(nq*ijp1llm,q)
+      print*,'av lectstart'
+
+      if(lectstart) then
+         CALL dynetat0("start.nc",nq,vcov,ucov,
+     .              teta,q,masse,ps,phis, time_0)
+         print*,'Lecture du start'
+c  On zappe le radon et le plomb.
+         q(:,:,:,1)=q(:,:,:,3)
+         q(:,:,:,2)=q(:,:,:,4)
+c Initialisation d'un traceur ` 1 pour tester l'impact du lessivage.
+         q(:,:,:,3)=1.
+      else
+         day_ini=0
+         anne_ini=0
+      endif
+
+      day_end=day_ini+nday
+C      print*,'av defrun'
+c     open (99,file='run.def',status='old',form='formatted')
+      clefinit=.true.
+      CALL defrun_new( 99, clefinit, clesphy0 )
+c     close(99)
+C      print*,'av iniconst'
+c   lecture du jour de demarrage
+c    premiere cnitialisation, eventuellement bidon
+      cALL iniconst
+      CALL inigeom
+C
+      print*,'ENTREE DANS redecoupenc ou lectfluxnc
+     s        pour irec=0'
+
+c  Lecture des entetes des fichiers de flux
+
+      if(redecoupage) then
+         call redecoupenc(0,masse,pbaru,pbarv,w,teta,phi,
+     s     nrec,avant,airefi,pphis,
+     s     t,zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
+     s     yu1,yv1,ftsol,pctsrf,
+     s     frac_impa,frac_nucl,phis)
+      else
+         call lectfluxnc(0,masse,pbaru,pbarv,w,teta,phi,
+     s     nrec,avant,airefi,pphis,
+     s     t,zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
+     s     yu1,yv1,ftsol,pctsrf,
+     s     frac_impa,frac_nucl,phis)
+         call inigeom
+      endif
+
+c   controle sur les records
+
+      if(avant) then
+         recmin=2+(jour0-1)*iday_step
+         recmax=1+(jour0+nday-1)*iday_step
+      else
+         recmin=(jour0-nday)*iday_step+2
+         recmax=jour0*iday_step+1
+      endif
+
+      if(recmin.le.1.or.recmax.ge.nrec) then
+         print*,'Probleme de lecture '
+         print*,'recmin,recmax,nrec',recmin,recmax,nrec
+         stop
+      endif
+
+C on recalcule le nombre de pas de temps dans une journee
+c   istdyn est la frequence de stokage en "pas de temps dynamique" dans
+c   le modele on-line. dtvr est le pas de temps du meme modele en s.
+c iday-step est le nombre de lectures par jour (grand pas de temps). 
+
+      iday_step=daysec/(istdyn*dtvr)
+C
+      CALL iniconst
+c  on calcule le pas de temps 
+      dtvr    = daysec/FLOAT(iday_step)
+      dtphys=dtvr/(nsplit*nsplit_phy) ! a mettre apres iniconst!
+      print*,'Pas de temps physique ',dtphys
+C
+      call gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
+      print *,'Pas de temps dynamique', dtvr
+      print*,'Pas de temps physique ',dtphys
+
+c-----------------------------------------------------------------------
+
+C maf est ce utile ?
+      call suphec
+      CALL inifilr
+      print*,'Pas de temps physique ',dtphys
+      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
+     *                tetagdiv, tetagrot , tetatemp              )
+      print*,'Pas de temps physique ',dtphys
+
+c-----------------------------------------------------------------------
+c   temps de depart et de fin:
+c   --------------------------
+      itau = 0
+      iday = dayref
+      time = time_0
+         IF(time.GT.1.) THEN
+          time = time-1.
+          iday = iday+1
+         ENDIF
+      print*,'Pas de temps physique ',dtphys
+c=======================================================================
+c   Initialisation des fichiers de sortie
+c=======================================================================
+      print*,'Initialisation de wrgras'
+	do i=1,iip1
+	print*,'rlonu(',i,')=',rlonu(i)
+	enddo
+	do i=1,jjp1
+	print*,'rlatu(',i,')=',rlatu(i)
+	enddo
+        do i=1,iip1
+        print*,'rlonv(',i,')=',rlonv(i)
+        enddo
+        do i=1,jjm
+        print*,'rlatv(',i,')=',rlatv(i)
+        enddo
+
+      file='sol'
+      call inigrads(1,iip1
+     s  ,rlonv,180./pi,-180.,180.,jjp1,rlatu,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,dtphys,file,'gcmq2 ')
+
+      file='atm'
+      print*,'Pas de temps physique ',dtphys
+      call inigrads(2,iip1
+     s  ,rlonv,180./pi,-180.,180.,jjp1,rlatu,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,dtphys,file,'gcmq2 ')
+
+      file='pbu'
+      call inigrads(3,iip1
+     s  ,rlonu,180./pi,-180.,180.,jjp1,rlatu,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,dtphys,file,'gcmq2 ')
+
+      file='pbv'
+      call inigrads(4,iip1
+     s  ,rlonv,180./pi,-180.,180.,jjm,rlatv,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,dtphys,file,'gcmq2 ')
+
+      file='qadv'
+      call inigrads(5,iip1
+     s  ,rlonv,180./pi,-180.,180.,jjp1,rlatu,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,dtphys,file,'gcmq2 ')
+
+      print*,'dtphys ap inigrads ',dtphys
+
+      print*,'Ecriture du fichier de conditions aux limites'
+      open (98,file='limit',form='unformatted')
+      write(98) float(im),float(jm),float(nq),float(nday)
+      write(98) (rlonv(i)*180./pi,i=1,iip1)
+      write(98) (rlatu(j)*180./pi,j=1,jjp1)
+      write(98) ((phis(i,j)/g,i=1,iip1),j=1,jjp1)
+      close(98)
+
+      CALL dynredem0("restart.nc",day_end,anne_ini,phis,nq)
+
+c-----------------------------------------------------------------------
+c   Debut de la boucle en temps:
+c   ----------------------------
+
+      do itau=1,nday*iday_step
+          print*,'ITAU ITAU ITAU =',itau
+         injecte='.'
+         stoke='.'
+c Gestion du temps
+         if (avant) then
+            dtdyn=dtvr/float(nsplit*nsplit_dyn)
+c            irec=1+(jour0-1)*iday_step+itau
+	     irec=(jour0-1)*iday_step+itau
+         else
+            dtdyn=-dtvr/float(nsplit*nsplit_dyn)
+            irec=1+jour0*iday_step-itau+1
+         endif
+
+         debut=itau.eq.1
+
+c-----------------------------------------------------------------------
+c   Lecture des fichiers fluxmass et physique:
+c   -----------------------------------------------------
+         print*,'CCCCC Appel a REDECOUPENC ou LECTFLUXNC
+     s           au pas itau=',itau
+      if(redecoupage) then
+         call redecoupenc(irec,masse,pbaru,pbarv,w,teta,phi,
+     s     nrec,avant,airefi,pphis,
+     s     t,zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
+     s     yu1,yv1,ftsol,pctsrf, 
+     s     frac_impa,frac_nucl,phis)
+      else
+         call lectfluxnc(irec,masse,pbaru,pbarv,w,teta,phi,
+     s     nrec,avant,airefi,pphis,
+     s     t,zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
+     s     yu1,yv1,ftsol,pctsrf, 
+     s     frac_impa,frac_nucl,phis)
+      endif
+
+
+      print*,'TESTPHYS: ON PREND LA PUIS ',1./float(nsplit*nsplit_phy)
+     s   ,'  DES FRAC A IT=',itau
+      frac_impa(:,:)=frac_impa(:,:)**(1./float(nsplit*nsplit_phy))
+      frac_nucl(:,:)=frac_nucl(:,:)**(1./float(nsplit*nsplit_phy))
+c    ...  ouverture du fichier de stockage netcdf ...
+C
+      IF (debut) then
+         dynhistave_file = 'histmoy.nc'
+         day_ini=0
+         anne_ini=0
+         t_ops =(1./48.)*daysec
+         t_wrt =(1./48.)*daysec
+         dtav=dtvr/float(nsplit)
+         mode=1
+
+c        CALL initdynav(dynhistave_file,day_ini,anne_ini,dtav,
+c    .              t_ops, t_wrt, nq,mode, histaveid)
+
+         pi=2.*asin(1.)
+         do iq=iqmin,iqmax
+            do l=1,llm
+               do j=1,jjp1
+                  do i=1,iip1
+                     q(i,j,l,iq)=0.
+                  enddo
+               enddo
+            enddo
+
+            zlon=lon_stat(iq)*pi/180.
+            zlat=lat_stat(iq)*pi/180.
+
+            CALL coordij(zlon,zlat,i_stat(iq),j_stat(iq))
+
+         enddo
+      ENDIF
+
+C calcul de la pression de surface.
+
+      do j=1,jjp1
+         do i=1,iip1
+            smass(i,j)=0.
+         enddo
+      enddo
+
+      do l=1,llm
+        do j=1,jjp1
+          do i=1,iip1
+             smass(i,j)=smass(i,j)+masse(i,j,l)
+          enddo
+       enddo
+      enddo
+
+      do j=1,jjp1
+         do i=1,iip1
+            ps (i,j)=smass(i,j)/aire(i,j)*g
+         end do
+      end do
+C
+C calcul de la pression et de pk (fonction d'Exner)
+C
+      CALL pression ( ip1jmp1, ap, bp, ps, p       )
+      CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
+C
+      do jj=1,jjp1
+         do ii=1,iip1
+           phis(ii,jj)= phi(ii,jj,1)-teta(ii,jj,1)*
+     s                             (pks(ii,jj)-pk(ii,jj,1))
+         end do
+      end do
+c=======================================================================
+c   TERMES SOURCES OU PUITS
+         do isplit=1,nsplit
+c=======================================================================
+c injection par Fred
+c	Print*,Verifier en fct de iapp_tracvl la boucle inj
+       goto 333
+c Inj pour le stokage ttes les 0.5h
+        if (itau.gt.32.and.itau.le.56)then
+        print*,'Masse de la maille inj :',
+     s          masse(i_stat(1),j_stat(1),1)
+	do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (float(nsplit)*24.*20.)
+
+        tinj1=tinj1+intensite(1)/(float(nsplit)*24.*20.)
+	enddo
+
+           print*,'Apres injection a itau ',itau
+
+            do iq=1,nq
+               write(str2,'(i2.2)') iq
+              call diagadv(q(:,:,:,iq),masse,'Traceur '//str2)
+            enddo
+
+        print*,'QT TOTALE INJECTEE TR1',tinj1
+        print*,'fin des injections'
+
+        endif
+
+c Inj pour le stokage ttes les 1h
+
+        if (itau.gt.16.and.itau.le.28)then
+        print*,'Masse de la maille inj :',
+     s          masse(i_stat(1),j_stat(1),1)
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (float(nsplit)*12.*20.)
+
+        tinj1=tinj1+intensite(1)/(float(nsplit)*12.*20.)
+
+        enddo
+
+           print*,'Apres injection a itau ',itau
+
+            do iq=1,nq
+               write(str2,'(i2.2)') iq
+              call diagadv(q(:,:,:,iq),masse,'Traceur '//str2)
+            enddo
+
+        print*,'QT TOTALE INJECTEE TR1',tinj1
+        print*,'fin des injections'
+
+        endif
+
+c Inj pour le stokage ttes les 1.5h
+
+        if (itau.eq.11.and.isplit.gt.2)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.ge.12.and.itau.le.18)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.eq.19.and.isplit.le.2)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+
+        endif
+
+c Inj pour le stokage ttes les 4h
+
+        if (itau.ge.5.and.itau.le.7)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+c Inj pour le stokage ttes les 3h
+
+        if (itau.eq.6.and.isplit.gt.2)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.ge.7.and.itau.le.9)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.eq.10.and.isplit.le.2)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+c  Inj pour le stokage ttes les 6h
+
+        if (itau.eq.3.and.isplit.gt.8)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.eq.4)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.eq.5.and.isplit.le.8)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+c Inj sur les 4 1ere couches pour le stokage ttes les 3h
+
+        if (itau.eq.6.and.isplit.gt.2)then
+	do l=1,4
+        q(i_stat(1),j_stat(1),l,1)=
+     s      q(i_stat(1),j_stat(1),l,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),l)/
+     s   (24.*4.)
+	enddo
+        endif
+
+        if (itau.ge.7.and.itau.le.9)then
+	do l=1,4
+        q(i_stat(1),j_stat(1),l,1)=
+     s      q(i_stat(1),j_stat(1),l,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),l)/
+     s   (24.*4.)
+	enddo
+        endif
+
+        if (itau.eq.10.and.isplit.le.2)then
+        do l=1,4
+        q(i_stat(1),j_stat(1),l,1)=
+     s      q(i_stat(1),j_stat(1),l,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),l)/
+     s   (24.*4.)
+        enddo
+        endif
+
+c Inj pour le stokage ttes les 12h
+
+	if (itau.eq.2.and.isplit.gt.8)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.eq.3.and.isplit.le.8)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+c Inj pour le stokage ttes les 24h
+
+        if (itau.eq.1.and.isplit.gt.32)then
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/24.
+        endif
+
+        if (itau.eq.2.and.isplit.le.8)then
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/24.
+        endif     
+
+c Inj pour le stokage ttes les 3h
+
+        if (itau.eq.6.and.isplit.gt.2)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.ge.7.and.itau.le.9)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+        if (itau.eq.10.and.isplit.le.2)then
+        do iiinj=1,20
+        q(i_stat(1),j_stat(1),1,1)=
+     s      q(i_stat(1),j_stat(1),1,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),1)/
+     s   (24.*20.)
+        enddo
+        endif
+
+333     continue
+
+        if (itau.eq.6.and.isplit.gt.2)then
+
+        do l=1,2
+        q(i_stat(1),j_stat(1),l,1)=
+     s      q(i_stat(1),j_stat(1),l,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),l)/
+     s   (24.*2.)
+        enddo
+        endif
+
+        if (itau.ge.7.and.itau.le.9)then
+        do l=1,2
+        q(i_stat(1),j_stat(1),l,1)=
+     s      q(i_stat(1),j_stat(1),l,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),l)/
+     s   (24.*2.)
+        enddo
+        endif
+
+        if (itau.eq.10.and.isplit.le.2)then
+        do l=1,2
+        q(i_stat(1),j_stat(1),l,1)=
+     s      q(i_stat(1),j_stat(1),l,1)
+     s  +intensite(1)/masse(i_stat(1),j_stat(1),l)/
+     s   (24.*2.)
+        enddo
+        endif
+
+c=======================================================================
+c   FIN DE LA PARTIE TERMES SOURCES
+c=======================================================================
+c-----------------------------------------------------------------------
+c   Advection
+c   ----------
+	print*,'ENTREE DANS VLSPLT'
+c=======================================================================
+c         do isplit=1,nsplit
+c=======================================================================
+CC MAF dans le cas du offline on ne fait pas la difference masse et massem
+            do iii=1,nsplit_dyn
+		  nom='pbaru'
+                  call wrgrads(3,llm,pbaru(:,:,1),nom,nom)
+                  nom='pbarv'
+                  call wrgrads(4,llm,pbarv(:,:,1),nom,nom)
+                  nom='masse'
+                  call wrgrads(3,llm,masse(:,:,1),nom,nom)
+                  nom='w'
+                  call wrgrads(3,llm,w(:,:,1),nom,nom)
+           print*,'Entree dans vlsplt a itau et au temps',itau,time
+	   print*,'Pas advect :',dtdyn
+           print*,'Avant vlsplt'
+            do iq=1,nq
+               write(str2,'(i2.2)') iq
+              call diagadv(q(:,:,:,iq),masse,'Traceur '//str2)
+            enddo
+               do iq=1,nq
+ctest abder   CALL vlsplt(q(1,1,1,iq),2.,masse,w,pbaru,pbarv,dtdyn)
+              CALL vlsplt(q(:,:,:,iq),2.,masse,w,pbaru,pbarv,dtdyn)
+               enddo
+
+               do iq=iqmin,iqmax
+                  write(str2,'(i2.2)') iq
+                  nom='q'//str2
+                  call wrgrads(5,1,q(:,:,1,iq),nom,nom)
+               enddo
+            print*,'Apres vlsplt'
+            do iq=1,nq
+               write(str2,'(i2.2)') iq
+              call diagadv(q(:,:,:,iq),masse,'Traceur '//str2)
+            enddo
+
+c   mise a jour du champ de masse tenant compte de l'advection sur
+c   le pas de temps considere.
+
+            enddo
+
+c-----------------------------------------------------------------------
+c   Physique  (lessivage dans phytrac maintenant) MAF
+c   ---------------------------------------------------------
+        if(physic) then
+         if(debut) then
+         latfi(1)=rlatu(1)*180./pi
+         lonfi(1)=0.
+         DO j=2,jjm
+            DO i=1,iim
+               latfi((j-2)*iim+1+i)= rlatu(j)*180./pi
+               lonfi((j-2)*iim+1+i)= rlonv(i)*180./pi
+            ENDDO
+         ENDDO
+         latfi(ngridmx)= rlatu(jjp1)*180./pi
+         lonfi(ngridmx)= 0.
+         endif
+c
+C Calcul de paprs et pplay et de temp
+c   -----------------------------------------------------------------
+c     .... paprs  definis aux (llm +1) interfaces des couches  ....
+c     .... pplay  definis aux (  llm )    milieux des couches  ....
+c   -----------------------------------------------------------------
+C
+      DO l = 1, llmp1
+        paprs( 1,l ) = p(1,1,l)
+        ig0 = 2
+          DO j = 2, jjm
+             DO i =1, iim
+              paprs( ig0,l ) = p(i,j,l)
+              ig0 = ig0 +1
+             ENDDO
+          ENDDO
+        paprs( ngridmx,l ) = p(1,jjp1,l)
+      ENDDO
+c
+      unskap   = 1./ kappa
+      DO l=1,llm
+         pksurcp     =  pk(1,1,l) / cpp
+         pplay(1,l)  =  preff * pksurcp ** unskap
+         tempfi(1,l)   =  teta(1,1,l) *  pksurcp
+         ig0         = 2
+         DO j = 2, jjm
+            DO i = 1, iim
+              pksurcp        = pk(i,j,l) / cpp
+              pplay(ig0,l)   = preff * pksurcp ** unskap
+              tempfi(ig0,l)    = teta(i,j,l)  * pksurcp
+              ig0            = ig0 + 1
+            ENDDO
+         ENDDO
+         pksurcp       = pk(1,jjp1,l) / cpp
+         pplay(ig0,l)  = preff * pksurcp ** unskap
+         tempfi (ig0,l)  = teta(1,jjp1,l)  * pksurcp
+      ENDDO
+
+c On passe le traceur et le geopot de surf  sur la grille physique
+             call gr_dyn_fi(llm*nq,iip1,jjp1,ngridmx,q,qfi)
+c             call gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,pphis)
+             do iii=1,nsplit_phy
+C
+      lafin=.false. ! en attendant mieux.
+      print*,'dtphys avant phytrac ',dtphys
+      print*,'TESTPHYS: APPEL A PHYTRAC IT=',itau
+
+             call phytrac(rnpb,
+     I                   debutphy, lafin,
+     I                   nq,
+     I                   ngridmx,llm,dtphys,
+     I                   t,paprs,pplay,
+     I                   zmfu, zmfd, zen_u, zde_u, zen_d, zde_d,
+     I                   coefkz,yu1,yv1,ftsol,pctsrf,latfi,
+     I                   frac_impa, frac_nucl,
+     I                   lonfi,presnivs,airefi,pphis,
+     O                   qfi)
+C
+             debutphy= .FALSE.
+C
+             enddo ! nsplit_phy
+C
+c   On passe le traceur sur la grille dynamique.
+             call gr_fi_dyn(llm*nq,ngridmx,iip1,jjp1,qfi,q)
+
+             endif
+
+             itauav=(itau-1)*nsplit+isplit
+c             itauav=itau*nsplit+isplit
+c            CALL writedynav(histaveid, nq,mode, itauav,vcov ,
+c    ,                   ucov,teta,pk,phi,q,masse,ps,phis)
+c            qmoy(:,:,:)=qmoy(:,:,:)+q(:,:,1,:)
+         do iq=1,nq
+            do j=1,jjp1
+               do i=1,iip1
+                  qmoy(i,j,iq)=qmoy(i,j,iq)+q(i,j,1,iq)
+               enddo
+            enddo
+         enddo
+         enddo ! isplit=1,nsplit
+
+         call histsync
+
+c-----------------------------------------------------------------------
+c    Calcul de ucov et vcov pour les sorties
+c   -------------------------------------
+
+         call massbar(masse, massebx, masseby )
+         do l=1,llm
+            do j=1,jjp1
+               do i=1,iip1
+               ucov(i,j,l)=pbaru(i,j,l)/massebx(i,j,l)*cu(i,j)*cu(i,j)
+     s         /istdyn
+               enddo
+            enddo
+
+            do j=1,jjm
+               do i=1,iip1
+               vcov(i,j,l)=pbarv(i,j,l)/masseby(i,j,l)*cv(i,j)*cv(i,j)
+     s         /istdyn
+               enddo
+            enddo
+         enddo
+         iday= dayref+itau/iday_step
+         time=
+     s   float(itau-(iday-dayref)*iday_step)/iday_step+time_0
+         IF(time.GT.1.) THEN
+            time = time-1.
+            iday = iday+1
+         ENDIF
+C
+c=======================================================================
+               do iq=iqmin,iqmax
+                  write(str2,'(i2.2)') iq
+                  nom='q'//str2
+                  call wrgrads(1,1,qmoy(:,:,iq),nom,nom)
+                  call wrgrads(2,1,q(:,:,ldec,iq),nom,nom)
+               enddo
+
+         do iq=1,nq
+            do j=1,jjp1
+               do i=1,iip1
+                  qmoy(i,j,iq)=0.
+               enddo
+            enddo
+         enddo
+
+         print*,'Record=',irec,'   stoke=',stoke,
+     s      '      injecte=',injecte
+
+      enddo ! itau
+
+      CALL dynredem1("restart.nc",0.0,
+     .          vcov,ucov,teta,q,nq,masse,ps)
+
+c=======================================================================
+C fermeture des fichiers netcdf
+          CALL histclo
+C
+ 300  FORMAT('1',/,15x,'run du pas',i7,2x,'au pas',i7,2x,
+     s 'c"est a dire du jour',i7,3x,'au jour',i7,/,/)
+C----------------------------------------------------------------------
+
+      stop
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/paramet.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/paramet.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/paramet.h	(revision 253)
@@ -7,5 +7,6 @@
       INTEGER jcfil,jcfllm
 
-      PARAMETER( iip1= iim+1, iip2= iim+2, iip3= iim+3, jjp1= jjm+1 )
+      PARAMETER( iip1= iim+1-1/iim,iip2=iim+2,iip3=iim+3
+     s    ,jjp1=jjm+1-1/jjm)
       PARAMETER( llmp1 = llm+1,  llmp2 = llm+2, llmm1 = llm-1 )
       PARAMETER( kftd  = iim/2 -ndm )
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/physdem.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/physdem.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/physdem.F	(revision 253)
@@ -41,8 +41,8 @@
 c Ajout de quelques parametres orographiques (F. LOTT janvier 1995)
 
-      REAL zmea(iip1,jjp1),zstd(iip1,jjp1)
-      REAL zsig(iip1,jjp1),zgam(iip1,jjp1),zthe(iip1,jjp1)
-      REAL zpic(iip1,jjp1),zval(iip1,jjp1)
-      REAL rugsrel(iip1,jjp1)
+      REAL zmea(klon),zstd(klon)
+      REAL zsig(klon),zgam(klon),zthe(klon)
+      REAL zpic(klon),zval(klon)
+      REAL rugsrel(klon)
       INTEGER idayref,anneeref
 
@@ -56,5 +56,4 @@
       REAL solaire
       REAL latfi(klon), lonfi(klon)
-      REAL champhys(klon)
       REAL ts(klon)
       REAL deltat(klon)
@@ -280,5 +279,4 @@
 #endif
 c
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zmea, champhys)
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -289,10 +287,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-c
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zstd, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zmea)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zmea)
+#endif
+c
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -303,10 +300,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zsig, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zstd)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zstd)
+#endif
+
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -317,10 +313,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zgam, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zsig)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zsig)
+#endif
+
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -331,10 +326,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zthe, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zgam)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zgam)
+#endif
+
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -345,10 +339,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zpic, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zthe)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zthe)
+#endif
+
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -359,10 +352,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, zval, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zpic)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zpic)
+#endif
+
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -373,10 +365,9 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
-#endif
-
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, rugsrel, champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zval)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zval)
+#endif
+
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
@@ -387,7 +378,7 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rugsrel)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,rugsrel)
 #endif
 c
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/pres2lev.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/pres2lev.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/pres2lev.F	(revision 253)
@@ -0,0 +1,77 @@
+c $Header$
+c******************************************************
+      SUBROUTINE   pres2lev(varo,varn,lmo,lmn,po,pn,
+     %                      ni,nj)
+c
+c interpolation lineaire pour passer
+c a une nouvelle discretisation verticale pour
+c les variables de GCM
+c Francois Forget (01/1995)
+c 
+c MOdif remy roca 12/97 pour passer de pres2sig
+c**********************************************************
+
+      IMPLICIT NONE
+
+c   Declarations:
+c ==============
+c
+c  ARGUMENTS
+c  """""""""
+
+       INTEGER lmo ! dimensions ancienne couches (input)
+       INTEGER lmn ! dimensions nouvelle couches (input)
+       INTEGER lmomx ! dimensions ancienne couches (input)
+       INTEGER lmnmx ! dimensions nouvelle couches (input)
+
+       parameter(lmomx=10000,lmnmx=10000)
+
+        real po(lmo)! niveau de pression en millibars
+        real pn(ni,nj,lmn) ! niveau de pression en pascals
+
+       INTEGER i,j,Nhoriz,ni,nj ! nombre de point horizontale (input)
+
+       REAL varo(ni,nj,lmo) ! var dans l'ancienne grille (input)
+       REAL varn(ni,nj,lmn) ! var dans la nouvelle grille (output)
+
+       real zvaro(lmomx),zpo(lmomx)
+
+c Autres variables
+c """"""""""""""""
+       INTEGER n, ln ,lo 
+       REAL coef
+
+c run
+c ====
+        do i=1,ni
+        do j=1,nj
+c a chaque point de grille correspond un nouveau sigma old
+c qui vaut pres(l)/ps(i,j)
+           do lo=1,lmo
+              zpo(lo)=po(lmo+1-lo)
+              zvaro(lo)=varo(i,j,lmo+1-lo)
+           enddo
+        
+           do ln=1,lmn
+              if (pn(i,j,ln).ge.zpo(1))then
+                 varn(i,j,ln) =  zvaro(1)
+              else if (pn(i,j,ln).le.zpo(lmo)) then
+                 varn(i,j,ln) =  zvaro(lmo)
+              else
+                 do lo=1,lmo-1 
+                    if ( (pn(i,j,ln).le.zpo(lo)).and.
+     &                 (pn(i,j,ln).gt.zpo(lo+1)) )then
+                       coef=(pn(i,j,ln)-zpo(lo))
+     &                 /(zpo(lo+1)-zpo(lo))
+                       varn(i,j,ln)=zvaro(lo)
+     &                 +coef*(zvaro(lo+1)-zvaro(lo))
+c       print*,'pn(',ln,')=',pn(i,j,ln),varn(i,j,ln)
+                    end if
+                 enddo           
+              endif
+           enddo
+
+        enddo
+        enddo
+      return
+      end    
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_dstoke.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_dstoke.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_dstoke.F	(revision 253)
@@ -0,0 +1,78 @@
+c $Header$
+            subroutine read_dstoke(irec,zdtvr,ziadvtrac,ziadvtrac2)
+
+
+            IMPLICIT NONE
+
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom.h"
+#include "comvert.h"
+
+	
+	integer ncidfd
+        save ncidfd
+        integer variddt,varididvt,varididvp
+        save variddt,varididvt,varididvp
+        real*4 dtv(1,1,1),adv2(1,1,1),adv(1,1,1)
+        real zdtvr,ziadvtrac,ziadvtrac2
+        integer status,irec
+        real rcode
+        INTEGER epais(2), debut(2)
+	
+	if (irec .eq. 0) then
+	
+	ncidfd=NCOPN('defstoke.nc',NCNOWRIT,rcode)
+
+        variddt=NCVID(ncidfd,'dtvr',rcode)
+        print*,'ncidfd,variddt',ncidfd,variddt
+
+        varididvt=NCVID(ncidfd,'istdyn',rcode)
+        print*,'ncidfd,varididvt',ncidfd,varididvt
+	
+	varididvp=NCVID(ncidfd,'istphy',rcode)
+        print*,'ncidfd,varididvp',ncidfd,varididvp
+
+c lecture de zdtvr et ziadvtrac
+	
+	epais(1) = 1
+        epais(2) = 1
+        debut(1) = 1
+        debut(2) = 1
+
+#ifdef NC_DOUBLE
+        status=NF_GET_VARA_DOUBLE(ncidfd,variddt,debut,epais,dtv)
+#else
+        status=NF_GET_VARA_REAL(ncidfd,variddt,debut,epais,dtv)
+#endif
+        zdtvr=dtv(1,1,1)
+
+#ifdef NC_DOUBLE
+        status=NF_GET_VARA_DOUBLE(ncidfd,varididvt,debut,epais,adv)
+#else
+        status=NF_GET_VARA_REAL(ncidfd,varididvt,debut,epais,adv)
+#endif
+        ziadvtrac= adv(1,1,1)
+	
+#ifdef NC_DOUBLE
+	status=NF_GET_VARA_DOUBLE(ncidfd,varididvp,debut,epais,adv2)
+#else
+	status=NF_GET_VARA_REAL(ncidfd,varididvp,debut,epais,adv2)
+#endif
+        ziadvtrac2= adv2(1,1,1)
+
+        write(*,*) 'ds read_dstoke zdtvr = ', zdtvr
+        write(*,*) 'ds read_dstoke ziadvtrac = ', ziadvtrac
+        write(*,*) 'ds read_dstoke ziadvtrac2 = ', ziadvtrac2
+	
+c           status=NF_CLOSE(ncidfd)
+
+        else
+            stop'Pas bon irec ne 0'
+	endif
+	
+	return
+
+	end
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_fstoke.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_fstoke.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_fstoke.F	(revision 253)
@@ -0,0 +1,297 @@
+c $Header$
+	subroutine read_fstoke(irec,
+     . zrec,zim,zjm,zlm,rlonu_dy,rlonv_dy,rlatu_dy,rlatv_dy,
+     . airedy,phis,
+     . masse,pbaru,pbarv,w,teta,phi)
+
+	IMPLICIT NONE
+
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom.h"
+#include "comvert.h"
+	
+      integer nlevnc,irec
+      parameter (nlevnc=19)
+      integer mode,l
+
+	integer imo,jmo,imo1,jmo1,imn,jmn
+	parameter (imn=iim,jmn=jjm,imo=imn/2,jmo=(jmn+1)/2)
+        parameter (imo1=imo+1,jmo1=jmo+1)
+
+      real*4 pbaru(imo1,jmo1,llm),pbarv(imo1,jmo,llm)
+      real*4 teta(imo1,jmo1,llm),phis(imo1,jmo1),phi(imo1,jmo1,llm)
+      real*4 masse(imo1,jmo1,llm),w(imo1,jmo1,llm)
+      real*4 airedy(imo1,jmo1)
+      real*4 rlonu_dy(imo1,jmo1),rlonv_dy(imo1,jmo),
+     . rlatu_dy(imo1,jmo1),rlatv_dy(imo1,jmo)
+      integer*4 ncrec,ncim,ncjm,nclm
+      integer*4 zrec,zim,zjm,zlm
+      integer*4 xid,yid,zid,tid
+      real*4 zdtvr,ziadvtrac
+      real adv(1), dtv(1)
+
+      integer ncidf,ncidfv
+      integer varidpu,varidpv,varidt,varidw,varidps,varidph,varidai
+      integer varidpl,varidm
+      integer varidnlo,varidnla,varidnlov,varidnlav
+      save ncidf,ncidfv
+      save varidpu,varidpv,varidt,varidw,varidps,varidph,varidai
+      save varidpl,varidm
+      save varidnlo,varidnla,varidnlov,varidnlav
+
+      real*4 pl(nlevnc)
+
+      integer start(4),count(4),status
+
+      real rcode
+	
+      character namedim	
+	
+c ---------------------------------------------
+c   Initialisation de la lecture des fichiers
+c ---------------------------------------------
+
+      if (irec .eq. 0) then
+
+            ncidf=NCOPN('fluxstoke.nc',NCNOWRIT,rcode)
+
+            varidps=NCVID(ncidf,'phis',rcode)
+            print*,'ncidf,varidps',ncidf,varidps
+
+            varidpl=NCVID(ncidf,'sig_s',rcode)
+            print*,'ncidf,varidpl',ncidf,varidpl
+	
+	    varidnlo=NCVID(ncidf,'nav_lon',rcode)
+            print*,'ncidf,varidnlo',ncidf,varidnlo
+          
+            varidnla=NCVID(ncidf,'nav_lat',rcode)
+            print*,'ncidf,varidnla',ncidf,varidnla
+	
+            varidai=NCVID(ncidf,'aire',rcode)
+            print*,'ncidf,varidai',ncidf,varidai
+         
+            varidm=NCVID(ncidf,'masse',rcode)
+            print*,'ncidf,varidm',ncidf,varidm
+
+            varidpu=NCVID(ncidf,'pbaru',rcode)
+            print*,'ncidf,varidpu',ncidf,varidpu
+		
+            varidw=NCVID(ncidf,'w',rcode)
+            print*,'ncidf,varidw',ncidf,varidw
+	
+	    varidt=NCVID(ncidf,'teta',rcode)
+            print*,'ncidf,varidt',ncidf,varidt
+ 
+	    varidph=NCVID(ncidf,'phi',rcode)
+            print*,'ncidf,varidph',ncidf,varidph
+	
+	    ncidfv=NCOPN('fluxstokev.nc',NCNOWRIT,rcode)
+
+            varidpv=NCVID(ncidfv,'pbarv',rcode)
+            print*,'ncidfv,varidpv',ncidfv,varidpv
+	
+	    varidnlov=NCVID(ncidfv,'nav_lon',rcode)
+            print*,'ncidf,varidnlov',ncidf,varidnlov
+          
+            varidnlav=NCVID(ncidfv,'nav_lat',rcode)
+            print*,'ncidfv,varidnlav',ncidfv,varidnlav
+	
+
+c ID pour les dimensions
+	
+	    status = nf_inq_dimid(ncidf,'y',yid)
+            status = nf_inq_dimid(ncidf,'x',xid)
+            status = nf_inq_dimid(ncidf,'sig_s',zid) 
+            status = nf_inq_dimid(ncidf,'time_counter',tid)
+
+c lecture des dimensions
+	
+	    status = nf_inq_dim(ncidf,yid,namedim,ncjm)
+            status = nf_inq_dim(ncidf,xid,namedim,ncim)
+            status = nf_inq_dim(ncidf,zid,namedim,nclm)
+            status = nf_inq_dim(ncidf,tid,namedim,ncrec)
+	
+	    zjm=ncjm
+            zim=ncim
+            zlm=nclm
+            zrec=ncrec
+	
+	    write(*,*) 'read_fstoke : zrec = ', zrec
+            write(*,*) 'read_fstoke : zlm = ', zlm
+            write(*,*) 'read_fstoke : zim = ', zim
+            write(*,*) 'read_fstoke : zjm = ', zjm
+
+c niveaux de pression
+        
+#ifdef NC_DOUBLE
+       status=NF_GET_VARA_DOUBLE(ncidf,varidpl,1,zlm,pl)
+#else
+       status=NF_GET_VARA_REAL(ncidf,varidpl,1,zlm,pl)
+#endif
+
+c rlonu,rlonv,rlatu,rlatv
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+	
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidnlo,start,count,rlonu_dy)
+      status=NF_GET_VARA_DOUBLE(ncidf,varidnla,start,count,rlatu_dy)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidnlo,start,count,rlonu_dy)
+      status=NF_GET_VARA_REAL(ncidf,varidnla,start,count,rlatu_dy)
+#endif
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm-1
+      count(3)=1
+      count(4)=0
+
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidfv,varidnlov,start,count,rlonv_dy)
+      status=NF_GET_VARA_DOUBLE(ncidfv,varidnlav,start,count,rlatv_dy)
+#else
+      status=NF_GET_VARA_REAL(ncidfv,varidnlov,start,count,rlonv_dy)
+      status=NF_GET_VARA_REAL(ncidfv,varidnlav,start,count,rlatv_dy)
+#endif
+
+c Lecture de phis et aire
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+
+c phis
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidps,start,count,phis)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidps,start,count,phis)
+#endif
+
+c aire
+#ifdef NC_DOUBLE
+       status=NF_GET_VARA_DOUBLE(ncidf,varidai,start,count,airedy)
+#else
+       status=NF_GET_VARA_REAL(ncidf,varidai,start,count,airedy)
+#endif
+
+       else 
+
+      print*,'ok1'
+
+c ---------------------
+c   lecture des champs 
+c ---------------------
+
+      print*,'WARNING!!! Il n y a pas de test de coherence'
+      print*,'sur le nombre de niveaux verticaux dans le fichier nc'
+
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=irec
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=zlm
+      count(4)=1
+
+c masse 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidm,start,count,masse)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidm,start,count,masse)
+#endif
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jmo1*nlevnc,masse)
+	print*,'***********Lecture MASSE '
+       call dump2d(imo1,jmo1,masse,'MASSE COUCHE 1')
+c pbaru 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidpu,start,count,pbaru)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidpu,start,count,pbaru)
+#endif
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jmo1*nlevnc,pbaru)
+c      call dump2d(imo1,jmo1,pbaru,'PBARUNC COUCHE 1')
+
+c w 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidw,start,count,w)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidw,start,count,w)
+#endif
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jmo1*nlevnc,w)
+c      call dump2d(imo1,jmo1,w,'WNC COUCHE 1')
+
+c teta 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidt,start,count,teta)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidt,start,count,teta)
+#endif
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jmo1*nlevnc,teta)
+c      call dump2d(imo1,jmo1,teta,'TETANC COUCHE 1')
+
+c phi 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidph,start,count,phi)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidph,start,count,phi)
+#endif
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jmo1*nlevnc,phi)
+c      call dump2d(imo1,jmo1,phi,'PHINC COUCHE 1')
+	
+	count(2) = zjm-1 
+
+c  pbarv
+	print*,'Lecture de pbarv irec=',irec
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidfv,varidpv,start,count,pbarv)
+#else
+      status=NF_GET_VARA_REAL(ncidfv,varidpv,start,count,pbarv)
+#endif
+c      call correctbid(iim,jjm*nlevnc,pbarv)
+	PRINT*,'*******LECTURE DE PBARV******'
+      call dump2d(imo1,jjm,pbarv,'PBARVNC COUCHE 1')
+	print*,'Ok Lecture de pbarv irec=',irec
+      start(3)=irec
+      start(4)=0
+      count(2)=jmo1
+      count(3)=1
+      count(4)=0
+
+	endif
+	print*,'Fin read_fstoke a irec=',irec
+      return
+      end
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_fstoke0.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_fstoke0.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_fstoke0.F	(revision 253)
@@ -0,0 +1,269 @@
+c $Header$
+	subroutine read_fstoke0(irec,
+     . zrec,zim,zjm,zlm,rlonu_dy,rlonv_dy,rlatu_dy,rlatv_dy,
+     . airedy,phis,
+     . masse,pbaru,pbarv,w,teta,phi)
+
+	IMPLICIT NONE
+
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom.h"
+#include "comvert.h"
+	
+      integer nlevnc,irec
+      parameter (nlevnc=19)
+      integer mode,l
+
+      real*4 pbaru(iip1,jjp1,llm),pbarv(iip1,jjm,llm)
+      real*4 teta(iip1,jjp1,llm),phis(iip1,jjp1),phi(iip1,jjp1,llm)
+      real*4 masse(iip1,jjp1,llm),w(iip1,jjp1,llm)
+      real*4 airedy(iip1,jjp1)
+      real*4 rlonu_dy(iip1,jjp1),rlonv_dy(iip1,jjm),
+     . rlatu_dy(iip1,jjp1),rlatv_dy(iip1,jjm)
+      integer*4 ncrec,ncim,ncjm,nclm
+      integer*4 zrec,zim,zjm,zlm
+      integer*4 xid,yid,zid,tid
+      real*4 zdtvr,ziadvtrac
+      real adv(1), dtv(1)
+
+      integer ncidf,ncidfv
+      integer varidpu,varidpv,varidt,varidw,varidps,varidph,varidai
+      integer varidpl,varidm
+      integer varidnlo,varidnla,varidnlov,varidnlav
+      save ncidf,ncidfv
+      save varidpu,varidpv,varidt,varidw,varidps,varidph,varidai
+      save varidpl,varidm
+      save varidnlo,varidnla,varidnlov,varidnlav
+
+      real*4 pl(nlevnc)
+
+      integer start(4),count(4),status
+
+      real rcode
+	
+      character namedim	
+	
+c ---------------------------------------------
+c   Initialisation de la lecture des fichiers
+c ---------------------------------------------
+
+      if (irec .eq. 0) then
+
+            ncidf=NCOPN('fluxstoke.nc',NCNOWRIT,rcode)
+
+            varidps=NCVID(ncidf,'phis',rcode)
+            print*,'ncidf,varidps',ncidf,varidps
+
+            varidpl=NCVID(ncidf,'sig_s',rcode)
+            print*,'ncidf,varidpl',ncidf,varidpl
+	
+	    varidnlo=NCVID(ncidf,'nav_lon',rcode)
+            print*,'ncidf,varidnlo',ncidf,varidnlo
+          
+            varidnla=NCVID(ncidf,'nav_lat',rcode)
+            print*,'ncidf,varidnla',ncidf,varidnla
+	
+            varidai=NCVID(ncidf,'aire',rcode)
+            print*,'ncidf,varidai',ncidf,varidai
+         
+            varidm=NCVID(ncidf,'masse',rcode)
+            print*,'ncidf,varidm',ncidf,varidm
+
+            varidpu=NCVID(ncidf,'pbaru',rcode)
+            print*,'ncidf,varidpu',ncidf,varidpu
+		
+            varidw=NCVID(ncidf,'w',rcode)
+            print*,'ncidf,varidw',ncidf,varidw
+	
+	    varidt=NCVID(ncidf,'teta',rcode)
+            print*,'ncidf,varidt',ncidf,varidt
+ 
+	    varidph=NCVID(ncidf,'phi',rcode)
+            print*,'ncidf,varidph',ncidf,varidph
+	
+	    ncidfv=NCOPN('fluxstokev.nc',NCNOWRIT,rcode)
+
+            varidpv=NCVID(ncidfv,'pbarv',rcode)
+            print*,'ncidfv,varidpv',ncidfv,varidpv
+	
+	    varidnlov=NCVID(ncidfv,'nav_lon',rcode)
+            print*,'ncidf,varidnlov',ncidf,varidnlov
+          
+            varidnlav=NCVID(ncidfv,'nav_lat',rcode)
+            print*,'ncidfv,varidnlav',ncidfv,varidnlav
+	
+
+c ID pour les dimensions
+	
+	    status = nf_inq_dimid(ncidf,'y',yid)
+            status = nf_inq_dimid(ncidf,'x',xid)
+            status = nf_inq_dimid(ncidf,'sig_s',zid) 
+            status = nf_inq_dimid(ncidf,'time_counter',tid)
+
+c lecture des dimensions
+	
+	    status = nf_inq_dim(ncidf,yid,namedim,ncjm)
+            status = nf_inq_dim(ncidf,xid,namedim,ncim)
+            status = nf_inq_dim(ncidf,zid,namedim,nclm)
+            status = nf_inq_dim(ncidf,tid,namedim,ncrec)
+	
+	    zjm=ncjm
+            zim=ncim
+            zlm=nclm
+            zrec=ncrec
+	
+	    write(*,*) 'read_fstoke : zrec = ', zrec
+            write(*,*) 'read_fstoke : zlm = ', zlm
+            write(*,*) 'read_fstoke : zim = ', zim
+            write(*,*) 'read_fstoke : zjm = ', zjm
+
+c niveaux de pression
+        
+#ifdef NC_DOUBLE
+       status=NF_GET_VARA_DOUBLE(ncidf,varidpl,1,zlm,pl)
+#else
+       status=NF_GET_VARA_REAL(ncidf,varidpl,1,zlm,pl)
+#endif
+
+c rlonu,rlonv,rlatu,rlatv
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+	
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidnlo,start,count,rlonu_dy)
+      status=NF_GET_VARA_DOUBLE(ncidf,varidnla,start,count,rlatu_dy)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidnlo,start,count,rlonu_dy)
+      status=NF_GET_VARA_REAL(ncidf,varidnla,start,count,rlatu_dy)
+#endif
+
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm-1
+      count(3)=1
+      count(4)=0
+
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidfv,varidnlov,start,count,rlonv_dy)
+      status=NF_GET_VARA_DOUBLE(ncidfv,varidnlav,start,count,rlatv_dy)
+#else
+      status=NF_GET_VARA_REAL(ncidfv,varidnlov,start,count,rlonv_dy)
+      status=NF_GET_VARA_REAL(ncidfv,varidnlav,start,count,rlatv_dy)
+#endif
+
+c Lecture de phis et aire
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+
+c phis
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidps,start,count,phis)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidps,start,count,phis)
+#endif
+
+c aire
+#ifdef NC_DOUBLE
+       status=NF_GET_VARA_DOUBLE(ncidf,varidai,start,count,airedy)
+#else
+       status=NF_GET_VARA_REAL(ncidf,varidai,start,count,airedy)
+#endif
+
+       else 
+
+      print*,'ok1'
+
+c ---------------------
+c   lecture des champs 
+c ---------------------
+
+      print*,'WARNING!!! Il n y a pas de test de coherence'
+      print*,'sur le nombre de niveaux verticaux dans le fichier nc'
+
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=irec
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=zlm
+      count(4)=1
+
+c masse 
+	PRINT*,'LECTURE DE masse'
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidm,start,count,masse)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidm,start,count,masse)
+#endif
+
+c pbaru 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidpu,start,count,pbaru)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidpu,start,count,pbaru)
+#endif
+
+c w 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidw,start,count,w)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidw,start,count,w)
+#endif
+
+c teta 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidt,start,count,teta)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidt,start,count,teta)
+#endif
+
+c phi 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidf,varidph,start,count,phi)
+#else
+      status=NF_GET_VARA_REAL(ncidf,varidph,start,count,phi)
+#endif
+	
+	count(2) = zjm-1 
+
+c  pbarv
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidfv,varidpv,start,count,pbarv)
+#else
+      status=NF_GET_VARA_REAL(ncidfv,varidpv,start,count,pbarv)
+#endif
+
+      start(3)=irec
+      start(4)=0
+      count(2)=jjp1
+      count(3)=1
+      count(4)=0
+
+	endif
+
+      return
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_pstoke.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_pstoke.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_pstoke.F	(revision 253)
@@ -0,0 +1,456 @@
+	subroutine read_pstoke0(irec,
+     .   zrec,zkon,zkev,airefi,phisfi,
+     .   t,mfu,mfd,en_u,de_u,en_d,de_d,coefh,
+     .   frac_impa,frac_nucl,pyu1,pyv1,ftsol,psrf)
+
+
+       IMPLICIT NONE
+
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "temps.h"
+#include "ener.h"
+#include "logic.h"
+#include "description.h"
+#include "serre.h"
+#include "indicesol.h"
+#include "control.h"
+#include "dimphy.h"
+	  
+	  integer*4 kon,kev,zkon,zkev
+	  parameter(kon=iim*(jjm-1)+2,kev=llm)
+	  REAL*4 phisfi(kon)
+          REAL*4 phisfi2(iim,jjm+1),airefi2(iim,jjm+1)
+
+          REAL*4 mfu(kon,kev), mfd(kon,kev)
+          REAL*4 en_u(kon,kev), de_u(kon,kev)
+          REAL*4 en_d(kon,kev), de_d(kon,kev)
+          REAL*4 coefh(kon,kev)
+		REAL*4 t(kon,kev)
+
+          REAL*4 mfu2(iim,jjm+1,kev), mfd2(iim,jjm+1,kev)
+          REAL*4 en_u2(iim,jjm+1,kev), de_u2(iim,jjm+1,kev)
+          REAL*4 en_d2(iim,jjm+1,kev), de_d2(iim,jjm+1,kev)
+          REAL*4 coefh2(iim,jjm+1,kev)
+		REAL*4 t2(iim,jjm+1,kev)
+
+          REAL*4 pl(kev)
+          integer irec
+          integer*4 xid,yid,zid,tid
+          integer*4 zrec,zim,zjm
+          integer*4 ncrec,nckon,nckev,ncim,ncjm
+
+          real*4 airefi(kon)
+          character namedim
+
+c  !! attention !!
+c attention il y a aussi le pb de def kon
+c dim de phis??
+
+          REAL*4 frac_impa(kon,kev), frac_nucl(kon,kev)
+          REAL*4 frac_impa2(iim,jjm+1,kev), 
+     .     frac_nucl2(iim,jjm+1,kev)
+          REAL*4 pyu1(kon), pyv1(kon)
+          REAL*4 pyu12(iim,jjm+1), pyv12(iim,jjm+1)
+          REAL*4 ftsol(kon,nbsrf)
+          REAL*4 psrf(kon,nbsrf) 
+	  REAL*4 ftsol1(kon),ftsol2(kon),ftsol3(kon),ftsol4(kon)
+          REAL*4 psrf1(kon),psrf2(kon),psrf3(kon),psrf4(kon)
+          REAL*4 ftsol12(iim,jjm+1),ftsol22(iim,jjm+1),
+     .     ftsol32(iim,jjm+1),
+     .     ftsol42(iim,jjm+1)
+          REAL*4 psrf12(iim,jjm+1),psrf22(iim,jjm+1),psrf32(iim,jjm+1),
+     .     psrf42(iim,jjm+1)
+	
+	  integer ncidp
+          save ncidp
+          integer varidmfu, varidmfd, varidps, varidenu, variddeu	
+		integer varidt
+          integer varidend,varidded,varidch,varidfi,varidfn
+          integer varidyu1,varidyv1,varidpl,varidai,varididvt
+          integer varidfts1,varidfts2,varidfts3,varidfts4
+          integer varidpsr1,varidpsr2,varidpsr3,varidpsr4
+          save varidmfu, varidmfd, varidps, varidenu, variddeu
+		save varidt
+          save varidend,varidded,varidch,varidfi,varidfn
+          save varidyu1,varidyv1,varidpl,varidai,varididvt
+          save varidfts1,varidfts2,varidfts3,varidfts4
+          save varidpsr1,varidpsr2,varidpsr3,varidpsr4
+
+          integer l, i
+          integer start(4),count(4),status
+          real rcode
+          logical first
+          save first
+          data first/.true./
+
+
+
+c ---------------------------------------------
+c   Initialisation de la lecture des fichiers
+c ---------------------------------------------
+
+      if (irec .eq. 0) then
+
+            ncidp=NCOPN('phystoke.nc',NCNOWRIT,rcode)
+
+            varidps=NCVID(ncidp,'phis',rcode)
+            print*,'ncidp,varidps',ncidp,varidps
+
+            varidpl=NCVID(ncidp,'sig_s',rcode)
+            print*,'ncidp,varidpl',ncidp,varidpl
+
+            varidai=NCVID(ncidp,'aire',rcode)
+            print*,'ncidp,varidai',ncidp,varidai
+
+            varidmfu=NCVID(ncidp,'mfu',rcode)
+            print*,'ncidp,varidmfu',ncidp,varidmfu
+
+		varidt=NCVID(ncidp,'t',rcode)
+                print*,'ncidp,varidt',ncidp,varidt
+
+            varidmfd=NCVID(ncidp,'mfd',rcode)
+            print*,'ncidp,varidmfd',ncidp,varidmfd
+
+            varidenu=NCVID(ncidp,'en_u',rcode)
+            print*,'ncidp,varidenu',ncidp,varidenu
+
+            variddeu=NCVID(ncidp,'de_u',rcode)
+            print*,'ncidp,variddeu',ncidp,variddeu
+
+            varidend=NCVID(ncidp,'en_d',rcode)
+            print*,'ncidp,varidend',ncidp,varidend
+	
+            varidded=NCVID(ncidp,'de_d',rcode)
+            print*,'ncidp,varidded',ncidp,varidded
+	
+            varidch=NCVID(ncidp,'coefh',rcode)
+            print*,'ncidp,varidch',ncidp,varidch
+	
+	    varidfi=NCVID(ncidp,'frac_impa',rcode)
+            print*,'ncidp,varidfi',ncidp,varidfi
+	
+	    varidfn=NCVID(ncidp,'frac_nucl',rcode)
+            print*,'ncidp,varidfn',ncidp,varidfn
+	
+            varidyu1=NCVID(ncidp,'pyu1',rcode)
+            print*,'ncidp,varidyu1',ncidp,varidyu1
+	
+            varidyv1=NCVID(ncidp,'pyv1',rcode)
+            print*,'ncidp,varidyv1',ncidp,varidyv1
+	
+            varidfts1=NCVID(ncidp,'ftsol1',rcode)
+            print*,'ncidp,varidfts1',ncidp,varidfts1
+	
+            varidfts2=NCVID(ncidp,'ftsol2',rcode)
+            print*,'ncidp,varidfts2',ncidp,varidfts2
+         
+            varidfts3=NCVID(ncidp,'ftsol3',rcode)
+            print*,'ncidp,varidfts3',ncidp,varidfts3
+  
+            varidfts4=NCVID(ncidp,'ftsol4',rcode)
+            print*,'ncidp,varidfts4',ncidp,varidfts4
+	
+            varidpsr1=NCVID(ncidp,'psrf1',rcode)
+            print*,'ncidp,varidpsr1',ncidp,varidpsr1
+	
+            varidpsr2=NCVID(ncidp,'psrf2',rcode)
+            print*,'ncidp,varidpsr2',ncidp,varidpsr2
+	
+	    varidpsr3=NCVID(ncidp,'psrf3',rcode)
+            print*,'ncidp,varidpsr3',ncidp,varidpsr3
+
+            varidpsr4=NCVID(ncidp,'psrf4',rcode)
+            print*,'ncidp,varidpsr4',ncidp,varidpsr4
+	
+c ID pour les dimensions
+
+            status = nf_inq_dimid(ncidp,'y',yid)
+            status = nf_inq_dimid(ncidp,'x',xid)
+            status = nf_inq_dimid(ncidp,'sig_s',zid)
+            status = nf_inq_dimid(ncidp,'time_counter',tid)
+
+c lecture des dimensions
+
+            status = nf_inq_dim(ncidp,yid,namedim,ncjm)
+            status = nf_inq_dim(ncidp,xid,namedim,ncim)
+            status = nf_inq_dim(ncidp,zid,namedim,nckev)
+            status = nf_inq_dim(ncidp,tid,namedim,ncrec)
+	
+            zrec=ncrec
+            zkev=nckev
+            zim=ncim
+            zjm=ncjm
+	
+	    zkon=zim*(zjm-2)+2
+	
+	    write(*,*) 'read_pstoke : zrec = ', zrec
+            write(*,*) 'read_pstoke : kev = ', zkev
+            write(*,*) 'read_pstoke : zim = ', zim 
+            write(*,*) 'read_pstoke : zjm = ', zjm
+            write(*,*) 'read_pstoke : kon = ', zkon
+
+c niveaux de pression
+
+#ifdef NC_DOUBLE
+            status=NF_GET_VARA_DOUBLE(ncidp,varidpl,1,kev,pl)
+#else
+            status=NF_GET_VARA_REAL(ncidp,varidpl,1,kev,pl)
+#endif
+
+c lecture de aire et phis
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+
+c 
+c phis
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidps,start,count,phisfi2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidps,start,count,phisfi2)
+#endif
+
+
+      call gr_ecrit_fi(1,kon,iim,jjm+1,phisfi2,phisfi)
+
+c aire
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidai,start,count,airefi2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidai,start,count,airefi2)
+#endif
+
+      call gr_ecrit_fi(1,kon,iim,jjm+1,airefi2,airefi)
+      else
+
+      print*,'ok1'
+
+c ---------------------
+c   lecture des champs
+c ---------------------
+	
+	print*,'WARNING!!! Il n y a pas de test de coherence'
+        print*,'sur le nombre de niveaux verticaux dans le fichier nc'
+
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=irec
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=kev
+      count(4)=1
+
+c frac_impa 
+
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidfi,start,count,frac_impa2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidfi,start,count,frac_impa2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,frac_impa2,frac_impa)
+
+c frac_nucl 
+
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidfn,start,count,frac_nucl2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidfn,start,count,frac_nucl2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,frac_nucl2,frac_nucl)
+
+c abder t
+
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidt,start,count,t2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidt,start,count,t2)
+#endif
+
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,t2,t)
+
+c mfu
+
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidmfu,start,count,mfu2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidmfu,start,count,mfu2)
+#endif
+
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,mfu2,mfu)
+
+c mfd
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidmfd,start,count,mfd2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidmfd,start,count,mfd2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,mfd2,mfd)
+
+c en_u 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidenu,start,count,en_u2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidenu,start,count,en_u2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,en_u2,en_u)
+
+c de_u 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,variddeu,start,count,de_u2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,variddeu,start,count,de_u2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,de_u2,de_u)
+
+c en_d 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidend,start,count,en_d2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidend,start,count,en_d2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,en_d2,en_d)
+
+c de_d 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidded,start,count,de_d2)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidded,start,count,de_d2)
+#endif
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,de_d2,de_d)
+
+c coefh 
+	print*,'LECTURE de coefh a irec =',irec
+#ifdef NC_DOUBLE
+       status=NF_GET_VARA_DOUBLE(ncidp,varidch,start,count,coefh2)
+#else
+       status=NF_GET_VARA_REAL(ncidp,varidch,start,count,coefh2)
+#endif
+
+       call gr_ecrit_fi(kev,kon,iim,jjm+1,coefh2,coefh)
+
+      start(3)=irec
+      start(4)=0
+      count(3)=1
+      count(4)=0
+
+c pyu1
+	print*,'LECTURE de yu1 a irec =',irec
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidyu1,start,count,pyu12)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidyu1,start,count,pyu12)
+#endif
+
+      call gr_ecrit_fi(1,kon,iim,jjm+1,pyu12,pyu1)
+
+c pyv1
+        print*,'LECTURE de yv1 a irec =',irec
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidyv1,start,count,pyv12)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidyv1,start,count,pyv12)
+#endif
+      call gr_ecrit_fi(1,kon,iim,jjm+1,pyv12,pyv1)
+
+c ftsol1
+        print*,'LECTURE de ftsol1 a irec =',irec
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidfts1,start,count,ftsol12)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidfts1,start,count,ftsol12)
+#endif
+       call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol12,ftsol1)
+
+c ftsol2
+        print*,'LECTURE de ftsol2 a irec =',irec
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidfts2,start,count,ftsol22)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidfts2,start,count,ftsol22)
+#endif
+      call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol22,ftsol2)
+
+c ftsol3
+	 print*,'LECTURE de ftsol3 a irec =',irec
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidfts3,start,count,ftsol32)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidfts3,start,count,ftsol32)
+#endif
+      call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol32,ftsol3)
+
+c ftsol4
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidfts4,start,count,ftsol42)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidfts4,start,count,ftsol42)
+#endif
+      call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol42,ftsol4)
+
+c psrf1 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidpsr1,start,count,psrf12)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidpsr1,start,count,psrf12)
+#endif
+c      call dump2d(iip1-1,jjm+1,psrf12,'PSRF1NC')
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf12,psrf1)
+
+c psrf2 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidpsr2,start,count,psrf22)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidpsr2,start,count,psrf22)
+#endif
+c      call dump2d(iip1-1,jjm+1,psrf22,'PSRF2NC')
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf22,psrf2)
+
+c psrf3 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidpsr3,start,count,psrf32)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidpsr3,start,count,psrf32)
+#endif
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf32,psrf3)
+
+c psrf4 
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidp,varidpsr4,start,count,psrf42)
+#else
+      status=NF_GET_VARA_REAL(ncidp,varidpsr4,start,count,psrf42)
+#endif
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf42,psrf4)
+	
+          do i = 1,kon
+	
+	psrf(i,1) = psrf1(i)
+        psrf(i,2) = psrf2(i)
+        psrf(i,3) = psrf3(i)
+        psrf(i,4) = psrf4(i)
+  
+        ftsol(i,1) = ftsol1(i)
+        ftsol(i,2) = ftsol2(i)
+        ftsol(i,3) = ftsol3(i)
+        ftsol(i,4) = ftsol4(i)
+	
+          enddo
+	
+	endif
+	
+	return
+	
+	end
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_reanalyse.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_reanalyse.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/read_reanalyse.F	(revision 253)
@@ -0,0 +1,362 @@
+c
+c $Header$
+c
+      subroutine read_reanalyse(timestep,u,v,t,masse,ps,mode)
+
+c   mode=0 variables naturelles
+c   mode=1 variabels GCM
+
+      IMPLICIT NONE
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom.h"
+#include "comvert.h"
+
+      integer nlevnc
+      parameter (nlevnc=15)
+C pour annee 2000      parameter (nlevnc=21)
+      integer timestep,mode,l
+
+      real u(iip1,jjp1,llm),v(iip1,jjm,llm)
+      real t(iip1,jjp1,llm),ps(iip1,jjp1)
+      real masse(iip1,jjp1,llm),pk(iip1,jjp1,llm)
+
+      integer ncidu,varidu,ncidv,varidv,ncidt,varidt,ncidps,varidps
+      integer varidpl
+      save ncidu,varidu,ncidv,varidv,ncidt,varidt,ncidps,varidps
+      save varidpl
+
+      real*4 unc(iip1,jjp1,nlevnc),vnc(iip1,jjm,nlevnc)
+      real*4 tnc(iip1,jjp1,nlevnc),psnc(iip1,jjp1)
+      real*4 pl(nlevnc)
+
+      integer start(4),count(4),status
+
+      real rcode
+      logical first,ncep
+      save first,ncep
+cMod 11 2 99
+       data first,ncep/.true.,.false./
+c      data first,ncep/.true.,.true./
+      print*,'ok0'
+c -----------------------------------------------------------------
+c   Initialisation de la lecture des fichiers
+c -----------------------------------------------------------------
+      if (first) then
+            ncidu=NCOPN('u.nc',NCNOWRIT,rcode)
+            varidu=NCVID(ncidu,'UWND',rcode)
+            print*,'ncidu,varidu',ncidu,varidu
+         if (ncep) then
+            varidpl=NCVID(ncidu,'LEVEL',rcode)
+         else
+            varidpl=NCVID(ncidu,'PRESSURE',rcode)
+         endif
+            print*,'ncidu,varidpl',ncidu,varidpl
+            ncidv=NCOPN('v.nc',NCNOWRIT,rcode)
+            varidv=NCVID(ncidv,'VWND',rcode)
+            print*,'ncidv,varidv',ncidv,varidv
+            ncidt=NCOPN('T.nc',NCNOWRIT,rcode)
+            varidt=NCVID(ncidt,'AIR',rcode)
+            print*,'ncidt,varidt',ncidt,varidt
+c           ncidps=NCOPN('ps.nc',NCNOWRIT,rcode)
+c           varidps=NCVID(ncidps,'SP',rcode)
+c           print*,'ncidps,varidps',ncidps,varidps
+      endif
+
+      print*,'ok1'
+c -----------------------------------------------------------------
+c   lecture des champs u, v, T, ps
+c -----------------------------------------------------------------
+
+c  niveaux de pression
+      print*,'WARNING!!! Il n y a pas de test de coherence'
+      print*,'sur le nombre de niveaux verticaux dans le fichier nc'
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidu,varidpl,1,nlevnc,pl)
+#else
+      status=NF_GET_VARA_REAL(ncidu,varidpl,1,nlevnc,pl)
+#endif
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=timestep
+
+      count(1)=iip1
+      count(2)=jjp1
+      count(3)=nlevnc
+      count(4)=1
+
+c  u
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidu,varidu,start,count,unc)
+#else
+      status=NF_GET_VARA_REAL(ncidu,varidu,start,count,unc)
+#endif
+      print*,'WARNING!!! Correction bidon pour palier a un '
+      print*,'probleme dans la creation des fichiers nc'
+      call correctbid(iim,jjp1*nlevnc,unc)
+c     call dump2d(iip1,jjp1,unc,'UNC COUCHE 1 ')
+c  T
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidt,varidt,start,count,tnc)
+#else
+      status=NF_GET_VARA_REAL(ncidt,varidt,start,count,tnc)
+#endif
+      call correctbid(iim,jjp1*nlevnc,tnc)
+c     call dump2d(iip1,jjp1,tnc,'TNC COUCHE 1 ')
+
+      count(2)=jjm
+c  v
+#ifdef NC_DOUBLE
+      status=NF_GET_VARA_DOUBLE(ncidv,varidv,start,count,vnc)
+#else
+      status=NF_GET_VARA_REAL(ncidv,varidv,start,count,vnc)
+#endif
+      call correctbid(iim,jjm*nlevnc,vnc)
+c     call dump2d(iip1,jjm,vnc,'VNC COUCHE 1 ')
+
+      start(3)=timestep
+      start(4)=0
+      count(2)=jjp1
+      count(3)=1
+      count(4)=0
+c  ps
+C#ifdef NC_DOUBLE
+c     status=NF_GET_VARA_DOUBLE(ncidps,varidps,start,count,psnc)
+C#else
+c     status=NF_GET_VARA_REAL(ncidps,varidps,start,count,psnc)
+C#endif
+c     call dump2d(iip1,jjp1,psnc,'PSNC COUCHE 1 ')
+c     call correctbid(iim,jjp1,psnc)
+
+c   Transformations
+      do l=1,nlevnc
+         pl(l)=pl(l)*100.
+      enddo
+      if(first) then
+         do l=1,nlevnc
+            print*,'PL(',l,')=',pl(l)
+         enddo
+      endif
+
+      call reanalyse2nat(nlevnc,unc,vnc,tnc,psnc,pl,u,v,t
+     s    ,ps,masse,pk)
+c     call dump2d(iip1,jjm,v,'V COUCHE 1 ')
+
+      if(mode.eq.1) call nat2gcm(u,v,t,pk,u,v,t)
+      print*,'TIMESTEP ',timestep
+      if(mode.ne.1) stop'mode pas egal 0'
+c     call dump2d(iip1,jjm,v,'VCOV COUCHE 1 ')
+
+c   Lignes introduites a une epoque pour un probleme oublie...
+c     do l=1,llm
+c        do i=1,iip1
+c           v(i,1,l)=0.
+c           v(i,jjm,l)=0.
+c        enddo
+c     enddo
+      first=.false.
+
+      return
+      end
+
+c -----------------------------------------------------------------
+      subroutine reanalyse2nat(nlevnc,unc,vnc,tnc,psnc,pl,u,v,t
+     s   ,ps,masse,pk)
+
+c -----------------------------------------------------------------
+c   Inversion Nord/sud de la grille + interpollation sur les niveaux
+c   verticaux du modele.
+c -----------------------------------------------------------------
+
+      implicit none
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+#include "comvert.h"
+#include "comconst.h"
+
+      integer nlevnc
+      real u(iip1,jjp1,llm),v(iip1,jjm,llm)
+      real t(iip1,jjp1,llm),ps(iip1,jjp1)
+
+      real pl(nlevnc)
+      real unc(iip1,jjp1,nlevnc),vnc(iip1,jjm,nlevnc)
+      real tnc(iip1,jjp1,nlevnc),psnc(iip1,jjp1)
+
+      real zu(iip1,jjp1,llm),zv(iip1,jjm,llm)
+      real zt(iip1,jjp1,llm)
+
+      real pext(iip1,jjp1,llm)
+      real pbarx(iip1,jjp1,llm),pbary(iip1,jjm,llm)
+      real plunc(iip1,jjp1,llm),plvnc(iip1,jjm,llm)
+      real plsnc(iip1,jjp1,llm)
+
+      REAL alpha(iip1,jjp1,llm),beta(iip1,jjp1,llm)
+      real p(iip1,jjp1,llmp1),pk(iip1,jjp1,llm),pks(iip1,jjp1)
+      real pkf(iip1,jjp1,llm)
+      real masse(iip1,jjp1,llm),pls(iip1,jjp1,llm)
+      real prefkap,unskap
+
+      integer i,j,l
+
+
+c -----------------------------------------------------------------
+c   calcul de la pression au milieu des couches.
+c -----------------------------------------------------------------
+
+c     do j=1,jjp1
+c        do i=1,iim
+c           ps(i,j)=psnc(i,jjp1+1-j)
+c        enddo
+c        ps(iip1,j)=ps(1,j)
+c     enddo
+
+      CALL pression( ip1jmp1, ap, bp, ps, p )
+      call massdair(p,masse)
+      CALL exner_hyb(ip1jmp1,ps,p,alpha,beta,pks,pk,pkf)
+c    ....  Calcul de pls , pression au milieu des couches ,en Pascals
+      unskap=1./kappa
+      prefkap =  preff  ** kappa
+c     PRINT *,' Pref kappa unskap  ',preff,kappa,unskap
+      DO l = 1, llm
+       DO j=1,jjp1
+        DO i =1, iip1
+        pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
+        ENDDO
+       ENDDO
+       ENDDO
+
+
+
+c -----------------------------------------------------------------
+c   calcul des pressions pour les grilles u et v
+c -----------------------------------------------------------------
+
+      do l=1,llm
+      do j=1,jjp1
+         do i=1,iip1
+            pext(i,j,l)=pls(i,j,l)*aire(i,j)
+         enddo
+      enddo
+      enddo
+      call massbar(pext, pbarx, pbary )
+      do l=1,llm
+      do j=1,jjp1
+         do i=1,iip1
+            plunc(i,jjp1+1-j,l)=pbarx(i,j,l)/aireu(i,j)
+            plsnc(i,jjp1+1-j,l)=pls(i,j,l)
+         enddo
+      enddo
+      enddo
+      do l=1,llm
+      do j=1,jjm
+         do i=1,iip1
+            plvnc(i,jjm+1-j,l)=pbary(i,j,l)/airev(i,j)
+         enddo
+      enddo
+      enddo
+
+c -----------------------------------------------------------------
+      call pres2lev(unc,zu,nlevnc,llm,pl,plunc,iip1,jjp1)
+      call pres2lev(vnc,zv,nlevnc,llm,pl,plvnc,iip1,jjm )
+      call pres2lev(tnc,zt,nlevnc,llm,pl,plsnc,iip1,jjp1)
+
+c     call dump2d(iip1,jjp1,ps,'PS    ')
+c     call dump2d(iip1,jjp1,psu,'PS    ')
+c     call dump2d(iip1,jjm,psv,'PS    ')
+c  Inversion Nord/Sud
+      do l=1,llm
+         do j=1,jjp1
+            do i=1,iim
+               u(i,j,l)=zu(i,jjp1+1-j,l)
+               t(i,j,l)=zt(i,jjp1+1-j,l)
+            enddo
+            u(iip1,j,l)=u(1,j,l)
+            t(iip1,j,l)=t(1,j,l)
+         enddo
+      enddo
+
+      do l=1,llm
+         do j=1,jjm
+            do i=1,iim
+               v(i,j,l)=zv(i,jjm+1-j,l)
+            enddo
+            v(iip1,j,l)=v(1,j,l)
+         enddo
+      enddo
+
+      return
+      end
+
+      subroutine nat2gcm(u,v,t,pk,ucov,vcov,teta)
+
+      implicit none
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+#include "comconst.h"
+#include "comvert.h"
+
+      real u(iip1,jjp1,llm),v(iip1,jjm,llm)
+      real t(iip1,jjp1,llm),pk(iip1,jjp1,llm)
+
+      real ucov(iip1,jjp1,llm),vcov(iip1,jjm,llm)
+      real teta(iip1,jjp1,llm)
+
+      integer i,j,l
+
+
+c   calcul de ucov et de la temperature potentielle
+      do l=1,llm
+         do j=1,jjp1
+            do i=1,iim
+               ucov(i,j,l)=u(i,j,l)*cu(i,j)
+               teta(i,j,l)=t(i,j,l)*cpp/pk(i,j,l)
+            enddo
+            ucov(iip1,j,l)=ucov(1,j,l)
+            teta(iip1,j,l)=teta(1,j,l)
+         enddo
+         do i=1,iip1
+            ucov(i,1,l)=0.
+            ucov(i,jjp1,l)=0.
+            teta(i,1,l)=teta(1,1,l)
+            teta(i,jjp1,l)=teta(1,jjp1,l)
+         enddo
+      enddo
+
+c   calcul de ucov
+      do l=1,llm
+         do j=1,jjm
+            do i=1,iim
+               vcov(i,j,l)=v(i,j,l)*cv(i,j)
+            enddo
+            vcov(iip1,j,l)=vcov(1,j,l)
+         enddo
+      enddo
+
+c     call dump2d(iip1,jjp1,teta,'TETA EN BAS   ')
+c     call dump2d(iip1,jjp1,teta(1,1,llm),'TETA EN HAUT   ')
+
+      return
+      end
+      subroutine correctbid(iim,nl,x)
+      integer iim,nl
+      real x(iim+1,nl)
+      integer i,l
+      real zz
+
+      do l=1,nl
+         do i=2,iim-1
+            if(abs(x(i,l)).gt.1.e10) then
+               zz=0.5*(x(i-1,l)+x(i+1,l))
+c              print*,'correction ',i,l,x(i,l),zz
+               x(i,l)=zz
+            endif
+         enddo
+      enddo
+      return
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/redecoupe.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/redecoupe.F	(revision 3)
+++ 	(revision )
@@ -1,637 +1,0 @@
-      SUBROUTINE redecoupe(irec,massemn,pbarun,pbarvn,wn,tetan,phin,
-     s     nrec,avant,airefi,
-     s     zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkz,
-     s     yu1,yv1,ftsol,pctsrf,
-     s     frac_impa,frac_nucl,phisn)
-
-      IMPLICIT NONE
-
-#include "dimensions.h"
-#include "paramet.h"
-
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom2.h"
-
-#include "tracstoke.h"
-
-      integer irec,nrec,i,j
-
-      integer ig,l
-      integer imo,jmo,imn,jmn,ii,jj,ig
-      parameter (imn=iim,jmn=jjm,imo=imn/2,jmo=(jmn+1)/2)
-      integer ngrido,ngridn
-      parameter(ngrido=(jmo-1)*imo+2,ngridn=(jmn-1)*imn+2)
-
-
-      INTEGER nbsrf
-      PARAMETER (nbsrf=4) ! nombre de sous-fractions pour une maille
-
-      real zmfd(ngridn,llm),zde_d(ngridn,llm),zen_d(ngridn,llm)
-      real zmfu(ngridn,llm),zde_u(ngridn,llm),zen_u(ngridn,llm)
-      real coefkz(ngridn,llm)
-      real frac_impa(ngridn,llm),frac_nucl(ngridn,llm)
-      real yu1(ngridn), yv1(ngridn)
-      real ftsol(ngridn,nbsrf),pctsrf(ngridn,nbsrf)
-      integer imfu,imfd,ien_u,ide_u,
-     s      ien_d,ide_d,
-     s      icoefkz,izu1,izv1,
-     s      itsol,ipsf,
-     s      ilei, ilec
-      parameter(imfu=1,imfd=llm+1,ien_u=2*llm+1,ide_u=3*llm+1,
-     s      ien_d=4*llm+1,ide_d=5*llm+1,
-     s      icoefkz=6*llm+1,
-     s      ilei=7*llm+1,ilec=8*llm+1,
-     s      izu1=9*llm+1,izv1=9*llm+2,
-     s      itsol=9*llm+3,ipsf=9*llm+3+nbsrf)
-      logical avant
-
-
-      real massefi(ngridn,llm)
-
-      real massemn(imn+1,jmn+1,llm),tetan(imn+1,jmn+1,llm)
-      real pbarun(imn+1,jmn+1,llm),pbarvn(imn+1,jmn,llm)
-      real wn(imn+1,jmn+1,llm),phin(imn+1,jmn+1,llm)
-      real phisn(imn+1,jmn+1)
-
-      real massemo(imo+1,jmo+1,llm),tetao(imo+1,jmo+1,llm)
-      real pbaruo(imo+1,jmo+1,llm),pbarvo(imo+1,jmo,llm)
-      real wo(imo+1,jmo+1,llm),phio(imo+1,jmo+1,llm)
-      real phiso(imo+1,jmo+1)
-
-      real pbarvst(imo+1,jmo+1,llm)
-
-      real airefi(ngridn)
-
-      real xlecn(ngridn,9*llm+2+2*nbsrf),tmpn(imn+1,jmn+1)
-      real xleco(ngrido,9*llm+2+2*nbsrf),tmpo(imo+1,jmo+1)
-
-      real zcontrole(ngridn),zmass,tmpdyn(imn+1,jmn+1),zflux
-
-      real ziadvtrac,zrec,ziadvtrac2,zrec2
-      real zim,zjm,zlm,zklon,zklev
-
-      real zpi
-c  longitudes et latitudes lues
-      real rlonul(1:imo+1),rlatvl(1:jmo)
-      real rlonvl(1:imo+1),rlatul(1:jmo+1)
-c  longitudes et latitudes anciennes
-      real rlonuo(0:imo+1),rlatvo(0:jmo+1)
-c  longitudes et latitudes nouvelles
-      real rlonun(0:imn+1),rlatvn(0:jmn+1)
-      real aireo(imo+1,jmo+1)
-
-      integer ndecx(imo+1),ndecy(jmo+1)
-      real alphax(imn+1),alphay(jmn+1)
-      real alphaxo(imo+1)
-      real alpha(imn+1,jmn+1)
-
-      real aa,uu(0:imo+1),vv(imo+1,0:jmo+1)
-
-
-      integer iest(imo+1),iouest(imo+1)
-      integer jsud(jmo+1),jnord(jmo+1)
-
-      integer in,io,jn,jo,l,iin,jjn
-      integer i,j
-      real dlatm,dlatp,dlonm,dlonp
-
-
-      zpi=2.*asin(1.)
-
-
-c==================================================================
-c   Si le numero du record est 0 alors: INITIALISATION
-c==================================================================
-c
-      print*,'ENTREE DANS LECTFLUX'
-        print*,'IREC=',IREC
-      if(irec.eq.0) then
-
-        print*,'IREC==',0
-
-C test         call inigeom
-c==================================================================
-c   Definition des surdecoupages dans les deux directions
-c==================================================================
-
-      ndecx(1)=1
-      do io=2,imo
-         ndecx(io)=2
-      enddo
-      ndecx(imo+1)=1
-
-      ndecy(1)=1
-      do jo=2,jmo
-         ndecy(jo)=2
-      enddo
-      ndecy(jmo+1)=1
-
-      ii=0
-      do io=1,imo+1
-         ii=ii+ndecx(io)
-      enddo
-      if(ii.ne.iim) then
-         print*,'ii=',ii,'   iim=',iim
-         stop
-      endif
-
-      jj=0
-      do jo=1,jmo+1
-         jj=jj+ndecy(jo)
-      enddo
-      if(jj.ne.jjp1) then
-         print*,'jj=',jj,'   jjm=',jjm
-         stop
-      endif
-
-c==================================================================
-c   Calcul des jsud,... correspondant aux intersections des
-c   grilles.
-c==================================================================
-
-      iest(1)=0
-      do io=2,imo+1
-         iest(io)=iest(io-1)+ndecx(io-1)
-         iouest(io-1)=iest(io)
-      enddo
-      iouest(imo+1)=iest(imo+1)+ndecx(imo+1)
-
-      jnord(1)=0
-      do jo=2,jmo+1
-         jnord(jo)=jnord(jo-1)+ndecy(jo-1)
-         jsud(jo-1)=jnord(jo)
-      enddo
-      jsud(jmo+1)=jnord(jmo+1)+ndecy(jmo+1)
-
-c==================================================================
-c   ouverture des fichiers, lecture des entetes
-c==================================================================
-
-c   Fichier fluxmass
-#ifdef CRAY
-         CALL ASSIGN("assign -N ieee -F null f:fluxmass")
-#endif
-      open(47,file='fluxmass',form='unformatted',
-     s     access='direct'
-     s     ,recl=4*6*(imo+1)*(jmo+1)*llm)
-      read(47,rec=1) zrec,dtvr,ziadvtrac,zim,zjm,zlm
-     s   ,rlonul,rlonvl,rlatul,rlatvl,aireo
-     s    ,phiso
-
-      print*,'zrec,dtvr,ziadvtrac,zim,zjm,zlm'
-      print*,zrec,dtvr,ziadvtrac,zim,zjm,zlm
-      if((imo-nint(zim))*(jmo-nint(zjm)).ne.0) then
-        print*,'Modifier les dimensions dans redecoupe '
-        print*,'Mettre imo=',zim,'   jmo=',zjm
-        stop
-      endif
-
-
-c  Fichier physique
-c  Fichier lessivage (supprime les donnees utiles sont dans "physique")
-#ifdef CRAY
-         CALL ASSIGN("assign -N ieee -F null f:physique")
-#endif
-      open(49,file='physique',form='unformatted',
-     s     access='direct'
-     s     ,recl=4*ngrido*(9*llm+2+2*nbsrf))
-      read(49,rec=1) zrec2,ziadvtrac2,zklon,zklev
-      print*,'Entete du fichier physique'
-      print*,zrec2,ziadvtrac2,zklon,zklev
-
-      nrec=zrec
-      istdyn=ziadvtrac
-      istphy=ziadvtrac2
-
-c==================================================================
-c   Definition des anciennes latitudes et longitudes
-c   (qui pourraient etre relues plus tard)
-c==================================================================
-
-      rlonuo(0)=-zpi
-      do io=1,imo
-c        rlonuo(io)=2.*zpi/FLOAT(imo)*(io+0.5-0.5*FLOAT(imo)-1.)
-c        print*,'LON ',io,rlonuo(io),rlonul(io)
-         rlonuo(io)=rlonul(io)
-      enddo
-      rlonuo(imo+1)=zpi
-
-      rlatvo(0)=zpi/2.
-      do jo=1,jmo
-c        rlatvo(jo)=zpi/FLOAT(jmo)*(0.5*FLOAT(jmo)+1.-jo-0.5)
-c        print*,'LAT ',jo,rlatvo(jo),rlatvl(jo)
-         rlatvo(jo)=rlatvl(jo)
-      enddo
-      rlatvo(jmo+1)=-zpi/2.
-
-c     do jo=1,jmo+1
-c        do io=1,imo+1
-c           aireo(io,jo)=rad*rad
-c    s         *(rlonuo(io)-rlonuo(io-1))
-c    s         *(sin(rlatvo(jo-1))-sin(rlatvo(jo)))
-c           aireo(io,jo)=airel(io,jo)
-c        enddo
-c        aireo(1,jo)=aireo(1,jo)+aireo(imo+1,jo)
-c        aireo(imo+1,jo)=aireo(1,jo)
-c     enddo
-
-      do io=2,imo
-         alphaxo(io)=1.
-      enddo
-      alphaxo(1)=(rlonuo(1)-rlonuo(0))
-     s        /(rlonuo(1)-rlonuo(0)+rlonuo(imo+1)-rlonuo(imo))
-      alphaxo(imo+1)=1.-alphaxo(1)
-
-c==================================================================
-c    Definition des nouvelles latitudes et longitudes
-c==================================================================
-
-      rlonun(0)=-zpi
-      do io=1,imo+1
-         do iin=1,iouest(io)-iest(io)
-            in=iin+iest(io)
-            rlonun(in)=
-     s      rlonuo(io-1)+iin*(rlonuo(io)-rlonuo(io-1))
-     s      /ndecx(io)
-            alphax(in)=alphaxo(io)/ndecx(io)
-            print787,io,rlonuo(io-1)*180./zpi,in
-     s      ,iest(io),iouest(io),rlonun(in)*180./zpi,alphax(in)
-         enddo
-      enddo
-
-      rlatvn(0)=0.5*zpi
-      do jo=1,jmo+1
-         print*,'jo=',jo
-         do jjn=1,jsud(jo)-jnord(jo)
-            jn=jnord(jo)+jjn
-            rlatvn(jn)=rlatvo(jo-1)+jjn*(rlatvo(jo)-rlatvo(jo-1))
-     s      /ndecy(jo)
-            alphay(jn)=(sin(rlatvn(jn-1))-sin(rlatvn(jn)))
-     s                /(sin(rlatvo(jo-1))-sin(rlatvo(jo)))
-            print787,jo,rlatvo(jo-1)*180./zpi,jn
-     s      ,jnord(jo),jsud(jo),rlatvn(jn)*180./zpi,alphay(jn)
-         enddo
-      enddo
-
-787   format(i5,f10.2,3(i5),2(f10.2))
-      do in=1,imn
-         rlonu(in)=rlonun(in)
-         rlonv(in)=0.5*(rlonun(in)+rlonun(in-1))
-      enddo
-      rlonv(imn+1)=rlonv(1)+2.*zpi
-      rlonu(imn+1)=rlonu(1)+2.*zpi
-
-      do jn=1,jmn
-         rlatv(jn)=rlatvn(jn)
-      enddo
-      do jn=1,jmn+1
-         rlatu(jn)=0.5*(rlatvn(jn-1)+rlatvn(jn))
-      enddo
-
-      do jn=1,jmn+1
-         do in=1,imn
-            alpha(in,jn)=alphax(in)*alphay(jn)
-         enddo
-         alpha(imn+1,jn)=0.
-      enddo
-
-c     call dump2d(iip1,jjp1,alpha,'ALPHA   ')
-
-c      .  on a :  cu(i,j) = rad * COS(y) * dx/dX         .
-c      .          cv( j ) = rad          * dy/dY         .
-c   A 1 point scalaire P (i,j) de la grille, reguliere en (X,Y) , sont
-c   affectees 4 aires entourant P , calculees respectivement aux points
-c            ( i + 1/4, j - 1/4 )    :    aireij1 (i,j)
-c            ( i + 1/4, j + 1/4 )    :    aireij2 (i,j)
-c            ( i - 1/4, j + 1/4 )    :    aireij3 (i,j)
-c            ( i - 1/4, j - 1/4 )    :    aireij4 (i,j)
-c
-c                             . V
-c
-c                 aireij4 .        . aireij1
-c
-c                   U .       . P      . U
-c
-c                 aireij3 .        . aireij2
-c
-c                             . V
-
-
-      do j=1,jjp1
-         do i=1,iim
-            dlonp=rlonun(i)-rlonv(i)
-            dlonm=rlonv(i)-rlonun(i-1)
-            dlatp=sin(rlatvn(j-1))-sin(rlatu(j))
-            dlatm=sin(rlatu(j))-sin(rlatvn(j))
-            aireij1 ( i,j ) = rad*rad*dlatp*dlonp
-            aireij2 ( i,j ) = rad*rad*dlatm*dlonp
-            aireij3 ( i,j ) = rad*rad*dlatm*dlonm
-            aireij4 ( i,j ) = rad*rad*dlatp*dlonm
-      aire    ( i,j )  = aireij1(i,j) + aireij2(i,j) + aireij3(i,j) +
-     *                          aireij4(i,j)
-      alpha1  ( i,j )  = aireij1(i,j) / aire(i,j)
-      alpha2  ( i,j )  = aireij2(i,j) / aire(i,j)
-      alpha3  ( i,j )  = aireij3(i,j) / aire(i,j)
-      alpha4  ( i,j )  = aireij4(i,j) / aire(i,j)
-      alpha1p2( i,j )  = alpha1 (i,j) + alpha2 (i,j)
-      alpha1p4( i,j )  = alpha1 (i,j) + alpha4 (i,j)
-      alpha2p3( i,j )  = alpha2 (i,j) + alpha3 (i,j)
-      alpha3p4( i,j )  = alpha3 (i,j) + alpha4 (i,j)
-           enddo
-           aireij1(iip1,j)=aireij1(1,j)
-           aireij2(iip1,j)=aireij2(1,j)
-           aireij3(iip1,j)=aireij3(1,j)
-           aireij4(iip1,j)=aireij4(1,j)
-           aire(iip1,j)=aire(1,j)
-           alpha1(iip1,j)=alpha1(1,j)
-           alpha2(iip1,j)=alpha2(1,j)
-           alpha3(iip1,j)=alpha3(1,j)
-           alpha4(iip1,j)=alpha4(1,j)
-           alpha1p2(iip1,j)=alpha1p2(1,j)
-           alpha1p4(iip1,j)=alpha1p4(1,j)
-           alpha2p3(iip1,j)=alpha2p3(1,j)
-           alpha3p4(iip1,j)=alpha3p4(1,j)
-       enddo
-c     call dump2d(iip1,jjp1,aire,'AIRE   ')
-
-c     do jn=1,jjp1
-c        do in=1,iim
-c           aire(in,jn)=rad*rad*(sin(rlatvn(jn-1))-sin(rlatvn(jn)))
-c    s      *(rlonun(in)-rlonun(in-1))
-c           unsaire(in,jn)=1./aire(in,jn)
-c        enddo
-c        aire(iip1,jn)=aire(1,jn)
-c        unsaire(iip1,jn)=unsaire(1,jn)
-c     enddo
-c     call dump2d(iip1,jjp1,aire,'AIRE2   ')
-      DO 42 j = 1,jjp1
-      DO 41 i = 1,iim
-      unsaire(i,j) = 1./ aire(i,j)
-      aireu  (i,j) = aireij1(i,j) + aireij2(i,j) + aireij4(i+1,j) +
-     *                           aireij3(i+1,j)
-  41  CONTINUE
-      aireu  (iip1,j) = aireu  (1,j)
-      unsaire(iip1,j) = unsaire(1,j)
-  42  CONTINUE
-      DO 48 j = 1,jjm
-        DO i=1,iim
-         airev(i,j)     = aireij2(i,j)+ aireij3(i,j)+ aireij1(i,j+1) +
-     *                           aireij4(i,j+1)
-        ENDDO
-       airev   (iip1,j) = airev(1,j)
-  48  CONTINUE
-      apoln=0.
-      apols=0.
-      do i=1,iim
-         apoln=apoln+aire(i,1)
-         apols=apols+aire(i,jjp1)
-      enddo
-
-
-
-      do jn=1,jjp1
-         do in=1,iim
-            cu(in,jn)=rad*cos(rlatu(jn))*(rlonv(in+1)-rlonv(in))
-         enddo
-         cu(iip1,jn)=cu(1,jn)
-      enddo
-      do jn=1,jjm
-         do in=1,iim+1
-            cv(in,jn)=rad*(rlatu(jn)-rlatu(jn+1))
-         enddo
-      enddo
-
-
-c==================================================================
-c   Fin des initialisations
-      else ! irec=0
-c==================================================================
-
-
-c-----------------------------------------------------------------------
-c   Lecture des fichiers fluxmass et  physique:
-c   -----------------------------------------------------
-
-c==================================================================
-c  Variables dynamiques
-c==================================================================
-
-         read(47,rec=irec) massemo,pbaruo,pbarvst,wo,tetao,phio
-        do l=1,llm
-           do j=1,jmo
-              do i=1,imo+1
-                 pbarvo(i,j,l)=pbarvst(i,j,l)
-              enddo
-           enddo
-        enddo
-
-         do l=1,llm
-            do jo=1,jmo+1
-               do io=1,imo+1
-                  do jn=jnord(jo)+1,jsud(jo)
-                     do in=iest(io)+1,iouest(io)
-                        wn(in,jn,l)=alpha(in,jn)*wo(io,jo,l)
-                        massemn(in,jn,l)=alpha(in,jn)
-     s                     *massemo(io,jo,l)
-                        tetan(in,jn,l)=tetao(io,jo,l)
-                        phin(in,jn,l)=phio(io,jo,l)
-                     enddo
-                  enddo
-               enddo
-            enddo
-            do jn=1,jmn+1
-               wn(imn+1,jn,l)=wn(1,jn,l)
-               massemn(imn+1,jn,l)=massemn(1,jn,l)
-               tetan(imn+1,jn,l)=tetan(1,jn,l)
-               phin(imn+1,jn,l)=phin(1,jn,l)
-            enddo
-         enddo
-
-         do l=1,llm
-            do jo=1,jmo+1
-               uu(imo+1)=0.5*(pbaruo(imo,jo,l)+pbaruo(imo+1,jo,l))
-               uu(0)=uu(imo+1)
-               do io=1,imo
-                  uu(io)=pbaruo(io,jo,l)
-               enddo
-               do io=1,imo+1
-                  do jn=jnord(jo)+1,jsud(jo)
-                     aa=0.
-                     do in=iest(io)+1,iouest(io)
-                        aa=aa+alphax(in)
-                        pbarun(in,jn,l)=alphay(jn)*
-     s                    (uu(io-1)+aa*(uu(io)-uu(io-1)))
-                     enddo
-                  enddo
-               enddo
-            enddo
-            do jn=1,jmn+1
-               pbarun(imn+1,jn,l)=pbarun(1,jn,l)
-            enddo
-         enddo
-
-         do l=1,llm
-            do jo=1,jmo
-               do io=1,imo+1
-                  vv(io,jo)=pbarvo(io,jo,l)
-               enddo
-            enddo
-            do io=1,imo+1
-               vv(io,0)=0.
-               vv(io,jmo+1)=0.
-            enddo
-            do jo=1,jmo+1
-               do io=1,imo+1
-                  aa=0.
-c                 do jn=jnord(jo)+1,max(jsud(jo),jmo)
-                  do jn=jnord(jo)+1,min(jsud(jo),jmn)
-                     aa=aa+alphay(jn)
-                     do in=iest(io)+1,iouest(io)
-                        pbarvn(in,jn,l)=alphax(in)*
-     s                  (vv(io,jo-1)+aa*(vv(io,jo)-vv(io,jo-1)))
-                     enddo
-                  enddo
-               enddo
-            enddo
-            do jn=1,jmn
-               pbarvn(iip1,jn,l)=pbarvn(1,jn,l)
-            enddo
-         enddo
-
-c==================================================================
-c  Variables physiques
-c==================================================================
-         read(49,rec=irec) ((xleco(ig,l),ig=1,ngrido),
-     s                                    l=1,9*llm+2+2*nbsrf)
-
-c==================================================================
-c  Passage  a la nouvelle grille
-c==================================================================
-         do l=1,9*llm+2+2*nbsrf
-c   passage aa la grille dynamique ancienne
-            do io=1,imo+1
-               tmpo(io,1)=xleco(1,l)
-               tmpo(io,jmo+1)=xleco(ngrido,l)
-            enddo
-            do jo=2,jmo
-               do io=1,imo
-                  tmpo(io,jo)=xleco((jo-2)*imo+io+1,l)
-               enddo
-               tmpo(imo+1,jo)=tmpo(1,jo)
-            enddo
-c   passage a la grillle dynamique nouvelle
-            do jo=1,jmo+1
-               do io=1,imo+1
-                  do jn=jnord(jo)+1,jsud(jo)
-                     do in=iest(io)+1,iouest(io)
-                        tmpn(in,jn)=tmpo(io,jo)
-                     enddo
-                  enddo
-               enddo
-            enddo
-c   passage a la grille physique nouvelle
-            xlecn(1,l)=tmpn(1,1)
-            xlecn(ngridn,l)=tmpn(1,jmn+1)
-            do jn=2,jmn
-               do in=1,imn
-                  xlecn((jn-2)*imn+in+1,l)=tmpn(in,jn)
-               enddo
-            enddo
-         enddo
-
-c==================================================================
-
-       do l=1,llm
-          do ig=1,ngridn
-             coefkz(ig,l)=xlecn(ig,icoefkz+l-1)
-             frac_impa(ig,l)=xlecn(ig,ilei+l-1)
-             frac_nucl(ig,l)=xlecn(ig,ilec+l-1)
-          enddo
-       enddo
-       do l=1,nbsrf
-          do ig=1,ngridn
-             ftsol(ig,l)=xlecn(ig,itsol+l-1)
-             pctsrf(ig,l)=xlecn(ig,ipsf+l-1)
-          enddo
-       enddo
-       do ig=1,ngridn
-          yv1(ig)=xlecn(ig,izv1)
-          yu1(ig)=xlecn(ig,izu1)
-       enddo
-C
-      if(avant) then
-c   Simu directe
-       do l=1,llm
-          do ig=1,ngridn
-             zmfu(ig,l)=xlecn(ig,imfu+l-1)
-             zmfd(ig,l)=xlecn(ig,imfd+l-1)
-             zde_u(ig,l)=xlecn(ig,ide_u+l-1)
-             zen_u(ig,l)=xlecn(ig,ien_u+l-1)
-             zde_d(ig,l)=xlecn(ig,ide_d+l-1)
-             zen_d(ig,l)=xlecn(ig,ien_d+l-1)
-          enddo
-       enddo
-      else
-c   Simu retro
-       do l=1,llm
-          do ig=1,ngridn
-             zmfd(ig,l)=-xlecn(ig,imfu+l-1)
-             zmfu(ig,l)=-xlecn(ig,imfd+l-1)
-             zen_d(ig,l)=xlecn(ig,ide_u+l-1)
-             zde_d(ig,l)=xlecn(ig,ien_u+l-1)
-             zen_u(ig,l)=xlecn(ig,ide_d+l-1)
-             zde_u(ig,l)=xlecn(ig,ien_d+l-1)
-          enddo
-       enddo
-      endif
-
-c-----------------------------------------------------------------------
-c   PETIT CONTROLE SUR LES FLUX CONVECTIFS...
-c-----------------------------------------------------------------------
-
-         call gr_dyn_fi(llm,iip1,jjp1,ngridn,massemn,massefi)
-
-      print*,'Ap redec irec'
-         do ig=1,ngridn
-            zcontrole(ig)=1.
-         enddo
-c   zmass=(max(massemn(ig,l),massemn(ig,l-1))/airefi(ig)
-         do l=2,llm
-            do ig=1,ngridn
-               zmass=max(massefi(ig,l),massefi(ig,l-1))/airefi(ig)
-               zflux=max(abs(zmfu(ig,l)),abs(zmfd(ig,l)))*dtphys
-               if(zflux.gt.0.9*zmass) then
-                 zcontrole(ig)=min(zcontrole(ig),0.9*zmass/zflux)
-               endif
-            enddo
-         enddo
-
-         do ig=1,ngridn
-            if(zcontrole(ig).lt.0.99999) then
-               print*,'ATTENTION !!! on reduit les flux de masse '
-               print*,'convectifs au point ig=',ig
-            endif
-         enddo
-
-         call gr_fi_dyn(1,ngridn,iip1,jjp1,zcontrole,tmpdyn)
-
-         do l=1,llm
-            do ig=1,ngridn
-               zmfu(ig,l)=zmfu(ig,l)*zcontrole(ig)
-               zmfd(ig,l)=zmfd(ig,l)*zcontrole(ig)
-               zen_u(ig,l)=zen_u(ig,l)*zcontrole(ig)
-               zde_u(ig,l)=zde_u(ig,l)*zcontrole(ig)
-               zen_d(ig,l)=zen_d(ig,l)*zcontrole(ig)
-               zde_d(ig,l)=zde_d(ig,l)*zcontrole(ig)
-            enddo
-         enddo
-
-
-      endif ! irec=0
-
-
-      RETURN
-      END
-
-
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/redecoupenc.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/redecoupenc.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/redecoupenc.F	(revision 253)
@@ -0,0 +1,1186 @@
+c
+c $Header$
+c
+      SUBROUTINE redecoupenc
+     s     (irec,massemn,pbarun,pbarvn,wn,tetan,phin,
+     s     nrec,avant,airefin,phisfin,
+     s     tn,zmfu, zmfd, zen_u, zde_u,zen_d, zde_d, coefkzn,
+     s     yu1n,yv1n,ftsoln,pctsrfn,
+     s     frac_impan,frac_nucln,phisn)
+
+      IMPLICIT NONE
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "comgeom2.h"
+#include "tracstoke.h"
+#include "logic.h"
+
+      integer irec,nrec,i,j
+      integer ig,l
+      integer imo,jmo,imn,jmn,ii,jj,ig
+      parameter (imn=iim,jmn=jjm,imo=imn/2,jmo=(jmn+1)/2)
+      integer ngrido,ngridn
+      parameter(ngrido=(jmo-1)*imo+2,ngridn=(jmn-1)*imn+2)
+      real zdtvr
+
+      INTEGER nbsrf
+      PARAMETER (nbsrf=4) ! nombre de sous-fractions pour une maille
+
+      real zmfd(ngridn,llm),zde_d(ngridn,llm),zen_d(ngridn,llm)
+      real zmfu(ngridn,llm),zde_u(ngridn,llm),zen_u(ngridn,llm)
+	
+       logical avant
+
+      real massefi(ngridn,llm)
+
+      real massemn(imn+1,jmn+1,llm),tetan(imn+1,jmn+1,llm)
+      real pbarun(imn+1,jmn+1,llm),pbarvn(imn+1,jmn,llm)
+      real wn(imn+1,jmn+1,llm),phin(imn+1,jmn+1,llm)
+      real phisn(imn+1,jmn+1)
+
+      real massemo(imo+1,jmo+1,llm),tetao(imo+1,jmo+1,llm)
+      real pbaruo(imo+1,jmo+1,llm),pbarvo(imo+1,jmo,llm)
+      real wo(imo+1,jmo+1,llm),phio(imo+1,jmo+1,llm)
+      real phiso(imo+1,jmo+1)
+
+      real pbarvst(imo+1,jmo+1,llm)
+
+      real tmpo2(imo+1,jmo+1,llm),tmpo1(imo,jmo+1,llm)
+      real tmpo4(imo+1,jmo+1,nbsrf),tmpo3(imo,jmo+1,nbsrf)
+      real tmpo6(imo+1,jmo+1),tmpo5(imo,jmo+1)
+      real tmpn6(imn+1,jmn+1),tmpn5(imn,jmn+1)
+      real tmpn2(imn+1,jmn+1,llm),tmpn1(imn,jmn+1,llm)
+      real tmpn4(imn+1,jmn+1,nbsrf),tmpn3(imn,jmn+1,nbsrf)
+
+	real airefio(ngrido),phisfio(ngrido),
+     .    mfuo(ngrido,llm),mfdo(ngrido,llm),en_uo(ngrido,llm),
+     .    de_uo(ngrido,llm),en_do(ngrido,llm),
+     .    de_do(ngrido,llm),coefkzo(ngrido,llm),
+     .    frac_impao(ngrido,llm),frac_nuclo(ngrido,llm),
+     .    yu1o(ngrido),yv1o(ngrido),ftsolo(ngrido,nbsrf),
+     .    pctsrfo(ngrido,nbsrf),to(ngrido,llm) 
+
+      real airefin(ngridn),phisfin(ngridn),
+     .    mfun(ngridn,llm),en_un(ngridn,llm),mfdn(ngridn,llm),
+     .    de_un(ngridn,llm),en_dn(ngridn,llm),
+     .    de_dn(ngridn,llm),coefkzn(ngridn,llm),
+     .    frac_impan(ngridn,llm),frac_nucln(ngridn,llm),
+     .    ftsoln(ngridn,nbsrf),yu1n(ngridn),yv1n(ngridn),
+     .    pctsrfn(ngridn,nbsrf),tn(ngridn,llm)
+
+      real zcontrole(ngridn),zmass,tmpdyn(imn+1,jmn+1),zflux
+
+      real ziadvtrac,ziadvtrac2,zrec2
+      integer zim,zjm,zlm,zklon,zklev,zrec
+
+      real zpi
+
+c  longitudes et latitudes lues
+      real rlonul(imo+1,jmo+1),rlatvl(imo+1,jmo)
+      real rlonvl(imo+1,jmo),rlatul(imo+1,jmo+1)
+c  longitudes et latitudes anciennes
+      real rlonuo(0:imo+1),rlatvo(0:jmo+1)
+      real rlonvo(0:imo+1),rlatuo(0:jmo+1)
+c  longitudes et latitudes nouvelles
+      real rlonun(0:imn+1),rlatvn(0:jmn+1)
+      real rlonvn(0:imn+1),rlatun(0:jmn+1)
+      real aireo(imo+1,jmo+1)
+
+      integer ndecx(imo+1),ndecy(jmo+1)
+      real alphax(imn+1),alphay(jmn+1)
+      real alphaxo(imo+1)
+      real alpha(imn+1,jmn+1)
+       real alphat(imn+1,jmn+1,llm)
+      real aa,uu(0:imo+1),vv(imo+1,0:jmo+1)
+
+
+      integer iest(imo+1),iouest(imo+1)
+      integer jsud(jmo+1),jnord(jmo+1)
+
+      integer in,io,jn,jo,l,iin,jjn
+      integer i,j
+      real dlatm,dlatp,dlonm,dlonp
+c abd
+       character*10 file
+       character*10 nom
+       character*2 str2
+c fin ab
+      zpi=2.*asin(1.)
+
+
+c==================================================================
+c   Si le numero du record est 0 alors: INITIALISATION
+c==================================================================
+c
+      print*,'ENTREE DANS LECTFLUX'
+        print*,'IREC=',IREC
+      if(irec.eq.0) then
+
+        print*,'IREC==',0
+
+C test         call inigeom
+c==================================================================
+c   Definition des surdecoupages dans les deux directions
+c==================================================================
+
+      ndecx(1)=1
+      do io=2,imo
+         ndecx(io)=2
+      enddo
+      ndecx(imo+1)=1
+
+      ndecy(1)=1
+      do jo=2,jmo
+         ndecy(jo)=2
+      enddo
+      ndecy(jmo+1)=1
+
+      ii=0
+      do io=1,imo+1
+         ii=ii+ndecx(io)
+      enddo
+      if(ii.ne.iim) then
+         print*,'ii=',ii,'   iim=',iim
+         stop
+      endif
+
+      jj=0
+      do jo=1,jmo+1
+         jj=jj+ndecy(jo)
+      enddo
+      if(jj.ne.jjp1) then
+         print*,'jj=',jj,'   jjm=',jjm
+         stop
+      endif
+
+c==================================================================
+c   Calcul des jsud,... correspondant aux intersections des
+c   grilles.
+c==================================================================
+
+      iest(1)=0
+	print*,'iest(1)=0'
+      do io=2,imo+1
+         iest(io)=iest(io-1)+ndecx(io-1)
+         iouest(io-1)=iest(io)
+	print*,'iest(',io,')=',iest(io),'iouest('
+     s              ,io-1,')=',iouest(io-1)
+	
+      enddo
+      iouest(imo+1)=iest(imo+1)+ndecx(imo+1)
+	print*,'iouest(',imo+1,')=',iouest(imo+1)
+
+      jnord(1)=0
+	print*,'jnord(1)=0'
+      do jo=2,jmo+1
+         jnord(jo)=jnord(jo-1)+ndecy(jo-1)
+         jsud(jo-1)=jnord(jo)
+        print*,'jnord(',jo,')=',jnord(jo),'jsud('
+     s              ,jo-1,')=',jsud(jo-1)
+      enddo
+      jsud(jmo+1)=jnord(jmo+1)+ndecy(jmo+1)
+	        print*,'jsud(',jmo+1,')=',jsud(jmo+1)
+
+c==================================================================
+c   ouverture des fichiers, lecture des entetes
+c==================================================================
+	
+	CALL read_dstoke(0,zdtvr,ziadvtrac,ziadvtrac2)
+
+        CALL read_fstoke(0,
+     .   zrec,zim,zjm,zlm,
+     .   rlonul,rlonvl,rlatul,rlatvl,aireo,phiso,
+     .   massemo,pbaruo,pbarvo,wo,tetao,phio)
+      
+      print*,'zrec,zdtvr,ziadvtrac,zim,zjm,zlm'
+      print*,zrec,zdtvr,ziadvtrac,zim,zjm,zlm
+
+      nrec=zrec
+      dtvr=zdtvr
+      istdyn=ziadvtrac
+      istphy=ziadvtrac2
+
+      print*,'rlonul '
+      do io=1,imo+1
+         print*,io,rlonul(io,1)
+      enddo
+	print*,'rlonvl '
+      do io=1,imo+1
+         print*,io,rlonvl(io,1)
+      enddo
+	print*,'rlatul '
+      do jo=1,jmo+1
+         print*,jo,rlatul(1,jo)
+      enddo
+	print*,'rlatvl'
+      do jo=1,jmo
+         print*,jo,rlatvl(1,jo)
+      enddo
+      
+c      if((imo-nint(zim))*(jmo-nint(zjm)).ne.0) then
+c        print*,'Modifier les dimensions dans redecoupe '
+c        print*,'Mettre imo=',zim,'   jmo=',zjm
+c  abderr      stop
+c      endif
+
+c abderrahmane
+	if(physic)then
+	CALL read_pstoke(0,
+     .   zrec,zklon,zklev,airefio,phisfio,
+     .   to,mfuo,mfdo,en_uo,de_uo,en_do,de_do,coefkzo,
+     .   frac_impao,frac_nuclo,yu1o,yv1o,ftsolo,pctsrfo)
+	
+	print*,'Entete du fichier physique'
+        print*,zrec,zklon,zklev
+	endif
+
+
+c==================================================================
+c   Definition des anciennes latitudes et longitudes
+c   (qui pourraient etre relues plus tard)
+c==================================================================
+
+
+      do io=1,imo
+         rlonuo(io)=rlonul(io,1)*zpi/180.
+	print*,'LON ',io,rlonuo(io)*180./zpi
+      enddo
+c abderr
+      rlonuo(imo+1)=0.5*(rlonul(imo,1)+rlonul(imo+1,1))*zpi/180.
+      print*,'LON ',imo+1,rlonuo(imo+1)*180./zpi
+      rlonuo(0)=rlonuo(imo+1)-2.*zpi
+      print*,'LON ',0,rlonuo(0)*180./zpi
+
+c abder
+c ATTENTION A REVOIR
+c	goto 22
+      do io=1,imo
+         rlonvo(io)=rlonvl(io,1)*zpi/180.
+        print*,'LON ',io,rlonvo(io)*180./zpi
+      enddo
+      rlonvo(imo+1)=0.5*(rlonvl(imo,1)+rlonvl(imo+1,1))*zpi/180.
+      print*,'LON ',imo+1,rlonvo(imo+1)*180./zpi
+      rlonvo(0)=rlonvo(imo+1)-2.*zpi
+      print*,'LON ',0,rlonvo(0)*180./zpi
+22    continue
+c fin ab
+
+      rlatvo(0)=zpi/2.
+      print*,'LAT ',0,rlatvo(0)*180./zpi
+      do jo=1,jmo
+        rlatvo(jo)=rlatvl(1,jo)*zpi/180.
+	print*,'LAT ',jo,rlatvo(jo)*180./zpi
+      enddo
+	rlatvo(jmo+1)=-zpi/2.
+	print*,'LAT ',jmo+1,rlatvo(jmo+1)*180./zpi
+c abd
+c ATTENTION A REVOIR
+c	goto 33
+c      rlatuo(0)=zpi/2.
+c      print*,'LAT ',0,rlatuo(0)*180./zpi
+      do jo=1,jmo+1
+        rlatuo(jo-1)=rlatul(1,jo)*zpi/180.
+        print*,'LAT ',jo-1,rlatuo(jo-1)*180./zpi
+      enddo
+        rlatuo(jmo+1)=-zpi/2.
+        print*,'LAT ',jmo+1,rlatuo(jmo+1)*180./zpi
+33    continue
+c abd
+
+      do io=2,imo
+         alphaxo(io)=1.
+      enddo
+      alphaxo(1)=(rlonuo(1)-rlonuo(0))
+     s        /(rlonuo(1)-rlonuo(0)+rlonuo(imo+1)-rlonuo(imo))
+      alphaxo(imo+1)=1.-alphaxo(1)
+
+c==================================================================
+c    Definition des nouvelles latitudes et longitudes
+c==================================================================
+
+c Nouvelles longitudes rlonun
+      rlonun(0)=rlonuo(0)
+      do io=1,imo+1
+         do iin=1,iouest(io)-iest(io)
+            in=iin+iest(io)
+            rlonun(in)=
+     s      rlonuo(io-1)+iin*(rlonuo(io)-rlonuo(io-1))
+     s      /ndecx(io)
+            alphax(in)=alphaxo(io)/ndecx(io)
+            print787,io,rlonuo(io-1)*180./zpi,in
+     s  ,iest(io),iouest(io),rlonun(in)*180./zpi,alphax(in)
+         enddo
+      enddo
+
+c Nouvelles longitudes rlonvn
+c	goto 44
+      rlonvn(0)=rlonvo(0)
+      do io=1,imo+1
+         do iin=1,iouest(io)-iest(io)
+            in=iin+iest(io)
+            rlonvn(in)=
+     s      rlonvo(io-1)+iin*(rlonvo(io)-rlonvo(io-1))
+     s      /ndecx(io)
+            alphax(in)=alphaxo(io)/ndecx(io)
+            print787,io,rlonvo(io-1)*180./zpi,in
+     s  ,iest(io),iouest(io),rlonvn(in)*180./zpi,alphax(in)
+         enddo
+      enddo
+44    continue
+
+c Nouvelles latitudes rlatvn
+      rlatvn(0)=0.5*zpi
+      do jo=1,jmo+1
+         do jjn=1,jsud(jo)-jnord(jo)
+            jn=jnord(jo)+jjn
+            rlatvn(jn)=
+     s      rlatvo(jo-1)+jjn*(rlatvo(jo)-rlatvo(jo-1))
+     s      /ndecy(jo)
+            alphay(jn)=(sin(rlatvn(jn-1))-sin(rlatvn(jn)))
+     s                /(sin(rlatvo(jo-1))-sin(rlatvo(jo)))
+           print*,jn,rlatvn(jn)*180./zpi
+         enddo
+      enddo
+
+c Nouvelles latitudes rlatun
+c	goto 55
+      rlatun(0)=0.5*zpi
+      do jo=1,jmo+1
+         do jjn=1,jsud(jo)-jnord(jo)
+            jn=jnord(jo)+jjn
+            rlatun(jn)=
+     s      rlatuo(jo-1)+jjn*(rlatuo(jo)-rlatuo(jo-1))
+     s      /ndecy(jo)
+           print*,jn,rlatvn(jn)*180./zpi
+         enddo
+      enddo
+55    continue
+
+787   format(i5,f10.2,3(i5),2(f12.6))
+      do in=1,imn
+         rlonu(in)=rlonun(in)
+         rlonv(in)=0.5*(rlonun(in)+rlonun(in-1))
+      enddo
+      rlonv(imn+1)=rlonv(1)+2.*zpi
+      rlonu(imn+1)=rlonu(1)+2.*zpi
+
+      do jn=1,jmn
+         rlatv(jn)=rlatvn(jn)
+      enddo
+      do jn=1,jmn+1
+         rlatu(jn)=0.5*(rlatvn(jn-1)+rlatvn(jn))
+      enddo
+
+      do jn=1,jmn+1
+         do in=1,imn
+            alpha(in,jn)=alphax(in)*alphay(jn)
+	    alphat(in,jn,1)=alpha(in,jn)
+         enddo
+         alpha(imn+1,jn)=0.
+	 alphat(imn+1,jn,1)=0.
+      enddo
+c abderr 19 4 00
+	do l=2,llm
+	 do jn=1,jmn+1
+         do in=1,imn+1
+	  alphat(in,jn,l)=alphat(in,jn,1)
+         enddo
+	 enddo
+        enddo
+c     call dump2d(iip1,jjp1,alpha,'ALPHA   ')
+
+c      .  on a :  cu(i,j) = rad * COS(y) * dx/dX         .
+c      .          cv( j ) = rad          * dy/dY         .
+c   A 1 point scalaire P (i,j) de la grille, reguliere en (X,Y) , sont
+c   affectees 4 aires entourant P , calculees respectivement aux points
+c            ( i + 1/4, j - 1/4 )    :    aireij1 (i,j)
+c            ( i + 1/4, j + 1/4 )    :    aireij2 (i,j)
+c            ( i - 1/4, j + 1/4 )    :    aireij3 (i,j)
+c            ( i - 1/4, j - 1/4 )    :    aireij4 (i,j)
+c
+c                             . V
+c
+c                 aireij4 .        . aireij1
+c
+c                   U .       . P      . U
+c
+c                 aireij3 .        . aireij2
+c
+c                             . V
+
+
+      do j=1,jjp1
+         do i=1,iim
+            dlonp=rlonun(i)-rlonv(i)
+            dlonm=rlonv(i)-rlonun(i-1)
+            dlatp=sin(rlatvn(j-1))-sin(rlatu(j))
+            dlatm=sin(rlatu(j))-sin(rlatvn(j))
+            aireij1 ( i,j ) = rad*rad*dlatp*dlonp
+            aireij2 ( i,j ) = rad*rad*dlatm*dlonp
+            aireij3 ( i,j ) = rad*rad*dlatm*dlonm
+            aireij4 ( i,j ) = rad*rad*dlatp*dlonm
+      aire    ( i,j )  = aireij1(i,j) + aireij2(i,j) + aireij3(i,j) +
+     *                          aireij4(i,j)
+      alpha1  ( i,j )  = aireij1(i,j) / aire(i,j)
+      alpha2  ( i,j )  = aireij2(i,j) / aire(i,j)
+      alpha3  ( i,j )  = aireij3(i,j) / aire(i,j)
+      alpha4  ( i,j )  = aireij4(i,j) / aire(i,j)
+      alpha1p2( i,j )  = alpha1 (i,j) + alpha2 (i,j)
+      alpha1p4( i,j )  = alpha1 (i,j) + alpha4 (i,j)
+      alpha2p3( i,j )  = alpha2 (i,j) + alpha3 (i,j)
+      alpha3p4( i,j )  = alpha3 (i,j) + alpha4 (i,j)
+           enddo
+           aireij1(iip1,j)=aireij1(1,j)
+           aireij2(iip1,j)=aireij2(1,j)
+           aireij3(iip1,j)=aireij3(1,j)
+           aireij4(iip1,j)=aireij4(1,j)
+           aire(iip1,j)=aire(1,j)
+           alpha1(iip1,j)=alpha1(1,j)
+           alpha2(iip1,j)=alpha2(1,j)
+           alpha3(iip1,j)=alpha3(1,j)
+           alpha4(iip1,j)=alpha4(1,j)
+           alpha1p2(iip1,j)=alpha1p2(1,j)
+           alpha1p4(iip1,j)=alpha1p4(1,j)
+           alpha2p3(iip1,j)=alpha2p3(1,j)
+           alpha3p4(iip1,j)=alpha3p4(1,j)
+       enddo
+c     call dump2d(iip1,jjp1,aire,'AIRE   ')
+
+      DO 42 j = 1,jjp1
+      DO 41 i = 1,iim
+      unsaire(i,j) = 1./ aire(i,j)
+      aireu  (i,j) = aireij1(i,j) + aireij2(i,j) + aireij4(i+1,j) +
+     *                           aireij3(i+1,j)
+  41  CONTINUE
+      aireu  (iip1,j) = aireu  (1,j)
+      unsaire(iip1,j) = unsaire(1,j)
+  42  CONTINUE
+      DO 48 j = 1,jjm
+        DO i=1,iim
+         airev(i,j)     = aireij2(i,j)+ aireij3(i,j)+ aireij1(i,j+1) +
+     *                           aireij4(i,j+1)
+        ENDDO
+       airev   (iip1,j) = airev(1,j)
+  48  CONTINUE
+      apoln=0.
+      apols=0.
+      do i=1,iim
+         apoln=apoln+aire(i,1)
+         apols=apols+aire(i,jjp1)
+      enddo
+
+
+
+      do jn=1,jjp1
+         do in=1,iim
+            cu(in,jn)=rad*cos(rlatu(jn))*(rlonv(in+1)-rlonv(in))
+         enddo
+         cu(iip1,jn)=cu(1,jn)
+      enddo
+      do jn=1,jjm
+         do in=1,iim+1
+            cv(in,jn)=rad*(rlatu(jn)-rlatu(jn+1))
+         enddo
+      enddo
+	Print*,'Fin irec=0'
+	go to 435
+      file='pbur'
+      call inigrads(11,iip1
+     s  ,rlonu,180./pi,-180.,180.,jjp1,rlatu,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,1800.,file,'gcmq2 ')
+      file='pbvr'
+      call inigrads(12,iip1
+     s  ,rlonv,180./pi,-180.,180.,jjm,rlatv,-90.,90.,180./pi
+     s  ,llm,presnivs,1.
+     s  ,1800.,file,'gcmq2 ')
+435   continue
+c==================================================================
+c   Fin des initialisations
+      else ! irec=0
+c==================================================================
+
+
+c-----------------------------------------------------------------------
+c   Lecture des fichiers fluxmass et  physique:
+c   -----------------------------------------------------
+	print*,'Entrer dans read_fstoke a irec=',irec
+	CALL read_fstoke(irec,
+     .   zrec,zim,zjm,zlm,
+     .   rlonul,rlonvl,rlatul,rlatvl,aireo,phiso,
+     .   massemo,pbaruo,pbarvo,wo,tetao,phio)
+
+	print*,'Apres read_fstoke a irec=',irec
+
+c	do l=1,llm
+c           do j=1,jmo
+c              do i=1,imo+1
+c                 pbarvo(i,j,l)=pbarvst(i,j,l)
+c              enddo
+c           enddo
+c        enddo
+
+         do l=1,llm
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+c                        wn(in,jn,l)=alpha(in,jn)*wo(io,jo,l)
+c                        massemn(in,jn,l)=alpha(in,jn)
+		       wn(in,jn,l)=alphat(in,jn,l)*wo(io,jo,l)
+		       massemn(in,jn,l)=alphat(in,jn,l)
+     s                                *massemo(io,jo,l)
+                        tetan(in,jn,l)=tetao(io,jo,l)
+                        phin(in,jn,l)=phio(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               wn(imn+1,jn,l)=wn(1,jn,l)
+               massemn(imn+1,jn,l)=massemn(1,jn,l)
+               tetan(imn+1,jn,l)=tetan(1,jn,l)
+               phin(imn+1,jn,l)=phin(1,jn,l)
+            enddo
+         enddo
+c Test massemn
+	print*,'MASSE DANS LA NOUVELLE GRILLE'
+	goto 908
+	do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+	print*,'massemn(',in,jn,1,')=',massemn(in,jn,1)
+        	     enddo
+                  enddo
+               enddo
+	enddo
+	do jn=1,jmn+1
+	print*,'massemn(',imn+1,jn,1,')=',massemn(imn+1,jn,1)
+        enddo
+908     continue
+	print*,'Fin calcul de massemn pour nouv. gril.'
+         do l=1,llm
+            do jo=1,jmo+1
+               uu(imo+1)=0.5*(pbaruo(imo,jo,l)+pbaruo(imo+1,jo,l))
+               uu(0)=uu(imo+1)
+               do io=1,imo
+                  uu(io)=pbaruo(io,jo,l)
+               enddo
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     aa=0.
+                     do in=iest(io)+1,iouest(io)
+                        aa=aa+alphax(in)
+                        pbarun(in,jn,l)=alphay(jn)*
+     s                    (uu(io-1)+aa*(uu(io)-uu(io-1)))
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               pbarun(imn+1,jn,l)=pbarun(1,jn,l)
+            enddo
+         enddo
+	print*,'Fin calcul de pbarun'
+	
+	do l=1,llm
+            do jo=1,jmo
+               do io=1,imo+1
+                  vv(io,jo)=pbarvo(io,jo,l)
+               enddo
+            enddo
+            do io=1,imo+1
+               vv(io,0)=0.
+               vv(io,jmo+1)=0.
+            enddo
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  aa=0.
+c                 do jn=jnord(jo)+1,max(jsud(jo),jmo)
+                  do jn=jnord(jo)+1,min(jsud(jo),jmn)
+                     aa=aa+alphay(jn)
+                     do in=iest(io)+1,iouest(io)
+                        pbarvn(in,jn,l)=alphax(in)*
+     s                  (vv(io,jo-1)+aa*(vv(io,jo)-vv(io,jo-1)))
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn
+               pbarvn(iip1,jn,l)=pbarvn(1,jn,l)
+            enddo
+         enddo
+
+c abd
+	go to 456
+ 	nom='pbaru'
+        call wrgrads(11,llm,pbarun(:,:,1),nom,nom)
+        nom='pbarv'
+        call wrgrads(12,llm,pbarvn(:,:,1),nom,nom)
+        nom='masse'
+        call wrgrads(11,llm,massemn(:,:,1),nom,nom)
+        nom='w'
+        call wrgrads(11,llm,wn(:,:,1),nom,nom)
+456	continue
+c fin ab
+
+	if(physic)then
+        CALL read_pstoke(irec,
+     .   zrec,zklon,zklev,airefio,phisfio,
+     .   to,mfuo,mfdo,en_uo,de_uo,en_do,de_do,coefkzo,
+     .   frac_impao,frac_nuclo,yu1o,yv1o,ftsolo,pctsrfo)
+       	print*,'OK read_pstoke pour irec=',irec
+c==================================================================
+c  Passage  a la nouvelle grille
+c==================================================================
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,to,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=to(1,l)
+                tmpo2(imo+1,jmo+1,l)=to(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,tn)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+
+	call gr_fi_ecrit(llm,ngrido,imo,jmo+1,mfuo,tmpo1)
+	do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+		tmpo2(imo+1,1,l)=mfuo(1,l)
+                tmpo2(imo+1,jmo+1,l)=mfuo(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+		tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+	enddo
+	call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,mfun)
+	call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+	call initial0(llm*imo*(jmo+1),tmpo1)
+	call initial0(llm*imn*(jmn+1),tmpn1)
+	call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,mfdo,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=mfdo(1,l)
+                tmpo2(imo+1,jmo+1,l)=mfdo(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,mfdn)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,en_uo,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=en_uo(1,l)
+                tmpo2(imo+1,jmo+1,l)=en_uo(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,en_un)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,en_do,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=en_do(1,l)
+                tmpo2(imo+1,jmo+1,l)=en_do(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,en_dn)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,de_do,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=de_do(1,l)
+                tmpo2(imo+1,jmo+1,l)=de_do(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,de_dn)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,de_uo,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=de_uo(1,l)
+                tmpo2(imo+1,jmo+1,l)=de_uo(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,de_un)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,coefkzo,tmpo1)
+	do l=1,llm
+	   do jo=1,jmo+1
+	      do io=1,imo
+		tmpo2(io,jo,l)=tmpo1(io,jo,l)
+	      enddo
+	   enddo
+
+           tmpo2(imo+1,1,l)=coefkzo(1,l)
+           tmpo2(imo+1,jmo+1,l)=coefkzo(ngrido,l)
+
+           do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo2(1,jo,l)
+           enddo
+	enddo
+	      
+c   passage a la grillle dynamique nouvelle
+	do l=1,llm	
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,coefkzn)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,frac_impao,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=frac_impao(1,l)
+                tmpo2(imo+1,jmo+1,l)=frac_impao(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,frac_impan)
+        call initial0(llm*(imo+1)*(jmo+1),tmpo2)
+        call initial0(llm*imo*(jmo+1),tmpo1)
+        call initial0(llm*imn*(jmn+1),tmpn1)
+        call initial0(llm*(imn+1)*(jmn+1),tmpn2)
+        call gr_fi_ecrit(llm,ngrido,imo,jmo+1,frac_nuclo,tmpo1)
+        do l=1,llm
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo2(io,jo,l)=tmpo1(io,jo,l)
+              enddo
+           enddo
+
+                tmpo2(imo+1,1,l)=frac_nuclo(1,l)
+                tmpo2(imo+1,jmo+1,l)=frac_nuclo(ngrido,l)
+            do jo=2,jmo
+                tmpo2(imo+1,jo,l)=tmpo1(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn2(in,jn,l)=tmpo2(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn1(in,jn,l)=tmpn2(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(llm,ngridn,imn,jmn+1,tmpn1,frac_nucln)
+
+        call gr_fi_ecrit(nbsrf,ngrido,imo,jmo+1,ftsolo,tmpo3)
+        do l=1,nbsrf
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo4(io,jo,l)=tmpo3(io,jo,l)
+              enddo
+           enddo
+
+                tmpo4(imo+1,1,l)=ftsolo(1,l)
+                tmpo4(imo+1,jmo+1,l)=ftsolo(ngrido,l)
+            do jo=2,jmo
+                tmpo4(imo+1,jo,l)=tmpo3(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn4(in,jn,l)=tmpo3(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn3(in,jn,l)=tmpn4(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(nbsrf,ngridn,imn,jmn+1,tmpn3,ftsoln)
+
+        call initial0(nbsrf*(imo+1)*(jmo+1),tmpo4)
+        call initial0(nbsrf*imo*(jmo+1),tmpo3)
+        call initial0(nbsrf*imn*(jmn+1),tmpn3)
+        call initial0(nbsrf*(imn+1)*(jmn+1),tmpn4)
+        call gr_fi_ecrit(nbsrf,ngrido,imo,jmo+1,pctsrfo,tmpo3)
+        do l=1,nbsrf
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo4(io,jo,l)=tmpo3(io,jo,l)
+              enddo
+           enddo
+
+                tmpo4(imo+1,1,l)=pctsrfo(1,l)
+                tmpo4(imo+1,jmo+1,l)=pctsrfo(ngrido,l)
+            do jo=2,jmo
+                tmpo4(imo+1,jo,l)=tmpo3(1,jo,l)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn4(in,jn,l)=tmpo3(io,jo,l)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn3(in,jn,l)=tmpn4(in,jn,l)
+               enddo
+            enddo
+        enddo
+        call gr_ecrit_fi(nbsrf,ngridn,imn,jmn+1,tmpn3,pctsrfn)
+
+        call gr_fi_ecrit(1,ngrido,imo,jmo+1,yv1o,tmpo5)
+
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo6(io,jo)=tmpo5(io,jo)
+              enddo
+           enddo
+
+                tmpo6(imo+1,1)=yv1o(1)
+                tmpo6(imo+1,jmo+1)=yv1o(ngrido)
+            do jo=2,jmo
+                tmpo6(imo+1,jo)=tmpo5(1,jo)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn6(in,jn)=tmpo5(io,jo)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn5(in,jn)=tmpn6(in,jn)
+               enddo
+            enddo
+        call gr_ecrit_fi(1,ngridn,imn,jmn+1,tmpn5,yv1n)
+
+        call initial0((imo+1)*(jmo+1),tmpo6)
+        call initial0(imo*(jmo+1),tmpo5)
+        call initial0(imn*(jmn+1),tmpn5)
+        call initial0((imn+1)*(jmn+1),tmpn6)
+        call gr_fi_ecrit(1,ngrido,imo,jmo+1,yu1o,tmpo5)
+
+           do jo=1,jmo+1
+              do io=1,imo
+                tmpo6(io,jo)=tmpo5(io,jo)
+              enddo
+           enddo
+
+                tmpo6(imo+1,1)=yu1o(1)
+                tmpo6(imo+1,jmo+1)=yu1o(ngrido)
+            do jo=2,jmo
+                tmpo6(imo+1,jo)=tmpo5(1,jo)
+            enddo
+c   passage a la grillle dynamique nouvelle
+            do jo=1,jmo+1
+               do io=1,imo+1
+                  do jn=jnord(jo)+1,jsud(jo)
+                     do in=iest(io)+1,iouest(io)
+                        tmpn6(in,jn)=tmpo5(io,jo)
+                     enddo
+                  enddo
+               enddo
+            enddo
+            do jn=1,jmn+1
+               do in=1,imn
+                tmpn5(in,jn)=tmpn6(in,jn)
+               enddo
+            enddo
+        call gr_ecrit_fi(1,ngridn,imn,jmn+1,tmpn5,yu1n)
+c==================================================================
+	if (avant) then
+c Simu directe
+         do l=1,llm
+          do ig=1,ngridn
+	     zmfd(ig,l)=mfdn(ig,l)
+             zmfu(ig,l)=mfun(ig,l)
+             zen_d(ig,l)=en_dn(ig,l)
+             zde_d(ig,l)=de_dn(ig,l)
+             zen_u(ig,l)=en_un(ig,l)
+             zde_u(ig,l)=de_un(ig,l)
+          enddo
+       enddo
+      else
+c   Simu retro
+       do l=1,llm
+          do ig=1,ngridn
+             zmfd(ig,l)=-mfdn(ig,l)
+             zmfu(ig,l)=-mfun(ig,l)
+             zen_d(ig,l)=en_dn(ig,l)
+             zde_d(ig,l)=de_dn(ig,l)
+             zen_u(ig,l)=en_un(ig,l)
+             zde_u(ig,l)=de_un(ig,l)
+          enddo
+       enddo
+      endif
+
+c-----------------------------------------------------------------------
+c   PETIT CONTROLE SUR LES FLUX CONVECTIFS...
+c-----------------------------------------------------------------------
+
+         call gr_dyn_fi(llm,iip1,jjp1,ngridn,massemn,massefi)
+
+      print*,'Ap redec irec'
+         do ig=1,ngridn
+            zcontrole(ig)=1.
+         enddo
+c   zmass=(max(massemn(ig,l),massemn(ig,l-1))/airefin(ig)
+         do l=2,llm
+            do ig=1,ngridn
+               zmass=max(massefi(ig,l),massefi(ig,l-1))/airefin(ig)
+               zflux=max(abs(zmfu(ig,l)),abs(zmfd(ig,l)))*dtphys
+               if(zflux.gt.0.9*zmass) then
+                 zcontrole(ig)=min(zcontrole(ig),0.9*zmass/zflux)
+               endif
+            enddo
+         enddo
+
+         do ig=1,ngridn
+            if(zcontrole(ig).lt.0.99999) then
+               print*,'ATTENTION !!! on reduit les flux de masse '
+               print*,'convectifs au point ig=',ig
+            endif
+         enddo
+
+         call gr_fi_dyn(1,ngridn,iip1,jjp1,zcontrole,tmpdyn)
+
+         do l=1,llm
+            do ig=1,ngridn
+               zmfu(ig,l)=zmfu(ig,l)*zcontrole(ig)
+               zmfd(ig,l)=zmfd(ig,l)*zcontrole(ig)
+               zen_u(ig,l)=zen_u(ig,l)*zcontrole(ig)
+               zde_u(ig,l)=zde_u(ig,l)*zcontrole(ig)
+               zen_d(ig,l)=zen_d(ig,l)*zcontrole(ig)
+               zde_d(ig,l)=zde_d(ig,l)*zcontrole(ig)
+            enddo
+         enddo
+	endif ! physic
+
+      endif ! irec=0
+
+
+      RETURN
+      END
+
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/run.def
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/run.def	(revision 3)
+++ 	(revision )
@@ -1,187 +1,0 @@
-
------------------------------------------------------------------------ 
-Parametres de controle du run:                                          
-------------------------------                                          
-
-- Jour de l'etat initial ( = 350  si 20 Decembre ,par expl. ,comme ici ) 
-   dayref
- 350
-
--  Annee de l'etat  initial (   avec  4  chiffres   )                        
-   anneeref
- 1987
-
-- Nombre de jours d'integration                                         
-     nday
- 2
-
-- nombre de pas par jour (multiple de iperiod) ( ici pour  dt = 1 min )      
- day_step
- 1440
-
-- periode pour le pas Matsuno (en pas)                                  
-  iperiod
- 5
-
-- periode de sortie des variables de controle (en pas)                  
-  iconser
- 5
-
-- periode d'ecriture du fichier histoire (en jour)                      
-    iecri
- 100
-
-- periode de stockage fichier histmoy (en jour)                         
- periodav
- 60.
-
-- periode de la dissipation (en pas)                                    
-  idissip
- 10
-
-- choix de l'operateur de dissipation (star ou  non star )              
- lstardis
- T
-
-- nombre d'iterations de l'operateur de dissipation   gradiv            
-nitergdiv
- 1
-
-- nombre d'iterations de l'operateur de dissipation  nxgradrot          
-nitergrot
- 2
-
-- nombre d'iterations de l'operateur de dissipation  divgrad            
-   niterh
- 2
-
-- temps de dissipation des plus petites long.d ondes pour u,v (gradiv)  
- tetagdiv
- 3000.
-
-- temps de dissipation des plus petites long.d ondes pour u,v(nxgradrot)
- tetagrot
- 3000.
-
-- temps de dissipation des plus petites long.d ondes pour  h ( divgrad) 
- tetatemp
- 3000.
-
-- coefficient pour gamdissip                                            
-  coefdis
- 0.
-
-- choix du shema d'integration temporelle (Matsuno ou Matsuno-leapfrog) 
-  purmats
- F
-
-- avec ou sans physique                                                 
-   physic
- T
-
-- periode de la physique (en pas)                                       
-  iphysiq
- 15
-
-- frequence (en  jours ) de l'ecriture du fichier histphy               
- ecritphy
- 4
-
--  Cycle diurne  ou non                 
- cycle_diurne
- T
-
--  Soil Model  ou non               
- soil_model
- F
-
--  Choix ou non  de  New oliq               
- new_oliq
- T
-
--  Orodr  ou  non   pour l orographie              
-  ok_orodr
- T
-
--  Orolf  ou  non   pour l orographie              
-  ok_orolf
- T
-
--   Si = .T. ,  lecture du fichier limit avec la bonne annee             
-  ok_limitvrai
- T
-
-- Nombre  d'appels des routines de rayonnements ( par jour)                 
-  nbapp_rad
- 12
-
--  Flag  pour la convection ( 1 pour LMD,  2 pour Tiedtke, 3  CCM )             
-  iflag_con
- 2
-
-- longitude en degres du centre du zoom                                 
-   clon
- 63.
-
-- latitude en degres du centre du zoom                                  
-   clat
- 0.
-
-- facteur de grossissement du zoom,selon longitude                      
-  grossismx
- 2.5
-
-- facteur de grossissement du zoom ,selon latitude                      
- grossismy
- 2.5
-
--  Fonction  f(y)  hyperbolique  si = .true.  , sinon  sinusoidale         
-  fxyhypb
- T
-
-- extension en longitude  de la zone du zoom  ( fraction de la zone totale)
-   dzoomx
- 0.291667
-
-- extension en latitude de la zone  du zoom  ( fraction de la zone totale)
-   dzoomy
- 0.291667
-
--  Fonction  f(y) avec y = Sin(latit.) si = .true. , sinon y = latit.         
-  ysinus
- T
-
-c
-cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-cc
-c   Autres  parametres ou cles  , non places dans run.def  mais
-c             dans les routines .
-cc
-ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-cc
-cc  A )   iadv(iq )  , iq =1, nqmx , avec  iadv = 1  , shema humid.
-cc                                                  specifique LMD
-cc
-cc                                avec  iadv = 2  , shema amont
-cc
-cc                (  avec a l'interieur de amont , la cle amont_qs ) 
-cc
-cc                                avec  iadv = 3 , shema Van_Leer
-cc
-cc                                           dans  ***  gcm.F  ****
-cc 
-cc  B )  ok_oasis   , pour coupleur Oasis  , dans  *** physiq.F ***
-cc
-cc  C )  ok_ocean                            dans  *** physiq.F ***
-cc
-cc  D )  ok_journe , ok_instan, ok_region   pour sorties analyses
-c
-cc                                           dans  *** physiq.F ***
-cc
-cc  E ) nvm  : nbre  de vegetations    
-cc                                           dans  *** physiq.F ***
-
-cc  F ) deltay : deplacement ( en degres ) en  y  de la zone du zoom
-cc                                          dans  *** inigeom.F ***
-
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/serre.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/serre.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/serre.h	(revision 253)
@@ -1,6 +1,9 @@
+c
+c $Header$
+c
 c..include serre.h
 c
        REAL clon,clat,transx,transy,alphax,alphay,pxo,pyo,
-     ,  grossismx, grossismy, dzoomx, dzoomy
+     ,  grossismx, grossismy, dzoomx, dzoomy,taux,tauy
        COMMON/serre/clon,clat,transx,transy,alphax,alphay,pxo,pyo , 
-     ,  grossismx, grossismy, dzoomx, dzoomy
+     ,  grossismx, grossismy, dzoomx, dzoomy,taux,tauy
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/sortvarc0.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/sortvarc0.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/sortvarc0.F	(revision 253)
@@ -1,4 +1,5 @@
       SUBROUTINE sortvarc0
-     $(itau,ucov,teta,ps,masse,pk,phis,vorpot,phi,bern,dp,time )
+     $(itau,ucov,teta,ps,masse,pk,phis,vorpot,phi,bern,dp,time ,
+     $ vcov)
       IMPLICIT NONE
 
@@ -32,4 +33,5 @@
       INTEGER itau
       REAL ucov(ip1jmp1,llm),teta(ip1jmp1,llm),masse(ip1jmp1,llm)
+      REAL vcov(ip1jm,llm)
       REAL ps(ip1jmp1),phis(ip1jmp1)
       REAL vorpot(ip1jm,llm)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/startvar.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/startvar.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/startvar.F	(revision 253)
@@ -316,4 +316,5 @@
      . iml-1, jml, lon_in, lat_in, 
      . phis, relief, zstd, zsig, zgam, zthe, zpic, zval, tmp_int)
+      phis = phis * 9.81
     !
       masque(:,:) = FLOAT(tmp_int(:,:))
@@ -660,5 +661,5 @@
               DO il=1,lml
                 xppn = SUM(aire(:,1)*champ(:,1,il))/apoln
-                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apoln
+                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
                 champ(:,1,il) = xppn
                 champ(:,jml,il) = xpps
@@ -689,5 +690,5 @@
               DO il=1,lml
                 xppn = SUM(aire(:,1)*champ(:,1,il))/apoln
-                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apoln
+                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
                 champ(:,1,il) = xppn
                 champ(:,jml,il) = xpps
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/temps.inc
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/temps.inc	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/temps.inc	(revision 253)
@@ -0,0 +1,11 @@
+!-----------------------------------------------------------------------
+! INCLUDE 'temps.h'
+
+      COMMON/temps/itaufin,dt, &
+     &  day_ini,day_end,anne_ini
+
+      INTEGER  itaufin
+      INTEGER*4 day_ini,day_end,anne_ini
+      REAL     dt
+
+!-----------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/tracvl.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/tracvl.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/tracvl.F	(revision 253)
@@ -1,4 +1,4 @@
       SUBROUTINE tracvl(numvanle,iapp_tracvl,nq,pbaru,pbarv ,
-     *                            p,  masse , q, iapptrac    )
+     *                    p, masse , q, iapptrac, iadv1, teta, pk  )
 c
 c     Auteur :  F. Hourdin
@@ -6,4 +6,6 @@
 c
 ccc   ..   Modif. P. Le Van  ( 20/12/97 )  ...
+c                 F. Codron     (10/99)
+
 c
       IMPLICIT NONE
@@ -15,10 +17,15 @@
 #include "comgeom.h"
 
-      INTEGER nq,iapp_tracvl
+c     .... Arguments  ....
+c
+      INTEGER numvanle, nq, iapp_tracvl, iapptrac, iadv1
 
       REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
       REAL q(ip1jmp1,llm,nq),masse(ip1jmp1,llm)
-      REAL p( ip1jmp1,llmp1 )
+      REAL p( ip1jmp1,llmp1 ),teta(ip1jmp1,llm)
+      REAL pk(ip1jmp1,llm)
 
+c     ....  var. locales  .....
+c
       REAL pbaruc(ip1jmp1,llm),pbarvc(ip1jm,llm)
       REAL massem(ip1jmp1,llm),zdp(ip1jmp1)
@@ -26,13 +33,13 @@
       REAL pbarug(ip1jmp1,llm),pbarvg(ip1jm,llm),wg(ip1jmp1,llm)
 
-      INTEGER iapptrac
 
-      INTEGER iadvtr, numvanle
+      INTEGER iadvtr, numvan
       INTEGER ij,l,iq
       REAL zdpmin, zdpmax
       EXTERNAL  minmax
- 
-      SAVE iadvtr, massem,pbaruc,pbarvc
+      SAVE iadvtr, massem, pbaruc, pbarvc, numvan
       DATA iadvtr/0/
+
+      numvan = numvanle
 
       IF(iadvtr.EQ.0) THEN
@@ -99,5 +106,14 @@
 
 c   Advection proprement dite.
-         DO iq = numvanle, nq
+c
+c   test sur iadv1 pour le schema de vapeur d'eau
+c
+         IF (numvanle.EQ.1.AND.iadv1.EQ.4) THEN
+           CALL vlspltqs( q(1,1,1), 2., massem, wg ,
+     *                 pbarug,pbarvg,dtvr,p,pk,teta )
+           numvan = 2
+         ENDIF
+
+         DO iq = numvan, nq
           CALL vlsplt( q(1,1,iq), 2. ,massem,wg,pbarug,pbarvg,dtvr )
          ENDDO
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/vanleer.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/dyn3d/vanleer.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/vanleer.F	(revision 253)
@@ -1,8 +1,10 @@
       SUBROUTINE vanleer(numvanle,iapp_tracvl,nq,q,pbaru,pbarv ,
-     *                                    p ,masse,  dq          )
+     *                     p ,masse, dq ,  iadv1, teta, pk      )
 c
       IMPLICIT NONE
 c
-c     Auteurs:   F.Hourdin , P.Le Van, F.Forget 
+c     Auteurs:   F.Hourdin , P.Le Van, F.Forget, F.Codron  
+c
+c     F.Codron (10/99) : ajout humidite specifique pour eau vapeur
 c=======================================================================
 c
@@ -18,8 +20,8 @@
 c   Arguments:
 c   ----------
-      INTEGER nq,numvanle,iapp_tracvl 
+      INTEGER nq, numvanle, iapp_tracvl, iadv1 
       REAL pbaru( ip1jmp1,llm ),pbarv( ip1jm,llm),masse(ip1jmp1,llm)
       REAL p( ip1jmp1,llmp1),q( ip1jmp1,llm,nq),dq( ip1jmp1,llm,nq )
-
+      REAL teta( ip1jmp1,llm),pk( ip1jmp1,llm)
 c  ..................................................................
 c
@@ -28,4 +30,6 @@
 c     numvanle est le numero du premier traceur qui appelle le
 c       shema de Van-Leer  (  1<=  numvanle <=  nqmx )  .
+c     si numvanle=1, iadv1=3 si Van-Leer seul, iadv1=4 si 
+c     Van-Leer+humidite specifique.
 c  ..................................................................
 c
@@ -61,5 +65,5 @@
 
       CALL tracvl( numvanle,iapp_tracvl,nq,pbaru,pbarv,p , masse,q  ,
-     *                                iapptrac                       )
+     *                      iapptrac, iadv1, teta ,pk              )
 
       IF( numvanle.EQ.1 ) THEN
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/vlspltqs.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/vlspltqs.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/dyn3d/vlspltqs.F	(revision 253)
@@ -0,0 +1,774 @@
+       SUBROUTINE vlspltqs ( q,pente_max,masse,w,pbaru,pbarv,pdt,
+     ,                                  p,pk,teta                 )
+c
+c     Auteurs:   P.Le Van, F.Hourdin, F.Forget, F.Codron 
+c
+c    ********************************************************************
+c          Shema  d'advection " pseudo amont " .
+c      + test sur humidite specifique: Q advecte< Qsat aval
+c                   (F. Codron, 10/99)
+c    ********************************************************************
+c     q,pbaru,pbarv,w sont des arguments d'entree  pour le s-pg ....
+c
+c     pente_max facteur de limitation des pentes: 2 en general
+c                                                0 pour un schema amont
+c     pbaru,pbarv,w flux de masse en u ,v ,w
+c     pdt pas de temps
+c
+c     teta temperature potentielle, p pression aux interfaces,
+c     pk exner au milieu des couches necessaire pour calculer Qsat
+c   --------------------------------------------------------------------
+      IMPLICIT NONE
+c
+#include "dimensions.h"
+#include "paramet.h"
+#include "logic.h"
+#include "comvert.h"
+#include "comconst.h"
+
+c
+c   Arguments:
+c   ----------
+      REAL masse(ip1jmp1,llm),pente_max
+      REAL pbaru( ip1jmp1,llm ),pbarv( ip1jm,llm)
+      REAL q(ip1jmp1,llm)
+      REAL w(ip1jmp1,llm),pdt
+      REAL p(ip1jmp1,llmp1),teta(ip1jmp1,llm),pk(ip1jmp1,llm)
+c
+c      Local 
+c   ---------
+c
+      INTEGER i,ij,l,j,ii
+c
+      REAL qsat(ip1jmp1,llm)
+      REAL zm(ip1jmp1,llm)
+      REAL mu(ip1jmp1,llm)
+      REAL mv(ip1jm,llm)
+      REAL mw(ip1jmp1,llm+1)
+      REAL zq(ip1jmp1,llm)
+      REAL temps1,temps2,temps3
+      REAL zzpbar, zzw
+      LOGICAL testcpu
+      SAVE testcpu
+      SAVE temps1,temps2,temps3
+
+      REAL qmin,qmax
+      DATA qmin,qmax/0.,1.e33/
+      DATA testcpu/.false./
+      DATA temps1,temps2,temps3/0.,0.,0./
+
+c--pour rapport de melange saturant--
+
+      REAL rtt,retv,r2es,r3les,r3ies,r4les,r4ies,play
+      REAL ptarg,pdelarg,foeew,zdelta
+      REAL tempe(ip1jmp1)
+
+c    fonction psat(T)
+
+       FOEEW ( PTARG,PDELARG ) = EXP (
+     *          (R3LES*(1.-PDELARG)+R3IES*PDELARG) * (PTARG-RTT)
+     * / (PTARG-(R4LES*(1.-PDELARG)+R4IES*PDELARG)) )
+
+        r2es  = 380.11733 
+        r3les = 17.269
+        r3ies = 21.875
+        r4les = 35.86
+        r4ies = 7.66
+        retv = 0.6077667
+        rtt  = 273.16
+
+c-- Calcul de Qsat en chaque point
+c-- approximation: au milieu des couches play(l)=(p(l)+p(l+1))/2
+c   pour eviter une exponentielle.
+        DO l = 1, llm
+         DO ij = 1, ip1jmp1
+          tempe(ij) = teta(ij,l) * pk(ij,l) /cpp
+         ENDDO
+         DO ij = 1, ip1jmp1
+          zdelta = MAX( 0., SIGN(1., rtt - tempe(ij)) )
+          play   = 0.5*(p(ij,l)+p(ij,l+1))
+          qsat(ij,l) = MIN(0.5, r2es* FOEEW(tempe(ij),zdelta) / play )
+          qsat(ij,l) = qsat(ij,l) / ( 1. - retv * qsat(ij,l) )
+         ENDDO
+        ENDDO
+
+c      PRINT*,'Debut vlsplt version debug sans vlyqs'
+
+        zzpbar = 0.5 * pdt
+        zzw    = pdt
+      DO l=1,llm
+        DO ij = iip2,ip1jm
+            mu(ij,l)=pbaru(ij,l) * zzpbar
+         ENDDO
+         DO ij=1,ip1jm
+            mv(ij,l)=pbarv(ij,l) * zzpbar
+         ENDDO
+         DO ij=1,ip1jmp1
+            mw(ij,l)=w(ij,l) * zzw
+         ENDDO
+      ENDDO
+
+      DO ij=1,ip1jmp1
+         mw(ij,llm+1)=0.
+      ENDDO
+
+      CALL SCOPY(ijp1llm,q,1,zq,1)
+      CALL SCOPY(ijp1llm,masse,1,zm,1)
+
+c      call minmaxq(zq,qmin,qmax,'avant vlxqs     ')
+      call vlxqs(zq,pente_max,zm,mu,qsat)
+
+
+c     call minmaxq(zq,qmin,qmax,'avant vlyqs     ')
+
+      call vlyqs(zq,pente_max,zm,mv,qsat)
+
+
+c      call minmaxq(zq,qmin,qmax,'avant vlz     ')
+
+      call vlz(zq,pente_max,zm,mw)
+
+
+c     call minmaxq(zq,qmin,qmax,'avant vlyqs     ')
+c     call minmaxq(zm,qmin,qmax,'M avant vlyqs     ')
+
+      call vlyqs(zq,pente_max,zm,mv,qsat)
+
+
+c     call minmaxq(zq,qmin,qmax,'avant vlxqs     ')
+c     call minmaxq(zm,qmin,qmax,'M avant vlxqs     ')
+
+      call vlxqs(zq,pente_max,zm,mu,qsat)
+
+c     call minmaxq(zq,qmin,qmax,'apres vlxqs     ')
+c     call minmaxq(zm,qmin,qmax,'M apres vlxqs     ')
+
+
+      DO l=1,llm
+         DO ij=1,ip1jmp1
+           q(ij,l)=zq(ij,l)
+         ENDDO
+         DO ij=1,ip1jm+1,iip1
+            q(ij+iim,l)=q(ij,l)
+         ENDDO
+      ENDDO
+
+      RETURN
+      END
+      SUBROUTINE vlxqs(q,pente_max,masse,u_m,qsat)
+c
+c     Auteurs:   P.Le Van, F.Hourdin, F.Forget 
+c
+c    ********************************************************************
+c     Shema  d'advection " pseudo amont " .
+c    ********************************************************************
+c
+c   --------------------------------------------------------------------
+      IMPLICIT NONE
+c
+#include "dimensions.h"
+#include "paramet.h"
+#include "logic.h"
+#include "comvert.h"
+#include "comconst.h"
+c
+c
+c   Arguments:
+c   ----------
+      REAL masse(ip1jmp1,llm),pente_max
+      REAL u_m( ip1jmp1,llm )
+      REAL q(ip1jmp1,llm)
+      REAL qsat(ip1jmp1,llm)
+c
+c      Local 
+c   ---------
+c
+      INTEGER ij,l,j,i,iju,ijq,indu(ip1jmp1),niju
+      INTEGER n0,iadvplus(ip1jmp1,llm),nl(llm)
+c
+      REAL new_m,zu_m,zdum(ip1jmp1,llm)
+      REAL dxq(ip1jmp1,llm),dxqu(ip1jmp1)
+      REAL zz(ip1jmp1)
+      REAL adxqu(ip1jmp1),dxqmax(ip1jmp1,llm)
+      REAL u_mq(ip1jmp1,llm)
+
+      Logical first,testcpu
+      SAVE first,testcpu
+
+      REAL      SSUM
+      EXTERNAL  SSUM
+      REAL temps0,temps1,temps2,temps3,temps4,temps5
+      SAVE temps0,temps1,temps2,temps3,temps4,temps5
+
+
+      DATA first,testcpu/.true.,.false./
+
+      IF(first) THEN
+         temps1=0.
+         temps2=0.
+         temps3=0.
+         temps4=0.
+         temps5=0.
+         first=.false.
+      ENDIF
+
+c   calcul de la pente a droite et a gauche de la maille
+
+
+      IF (pente_max.gt.-1.e-5) THEN
+c     IF (pente_max.gt.10) THEN
+
+c   calcul des pentes avec limitation, Van Leer scheme I:
+c   -----------------------------------------------------
+
+c   calcul de la pente aux points u
+         DO l = 1, llm
+            DO ij=iip2,ip1jm-1
+               dxqu(ij)=q(ij+1,l)-q(ij,l)
+c              IF(u_m(ij,l).lt.0.) stop'limx n admet pas les U<0'
+c              sigu(ij)=u_m(ij,l)/masse(ij,l)
+            ENDDO
+            DO ij=iip1+iip1,ip1jm,iip1
+               dxqu(ij)=dxqu(ij-iim)
+c              sigu(ij)=sigu(ij-iim)
+            ENDDO
+
+            DO ij=iip2,ip1jm
+               adxqu(ij)=abs(dxqu(ij))
+            ENDDO
+
+c   calcul de la pente maximum dans la maille en valeur absolue
+
+            DO ij=iip2+1,ip1jm
+               dxqmax(ij,l)=pente_max*
+     ,      min(adxqu(ij-1),adxqu(ij))
+c limitation subtile
+c    ,      min(adxqu(ij-1)/sigu(ij-1),adxqu(ij)/(1.-sigu(ij)))
+          
+
+            ENDDO
+
+            DO ij=iip1+iip1,ip1jm,iip1
+               dxqmax(ij-iim,l)=dxqmax(ij,l)
+            ENDDO
+
+            DO ij=iip2+1,ip1jm
+#ifdef CRAY
+               dxq(ij,l)=
+     ,         cvmgp(dxqu(ij-1)+dxqu(ij),0.,dxqu(ij-1)*dxqu(ij))
+#else
+               IF(dxqu(ij-1)*dxqu(ij).gt.0) THEN
+                  dxq(ij,l)=dxqu(ij-1)+dxqu(ij)
+               ELSE
+c   extremum local
+                  dxq(ij,l)=0.
+               ENDIF
+#endif
+               dxq(ij,l)=0.5*dxq(ij,l)
+               dxq(ij,l)=
+     ,         sign(min(abs(dxq(ij,l)),dxqmax(ij,l)),dxq(ij,l))
+            ENDDO
+
+         ENDDO ! l=1,llm
+
+      ELSE ! (pente_max.lt.-1.e-5)
+
+c   Pentes produits:
+c   ----------------
+
+         DO l = 1, llm
+            DO ij=iip2,ip1jm-1
+               dxqu(ij)=q(ij+1,l)-q(ij,l)
+            ENDDO
+            DO ij=iip1+iip1,ip1jm,iip1
+               dxqu(ij)=dxqu(ij-iim)
+            ENDDO
+
+            DO ij=iip2+1,ip1jm
+               zz(ij)=dxqu(ij-1)*dxqu(ij)
+               zz(ij)=zz(ij)+zz(ij)
+               IF(zz(ij).gt.0) THEN
+                  dxq(ij,l)=zz(ij)/(dxqu(ij-1)+dxqu(ij))
+               ELSE
+c   extremum local
+                  dxq(ij,l)=0.
+               ENDIF
+            ENDDO
+
+         ENDDO
+
+      ENDIF ! (pente_max.lt.-1.e-5)
+
+c   bouclage de la pente en iip1:
+c   -----------------------------
+
+      DO l=1,llm
+         DO ij=iip1+iip1,ip1jm,iip1
+            dxq(ij-iim,l)=dxq(ij,l)
+         ENDDO
+
+         DO ij=1,ip1jmp1
+            iadvplus(ij,l)=0
+         ENDDO
+
+      ENDDO
+
+
+c   calcul des flux a gauche et a droite
+
+#ifdef CRAY
+c--pas encore modification sur Qsat
+      DO l=1,llm
+       DO ij=iip2,ip1jm-1
+          zdum(ij,l)=cvmgp(1.-u_m(ij,l)/masse(ij,l),
+     ,                     1.+u_m(ij,l)/masse(ij+1,l),
+     ,                     u_m(ij,l))
+          zdum(ij,l)=0.5*zdum(ij,l)
+          u_mq(ij,l)=cvmgp(
+     ,                q(ij,l)+zdum(ij,l)*dxq(ij,l),
+     ,                q(ij+1,l)-zdum(ij,l)*dxq(ij+1,l),
+     ,                u_m(ij,l))
+          u_mq(ij,l)=u_m(ij,l)*u_mq(ij,l)
+       ENDDO
+      ENDDO
+#else
+c   on cumule le flux correspondant a toutes les mailles dont la masse
+c   au travers de la paroi pENDant le pas de temps.
+c   le rapport de melange de l'air advecte est min(q_vanleer, Qsat_downwind)
+      DO l=1,llm
+       DO ij=iip2,ip1jm-1
+          IF (u_m(ij,l).gt.0.) THEN
+             zdum(ij,l)=1.-u_m(ij,l)/masse(ij,l)
+             u_mq(ij,l)=u_m(ij,l)*
+     $         min(q(ij,l)+0.5*zdum(ij,l)*dxq(ij,l),qsat(ij+1,l))
+          ELSE
+             zdum(ij,l)=1.+u_m(ij,l)/masse(ij+1,l)
+             u_mq(ij,l)=u_m(ij,l)*
+     $         min(q(ij+1,l)-0.5*zdum(ij,l)*dxq(ij+1,l),qsat(ij,l))
+          ENDIF
+       ENDDO
+      ENDDO
+#endif
+
+
+c   detection des points ou on advecte plus que la masse de la
+c   maille
+      DO l=1,llm
+         DO ij=iip2,ip1jm-1
+            IF(zdum(ij,l).lt.0) THEN
+               iadvplus(ij,l)=1
+               u_mq(ij,l)=0.
+            ENDIF
+         ENDDO
+      ENDDO
+      DO l=1,llm
+       DO ij=iip1+iip1,ip1jm,iip1
+          iadvplus(ij,l)=iadvplus(ij-iim,l)
+       ENDDO
+      ENDDO
+
+
+
+c   traitement special pour le cas ou on advecte en longitude plus que le
+c   contenu de la maille.
+c   cette partie est mal vectorisee.
+
+c   pas d'influence de la pression saturante (pour l'instant)
+
+c  calcul du nombre de maille sur lequel on advecte plus que la maille.
+
+      n0=0
+      DO l=1,llm
+         nl(l)=0
+         DO ij=iip2,ip1jm
+            nl(l)=nl(l)+iadvplus(ij,l)
+         ENDDO
+         n0=n0+nl(l)
+      ENDDO
+
+      IF(n0.gt.1) THEN
+ccc      PRINT*,'Nombre de points pour lesquels on advect plus que le'
+ccc     &       ,'contenu de la maille : ',n0
+
+         DO l=1,llm
+            IF(nl(l).gt.0) THEN
+               iju=0
+c   indicage des mailles concernees par le traitement special
+               DO ij=iip2,ip1jm
+                  IF(iadvplus(ij,l).eq.1.and.mod(ij,iip1).ne.0) THEN
+                     iju=iju+1
+                     indu(iju)=ij
+                  ENDIF
+               ENDDO
+               niju=iju
+c              PRINT*,'niju,nl',niju,nl(l)
+
+c  traitement des mailles
+               DO iju=1,niju
+                  ij=indu(iju)
+                  j=(ij-1)/iip1+1
+                  zu_m=u_m(ij,l)
+                  u_mq(ij,l)=0.
+                  IF(zu_m.gt.0.) THEN
+                     ijq=ij
+                     i=ijq-(j-1)*iip1
+c   accumulation pour les mailles completements advectees
+                     do while(zu_m.gt.masse(ijq,l))
+                        u_mq(ij,l)=u_mq(ij,l)+q(ijq,l)*masse(ijq,l)
+                        zu_m=zu_m-masse(ijq,l)
+                        i=mod(i-2+iim,iim)+1
+                        ijq=(j-1)*iip1+i
+                     ENDDO
+c   ajout de la maille non completement advectee
+                     u_mq(ij,l)=u_mq(ij,l)+zu_m*
+     &               (q(ijq,l)+0.5*(1.-zu_m/masse(ijq,l))*dxq(ijq,l))
+                  ELSE
+                     ijq=ij+1
+                     i=ijq-(j-1)*iip1
+c   accumulation pour les mailles completements advectees
+                     do while(-zu_m.gt.masse(ijq,l))
+                        u_mq(ij,l)=u_mq(ij,l)-q(ijq,l)*masse(ijq,l)
+                        zu_m=zu_m+masse(ijq,l)
+                        i=mod(i,iim)+1
+                        ijq=(j-1)*iip1+i
+                     ENDDO
+c   ajout de la maille non completement advectee
+                     u_mq(ij,l)=u_mq(ij,l)+zu_m*(q(ijq,l)-
+     &               0.5*(1.+zu_m/masse(ijq,l))*dxq(ijq,l))
+                  ENDIF
+               ENDDO
+            ENDIF
+         ENDDO
+      ENDIF  ! n0.gt.0 
+
+
+
+c   bouclage en latitude
+
+      DO l=1,llm
+        DO ij=iip1+iip1,ip1jm,iip1
+           u_mq(ij,l)=u_mq(ij-iim,l)
+        ENDDO
+      ENDDO
+
+
+c   calcul des tendances
+
+      DO l=1,llm
+         DO ij=iip2+1,ip1jm
+            new_m=masse(ij,l)+u_m(ij-1,l)-u_m(ij,l)
+            q(ij,l)=(q(ij,l)*masse(ij,l)+
+     &      u_mq(ij-1,l)-u_mq(ij,l))
+     &      /new_m
+            masse(ij,l)=new_m
+         ENDDO
+c   Modif Fred 22 03 96 correction d'un bug (les scopy ci-dessous)
+         DO ij=iip1+iip1,ip1jm,iip1
+            q(ij-iim,l)=q(ij,l)
+            masse(ij-iim,l)=masse(ij,l)
+         ENDDO
+      ENDDO
+
+c     CALL SCOPY((jjm-1)*llm,q(iip1+iip1,1),iip1,q(iip2,1),iip1)
+c     CALL SCOPY((jjm-1)*llm,masse(iip1+iip1,1),iip1,masse(iip2,1),iip1)
+
+
+      RETURN
+      END
+      SUBROUTINE vlyqs(q,pente_max,masse,masse_adv_v,qsat)
+c
+c     Auteurs:   P.Le Van, F.Hourdin, F.Forget 
+c
+c    ********************************************************************
+c     Shema  d'advection " pseudo amont " .
+c    ********************************************************************
+c     q,masse_adv_v,w sont des arguments d'entree  pour le s-pg ....
+c     qsat 	       est   un argument de sortie pour le s-pg ....
+c
+c
+c   --------------------------------------------------------------------
+      IMPLICIT NONE
+c
+#include "dimensions.h"
+#include "paramet.h"
+#include "logic.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "comgeom.h"
+c
+c
+c   Arguments:
+c   ----------
+      REAL masse(ip1jmp1,llm),pente_max
+      REAL masse_adv_v( ip1jm,llm)
+      REAL q(ip1jmp1,llm)
+      REAL qsat(ip1jmp1,llm)
+c
+c      Local 
+c   ---------
+c
+      INTEGER i,ij,l
+c
+      REAL airej2,airejjm,airescb(iim),airesch(iim)
+      REAL dyq(ip1jmp1,llm),dyqv(ip1jm)
+      REAL adyqv(ip1jm),dyqmax(ip1jmp1)
+      REAL qbyv(ip1jm,llm)
+
+      REAL qpns,qpsn,dyn1,dys1,dyn2,dys2,newmasse,fn,fs
+c     REAL newq,oldmasse
+      Logical first,testcpu
+      REAL temps0,temps1,temps2,temps3,temps4,temps5
+      SAVE temps0,temps1,temps2,temps3,temps4,temps5
+      SAVE first,testcpu
+
+      REAL convpn,convps,convmpn,convmps
+      REAL sinlon(iip1),sinlondlon(iip1)
+      REAL coslon(iip1),coslondlon(iip1)
+      SAVE sinlon,coslon,sinlondlon,coslondlon
+      SAVE airej2,airejjm
+c
+c
+      REAL      SSUM
+      EXTERNAL  SSUM
+
+      DATA first,testcpu/.true.,.false./
+      DATA temps0,temps1,temps2,temps3,temps4,temps5/0.,0.,0.,0.,0.,0./
+
+      IF(first) THEN
+         PRINT*,'Shema  Amont nouveau  appele dans  Vanleer   '
+         first=.false.
+         do i=2,iip1
+            coslon(i)=cos(rlonv(i))
+            sinlon(i)=sin(rlonv(i))
+            coslondlon(i)=coslon(i)*(rlonu(i)-rlonu(i-1))/pi
+            sinlondlon(i)=sinlon(i)*(rlonu(i)-rlonu(i-1))/pi
+         ENDDO
+         coslon(1)=coslon(iip1)
+         coslondlon(1)=coslondlon(iip1)
+         sinlon(1)=sinlon(iip1)
+         sinlondlon(1)=sinlondlon(iip1)
+         airej2 = SSUM( iim, aire(iip2), 1 )
+         airejjm= SSUM( iim, aire(ip1jm -iim), 1 ) 
+      ENDIF
+
+c
+
+
+      DO l = 1, llm
+c
+c   --------------------------------
+c      CALCUL EN LATITUDE
+c   --------------------------------
+
+c   On commence par calculer la valeur du traceur moyenne sur le premier cercle
+c   de latitude autour du pole (qpns pour le pole nord et qpsn pour
+c    le pole nord) qui sera utilisee pour evaluer les pentes au pole.
+
+      DO i = 1, iim
+      airescb(i) = aire(i+ iip1) * q(i+ iip1,l)
+      airesch(i) = aire(i+ ip1jm- iip1) * q(i+ ip1jm- iip1,l)
+      ENDDO
+      qpns   = SSUM( iim,  airescb ,1 ) / airej2
+      qpsn   = SSUM( iim,  airesch ,1 ) / airejjm
+
+c   calcul des pentes aux points v
+
+      DO ij=1,ip1jm
+         dyqv(ij)=q(ij,l)-q(ij+iip1,l)
+         adyqv(ij)=abs(dyqv(ij))
+      ENDDO
+
+c   calcul des pentes aux points scalaires
+
+      DO ij=iip2,ip1jm
+         dyq(ij,l)=.5*(dyqv(ij-iip1)+dyqv(ij))
+         dyqmax(ij)=min(adyqv(ij-iip1),adyqv(ij))
+         dyqmax(ij)=pente_max*dyqmax(ij)
+      ENDDO
+
+c   calcul des pentes aux poles
+
+      DO ij=1,iip1
+         dyq(ij,l)=qpns-q(ij+iip1,l)
+         dyq(ip1jm+ij,l)=q(ip1jm+ij-iip1,l)-qpsn
+      ENDDO
+
+c   filtrage de la derivee
+      dyn1=0.
+      dys1=0.
+      dyn2=0.
+      dys2=0.
+      DO ij=1,iim
+         dyn1=dyn1+sinlondlon(ij)*dyq(ij,l)
+         dys1=dys1+sinlondlon(ij)*dyq(ip1jm+ij,l)
+         dyn2=dyn2+coslondlon(ij)*dyq(ij,l)
+         dys2=dys2+coslondlon(ij)*dyq(ip1jm+ij,l)
+      ENDDO
+      DO ij=1,iip1
+         dyq(ij,l)=dyn1*sinlon(ij)+dyn2*coslon(ij)
+         dyq(ip1jm+ij,l)=dys1*sinlon(ij)+dys2*coslon(ij)
+      ENDDO
+
+c   calcul des pentes limites aux poles
+
+      fn=1.
+      fs=1.
+      DO ij=1,iim
+         IF(pente_max*adyqv(ij).lt.abs(dyq(ij,l))) THEN
+            fn=min(pente_max*adyqv(ij)/abs(dyq(ij,l)),fn)
+         ENDIF
+      IF(pente_max*adyqv(ij+ip1jm-iip1).lt.abs(dyq(ij+ip1jm,l))) THEN
+         fs=min(pente_max*adyqv(ij+ip1jm-iip1)/abs(dyq(ij+ip1jm,l)),fs)
+         ENDIF
+      ENDDO
+      DO ij=1,iip1
+         dyq(ij,l)=fn*dyq(ij,l)
+         dyq(ip1jm+ij,l)=fs*dyq(ip1jm+ij,l)
+      ENDDO
+
+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
+C  En memoire de dIFferents tests sur la 
+C  limitation des pentes aux poles.
+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
+C     PRINT*,dyq(1)
+C     PRINT*,dyqv(iip1+1)
+C     apn=abs(dyq(1)/dyqv(iip1+1))
+C     PRINT*,dyq(ip1jm+1)
+C     PRINT*,dyqv(ip1jm-iip1+1)
+C     aps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
+C     DO ij=2,iim
+C        apn=amax1(abs(dyq(ij)/dyqv(ij)),apn)
+C        aps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),aps)
+C     ENDDO
+C     apn=min(pente_max/apn,1.)
+C     aps=min(pente_max/aps,1.)
+C
+C
+C   cas ou on a un extremum au pole
+C
+C     IF(dyqv(ismin(iim,dyqv,1))*dyqv(ismax(iim,dyqv,1)).le.0.)
+C    &   apn=0.
+C     IF(dyqv(ismax(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1)*
+C    &   dyqv(ismin(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1).le.0.)
+C    &   aps=0.
+C
+C   limitation des pentes aux poles
+C     DO ij=1,iip1
+C        dyq(ij)=apn*dyq(ij)
+C        dyq(ip1jm+ij)=aps*dyq(ip1jm+ij)
+C     ENDDO
+C
+C   test
+C      DO ij=1,iip1
+C         dyq(iip1+ij)=0.
+C         dyq(ip1jm+ij-iip1)=0.
+C      ENDDO
+C      DO ij=1,ip1jmp1
+C         dyq(ij)=dyq(ij)*cos(rlatu((ij-1)/iip1+1))
+C      ENDDO
+C
+C changement 10 07 96
+C     IF(dyqv(ismin(iim,dyqv,1))*dyqv(ismax(iim,dyqv,1)).le.0.)
+C    &   THEN
+C        DO ij=1,iip1
+C           dyqmax(ij)=0.
+C        ENDDO
+C     ELSE
+C        DO ij=1,iip1
+C           dyqmax(ij)=pente_max*abs(dyqv(ij))
+C        ENDDO
+C     ENDIF
+C
+C     IF(dyqv(ismax(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1)*
+C    & dyqv(ismin(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1).le.0.)
+C    &THEN
+C        DO ij=ip1jm+1,ip1jmp1
+C           dyqmax(ij)=0.
+C        ENDDO
+C     ELSE
+C        DO ij=ip1jm+1,ip1jmp1
+C           dyqmax(ij)=pente_max*abs(dyqv(ij-iip1))
+C        ENDDO
+C     ENDIF
+C   fin changement 10 07 96
+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
+
+c   calcul des pentes limitees
+
+      DO ij=iip2,ip1jm
+         IF(dyqv(ij)*dyqv(ij-iip1).gt.0.) THEN
+            dyq(ij,l)=sign(min(abs(dyq(ij,l)),dyqmax(ij)),dyq(ij,l))
+         ELSE
+            dyq(ij,l)=0.
+         ENDIF
+      ENDDO
+
+      ENDDO
+
+      DO l=1,llm
+       DO ij=1,ip1jm
+         IF( masse_adv_v(ij,l).GT.0. ) THEN
+           qbyv(ij,l)= MIN( qsat(ij+iip1,l), q(ij+iip1,l )  +
+     ,      dyq(ij+iip1,l)*0.5*(1.-masse_adv_v(ij,l)/masse(ij+iip1,l)))
+         ELSE
+              qbyv(ij,l)= MIN( qsat(ij,l), q(ij,l) - dyq(ij,l) *
+     ,                   0.5*(1.+masse_adv_v(ij,l)/masse(ij,l)) )
+         ENDIF
+          qbyv(ij,l) = masse_adv_v(ij,l)*qbyv(ij,l)
+       ENDDO
+      ENDDO
+
+
+      DO l=1,llm
+         DO ij=iip2,ip1jm
+            newmasse=masse(ij,l)
+     &      +masse_adv_v(ij,l)-masse_adv_v(ij-iip1,l)
+            q(ij,l)=(q(ij,l)*masse(ij,l)+qbyv(ij,l)-qbyv(ij-iip1,l))
+     &         /newmasse
+            masse(ij,l)=newmasse
+         ENDDO
+c.-. ancienne version
+         convpn=SSUM(iim,qbyv(1,l),1)/apoln
+         convmpn=ssum(iim,masse_adv_v(1,l),1)/apoln
+         DO ij = 1,iip1
+            newmasse=masse(ij,l)+convmpn*aire(ij)
+            q(ij,l)=(q(ij,l)*masse(ij,l)+convpn*aire(ij))/
+     &               newmasse
+            masse(ij,l)=newmasse
+         ENDDO
+         convps  = -SSUM(iim,qbyv(ip1jm-iim,l),1)/apols
+         convmps = -SSUM(iim,masse_adv_v(ip1jm-iim,l),1)/apols
+         DO ij = ip1jm+1,ip1jmp1
+            newmasse=masse(ij,l)+convmps*aire(ij)
+            q(ij,l)=(q(ij,l)*masse(ij,l)+convps*aire(ij))/
+     &               newmasse
+            masse(ij,l)=newmasse
+         ENDDO
+c.-. fin ancienne version
+
+c._. nouvelle version
+c        convpn=SSUM(iim,qbyv(1,l),1)
+c        convmpn=ssum(iim,masse_adv_v(1,l),1)
+c        oldmasse=ssum(iim,masse(1,l),1)
+c        newmasse=oldmasse+convmpn
+c        newq=(q(1,l)*oldmasse+convpn)/newmasse
+c        newmasse=newmasse/apoln
+c        DO ij = 1,iip1
+c           q(ij,l)=newq
+c           masse(ij,l)=newmasse*aire(ij)
+c        ENDDO
+c        convps=-SSUM(iim,qbyv(ip1jm-iim,l),1)
+c        convmps=-ssum(iim,masse_adv_v(ip1jm-iim,l),1)
+c        oldmasse=ssum(iim,masse(ip1jm-iim,l),1)
+c        newmasse=oldmasse+convmps
+c        newq=(q(ip1jmp1,l)*oldmasse+convps)/newmasse
+c        newmasse=newmasse/apols
+c        DO ij = ip1jm+1,ip1jmp1
+c           q(ij,l)=newq
+c           masse(ij,l)=newmasse*aire(ij)
+c        ENDDO
+c._. fin nouvelle version
+      ENDDO
+
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/filtrez/filtreg.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/filtrez/filtreg.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/filtrez/filtreg.F	(revision 253)
@@ -290,8 +290,8 @@
  100  CONTINUE
 c
-1111  FORMAT(//20x,'ERREUR dans le dimensionnement du tableau CHAMP a fil
-     *-trer, sur la grille des scalaires'/)
-2222  FORMAT(//20x,'ERREUR dans le dimensionnement du tableau CHAMP a fil
-     *-trer, sur la grille de V ou de Z'/)
+1111  FORMAT(//20x,'ERREUR dans le dimensionnement du tableau  CHAMP a 
+     *filtrer, sur la grille des scalaires'/)
+2222  FORMAT(//20x,'ERREUR dans le dimensionnement du tableau CHAMP a fi
+     *ltrer, sur la grille de V ou de Z'/)
       RETURN
       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/filtrez/jacobi.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/filtrez/jacobi.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/filtrez/jacobi.F	(revision 253)
@@ -1,4 +1,4 @@
       SUBROUTINE JACOBI(A,N,NP,D,V,NROT)
-      PARAMETER (NMAX=200)
+      PARAMETER (NMAX=400)
       DIMENSION A(NP,NP),D(NP),V(NP,NP),B(NMAX),Z(NMAX)
       IF (n.gt.nmax) THEN
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/filtrez/parafilt.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/filtrez/parafilt.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/filtrez/parafilt.h	(revision 253)
@@ -4,5 +4,5 @@
 c       PARAMETER (nfilun=30,nfilus=30,nfilvn=30,nfilvs=30)
 c        PARAMETER (nfilun=6, nfilus=5, nfilvn=5, nfilvs=5)
-         PARAMETER (nfilun=15, nfilus=8, nfilvn=14, nfilvs=8)
+c         PARAMETER (nfilun=15, nfilus=8, nfilvn=14, nfilvs=8)
 c        PARAMETER (nfilun=24, nfilus=23, nfilvn=24, nfilvs=24)
 cmaf -debug  PARAMETER (nfilun=2, nfilus=1, nfilvn=2, nfilvs=2)
@@ -16,4 +16,10 @@
 ccc      PARAMETER (nfilun=13, nfilus=12, nfilvn=12, nfilvs=12)
 c
+c 192 143 19 non-zoom:
+c             PARAMETER (nfilun=13, nfilus=12, nfilvn=13, nfilvs=13)
+c      PARAMETER (nfilun=15, nfilus=14, nfilvn=14, nfilvs=14) !!NO fxyhyper
+c      PARAMETER (nfilun=18, nfilus=17, nfilvn=17, nfilvs=17) !!NO fxyhyper
+        PARAMETER (nfilun=30,nfilus=30,nfilvn=30,nfilvs=30)
+
 c 96 72 19 non-zoom:
 ccc      PARAMETER (nfilun=12, nfilus=11, nfilvn=12, nfilvs=12)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/1DUTILS.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/1DUTILS.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/1DUTILS.h	(revision 253)
@@ -0,0 +1,920 @@
+      SUBROUTINE initial0(n,x)
+      IMPLICIT NONE
+      INTEGER n,i
+      REAL x(n)
+      DO 10 i=1,n
+         x(i)=0.
+10    CONTINUE
+      RETURN
+      END
+      SUBROUTINE gr_fi_dyn(nfield,ngrid,im,jm,pfi,pdyn)
+      IMPLICIT NONE
+c=======================================================================
+c   passage d'un champ de la grille scalaire a la grille physique
+c=======================================================================
+
+c-----------------------------------------------------------------------
+c   declarations:
+c   -------------
+
+      INTEGER im,jm,ngrid,nfield
+      REAL pdyn(im,jm,nfield)
+      REAL pfi(ngrid,nfield)
+
+      INTEGER i,j,ifield,ig
+
+c-----------------------------------------------------------------------
+c   calcul:
+c   -------
+
+      DO ifield=1,nfield
+c   traitement des poles
+         DO i=1,im
+            pdyn(i,1,ifield)=pfi(1,ifield)
+            pdyn(i,jm,ifield)=pfi(ngrid,ifield)
+         ENDDO
+
+c   traitement des point normaux
+         DO j=2,jm-1
+	    ig=2+(j-2)*(im-1)
+            CALL SCOPY(im-1,pfi(ig,ifield),1,pdyn(1,j,ifield),1)
+	    pdyn(im,j,ifield)=pdyn(1,j,ifield)
+         ENDDO
+      ENDDO
+
+      RETURN
+      END
+
+      SUBROUTINE disvert1d(llm,kappa,sig,dsig,s,ds,dsig1,sdsig)
+      IMPLICIT NONE
+c
+c=======================================================================
+c
+c
+c    s = sigma ** kappa   :  coordonnee  verticale
+c    dsig(l)            : epaisseur de la couche l ds la coord.  s
+c    sig(l)             : sigma a l'interface des couches l et l-1
+c    ds(l)              : distance entre les couches l et l-1 en coord.s
+c
+c=======================================================================
+c
+c   declarations:
+c   -------------
+c
+      integer llm
+      real kappa,pi,x
+      real sig(llm+1),dsig(llm),s(llm),ds(llm),dsig1(llm),sdsig(llm)
+c
+      integer ll,l,lllm,lllmm1,lllmp1
+      real abid,abid2,som,quoi,quand,snorm,sigbid,sbid
+      REAL alpha,beta,h,zd,dz0,dz1
+      REAL gama,delta,deltaz,np
+
+      real nhaut
+      INTEGER ierr,ierr1,ierr2
+      real puiss
+
+      real asig,bsig,csig,esig,zsig,p,zz,sig1
+      REAL z1,z2
+c
+c-----------------------------------------------------------------------
+c
+      lllm=llm
+      lllmm1=lllm-1
+      lllmp1=lllm+1
+      pi=2.*asin(1.)
+
+      OPEN(99,file='sigma.def',status='old',form='formatted',
+     s   iostat=ierr1)
+      if(ierr1.ne.0) then
+         close(99)
+         open(99,file='esasig.def',status='old',form='formatted',
+     s   iostat=ierr2)
+      endif
+
+
+c-----------------------------------------------------------------------
+c   cas 1 on lit les options dans sigma.def:
+c   ----------------------------------------
+
+
+      if (ierr1.eq.0) then
+         PRINT*,'WARNING Lecture de sigma.def'
+         READ(99,*) deltaz
+         READ(99,*) h
+         READ(99,*) beta
+         READ(99,*) gama
+         READ(99,*) delta
+         READ(99,*) np
+         CLOSE(99)
+         alpha=deltaz/(llm*h)
+          do l= 1, llm
+             dsig(l) = (alpha+(1.-alpha)*exp(-beta*(llm-l)))*
+     $          ( (tanh(gama*l)/tanh(gama*llm))**np +
+     $            (1.-l/FLOAT(llm))*delta )
+          enddo
+
+          sig(1)=1.
+          do l=1,llm-1
+             sig(l+1)=sig(l)*(1.-dsig(l))/(1.+dsig(l))
+          enddo
+          sig(llm+1)=0.
+
+          do l = 1, llm
+             dsig(l) = sig(l)-sig(l+1)
+          enddo
+
+      else if(ierr2.eq.0) then
+
+         PRINT*,'WARNING Lecture de esasig.def'
+         READ(99,*) h
+         READ(99,*) dz0
+         READ(99,*) dz1
+         READ(99,*) nhaut
+         CLOSE(99)
+
+         dz0=dz0/h
+         dz1=dz1/h
+
+         sig1=(1.-dz1)/tanh(.5*(llm-1)/nhaut)
+
+         esig=1.
+
+         PRINT*
+         do l=1,20
+            print*,'esig=',esig
+            esig=-log((1./sig1-1.)*exp(-dz0)/esig)/(llm-1.)
+         enddo
+         PRINT*
+         csig=(1./sig1-1.)/(exp(esig)-1.)
+
+         DO L = 2, llm
+           zz=csig*(exp(esig*(l-1.))-1.)
+           sig(l) =1./(1.+zz)
+     &    * tanh(.5*(llm+1-l)/nhaut)
+         ENDDO
+         sig(1)=1.
+         sig(llm+1)=0.
+
+         do  l = 1, llm
+         dsig(l) =sig(l)-sig(l+1)
+         enddo
+
+      else
+
+         print*,'WARNING!!! Ancienne discretisation verticale'
+c        stop
+         h=7.
+         snorm  = 0.
+         do l = 1, llm
+            x = 2.*asin(1.) * (float(l)-0.5) / float(llm+1)
+            dsig(l) = 1.0 + 7.0 * sin(x)**2
+            snorm = snorm + dsig(l)
+         enddo
+         snorm = 1./snorm
+         do l = 1, llm
+            dsig(l) = dsig(l)*snorm
+         enddo
+         sig(llm+1) = 0.
+         do l = llm, 1, -1
+            sig(l) = sig(l+1) + dsig(l)
+         enddo
+
+      endif
+
+c-----------------------------------------------------------------------
+c   calcul de s, ds, sdsig...
+c   -------------------------
+
+       quoi      = 1. + 2.* kappa
+       s( llm )  = 1.
+       s(lllmm1) = quoi
+       IF( llm.gt.2 )  THEN
+          DO  ll = 2, lllmm1
+             l         = lllmp1 - ll
+             quand     = sig(l+1)/ sig(l)
+             s(l-1)    = quoi * (1.-quand) * s(l)  + quand * s(l+1)
+          ENDDO
+       END IF
+c
+       snorm=(1.-.5*sig(2)+kappa*(1.-sig(2)))*s(1)+.5*sig(2)*s(2)
+       DO l = 1, llm
+          s(l)    = s(l)/ snorm
+       ENDDO
+
+       DO l = 2, llm
+          ds(l)   = s(l-1) - s(l)
+       ENDDO
+       ds(1)  = 1. - s(1)
+c
+       DO l  = 1, llm
+          sdsig(l) = s(l) * dsig(l)
+          dsig1(l)= 1./dsig(l)
+       ENDDO
+
+c-----------------------------------------------------------------------
+c
+c     Diagnostique sur la discretisation verticale:
+c     ---------------------------------------------
+c
+      print*,'Diagnostique de la discretisation verticale'
+      print*
+      print*,'comparaison de sig(l) et (s(l)+s(l+1))/2)**(1/K)'
+      do 14 l=1,llm-1
+         sigbid=(0.5*(s(l)+s(l+1)))**(1./kappa)
+         print*,'sig(',l+1,')  = ',sig(l+1),
+     S           '    valeur approchee :',sigbid,'   ',dsig(l)
+14    continue
+      print*
+      print*,'comparaison de s(l) et (sig(l)+sig(l+1))/2)**K'
+      do 15 l=1,llm
+         sbid=(0.5*(sig(l+1)+sig(l)))**kappa
+         print*,'  s(',l,')  = ',s(l),
+     S           '    valeur approchee :',sbid
+15    continue
+c
+      PRINT*,'Altitude approchee z,dz'
+      PRINT*
+      z1=0.
+      print*,'   l       Z      DZ      Ztop   dsig'
+      DO 18 l=1,llm-1
+         z2=-h*log(sig(l+1))
+         write(*,'(i5,3x,4f8.4)') l,-h*log(s(l))/kappa,z2-z1,z2
+     &    ,dsig(l)
+         write(14,'(3x,i5,1f10.4)') l,-h*log(s(l))/kappa
+         z1=z2
+18    CONTINUE
+      write(*,'(i5,3x,3f8.4)') l,-h*log(s(llm))/kappa
+      write(14,'(3x,i5,1f10.4)') l,-h*log(s(llm))/kappa
+
+
+      RETURN
+      END
+
+c---------------------------------------------------------------
+      subroutine adv_vert2(w,q,plev)
+c   Schéma amont pour l'advection verticale de l'eau
+      implicit none
+
+#include "dimensions.h"
+#include "dimphy.h"
+
+      real w(llm+1),wq(llm+1),q(llm),plev(llm+1),dsig(llm+1)
+
+      integer l
+
+      do l=1,llm
+         wq(l)=q(l)*w(l)
+         dsig(l)=(plev(l)-plev(l+1))/plev(1)
+      enddo
+
+      wq(llm+1)=0.
+      do l=1,llm
+         q(l)=(q(l)*dsig(l)+wq(l+1)-wq(l))/(dsig(l)+w(l+1)-w(l))
+      enddo
+      do l=1,llm
+         wq(l)=q(l)*w(l)
+      enddo
+      wq(llm+1)=0.
+      do l=1,llm
+         q(l)=(q(l)*dsig(l)+wq(l+1)-wq(l))/(dsig(l)+w(l+1)-w(l))
+      enddo
+
+      return
+      end
+c---------------------------------------------------------------
+      subroutine adv_vert(w,q)
+c   Schéma amont pour l'advection verticale de l'eau
+      implicit none
+
+#include "dimensions.h"
+#include "dimphy.h"
+#include "comvert1d.h"
+
+      real w(llm+1),wq(llm+1),q(llm)
+
+      integer l
+
+      do l=1,llm
+         wq(l)=q(l)*w(l)
+      enddo
+
+      wq(llm+1)=0.
+      do l=1,llm
+         q(l)=(q(l)*dsig(l)+wq(l+1)-wq(l))/(dsig(l)+w(l+1)-w(l))
+      enddo
+      do l=1,llm
+         wq(l)=q(l)*w(l)
+      enddo
+      wq(llm+1)=0.
+      do l=1,llm
+         q(l)=(q(l)*dsig(l)+wq(l+1)-wq(l))/(dsig(l)+w(l+1)-w(l))
+      enddo
+
+      return
+      end
+      subroutine ug_vg(lm,sig,ug,vg)
+      implicit none
+
+      integer lm
+
+      real u0,uinf,sigu0,alphau
+      real v0,vinf,sigv0,alphav
+
+      real sig(lm),ug(lm),vg(lm)
+      integer l
+
+      data u0,uinf,sigu0/-9.,6.,0.8/
+c     data v0,vinf,sigv0/-1.,4.,0.98/
+      data v0,vinf,sigv0/-1.,7.,0.98/
+
+
+      alphau=-log((uinf-u0)/uinf)/log(sigu0)
+      alphav=-log((vinf-v0)/vinf)/log(sigv0)
+      print*,'Alpha=',alphau,alphav
+
+      do l=1,lm
+         ug(l)=uinf+(u0-uinf)*sig(l)**alphau
+         vg(l)=vinf+(v0-vinf)*sig(l)**alphav
+      enddo
+
+      return
+      end
+      SUBROUTINE abort_gcm(modname, message, ierr)
+     
+      USE IOIPSL
+C
+C Stops the simulation cleanly, closing files and printing various
+C comments
+C
+C  Input: modname = name of calling program
+C         message = stuff to print
+C         ierr    = severity of situation ( = 0 normal )
+
+      character*20 modname
+      integer ierr
+      character*80 message
+
+      write(*,*) 'in abort_gcm'
+      call histclo
+c     call histclo(2)
+c     call histclo(3)
+c     call histclo(4)
+c     call histclo(5)
+      write(*,*) 'out of histclo'
+      write(*,*) 'Stopping in ', modname
+      write(*,*) 'Reason = ',message
+      if (ierr .eq. 0) then
+        write(*,*) 'Everything is cool'
+      else
+        write(*,*) 'Houston, we have a problem ', ierr
+      endif
+      STOP
+      END
+      FUNCTION q_sat(kelvin, millibar)
+c
+      IMPLICIT none
+c======================================================================
+c Autheur(s): Z.X. Li (LMD/CNRS)
+c Objet: calculer la vapeur d'eau saturante (formule Centre Euro.)
+c======================================================================
+c Arguments:
+c kelvin---input-R: temperature en Kelvin
+c millibar--input-R: pression en mb
+c
+c q_sat----output-R: vapeur d'eau saturante en kg/kg
+c======================================================================
+c
+      REAL q_sat, kelvin, millibar
+c
+      REAL r2es
+      PARAMETER (r2es=611.14 *18.0153/28.9644)
+c
+      REAL r3les, r3ies, r3es
+      PARAMETER (R3LES=17.269)
+      PARAMETER (R3IES=21.875)
+c
+      REAL r4les, r4ies, r4es
+      PARAMETER (R4LES=35.86)
+      PARAMETER (R4IES=7.66)
+c
+      REAL rtt
+      PARAMETER (rtt=273.16)
+c
+      REAL retv
+      PARAMETER (retv=28.9644/18.0153 - 1.0)
+c
+      REAL zqsat
+      REAL temp, pres
+C     ------------------------------------------------------------------
+c
+c
+      temp = kelvin
+      pres = millibar * 100.0
+c      write(*,*)'kelvin,millibar=',kelvin,millibar
+c      write(*,*)'temp,pres=',temp,pres
+c
+      IF (temp .LE. rtt) THEN
+         r3es = r3ies
+         r4es = r4ies
+      ELSE
+         r3es = r3les
+         r4es = r4les
+      ENDIF
+c
+      zqsat=r2es/pres * EXP ( r3es*(temp-rtt) / (temp-r4es) )
+      zqsat=MIN(0.5,ZQSAT)
+      zqsat=zqsat/(1.-retv  *zqsat)
+c
+      q_sat = zqsat
+c
+      RETURN
+      END
+      subroutine scopy(n,sx,incx,sy,incy)
+c
+      IMPLICIT NONE
+c
+      integer n,incx,incy,ix,iy,i
+      real sx((n-1)*incx+1),sy((n-1)*incy+1)
+c
+      iy=1
+      ix=1
+      do 10 i=1,n
+	 sy(iy)=sx(ix)
+         ix=ix+incx
+         iy=iy+incy
+10    continue
+c
+      return
+      end
+      subroutine wrgradsfi(if,nl,field,name,titlevar)
+      implicit none
+
+c   Declarations
+
+#include "gradsdef.h"
+
+c   arguments
+      integer if,nl
+      real field(imx*jmx*lmx)
+      character*10 name,file
+      character*10 titlevar
+
+c   local
+
+      integer im,jm,lm,i,j,l,lnblnk,iv,iii,iji,iif,ijf
+
+      logical writectl
+
+
+      writectl=.false.
+
+c     print*,if,iid(if),jid(if),ifd(if),jfd(if)
+      iii=iid(if)
+      iji=jid(if)
+      iif=ifd(if)
+      ijf=jfd(if)
+      im=iif-iii+1
+      jm=ijf-iji+1
+      lm=lmd(if)
+
+c     print*,'im,jm,lm,name,firsttime(if)'
+c     print*,im,jm,lm,name,firsttime(if)
+
+      if(firsttime(if)) then
+         if(name.eq.var(1,if)) then
+            firsttime(if)=.false.
+            ivar(if)=1
+         print*,'fin de l initialiation de l ecriture du fichier'
+         print*,file
+           print*,'fichier no: ',if
+           print*,'unit ',unit(if)
+           print*,'nvar  ',nvar(if)
+           print*,'vars ',(var(iv,if),iv=1,nvar(if))
+         else
+            ivar(if)=ivar(if)+1
+            nvar(if)=ivar(if)
+            var(ivar(if),if)=name
+            tvar(ivar(if),if)=titlevar(1:lnblnk(titlevar))
+            nld(ivar(if),if)=nl
+            print*,'initialisation ecriture de ',var(ivar(if),if)
+            print*,'if ivar(if) nld ',if,ivar(if),nld(ivar(if),if)
+         endif
+         writectl=.true.
+         itime(if)=1
+      else
+         ivar(if)=mod(ivar(if),nvar(if))+1
+         if (ivar(if).eq.nvar(if)) then
+            writectl=.true.
+            itime(if)=itime(if)+1
+         endif
+
+         if(var(ivar(if),if).ne.name) then
+           print*,'Il faut stoker la meme succession de champs a chaque'
+           print*,'pas de temps'
+           print*,'fichier no: ',if
+           print*,'unit ',unit(if)
+           print*,'nvar  ',nvar(if)
+           print*,'vars ',(var(iv,if),iv=1,nvar(if))
+
+           stop
+         endif
+      endif
+
+c     print*,'ivar(if),nvar(if),var(ivar(if),if),writectl'
+c     print*,ivar(if),nvar(if),var(ivar(if),if),writectl
+      do l=1,nl
+         irec(if)=irec(if)+1
+c        print*,'Ecrit rec=',irec(if),iii,iif,iji,ijf,
+c    s (l-1)*imd(if)*jmd(if)+(iji-1)*imd(if)+iii
+c    s ,(l-1)*imd(if)*jmd(if)+(ijf-1)*imd(if)+iif
+         write(unit(if)+1,rec=irec(if))
+     s   ((field((l-1)*imd(if)*jmd(if)+(j-1)*imd(if)+i)
+     s   ,i=iii,iif),j=iji,ijf)
+      enddo
+      if (writectl) then
+
+      file=fichier(if)
+c   WARNING! on reecrase le fichier .ctl a chaque ecriture
+      open(unit(if),file=file(1:lnblnk(file))//'.ctl',
+     &         form='formatted',status='unknown')
+      write(unit(if),'(a5,1x,a40)')
+     &       'DSET ','^'//file(1:lnblnk(file))//'.dat'
+
+      write(unit(if),'(a12)') 'UNDEF 1.0E30'
+      write(unit(if),'(a5,1x,a40)') 'TITLE ',title(if)
+      call formcoord(unit(if),im,xd(iii,if),1.,.false.,'XDEF')
+      call formcoord(unit(if),jm,yd(iji,if),1.,.true.,'YDEF')
+      call formcoord(unit(if),lm,zd(1,if),1.,.false.,'ZDEF')
+      write(unit(if),'(a4,i10,a30)')
+     &       'TDEF ',itime(if),' LINEAR 07AUG1998 30MN '
+      write(unit(if),'(a4,2x,i5)') 'VARS',nvar(if)
+      do iv=1,nvar(if)
+c        print*,'if,var(iv,if),nld(iv,if),nld(iv,if)-1/nld(iv,if)'
+c        print*,if,var(iv,if),nld(iv,if),nld(iv,if)-1/nld(iv,if)
+         write(unit(if),1000) var(iv,if),nld(iv,if)-1/nld(iv,if)
+     &     ,99,tvar(iv,if)
+      enddo
+      write(unit(if),'(a7)') 'ENDVARS'
+c
+1000  format(a5,3x,i4,i3,1x,a39)
+
+      close(unit(if))
+
+      endif ! writectl
+
+      return
+
+      END
+
+      subroutine inigrads(if,im
+     s  ,x,fx,xmin,xmax,jm,y,ymin,ymax,fy,lm,z,fz
+     s  ,dt,file,titlel)
+
+
+      implicit none
+
+      integer if,im,jm,lm,i,j,l,lnblnk
+      real x(im),y(jm),z(lm),fx,fy,fz,dt
+      real xmin,xmax,ymin,ymax
+
+      character file*10,titlel*40
+
+#include "gradsdef.h"
+
+      data unit/24,32,34,36,38,40,42,44,46,48/
+      data nf/0/
+
+      if (if.le.nf) stop'verifier les appels a inigrads'
+
+      print*,'Entree dans inigrads'
+
+      nf=if
+      title(if)=titlel
+      ivar(if)=0
+
+      fichier(if)=file(1:lnblnk(file))
+
+      firsttime(if)=.true.
+      dtime(if)=dt
+
+      iid(if)=1
+      ifd(if)=im
+      imd(if)=im
+      do i=1,im
+         xd(i,if)=x(i)*fx
+         if(xd(i,if).lt.xmin) iid(if)=i+1
+         if(xd(i,if).le.xmax) ifd(if)=i
+      enddo
+      print*,'On stoke du point ',iid(if),'  a ',ifd(if),' en x'
+
+      jid(if)=1
+      jfd(if)=jm
+      jmd(if)=jm
+      do j=1,jm
+         yd(j,if)=y(j)*fy
+         if(yd(j,if).gt.ymax) jid(if)=j+1
+         if(yd(j,if).ge.ymin) jfd(if)=j
+      enddo
+      print*,'On stoke du point ',jid(if),'  a ',jfd(if),' en y'
+
+      print*,'Open de dat'
+      print*,'file=',file
+      print*,'fichier(if)=',fichier(if)
+
+      print*,4*(ifd(if)-iid(if))*(jfd(if)-jid(if))
+      print*,file(1:lnblnk(file))//'.dat'
+
+      OPEN (unit(if)+1,FILE=file(1:lnblnk(file))//'.dat',
+     s   FORM='UNFORMATTED',
+     s   ACCESS='DIRECT'
+     s  ,RECL=4*(ifd(if)-iid(if)+1)*(jfd(if)-jid(if)+1))
+
+      print*,'Open de dat ok'
+
+      lmd(if)=lm
+      do l=1,lm
+         zd(l,if)=z(l)*fz
+      enddo
+
+      irec(if)=0
+
+      print*,if,imd(if),jmd(if),lmd(if)
+      print*,'if,imd(if),jmd(if),lmd(if)'
+
+      return
+      end
+      SUBROUTINE gr_dyn_fi(nfield,im,jm,ngrid,pdyn,pfi)
+      IMPLICIT NONE
+c=======================================================================
+c   passage d'un champ de la grille scalaire a la grille physique
+c=======================================================================
+
+c-----------------------------------------------------------------------
+c   declarations:
+c   -------------
+
+      INTEGER im,jm,ngrid,nfield
+      REAL pdyn(im,jm,nfield)
+      REAL pfi(ngrid,nfield)
+
+      INTEGER j,ifield,ig
+
+c-----------------------------------------------------------------------
+c   calcul:
+c   -------
+
+      IF(ngrid.NE.2+(jm-2)*(im-1).AND.ngrid.NE.1)
+     s    STOP 'probleme de dim'
+c   traitement des poles
+      CALL SCOPY(nfield,pdyn,im*jm,pfi,ngrid)
+      CALL SCOPY(nfield,pdyn(1,jm,1),im*jm,pfi(ngrid,1),ngrid)
+
+c   traitement des point normaux
+      DO ifield=1,nfield
+         DO j=2,jm-1
+	    ig=2+(j-2)*(im-1)
+            CALL SCOPY(im-1,pdyn(1,j,ifield),1,pfi(ig,ifield),1)
+         ENDDO
+      ENDDO
+
+      RETURN
+      END
+
+      subroutine writelim
+     s   (phy_nat,phy_alb,phy_sst,phy_bil,phy_rug,phy_ice)
+c
+#include "dimensions.h"
+#include "dimphy.h"
+#include "netcdf.inc"
+
+      REAL phy_nat(klon,360)
+      REAL phy_alb(klon,360)
+      REAL phy_sst(klon,360)
+      REAL phy_bil(klon,360)
+      REAL phy_rug(klon,360)
+      REAL phy_ice(klon,360)
+
+      INTEGER ierr
+      INTEGER dimfirst(3)
+      INTEGER dimlast(3)
+c
+      INTEGER nid, ndim, ntim
+      INTEGER dims(2), debut(2), epais(2)
+      INTEGER id_tim
+      INTEGER id_NAT, id_SST, id_BILS, id_RUG, id_ALB
+
+      PRINT*, 'Ecriture du fichier limit'
+c
+      ierr = NF_CREATE ("limit.nc", NF_CLOBBER, nid)
+c
+      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 30,
+     .                       "Fichier conditions aux limites")
+      ierr = NF_DEF_DIM (nid, "points_physiques", klon, ndim)
+      ierr = NF_DEF_DIM (nid, "time", NF_UNLIMITED, ntim)
+c
+      dims(1) = ndim
+      dims(2) = ntim
+c
+ccc      ierr = NF_DEF_VAR (nid, "TEMPS", NF_DOUBLE, 1,ntim, id_tim)
+      ierr = NF_DEF_VAR (nid, "TEMPS", NF_FLOAT, 1,ntim, id_tim)
+      ierr = NF_PUT_ATT_TEXT (nid, id_tim, "title", 17,
+     .                        "Jour dans l annee")
+ccc      ierr = NF_DEF_VAR (nid, "NAT", NF_DOUBLE, 2,dims, id_NAT)
+      ierr = NF_DEF_VAR (nid, "NAT", NF_FLOAT, 2,dims, id_NAT)
+      ierr = NF_PUT_ATT_TEXT (nid, id_NAT, "title", 23,
+     .                        "Nature du sol (0,1,2,3)")
+ccc      ierr = NF_DEF_VAR (nid, "SST", NF_DOUBLE, 2,dims, id_SST)
+      ierr = NF_DEF_VAR (nid, "SST", NF_FLOAT, 2,dims, id_SST)
+      ierr = NF_PUT_ATT_TEXT (nid, id_SST, "title", 35,
+     .                        "Temperature superficielle de la mer")
+ccc      ierr = NF_DEF_VAR (nid, "BILS", NF_DOUBLE, 2,dims, id_BILS)
+      ierr = NF_DEF_VAR (nid, "BILS", NF_FLOAT, 2,dims, id_BILS)
+      ierr = NF_PUT_ATT_TEXT (nid, id_BILS, "title", 32,
+     .                        "Reference flux de chaleur au sol")
+ccc      ierr = NF_DEF_VAR (nid, "ALB", NF_DOUBLE, 2,dims, id_ALB)
+      ierr = NF_DEF_VAR (nid, "ALB", NF_FLOAT, 2,dims, id_ALB)
+      ierr = NF_PUT_ATT_TEXT (nid, id_ALB, "title", 19,
+     .                        "Albedo a la surface")
+ccc      ierr = NF_DEF_VAR (nid, "RUG", NF_DOUBLE, 2,dims, id_RUG)
+      ierr = NF_DEF_VAR (nid, "RUG", NF_FLOAT, 2,dims, id_RUG)
+      ierr = NF_PUT_ATT_TEXT (nid, id_RUG, "title", 8,
+     .                        "Rugosite")
+c
+      ierr = NF_ENDDEF(nid)
+c
+      DO k = 1, 360
+c
+      debut(1) = 1
+      debut(2) = k
+      epais(1) = klon
+      epais(2) = 1
+c
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR1_DOUBLE (nid,id_tim,k,DBLE(k))
+      ierr = NF_PUT_VARA_DOUBLE (nid,id_NAT,debut,epais,phy_nat(1,k))
+      ierr = NF_PUT_VARA_DOUBLE (nid,id_SST,debut,epais,phy_sst(1,k))
+      ierr = NF_PUT_VARA_DOUBLE (nid,id_BILS,debut,epais,phy_bil(1,k))
+      ierr = NF_PUT_VARA_DOUBLE (nid,id_ALB,debut,epais,phy_alb(1,k))
+      ierr = NF_PUT_VARA_DOUBLE (nid,id_RUG,debut,epais,phy_rug(1,k))
+#else
+      ierr = NF_PUT_VAR1_REAL (nid,id_tim,k,FLOAT(k))
+      ierr = NF_PUT_VARA_REAL (nid,id_NAT,debut,epais,phy_nat(1,k))
+      ierr = NF_PUT_VARA_REAL (nid,id_SST,debut,epais,phy_sst(1,k))
+      ierr = NF_PUT_VARA_REAL (nid,id_BILS,debut,epais,phy_bil(1,k))
+      ierr = NF_PUT_VARA_REAL (nid,id_ALB,debut,epais,phy_alb(1,k))
+      ierr = NF_PUT_VARA_REAL (nid,id_RUG,debut,epais,phy_rug(1,k))
+#endif
+c
+      ENDDO
+c
+      ierr = NF_CLOSE(nid)
+c
+      return
+      end
+
+      SUBROUTINE disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
+
+c    Auteur :  P. Le Van .
+c
+      IMPLICIT NONE
+
+#include "dimensions.h"
+#include "paramet.h"
+c
+c=======================================================================
+c
+c
+c    s = sigma ** kappa   :  coordonnee  verticale
+c    dsig(l)            : epaisseur de la couche l ds la coord.  s
+c    sig(l)             : sigma a l'interface des couches l et l-1
+c    ds(l)              : distance entre les couches l et l-1 en coord.s
+c
+c=======================================================================
+c
+      REAL pa,preff
+      REAL ap(llmp1),bp(llmp1),dpres(llm),nivsigs(llm),nivsig(llmp1)
+      REAL presnivs(llm)
+c
+c   declarations:
+c   -------------
+c
+      REAL sig(llm+1),dsig(llm)
+c
+      INTEGER l
+      REAL snorm
+      REAL alpha,beta,gama,delta,deltaz,h
+      INTEGER np,ierr
+      REAL pi,x
+
+c-----------------------------------------------------------------------
+c
+      pi=2.*ASIN(1.)
+
+      OPEN(99,file='sigma.def',status='old',form='formatted',
+     s   iostat=ierr)
+
+c-----------------------------------------------------------------------
+c   cas 1 on lit les options dans sigma.def:
+c   ----------------------------------------
+
+      IF (ierr.eq.0) THEN
+
+      print*,'WARNING!!! on lit les options dans sigma.def'
+      READ(99,*) deltaz
+      READ(99,*) h
+      READ(99,*) beta
+      READ(99,*) gama
+      READ(99,*) delta
+      READ(99,*) np
+      CLOSE(99)
+      alpha=deltaz/(llm*h)
+c
+
+       DO 1  l = 1, llm
+       dsig(l) = (alpha+(1.-alpha)*exp(-beta*(llm-l)))*
+     $          ( (tanh(gama*l)/tanh(gama*llm))**np +
+     $            (1.-l/FLOAT(llm))*delta )
+   1   CONTINUE
+
+       sig(1)=1.
+       DO 101 l=1,llm-1
+          sig(l+1)=sig(l)*(1.-dsig(l))/(1.+dsig(l))
+101    CONTINUE
+       sig(llm+1)=0.
+
+       DO 2  l = 1, llm
+       dsig(l) = sig(l)-sig(l+1)
+   2   CONTINUE
+c
+
+      ELSE
+c-----------------------------------------------------------------------
+c   cas 2 ancienne discretisation (LMD5...):
+c   ----------------------------------------
+
+      PRINT*,'WARNING!!! Ancienne discretisation verticale'
+
+      h=7.
+      snorm  = 0.
+      DO l = 1, llm
+         x = 2.*asin(1.) * (FLOAT(l)-0.5) / float(llm+1)
+         dsig(l) = 1.0 + 7.0 * SIN(x)**2
+         snorm = snorm + dsig(l)
+      ENDDO
+      snorm = 1./snorm
+      DO l = 1, llm
+         dsig(l) = dsig(l)*snorm
+      ENDDO
+      sig(llm+1) = 0.
+      DO l = llm, 1, -1
+         sig(l) = sig(l+1) + dsig(l)
+      ENDDO
+
+      ENDIF
+
+
+      DO l=1,llm
+        nivsigs(l) = FLOAT(l)
+      ENDDO
+
+      DO l=1,llmp1
+        nivsig(l)= FLOAT(l)
+      ENDDO
+
+c
+c    ....  Calculs  de ap(l) et de bp(l)  ....
+c    .........................................
+c
+c
+c   .....  pa et preff sont lus  sur les fichiers start par lectba  .....
+c
+
+      bp(llmp1) =   0.
+
+      DO l = 1, llm
+cc
+ccc    ap(l) = 0.
+ccc    bp(l) = sig(l)
+
+      bp(l) = EXP( 1. -1./( sig(l)*sig(l)) )
+      ap(l) = pa * ( sig(l) - bp(l) )
+c
+      ENDDO
+      ap(llmp1) = pa * ( sig(llmp1) - bp(llmp1) )
+
+      PRINT *,' BP '
+      PRINT *,  bp
+      PRINT *,' AP '
+      PRINT *,  ap
+
+      DO l = 1, llm
+       dpres(l) = bp(l) - bp(l+1)
+       presnivs(l) = 0.5 *( ap(l)+bp(l)*preff + ap(l+1)+bp(l+1)*preff )
+      ENDDO
+
+      PRINT *,' PRESNIVS '
+      PRINT *,presnivs
+
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/1Dconv.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/1Dconv.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/1Dconv.h	(revision 253)
@@ -0,0 +1,1755 @@
+        SUBROUTINE get_uvd(itap,dtime,tsol,qsol,file_fordat
+     s                    ,ht,hq,hw)
+
+        implicit none
+ 
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c cette routine permet d'obtenir u_convg,v_convg,ht,hq et ainsi de
+c pouvoir calculer la convergence et le cisaillement dans la physiq
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+#include "YOMCST.h"
+
+      INTEGER klev
+      REAL play(100)  !pression en Pa au milieu de chaque couche GCM
+      INTEGER JM(100) !pression en Pa au milieu de chaque couche GCM
+      REAL coef1(100) !coefficient d'interpolation
+      REAL coef2(100) !coefficient d'interpolation
+
+      INTEGER nblvlm !nombre de niveau de pression du mesoNH
+      REAL playm(100)  !pression en Pa au milieu de chaque couche Meso-NH
+      REAL hplaym(100) !pression en hPa milieux des couches Meso-NH
+
+      integer i,j,k,ii,ll,in
+      REAL tsol,qsol
+
+      CHARACTER*80 file_forctl,file_fordat,file_start
+
+      COMMON/physiq1/klev,play,JM,coef1,coef2
+      COMMON/physiq2/nblvlm,playm,hplaym
+
+c======================================================================
+c methode: on va chercher les donnees du mesoNH de meteo france, on y
+c          a acces a tout pas detemps grace a la routine rdgrads qui
+c          est une boucle lisant dans ces fichiers.
+c          Puis on interpole ces donnes sur les 11 niveaux du gcm et
+c          et sur les pas de temps de ce meme gcm
+c======================================================================
+c input:
+c       pasmax     :nombre de pas de temps maximum du mesoNH
+c       dt         :pas de temps du meso_NH (en secondes)
+c----------------------------------------------------------------------
+      integer pasmax,dt
+      save pasmax,dt
+c----------------------------------------------------------------------
+c arguments:
+c           itap   :compteur de la physique(le nombre de ces pas est
+c                   fixe dans la subroutine calcul_ini_gcm de interpo
+c                   -lation
+c           dtime  :pas detemps du gcm (en secondes)
+c           ht     :convergence horizontale de temperature(K/s)
+c           hq     :    "         "       d'humidite (kg/kg/s)
+c           hw     :vitesse verticale moyenne (m/s**2)
+c----------------------------------------------------------------------
+        integer itap
+        real dtime
+        real ht(100)
+        real hq(100)
+        real hw(100)
+c----------------------------------------------------------------------
+c Variables internes de get_uvd (note : l'interpolation temporelle
+c est faite entre les pas de temps before et after, sur les variables
+c definies sur la grille du SCM)
+c     time0     :date initiale en secondes
+c     time      :temps associe a chaque pas
+c     pas       :numero du pas du meso_NH
+c     pasprev   :numero du pas precedent
+c     htaft     :advection horizontale de temp. au pas de temps after
+c     hqaft     :    "         "      d'humidite        "
+c     hwaft     :vitesse verticalle moyenne  au pas de temps after
+c     htbef     :idem htaft, mais pour le pas de temps before
+c     hqbef     :voir hqaft
+c     hwbef     :voir hwaft
+c----------------------------------------------------------------------
+        integer time0,pas,pasprev
+        save time0,pas,pasprev
+        real time
+        real htaft(100),hqaft(100),hwaft(100)
+        save htaft,hqaft,hwaft
+        real htbef(100),hqbef(100),hwbef(100)
+        save htbef,hqbef,hwbef
+        integer timeaft,timebef
+        save timeaft,timebef
+        integer temps
+        character*4 string
+c----------------------------------------------------------------------
+c variables arguments de la subroutine rdgrads
+c---------------------------------------------------------------------
+        integer icompt      !compteur de rdgrads
+        real z(100)         ! altitude (grille Meso)
+        real ht_mes(100)    !convergence horizontale de temperature
+                            !-(grille Meso)
+        real hq_mes(100)    !convergence horizontale d'humidite
+                            !(grille Meso)
+        real hw_mes(100)    !vitesse verticale moyenne
+                            !(grille Meso)
+c
+c---------------------------------------------------------------------
+c variable argument de la subroutine copie
+c---------------------------------------------------------------------
+c SB        real pplay(100)    !pression en milieu de couche du gcm
+c SB                            !argument de la physique
+c---------------------------------------------------------------------
+c variables destinees a la lecture du pas de temps du fichier de donnees
+c---------------------------------------------------------------------
+       character*80 aaa,atemps,spaces,apasmax
+       integer nch,imn,ipa
+c---------------------------------------------------------------------
+c  procedures appelees
+        external rdgrads    !lire en iterant dans forcing.dat
+c---------------------------------------------------------------------
+               print*,'le pas itap est:',itap
+c*** on determine le pas du meso_NH correspondant au nouvel itap ***
+c*** pour aller chercher les champs dans rdgrads                 ***
+        time=time0+itap*dtime
+        temps=int(time/dt+1)
+        pas=min(temps,pasmax)
+             print*,'le pas Meso est:',pas
+c
+c
+c===================================================================
+c
+c*** on remplit les champs before avec les champs after du pas   ***
+c*** precedent en format gcm                                     ***
+        if(pas.gt.pasprev)then
+               do i=1,klev
+                  htbef(i)=htaft(i)
+                  hqbef(i)=hqaft(i)
+                  hwbef(i)=hwaft(i)
+               enddo
+               timebef=pasprev*dt
+               timeaft=timebef+dt
+               icompt=(pas-1)*(nblvlm*4)
+                       print*,'le pas pas est:',pas
+c*** on va chercher les nouveaux champs after dans toga.dat     ***
+c*** champs en format meso_NH                                   ***
+c          open(99,FILE='forcing.dat',FORM='UNFORMATTED',
+
+          write(*,'(a)') 'OPEN dans get_uvd de '//file_fordat
+          open(99,FILE=file_fordat,FORM='UNFORMATTED',
+     .             ACCESS='DIRECT',RECL=4)
+          call rdgrads(99,icompt,nblvlm,z,ht_mes,hq_mes,hw_mes)
+          do i = 1,nblvlm
+            ht_mes(i) = ht_mes(i)*(hplaym(i)/1000.)**rkappa
+          enddo
+c
+               print*,'ht_mes ',(ht_mes(i),i=1,nblvlm)
+               print*,'hq_mes ',(hq_mes(i),i=1,nblvlm)
+               print*,'hw_mes ',(hw_mes(i),i=1,nblvlm)
+c*** on interpole les champs meso_NH sur les niveaux de pression***
+c*** gcm . on obtient le nouveau champ after                    ***
+            do k=1,klev
+             if (JM(k) .eq. 0) then
+         htaft(k)=coef1(k)*tsol+coef2(k)*ht_mes(jm(k)+1)
+         hqaft(k)=coef1(k)*qsol+coef2(k)*hq_mes(jm(k)+1)
+         hwaft(k)=              coef2(k)*hw_mes(jm(k)+1)
+             else
+         htaft(k)=coef1(k)*ht_mes(jm(k))+coef2(k)*ht_mes(jm(k)+1)
+         hqaft(k)=coef1(k)*hq_mes(jm(k))+coef2(k)*hq_mes(jm(k)+1)
+         hwaft(k)=coef1(k)*hw_mes(jm(k))+coef2(k)*hw_mes(jm(k)+1)
+             endif
+            enddo
+          pasprev=pas
+         else
+                      print*,'timebef est:',timebef
+         endif      !fin du bloc relatif au passage au pas
+                    !de temps (meso) suivant
+c*** si on atteint le pas max des donnees experimentales ,on     ***
+c*** on conserve les derniers champs calcules                    ***
+      if(pas.ge.pasmax)then
+          do ll=1,klev
+               ht(ll)=htaft(ll)
+               hq(ll)=hqaft(ll)
+               hw(ll)=hwaft(ll)
+          enddo
+      else
+c*** on interpole sur les pas de temps de 10mn du gcm a partir   ***
+c** des pas de temps de 1h du meso_NH                            ***
+         do j=1,klev
+         ht(j)=((timeaft-time)*htbef(j)+(time-timebef)*htaft(j))/dt
+         hq(j)=((timeaft-time)*hqbef(j)+(time-timebef)*hqaft(j))/dt
+         hw(j)=((timeaft-time)*hwbef(j)+(time-timebef)*hwaft(j))/dt
+         enddo
+       endif
+c
+c-------------------------------------------------------------------
+c
+         return
+c
+c-----------------------------------------------------------------------
+c on sort les champs de "convergence" pour l'instant initial 'in'
+c ceci se passe au pas temps itap=0 de la physique
+c-----------------------------------------------------------------------
+        entry get_uvd2(itap,file_forctl,file_fordat,file_start
+     s                ,ht,hq,hw)
+             print*,'le pas itap est:',itap
+c
+c===================================================================
+c
+      write(*,*) '   '
+      write(*,*) 'FICHIERS A LIRE DANS GET_UVD2:   '
+      write(*,'(a)') 'fichier forcing.ctl: '//file_forctl
+      write(*,'(a)') 'fichier forcing.dat: '//file_fordat
+      write(*,'(a)') 'fichier start18.data: '//file_start
+      write(*,*) '   '
+
+c!! en attendant de pouvoir compiler les fns CERN, en prescrit
+c!! les variables imn et pasmax a la main...
+c!!
+       write(*,'(a)') 'OPEN '//file_forctl
+       open(97,FILE=file_forctl,FORM='FORMATTED')
+c
+c------------------
+      do i=1,1000
+      read(97,1000,end=999) string
+ 1000 format (a4)
+      if (string .eq. 'TDEF') go to 50
+      enddo
+ 50   backspace(97)
+c-------------------------------------------------------------------
+c   *** on lit le pas de temps dans le fichier de donnees ***
+c   *** "forcing.ctl" et pasmax                           ***
+c-------------------------------------------------------------------
+      read(97,2000) aaa
+2000  format (a80)
+         print*,'aaa est',aaa
+      aaa=spaces(aaa,1)
+         print*,'aaa',aaa
+      call getsch(aaa,' ',' ',5,atemps,nch)
+         print*,'atemps est',atemps
+        atemps=atemps(1:nch-2)
+         print*,'atemps',atemps
+        read(atemps,*) imn
+        dt=imn*60
+         print*,'le pas de temps dt',dt
+      call getsch(aaa,' ',' ',2,apasmax,nch)
+        apasmax=apasmax(1:nch)
+        read(apasmax,*) ipa
+        pasmax=ipa
+         print*,'pasmax est',pasmax
+      CLOSE(97)
+
+c CASE_E:
+c!!         imn = 60
+c!!         ipa = 8
+c TOGA:
+c!!         imn = 360
+c!!         ipa = 480
+
+         dt=imn*60
+         pasmax=ipa
+         print*,'le pas de temps dt',dt
+         print*,'pasmax est',pasmax
+
+
+c------------------------------------------------------------------
+c *** onlit le pas de temps initial de la simulation dans ***
+c *** "start.data"                                        ***
+c------------------------------------------------------------------
+c      open(98,file='start18.data',form='formatted')
+      write(*,'(a)') 'OPEN '//file_start
+      open(98,FILE=file_start,FORM='FORMATTED')
+          read(98,*)in
+                  pasprev=in
+                    print*,'le pas in ini est:',pasprev
+C
+Cjyg     Correction de la date du demarrage.
+CC                  time0=dt*pasprev
+                  time0=dt*(pasprev-1)
+C
+          close(98)
+c
+c      open(99,FILE='forcing.dat',FORM='UNFORMATTED',
+      write(*,'(a)') 'OPEN '//file_fordat
+      open(99,FILE=file_fordat,FORM='UNFORMATTED',
+     .          ACCESS='DIRECT',RECL=4)
+                  icompt=(in-1)*(nblvlm*4)
+        call rdgrads(99,icompt,nblvlm,z,ht_mes,hq_mes,hw_mes)
+          do i = 1,nblvlm
+            ht_mes(i) = ht_mes(i)*(hplaym(i)/1000.)**rkappa
+          enddo
+c
+               print*,'ht_mes ',(ht_mes(i),i=1,nblvlm)
+               print*,'hq_mes ',(hq_mes(i),i=1,nblvlm)
+               print*,'hw_mes ',(hw_mes(i),i=1,nblvlm)
+c----------------------------------------------------------------------
+c on a obtenu des champs initiaux sur les niveaux du meso_NH
+c on interpole sur les niveaux du gcm(niveau pression bien sur!)
+c-----------------------------------------------------------------------
+         do ii=1,klev
+         htaft(ii)=coef1(ii)*ht_mes(JM(ii))+coef2(ii)*ht_mes(JM(ii)+1)
+         hqaft(ii)=coef1(ii)*hq_mes(JM(ii))+coef2(ii)*hq_mes(JM(ii)+1)
+         hwaft(ii)=coef1(ii)*hw_mes(JM(ii))+coef2(ii)*hw_mes(JM(ii)+1)
+             enddo
+c valeurs initiales des champs de convergence
+          do k=1,klev
+             ht(k)=htaft(k)
+             hq(k)=hqaft(k)
+             hw(k)=hwaft(k)
+          enddo
+        close(99)
+        close(98)
+c
+c-------------------------------------------------------------------
+c
+ 100    return
+c
+999     continue
+        stop 'erreur lecture, file forcing.ctl'
+        end
+ 
+ 
+      SUBROUTINE cool_pool(istep
+     e                    ,n_cooling,dt_cooling,dq_cooling
+     s                    ,dt_cool,dq_cool)
+       implicit none
+C***************************************************************
+C*                                                             *
+C* COOL_POOL                                                   *
+C*                                                             *
+C*                                                             *
+C* written by   : Gilles Foret RAMSES, 15/09/97, 22.00.2       *
+C* modified by :  Sandrine Bony 10/09/98                       *
+C***************************************************************
+c Arguments
+c =========
+c Input
+c -----
+c   istep : numero du pas de temps
+c   n_cooling: nbre de pas de temps ou la pertubation nominale
+c              est appliquee (ensuite, la pertubation decroit
+c              exponentiellement).
+c   dt_cooling : pertubation nominale en temperature
+c   dq_cooling : pertubation nominale en humidite
+c Output
+c ------
+c    dt_cool : pertubation en temperature
+c    dq_cool : pertubation en humidite
+c
+c Variables internes
+c ==================
+c    scale :  facteur applique a la pertubation nominale
+c
+#include "dimensions.h"
+#include "dimphy.h"
+c
+      integer n_cooling,k,istep
+      real dt_cooling(klev),dq_cooling(klev),scale
+      real dt_cool(klev),dq_cool(klev)
+c
+      if (istep .le. n_cooling ) then
+        scale = 1.
+      else
+        scale = 4**(min(15,istep-n_cooling))
+      endif
+c
+        do k = 1,klev
+          dt_cool(k) = dt_cooling(k)/scale
+          dq_cool(k) = dq_cooling(k)/scale
+        enddo
+c
+      return
+      end
+      SUBROUTINE advect_tvl(dtime,t,q,vu_f,vv_f,t_f,q_f
+     :                     ,d_t_adv,d_q_adv)
+      implicit none
+
+#include "dimensions.h"
+#include "dimphy.h"
+
+      integer k
+      real dtime, fact, du, dv, cx, cy, alx, aly
+      real t(klev), q(klev,3)
+     :   , vu_f(klev), vv_f(klev), t_f(klev), q_f(klev,3)
+
+      real d_t_adv(klev), d_q_adv(klev,3)
+
+c Velocity of moving cell
+      data cx,cy /12., -2./
+
+c Dimensions of moving cell
+      data alx,aly /100 000.,150 000./
+
+      do k = 1, klev
+            du = abs(vu_f(k)-cx)/alx
+            dv = abs(vv_f(k)-cy)/aly
+            fact = dtime *(du+dv-du*dv*dtime)
+            d_t_adv(k) = fact * (t_f(k)-t(k))
+            d_q_adv(k,1) = fact * (q_f(k,1)-q(k,1))
+            d_q_adv(k,2) = fact * (q_f(k,2)-q(k,2))
+            d_q_adv(k,3) = fact * (q_f(k,3)-q(k,3))
+      enddo
+
+      return
+      end
+      SUBROUTINE copie(klevgcm,playgcm,psolgcm,file_forctl)
+      implicit none
+
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c cette routine remplit les COMMON physiq1 et physiq2.h
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      INTEGER JM
+      INTEGER klev !nombre de niveau de pression du GCM
+      INTEGER nblvlm !nombre de niveau de pression du mesoNH
+
+      REAL playm(100) !pression en Pa au milieu de chaque couche Meso-NH
+      REAL hplaym(100)!pression en hecto-Pa des milieux de couche Meso-NH
+      REAL play(100)  !pression en Pa au milieu de chaque couche GCM
+      REAL coef1(100)   !coefficient d'interpolation
+      REAL coef2(100)   !coefficient d'interpolation
+
+      COMMON/physiq1/klev,play,JM,coef1,coef2
+      COMMON/physiq2/nblvlm,playm,hplaym
+
+      integer i,k,klevgcm
+      real playgcm(klevgcm) ! pression en milieu de couche du gcm
+      real psolgcm
+      character*80 file_forctl
+
+      klev = klevgcm
+
+c---------------------------------------------------------------------
+c pression au milieu des couches du gcm dans la physiq
+c (SB: remplace le call conv_lipress_gcm(playgcm) )
+c---------------------------------------------------------------------
+
+       do k = 1, klev
+        play(k) = playgcm(k)
+        print*,'la pression gcm est:',play(k)
+       enddo
+
+c----------------------------------------------------------------------
+c lecture du descripteur des donnees Meso-NH (forcing.ctl):
+c  -> nb niveaux du meso.NH (nblvlm) + pressions meso.NH
+c (on remplit le COMMON physiq2)
+c----------------------------------------------------------------------
+
+      call mesolupbis(file_forctl)
+
+      print*,'la valeur de nblvlm est:',nblvlm
+
+c----------------------------------------------------------------------
+c etude de la correspondance entre les niveaux meso.NH et GCM;
+c calcul des coefficients d'interpolation coef1 et coef2
+c (on remplit le COMMON physiq1)
+c----------------------------------------------------------------------
+
+      call corresbis(psolgcm)
+
+c---------------------------------------------------------
+c TEST sur le remplissage de physiq1 et physiq2:
+c---------------------------------------------------------
+ 
+      write(*,*) ' '
+      write(*,*) 'TESTS physiq1 et physiq2 dans copie.F '
+      write(*,*) '--------------------------------------'
+      write(*,*) 'GCM: nb niveaux:',klev,' et pression, coeffs:'
+      do k = 1, klev
+      write(*,*) play(k), coef1(k), coef2(k)
+      enddo
+      write(*,*) 'MESO-NH: nb niveaux:',nblvlm,' et pression:'
+      do k = 1, nblvlm
+      write(*,*) playm(k), hplaym(k)
+      enddo
+      write(*,*) ' '
+
+      end
+      SUBROUTINE writeg1d(ngrid,nx,x,nom,titre)
+      IMPLICIT NONE
+c.......................................................................
+c
+c  ecriture de x pour GRADS-1D
+c
+c  in :
+c         * ngrid      ---> pour controler que l'on est bien en 1D
+c         * nx         ---> taille du vecteur a stocker
+c                             "1" pour une variable de surface
+c                             "nlayer" pour une variable de centre de couche
+c                             "nlayer+1" pour une variable d'interface
+c         * x          ---> variable a stocker
+c         * nom        ---> nom "pour grads"
+c         * titre      ---> titre "pour grads"
+c
+c.......................................................................
+c
+#include "comg1d.h"
+c
+c.......................................................................
+c  declaration des arguments 
+c
+      INTEGER ngrid,nx
+      REAL x(nx)
+      CHARACTER*(*) nom
+      CHARACTER*(*) titre
+c
+c  declaration des arguments 
+c....................................................................... 
+c  declaration des variables locales
+c
+      INTEGER ilayer,ivar
+      LOGICAL test 
+c
+c  declaration des variables locales
+c.......................................................................
+c  contole 1D
+c
+c     print*,'ngrid=',ngrid
+      IF (ngrid.NE.1) return
+c
+c  contole 1D
+c.......................................................................
+c  ouverture du fichier au premier appel
+c
+      IF (g1d_premier) THEN
+        OPEN (g1d_unitfich,FILE=g1d_nomfich
+     &       ,FORM='unformatted',ACCESS='direct',RECL=4)
+        g1d_irec=0
+        g1d_nvar=0
+        g1d_premier=.false.
+      ENDIF
+c
+c  ouverture du fichier au premier appel
+c.......................................................................
+c  pour l'ecriture du fichier ctl
+c
+      test=.true.
+      DO ivar=1,g1d_nvar
+        IF (nom.EQ.g1d_nomvar(ivar)) test=.false.
+      ENDDO
+      IF (test) THEN
+        g1d_nvar=g1d_nvar+1
+        g1d_nomvar(g1d_nvar)=nom
+        g1d_titrevar(g1d_nvar)=titre
+        IF (nx.EQ.1) THEN
+           g1d_dimvar(g1d_nvar)=0
+        ELSEIF (nx.EQ.g1d_nlayer) THEN
+           g1d_dimvar(g1d_nvar)=g1d_nlayer
+        ELSEIF (nx.EQ.g1d_nlayer+1) THEN
+           g1d_dimvar(g1d_nvar)=g1d_nlayer
+        ELSE
+           PRINT *,'._. probleme de dimension dans GRADS-1D ._.'
+        ENDIF
+      ENDIF
+c
+c  pour l'ecriture du fichier ctl
+c.......................................................................
+c  ecriture
+c
+      IF (nx.EQ.1) THEN
+        g1d_irec=g1d_irec+1
+        WRITE(g1d_unitfich,REC=g1d_irec) x(1)
+      ELSE
+        DO ilayer=1,g1d_nlayer
+          g1d_irec=g1d_irec+1
+          WRITE(g1d_unitfich,REC=g1d_irec) x(ilayer)
+        ENDDO
+      ENDIF
+c
+c  ecriture
+c.......................................................................
+c
+10001 CONTINUE
+c
+c.......................................................................
+c
+      RETURN
+      END
+
+
+
+
+
+
+c SB      SUBROUTINE endg1d(ngrid,nlayer,zlayer,ndt)
+      SUBROUTINE endg1d(ngrid,nlayer,player,ndt,dt)
+      IMPLICIT NONE
+c.......................................................................
+c
+c  ecriture du fichier de controle pour GRADS-1D
+c
+c  in :
+c         * ngrid      ---> pour controler que l'on est bien en 1D
+c         * nlayer     ---> nombre de couches
+c         * zlayer     ---> altitude au centre de chaque couche (km)
+c         * player     ---> pression au centre de chaque couche (hPa)
+c         * ndt        ---> nombre de pas de temps
+c         * dt         ---> valeur du pas de temps (s)
+c
+c.......................................................................
+c
+#include "comg1d.h"
+c
+c.......................................................................
+c  declaration des arguments 
+c
+      INTEGER ngrid,nlayer
+c SB      REAL zlayer(nlayer)
+      REAL player(nlayer)
+      INTEGER ndt
+      REAL dt,dtm
+c
+c  declaration des arguments 
+c....................................................................... 
+c  declaration des variables locales
+c
+      INTEGER ivar,ilayer
+c
+c  declaration des variables locales
+c.......................................................................
+c  contole 1D
+c
+      IF (ngrid.NE.1) GOTO 10001
+c
+c  contole 1D
+c.......................................................................
+c
+      IF (nlayer.ne.g1d_nlayer) 
+     &   PRINT *,'._. probleme de dimension dans GRADS-1D ._.'
+c
+c.......................................................................
+c
+      CLOSE (g1d_unitfich)
+c
+c.......................................................................
+c
+      dtm = dt/60.
+
+      OPEN (g1d_unitctl,FILE=g1d_nomctl,FORM='formatted'
+     s     ,status='new')
+      WRITE (g1d_unitctl,'(a4,2x,a20)') 'DSET',g1d_nomfich
+      WRITE (g1d_unitctl,'(a5,2x,a20)') 'UNDEF ','1.E+30'
+      WRITE (g1d_unitctl,'(a11)') 'FORMAT YREV'
+      WRITE (g1d_unitctl,'(a5,2x,a30)') 'TITLE ','champs 1D'
+      WRITE (g1d_unitctl,'(a5,i4,a20)') 'XDEF ',1,' LINEAR 0 1'
+      WRITE (g1d_unitctl,'(a5,i4,a20)') 'YDEF ',1,' LINEAR 0 1'
+      WRITE (g1d_unitctl,'(a5,i4,a20)') 'ZDEF ',g1d_nlayer,' LEVELS'
+      WRITE (g1d_unitctl,'(5(1x,f13.5))')
+c SB     &      (zlayer(ilayer),ilayer=1,g1d_nlayer)
+     &      (player(ilayer)/100.,ilayer=1,g1d_nlayer)
+c SB      WRITE (g1d_unitctl,'(a4,2x,i10,a25)')
+c SB     &      'TDEF ',ndt,' LINEAR 02JAN1987 1HR '
+      WRITE (g1d_unitctl,'(a4,2x,i10,a20,i3,a3)')
+     &      'TDEF ',ndt,' LINEAR 02JAN1987 ',INT(dtm),'MN '
+      WRITE (g1d_unitctl,'(a5,i5)') 'VARS ',g1d_nvar
+      DO ivar=1,g1d_nvar
+      WRITE (g1d_unitctl,'(a5,3x,i4,i3,1x,a39)') 
+     &       g1d_nomvar(ivar),g1d_dimvar(ivar),99,g1d_titrevar(ivar)
+      ENDDO
+      WRITE (g1d_unitctl,'(a7)') 'ENDVARS'
+      CLOSE (g1d_unitctl)
+c
+c.......................................................................
+c
+10001 CONTINUE
+c
+c.......................................................................
+c
+      RETURN
+      END
+      SUBROUTINE mesolupbis(file_forctl)
+      implicit none 
+c
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c
+c Lecture descripteur des donnees MESO-NH (forcing.ctl):
+c -------------------------------------------------------
+c
+c     Cette subroutine lit dans le fichier de controle "essai.ctl"
+c     et affiche le nombre de niveaux du Meso-NH ainsi que les valeurs
+c     des pressions en milieu de couche du Meso-NH (en Pa puis en hPa).
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c
+      INTEGER nblvlm !nombre de niveau de pression du mesoNH
+      REAL playm(100)  !pression en Pa milieu de chaque couche Meso-NH
+      REAL hplaym(100) !pression en hPa des milieux de couche Meso-NH
+      COMMON/physiq2/nblvlm,playm,hplaym
+
+      INTEGER i,lu,k,mlz,mlzh,j
+ 
+      character*80 file_forctl
+
+      character*4 a
+      character*80 aaa,anblvl,spaces
+      integer nch
+
+      lu=9
+c      open (lu,file='forcing.ctl')
+      open(lu,file=file_forctl,form='formatted')
+c
+      do i=1,1000
+      read(lu,1000,end=999) a
+      if (a .eq. 'ZDEF') go to 100
+      enddo
+c
+ 100  backspace(lu)
+      print*,'  DESCRIPTION DES 2 MODELES : '
+      print*,' '
+c
+      read(lu,2000) aaa
+ 2000  format (a80)
+       aaa=spaces(aaa,1)
+       call getsch(aaa,' ',' ',2,anblvl,nch)
+         read(anblvl,*) nblvlm
+
+c      write(*,*) 'ATTENTION! dans mesolupbis on rentre
+c     : nblvlm a la main car pas de bibliotheque CERN..:'
+c CASE_e:
+c!          nblvlm = 43
+c TOGA:
+c!!          nblvlm = 40
+c
+      print*,'nbre de niveaux de pression Meso-NH :',nblvlm
+      print*,' '
+      print*,'pression en Pa de chaque couche du meso-NH :'
+c
+      read(lu,*) (playm(mlz),mlz=1,nblvlm)
+c      Si la pression est en HPa, la multiplier par 100
+      if (playm(1) .lt. 10000.) then
+        do mlz = 1,nblvlm
+         playm(mlz) = playm(mlz)*100.
+        enddo
+      endif
+      print*,(playm(mlz),mlz=1,nblvlm)
+c
+ 1000 format (a4)
+ 1001 format(5x,i2)
+c
+      print*,' '
+      do mlzh=1,nblvlm
+      hplaym(mlzh)=playm(mlzh)/100.
+      enddo
+c
+      print*,'pression en hPa de chaque couche du meso-NH: '
+      print*,(hplaym(mlzh),mlzh=1,nblvlm)
+c
+      close (lu)
+      return
+c
+ 999  stop 'erreur lecture des niveaux pression des donnees'
+      end
+      SUBROUTINE GETSCH(STR,DEL,TRM,NTH,SST,NCH)
+C***************************************************************
+C*                                                             *
+C*                                                             *
+C* GETSCH                                                      *
+C*                                                             *
+C*                                                             *
+C* modified by :                                               *
+C***************************************************************
+C*   Return in SST the character string found between the NTH-1 and NTH
+C*   occurence of the delimiter 'DEL' but before the terminator 'TRM' in
+C*   the input string 'STR'. If TRM=DEL then STR is considered unlimited.
+C*   NCH=Length of the string returned in SST or =-1 if NTH is <1 or if
+C*   NTH is greater than the number of delimiters in STR.
+      IMPLICIT INTEGER (A-Z)
+      CHARACTER STR*(*),DEL*1,TRM*1,SST*(*)
+      NCH=-1
+      SST=' '
+      IF(NTH.GT.0) THEN
+        IF(TRM.EQ.DEL) THEN
+          LENGTH=LEN(STR)
+        ELSE
+          LENGTH=INDEX(STR,TRM)-1
+          IF(LENGTH.LT.0) LENGTH=LEN(STR)
+        ENDIF
+C*     Find beginning and end of the NTH DEL-limited substring in STR
+        END=-1
+        DO 1,N=1,NTH
+        IF(END.EQ.LENGTH) RETURN
+        BEG=END+2
+        END=BEG+INDEX(STR(BEG:LENGTH),DEL)-2
+        IF(END.EQ.BEG-2) END=LENGTH
+C*        PRINT *,'NTH,LENGTH,N,BEG,END=',NTH,LENGTH,N,BEG,END
+    1   CONTINUE
+        NCH=END-BEG+1
+        IF(NCH.GT.0) SST=STR(BEG:END)
+      ENDIF
+      END
+      SUBROUTINE rdgrads(itape,icount,nl,z,ht,hq,hw)
+      IMPLICIT none
+
+      INTEGER itape,icount,icomp, nl
+      real z(nl),ht(nl),hq(nl),hw(nl)
+c
+      INTEGER i, k
+c
+      icomp = icount
+c
+c
+         do k=1,nl
+            icomp=icomp+1
+            read(itape,rec=icomp)z(k)
+         enddo
+         do k=1,nl
+            icomp=icomp+1
+            read(itape,rec=icomp)hT(k)
+         enddo
+         do k=1,nl
+            icomp=icomp+1
+            read(itape,rec=icomp)hQ(k)
+         enddo
+         do k=1,nl
+            icomp=icomp+1
+            read(itape,rec=icomp)hw(k)
+         enddo
+c
+c
+      RETURN
+      END
+      SUBROUTINE corresbis(psol)
+      implicit none
+
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c Cette subroutine calcule et affiche les valeurs des coefficients
+c d'interpolation qui serviront dans la formule d'interpolation elle-
+c meme.
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      INTEGER klev    !nombre de niveau de pression du GCM
+      REAL play(100)  !pression en Pa au milieu de chaque couche GCM
+      INTEGER JM(100)
+      REAL coef1(100) !coefficient d'interpolation
+      REAL coef2(100) !coefficient d'interpolation
+
+      INTEGER nblvlm !nombre de niveau de pression du mesoNH
+      REAL playm(100) !pression en Pa milieu de chaque couche Meso-NH
+      REAL hplaym(100)!pression en hPa des milieux de couche Meso-NH
+
+      COMMON/physiq1/klev,play,JM,coef1,coef2
+      COMMON/physiq2/nblvlm,playm,hplaym
+
+      REAL psol
+      REAL val
+      INTEGER k, mlz, mlzh
+
+
+      do k=1,klev
+         val=play(k)
+       if (val .gt. playm(1)) then
+          mlz = 0
+          JM(1) = mlz
+          coef1(1)=(playm(mlz+1)-val)
+     *             /(playm(mlz+1)-psol)
+          coef2(1)=(val-psol)
+     *             /(playm(mlz+1)-psol)
+       else
+         do mlz=1,nblvlm
+          if (     val .le. playm(mlz)
+     *       .and. val .gt. playm(mlz+1))then
+           JM(k)=mlz
+           coef1(k)=(playm(mlz+1)-val)
+     *              /(playm(mlz+1)-playm(mlz))
+           coef2(k)=(val-playm(mlz))
+     *              /(playm(mlz+1)-playm(mlz))
+          endif
+c
+         enddo
+       endif
+      enddo
+c
+      if (play(klev) .le. playm(nblvlm)) then
+         mlz=nblvlm-1
+         JM(klev)=mlz
+         coef1(klev)=(playm(mlz+1)-val)
+     *            /(playm(mlz+1)-playm(mlz))
+         coef2(klev)=(val-playm(mlz))
+     *            /(playm(mlz+1)-playm(mlz))
+      endif
+c
+      print*,' '
+      print*,'         INTERPOLATION  : '
+      print*,' '
+      print*,'correspondance de 9 niveaux du GCM sur les 53 du meso-NH:'
+      print*,(JM(k),k=1,klev)
+      print*,'correspondance de 9 niveaux du GCM sur les 53 du meso-NH:'
+      print*,(JM(k),k=1,klev)
+      print*,' '
+      print*,'valeurs du premier coef d"interpolation pour les 9 niveaux
+     *: '
+      print*,(coef1(k),k=1,klev)
+      print*,' '
+      print*,'valeurs du deuxieme coef d"interpolation pour les 9 niveau
+     *x: '
+      print*,(coef2(k),k=1,klev)
+c
+      return
+      end
+      SUBROUTINE phyredem (fichnom,dtime,radpas,co2_ppm,solaire,
+     .           rlat,rlon,tsol,tsoil,deltat,qsol,snow,
+     .           radsol,rugmer,agesno,
+     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel,
+     .           t_ancien, q_ancien)
+      IMPLICIT none
+c======================================================================
+c Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
+c Objet: Ecriture de l'etat de redemarrage pour la physique
+c======================================================================
+#include "dimensions.h"
+#include "dimphy.h"
+#include "netcdf.inc"
+#include "indicesol.h"
+#include "dimsoil.h"
+#include "clesphys.h"
+#include "control.h"
+#include "temps.h"
+c======================================================================
+      CHARACTER*(*) fichnom
+      REAL dtime
+      INTEGER radpas
+      REAL rlat(klon), rlon(klon)
+      REAL co2_ppm
+      REAL solaire
+      REAL tsol(klon,nbsrf)
+      REAL tsoil(klon,nsoilmx,nbsrf)
+      REAL deltat(klon)
+      REAL qsol(klon,nbsrf)
+      REAL snow(klon,nbsrf)
+      REAL radsol(klon)
+      REAL rugmer(klon)
+      REAL agesno(klon)
+      REAL zmea(klon)
+      REAL zstd(klon)
+      REAL zsig(klon)
+      REAL zgam(klon)
+      REAL zthe(klon)
+      REAL zpic(klon)
+      REAL zval(klon)
+      REAL rugsrel(klon)
+      REAL t_ancien(klon,klev), q_ancien(klon,klev)
+c
+      INTEGER nid, nvarid, idim1, idim2, idim3
+      INTEGER ierr
+      INTEGER length
+      PARAMETER (length=100)
+      REAL tab_cntrl(length)
+c
+      INTEGER isoil, nsrf
+      CHARACTER*7 str7
+      CHARACTER*2 str2
+c
+      ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
+      IF (ierr.NE.NF_NOERR) THEN
+        write(6,*)' Pb d''ouverture du fichier '//fichnom
+        write(6,*)' ierr = ', ierr
+        CALL ABORT
+      ENDIF
+c
+      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 28,
+     .                       "Fichier redemmarage physique")
+c
+      ierr = NF_DEF_DIM (nid, "index", length, idim1)
+      ierr = NF_DEF_DIM (nid, "points_physiques", klon, idim2)
+      ierr = NF_DEF_DIM (nid, "horizon_vertical", klon*klev, idim3)
+c
+      ierr = NF_ENDDEF(nid)
+c
+      DO ierr = 1, length
+         tab_cntrl(ierr) = 0.0
+      ENDDO
+      tab_cntrl(1) = dtime
+      tab_cntrl(2) = radpas
+      tab_cntrl(3) = co2_ppm
+      tab_cntrl(4) = solaire
+      tab_cntrl(5) = iflag_con
+      tab_cntrl(6) = nbapp_rad
+
+      IF( cycle_diurne ) tab_cntrl( 7 ) = 1.
+      IF(   soil_model ) tab_cntrl( 8 ) = 1.
+      IF(     new_oliq ) tab_cntrl( 9 ) = 1.
+      IF(     ok_orodr ) tab_cntrl(10 ) = 1.
+      IF(     ok_orolf ) tab_cntrl(11 ) = 1.
+
+      tab_cntrl(13) = dayref
+      tab_cntrl(14) = anneeref
+      tab_cntrl(13) = day_end
+      tab_cntrl(14) = anne_ini
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "controle", NF_DOUBLE, 1, idim1,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "controle", NF_FLOAT, 1, idim1,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 22,
+     .                        "Parametres de controle")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "longitude", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "longitude", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 32,
+     .                        "Longitudes de la grille physique")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlon)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlon)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "latitude", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "latitude", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 31,
+     .                        "Latitudes de la grille physique")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlat)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlat)
+#endif
+c
+c
+      DO nsrf = 1, nbsrf
+        IF (nsrf.LE.99) THEN
+        WRITE(str2,'(i2.2)') nsrf
+        ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+        ierr = NF_DEF_VAR (nid, "TS"//str2, NF_DOUBLE, 1, idim2,nvarid)
+#else
+        ierr = NF_DEF_VAR (nid, "TS"//str2, NF_FLOAT, 1, idim2,nvarid)
+#endif
+        ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 28,
+     .                        "Temperature de surface No."//str2)
+        ierr = NF_ENDDEF(nid)
+        ELSE
+        PRINT*, "Trop de sous-mailles"
+        CALL abort
+        ENDIF
+#ifdef NC_DOUBLE
+        ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tsol(1,nsrf))
+#else
+        ierr = NF_PUT_VAR_REAL (nid,nvarid,tsol(1,nsrf))
+#endif
+      ENDDO
+c
+      DO nsrf = 1, nbsrf
+      DO isoil=1, nsoilmx
+        IF (isoil.LE.99 .AND. nsrf.LE.99) THEN
+        WRITE(str7,'(i2.2,"srf",i2.2)') isoil,nsrf
+        ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+        ierr = NF_DEF_VAR (nid, "Tsoil"//str7,NF_DOUBLE,1,idim2,nvarid)
+#else
+        ierr = NF_DEF_VAR (nid, "Tsoil"//str7,NF_FLOAT,1,idim2,nvarid)
+#endif
+        ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 29,
+     .                        "Temperature du sol No."//str7)
+        ierr = NF_ENDDEF(nid)
+        ELSE
+        PRINT*, "Trop de couches"
+        CALL abort
+        ENDIF
+#ifdef NC_DOUBLE
+        ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tsoil(1,isoil,nsrf))
+#else
+        ierr = NF_PUT_VAR_REAL (nid,nvarid,tsoil(1,isoil,nsrf))
+#endif
+      ENDDO
+      ENDDO
+c
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "DELTAT", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "DELTAT", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 33,
+     .                        "Ecart de la SST (pour slab-ocean)")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,deltat)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,deltat)
+#endif
+c
+      DO nsrf = 1, nbsrf
+        IF (nsrf.LE.99) THEN
+        WRITE(str2,'(i2.2)') nsrf
+        ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+        ierr = NF_DEF_VAR (nid,"QS"//str2,NF_DOUBLE,1,idim2,nvarid)
+#else
+        ierr = NF_DEF_VAR (nid,"QS"//str2,NF_FLOAT,1,idim2,nvarid)
+#endif
+        ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 25,
+     .                        "Humidite de surface No."//str2)
+        ierr = NF_ENDDEF(nid)
+        ELSE
+        PRINT*, "Trop de sous-mailles"
+        CALL abort
+        ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,qsol(1,nsrf))
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,qsol(1,nsrf))
+#endif
+      ENDDO
+c
+      DO nsrf = 1, nbsrf
+        IF (nsrf.LE.99) THEN
+        WRITE(str2,'(i2.2)') nsrf
+        ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+        ierr = NF_DEF_VAR (nid,"SNOW"//str2,NF_DOUBLE,1,idim2,nvarid)
+#else
+        ierr = NF_DEF_VAR (nid,"SNOW"//str2,NF_FLOAT,1,idim2,nvarid)
+#endif
+        ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 22,
+     .                        "Neige de surface No."//str2)
+        ierr = NF_ENDDEF(nid)
+        ELSE
+        PRINT*, "Trop de sous-mailles"
+        CALL abort
+        ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,snow(1,nsrf))
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,snow(1,nsrf))
+#endif
+      ENDDO
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "RADS", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "RADS", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 28,
+     .                        "Rayonnement net a la surface")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,radsol)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,radsol)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "RUGMER", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "RUGMER", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 28,
+     .                        "Longueur de rugosite sur mer")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rugmer)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,rugmer)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "AGESNO", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "AGESNO", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 15,
+     .                        "Age de la neige")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,agesno)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,agesno)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZMEA", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZMEA", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zmea)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zmea)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZSTD", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZSTD", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zstd)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zstd)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZSIG", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZSIG", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zsig)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zsig)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZGAM", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZGAM", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zgam)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zgam)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZTHE", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZTHE", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zthe)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zthe)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZPIC", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZPIC", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zpic)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zpic)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZVAL", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZVAL", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zval)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,zval)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "RUGSREL", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "RUGSREL", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rugsrel)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,rugsrel)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "TANCIEN", NF_DOUBLE, 1, idim3,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "TANCIEN", NF_FLOAT, 1, idim3,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,t_ancien)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,t_ancien)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "QANCIEN", NF_DOUBLE, 1, idim3,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "QANCIEN", NF_FLOAT, 1, idim3,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,q_ancien)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,q_ancien)
+#endif
+c
+      ierr = NF_CLOSE(nid)
+c
+      RETURN
+      END
+      subroutine physdem(lonfi, latfi,phystep,radpas,co2_ppm,
+     .                   solaire, ts, ws, 
+     .                   sn, radsol, deltat, rugmer,
+     .                   agesno, zmea, zstd, zsig,
+     .                   zgam, zthe, zpic, zval,
+     .                   rugsrel)
+
+      IMPLICIT none
+c-------------------------------------------------------------
+C Author : L. Fairhead
+C Date   : 01/10/1999
+C Objet  : Ecriture des etats initiaux physiques
+c-------------------------------------------------------------
+c
+c
+c
+      INTEGER ivap
+      PARAMETER (ivap=1)
+c
+      REAL qsolmax
+      PARAMETER ( qsolmax = 150.0 )
+c
+#include "dimensions.h"
+#include "paramet.h"
+#include "dimphy.h"
+#include "control.h"
+#include "netcdf.inc"
+c
+      INTEGER nid
+
+c Ajout de quelques parametres orographiques (F. LOTT janvier 1995)
+
+      REAL zmea(iip1,jjp1),zstd(iip1,jjp1)
+      REAL zsig(iip1,jjp1),zgam(iip1,jjp1),zthe(iip1,jjp1)
+      REAL zpic(iip1,jjp1),zval(iip1,jjp1)
+      REAL rugsrel(iip1,jjp1)
+      INTEGER idayref,anneeref
+
+
+      integer ierr, idim1, idim2, nvarid
+
+c
+      REAL phystep
+      INTEGER radpas
+      REAL co2_ppm
+      REAL solaire
+      REAL latfi(klon), lonfi(klon)
+      REAL champhys(klon)
+      REAL ts(klon)
+      REAL deltat(klon)
+      REAL ws(klon)
+      REAL sn(klon)
+      REAL radsol(klon)
+      REAL rugmer(klon)
+      REAL agesno(klon)
+      INTEGER length
+      PARAMETER (length=100)
+      REAL tab_cntrl(length)
+      real pi
+
+c
+
+#include "serre.h"
+#include "clesphys.h"
+#include "fxyprim.h"
+c-----------------------------------------------------------------------
+c
+c  stockage sur le fichier Physique:
+c
+      pi=2.*asin(1.)
+      ierr = NF_CREATE("startphy.nc", NF_CLOBBER, nid)
+      IF (ierr.NE.NF_NOERR) THEN
+        WRITE(6,*)' Pb d''ouverture du fichier startphy.nc'
+        WRITE(6,*)' ierr = ', ierr
+        CALL ABORT
+      ENDIF
+c
+      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 28,
+     .                       "Fichier demmarage physique")
+c
+      ierr = NF_DEF_DIM (nid, "index", length, idim1)
+      ierr = NF_DEF_DIM (nid, "points_physiques", klon, idim2)
+c
+      ierr = NF_ENDDEF(nid)
+c
+      DO ierr = 1, length
+         tab_cntrl(ierr) = 0.0
+      ENDDO
+      tab_cntrl(1)  = phystep
+      tab_cntrl(2)  = radpas
+      tab_cntrl(3)  = co2_ppm
+      tab_cntrl(4)  = solaire
+      tab_cntrl(5)  = iflag_con
+      tab_cntrl(6)  = nbapp_rad
+c
+cc     Modif ( P. Le Van )
+c
+       tab_cntrl( 7 ) = 0. 
+       tab_cntrl( 8 ) = 0. 
+       tab_cntrl( 9 ) = 0. 
+       tab_cntrl(10 ) = 0. 
+       tab_cntrl(11 ) = 0. 
+       tab_cntrl(12 ) = 0. 
+
+      IF(  cycle_diurne )  tab_cntrl( 7 ) = 1. 
+      IF(   soil_model  )  tab_cntrl( 8 ) = 1. 
+      IF(    new_oliq   )  tab_cntrl( 9 ) = 1. 
+      IF(    ok_orodr   )  tab_cntrl(10 ) = 1. 
+      IF(    ok_orolf   )  tab_cntrl(11 ) = 1. 
+      IF(  ok_limitvrai )  tab_cntrl(12 ) = 1. 
+
+      tab_cntrl(13)  = dayref
+      tab_cntrl(14)  = anneeref
+
+
+cc   ***    new_oliq   (  commentaires de L. LI dans routine physique ) 
+cc   ***  ok_orodr  et ok_orolf   si on appelle l'orographie      ****
+
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "controle", NF_DOUBLE, 1, idim1,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "controle", NF_FLOAT, 1, idim1,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 22,
+     .                        "Parametres de controle")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "longitude", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "longitude", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 32,
+     .                        "Longitudes de la grille physique")
+      ierr = NF_ENDDEF(nid)
+
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,lonfi)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,lonfi)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "latitude", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "latitude", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 31,
+     .                        "Latitudes de la grille physique")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,latfi)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,latfi)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "TS", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "TS", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 25,
+     .                        "Temperature de la surface")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,ts)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,ts)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "QS", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "QS", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 15,
+     .                        "Humidite du sol")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,ws)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,ws)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "SNOW", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "SNOW", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 5,
+     .                        "Neige")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,sn)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,sn)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "RADS", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "RADS", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 28,
+     .                        "Rayonnement net a la surface")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,radsol)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,radsol)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "DELTAT", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "DELTAT", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 33,
+     .                        "Ecart de la SST (pour slab-ocean)")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,deltat)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,deltat)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "RUGMER", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "RUGMER", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 28,
+     .                        "Longueur de rugosite sur mer")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rugmer)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,rugmer)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "AGESNO", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "AGESNO", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 15,
+     .                        "Age de la neige")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,agesno)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,agesno)
+#endif
+c
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zmea, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZMEA", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZMEA", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+c
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zstd, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZSTD", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZSTD", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zsig, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZSIG", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZSIG", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zgam, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZGAM", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZGAM", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zthe, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZTHE", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZTHE", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zpic, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZPIC", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZPIC", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, zval, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "ZVAL", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "ZVAL", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+
+      CALL gr_dyn_fi(1, iip1, jjp1, klon, rugsrel, champhys)
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "RUGSREL", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "RUGSREL", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,champhys)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,champhys)
+#endif
+c
+      ierr = NF_CLOSE(nid)
+
+      RETURN
+
+      END
+*CMZ :          28/02/95  17.58.56  by  Unknown
+*-- Author :
+      CHARACTER*(*) FUNCTION SPACES(STR,NSPACE)
+C
+C CERN PROGLIB# M433    SPACES          .VERSION KERNFOR  4.14  860211
+C ORIG.  6/05/86 M.GOOSSENS/DD
+C
+C-    The function value SPACES returns the character string STR with
+C-    leading blanks removed and each occurence of one or more blanks
+C-    replaced by NSPACE blanks inside the string STR
+C
+      CHARACTER*(*) STR
+C
+      LENSPA = LEN(SPACES)
+      SPACES = ' '
+      IF (NSPACE.LT.0) NSPACE = 0
+      IBLANK = 1
+      ISPACE = 1
+  100 INONBL = INDEXC(STR(IBLANK:),' ')
+      IF (INONBL.EQ.0) THEN
+          SPACES(ISPACE:) = STR(IBLANK:)
+                                                    GO TO 999
+      ENDIF
+      INONBL = INONBL + IBLANK - 1
+      IBLANK = INDEX(STR(INONBL:),' ')
+      IF (IBLANK.EQ.0) THEN
+          SPACES(ISPACE:) = STR(INONBL:)
+                                                    GO TO 999
+      ENDIF
+      IBLANK = IBLANK + INONBL - 1
+      SPACES(ISPACE:) = STR(INONBL:IBLANK-1)
+      ISPACE = ISPACE + IBLANK - INONBL + NSPACE
+      IF (ISPACE.LE.LENSPA)                         GO TO 100
+  999 END
+      FUNCTION INDEXC(STR,SSTR)
+C
+C CERN PROGLIB# M433    INDEXC          .VERSION KERNFOR  4.14  860211
+C ORIG. 26/03/86 M.GOOSSENS/DD
+C
+C-    Find the leftmost position where substring SSTR does not match
+C-    string STR scanning forward
+C
+      CHARACTER*(*) STR,SSTR
+C
+      LENS   = LEN(STR)
+      LENSS  = LEN(SSTR)
+C
+      DO 10 I=1,LENS-LENSS+1
+          IF (STR(I:I+LENSS-1).NE.SSTR) THEN
+              INDEXC = I
+                                         GO TO 999
+          ENDIF
+   10 CONTINUE
+      INDEXC = 0
+C
+  999 END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/FCTTRE.inc
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/FCTTRE.inc	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/FCTTRE.inc	(revision 253)
@@ -0,0 +1,36 @@
+!      ------------------------------------------------------------------
+!      This COMDECK includes the Thermodynamical functions for the cy39
+!       ECMWF Physics package.
+!       Consistent with YOMCST Basic physics constants, assuming the
+!       partial pressure of water vapour is given by a first order
+!       Taylor expansion of Qs(T) w.r.t. to Temperature, using constants
+!       in YOETHF
+!     ------------------------------------------------------------------
+      REAL PTARG, PDELARG, P5ARG, PQSARG, PCOARG
+      REAL FOEEW, FOEDE, qsats, qsatl, dqsats, dqsatl
+      LOGICAL thermcep
+      PARAMETER (thermcep=.TRUE.)
+!
+      FOEEW ( PTARG,PDELARG ) = EXP ( &
+     &          (R3LES*(1.-PDELARG)+R3IES*PDELARG) * (PTARG-RTT) &
+     & / (PTARG-(R4LES*(1.-PDELARG)+R4IES*PDELARG)) )
+!
+      FOEDE ( PTARG,PDELARG,P5ARG,PQSARG,PCOARG ) = PQSARG*PCOARG*P5ARG &
+     & / (PTARG-(R4LES*(1.-PDELARG)+R4IES*PDELARG))**2
+!
+      qsats(ptarg) = 100.0 * 0.622 * 10.0 &
+     &           ** (2.07023 - 0.00320991 * ptarg &
+     &           - 2484.896 / ptarg + 3.56654 * LOG10(ptarg))
+      qsatl(ptarg) = 100.0 * 0.622 * 10.0 &
+     &           ** (23.8319 - 2948.964 / ptarg &
+     &           - 5.028 * LOG10(ptarg) &
+     &           - 29810.16 * EXP( - 0.0699382 * ptarg) &
+     &           + 25.21935 * EXP( - 2999.924 / ptarg))
+!
+      dqsats(ptarg,pqsarg) = RLVTT/RCPD*pqsarg * (3.56654/ptarg &
+     &                     +2484.896*LOG(10.)/ptarg**2 &
+     &                     -0.00320991*LOG(10.))
+      dqsatl(ptarg,pqsarg) = RLVTT/RCPD*pqsarg*LOG(10.)* &
+     &                (2948.964/ptarg**2-5.028/LOG(10.)/ptarg &
+     &                +25.21935*2999.924/ptarg**2*EXP(-2999.924/ptarg) &
+     &                +29810.16*0.0699382*EXP(-0.0699382*ptarg))
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/YOETHF.inc
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/YOETHF.inc	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/YOETHF.inc	(revision 253)
@@ -0,0 +1,12 @@
+!*    COMMON *YOETHF* DERIVED CONSTANTS SPECIFIC TO ECMWF THERMODYNAMICS
+!
+!     *R__ES*   *CONSTANTS USED FOR COMPUTATION OF SATURATION
+!                MIXING RATIO OVER LIQUID WATER(*R_LES*) OR
+!                ICE(*R_IES*).
+!     *RVTMP2*  *RVTMP2=RCPV/RCPD-1.
+!     *RHOH2O*  *DENSITY OF LIQUID WATER.   (RATM/100.)
+!
+      REAL R2ES, R3LES, R3IES, R4LES, R4IES, R5LES, R5IES
+      REAL RVTMP2, RHOH2O
+      COMMON /YOETHF/R2ES, R3LES, R3IES, R4LES, R4IES, R5LES, R5IES, &
+     &               RVTMP2, RHOH2O
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/YOMCST.inc
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/YOMCST.inc	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/YOMCST.inc	(revision 253)
@@ -0,0 +1,26 @@
+! A1.0 Fundamental constants
+      REAL :: RPI,RCLUM,RHPLA,RKBOL,RNAVO
+! A1.1 Astronomical constants
+      REAL :: RDAY,REA,REPSM,RSIYEA,RSIDAY,ROMEGA
+! A1.1.bis Constantes concernant l'orbite de la Terre:
+      REAL :: R_ecc, R_peri, R_incl
+! A1.2 Geoide
+      REAL :: RA,RG,R1SA
+! A1.3 Radiation
+      REAL :: RSIGMA,RI0
+! A1.4 Thermodynamic gas phase
+      REAL :: R,RMD,RMV,RD,RV,RCPD,RCPV,RCVD,RCVV
+      REAL :: RKAPPA,RETV
+! A1.5,6 Thermodynamic liquid,solid phases
+      REAL :: RCW,RCS
+! A1.7 Thermodynamic transition of phase
+      REAL :: RLVTT,RLSTT,RLMLT,RTT,RATM
+! A1.8 Curve of saturation
+      REAL :: RESTT,RALPW,RBETW,RGAMW,RALPS,RBETS,RGAMS
+      REAL :: RALPD,RBETD,RGAMD
+!
+      COMMON/YOMCST/RPI ,RCLUM, RHPLA, RKBOL, RNAVO ,RDAY  ,REA &
+     & ,REPSM ,RSIYEA,RSIDAY,ROMEGA ,R_ecc, R_peri, R_incl, RA    ,RG &
+     & ,R1SA ,RSIGMA,RI0,R ,RMD   ,RMV   ,RD    ,RV    ,RCPD ,RCPV,RCVD &
+     & ,RCVV  ,RKAPPA,RETV ,RCW   ,RCS ,RLVTT ,RLSTT ,RLMLT ,RTT ,RATM &
+     & ,RESTT ,RALPW ,RBETW ,RGAMW ,RALPS ,RBETS ,RGAMS ,RALPD ,RBETD ,RGAMD
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/ajsec.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/ajsec.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/ajsec.F	(revision 253)
@@ -1,3 +1,3 @@
-      SUBROUTINE ajsec(paprs, pplay, t,q, d_t,d_q, itr, tr, d_tr)
+      SUBROUTINE ajsec(paprs, pplay, t,q, d_t,d_q)
       IMPLICIT none
 c======================================================================
@@ -16,8 +16,4 @@
       REAL t(klon,klev), q(klon,klev)
       REAL d_t(klon,klev), d_q(klon,klev)
-c
-      INTEGER it, itr
-      REAL tr(klon,klev,nbtr), d_tr(klon,klev,nbtr)
-      REAL ztr(klon,klev,nbtr), trm(nbtr)
 c
       INTEGER limbas, limhau ! les couches a ajuster
@@ -45,13 +41,4 @@
       ENDDO
       ENDDO
-      IF (itr.GE.1) THEN
-      DO it = 1, itr
-      DO k = 1, klev
-      DO i = 1, klon
-         d_tr(i,k,it) = 0.0
-      ENDDO
-      ENDDO
-      ENDDO
-      ENDIF
 c------------------------------------- detection des profils a modifier
       DO k = limbas, limhau
@@ -62,14 +49,4 @@
       ENDDO
       ENDDO
-c
-      IF (itr.GE.1) THEN
-      DO it = 1, itr
-      DO k = limbas, limhau
-      DO i = 1, klon
-         ztr(i,k,it) = tr(i,k,it)
-      ENDDO
-      ENDDO
-      ENDDO
-      ENDIF
 c
       DO k = limbas, limhau
@@ -102,19 +79,8 @@
               hm = zh(i,k2)
               qm = zq(i,k2)
-              IF (itr.GE.1) THEN
-              DO it = 1, itr
-                trm(it) = ztr(i,k2,it)
-              ENDDO
-              ENDIF
  8020         CONTINUE
                 sm = sm +zpkdp(i,k)
                 hm = hm +zpkdp(i,k) * (zh(i,k)-hm) / sm
                 qm = qm +zpkdp(i,k) * (zq(i,k)-qm) / sm
-                IF (itr.GE.1) THEN
-                DO it = 1, itr
-                trm(it) = trm(it) +
-     .                    zpkdp(i,k) * (ztr(i,k,it)-trm(it)) / sm
-                ENDDO
-                ENDIF
                 down = .FALSE.
                 IF (k1 .ne. limbas) THEN
@@ -137,11 +103,4 @@
                 zq(i,k) = qm
               ENDDO
-              IF (itr.GE.1) THEN
-              DO it = 1, itr
-              DO k = k1, k2
-                ztr(i,k,it) = trm(it)
-              ENDDO
-              ENDDO
-              ENDIF
               k2 = k2 + 1
             ENDIF
@@ -173,32 +132,4 @@
          d_q(i,k) = 0.0
       ENDDO
-      ENDDO
-      ENDIF
-c
-      IF (itr.GE.1) THEN
-      DO it = 1, itr
-c
-      DO k = limbas, limhau
-      DO i = 1, klon
-         d_tr(i,k,it) = ztr(i,k,it) - tr(i,k,it)
-      ENDDO
-      ENDDO
-c
-      IF (limbas.GT.1) THEN
-      DO k = 1, limbas-1
-      DO i = 1, klon
-         d_tr(i,k,it) = 0.0
-      ENDDO
-      ENDDO
-      ENDIF
-c
-      IF (limhau.LT.klev) THEN
-      DO k = limhau+1, klev
-      DO i = 1, klon
-         d_tr(i,k,it) = 0.0
-      ENDDO
-      ENDDO
-      ENDIF
-c
       ENDDO
       ENDIF
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/albedo.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/albedo.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/albedo.F	(revision 253)
@@ -17,5 +17,6 @@
 c
       REAL fmagic ! un facteur magique pour regler l'albedo
-      PARAMETER (fmagic=0.7)
+ccc      PARAMETER (fmagic=0.7)
+      PARAMETER (fmagic=1.1)
       INTEGER npts ! il controle la precision de l'integration
       PARAMETER (npts=120) ! 120 correspond a l'interval 6 minutes
@@ -83,4 +84,8 @@
       REAL rmu0(klon), albedo(klon)
 c
+      REAL fmagic ! un facteur magique pour regler l'albedo
+ccc      PARAMETER (fmagic=0.7)
+      PARAMETER (fmagic=1.1)
+c
       REAL fauxo
       INTEGER i
@@ -88,5 +93,5 @@
       DO i = 1, klon
          fauxo = ( 1.47 - ACOS( rmu0(i) ) )/0.15
-         albedo(i) = 1.1*( .03 + .630/( 1. + fauxo*fauxo))
+         albedo(i) = fmagic*( .03 + .630/( 1. + fauxo*fauxo))
          albedo(i) = MAX(MIN(albedo(i),0.60),0.04)
       ENDDO
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/atm2geo.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/atm2geo.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/atm2geo.F	(revision 253)
@@ -0,0 +1,44 @@
+C
+      SUBROUTINE atm2geo ( im, jm, pte, ptn, plon, plat, pxx, pyy, pzz )
+cc
+cc Change wind local atmospheric coordinates to
+cc geocentric
+cc
+c$$$      INCLUDE 'param.h'
+c
+      INTEGER, INTENT (in)              :: im, jm
+      REAL, DIMENSION (im,jm), INTENT (in) :: pte, ptn
+      REAL, DIMENSION (im,jm), INTENT (in) :: plon, plat
+      REAL, DIMENSION (im,jm), INTENT(out) :: pxx, pyy, pzz
+c
+      REAL, PARAMETER :: rpi = 3.141592653E0
+      REAL, PARAMETER :: rad = rpi / 180.0E0
+c
+      REAL, DIMENSION (im,jm) :: zsinlon, zcoslon
+      REAL, DIMENSION (im,jm) :: zsinlat, zcoslat
+c
+      LOGICAL, SAVE :: linit = .FALSE.
+c
+c$$$      IF ( .NOT. linit ) THEN 
+          zsinlon = SIN (rad * plon)
+          zcoslon = COS (rad * plon)
+          zsinlat = SIN (rad * plat)
+          zcoslat = COS (rad * plat)
+          linit = .TRUE.
+c$$$      ENDIF 
+c
+      pxx = - zsinlon * pte - zsinlat * zcoslon * ptn
+      pyy =   zcoslon * pte - zsinlat * zsinlon * ptn
+      pzz =   zcoslat * ptn
+c
+c Value at North Pole
+      pxx ( :,  1) = - ptn ( 1, 1)
+      pyy ( :,  1) = - pte ( 1, 1)
+      pzz ( :,  1) = 0.0
+c Value at South Pole
+      pxx ( :, jm) = + ptn ( 1, jm)
+      pyy ( :, jm) = + pte ( 1, jm)
+      pzz ( :, jm) = 0.0
+c
+      RETURN 
+      END SUBROUTINE atm2geo
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/calcratqs.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/calcratqs.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/calcratqs.F	(revision 253)
@@ -0,0 +1,161 @@
+c $Header$
+      SUBROUTINE calcratqs (
+     I            paprs,pplay,q_seri,d_t_con,d_t_ajs
+     O           ,ratqs,zpt_conv)
+      IMPLICIT none
+c======================================================================
+c
+c Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
+c
+c Objet: Moniteur general de la physique du modele
+cAA      Modifications quant aux traceurs :
+cAA                  -  uniformisation des parametrisations ds phytrac
+cAA                  -  stockage des moyennes des champs necessaires
+cAA                     en mode traceur off-line 
+c======================================================================
+c    modif   ( P. Le Van ,  12/10/98 )
+c
+c  Arguments:
+c
+c paprs---input-R-pression pour chaque inter-couche (en Pa)
+c pplay---input-R-pression pour le mileu de chaque couche (en Pa)
+c presnivs-input_R_pressions approximat. des milieux couches ( en PA)
+#include "dimensions.h"
+#include "dimphy.h"
+      REAL paprs(klon,klev+1)
+      REAL pplay(klon,klev)
+      REAL d_t_con(klon,klev)
+      REAL d_t_ajs(klon,klev)
+      REAL ratqs(klon,klev)
+      LOGICAL pt_conv(klon,klev)
+      REAL q_seri(klon,klev)
+
+      logical firstcall
+      save firstcall
+      data firstcall/.true./
+
+
+      REAL ratqsmin,ratqsmax,zx,epmax
+      REAL ratqs1,ratqs2,ratqs3,ratqs4
+      REAL ratqsc1,ratqsc2,ratqsc3,ratqsc4
+      INTEGER i,k
+      INTEGER flag_ratqs
+      save ratqsmin,ratqsmax,flag_ratqs,epmax
+      save ratqs1,ratqs2,ratqs3,ratqs4
+      save ratqsc1,ratqsc2,ratqsc3,ratqsc4
+      real zpt_conv(klon,klev)
+
+      REAL zx_min
+      PARAMETER (zx_min=1.0)
+      REAL zx_max
+      PARAMETER (zx_max=0.1)
+
+      flag_ratqs=1
+      flag_ratqs=0
+c
+c Appeler le processus de condensation a grande echelle
+c et le processus de precipitation
+c
+      if (flag_ratqs.eq.0) then
+
+         ratqsmax=0.01
+         ratqsmin=0.3
+
+         if (firstcall) print*,'RATQS ANCIEN '
+         do k=1,klev
+         do i=1,klon
+            zx = pplay(i,k)/paprs(i,1)
+            zx = (zx_max-zx)/(zx_max-zx_min)
+            zx = MIN(MAX(zx,0.0),1.0)
+            zx = zx * zx * zx
+            ratqs(i,k)= zx * (ratqsmax-ratqsmin) + ratqsmin
+         enddo
+         enddo
+
+      else
+
+c  On aplique un ratqs "interactif" a toutes les mailles affectees
+c  par la convection ou se trouvant "sous" une maille affectee.
+         do i=1,klon
+            pt_conv(i,klev)=.false.
+         enddo
+         do k=klev-1,1,-1
+            do i=1,klon
+               pt_conv(i,k)=pt_conv(i,k+1).or.
+     s               (abs(d_t_con(i,k))+abs(d_t_ajs(i,k))).gt.1.e-8
+               if(pt_conv(i,k)) then
+                  zpt_conv(i,k)=1.
+               else
+                  zpt_conv(i,k)=0.
+               endif
+            enddo
+         enddo
+
+         if (flag_ratqs.eq.1) then
+
+            ratqsmin=0.4
+            ratqsmax=0.99
+            if (firstcall) print*,'RATQS INTERACTIF '
+            do k=1,klev
+                do i=1,klon
+                   if (pt_conv(i,k)) then
+                      ratqs(i,k)=0.01
+     s                +0.25*(q_seri(i,1)-q_seri(i,k))/q_seri(i,k)
+                      ratqs(i,k)=min(ratqs(i,k),ratqsmax)
+                      ratqs(i,k)=max(ratqs(i,k),0.1)
+                   else
+                      ratqs(i,k)=0.01+(ratqsmin-0.01)*
+     s             min((paprs(i,1)-pplay(i,k))/(paprs(i,1)-30000.),1.)
+                   endif
+                enddo
+            enddo
+         else if (flag_ratqs.eq.2) then
+            do k=1,klev
+                do i=1,klon
+                   ratqs(i,k)=0.001+
+     s             (q_seri(i,1)-q_seri(i,k))/q_seri(i,k)
+                   if (pt_conv(i,k)) then
+                      ratqs(i,k)=min(ratqs(i,k),ratqsmax)
+                   else
+                      ratqs(i,k)=min(ratqs(i,k),ratqsmin)
+                   endif
+                enddo
+            enddo
+         else
+            do k=1,klev
+               do i=1,klon
+                  if (pplay(i,k).ge.95000.) then
+                     if (pt_conv(i,k)) then
+                        ratqs(i,k)=ratqsc1
+                     else
+                        ratqs(i,k)=ratqs1
+                     endif
+                  else if (pplay(i,k).ge.75000.) then
+                     if (pt_conv(i,k)) then
+                        ratqs(i,k)=ratqsc2
+                     else
+                        ratqs(i,k)=ratqs2
+                     endif
+                  else if (pplay(i,k).ge.50000.) then
+                     if (pt_conv(i,k)) then
+                        ratqs(i,k)=ratqsc3
+                     else
+                        ratqs(i,k)=ratqs3
+                     endif
+                  else
+                     if (pt_conv(i,k)) then
+                        ratqs(i,k)=ratqsc4
+                     else
+                        ratqs(i,k)=ratqs4
+                     endif
+                  endif
+               enddo
+            enddo
+         endif
+
+      endif
+
+      firstcall=.false.
+
+      return
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/clift.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/clift.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/clift.F	(revision 253)
@@ -0,0 +1,70 @@
+c $Header$
+        SUBROUTINE CLIFT (P,T,RR,RS,PLCL,DPLCLDT,DPLCLDQ)
+C***************************************************************
+C*                                                             *
+C* CLIFT : COMPUTE LIFTING CONDENSATION LEVEL AND ITS          *
+C*         DERIVATIVES RELATIVE TO T AND R                     *
+C*   (WITHIN 0.2% OF FORMULA OF BOLTON, MON. WEA. REV.,1980)   *
+C*                                                             *
+C* written by   : GRANDPEIX Jean-Yves, 17/11/98, 12.39.01      *
+C* modified by :                                               *
+C***************************************************************
+C*
+C*Arguments :
+C*
+C* Input :  P = pressure of level from wich lifting is performed
+C*          T = temperature of level P
+C*          RR = vapour mixing ratio at level P
+C*          RS = vapour saturation mixing ratio at level P
+C*
+C* Output : PLCL = lifting condensation level
+C*          DPLCLDT = derivative of PLCL relative to T
+C*          DPLCLDQ = derivative of PLCL relative to R
+C*
+ccccccccccccccccccccccc
+c constantes coherentes avec le modele du Centre Europeen
+c      RD = 1000.0 * 1.380658E-23 * 6.0221367E+23 / 28.9644
+c      RV = 1000.0 * 1.380658E-23 * 6.0221367E+23 / 18.0153
+c      CPD = 3.5 * RD
+c      CPV = 4.0 * RV
+c      CL = 4218.0
+c      CI=2090.0
+c      CPVMCL=CL-CPV
+c      CLMCI=CL-CI
+c      EPS=RD/RV
+c      ALV0=2.5008E+06
+c      ALF0=3.34E+05
+c
+c on utilise les constantes thermo du Centre Europeen: (sb)
+c
+#include "YOMCST.h"
+c
+       CPD = RCPD
+       CPV = RCPV
+       CL = RCW
+       CPVMCL = CL-CPV
+       EPS = RD/RV
+       ALV0 = RLVTT
+c
+c
+c      Bolton formula coefficients :
+      A = 1669.0
+      B = 122.0
+c
+      RH=RR/RS
+      CHI=T/(A-B*RH-T)
+      PLCL=P*(RH**CHI)
+c
+      ALV = ALV0 - CPVMCL*(T-273.15)
+c
+c -- sb: correction:
+c       DPLCLDQ = PLCL*CHI*( 1./RR - B*CHI/T/RS*ALOG(RH) )
+      DPLCLDQ = PLCL*CHI*( 1./RR + B*CHI/T/RS*ALOG(RH) )
+c sb --
+c
+      DPLCLDT = PLCL*CHI*((A-B*RH*(1.+ALV/RV/T))/T**2*CHI*ALOG(RH)
+     $                    - ALV/RV/T**2 )
+c
+c
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/clmain.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/clmain.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/clmain.F	(revision 253)
@@ -122,4 +122,7 @@
 cAA      REAL yflxsrf(klon,nbtr)
 c
+      LOGICAL contreg
+      PARAMETER (contreg=.TRUE.)
+c
       LOGICAL ok_nonloc
       PARAMETER (ok_nonloc=.FALSE.)
@@ -272,4 +275,12 @@
      .            yts, yrugos, yu, yv, yt, yq,
      .            ycoefm, ycoefh)
+      CALL coefkz2(nsrf, knon, ypaprs, ypplay,yt,
+     .                  ycoefm0, ycoefh0)
+      DO k = 1, klev
+      DO i = 1, knon
+         ycoefm(i,k) = MAX(ycoefm(i,k),ycoefm0(i,k))
+         ycoefh(i,k) = MAX(ycoefh(i,k),ycoefh0(i,k))
+      ENDDO
+      ENDDO
 c
 c parametrisation non-locale:
@@ -289,4 +300,12 @@
          ENDDO
       ELSE
+         IF (.NOT.contreg) THEN
+            DO k = 2, klev
+            DO i = 1, knon
+               ygamq(i,k) = 0.0
+               ygamt(i,k) = 0.0
+            ENDDO
+            ENDDO
+         ELSE
          DO k = 3, klev
          DO i = 1, knon
@@ -299,4 +318,5 @@
             ygamt(i,2) = -2.5E-03
          ENDDO
+         ENDIF
       ENDIF
 c
@@ -477,5 +497,4 @@
       REAL local_q(klon,klev)
       REAL local_ts(klon)
-      REAL zx_alf1(klon), zx_alf2(klon) !valeur ambiante par extrapola.
       REAL psref(klon) ! pression de reference pour temperature potent.
       REAL zx_pkh(klon,klev), zx_pkf(klon,klev)
@@ -488,4 +507,10 @@
       REAL zdelz
 c======================================================================
+C Variables intermediaires pour le calcul des fluxs a la surface
+      real zx_mh(klon), zx_nh(klon), zx_oh(klon)
+      real zx_mq(klon), zx_nq(klon), zx_oq(klon)
+      real zx_k1(klon), zx_dq_s_dt(klon)
+      real zx_qsat(klon)
+c======================================================================
       REAL zcor, zdelta, zcvm5
 #include "YOMCST.h"
@@ -496,7 +521,4 @@
          psref(i) = paprs(i,1) !pression de reference est celle au sol
          local_ts(i) = ts(i)
-ccc         zx_alf1(i) = (paprs(i,1)-pplay(i,2))/(pplay(i,1)-pplay(i,2))
-         zx_alf1(i) = 1.0
-         zx_alf2(i) = 1.0 - zx_alf1(i)
       ENDDO
       DO k = 1, klev
@@ -515,5 +537,4 @@
      .                 * (1.0+SQRT(u1lay(i)**2+v1lay(i)**2))
      .                 * pplay(i,1)/(RD*t(i,1))
-         zx_coef(i,1) = zx_coef(i,1) * dtime*RG
       ENDDO
 c
@@ -537,4 +558,7 @@
       ENDDO
 c======================================================================
+c
+c zx_qs = qsat en kg/kg
+c
       DO i = 1, knon
          IF (thermcep) THEN
@@ -559,7 +583,9 @@
            ENDIF
          ENDIF
-c
-         zx_dq0(i) = zx_dq_s_dh
-         zx_cq0(i) = zx_qs -zx_dq_s_dh *local_ts(i)*RCPD*zx_pkh(i,1)
+
+c        zx_dq_s_dh = 0.
+         zx_dq_s_dt(i) = RCPD * zx_pkh(i,1) * zx_dq_s_dh
+         zx_qsat(i) = zx_qs
+c
       ENDDO
       DO i = 1, knon
@@ -593,60 +619,70 @@
       ENDDO
       ENDDO
+C
+C nouvelle formulation JL Dufresne
+C
+C q1 = zx_cq(i,1) + zx_dq(i,1) * Flux_Q(i,1) * dt
+C h1 = zx_ch(i,1) + zx_dh(i,1) * Flux_H(i,1) * dt
+C
       DO i = 1, knon
          zx_buf1(i) = delp(i,1) + zx_coef(i,2)*(1.-zx_dq(i,2))
-     .              + zx_coef(i,1)*beta(i)
-     .                *(zx_alf1(i)+zx_alf2(i)*zx_dq(i,2))
          zx_cq(i,1) = (local_q(i,1)*delp(i,1)
-     .                 +zx_coef(i,2)*z_gamaq(i,2)
-     .                 +zx_cq(i,2)*(zx_coef(i,2)
-     .                  -zx_coef(i,1)*zx_alf2(i)*beta(i)) )
+     .                 +zx_coef(i,2)*(z_gamaq(i,2)+zx_cq(i,2)))
      .                /zx_buf1(i)
-         zx_dq(i,1) = beta(i) * zx_coef(i,1) / zx_buf1(i)
+         zx_dq(i,1) = -1. * RG / zx_buf1(i)
 c
          zx_buf2(i) = delp(i,1) + zx_coef(i,2)*(1.-zx_dh(i,2))
-     .               +zx_coef(i,1)
-     .                *(zx_alf1(i)+zx_alf2(i)*zx_dh(i,2))
          zx_ch(i,1) = (local_h(i,1)*delp(i,1)
-     .                 +zx_coef(i,2)*z_gamah(i,2)
-     .                 +zx_ch(i,2)*(zx_coef(i,2)
-     .                  -zx_coef(i,1)*zx_alf2(i)) )
+     .                 +zx_coef(i,2)*(z_gamah(i,2)+zx_ch(i,2)))
      .                /zx_buf2(i)
-         zx_dh(i,1) = zx_coef(i,1) / zx_buf2(i)
-      ENDDO
-c==== calculer d'abord local_h(0) ============================
-      DO i = 1, knon
-         zx_sl(i) = RLVTT
-         if (local_ts(i) .LT. RTT) zx_sl(i) = RLSTT
-      ENDDO
-      DO i = 1, knon
-         zx_h_grnd = t_grnd * zx_pkh(i,1) *RCPD
-         zx_h_ts(i) = local_ts(i) * zx_pkh(i,1) *RCPD
-         zx_a = radsol(i)
-     .        + zx_coef(i,1)/(RG*dtime)*beta(i)*zx_sl(i)
-     .          *(zx_cq(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dq(i,2))
-     .            +zx_alf2(i)*zx_cq(i,2))
-     .        + zx_coef(i,1)/(RG*dtime)*beta(i)*zx_sl(i)
-     .          *((zx_dq(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dq(i,2))
-     .             -1.0)*zx_cq0(i))
-     .        + zx_coef(i,1)/(RG*dtime)/zx_pkh(i,1)
-     .          *(zx_ch(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dh(i,2))
-     .           +zx_alf2(i)*zx_ch(i,2))
-         zx_a = zx_h_ts(i) + dif_grnd(i)*dtime*zx_h_grnd
-     .                     + cal(i)*zx_pkh(i,1)*dtime * zx_a 
-         zx_b = zx_coef(i,1)/(RG*dtime) *beta(i)*zx_sl(i)*zx_dq0(i)
-     .          *(1.0-zx_dq(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dq(i,2)))
-     .        + zx_coef(i,1)/(RG*dtime)/zx_pkh(i,1)
-     .          *(1.0-zx_dh(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dh(i,2)))
-         zx_b = 1.0 + dif_grnd(i)*dtime + cal(i)*zx_pkh(i,1)*dtime*zx_b
-         zx_h_ts(i) = zx_a / zx_b
-         local_ts(i) = zx_h_ts(i) / zx_pkh(i,1)/RCPD
-      ENDDO
+         zx_dh(i,1) = -1. * RG / zx_buf2(i)
+      ENDDO
+
+C === Calcul de la temperature de surface ===
+C 
+C zx_sl = chaleur latente d'evaporation ou de sublimation
+C
+      do i = 1, knon
+        zx_sl(i) = RLVTT
+        if (local_ts(i) .LT. RTT) zx_sl(i) = RLSTT
+        zx_k1(i) = zx_coef(i,1)
+      enddo
+      do i = 1, knon
+C Q
+        zx_oq(i) = 1. - (beta(i) * zx_k1(i) * zx_dq(i,1) * dtime)
+        zx_mq(i) = beta(i) * zx_k1(i) * 
+     .              (zx_cq(i,1) - zx_qsat(i) 
+     .                             + zx_dq_s_dt(i) * local_ts(i))
+     .              / zx_oq(i)
+        zx_nq(i) = beta(i) * zx_k1(i) * (-1. * zx_dq_s_dt(i))
+     .                                                / zx_oq(i)
+c H
+        zx_oh(i) = 1. - (zx_k1(i) * zx_dh(i,1) * dtime)
+        zx_mh(i) = zx_k1(i) * zx_ch(i,1) / zx_oh(i)
+        zx_nh(i) = - (zx_k1(i) * RCPD * zx_pkh(i,1))/ zx_oh(i)
+c Tsurface
+        local_ts(i) = (ts(i) + cal(i)/(RCPD * zx_pkh(i,1)) * dtime *
+     .                   (radsol(i) + zx_mh(i) + zx_sl(i) * zx_mq(i)) 
+     .                       + dif_grnd(i) * t_grnd * dtime)/
+     .                ( 1. - dtime * cal(i)/(RCPD * zx_pkh(i,1)) * (
+     .                       zx_nh(i) + zx_sl(i) * zx_nq(i))  
+     .                     + dtime * dif_grnd(i))
+        zx_h_ts(i) = local_ts(i) * RCPD * zx_pkh(i,1)
+        d_ts(i) = local_ts(i) - ts(i)
+        zx_q_0(i) = zx_qsat(i) + zx_dq_s_dt(i) * d_ts(i)
+c== flux_q est le flux de vapeur d'eau: kg/(m**2 s)  positive vers bas
+c== flux_t est le flux de cpt (energie sensible): j/(m**2 s)
+        flux_q(i,1) = zx_mq(i) + zx_nq(i) * local_ts(i) 
+        flux_t(i,1) = zx_mh(i) + zx_nh(i) * local_ts(i)
+c Derives des flux dF/dTs (W m-2 K-1):
+        dflux_s(i) = zx_nh(i)
+        dflux_l(i) = (zx_sl(i) * zx_nq(i))
+      ENDDO
+
+
 c==== une fois on a zx_h_ts, on peut faire l'iteration ========
       DO i = 1, knon
-         zx_q_0(i) = zx_cq0(i) + zx_dq0(i)*zx_h_ts(i)
-      ENDDO
-      DO i = 1, knon
-         local_h(i,1) = zx_ch(i,1) + zx_dh(i,1)*zx_h_ts(i)
-         local_q(i,1) = zx_cq(i,1) + zx_dq(i,1)*zx_q_0(i)
+         local_h(i,1) = zx_ch(i,1) + zx_dh(i,1)*flux_t(i,1)*dtime
+         local_q(i,1) = zx_cq(i,1) + zx_dq(i,1)*flux_q(i,1)*dtime
       ENDDO
       DO k = 2, klev
@@ -659,13 +695,4 @@
 c== flux_q est le flux de vapeur d'eau: kg/(m**2 s)  positive vers bas
 c== flux_t est le flux de cpt (energie sensible): j/(m**2 s)
-      DO i = 1, knon
-        flux_q(i,1) = (zx_coef(i,1)/dtime/RG) * beta(i)
-     .              * (local_q(i,1)*zx_alf1(i)
-     .                +local_q(i,2)*zx_alf2(i)-zx_q_0(i))
-        flux_t(i,1) = (zx_coef(i,1)/dtime/RG)
-     .              * (local_h(i,1)*zx_alf1(i)
-     .                +local_h(i,2)*zx_alf2(i)-zx_h_ts(i))
-     .              / zx_pkh(i,1)
-      ENDDO
       DO k = 2, klev
       DO i = 1, knon
@@ -678,14 +705,5 @@
       ENDDO
 c======================================================================
-c Derives des flux dF/dTs (W m-2 K-1):
-      DO i = 1, knon
-         dflux_s(i) = (RCPD*zx_coef(i,1))/(RG*dtime)/zx_pkh(i,1)
-     .         *(zx_dh(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dh(i,2))-1.0)
-         dflux_l(i) = (beta(i)*RLVTT*RCPD*zx_coef(i,1))/(RG*dtime)
-     .         *zx_dq0(i)
-     .         *(zx_dq(i,1)*(zx_alf1(i)+zx_alf2(i)*zx_dq(i,2))-1.0)
-         dflux_g(i) = dif_grnd(i) * RCPD
-      ENDDO
-c======================================================================
+C Calcul tendances
       DO k = 1, klev
       DO i = 1, knon
@@ -693,7 +711,4 @@
          d_q(i,k) = local_q(i,k) - q(i,k)
       ENDDO
-      ENDDO
-      DO i = 1, knon
-         d_ts(i) = local_ts(i) - ts(i)
       ENDDO
 c
@@ -873,5 +888,5 @@
       PARAMETER (clam=160.0)
       REAL ratqs ! largeur de distribution de vapeur d'eau
-      PARAMETER (ratqs=0.2)
+      PARAMETER (ratqs=0.05)
       LOGICAL richum ! utilise le nombre de Richardson humide
       PARAMETER (richum=.TRUE.)
@@ -881,5 +896,5 @@
       PARAMETER (prandtl=0.4)
       REAL kstable ! diffusion minimale (situation stable)
-      PARAMETER (kstable=1.0e-06)
+      PARAMETER (kstable=1.0e-10)
       REAL mixlen ! constante controlant longueur de melange
       PARAMETER (mixlen=35.0)
@@ -950,5 +965,5 @@
 c Prescrire la valeur de contre-gradient
 c
-      IF (contreg) THEN
+      IF (.NOT.contreg) THEN
          DO k = 2, klev
             gamt(k) = 0.0
@@ -1131,4 +1146,101 @@
       RETURN
       END
+      SUBROUTINE coefkz2(nsrf, knon, paprs, pplay,t,
+     .                  pcfm, pcfh)
+      IMPLICIT none
+c======================================================================
+c J'introduit un peu de diffusion sauf dans les endroits
+c ou une forte inversion est presente
+c On peut dire qu'il represente la convection peu profonde
+c
+c Arguments:
+c nsrf-----input-I- indicateur de la nature du sol
+c knon-----input-I- nombre de points a traiter
+c paprs----input-R- pression a chaque intercouche (en Pa)
+c pplay----input-R- pression au milieu de chaque couche (en Pa)
+c t--------input-R- temperature (K)
+c
+c pcfm-----output-R- coefficients a calculer (vitesse)
+c pcfh-----output-R- coefficients a calculer (chaleur et humidite)
+c======================================================================
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+#include "indicesol.h"
+c
+c Arguments:
+c
+      INTEGER knon, nsrf
+      REAL paprs(klon,klev+1), pplay(klon,klev)
+      REAL t(klon,klev)
+c
+      REAL pcfm(klon,klev), pcfh(klon,klev)
+c
+c Quelques constantes et options:
+c
+      REAL prandtl
+      PARAMETER (prandtl=0.4)
+      REAL kstable
+      PARAMETER (kstable=0.002)
+ccc      PARAMETER (kstable=0.001)
+      REAL mixlen ! constante controlant longueur de melange
+      PARAMETER (mixlen=35.0)
+      REAL seuil ! au-dela l'inversion est consideree trop faible
+      PARAMETER (seuil=-0.02)
+ccc      PARAMETER (seuil=-0.04)
+ccc      PARAMETER (seuil=-0.06)
+ccc      PARAMETER (seuil=-0.09)
+c
+c Variables locales:
+c
+      INTEGER i, k, invb(knon)
+      REAL zl2(knon)
+      REAL zdthmin(knon), zdthdp
+c
+c Initialiser les sorties
+c
+      DO k = 1, klev
+      DO i = 1, knon
+         pcfm(i,k) = 0.0
+         pcfh(i,k) = 0.0
+      ENDDO
+      ENDDO
+c
+c Chercher la zone d'inversion forte
+c
+      DO i = 1, knon
+         invb(i) = klev
+         zdthmin(i)=0.0
+      ENDDO
+      DO k = 2, klev/2-1
+      DO i = 1, knon
+         zdthdp = (t(i,k)-t(i,k+1))/(pplay(i,k)-pplay(i,k+1))
+     .          - RD * 0.5*(t(i,k)+t(i,k+1))/RCPD/paprs(i,k+1)
+         zdthdp = zdthdp * 100.0
+         IF (pplay(i,k).GT.0.8*paprs(i,1) .AND.
+     .       zdthdp.LT.zdthmin(i) ) THEN
+            zdthmin(i) = zdthdp
+            invb(i) = k
+         ENDIF
+      ENDDO
+      ENDDO
+c
+c Introduire une diffusion:
+c
+      DO k = 2, klev
+      DO i = 1, knon
+      IF ( (nsrf.NE.is_oce) .OR.  ! si ce n'est pas sur l'ocean
+     .     (invb(i).EQ.klev) .OR. ! s'il n'y a pas d'inversion
+     .     (zdthmin(i).GT.seuil) )THEN ! si l'inversion est trop faible
+         zl2(i)=(mixlen*MAX(0.0,(paprs(i,k)-paprs(i,klev+1))
+     .                       /(paprs(i,2)-paprs(i,klev+1)) ))**2
+         pcfm(i,k)= zl2(i)* kstable
+         pcfh(i,k) = pcfm(i,k) /prandtl ! h et m different
+      ENDIF
+      ENDDO
+      ENDDO
+c
+      RETURN
+      END
       SUBROUTINE calbeta(dtime,indice,snow,qsol,
      .                    vbeta,vcal,vdif)
@@ -1146,5 +1258,6 @@
 #include "indicesol.h"
       REAL tau_gl ! temps de relaxation pour la glace de mer
-      PARAMETER (tau_gl=86400.0*30.0)
+ccc      PARAMETER (tau_gl=86400.0*30.0)
+      PARAMETER (tau_gl=86400.0*5.0)
       REAL mx_eau_sol
       PARAMETER (mx_eau_sol=150.0)
@@ -1178,6 +1291,6 @@
           IF (snow(i,is_sic) .GT. 0.0) vcal(i) = calsno
           vbeta(i)  = 1.0
-ccc          vdif(i) = 1.0/tau_gl ! c'etait une erreur
-          vdif(i) = calice/tau_gl
+          vdif(i) = 1.0/tau_gl
+ccc          vdif(i) = calice/tau_gl ! c'etait une erreur
       ENDDO
       ENDIF
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/comg1d.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/comg1d.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/comg1d.h	(revision 253)
@@ -0,0 +1,52 @@
+c.......................................................................
+c  le COMMON pour GRADS-1D
+c
+c  on peut se dire : "on ne sauvera pas plus de 1000 variables ... hein ?"
+c
+      INTEGER g1d_nvarmx
+      PARAMETER(g1d_nvarmx=1000)
+c
+c         * g1d_nlayer     ---> nombre de couches verticales
+c         * g1d_nomfich    ---> nom du fichier grads
+c         * g1d_unitfich   ---> code du fichier grads
+c         * g1d_nomctl     ---> nom du fichier ctl
+c         * g1d_unitctl    ---> code du fichier ctl
+c         * g1d_premier    ---> variable logique pour dire si le fichier
+c                               est deja ouvert
+c         * g1d_irec       ---> indice de derniere ecriture
+c         * g1d_nvar       ---> nombre de variables deja definies a la
+c                               derniere ecriture
+c         * g1d_nomvar     ---> noms des vecteurs existants
+c         * g1d_dimvar     ---> taille des vecteurs
+c         * g1d_titrevar   ---> titres des vecteurs
+c         * g1d_tmp1       ---> caractere 
+c         * g1d_tmp2       ---> caractere 
+c
+      INTEGER g1d_nlayer
+      CHARACTER*100 g1d_nomfich
+      INTEGER g1d_unitfich
+      CHARACTER*100 g1d_nomctl
+      INTEGER g1d_unitctl
+      LOGICAL g1d_premier
+      INTEGER g1d_irec
+      INTEGER g1d_nvar
+      CHARACTER*100 g1d_nomvar
+      INTEGER g1d_dimvar
+      CHARACTER*100 g1d_titrevar
+      CHARACTER*100 g1d_tmp1,g1d_tmp2
+c
+      COMMON/COMG1DI/g1d_nlayer
+     &             ,g1d_unitfich
+     &             ,g1d_unitctl
+     &             ,g1d_irec
+     &             ,g1d_nvar
+      COMMON/COMG1DC/g1d_dimvar(0:g1d_nvarmx)
+     &             ,g1d_nomfich
+     &             ,g1d_nomctl
+     &             ,g1d_nomvar(0:g1d_nvarmx)
+     &             ,g1d_titrevar(0:g1d_nvarmx)
+     &             ,g1d_tmp1
+     &             ,g1d_tmp2
+      COMMON/COMG1DL/g1d_premier
+c
+c.......................................................................
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/comvert1d.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/comvert1d.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/comvert1d.h	(revision 253)
@@ -0,0 +1,10 @@
+c-----------------------------------------------------------------------
+c   INCLUDE 'comvert.h'
+
+      COMMON/comvert/
+     . s(klev),sig(klev+1),ds(klev),dsig(klev),dsig1(klev),sdsig(klev)
+     . ,sig_s(klev)
+
+      REAL s,sig,ds,dsig,dsig1,sdsig,sig_s
+
+c-----------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/condsurf.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/condsurf.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/condsurf.F	(revision 253)
@@ -1,2 +1,4 @@
+c $Header$
+c
       SUBROUTINE condsurf( jour, jourvrai, pctsrf,
      s                    lmt_sst,lmt_alb,lmt_rug,lmt_bils )
@@ -43,9 +45,4 @@
       REAL lmt_rug(klon) ! longeur de rugosite du sol
       REAL lmt_bils(klon)
-c
-c Couplage OASIS:
-#include "oasis.h"
-      REAL cpl_sst(iim,jjm+1), cpl_sic(iim,jjm+1)
-      REAL cpl_alb_sst(iim,jjm+1), cpl_alb_sic(iim,jjm+1)
 c
 c Variables locales:
@@ -299,52 +296,4 @@
       PRINT*, 'SST, ALB, RUG, etc. sont lus pour jour: ', jour
 c
-      IF (ok_oasis) THEN
-C
-         CALL fromcpl(jour,(jjm+1)*iim,
-     .        cpl_sst,cpl_sic,cpl_alb_sst,cpl_alb_sic)
-         DO i = 1, iim-1 ! un seul point pour le pole nord
-            cpl_sst(i,1) = cpl_sst(iim,1)
-            cpl_sic(i,1) = cpl_sic(iim,1)
-            cpl_alb_sst(i,1) = cpl_alb_sst(iim,1)
-            cpl_alb_sic(i,1) = cpl_alb_sic(iim,1)
-         ENDDO
-         DO i = 2, iim ! un seul point pour le pole sud
-            cpl_sst(i,jjm+1) = cpl_sst(1,jjm+1)
-            cpl_sic(i,jjm+1) = cpl_sic(1,jjm+1)
-            cpl_alb_sst(i,jjm+1) = cpl_alb_sst(1,jjm+1)
-            cpl_alb_sic(i,jjm+1) = cpl_alb_sic(1,jjm+1)
-         ENDDO
-c
-         ig = 1
-         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
-     .       pctsrf(ig,is_sic).GT.epsfra) THEN
-            pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
-     .                        - (cpl_sic(1,1)-pctsrf(ig,is_sic))
-            pctsrf(ig,is_sic) = cpl_sic(1,1)
-            lmt_sst(ig) = cpl_sst(1,1)
-         ENDIF
-         DO j = 2, jjm
-         DO i = 1, iim
-         ig = ig + 1
-         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
-     .       pctsrf(ig,is_sic).GT.epsfra) THEN
-           pctsrf(ig,is_oce) = pctsrf(ig,is_oce) 
-     .                       - (cpl_sic(i,j)-pctsrf(ig,is_sic))
-           pctsrf(ig,is_sic) = cpl_sic(i,j)
-           lmt_sst(ig) = cpl_sst(i,j)
-         ENDIF
-         ENDDO
-         ENDDO
-         ig = ig + 1
-         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
-     .       pctsrf(ig,is_sic).GT.epsfra) THEN
-            pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
-     .                        - (cpl_sic(1,jjm+1)-pctsrf(ig,is_sic))
-            pctsrf(ig,is_sic) = cpl_sic(1,jjm+1)
-            lmt_sst(ig) = cpl_sst(1,jjm+1)
-         ENDIF
-c
-      ENDIF ! ok_oasis
-c
       RETURN
       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conema3.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conema3.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conema3.F	(revision 253)
@@ -0,0 +1,281 @@
+c $Header$
+      SUBROUTINE conema (dtime,paprs,pplay,t,q,u,v,tra,ntra,
+     .             work1,work2,d_t,d_q,d_u,d_v,d_tra,
+     .             rain, snow, kbas, ktop,
+     .             upwd,dnwd,dnwdbis,bas,top,Ma,cape,tvp,rflag,
+     .             pbase,bbase,dtvpdt1,dtvpdq1,dplcldt,dplcldr)
+
+      IMPLICIT none
+c======================================================================
+c Auteur(s): Z.X. Li (LMD/CNRS) date: 19930818
+c Objet: schema de convection de Emanuel (1991) interface
+c Mai 1998: Interface modifiee pour implementation dans LMDZ
+c======================================================================
+c Arguments:
+c dtime---input-R-pas d'integration (s)
+c paprs---input-R-pression inter-couches (Pa)
+c pplay---input-R-pression au milieu des couches (Pa)
+c t-------input-R-temperature (K)
+c q-------input-R-humidite specifique (kg/kg)
+c u-------input-R-vitesse du vent zonal (m/s)
+c v-------input-R-vitesse duvent meridien (m/s)
+c tra-----input-R-tableau de rapport de melange des traceurs
+c work*: input et output: deux variables de travail,
+c                            on peut les mettre a 0 au debut
+c
+C d_t-----output-R-increment de la temperature
+c d_q-----output-R-increment de la vapeur d'eau
+c d_u-----output-R-increment de la vitesse zonale
+c d_v-----output-R-increment de la vitesse meridienne
+c d_tra---output-R-increment du contenu en traceurs
+c rain----output-R-la pluie (mm/s)
+c snow----output-R-la neige (mm/s)
+c kbas----output-R-bas du nuage (integer)
+c ktop----output-R-haut du nuage (integer)
+c upwd----output-R-saturated updraft mass flux (kg/m**2/s)
+c dnwd----output-R-saturated downdraft mass flux (kg/m**2/s)
+c dnwdbis-output-R-unsaturated downdraft mass flux (kg/m**2/s)
+c bas-----output-R-bas du nuage (real)
+c top-----output-R-haut du nuage (real)
+c Ma------output-R-flux ascendant non dilue (kg/m**2/s)
+c cape----output-R-CAPE
+c tvp-----output-R-virtual temperature of the lifted parcel
+c rflag---output-R-flag sur le fonctionnement de convect
+c pbase---output-R-pression a la base du nuage (Pa)
+c bbase---output-R-buoyancy a la base du nuage (K)
+c dtvpdt1-output-R-derivative of parcel virtual temp wrt T1 
+c dtvpdq1-output-R-derivative of parcel virtual temp wrt Q1 
+c dplcldt-output-R-derivative of the PCP pressure wrt T1
+c dplcldr-output-R-derivative of the PCP pressure wrt Q1
+c======================================================================
+c
+#include "dimensions.h"
+#include "dimphy.h"
+      INTEGER i, l,m,itra
+      INTEGER ntra,ntrac !number of tracers; if no tracer transport
+                         ! is needed, set ntra = 1 (or 0)
+      PARAMETER (ntrac=nqmx-2)
+      REAL dtime
+c
+
+c 
+      REAL paprs(klon,klev+1), pplay(klon,klev)
+      REAL t(klon,klev), q(klon,klev), d_t(klon,klev), d_q(klon,klev)
+      REAL u(klon,klev), v(klon,klev), tra(klon,klev,ntra)
+      REAL d_u(klon,klev), d_v(klon,klev), d_tra(klon,klev,ntra)
+      REAL work1(klon,klev), work2(klon,klev)
+      REAL upwd(klon,klev), dnwd(klon,klev), dnwdbis(klon,klev)
+      REAL rain(klon)
+      REAL snow(klon)
+      REAL cape(klon), tvp(klon,klev), rflag(klon)
+      REAL pbase(klon), bbase(klon)
+      REAL dtvpdt1(klon,klev), dtvpdq1(klon,klev)
+      REAL dplcldt(klon), dplcldr(klon)
+      INTEGER kbas(klon), ktop(klon)
+c
+      REAL em_t(klev)
+      REAL em_q(klev)
+      REAL em_qs(klev)
+      REAL em_u(klev), em_v(klev), em_tra(klev,ntrac)
+      REAL em_ph(klev+1), em_p(klev)
+      REAL em_work1(klev), em_work2(klev)
+      REAL em_precip, em_d_t(klev), em_d_q(klev)
+      REAL em_d_u(klev), em_d_v(klev), em_d_tra(klev,ntrac)
+      REAL em_upwd(klev), em_dnwd(klev), em_dnwdbis(klev)
+      REAL em_dtvpdt1(klev), em_dtvpdq1(klev)
+      REAL em_dplcldt, em_dplcldr
+      SAVE em_t,em_q, em_qs, em_ph, em_p, em_work1, em_work2
+      SAVE em_u,em_v, em_tra
+      SAVE em_d_u,em_d_v, em_d_tra
+      SAVE em_precip, em_d_t, em_d_q, em_upwd, em_dnwd, em_dnwdbis
+      INTEGER em_bas, em_top
+      SAVE em_bas, em_top
+c
+      REAL zx_t, zx_qs, zdelta, zcor
+      INTEGER iflag
+      REAL sigsum
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c     VARIABLES A SORTIR
+cccccccccccccccccccccccccccccccccccccccccccccccccc
+ 
+      REAL emmip(klev) !variation de flux ascnon dilue i et i+1
+      SAVE emmip
+      real emMke(klev)
+      save emMke
+      real top
+      real bas
+      real emMa(klev)
+      save emMa
+      real Ma(klon,klev)
+      real Ment(klev,klev)
+      real Qent(klev,klev)
+      real TPS(klev),TLS(klev)
+      real SIJ(klev,klev)
+      real em_CAPE, em_TVP(klev)
+      real em_pbase, em_bbase
+      integer iw,j,k,ix,iy
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c
+#include "YOMCST.h"
+#include "YOETHF.h"
+#include "FCTTRE.h"
+ 
+c
+c$$$      print*,'debut conema'
+
+      DO 999 i = 1, klon
+      DO l = 1, klev+1
+         em_ph(l) = paprs(i,l) / 100.0
+      ENDDO
+c
+      DO l = 1, klev
+         em_p(l) = pplay(i,l) / 100.0
+         em_t(l) = t(i,l)
+         em_q(l) = q(i,l)
+         em_u(l) = u(i,l)
+         em_v(l) = v(i,l)
+         do itra = 1, ntra
+          em_tra(l,itra) = tra(i,l,itra)
+         enddo
+c$$$      print*,'em_t',em_t
+c$$$      print*,'em_q',em_q
+c$$$      print*,'em_qs',em_qs
+c$$$      print*,'em_u',em_u
+c$$$      print*,'em_v',em_v
+c$$$      print*,'em_tra',em_tra
+c$$$      print*,'em_p',em_p
+
+ 
+c
+         zx_t = em_t(l)
+         zdelta=MAX(0.,SIGN(1.,rtt-zx_t))
+         zx_qs= r2es * FOEEW(zx_t,zdelta)/em_p(l)/100.0
+         zx_qs=MIN(0.5,zx_qs)
+c$$$       print*,'zx_qs',zx_qs
+         zcor=1./(1.-retv*zx_qs) 
+         zx_qs=zx_qs*zcor
+         em_qs(l) = zx_qs
+c$$$      print*,'em_qs',em_qs
+c
+         em_work1(l) = work1(i,l)
+         em_work2(l) = work2(i,l)
+         emMke(l)=0
+c        emMa(l)=0
+c        Ma(i,l)=0
+     
+         em_dtvpdt1(l) = 0.
+         em_dtvpdq1(l) = 0.
+         dtvpdt1(i,l) = 0.
+         dtvpdq1(i,l) = 0.
+      ENDDO
+c
+      em_dplcldt = 0.
+      em_dplcldr = 0.
+      rain(i) = 0.0
+      snow(i) = 0.0
+      kbas(i) = 1
+      ktop(i) = 1
+c ajout SB:
+      bas = 1
+      top = 1
+ 
+ 
+c sb3d      write(*,1792) (em_work1(m),m=1,klev)
+1792  format('sig avant convect ',/,10(1X,E13.5))
+c
+c sb d      write(*,1793) (em_work2(m),m=1,klev)
+1793  format('w avant convect ',/,10(1X,E13.5))
+ 
+c$$$      print*,'avant convect' 
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c 
+      CALL convect(dtime, em_t, em_q, em_qs,em_u ,em_v ,
+     .              em_tra, em_p, em_ph,
+     .              klev, klev+1, klev-1,ntra, dtime, iflag,
+     .              em_d_t, em_d_q,em_d_u,em_d_v,
+     .              em_d_tra, em_precip,
+     .              em_bas, em_top,em_upwd, em_dnwd, em_dnwdbis,
+     .              em_work1, em_work2,emmip,emMke,emMa,Ment,
+c SB 11sept98     .              Qent,TPS,TLS,SIJ)
+c 19oct98     .              Qent,TPS,TLS,SIJ,em_CAPE,em_TVP)
+     .  Qent,TPS,TLS,SIJ,em_CAPE,em_TVP,em_pbase,em_bbase,
+     .  em_dtvpdt1,em_dtvpdq1,em_dplcldt,em_dplcldr)
+c
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c
+c SB:
+      if (iflag.ne.1 .and. iflag.ne.4) then
+         em_CAPE = 0.
+      do l = 1, klev
+         em_upwd(l) = 0.
+         em_dnwd(l) = 0.
+         em_dnwdbis(l) = 0.
+         emMa(l) = 0.
+         em_TVP(l) = 0.
+      enddo
+      endif
+c fin SB
+c
+c  If sig has been set to zero, then set Ma to zero
+c
+      sigsum = 0.
+      do k = 1,klev
+        sigsum = sigsum + em_work1(k)
+      enddo
+      if (sigsum .eq. 0.0) then
+        do k = 1,klev
+          emMa(k) = 0.
+        enddo
+      endif
+c
+c sb3d       print*,'i, iflag=',i,iflag
+c 
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c
+c       SORTIE DES ICB ET INB
+c       en fait inb et icb correspondent au niveau ou se trouve
+c       le nuage,le numero d'interface
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+ 
+c modif SB:
+      if (iflag.EQ.1 .or. iflag.EQ.4) then
+       top=em_top
+       bas=em_bas
+       kbas(i) = em_bas
+       ktop(i) = em_top
+      endif
+ 
+      pbase(i) = em_pbase
+      bbase(i) = em_bbase
+      rain(i) = em_precip/ 86400.0
+      snow(i) = 0.0
+      cape(i) = em_CAPE
+      rflag(i) = float(iflag)
+c SB      kbas(i) = em_bas
+c SB      ktop(i) = em_top
+      dplcldt(i) = em_dplcldt
+      dplcldr(i) = em_dplcldr
+      DO l = 1, klev
+         d_t(i,l) = dtime * em_d_t(l) 
+         d_q(i,l) = dtime * em_d_q(l)
+         d_u(i,l) = dtime * em_d_u(l)
+         d_v(i,l) = dtime * em_d_v(l)
+         do itra = 1, ntra
+         d_tra(i,l,itra) = dtime * em_d_tra(l,itra)
+         enddo
+         upwd(i,l) = em_upwd(l)
+         dnwd(i,l) = em_dnwd(l)
+         dnwdbis(i,l) = em_dnwdbis(l)
+         work1(i,l) = em_work1(l)
+         work2(i,l) = em_work2(l)
+         Ma(i,l)=emMa(l)
+         tvp(i,l)=em_TVP(l)
+         dtvpdt1(i,l) = em_dtvpdt1(l)
+         dtvpdq1(i,l) = em_dtvpdq1(l)
+      ENDDO
+  999 CONTINUE
+ 
+
+      RETURN
+      END
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conf_phys.F90
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conf_phys.F90	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conf_phys.F90	(revision 253)
@@ -0,0 +1,97 @@
+!
+! $Header$
+!
+
+  subroutine conf_phys(ocean, ok_veget, ok_journe, ok_mensuel, ok_instan)
+
+   use IOIPSL
+   implicit none
+
+!
+! Configuration de la "physique" de LMDZ a l'aide de la fonction
+! GETIN de IOIPSL
+!
+! LF 05/2001
+!
+
+!
+! ocean:      type d'ocean (force, slab, couple)
+! ok_veget:   type de modele de vegetation
+! ok_journe:  sorties journalieres
+! ok_mensuel: sorties mensuelles
+! ok_instan:  sorties instantanees
+
+
+
+! Sortie:
+  character (len = 6)  :: ocean
+  logical              :: ok_veget
+  logical              :: ok_journe, ok_mensuel, ok_instan
+! Local
+  integer              :: numout = 6
+
+!
+!
+!
+
+
+!Config Key  = OCEAN 
+!Config Desc = Type d'ocean
+!Config Def  = force
+!Config Help = Type d'ocean utilise: force, slab,couple
+!
+  ocean = 'force '
+  call getin('OCEAN', ocean)
+!
+!Config Key  = VEGET 
+!Config Desc = Type de modele de vegetation
+!Config Def  = .false.
+!Config Help = Type de modele de vegetation utilise
+!
+  ok_veget = .false.
+  call getin('VEGET', ok_veget)
+!
+!Config Key  = OK_journe
+!Config Desc = Pour des sorties journalieres 
+!Config Def  = .false.
+!Config Help = Pour creer le fichier histday contenant les sorties
+!              journalieres 
+!
+  ok_journe = .false.
+  call getin('OK_journe', ok_journe)
+!
+!Config Key  = OK_mensuel
+!Config Desc = Pour des sorties mensuelles 
+!Config Def  = .true.
+!Config Help = Pour creer le fichier histmth contenant les sorties
+!              mensuelles 
+!
+  ok_mensuel = .true.
+  call getin('OK_mensuel', ok_mensuel)
+!
+!Config Key  = OK_instan
+!Config Desc = Pour des sorties instantanees 
+!Config Def  = .false.
+!Config Help = Pour creer le fichier histins contenant les sorties
+!              instantanees 
+!
+  ok_instan = .false.
+  call getin('OK_instan', ok_instan)
+
+!
+!
+!
+
+  write(numout,*)' ##############################################'
+  write(numout,*)' Configuration des parametres de la physique: '
+  write(numout,*)' Config ocean = ', ocean
+  write(numout,*)' Config veget = ', ok_veget
+  write(numout,*)' Sortie journaliere = ', ok_journe
+  write(numout,*)' Sortie mensuelle = ', ok_mensuel
+  write(numout,*)' Sortie instantanee = ', ok_instan
+
+
+  return
+
+  end subroutine conf_phys
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conflx.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/conflx.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conflx.F	(revision 253)
@@ -65,4 +65,6 @@
       REAL zde_u(klon,klev)
       REAL zde_d(klon,klev)
+      REAL zmflxr(klon,klev+1)
+      REAL zmflxs(klon,klev+1)
 cAA
 
@@ -101,6 +103,6 @@
       DO k = 1, klev+1
       DO i = 1, klon
-         pmflxr(i,k) = 0.0
-         pmflxs(i,k) = 0.0
+         zmflxr(i,k) = 0.0
+         zmflxs(i,k) = 0.0
       ENDDO
       ENDDO
@@ -150,5 +152,5 @@
      .             rain, snow, kcbot, kctop, kdtop,
      .             zmfu, zmfd, zen_u, zde_u, zen_d, zde_d,
-     .             d_t_bis, d_q_bis, pmflxr, pmflxs)
+     .             d_t_bis, d_q_bis, zmflxr, zmflxs)
 C
 cAA--------------------------------------------------------
@@ -193,5 +195,11 @@
       ENDDO
 
-c
+      DO k = 1, klev+1
+      DO i = 1, klon
+         pmflxr(i,klev+2-k)= zmflxr(i,k)
+         pmflxs(i,klev+2-k)= zmflxs(i,k)
+      ENDDO
+      ENDDO
+
       RETURN
       END
@@ -309,5 +317,6 @@
       DO i = 1, klon
          ktype(i) = 2
-         if (zdqcv(i).GT.MAX(0.,-1.1*pqhfl(i)*RG)) ktype(i) = 1
+         if (zdqcv(i).GT.MAX(0.,-1.5*pqhfl(i)*RG)) ktype(i) = 1
+ccc         if (zdqcv(i).GT.MAX(0.,-1.1*pqhfl(i)*RG)) ktype(i) = 1
       ENDDO
 c
@@ -972,4 +981,6 @@
       ENDDO
 c
+      ldcum(1)=ldcum(1)
+c
       is = 0
       DO i = 1, klon
@@ -1030,10 +1041,12 @@
       REAL plude(klon,klev)
       REAL pdmfup(klon,klev), pdpmel(klon,klev)
-      REAL pdmfdp(klon,klev)
+cjq The variable maxpdmfdp(klon) has been introduced by Olivier Boucher
+cjq 14/11/00 to fix the problem with the negative precipitation.      
+      REAL pdmfdp(klon,klev), maxpdmfdp(klon,klev) 
       REAL prfl(klon), psfl(klon)
       REAL pmflxr(klon,klev+1), pmflxs(klon,klev+1)
       INTEGER  kcbot(klon), kctop(klon), ktype(klon)
       LOGICAL  ldland(klon), ldcum(klon)
-      INTEGER k, i
+      INTEGER k, kp, i
       REAL zcons1, zcons2, zcucov, ztmelp2
       REAL pdtime, zdp, zzp, zfac, zsnmlt, zrfl, zrnew
@@ -1151,7 +1164,9 @@
          ENDIF
          IF (pten(i,k).GT.RTT) THEN
-           pmflxr(i,k+1)=pmflxr(i,k)+pdmfup(i,k)+pdmfdp(i,k)+pdpmel(i,k)
+         pmflxr(i,k+1)=pmflxr(i,k)+pdmfup(i,k)+pdmfdp(i,k)+pdpmel(i,k)
+         pmflxs(i,k+1)=pmflxs(i,k)-pdpmel(i,k)
          ELSE
-           pmflxs(i,k+1)=pmflxs(i,k)+pdmfup(i,k)+pdmfdp(i,k)-pdpmel(i,k)
+           pmflxs(i,k+1)=pmflxs(i,k)+pdmfup(i,k)+pdmfdp(i,k)
+           pmflxr(i,k+1)=pmflxr(i,k)
          ENDIF
 c        si la precipitation est negative, on ajuste le plux du
@@ -1167,4 +1182,26 @@
       ENDDO
 c
+cjq The new variable is initialized here.
+cjq It contains the humidity which is fed to the downdraft
+cjq by evaporation of precipitation in the column below the base
+cjq of convection.
+cjq 
+cjq In the former version, this term has been subtracted from precip
+cjq as well as the evaporation.
+cjq      
+      DO k = 1, klev
+      DO i = 1, klon 
+         maxpdmfdp(i,k)=0.0
+      ENDDO
+      ENDDO
+      DO k = 1, klev
+       DO kp = k, klev
+        DO i = 1, klon
+         maxpdmfdp(i,k)=maxpdmfdp(i,k)+pdmfdp(i,kp)
+        ENDDO
+       ENDDO
+      ENDDO
+cjq End of initialization
+c      
       DO k = ktopm2, klev
       DO i = 1, klon
@@ -1180,4 +1217,11 @@
             zrfln=MAX(zrnew,0.)
             zdrfl=MIN(0.,zrfln-zrfl)
+cjq At least the amount of precipiation needed to feed the downdraft
+cjq with humidity below the base of convection has to be left and can't
+cjq be evaporated (surely the evaporation can't be positive):            
+            zdrfl=MAX(zdrfl,
+     .            MIN(-pmflxr(i,k)-pmflxs(i,k)-maxpdmfdp(i,k),0.0))
+cjq End of insertion
+c            
             zdenom=1.0/MAX(1.0E-20,pmflxr(i,k)+pmflxs(i,k))
             IF (pten(i,k).GT.RTT) THEN
@@ -1198,5 +1242,7 @@
             pdmfdp(i,k) = 0.0
             pdpmel(i,k) = 0.0
-         ENDIF
+         ENDIF         
+         if (pmflxr(i,k) + pmflxs(i,k).lt.-1.e-26) 
+     .    write(*,*) 'precip. < 1e-16 ',pmflxr(i,k) + pmflxs(i,k)
       ENDIF
       ENDDO
@@ -1539,4 +1585,9 @@
       zalsdcp = rlstt/RCPD
 C
+
+      DO i = 1, klon
+         zcond(i) = 0.0
+      ENDDO
+
       DO 210 i =1, klon
       IF (ldflag(i)) THEN
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conlmd.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/conlmd.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/conlmd.F	(revision 253)
@@ -126,10 +126,8 @@
       INTEGER nb ! nombre de sous-fractions a considere
       PARAMETER (nb=1)
-ccc      PARAMETER (nb=5)
 ccc      PARAMETER (nb=3)
 c
       REAL ratqs ! largeur de la distribution pour vapeur d'eau
-      PARAMETER (ratqs=0.2)
-c
+      PARAMETER (ratqs=0.05)
 c
       REAL w_q(klon,klev)
@@ -167,8 +165,6 @@
       DATA frac / 1.0 /
       DATA opt_cld / 4 /
-ccc      DATA frac    / 1.0, 0.75, 0.50, 0.25, 0.05 /
-ccc      DATA opt_cld / 3,   3,    3,    3,    3 /
 ccc      DATA frac    / 1.0, 0.50, 0.25/
-ccc      DATA opt_cld / 3,   3,    3/
+ccc      DATA opt_cld / 4,   4,    4/
 c
       DATA appel1er /.TRUE./
@@ -248,5 +244,6 @@
          zflo = t(i,k) + zgamdz - t(i,k+1)
          zsat = (q(i,k)-zqs1)*zdp1 + (q(i,k+1)-zqs2)*zdp2
-         IF (zflo.GT.0.0 .AND. zsat.GT.0.0) afaire(i) = .TRUE.
+         IF (zflo.GT.0.0) afaire(i) = .TRUE.
+c erreur         IF (zflo.GT.0.0 .AND. zsat.GT.0.0) afaire(i) = .TRUE.
       ENDDO
       ENDDO
@@ -339,5 +336,5 @@
       PARAMETER (new_top=.FALSE.)
       LOGICAL evap_prec ! evaporation de pluie au-dessous de convection
-      PARAMETER (evap_prec=.FALSE.)
+      PARAMETER (evap_prec=.TRUE.)
       REAL coef_eva
       PARAMETER (coef_eva=1.0E-05)
@@ -350,9 +347,14 @@
       REAL toliq(klon) ! rapport entre l'eau nuageuse et l'eau precipitante
       REAL dpmin, tomax !Epaisseur faible, rapport eau liquide plus grande
-      PARAMETER (dpmin=0.1, tomax=0.2)
+      PARAMETER (dpmin=0.15, tomax=0.97)
       REAL dpmax, tomin !Epaisseur grande, rapport eau liquide plus faible
-      PARAMETER (dpmax=0.6, tomin=0.1)
+      PARAMETER (dpmax=0.30, tomin=0.05)
+      REAL deep_sig, deep_to ! au dela de deep_sig, utiliser deep_to
+      PARAMETER (deep_sig=0.50, deep_to=0.05)
       LOGICAL exigent ! implique un calcul supplementaire pour Qs
       PARAMETER (exigent=.FALSE.)
+c
+      INTEGER kbase
+      PARAMETER (kbase=0)
 c
 c Variables locales:
@@ -479,6 +481,6 @@
       DO i = 1, klon
       IF (possible(i)) THEN
-         k1(i) = 0
-         k2(i) = 1
+         k1(i) = kbase
+         k2(i) = k1(i) + 1
       ENDIF
       ENDDO
@@ -688,4 +690,5 @@
      .                 *(tomax-tomin)/(dpmax-dpmin)
       toliq(i) = MAX(tomin,MIN(tomax,toliq(i)))
+      IF (pplay(i,k2(i))/paprs(i,1) .LE. deep_sig) toliq(i) = deep_to
       IF (old_tau) toliq(i) = 1.0
       ENDIF
@@ -787,5 +790,6 @@
       ELSE IF (opt_cld.EQ.4) THEN
 c
-         nexpo = 1 ! distribution lineaire
+         nexpo = 3
+ccc         nexpo = 1 ! distribution lineaire
 c
          DO i = 1, klon
@@ -927,9 +931,12 @@
       k1max = 1
       DO i = 1, klon
-      IF (todo(i) .AND. k1(i).GT.1) THEN
+      IF (todo(i) .AND. k1(i).GT.(kbase+1)) THEN
          k = k1(i)
          zflo(i) = zt(i,k-1) + zgamdz(i,k-1) - zt(i,k)
          zsat(i) = zqmqsdp(i,k) + zqmqsdp(i,k-1)
-         IF (zflo(i).LE.0.0 .OR. zsat(i).LE.0.0) THEN
+csc voici l'ancienne ligne:
+csc         IF (zflo(i).LE.0.0 .OR. zsat(i).LE.0.0) THEN
+csc sylvain: il faut RESPECTER les 2 criteres:
+         IF (zflo(i).GT.0.0 .AND. zsat(i).GT.0.0) THEN
             etendre(i) = .TRUE.
             k1(i) = k1(i) - 1
@@ -940,6 +947,6 @@
       ENDDO
 c
-      IF (k1max.GT.1) THEN
-      DO k = k1max, 1, -1
+      IF (k1max.GT.(kbase+1)) THEN
+      DO k = k1max, kbase+1, -1
       DO i = 1, klon
       IF (etendre(i) .AND. k.LT.k1(i) .AND. aller(i)) THEN
@@ -1095,5 +1102,5 @@
       PARAMETER (opt_cld=4) ! valeur possible: 0, 1, 2, 3 ou 4
       LOGICAL evap_prec ! evaporation de pluie au-dessous de convection
-      PARAMETER (evap_prec=.FALSE.)
+      PARAMETER (evap_prec=.TRUE.)
       REAL coef_eva
       PARAMETER (coef_eva=1.0E-05)
@@ -1106,7 +1113,9 @@
       REAL toliq(klon) ! rapport entre l'eau nuageuse et l'eau precipitante
       REAL dpmin, tomax !Epaisseur faible, rapport eau liquide plus grande
-      PARAMETER (dpmin=0.1, tomax=0.2)
+      PARAMETER (dpmin=0.15, tomax=0.97)
       REAL dpmax, tomin !Epaisseur grande, rapport eau liquide plus faible
-      PARAMETER (dpmax=0.6, tomin=0.1)
+      PARAMETER (dpmax=0.30, tomin=0.05)
+      REAL deep_sig, deep_to ! au dela de deep_sig, utiliser deep_to
+      PARAMETER (deep_sig=0.50, deep_to=0.05)
 c
 c Variables locales:
@@ -1383,4 +1392,5 @@
      .             *(tomax-tomin)/(dpmax-dpmin)
       toliq(i) = MAX(tomin,MIN(tomax,toliq(i)))
+      IF (pplay(i,kh(i))/paprs(i,1) .LE. deep_sig) toliq(i) = deep_to
       IF (old_tau) toliq(i) = 1.0
       ENDIF
@@ -1497,5 +1507,6 @@
       ELSE IF (opt_cld.EQ.4) THEN
 c
-         nexpo = 1 ! distribution lineaire
+         nexpo = 3
+ccc         nexpo = 1 ! distribution lineaire
 c
          DO i = 1, klon
@@ -1708,4 +1719,8 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
+c
+      DO i = 1, klon
+         zcond(i) = 0.0
+      ENDDO
 C
       DO 210 i=1, klon
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/convect3.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/convect3.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/convect3.F	(revision 253)
@@ -0,0 +1,1252 @@
+c $Header$
+      SUBROUTINE CONVECT
+     *    (DTIME,  T1,   R1,   RS,    U,  V,  TRA,   P,     PH,
+     *     ND,       NDP1,     NL, NTRA,  DELT,  IFLAG,
+     *     FT, FR, FU,  FV,  FTRA,  PRECIP,
+     *     icb,inb,   upwd,dnwd,dnwd0,SIG, W0,Mike,Mke,
+     *     Ma,MENTS,QENTS,TPS,TLS,SIGIJ,CAPE,TVP,PBASE,BUOYBASE,
+     *     DTVPDT1,DTVPDQ1,DPLCLDT,DPLCLDR)
+C
+C    ***  THE PARAMETER NA SHOULD IN GENERAL EQUAL ND   ***
+C
+c#################################################################
+cFleur       Introduction des traceurs dans convect3 le 6 juin 200
+c#################################################################
+#include "dimensions.h"
+#include "dimphy.h"
+      PARAMETER (NA=60)
+
+      integer NTRAC
+      PARAMETER (NTRAC=nqmx-2)
+
+      INTEGER NENT(NA)
+      REAL T1(ND),R1(ND),RS(ND),U(ND),V(ND),TRA(ND,NTRA)
+      REAL P(ND),PH(NDP1)
+      REAL FT(ND),FR(ND),FU(ND),FV(ND),FTRA(ND,NTRA)
+      REAL SIG(ND),W0(ND)
+      REAL UENT(NA,NA),VENT(NA,NA),TRAENT(NA,NA,NTRAC),TRATM(NA)
+      REAL UP(NA),VP(NA),TRAP(NA,NTRAC)
+      REAL M(NA),MP(NA),MENT(NA,NA),QENT(NA,NA),ELIJ(NA,NA)
+      REAL SIJ(NA,NA),TVP(NA),TV(NA),WATER(NA)
+      REAL RP(NA),EP(NA),TH(NA),WT(NA),EVAP(NA),CLW(NA)
+      REAL SIGP(NA),B(NA),TP(NA),CPN(NA)
+      REAL LV(NA),LVCP(NA),H(NA),HP(NA),GZ(NA)
+      REAL T(NA),RR(NA)
+C
+      REAL BUOY(NA)     !  Lifted parcel buoyancy
+      REAL DTVPDT1(ND),DTVPDQ1(ND)   ! Derivatives of parcel virtual
+C                                      temperature wrt T1 and Q1
+      REAL CLW_NEW(NA),QI(NA)
+C
+      LOGICAL ICE_CONV
+      PARAMETER (ICE_CONV=.TRUE.)
+ 
+cccccccccccccccccccccccccccccccccccccccccccccc
+c     declaration des variables a sortir
+ccccccccccccccccccccccccccccccccccccccccccccc
+      real Mke(nd)
+      real Mike(nd)
+      real Ma(nd)
+      real TPS(ND) !temperature dans les ascendances non diluees
+      real TLS(ND) !temperature potentielle
+      real MENTS(nd,nd)
+      real QENTS(nd,nd)
+      REAL SIGIJ(KLEV,KLEV)
+      REAL PBASE ! pressure at the cloud base level
+      REAL BUOYBASE ! buoyancy at the cloud base level
+cccccccccccccccccccccccccccccccccccccccccccccc
+ 
+ 
+ 
+c
+      real dnwd0(nd)  !  precipitation driven unsaturated downdraft flux
+      real dnwd(nd), dn1  ! in-cloud saturated downdraft mass flux
+      real upwd(nd), up1  ! in-cloud saturated updraft mass flux
+C
+C   ***         ASSIGN VALUES OF THERMODYNAMIC CONSTANTS        ***
+C   ***             THESE SHOULD BE CONSISTENT WITH             ***
+C   ***              THOSE USED IN CALLING PROGRAM              ***
+C   ***     NOTE: THESE ARE ALSO SPECIFIED IN SUBROUTINE TLIFT  ***
+C
+c sb      CPD=1005.7
+c sb      CPV=1870.0
+c sb      CL=4190.0
+c sb      CPVMCL=CL-CPV
+c sb      RV=461.5
+c sb      RD=287.04
+c sb      EPS=RD/RV
+c sb      ALV0=2.501E6
+ccccccccccccccccccccccc
+c constantes coherentes avec le modele du Centre Europeen
+c sb      RD = 1000.0 * 1.380658E-23 * 6.0221367E+23 / 28.9644
+c sb      RV = 1000.0 * 1.380658E-23 * 6.0221367E+23 / 18.0153
+c sb      CPD = 3.5 * RD
+c sb      CPV = 4.0 * RV
+c sb      CL = 4218.0
+c sb      CPVMCL=CL-CPV
+c sb      EPS=RD/RV
+c sb      ALV0=2.5008E+06
+cccccccccccccccccccccc
+c on utilise les constantes thermo du Centre Europeen: (SB)
+c
+#include "YOMCST.h"
+c
+       CPD = RCPD
+       CPV = RCPV
+       CL = RCW
+       CPVMCL = CL-CPV
+       EPS = RD/RV
+       ALV0 = RLVTT
+c
+       NK = 1 ! origin level of the lifted parcel
+c
+cccccccccccccccccccccc
+C
+C           ***  INITIALIZE OUTPUT ARRAYS AND PARAMETERS  ***
+C
+      DO 5 I=1,ND
+         FT(I)=0.0
+         FR(I)=0.0
+         FU(I)=0.0
+         FV(I)=0.0
+         DO 4 J=1,NTRA
+          FTRA(I,J)=0.0
+    4    CONTINUE
+         T(I)=T1(I)
+         RR(I)=R1(I)
+    5 CONTINUE
+      DO 7 I=1,NL
+         RDCP=(RD*(1.-RR(I))+RR(I)*RV)/ (CPD*(1.-RR(I))+RR(I)*CPV)
+         TH(I)=T(I)*(1000.0/P(I))**RDCP
+    7 CONTINUE
+C
+*************************************************************
+**    CALCUL DES TEMPERATURES POTENTIELLES A SORTIR
+*************************************************************
+      do i=1,ND
+      RDCP=(RD*(1.-RR(I))+RR(I)*RV)/ (CPD*(1.-RR(I))+RR(I)*CPV)
+ 
+      TLS(i)=T(I)*(1000.0/P(I))**RDCP
+      enddo
+ 
+ 
+ 
+ 
+************************************************************
+ 
+ 
+      PRECIP=0.0
+      IFLAG=1
+C
+C   ***                    SPECIFY PARAMETERS                        ***
+C   ***  PBCRIT IS THE CRITICAL CLOUD DEPTH (MB) BENEATH WHICH THE   ***
+C   ***       PRECIPITATION EFFICIENCY IS ASSUMED TO BE ZERO         ***
+C   ***  PTCRIT IS THE CLOUD DEPTH (MB) ABOVE WHICH THE PRECIP.      ***
+C   ***            EFFICIENCY IS ASSUMED TO BE UNITY                 ***
+C   ***  SIGD IS THE FRACTIONAL AREA COVERED BY UNSATURATED DNDRAFT  ***
+C   ***  SPFAC IS THE FRACTION OF PRECIPITATION FALLING OUTSIDE      ***
+C   ***                        OF CLOUD                              ***
+C   ***    ALPHA AND BETA ARE PARAMETERS THAT CONTROL THE RATE OF    ***
+C   ***                 APPROACH TO QUASI-EQUILIBRIUM                ***
+C   ***    (THEIR STANDARD VALUES ARE 1.0 AND 0.96, RESPECTIVELY)    ***
+C   ***           (BETA MUST BE LESS THAN OR EQUAL TO 1)             ***
+C   ***    DTCRIT IS THE CRITICAL BUOYANCY (K) USED TO ADJUST THE    ***
+C   ***                 APPROACH TO QUASI-EQUILIBRIUM                ***
+C   ***                     IT MUST BE LESS THAN 0                   ***
+C
+      PBCRIT=150.0
+      PTCRIT=500.0
+      SIGD=0.01
+      SPFAC=0.15
+c sb:
+      EPMAX=0.993 ! precip efficiency less than unity
+c      EPMAX=1. ! precip efficiency less than unity
+C
+Cjyg
+CCC      BETA=0.96
+C  Beta is now expressed as a function of the characteristic time
+C  of the convective process.
+CCC        Old value : TAU = 15000.   !(for dtime = 600.s)
+CCC        Other value (inducing little change) :TAU = 8000.
+      TAU = 8000.
+      BETA = 1.-DTIME/TAU
+Cjyg
+CCC      ALPHA=1.0
+      ALPHA=1.5E-3*DTIME/TAU
+C        Increase alpha in order to compensate W decrease
+      ALPHA = ALPHA*1.5
+C
+Cjyg (voir CONVECT 3)
+CCC      DTCRIT=-0.2
+      DTCRIT=-2.
+Cgf&jyg
+CCC     DT pour l'overshoot.
+      DTOVSH = -0.2
+ 
+C
+C           ***        INCREMENT THE COUNTER       ***
+C
+      SIG(ND)=SIG(ND)+1.0
+      SIG(ND)=AMIN1(SIG(ND),12.1)
+C
+C           ***    IF NOPT IS AN INTEGER OTHER THAN 0, CONVECT     ***
+C           ***     RETURNS ARRAYS T AND R THAT MAY HAVE BEEN      ***
+C           ***  ALTERED BY DRY ADIABATIC ADJUSTMENT; OTHERWISE    ***
+C           ***        THE RETURNED ARRAYS ARE UNALTERED.          ***
+C
+      NOPT=0
+C
+C     ***            PERFORM DRY ADIABATIC ADJUSTMENT            ***
+C
+C     ***  DO NOT BYPASS THIS EVEN IF THE CALLING PROGRAM HAS A  ***
+C     ***                BOUNDARY LAYER SCHEME !!!               ***
+C
+c test sb      DO 30 I=NL-1,1,-1
+c test sb         JN=0
+c test sb         DO 10 J=I+1,NL
+c test sb   10    IF(TH(J).LT.TH(I))JN=J
+c test sb         IF(JN.EQ.0)GOTO 30
+c test sb         AHM=0.0
+c test sb         RM=0.0
+c test sb         UM=0.0
+c test sb         VM=0.0
+c test sb         DO K=1,NTRA
+c test sb          TRATM(K)=0.0
+c test sb         END DO
+c test sb         DO 15 J=I,JN
+c test sb          AHM=AHM+(CPD*(1.-RR(J))+RR(J)*CPV)*T(J)*(PH(J)-PH(J+1))
+c test sb          RM=RM+RR(J)*(PH(J)-PH(J+1))
+c test sb          UM=UM+U(J)*(PH(J)-PH(J+1))
+c test sb          VM=VM+V(J)*(PH(J)-PH(J+1))
+c test sb          DO K=1,NTRA
+c test sb           TRATM(K)=TRATM(K)+TRA(J,K)*(PH(J)-PH(J+1))
+c test sb          END DO
+c test sb   15    CONTINUE
+c test sb         DPHINV=1./(PH(I)-PH(JN+1))
+c test sb         RM=RM*DPHINV
+c test sb         UM=UM*DPHINV
+c test sb         VM=VM*DPHINV
+c test sb         DO K=1,NTRA
+c test sb          TRATM(K)=TRATM(K)*DPHINV
+c test sb         END DO
+c test sb         A2=0.0
+c test sb         DO 20 J=I,JN
+c test sb            RR(J)=RM
+c test sb          U(J)=UM
+c test sb          V(J)=VM
+c test sb          DO K=1,NTRA
+c test sb           TRA(J,K)=TRATM(K)
+c test sb          END DO
+c test sb            RDCP=(RD*(1.-RR(J))+RR(J)*RV)/ (CPD*(1.-RR(J))+RR(J)*CPV)
+c test sb            X=(0.001*P(J))**RDCP
+c test sb            T(J)=X
+c test sb            A2=A2+(CPD*(1.-RR(J))+RR(J)*CPV)*X*(PH(J)-PH(J+1))
+c test sb   20    CONTINUE
+c test sb         DO 25 J=I,JN
+c test sb            TH(J)=AHM/A2
+c test sb            T(J)=T(J)*TH(J)
+c test sb   25    CONTINUE
+c test sb   30 CONTINUE
+C
+C   ***   RESET INPUT ARRAYS IF NOPT .NE. 0   ***
+C
+      IF (NOPT.NE.0)THEN
+         DO 35 I=1,ND
+            T1(I)=T(I)
+            R1(I)=RR(I)
+   35    CONTINUE
+      END IF
+C
+C  *** CALCULATE ARRAYS OF GEOPOTENTIAL, HEAT CAPACITY AND STATIC ENERGY
+C
+      GZ(1)=0.0
+      CPN(1)=CPD*(1.-RR(1))+RR(1)*CPV
+      H(1)=T(1)*CPN(1)
+      DO 40 I=2,NL
+        TVX=T(I)*(1.+RR(I)/EPS-RR(I))
+        TVY=T(I-1)*(1.+RR(I-1)/EPS-RR(I-1))
+        GZ(I)=GZ(I-1)+0.5*RD*(TVX+TVY)*(P(I-1)-P(I))/PH(I)
+        CPN(I)=CPD*(1.-RR(I))+CPV*RR(I)
+        H(I)=T(I)*CPN(I)+GZ(I)
+   40 CONTINUE
+C
+C   ***  CALCULATE LIFTED CONDENSATION LEVEL OF AIR AT LOWEST MODEL LEVEL ***
+C   ***       (WITHIN 0.2% OF FORMULA OF BOLTON, MON. WEA. REV.,1980)     ***
+C
+      IF (T(1).LT.250.0.OR.RR(1).LE.0.0)THEN
+         IFLAG=0
+c sb3d         print*,'je suis passe par 366'
+         RETURN
+      END IF
+
+cjyg1 Utilisation de la subroutine CLIFT
+CC      RH=RR(1)/RS(1)
+CC      CHI=T(1)/(1669.0-122.0*RH-T(1))
+CC      PLCL=P(1)*(RH**CHI)
+      CALL CLIFT(P(1),T(1),RR(1),RS(1),PLCL,DPLCLDT,DPLCLDR)
+cjyg2
+c sb3d      PRINT *,' em_plcl,p1,t1,r1,rs1,rh '
+c sb3d     $        ,PLCL,P(1),T(1),RR(1),RS(1),RH
+c
+      IF (PLCL.LT.200.0.OR.PLCL.GE.2000.0)THEN
+         IFLAG=2
+         RETURN
+      END IF
+Cjyg1
+C     Essais de modification de ICB
+C
+C   ***  CALCULATE FIRST LEVEL ABOVE LCL (=ICB)  ***
+C
+CC      ICB=NL-1
+CC      DO 50 I=2,NL-1
+CC         IF(P(I).LT.PLCL)THEN
+CC            ICB=MIN(ICB,I)   ! ICB sup ou egal a 2
+CC         END IF
+CC   50 CONTINUE
+CC      IF(ICB.EQ.(NL-1))THEN
+CC         IFLAG=3
+CC         RETURN
+CC      END IF
+C
+C   *** CALCULATE LAYER CONTAINING LCL (=ICB)   ***
+C
+      ICB=NL-1
+c sb      DO 50 I=2,NL-1
+      DO 50 I=3,NL-1 ! modif sb pour que ICB soit sup/egal a 2
+C   la modification consiste a comparer PLCL a PH et non a P:
+C   ICB est defini par :  PH(ICB)<PLCL<PH(ICB-!)
+         IF(PH(I).LT.PLCL)THEN
+            ICB=MIN(ICB,I)
+         END IF
+   50 CONTINUE
+      IF(ICB.EQ.(NL-1))THEN
+         IFLAG=3
+         RETURN
+      END IF
+      ICB = ICB-1 ! ICB sup ou egal a 2 
+Cjyg2
+C
+C
+ 
+C   *** SUBROUTINE TLIFT CALCULATES PART OF THE LIFTED PARCEL VIRTUAL      ***
+C   ***  TEMPERATURE, THE ACTUAL TEMPERATURE AND THE ADIABATIC             ***
+C   ***                   LIQUID WATER CONTENT                             ***
+C
+ 
+cjyg1
+c make sure that "Cloud base" seen by TLIFT is actually the 
+c fisrt level where adiabatic ascent is saturated 
+       IF (PLCL .GT. P(ICB)) THEN
+c sb        CALL TLIFT(P,T,RR,RS,GZ,PLCL,ICB,TVP,TP,CLW,ND,NL)
+        CALL TLIFT(P,T,RR,RS,GZ,PLCL,ICB,NK,TVP,TP,CLW,ND,NL
+     :            ,DTVPDT1,DTVPDQ1)
+       ELSE
+c sb        CALL TLIFT(P,T,RR,RS,GZ,PLCL,ICB+1,TVP,TP,CLW,ND,NL)
+        CALL TLIFT(P,T,RR,RS,GZ,PLCL,ICB+1,NK,TVP,TP,CLW,ND,NL
+     :            ,DTVPDT1,DTVPDQ1)
+       ENDIF
+cjyg2
+ 
+******************************************************************************
+****     SORTIE DE LA TEMPERATURE DE L ASCENDANCE NON DILUE
+******************************************************************************
+        do i=1,ND
+        TPS(i)=TP(i)
+        enddo
+ 
+ 
+******************************************************************************
+ 
+C
+C   ***  SET THE PRECIPITATION EFFICIENCIES AND THE FRACTION OF   ***
+C   ***          PRECIPITATION FALLING OUTSIDE OF CLOUD           ***
+C   ***      THESE MAY BE FUNCTIONS OF TP(I), P(I) AND CLW(I)     ***
+C
+      DO 55 I=1,NL
+         PDEN=PTCRIT-PBCRIT
+c
+cjyg
+ccc         EP(I)=(P(ICB)-P(I)-PBCRIT)/PDEN
+c sb         EP(I)=(PLCL-P(I)-PBCRIT)/PDEN
+         EP(I)=(PLCL-P(I)-PBCRIT)/PDEN * EPMAX ! sb
+c
+         EP(I)=AMAX1(EP(I),0.0)
+c sb         EP(I)=AMIN1(EP(I),1.0)
+         EP(I)=AMIN1(EP(I),EPMAX) ! sb
+         SIGP(I)=SPFAC
+C
+C   ***       CALCULATE VIRTUAL TEMPERATURE AND LIFTED PARCEL     ***
+C   ***                    VIRTUAL TEMPERATURE                    ***
+C
+         TV(I)=T(I)*(1.+RR(I)/EPS-RR(I))
+Ccd1
+C    . Keep all liquid water in lifted parcel (-> adiabatic CAPE)
+C
+ccc    TVP(I)=TVP(I)-TP(I)*(RR(1)-EP(I)*CLW(I))
+c!!! sb         TVP(I)=TVP(I)-TP(I)*RR(1) ! calcule dans tlift
+Ccd2
+C
+C   ***       Calculate first estimate of buoyancy
+C
+         BUOY(I) = TVP(I) - TV(I)
+   55 CONTINUE
+C
+C   ***   Set Cloud Base Buoyancy at (Plcl+DPbase) level buoyancy
+C
+      DPBASE = -40.   !That is 400m above LCL
+      PBASE = PLCL + DPBASE
+      TVPBASE = TVP(ICB  )*(PBASE -P(ICB+1))/(P(ICB)-P(ICB+1))
+     $         +TVP(ICB+1)*(P(ICB)-PBASE   )/(P(ICB)-P(ICB+1))
+      TVBASE = TV(ICB  )*(PBASE -P(ICB+1))/(P(ICB)-P(ICB+1))
+     $        +TV(ICB+1)*(P(ICB)-PBASE   )/(P(ICB)-P(ICB+1))
+C
+      BUOYBASE = TVPBASE - TVBASE
+C
+CC       Set buoyancy = BUOYBASE for all levels below BASE.
+CC       For safety, set : BUOY(ICB) = BUOYBASE
+      DO I = ICB,NL
+        IF (P(I) .GE. PBASE) THEN
+          BUOY(I) = BUOYBASE
+        ENDIF
+      ENDDO
+      BUOY(ICB) = BUOYBASE
+C
+c sb3d      print *,'buoybase,tvp_tv,tvpbase,tvbase,pbase,plcl'
+c sb3d     $,        buoybase,tvp(icb)-tv(icb),tvpbase,tvbase,pbase,plcl
+c sb3d      print *,'TVP ',(tvp(i),i=1,nl)
+c sb3d      print *,'TV ',(tv(i),i=1,nl)
+c sb3d      print *, 'P ',(p(i),i=1,nl)
+c sb3d      print *,'ICB ',icb
+C
+C   ***   MAKE SURE THAT COLUMN IS DRY ADIABATIC BETWEEN THE SURFACE  ***
+C   ***    AND CLOUD BASE, AND THAT LIFTED AIR IS POSITIVELY BUOYANT  ***
+C   ***                         AT CLOUD BASE                         ***
+C   ***       IF NOT, RETURN TO CALLING PROGRAM AFTER RESETTING       ***
+C   ***                        SIG(I) AND W0(I)                       ***
+C
+Cjyg
+CCC      TDIF=TVP(ICB)-TV(ICB)
+      TDIF = BUOY(ICB)
+      ATH1=TH(1)
+Cjyg
+CCC      ATH=TH(ICB-1)-1.0
+      ATH=TH(ICB-1)-5.0
+c      ATH=0.                          ! ajout sb
+c      IF (ICB.GT.1) ATH=TH(ICB-1)-5.0 ! modif sb
+      IF(TDIF.LT.DTCRIT.OR.ATH.GT.ATH1)THEN
+         DO 60 I=1,NL
+            SIG(I)=BETA*SIG(I)-2.*ALPHA*TDIF*TDIF
+            SIG(I)=AMAX1(SIG(I),0.0)
+            W0(I)=BETA*W0(I)
+   60    CONTINUE
+         IFLAG=0
+         RETURN
+      END IF
+C
+ 
+ 
+C   ***  IF THIS POINT IS REACHED, MOIST CONVECTIVE ADJUSTMENT IS NECESSARY ***
+C   ***        NOW INITIALIZE VARIOUS ARRAYS USED IN THE COMPUTATIONS       ***
+C
+      DO 70 I=1,NL
+         HP(I)=H(I)
+         WT(I)=0.001
+         RP(I)=RR(I)
+         UP(I)=U(I)
+         VP(I)=V(I)
+         DO 71 J=1,NTRA
+          TRAP(I,J)=TRA(I,J)
+   71    CONTINUE
+         NENT(I)=0
+         WATER(I)=0.0
+         EVAP(I)=0.0
+         B(I)=0.0
+         MP(I)=0.0
+         M(I)=0.0
+         LV(I)=ALV0-CPVMCL*(T(I)-273.15)
+         LVCP(I)=LV(I)/CPN(I)
+         DO 70 J=1,NL
+            QENT(I,J)=RR(J)
+            ELIJ(I,J)=0.0
+            MENT(I,J)=0.0
+            SIJ(I,J)=0.0
+          UENT(I,J)=U(J)
+          VENT(I,J)=V(J)
+          DO 70 K=1,NTRA
+           TRAENT(I,J,K)=TRA(J,K)
+   70 CONTINUE
+ 
+      DELTI=1.0/DELT
+C
+C  ***  FIND THE FIRST MODEL LEVEL (INB) ABOVE THE PARCEL'S       ***
+C  ***                LEVEL OF NEUTRAL BUOYANCY                   ***
+C
+      INB=NL-1
+      DO 80 I=ICB,NL-1
+Cjyg
+CCC         IF((TVP(I)-TV(I)).LT.DTCRIT)THEN
+         IF(BUOY(I).LT.DTOVSH)THEN
+            INB=MIN(INB,I)
+         END IF
+   80 CONTINUE
+ 
+ 
+ 
+ 
+C
+C   ***          RESET SIG(I) AND W0(I) FOR I>INB AND I<ICB       ***
+C
+      IF(INB.LT.(NL-1))THEN
+         DO 85 I=INB+1,NL-1
+Cjyg
+CCC            SIG(I)=BETA*SIG(I)-2.0E-4*ALPHA*(TV(INB)-TVP(INB))*
+CCC     1              ABS(TV(INB)-TVP(INB))
+            SIG(I)=BETA*SIG(I)+2.*ALPHA*BUOY(INB)*
+     1              ABS(BUOY(INB))
+            SIG(I)=AMAX1(SIG(I),0.0)
+            W0(I)=BETA*W0(I)
+   85    CONTINUE
+      END IF
+      DO 87 I=1,ICB
+Cjyg
+CCC         SIG(I)=BETA*SIG(I)-2.0E-4*ALPHA*(TV(ICB)-TVP(ICB))*
+CCC     1           (TV(ICB)-TVP(ICB))
+         SIG(I)=BETA*SIG(I)-2.*ALPHA*BUOY(ICB)*BUOY(ICB)
+         SIG(I)=AMAX1(SIG(I),0.0)
+         W0(I)=BETA*W0(I)
+   87 CONTINUE
+C
+C   ***    RESET FRACTIONAL AREAS OF UPDRAFTS AND W0 AT INITIAL TIME    ***
+C   ***           AND AFTER 10 TIME STEPS OF NO CONVECTION              ***
+C
+ 
+      IF(SIG(ND).LT.1.5.OR.SIG(ND).GT.12.0)THEN
+         DO 90 I=1,NL-1
+            SIG(I)=0.0
+            W0(I)=0.0
+   90    CONTINUE
+      END IF
+C
+C   ***   CALCULATE LIQUID WATER STATIC ENERGY OF LIFTED PARCEL   ***
+C
+      DO 95 I=ICB,INB
+         HP(I)=H(1)+(LV(I)+(CPD-CPV)*T(I))*EP(I)*CLW(I)
+   95 CONTINUE
+C
+C   ***  CALCULATE CONVECTIVE AVAILABLE POTENTIAL ENERGY (CAPE),  ***
+C   ***     VERTICAL VELOCITY (W), FRACTIONAL AREA COVERED BY     ***
+C   ***     UNDILUTE UPDRAFT (SIG),  AND UPDRAFT MASS FLUX (M)    ***
+C
+      CAPE=0.0
+C
+      DO 98 I=ICB+1,INB
+Cjyg1
+CCC         CAPE=CAPE+RD*(TVP(I-1)-TV(I-1))*(PH(I-1)-PH(I))/P(I-1)
+CCC         DCAPE=RD*BUOY(I-1)*(PH(I-1)-PH(I))/P(I-1)
+CCC         DLNP=(PH(I-1)-PH(I))/P(I-1)
+C          The interval on which CAPE is computed starts at PBASE :
+         DELTAP = MIN(PBASE,PH(I-1))-MIN(PBASE,PH(I))
+         CAPE=CAPE+RD*BUOY(I-1)*DELTAP/P(I-1)
+         DCAPE=RD*BUOY(I-1)*DELTAP/P(I-1)
+         DLNP=DELTAP/P(I-1)
+Cjyg2
+c sb3d         print *,'buoy,dlnp,dcape,cape',buoy(i-1),dlnp,dcape,cape
+         CAPE=AMAX1(0.0,CAPE)
+C
+         SIGOLD=SIG(I)
+         DTMIN=100.0
+         DO 97 J=ICB,I-1
+Cjyg
+CCC            DTMIN=AMIN1(DTMIN,(TVP(J)-TV(J)))
+            DTMIN=AMIN1(DTMIN,BUOY(J))
+   97    CONTINUE
+c sb3d     print *, 'DTMIN, BETA, ALPHA, SIG = ',DTMIN,BETA,ALPHA,SIG(I)
+         SIG(I)=BETA*SIG(I)+ALPHA*DTMIN*ABS(DTMIN)
+         SIG(I)=AMAX1(SIG(I),0.0)
+         SIG(I)=AMIN1(SIG(I),0.01)
+         FAC=AMIN1(((DTCRIT-DTMIN)/DTCRIT),1.0)
+Cjyg
+CC    Essais de reduction de la vitesse
+CC         FAC = FAC*.5
+C
+         W=(1.-BETA)*FAC*SQRT(CAPE)+BETA*W0(I)
+         AMU=0.5*(SIG(I)+SIGOLD)*W
+         M(I)=AMU*0.007*P(I)*(PH(I)-PH(I+1))/TV(I)
+         W0(I)=W
+   98 CONTINUE
+      W0(ICB)=0.5*W0(ICB+1)
+      M(ICB)=0.5*M(ICB+1)*(PH(ICB)-PH(ICB+1))/(PH(ICB+1)-PH(ICB+2))
+      SIG(ICB)=SIG(ICB+1)
+      SIG(ICB-1)=SIG(ICB)
+cjyg1
+c sb3d      print *, 'Cloud base, c. top, CAPE',ICB,INB,cape
+c sb3d      print *, 'SIG ',(sig(i),i=1,inb)
+c sb3d      print *, 'W ',(w0(i),i=1,inb)
+c sb3d      print *, 'M ',(m(i), i=1,inb)
+c sb3d      print *, 'Dt1 ',(tvp(i)-tv(i),i=1,inb)
+c sb3d      print *, 'Dt_vrai ',(buoy(i),i=1,inb)
+Cjyg2
+C
+C   ***  CALCULATE ENTRAINED AIR MASS FLUX (MENT), TOTAL WATER MIXING  ***
+C   ***     RATIO (QENT), TOTAL CONDENSED WATER (ELIJ), AND MIXING     ***
+C   ***                        FRACTION (SIJ)                          ***
+C
+ 
+ 
+      DO 170 I=ICB,INB
+         RTI=RR(1)-EP(I)*CLW(I)
+         DO 160 J=ICB-1,INB
+            BF2=1.+LV(J)*LV(J)*RS(J)/(RV*T(J)*T(J)*CPD)
+            ANUM=H(J)-HP(I)+(CPV-CPD)*T(J)*(RTI-RR(J))
+            DENOM=H(I)-HP(I)+(CPD-CPV)*(RR(I)-RTI)*T(J)
+            DEI=DENOM
+            IF(ABS(DEI).LT.0.01)DEI=0.01
+            SIJ(I,J)=ANUM/DEI
+            SIJ(I,I)=1.0
+            ALTEM=SIJ(I,J)*RR(I)+(1.-SIJ(I,J))*RTI-RS(J)
+            ALTEM=ALTEM/BF2
+            CWAT=CLW(J)*(1.-EP(J))
+            STEMP=SIJ(I,J)
+            IF((STEMP.LT.0.0.OR.STEMP.GT.1.0.OR.
+     1      ALTEM.GT.CWAT).AND.J.GT.I)THEN
+            ANUM=ANUM-LV(J)*(RTI-RS(J)-CWAT*BF2)
+            DENOM=DENOM+LV(J)*(RR(I)-RTI)
+            IF(ABS(DENOM).LT.0.01)DENOM=0.01
+            SIJ(I,J)=ANUM/DENOM
+            ALTEM=SIJ(I,J)*RR(I)+(1.-SIJ(I,J))*RTI-RS(J)
+            ALTEM=ALTEM-(BF2-1.)*CWAT
+            END IF
+ 
+ 
+            IF(SIJ(I,J).GT.0.0.AND.SIJ(I,J).LT.0.95)THEN
+               QENT(I,J)=SIJ(I,J)*RR(I)+(1.-SIJ(I,J))*RTI
+               UENT(I,J)=SIJ(I,J)*U(I)+(1.-SIJ(I,J))*U(NK)
+               VENT(I,J)=SIJ(I,J)*V(I)+(1.-SIJ(I,J))*V(NK)
+               DO K=1,NTRA
+               TRAENT(I,J,K)=SIJ(I,J)*TRA(I,K)+(1.-SIJ(I,J))*
+     1         TRA(NK,K)
+               END DO
+               ELIJ(I,J)=ALTEM
+               ELIJ(I,J)=AMAX1(0.0,ELIJ(I,J))
+               MENT(I,J)=M(I)/(1.-SIJ(I,J))
+               NENT(I)=NENT(I)+1
+            END IF
+            SIJ(I,J)=AMAX1(0.0,SIJ(I,J))
+            SIJ(I,J)=AMIN1(1.0,SIJ(I,J))
+  160    CONTINUE
+C
+C   ***   IF NO AIR CAN ENTRAIN AT LEVEL I ASSUME THAT UPDRAFT DETRAINS  ***
+C   ***   AT THAT LEVEL AND CALCULATE DETRAINED AIR FLUX AND PROPERTIES  ***
+C
+         IF(NENT(I).EQ.0)THEN
+            MENT(I,I)=M(I)
+            QENT(I,I)=RR(NK)-EP(I)*CLW(I)
+           UENT(I,I)=U(NK)
+           VENT(I,I)=V(NK)
+           DO J=1,NTRA
+            TRAENT(I,I,J)=TRA(NK,J)
+           END DO
+            ELIJ(I,I)=CLW(I)
+            SIJ(I,I)=1.0
+         END IF
+C
+         DO J = ICB-1,INB
+           SIGIJ(I,J) = SIJ(I,J)
+         ENDDO
+C	
+  170 CONTINUE
+C
+C   ***  NORMALIZE ENTRAINED AIR MASS FLUXES TO REPRESENT EQUAL  ***
+C   ***              PROBABILITIES OF MIXING                     ***
+C
+ 
+      DO 200 I=ICB,INB
+      IF(NENT(I).NE.0)THEN
+       QP=RR(1)-EP(I)*CLW(I)
+       ANUM=H(I)-HP(I)-LV(I)*(QP-RS(I))+(CPV-CPD)*T(I)*
+     1    (QP-RR(I))
+       DENOM=H(I)-HP(I)+LV(I)*(RR(I)-QP)+
+     1    (CPD-CPV)*T(I)*(RR(I)-QP)
+       IF(ABS(DENOM).LT.0.01)DENOM=0.01
+       SCRIT=ANUM/DENOM
+       ALT=QP-RS(I)+SCRIT*(RR(I)-QP)
+       IF(SCRIT.LE.0.0.OR.ALT.LE.0.0)SCRIT=1.0
+       SMAX=0.0
+       ASIJ=0.0
+        DO 175 J=INB,ICB-1,-1
+        IF(SIJ(I,J).GT.1.0E-16.AND.SIJ(I,J).LT.0.95)THEN
+         WGH=1.0
+         IF(J.GT.I)THEN
+          SJMAX=AMAX1(SIJ(I,J+1),SMAX)
+          SJMAX=AMIN1(SJMAX,SCRIT)
+          SMAX=AMAX1(SIJ(I,J),SMAX)
+          SJMIN=AMAX1(SIJ(I,J-1),SMAX)
+          SJMIN=AMIN1(SJMIN,SCRIT)
+          IF(SIJ(I,J).LT.(SMAX-1.0E-16))WGH=0.0
+          SMID=AMIN1(SIJ(I,J),SCRIT)
+         ELSE
+          SJMAX=AMAX1(SIJ(I,J+1),SCRIT)
+          SMID=AMAX1(SIJ(I,J),SCRIT)
+          SJMIN=0.0
+          IF(J.GT.1)SJMIN=SIJ(I,J-1)
+          SJMIN=AMAX1(SJMIN,SCRIT)
+         END IF
+         DELP=ABS(SJMAX-SMID)
+         DELM=ABS(SJMIN-SMID)
+         ASIJ=ASIJ+WGH*(DELP+DELM)
+         MENT(I,J)=MENT(I,J)*(DELP+DELM)*WGH
+        END IF
+  175       CONTINUE
+       ASIJ=AMAX1(1.0E-16,ASIJ)
+       ASIJ=1.0/ASIJ
+       DO 180 J=ICB-1,INB
+        MENT(I,J)=MENT(I,J)*ASIJ
+  180    CONTINUE
+       ASUM=0.0
+       BSUM=0.0
+       DO 190 J=ICB-1,INB
+        ASUM=ASUM+MENT(I,J)
+        MENT(I,J)=MENT(I,J)*SIG(J)
+        BSUM=BSUM+MENT(I,J)
+  190       CONTINUE
+       BSUM=AMAX1(BSUM,1.0E-16)
+       BSUM=1.0/BSUM
+       DO 195 J=ICB-1,INB
+        MENT(I,J)=MENT(I,J)*ASUM*BSUM	
+  195       CONTINUE
+       CSUM=0.0
+       DO 197 J=ICB-1,INB
+        CSUM=CSUM+MENT(I,J)
+  197       CONTINUE
+ 
+       IF(CSUM.LT.M(I))THEN
+        NENT(I)=0
+        MENT(I,I)=M(I)
+        QENT(I,I)=RR(1)-EP(I)*CLW(I)
+          UENT(I,I)=U(NK)
+          VENT(I,I)=V(NK)
+          DO J=1,NTRA
+           TRAENT(I,I,J)=TRA(NK,J)
+          END DO
+        ELIJ(I,I)=CLW(I)
+        SIJ(I,I)=1.0
+       END IF
+      END IF
+  200      CONTINUE
+ 
+ 
+ 
+***************************************************************
+**       CALCUL DES MENTS(I,J) ET DES QENTS(I,J)
+**************************************************************
+ 
+         DO im=1,nd
+         do jm=1,nd
+ 
+         QENTS(im,jm)=QENT(im,jm)
+         MENTS(im,jm)=MENT(im,jm)
+         enddo
+         enddo
+ 
+***********************************************************
+ 
+ 
+ 
+C
+C   ***  CHECK WHETHER EP(INB)=0, IF SO, SKIP PRECIPITATING    ***
+C   ***             DOWNDRAFT CALCULATION                      ***
+C
+        IF(EP(INB).LT.0.0001)GOTO 405
+C
+C   ***  INTEGRATE LIQUID WATER EQUATION TO FIND CONDENSED WATER   ***
+C   ***                AND CONDENSED WATER FLUX                    ***
+C
+        WFLUX=0.0
+        TINV=1./3.
+C
+C    ***                    BEGIN DOWNDRAFT LOOP                    ***
+C
+        DO 400 I=INB,1,-1
+C
+C    ***              CALCULATE DETRAINED PRECIPITATION             ***
+C
+ 
+ 
+        WDTRAIN=10.0*EP(I)*M(I)*CLW(I)
+        IF(I.GT.1)THEN
+         DO 320 J=1,I-1
+       AWAT=ELIJ(J,I)-(1.-EP(I))*CLW(I)
+       AWAT=AMAX1(AWAT,0.0)
+  320    WDTRAIN=WDTRAIN+10.0*AWAT*MENT(J,I)
+        END IF
+C
+C    ***    FIND RAIN WATER AND EVAPORATION USING PROVISIONAL   ***
+C    ***              ESTIMATES OF RP(I)AND RP(I-1)             ***
+C
+ 
+ 
+        WT(I)=45.0
+      IF(I.LT.INB)THEN
+       RP(I)=RP(I+1)+(CPD*(T(I+1)-T(I))+GZ(I+1)-GZ(I))/LV(I)
+       RP(I)=0.5*(RP(I)+RR(I))
+      END IF
+      RP(I)=AMAX1(RP(I),0.0)
+      RP(I)=AMIN1(RP(I),RS(I))
+      RP(INB)=RR(INB)
+      IF(I.EQ.1)THEN
+       AFAC=P(1)*(RS(1)-RP(1))/(1.0E4+2000.0*P(1)*RS(1))
+      ELSE
+       RP(I-1)=RP(I)+(CPD*(T(I)-T(I-1))+GZ(I)-GZ(I-1))/LV(I)
+       RP(I-1)=0.5*(RP(I-1)+RR(I-1))
+       RP(I-1)=AMIN1(RP(I-1),RS(I-1))
+       RP(I-1)=AMAX1(RP(I-1),0.0)
+       AFAC1=P(I)*(RS(I)-RP(I))/(1.0E4+2000.0*P(I)*RS(I))
+       AFAC2=P(I-1)*(RS(I-1)-RP(I-1))/(1.0E4+
+     1    2000.0*P(I-1)*RS(I-1))
+       AFAC=0.5*(AFAC1+AFAC2)
+      END IF
+      IF(I.EQ.INB)AFAC=0.0
+        AFAC=AMAX1(AFAC,0.0)
+        BFAC=1./(SIGD*WT(I))
+C
+Cjyg1
+CCC        SIGT=1.0
+CCC        IF(I.GE.ICB)SIGT=SIGP(I)
+C Prise en compte de la variation progressive de SIGT dans
+C les couches ICB et ICB-1:
+C 	Pour PLCL<PH(I+1), PR1=0 & PR2=1
+C 	Pour PLCL>PH(I),   PR1=1 & PR2=0
+C 	Pour PH(I+1)<PLCL<PH(I), PR1 est la proportion a cheval
+C    sur le nuage, et PR2 est la proportion sous la base du
+C    nuage.
+         PR1 =(PLCL-PH(I+1))/(PH(I)-PH(I+1))
+         PR1 = MAX(0.,MIN(1.,PR1))
+         PR2 = (PH(I)-PLCL)/(PH(I)-PH(I+1))
+         PR2 = MAX(0.,MIN(1.,PR2))
+         SIGT = SIGP(I)*PR1 + PR2
+c sb3d         print *,'i,sigt,pr1,pr2', i,sigt,pr1,pr2
+Cjyg2
+C
+        B6=BFAC*50.*SIGD*(PH(I)-PH(I+1))*SIGT*AFAC
+        C6=WATER(I+1)+BFAC*WDTRAIN-50.*SIGD*BFAC*
+     1   (PH(I)-PH(I+1))*EVAP(I+1)
+      IF(C6.GT.0.0)THEN
+         REVAP=0.5*(-B6+SQRT(B6*B6+4.*C6))
+         EVAP(I)=SIGT*AFAC*REVAP
+         WATER(I)=REVAP*REVAP
+      ELSE
+       EVAP(I)=-EVAP(I+1)+0.02*(WDTRAIN+SIGD*WT(I)*
+     1    WATER(I+1))/(SIGD*(PH(I)-PH(I+1)))
+      END IF
+ 
+ 
+C
+C    ***  CALCULATE PRECIPITATING DOWNDRAFT MASS FLUX UNDER     ***
+C    ***              HYDROSTATIC APPROXIMATION                 ***
+C
+        IF(I.EQ.1)GOTO 360
+      TEVAP=AMAX1(0.0,EVAP(I))
+      DELTH=AMAX1(0.001,(TH(I)-TH(I-1)))
+      MP(I)=10.*LVCP(I)*SIGD*TEVAP*(P(I-1)-P(I))/DELTH
+C
+C    ***           IF HYDROSTATIC ASSUMPTION FAILS,             ***
+C    ***   SOLVE CUBIC DIFFERENCE EQUATION FOR DOWNDRAFT THETA  ***
+C    ***  AND MASS FLUX FROM TWO SIMULTANEOUS DIFFERENTIAL EQNS ***
+C
+      AMFAC=SIGD*SIGD*70.0*PH(I)*(P(I-1)-P(I))*
+     1   (TH(I)-TH(I-1))/(TV(I)*TH(I))
+      AMP2=ABS(MP(I+1)*MP(I+1)-MP(I)*MP(I))
+      IF(AMP2.GT.(0.1*AMFAC))THEN
+         XF=100.0*SIGD*SIGD*SIGD*(PH(I)-PH(I+1))
+         TF=B(I)-5.0*(TH(I)-TH(I-1))*T(I)/(LVCP(I)*SIGD*TH(I))
+         AF=XF*TF+MP(I+1)*MP(I+1)*TINV
+         BF=2.*(TINV*MP(I+1))**3+TINV*MP(I+1)*XF*TF+50.*
+     1    (P(I-1)-P(I))*XF*TEVAP
+         FAC2=1.0
+         IF(BF.LT.0.0)FAC2=-1.0
+         BF=ABS(BF)
+         UR=0.25*BF*BF-AF*AF*AF*TINV*TINV*TINV
+         IF(UR.GE.0.0)THEN
+          SRU=SQRT(UR)
+          FAC=1.0
+          IF((0.5*BF-SRU).LT.0.0)FAC=-1.0
+          MP(I)=MP(I+1)*TINV+(0.5*BF+SRU)**TINV+
+     1     FAC*(ABS(0.5*BF-SRU))**TINV
+         ELSE
+          D=ATAN(2.*SQRT(-UR)/(BF+1.0E-28))
+          IF(FAC2.LT.0.0)D=3.14159-D
+          MP(I)=MP(I+1)*TINV+2.*SQRT(AF*TINV)*COS(D*TINV)
+         END IF
+         MP(I)=AMAX1(0.0,MP(I))
+         B(I-1)=B(I)+100.0*(P(I-1)-P(I))*TEVAP/(MP(I)+SIGD*0.1)-
+     1    10.0*(TH(I)-TH(I-1))*T(I)/(LVCP(I)*SIGD*TH(I))
+         B(I-1)=AMAX1(B(I-1),0.0)
+      END IF
+ 
+ 
+C
+C   ***         LIMIT MAGNITUDE OF MP(I) TO MEET CFL CONDITION      ***
+C
+      AMPMAX=2.0*(PH(I)-PH(I+1))*DELTI
+      AMP2=2.0*(PH(I-1)-PH(I))*DELTI
+      AMPMAX=AMIN1(AMPMAX,AMP2)
+      MP(I)=AMIN1(MP(I),AMPMAX)
+C
+C    ***      FORCE MP TO DECREASE LINEARLY TO ZERO                 ***
+C    ***       BETWEEN CLOUD BASE AND THE SURFACE                   ***
+C
+          IF(P(I).GT.P(ICB))THEN
+           MP(I)=MP(ICB)*(P(1)-P(I))/(P(1)-P(ICB))
+          END IF
+  360   CONTINUE
+C
+C    ***       FIND MIXING RATIO OF PRECIPITATING DOWNDRAFT     ***
+C
+        IF(I.EQ.INB)GOTO 400
+      RP(I)=RR(I)
+        IF(MP(I).GT.MP(I+1))THEN
+        RP(I)=RP(I+1)*MP(I+1)+RR(I)*(MP(I)-MP(I+1))+
+     1       5.*SIGD*(PH(I)-PH(I+1))*(EVAP(I+1)+EVAP(I))
+        RP(I)=RP(I)/MP(I)
+          UP(I)=UP(I+1)*MP(I+1)+U(I)*(MP(I)-MP(I+1))
+         UP(I)=UP(I)/MP(I)
+          VP(I)=VP(I+1)*MP(I+1)+V(I)*(MP(I)-MP(I+1))
+         VP(I)=VP(I)/MP(I)
+          DO J=1,NTRA
+           TRAP(I,J)=TRAP(I+1,J)*MP(I+1)+
+     s     TRAP(I,J)*(MP(I)-MP(I+1))
+           TRAP(I,J)=TRAP(I,J)/MP(I)
+          END DO
+        ELSE
+        IF(MP(I+1).GT.1.0E-16)THEN
+           RP(I)=RP(I+1)+5.0*SIGD*(PH(I)-PH(I+1))*(EVAP(I+1)+
+     1      EVAP(I))/MP(I+1)
+            UP(I)=UP(I+1)
+            VP(I)=VP(I+1)
+            DO J=1,NTRA
+             TRAP(I,J)=TRAP(I+1,J)
+            END DO
+        END IF
+        END IF
+      RP(I)=AMIN1(RP(I),RS(I))
+      RP(I)=AMAX1(RP(I),0.0)
+  400   CONTINUE
+C
+C   ***  CALCULATE SURFACE PRECIPITATION IN MM/DAY     ***
+C
+        PRECIP=WT(1)*SIGD*WATER(1)*8640.0
+  405   CONTINUE
+C
+C   ***  CALCULATE TENDENCIES OF LOWEST LEVEL POTENTIAL TEMPERATURE  ***
+C   ***                      AND MIXING RATIO                        ***
+C
+      DPINV=1.0/(PH(1)-PH(2))
+        AM=0.0
+        DO 410 K=2,INB
+  410   AM=AM+M(K)
+      IF((0.1*DPINV*AM).GE.DELTI)IFLAG=4
+      FT(1)=0.1*DPINV*AM*(T(2)-T(1)+(GZ(2)-GZ(1))/CPN(1))
+        FT(1)=FT(1)-0.5*LVCP(1)*SIGD*(EVAP(1)+EVAP(2))
+        FT(1)=FT(1)-0.09*SIGD*MP(2)*T(1)*B(1)*DPINV
+      FT(1)=FT(1)+0.01*SIGD*WT(1)*(CL-CPD)*WATER(2)*(T(2)-
+     1   T(1))*DPINV/CPN(1)
+        FR(1)=0.1*MP(2)*(RP(2)-RR(1))*
+     1    DPINV+SIGD*0.5*(EVAP(1)+EVAP(2))
+        FR(1)=FR(1)+0.1*AM*(RR(2)-RR(1))*DPINV
+        FU(1)=FU(1)+0.1*DPINV*(MP(2)*(UP(2)-U(1))+AM*(U(2)-U(1)))
+        FV(1)=FV(1)+0.1*DPINV*(MP(2)*(VP(2)-V(1))+AM*(V(2)-V(1)))
+        DO J=1,NTRA
+         FTRA(1,J)=FTRA(1,J)+0.1*DPINV*(MP(2)*(TRAP(2,J)-TRA(1,J))+
+     1    AM*(TRA(2,J)-TRA(1,J)))
+        END DO
+        AMDE=0.0
+        DO 415 J=2,INB
+         FR(1)=FR(1)+0.1*DPINV*MENT(J,1)*(QENT(J,1)-RR(1))
+         FU(1)=FU(1)+0.1*DPINV*MENT(J,1)*(UENT(J,1)-U(1))
+         FV(1)=FV(1)+0.1*DPINV*MENT(J,1)*(VENT(J,1)-V(1))
+         DO K=1,NTRA
+          FTRA(1,K)=FTRA(1,K)+0.1*DPINV*MENT(J,1)*(TRAENT(J,1,K)-
+     1     TRA(1,K))
+         END DO
+  415      CONTINUE
+C
+C   ***  CALCULATE TENDENCIES OF POTENTIAL TEMPERATURE AND MIXING RATIO  ***
+C   ***               AT LEVELS ABOVE THE LOWEST LEVEL                   ***
+C
+C   ***  FIRST FIND THE NET SATURATED UPDRAFT AND DOWNDRAFT MASS FLUXES  ***
+C   ***                      THROUGH EACH LEVEL                          ***
+C
+ 
+ 
+        DO 500 I=2,INB
+        DPINV=1.0/(PH(I)-PH(I+1))
+      CPINV=1.0/CPN(I)
+        AMP1=0.0
+        DO 440 K=I+1,INB+1
+  440   AMP1=AMP1+M(K)
+        DO 450 K=1,I
+        DO 450 J=I+1,INB+1
+         AMP1=AMP1+MENT(K,J)
+  450   CONTINUE
+      IF((0.1*DPINV*AMP1).GE.DELTI)IFLAG=4
+        AD=0.0
+        DO 470 K=1,I-1
+        DO 470 J=I,INB
+  470   AD=AD+MENT(J,K)
+      FT(I)=0.1*DPINV*(AMP1*(T(I+1)-T(I)+(GZ(I+1)-GZ(I))*
+     1   CPINV)-AD*(T(I)-T(I-1)+(GZ(I)-GZ(I-1))*CPINV))
+     2   -0.5*SIGD*LVCP(I)*(EVAP(I)+EVAP(I+1))
+      RAT=CPN(I-1)*CPINV
+        FT(I)=FT(I)-0.09*SIGD*(MP(I+1)*T(I)*
+     1    B(I)-MP(I)*T(I-1)*RAT*B(I-1))*DPINV
+      FT(I)=FT(I)+0.1*DPINV*MENT(I,I)*(HP(I)-H(I)+
+     1    T(I)*(CPV-CPD)*(RR(I)-QENT(I,I)))*CPINV
+      FT(I)=FT(I)+0.01*SIGD*WT(I)*(CL-CPD)*WATER(I+1)*
+     1    (T(I+1)-T(I))*DPINV*CPINV
+        FR(I)=0.1*DPINV*(AMP1*(RR(I+1)-RR(I))-
+     1    AD*(RR(I)-RR(I-1)))
+        FU(I)=FU(I)+0.1*DPINV*(AMP1*(U(I+1)-U(I))-
+     1    AD*(U(I)-U(I-1)))
+        FV(I)=FV(I)+0.1*DPINV*(AMP1*(V(I+1)-V(I))-
+     1    AD*(V(I)-V(I-1)))
+        DO K=1,NTRA
+         FTRA(I,K)=FTRA(I,K)+0.1*DPINV*(AMP1*(TRA(I+1,K)-
+     1    TRA(I,K))-AD*(TRA(I,K)-TRA(I-1,K)))
+        END DO
+        DO 480 K=1,I-1
+       AWAT=ELIJ(K,I)-(1.-EP(I))*CLW(I)
+       AWAT=AMAX1(AWAT,0.0)
+         FR(I)=FR(I)+0.1*DPINV*MENT(K,I)*(QENT(K,I)-AWAT
+     1    -RR(I))
+         FU(I)=FU(I)+0.1*DPINV*MENT(K,I)*(UENT(K,I)-U(I))
+         FV(I)=FV(I)+0.1*DPINV*MENT(K,I)*(VENT(K,I)-V(I))
+         DO J=1,NTRA
+          FTRA(I,J)=FTRA(I,J)+0.1*DPINV*MENT(K,I)*(TRAENT(K,I,J)-
+     1     TRA(I,J))
+         END DO
+  480   CONTINUE
+      DO 490 K=I,INB
+       FR(I)=FR(I)+0.1*DPINV*MENT(K,I)*(QENT(K,I)-RR(I))
+         FU(I)=FU(I)+0.1*DPINV*MENT(K,I)*(UENT(K,I)-U(I))
+         FV(I)=FV(I)+0.1*DPINV*MENT(K,I)*(VENT(K,I)-V(I))
+         DO J=1,NTRA
+          FTRA(I,J)=FTRA(I,J)+0.1*DPINV*MENT(K,I)*(TRAENT(K,I,J)-
+     1     TRA(I,J))
+         END DO
+  490      CONTINUE
+        FR(I)=FR(I)+0.5*SIGD*(EVAP(I)+EVAP(I+1))+0.1*(MP(I+1)*
+     1    (RP(I+1)-RR(I))-MP(I)*(RP(I)-RR(I-1)))*DPINV
+        FU(I)=FU(I)+0.1*(MP(I+1)*(UP(I+1)-U(I))-MP(I)*
+     1    (UP(I)-U(I-1)))*DPINV
+        FV(I)=FV(I)+0.1*(MP(I+1)*(VP(I+1)-V(I))-MP(I)*
+     1    (VP(I)-V(I-1)))*DPINV
+        DO J=1,NTRA
+         FTRA(I,J)=FTRA(I,J)+0.1*DPINV*(MP(I+1)*(TRAP(I+1,J)-TRA(I,J))-
+     1    MP(I)*(TRAP(I,J)-TRAP(I-1,J)))
+        END DO
+  500   CONTINUE
+ 
+ 
+ 
+C
+C   ***   MOVE THE DETRAINMENT AT LEVEL INB DOWN TO LEVEL INB-1   ***
+C   ***        IN SUCH A WAY AS TO PRESERVE THE VERTICALLY        ***
+C   ***          INTEGRATED ENTHALPY AND WATER TENDENCIES         ***
+C
+      AX=0.1*MENT(INB,INB)*(HP(INB)-H(INB)+T(INB)*
+     1    (CPV-CPD)*(RR(INB)-QENT(INB,INB)))/(CPN(INB)*
+     2    (PH(INB)-PH(INB+1)))
+      FT(INB)=FT(INB)-AX
+      FT(INB-1)=FT(INB-1)+AX*CPN(INB)*(PH(INB)-PH(INB+1))/
+     1    (CPN(INB-1)*(PH(INB-1)-PH(INB)))
+      BX=0.1*MENT(INB,INB)*(QENT(INB,INB)-RR(INB))/
+     1    (PH(INB)-PH(INB+1))
+      FR(INB)=FR(INB)-BX
+      FR(INB-1)=FR(INB-1)+BX*(PH(INB)-PH(INB+1))/
+     1    (PH(INB-1)-PH(INB))
+      CX=0.1*MENT(INB,INB)*(UENT(INB,INB)-U(INB))/
+     1    (PH(INB)-PH(INB+1))
+      FU(INB)=FU(INB)-CX
+      FU(INB-1)=FU(INB-1)+CX*(PH(INB)-PH(INB+1))/
+     1    (PH(INB-1)-PH(INB))
+      DX=0.1*MENT(INB,INB)*(VENT(INB,INB)-V(INB))/
+     1    (PH(INB)-PH(INB+1))
+      FV(INB)=FV(INB)-DX
+      FV(INB-1)=FV(INB-1)+DX*(PH(INB)-PH(INB+1))/
+     1    (PH(INB-1)-PH(INB))
+      DO J=1,NTRA
+      EX=0.1*MENT(INB,INB)*(TRAENT(INB,INB,J)
+     1    -TRA(INB,J))/(PH(INB)-PH(INB+1))
+      FTRA(INB,J)=FTRA(INB,J)-EX
+      FTRA(INB-1,J)=FTRA(INB-1,J)+EX*
+     1     (PH(INB)-PH(INB+1))/(PH(INB-1)-PH(INB))
+      ENDDO   
+C
+C   ***    HOMOGINIZE TENDENCIES BELOW CLOUD BASE    ***
+C
+      ASUM=0.0
+      BSUM=0.0
+      CSUM=0.0
+        DSUM=0.0
+      DO 650 I=1,ICB-1
+       ASUM=ASUM+FT(I)*(PH(I)-PH(I+1))
+         BSUM=BSUM+FR(I)*(LV(I)+(CL-CPD)*(T(I)-T(1)))*
+     1    (PH(I)-PH(I+1))
+       CSUM=CSUM+(LV(I)+(CL-CPD)*(T(I)-T(1)))*(PH(I)-PH(I+1))
+       DSUM=DSUM+T(I)*(PH(I)-PH(I+1))/TH(I)
+  650      CONTINUE
+      DO 700 I=1,ICB-1
+       FT(I)=ASUM*T(I)/(TH(I)*DSUM)
+       FR(I)=BSUM/CSUM
+  700      CONTINUE
+C
+C   ***           RESET COUNTER AND RETURN           ***
+C
+      SIG(ND)=2.0
+c
+c
+      do i = 1, nd
+         upwd(i) = 0.0
+         dnwd(i) = 0.0
+c sb       dnwd0(i) = - mp(i)
+      enddo
+c
+      do i = 1, nl
+       dnwd0(i) = - mp(i)
+      enddo
+      do i = nl+1, nd
+       dnwd0(i) = 0.
+      enddo
+c
+      do i = icb, inb
+         upwd(i) = 0.0
+         dnwd(i) = 0.0
+
+         do k =i, inb
+            up1=0.0
+            dn1=0.0
+            do n = 1, i-1
+               up1 = up1 + ment(n,k)
+               dn1 = dn1 - ment(k,n)
+            enddo
+            upwd(i) = upwd(i)+ m(k) + up1
+            dnwd(i) = dnwd(i) + dn1
+         enddo
+        enddo
+ 
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c        DETERMINATION DE LA VARIATION DE FLUX ASCENDANT ENTRE
+C        DEUX NIVEAU NON DILUE Mike
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+ 
+ 
+c sb      do i=1,ND
+c sb      Mike(i)=M(i)
+c sb      enddo
+ 
+      do i = 1, NL
+       Mike(i) = M(i)
+      enddo
+      do i = NL+1, ND
+       Mike(i) = 0.
+      enddo
+ 
+      do i=1,nd
+      Ma(i)=0
+      enddo
+ 
+c sb      do i=1,nd
+c sb      do j=i,nd
+c sb      Ma(i)=Ma(i)+M(j)
+c sb      enddo
+c sb      enddo
+
+      do i = 1, NL
+      do j = i, NL
+       Ma(i) = Ma(i) + M(j)
+      enddo
+      enddo
+c
+      do i = NL+1, ND
+       Ma(i) = 0.
+      enddo
+c 
+      do i=1,ICB-1
+      Ma(i)=0
+      enddo
+ 
+ 
+ 
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+C        ICB REPRESENTE DE NIVEAU OU SE TROUVE LA
+c        BASE DU NUAGE , ET INB LE TOP DU NUAGE
+cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+ 
+ 
+       do i=1,ND
+       Mke(i)=upwd(i)+dnwd(i)
+       enddo
+c$$$cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c$$$         call writeg1d(1,klev,ma,'ma  ','ma  ')
+c$$$          call writeg1d(1,klev,upwd,'upwd  ','upwd  ')
+c$$$          call writeg1d(1,klev,dnwd,'dnwd  ','dnwd  ')
+c$$$          call writeg1d(1,klev,dnwd0,'dnwd0  ','dnwd0  ')
+c$$$          call writeg1d(1,klev,tvp,'tvp  ','tvp  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,3),'tra3  ','tra3  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,4),'tra4  ','tra4  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,5),'tra5  ','tra5  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,6),'tra6  ','tra6  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,7),'tra7  ','tra7  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,8),'tra8  ','tra8  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,9),'tra9  ','tra9  ')
+c$$$          call writeg1d(1,klev,tra(1:klev,10),'tra10','tra10')
+c$$$          call writeg1d(1,klev,tra(1:klev,11),'tra11','tra11')
+c$$$          call writeg1d(1,klev,tra(1:klev,12),'tra12','tra12')
+c$$$          call writeg1d(1,klev,tra(1:klev,13),'tra13','tra13')
+c$$$          call writeg1d(1,klev,tra(1:klev,14),'tra14','tra14')
+c$$$          call writeg1d(1,klev,tra(1:klev,15),'tra15','tra15')
+c$$$          call writeg1d(1,klev,tra(1:klev,16),'tra16','tra16')
+c$$$          call writeg1d(1,klev,tra(1:klev,17),'tra17','tra17')
+c$$$          call writeg1d(1,klev,tra(1:klev,18),'tra18','tra18')
+c$$$          call writeg1d(1,klev,tra(1:klev,19),'tra19','tra19')
+c$$$          call writeg1d(1,klev,tra(1:klev,20),'tra20','tra20 ')
+c$$$          call writeg1d(1,klev,trap(1:klev,1),'trp1','trp1')
+c$$$          call writeg1d(1,klev,trap(1:klev,2),'trp2','trp2')
+c$$$          call writeg1d(1,klev,trap(1:klev,3),'trp3','trp3')
+c$$$          call writeg1d(1,klev,trap(1:klev,4),'trp4','trp4')
+c$$$          call writeg1d(1,klev,trap(1:klev,5),'trp5','trp5')
+c$$$          call writeg1d(1,klev,trap(1:klev,10),'trp10','trp10')
+c$$$          call writeg1d(1,klev,trap(1:klev,12),'trp12','trp12')
+c$$$          call writeg1d(1,klev,trap(1:klev,15),'trp15','trp15')
+c$$$          call writeg1d(1,klev,trap(1:klev,20),'trp20','trp20')
+c$$$          call writeg1d(1,klev,ftra(1:klev,1),'ftr1  ','ftr1  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,2),'ftr2  ','ftr2  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,3),'ftr3  ','ftr3  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,4),'ftr4  ','ftr4  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,5),'ftr5  ','ftr5  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,6),'ftr6  ','ftr6  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,7),'ftr7  ','ftr7  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,8),'ftr8  ','ftr8  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,9),'ftr9  ','ftr9  ')
+c$$$          call writeg1d(1,klev,ftra(1:klev,10),'ftr10','ftr10')
+c$$$          call writeg1d(1,klev,ftra(1:klev,11),'ftr11','ftr11')
+c$$$          call writeg1d(1,klev,ftra(1:klev,12),'ftr12','ftr12')
+c$$$          call writeg1d(1,klev,ftra(1:klev,13),'ftr13','ftr13')
+c$$$          call writeg1d(1,klev,ftra(1:klev,14),'ftr14','ftr14')
+c$$$          call writeg1d(1,klev,ftra(1:klev,15),'ftr15','ftr15')
+c$$$          call writeg1d(1,klev,ftra(1:klev,16),'ftr16','ftr16')
+c$$$          call writeg1d(1,klev,ftra(1:klev,17),'ftr17','ftr17')
+c$$$          call writeg1d(1,klev,ftra(1:klev,18),'ftr18','ftr18')
+c$$$          call writeg1d(1,klev,ftra(1:klev,19),'ftr19','ftr19')
+c$$$          call writeg1d(1,klev,ftra(1:klev,20),'ftr20','ftr20 ')
+c$$$          call writeg1d(1,klev,mp,'mp  ','mp ')
+c$$$          call writeg1d(1,klev,Mke,'Mke  ','Mke ')
+
+ 
+ 
+ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+c
+c
+        RETURN
+        END
+C ---------------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/dimphy.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/dimphy.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/dimphy.h	(revision 253)
@@ -1,5 +1,5 @@
 c-----------------------------------------------------------------------
       INTEGER KIDIA, KFDIA, KLON, KLEV
-      PARAMETER (KIDIA=1,KFDIA=iim*(jjm-1)+2,
+      PARAMETER (KIDIA=1,KFDIA=iim*(jjm-1)+2-1/jjm,
      .           KLON=KFDIA-KIDIA+1,KLEV=llm)
 c-----------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/fisrtilp.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/fisrtilp.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/fisrtilp.F	(revision 253)
@@ -1,4 +1,5 @@
       SUBROUTINE fisrtilp(dtime,paprs,pplay,t,q,
-     s                   d_t, d_q, d_ql, rneb, radliq, rain, snow)
+     s                   d_t, d_q, d_ql, rneb, radliq, rain, snow,
+     s                   prfl, psfl)
 c
       IMPLICIT none
@@ -28,4 +29,6 @@
       REAL rain(klon) ! pluies (mm/s)
       REAL snow(klon) ! neige (mm/s)
+      REAL prfl(klon,klev+1) ! flux d'eau precipitante aux interfaces (kg/m2/s)
+      REAL psfl(klon,klev+1) ! flux d'eau precipitante aux interfaces (kg/m2/s)
 c
 c Options du programme:
@@ -36,5 +39,7 @@
       PARAMETER (ct=1./1800.)
       REAL cl ! seuil de precipitation
-      PARAMETER (cl=2.0e-4)
+      PARAMETER (cl=2.6e-4)
+ccc      PARAMETER (cl=2.3e-4)
+ccc      PARAMETER (cl=2.0e-4)
       INTEGER ninter ! sous-intervals pour la precipitation
       PARAMETER (ninter=5)
@@ -77,6 +82,7 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
-CCC      fallv (zzz) = 3.29/3.0 * ((zzz)**0.
-       fallv (zzz) = 3.29 * ((zzz)**0.16)
+      fallv (zzz) = 3.29/2.0 * ((zzz)**0.16)
+ccc      fallv (zzz) = 3.29/3.0 * ((zzz)**0.16)
+ccc      fallv (zzz) = 3.29 * ((zzz)**0.16)
 c
       DATA appel1er /.TRUE./
@@ -103,4 +109,10 @@
 c Initialiser les sorties:
 c
+      DO k = 1, klev+1
+      DO i = 1, klon
+         prfl(i,k) = 0.0
+         psfl(i,k) = 0.0
+      ENDDO
+      ENDDO
       DO k = 1, klev
       DO i = 1, klon
@@ -205,5 +217,6 @@
             zx = zx * zx * zx
             ratqs = zx * (rat_max-rat_min) + rat_min
-            IF (.NOT.calcrat) ratqs=0.2
+            IF (.NOT.calcrat) ratqs=0.05
+ccc            IF (.NOT.calcrat) ratqs=0.2
 c
             zdelq = ratqs * zq(i)
@@ -269,4 +282,9 @@
      .                    * (paprs(i,k)-paprs(i,k+1))/(RG*dtime)
       ENDIF
+      IF (zt(i).LT.RTT) THEN
+        psfl(i,k)=zrfl(i)
+      ELSE
+        prfl(i,k)=zrfl(i)
+      ENDIF
       ENDDO
 c
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/fisrtilp_tr.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/fisrtilp_tr.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/fisrtilp_tr.F	(revision 253)
@@ -1,6 +1,9 @@
-      SUBROUTINE fisrtilp_tr(dtime,paprs,pplay,t,q,
+c $Header$
+c
+      SUBROUTINE fisrtilp_tr(dtime,paprs,pplay,t,q,ratqs,
      s                   d_t, d_q, d_ql, rneb, radliq, rain, snow,
      s                   pfrac_impa, pfrac_nucl, pfrac_1nucl,
-     s                   frac_impa, frac_nucl )
+     s                   frac_impa, frac_nucl,
+     s                   prfl, psfl)
 
 c
@@ -32,4 +35,6 @@
       REAL rain(klon) ! pluies (mm/s)
       REAL snow(klon) ! neige (mm/s)
+      REAL prfl(klon,klev+1) ! flux d'eau precipitante aux interfaces (kg/m2/s)
+      REAL psfl(klon,klev+1) ! flux d'eau precipitante aux interfaces (kg/m2/s)
 cAA
 c Coeffients de fraction lessivee : pour OFF-LINE
@@ -53,5 +58,7 @@
       PARAMETER (ct=1./1800.)
       REAL cl ! seuil de precipitation
-      PARAMETER (cl=2.0e-4)
+      PARAMETER (cl=2.6e-4)
+ccc      PARAMETER (cl=2.3e-4)
+ccc      PARAMETER (cl=2.0e-4)
       INTEGER ninter ! sous-intervals pour la precipitation
       PARAMETER (ninter=5)
@@ -61,6 +68,6 @@
       PARAMETER (coef_eva=2.0E-05)
       LOGICAL calcrat ! calculer ratqs au lieu de fixer sa valeur
-      REAL ratqs ! determine la largeur de distribution de vapeur
-      PARAMETER (calcrat=.FALSE.)
+      REAL ratqs(klon,klev) ! determine la largeur de distribution de vapeur
+      PARAMETER (calcrat=.TRUE.)
       REAL zx_min, rat_max
       PARAMETER (zx_min=1.0, rat_max=0.01)
@@ -101,5 +108,5 @@
       REAL zalpha_tr
       REAL zfrac_lessi
-      REAL zprec_cond
+      REAL zprec_cond(klon)
 cAA
 c---------------------------------------------------------------
@@ -111,5 +118,7 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
-      fallv (zzz) = 3.29 * ((zzz)**0.16)
+      fallv (zzz) = 3.29/2.0 * ((zzz)**0.16)
+ccc      fallv (zzz) = 3.29/3.0 * ((zzz)**0.16)
+ccc      fallv (zzz) = 3.29 * ((zzz)**0.16)
 c
       DATA appel1er /.TRUE./
@@ -158,4 +167,11 @@
 c Initialiser les sorties:
 c
+      DO k = 1, klev+1
+      DO i = 1, klon
+         prfl(i,k) = 0.0
+         psfl(i,k) = 0.0
+      ENDDO
+      ENDDO
+
       DO k = 1, klev
       DO i = 1, klon
@@ -186,5 +202,4 @@
       zalpha_tr   = 0.
       zfrac_lessi = 0.
-      zprec_cond  = 0.
 
 cAA----------------------------------------------------------
@@ -268,12 +283,5 @@
          DO i = 1, klon
 c
-            zx = pplay(i,k)/paprs(i,1)
-            zx = (zx_max-zx)/(zx_max-zx_min)
-            zx = MIN(MAX(zx,0.0),1.0)
-            zx = zx * zx * zx
-            ratqs = zx * (rat_max-rat_min) + rat_min
-            IF (.NOT.calcrat) ratqs=0.2
-c
-            zdelq = ratqs * zq(i)
+            zdelq = ratqs(i,k) * zq(i)
             rneb(i,k) = (zq(i)+zdelq-zqs(i)) / (2.0*zdelq)
             zqn(i) = (zq(i)+zdelq+zqs(i))/2.0
@@ -337,4 +345,9 @@
      .                    * (paprs(i,k)-paprs(i,k+1))/(RG*dtime)
       ENDIF
+      IF (zt(i).LT.RTT) THEN
+        psfl(i,k)=zrfl(i)
+      ELSE
+        prfl(i,k)=zrfl(i)
+      ENDIF
       ENDDO
 c
@@ -350,7 +363,7 @@
       DO i = 1,klon
 c
-             zprec_cond = MAX(zcond(i)-zoliq(i),0.0)
+         zprec_cond(i) = MAX(zcond(i)-zoliq(i),0.0)
      .                * (paprs(i,k)-paprs(i,k+1))/RG
-         IF (rneb(i,k).GT.0.0.and.zprec_cond.gt.0.) THEN
+         IF (rneb(i,k).GT.0.0.and.zprec_cond(i).gt.0.) THEN
 cAA lessivage nucleation LMD5 dans la couche elle-meme
             if (t(i,k) .GE. ztglace) THEN
@@ -359,25 +372,30 @@
                zalpha_tr = a_tr_sca(4)
             endif
-            zfrac_lessi = 1. - EXP(zalpha_tr*zprec_cond/zneb(i))
+            zfrac_lessi = 1. - EXP(zalpha_tr*zprec_cond(i)/zneb(i))
             pfrac_nucl(i,k)=pfrac_nucl(i,k)*(1.-zneb(i)*zfrac_lessi)
             frac_nucl(i,k)= 1.-zneb(i)*zfrac_lessi 
 c
 c nucleation avec un facteur -1 au lieu de -0.5
-            zfrac_lessi = 1. - EXP(-zprec_cond/zneb(i))
+            zfrac_lessi = 1. - EXP(-zprec_cond(i)/zneb(i))
             pfrac_1nucl(i,k)=pfrac_1nucl(i,k)*(1.-zneb(i)*zfrac_lessi)
+         ENDIF
+c
+      ENDDO      ! boucle sur i
+c
 cAA Lessivage par impaction dans les couches en-dessous
-            do kk=k-1,1,-1
-              if (t(i,kk) .GE. ztglace) THEN
-                 zalpha_tr = a_tr_sca(1)
-              else
-                 zalpha_tr = a_tr_sca(2)
-              endif
-              zfrac_lessi = 1. - EXP(zalpha_tr*zprec_cond/zneb(i))
-              pfrac_impa(i,kk)=pfrac_impa(i,kk)*(1.-zneb(i)*zfrac_lessi)
-              frac_impa(i,kk)= 1.-zneb(i)*zfrac_lessi 
-            enddo
-         ENDIF
-c
-      ENDDO      ! boucle sur i
+      DO kk = k-1, 1, -1
+        DO i = 1, klon
+          IF (rneb(i,k).GT.0.0.and.zprec_cond(i).gt.0.) THEN
+            if (t(i,kk) .GE. ztglace) THEN
+              zalpha_tr = a_tr_sca(1)
+            else
+              zalpha_tr = a_tr_sca(2)
+            endif
+            zfrac_lessi = 1. - EXP(zalpha_tr*zprec_cond(i)/zneb(i))
+            pfrac_impa(i,kk)=pfrac_impa(i,kk)*(1.-zneb(i)*zfrac_lessi)
+            frac_impa(i,kk)= 1.-zneb(i)*zfrac_lessi
+          ENDIF
+        ENDDO
+      ENDDO
 c
 cAA----------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/inc_cpl.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/inc_cpl.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/inc_cpl.h	(revision 253)
@@ -0,0 +1,16 @@
+C
+C -- inc_cpl.h  
+C    **********
+C@
+C@  Contents : variables describing field restart file names 
+C@  --------
+C@
+C@ -- cl_write/cl_read  : for fields to write/READ
+C@ -- cl_f_write/cl_f_read  : for fields to write/read
+C@
+C     -------------------------------------------------------------------
+C
+      CHARACTER*8 cl_writ(jpmaxfld), cl_read(jpmaxfld)
+      CHARACTER*8 cl_f_writ(jpmaxfld), cl_f_read(jpmaxfld)
+      COMMON / comcpl / cl_writ, cl_read, cl_f_writ, cl_f_read
+C     -------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/inc_sipc.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/inc_sipc.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/inc_sipc.h	(revision 253)
@@ -0,0 +1,23 @@
+C
+C -- inc_sipc.h   97-08-11   Version 2.0   Author: S&A
+C    **********
+C@
+C@  Contents : variables describing pools formed of shared memory segments 
+C@  --------
+C@
+C@ -- mpoolinit(r/w) : handles associated to model pools for passing initial info
+C@
+C@ -- mpoolwrit : handles associated to pools used to pass fields exchanged 
+C@               from model to coupler (see libsipc/SIPC_Write_Model.f)
+C@
+C@ -- mpoolread : handles associated to pools used to pass fields exchanged
+C@               from model to coupler (see libsipc/SIPC_Read_Model.f) 
+C@ 
+C     -------------------------------------------------------------------
+C
+      INTEGER  mpoolinitr
+      INTEGER  mpoolinitw
+      INTEGER  mpoolwrit(jpflda2o)
+      INTEGER  mpoolread(jpfldo2a)
+      COMMON / compool / mpoolinitr, mpoolinitw, mpoolwrit, mpoolread
+C     -------------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/indicesol.inc
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/indicesol.inc	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/indicesol.inc	(revision 253)
@@ -0,0 +1,9 @@
+      INTEGER, parameter :: nbsrf=4
+      INTEGER, parameter :: is_oce=3 !ocean
+      INTEGER, parameter :: is_sic = 4 ! glace de mer
+      INTEGER, parameter :: is_ter = 1 ! terre
+      INTEGER, parameter :: is_lic = 2 ! glacier continental
+      REAL,parameter :: epsfra = 1.0E-05
+!
+      CHARACTER (len=3),dimension(nbsrf) :: clnsurf(nbsrf)
+      DATA clnsurf/'ter', 'lic', 'oce', 'sic'/
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/initphysto.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/initphysto.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/initphysto.F	(revision 253)
@@ -0,0 +1,288 @@
+C
+C $Header$
+C
+      subroutine initphysto
+     .  (infile,
+     .  rlon, rlat, tstep,t_ops,t_wrt,nq,fileid)
+
+       USE IOIPSL
+
+      implicit none
+
+C
+C   Routine d'initialisation des ecritures des fichiers histoires LMDZ
+C   au format IOIPSL
+C
+C   Appels succesifs des routines: histbeg
+C                                  histhori
+C                                  histver
+C                                  histdef
+C                                  histend
+C
+C   Entree:
+C
+C      infile: nom du fichier histoire a creer
+C      day0,anne0: date de reference
+C      tstep: duree du pas de temps en seconde
+C      t_ops: frequence de l'operation pour IOIPSL
+C      t_wrt: frequence d'ecriture sur le fichier
+C      nq: nombre de traceurs
+C
+C   Sortie:
+C      fileid: ID du fichier netcdf cree
+C      filevid:ID du fichier netcdf pour la grille v
+C
+C   L. Fairhead, LMD, 03/99
+C
+C =====================================================================
+C
+C   Declarations
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "temps.h"
+#include "ener.h"
+#include "logic.h"
+#include "description.h"
+#include "serre.h"
+#include "indicesol.h"
+#include "control.h"
+#include "dimphy.h"
+
+C   Arguments
+      character*(*) infile
+      integer*4 nhoriid, i
+      real tstep, t_ops, t_wrt
+      integer fileid, filevid
+      integer nq,l
+      real nivsigs(llm)
+
+C   Variables locales
+C
+      integer tau0
+      real zjulian
+      character*3 str
+      character*10 ctrac
+      integer iq
+      integer uhoriid, vhoriid, thoriid, zvertiid
+      integer ii,jj
+      integer zan
+      logical ok_sync
+      REAL zx_lon(iim,jjm+1), zx_lat(iim,jjm+1)
+C
+      REAL rlon(klon), rlat(klon)
+
+C  Initialisations
+C
+      pi = 4. * atan (1.)
+      str='q  '
+      ctrac = 'traceur   '
+      ok_sync= .true.
+C
+C  Appel a histbeg: creation du fichier netcdf et initialisations diverses
+C         
+
+      zan = anneeref
+      CALL ymds2ju(zan, 1, 1, 0.0, zjulian)
+      zjulian = zjulian + dayref
+      tau0 = 0
+	
+	CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,zx_lon)
+         DO i = 1, iim
+            zx_lon(i,1) = rlon(i+1)
+            zx_lon(i,jjm+1) = rlon(i+1)
+         ENDDO
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,zx_lat)
+
+
+      call histbeg(infile, iim, zx_lon, jjm+1, zx_lat,
+     .             1, iim, 1, jjm+1,
+     .             tau0, zjulian, tstep, nhoriid, fileid)
+
+C  Appel a histvert pour la grille verticale
+C
+	DO l=1,llm
+            nivsigs(l)=float(l)
+         ENDDO
+	
+	write(*,*) 'avant histvert ds initphysto'
+
+      call histvert(fileid, 'sig_s', 'Niveaux sigma',
+     . 'sigma_level',
+     .              llm, nivsigs, zvertiid)
+C
+C  Appels a histdef pour la definition des variables a sauvegarder
+C
+	write(*,*) 'apres histvert ds initphysto'
+
+       CALL histdef(fileid, "phis", "Surface geop. height", "-",
+     .                iim,jjm+1,nhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+c
+	write(*,*) 'apres phis ds initphysto'
+
+         CALL histdef(fileid, "aire", "Grid area", "-",
+     .                iim,jjm+1,nhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+         write(*,*) 'apres aire ds initphysto'
+
+         CALL histdef(fileid, "dtime", "tps phys ", "s",
+     .                1,1,nhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+	
+	 CALL histdef(fileid, "istphy", "tps stock", "s",
+     .                1,1,nhoriid, 1,1,1, -99, 32,
+     .                "once", t_ops, t_wrt)
+
+C T 
+C
+      call histdef(fileid, 't', 'Temperature', 'K',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+        write(*,*) 'apres t ds initphysto'
+C mfu 
+C
+      call histdef(fileid, 'mfu', 'flx m. pan. mt', 'kg m/s',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+        write(*,*) 'apres mfu ds initphysto'
+C
+C mfd 
+C
+      call histdef(fileid, 'mfd', 'flx m. pan. des', 'kg m/s',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+
+C
+C en_u 
+C
+      call histdef(fileid, 'en_u', 'flx ent pan mt', 'kg m/s',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+               write(*,*) 'apres en_u ds initphysto'
+C
+C de_u 
+C
+      call histdef(fileid, 'de_u', 'flx det pan mt', 'kg m/s',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+
+C
+C en_d 
+C
+      call histdef(fileid, 'en_d', 'flx ent pan dt', 'kg m/s',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+C
+
+C
+C de_d 
+C
+      call histdef(fileid, 'de_d', 'flx det pan dt', 'kg m/s',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+
+c coefh frac_impa,frac_nucl
+	
+	call histdef(fileid, 'coefh', ' ', ' ',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+	
+	write(*,*) 'apres coefh ds initphysto'	
+
+	call histdef(fileid, 'frac_impa', ' ', ' ',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+	
+	call histdef(fileid, 'frac_nucl', ' ', ' ',
+     .             iim, jjm+1, nhoriid, llm, 1, llm, zvertiid,
+     .             32, 'inst(X)', t_ops, t_wrt)
+
+c
+c pyu1
+c
+      CALL histdef(fileid, "pyu1", " ", " ",
+     .                iim,jjm+1,nhoriid, 1,1,1, -99, 32,
+     .                "inst(X)", t_ops, t_wrt)
+
+c
+c pyv1
+c
+	CALL histdef(fileid, "pyv1", " ", " ",
+     .                iim,jjm+1,nhoriid, 1,1,1, -99, 32,
+     .                "inst(X)", t_ops, t_wrt)
+	
+	write(*,*) 'apres pyv1 ds initphysto'
+c
+c ftsol1
+c
+	call histdef(fileid, "ftsol1", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1,1, -99,32,
+     .             "inst(X)", t_ops, t_wrt)
+
+c
+c ftsol2
+c
+        call histdef(fileid, "ftsol2", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1,1, -99,32,
+     .             "inst(X)", t_ops, t_wrt)
+
+c
+c ftsol3
+c
+        call histdef(fileid, "ftsol3", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1,1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+
+c
+c ftsol4
+c
+        call histdef(fileid, "ftsol4", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1,1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+	
+c
+c rain
+c
+        call histdef(fileid, "rain", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1,1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+
+c
+c psrf1
+c
+	call histdef(fileid, "psrf1", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1, 1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+	
+c
+c psrf2
+c
+        call histdef(fileid, "psrf2", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1, 1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+
+c
+c psrf3
+c
+        call histdef(fileid, "psrf3", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1, 1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+
+c
+c psrf4
+c
+        call histdef(fileid, "psrf4", " ", " ",
+     .             iim, jjm+1, nhoriid, 1, 1, 1, -99,
+     .             32, "inst(X)", t_ops, t_wrt)
+	
+	write(*,*) 'avant histend ds initphysto'	
+
+      call histend(fileid)
+      if (ok_sync) call histsync(fileid)
+
+	
+
+      return
+      end
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/interface_surf.F90
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/interface_surf.F90	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/interface_surf.F90	(revision 253)
@@ -0,0 +1,980 @@
+
+  MODULE interface_surf
+
+! Ce module regroupe toutes les routines gerant l'interface entre le modele 
+! atmospherique et les modeles de surface (sols continentaux, oceans, glaces)
+! Les routines sont les suivantes:
+!
+!   interfsurf_*: routines d'aiguillage vers les interfaces avec les 
+!                 differents modeles de surface
+!   interfsol\
+!             > routines d'interface proprement dite
+!   interfoce/
+!
+!   interfstart: routine d'initialisation et de lecture de l'etat initial
+!                "interface"
+!   interffin  : routine d'ecriture de l'etat de redemmarage de l'interface
+!
+! 
+! L. Fairhead, LMD, 02/2000
+
+  USE ioipsl
+
+  IMPLICIT none
+
+  PRIVATE
+  PUBLIC :: interfsurf,interfsurf_hq 
+
+  INTERFACE interfsurf
+    module procedure interfsurf_hq, interfsurf_vent
+  END INTERFACE
+
+  INTERFACE interfoce
+    module procedure interfoce_cpl, interfoce_slab, interfoce_lim
+  END INTERFACE
+
+#include "YOMCST.inc"
+#include "indicesol.inc"
+
+
+! run_off      ruissellement total
+  real, allocatable, dimension(:),save    :: run_off
+
+
+  CONTAINS
+!
+!############################################################################
+!
+  SUBROUTINE interfsurf_hq(itime, dtime, jour, &
+      & klon, nisurf, knon, knindex, rlon, rlat, &
+      & debut, lafin, ok_veget, &
+      & zlev, zlflu, u1_lay, v1_lay, temp_air, spechum, hum_air, ccanopy, & 
+      & tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
+      & precip_rain, precip_snow, lwdown, swnet, swdown, &
+      & tsurf, p1lay, cal, beta, coef1lay, ps, radsol, dif_grnd, &
+      & ocean, &
+      & evap, fluxsens, fluxlat, dflux_l, dflux_s, &              
+      & tsol_rad, tsurf_new, alb_new, emis_new, z0_new, pctsrf_new)
+
+
+! Cette routine sert d'aiguillage entre l'atmosphere et la surface en general 
+! (sols continentaux, oceans, glaces) pour les fluxs de chaleur et d'humidite.
+! En pratique l'interface se fait entre la couche limite du modele 
+! atmospherique (clmain.F) et les routines de surface (sechiba, oasis, ...)
+!
+! 
+! L.Fairhead 02/2000
+!
+! input:
+!   itime        numero du pas de temps
+!   klon         nombre total de points de grille
+!   dtime        pas de temps de la physique (en s)
+!   jour         jour dans l'annee en cours
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   knon         nombre de points de la surface a traiter
+!   knindex      index des points de la surface a traiter
+!   rlon         longitudes
+!   rlat         latitudes
+!   debut        logical: 1er appel a la physique
+!   lafin        logical: dernier appel a la physique
+!   ok_veget     logical: appel ou non au schema de surface continental
+!                     (si false calcul simplifie des fluxs sur les continents)
+!   zlev         hauteur de la premiere couche
+!   zlflu        epaisseur de la premier couche
+!   u1_lay       vitesse u 1ere couche
+!   v1_lay       vitesse v 1ere couche
+!   temp_air     temperature de l'air 1ere couche
+!   spechum      humidite specifique 1ere couche
+!   hum_air      humidite de l'air
+!   ccanopy      concentration CO2 canopee
+!   tq_cdrag     cdrag
+!   petAcoef     coeff. A de la resolution de la CL pour t
+!   peqAcoef     coeff. A de la resolution de la CL pour q
+!   petBcoef     coeff. B de la resolution de la CL pour t
+!   peqBcoef     coeff. B de la resolution de la CL pour q
+!   precip_rain  precipitation liquide
+!   precip_snow  precipitation solide
+!   lwdown       flux IR entrant a la surface
+!   swnet        flux solaire net
+!   swdown       flux solaire entrant a la surface
+!   tsurf        temperature de surface
+!   p1lay        pression 1er niveau (milieu de couche)
+!   cal          capacite calorifique du sol
+!   beta         evap reelle
+!   coef1lay     coefficient d'echange
+!   ps           pression au sol
+!   radsol       rayonnement net aus sol (LW + SW)
+!   dif_grnd     coeff. diffusion vers le sol profond
+!   ocean        type d'ocean utilise (force, slab, couple)
+!
+! output:
+!   evap         evaporation totale
+!   fluxsens     flux de chaleur sensible
+!   fluxlat      flux de chaleur latente
+!   tsol_rad     
+!   tsurf_new    temperature au sol
+!   alb_new      albedo
+!   emis_new     emissivite
+!   z0_new       surface roughness
+
+
+! Parametres d'entree
+  integer, intent(IN) :: itime
+  integer, intent(IN) :: klon
+  real, intent(IN) :: dtime
+  integer, intent(IN) :: jour
+  integer, intent(IN) :: nisurf
+  integer, intent(IN) :: knon
+  integer, dimension(knon), intent(in) :: knindex
+  logical, intent(IN) :: debut, lafin, ok_veget
+  real, dimension(klon), intent(IN) :: rlon, rlat
+  real, dimension(knon), intent(IN) :: zlev, zlflu
+  real, dimension(knon), intent(IN) :: u1_lay, v1_lay
+  real, dimension(knon), intent(IN) :: temp_air, spechum
+  real, dimension(knon), intent(IN) :: hum_air, ccanopy
+  real, dimension(knon), intent(IN) :: tq_cdrag, petAcoef, peqAcoef
+  real, dimension(knon), intent(IN) :: petBcoef, peqBcoef
+  real, dimension(knon), intent(IN) :: precip_rain, precip_snow
+  real, dimension(knon), intent(IN) :: lwdown, swnet, swdown, ps
+  real, dimension(knon), intent(IN) :: tsurf, p1lay, cal, beta, coef1lay
+  real, dimension(knon), intent(IN) :: radsol, dif_grnd
+  character (len = 6)  :: ocean
+
+! Parametres de sortie
+  real, dimension(knon), intent(OUT):: evap, fluxsens, fluxlat
+  real, dimension(knon), intent(OUT):: tsol_rad, tsurf_new, alb_new
+  real, dimension(knon), intent(OUT):: emis_new, z0_new
+  real, dimension(knon), intent(OUT):: dflux_l, dflux_s
+  real, dimension(klon,nbsrf), intent(OUT) :: pctsrf_new
+
+! Local
+  character (len = 20) :: modname = 'interfsurf_hq'
+  character (len = 80) :: abort_message 
+  logical, save        :: first_call = .true.
+  integer              :: error
+  logical              :: check = .true.
+
+  if (check) write(*,*) 'Entree ', modname
+!
+! On doit commencer par appeler les schemas de surfaces continentales
+! car l'ocean a besoin du ruissellement qui est y calcule
+!
+  if (first_call) then
+    if (nisurf /= is_ter .and. klon > 1) then 
+      write(*,*)' *** Warning ***'
+      write(*,*)' nisurf = ',nisurf,' /= is_ter = ',is_ter
+      write(*,*)'or on doit commencer par les surfaces continentales'
+      abort_message='voir ci-dessus'
+      call abort_gcm(modname,abort_message,1)
+    endif
+    if (ocean /= 'slab  ' .and. ocean /= 'force ' .and. ocean /= 'couple') then
+      write(*,*)' *** Warning ***'
+      write(*,*)'Option couplage pour l''ocean = ', ocean
+      abort_message='option pour l''ocean non valable'
+      call abort_gcm(modname,abort_message,1)
+    endif
+  endif
+  first_call = .false.
+
+! Aiguillage vers les differents schemas de surface
+
+  if (nisurf == is_ter) then
+!
+! Surface "terre" appel a l'interface avec les sols continentaux
+!
+! allocation du run-off
+    if (.not. allocated(run_off)) then
+      allocate(run_off(knon), stat = error)
+      if (error /= 0) then
+        abort_message='Pb allocation run_off'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    else if (size(run_off) /= knon) then
+      write(*,*)'Bizarre, le nombre de points continentaux'
+      write(*,*)'a change entre deux appels. Je continue ...'
+      deallocate(run_off, stat = error)
+      allocate(run_off(knon), stat = error)
+      if (error /= 0) then
+        abort_message='Pb allocation run_off'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    endif
+!
+    call interfsol(itime, klon, dtime, nisurf, knon, &
+     &  knindex, rlon, rlat, &
+     &  debut, lafin, ok_veget, &
+     &  zlev, zlflu, u1_lay, v1_lay, temp_air, spechum, hum_air, ccanopy, & 
+     &  tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     &  precip_rain, precip_snow, lwdown, swnet, swdown, &
+     &  tsurf, p1lay, cal, beta, coef1lay, ps, radsol, dif_grnd, &
+     &  evap, fluxsens, fluxlat, &              
+     &  tsol_rad, tsurf_new, alb_new, emis_new, z0_new, dflux_l, dflux_s)
+      
+!
+  else if (nisurf == is_oce) then
+
+    if (check) write(*,*)'ocean, nisurf = ',nisurf 
+!
+! Surface "ocean" appel a l'interface avec l'ocean
+!
+!    if (ocean == 'couple') then
+!      call interfoce(nisurf, ocean)
+!    else if (ocean == 'slab  ') then
+!      call interfoce(nisurf)
+!    else                              ! lecture conditions limites
+!      call interfoce(itime, dtime, jour, & 
+!     &  klon, nisurf, knon, knindex, &
+!     &  debut, &
+!     &  tsurf_new, alb_new, z0_new, pctsrf_new)
+!    endif
+!
+    call calcul_fluxs( knon, dtime, &
+     &   tsurf, p1lay, cal, beta, coef1lay, ps, &
+     &   radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, &
+     &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     &   tsurf_new, fluxlat, fluxsens, dflux_s, dflux_l)
+!
+  else if (nisurf == is_sic) then
+
+    if (check) write(*,*)'sea ice, nisurf = ',nisurf 
+
+!
+! Surface "glace de mer" appel a l'interface avec l'ocean
+!
+!    call interfoce(nisurf, ocean)
+!
+    call calcul_fluxs( knon, dtime, &
+     &   tsurf, p1lay, cal, beta, coef1lay, ps, &
+     &   radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, &
+     &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     &   tsurf_new, fluxlat, fluxsens, dflux_s, dflux_l)
+
+  else if (nisurf == is_lic) then
+
+    if (check) write(*,*)'glacier, nisurf = ',nisurf 
+
+!
+! Surface "glacier continentaux" appel a l'interface avec le sol
+!
+!    call interfsol(nisurf)
+    call calcul_fluxs( knon, dtime, &
+     &   tsurf, p1lay, cal, beta, coef1lay, ps, &
+     &   radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, &
+     &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     &   tsurf_new, fluxlat, fluxsens, dflux_s, dflux_l)
+
+  else
+    write(*,*)'Index surface = ',nisurf
+    abort_message = 'Index surface non valable'
+    call abort_gcm(modname,abort_message,1)
+  endif
+
+  END SUBROUTINE interfsurf_hq
+
+!
+!#########################################################################
+!
+  SUBROUTINE interfsurf_vent(nisurf, knon   &         
+  &                     )
+!
+! Cette routine sert d'aiguillage entre l'atmosphere et la surface en general 
+! (sols continentaux, oceans, glaces) pour les tensions de vents.
+! En pratique l'interface se fait entre la couche limite du modele 
+! atmospherique (clmain.F) et les routines de surface (sechiba, oasis, ...)
+!
+! 
+! L.Fairhead 02/2000
+!
+! input:
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   knon         nombre de points de la surface a traiter
+
+! Parametres d'entree
+  integer, intent(IN) :: nisurf
+  integer, intent(IN) :: knon
+
+
+  return
+  END SUBROUTINE interfsurf_vent
+!
+!#########################################################################
+!
+  SUBROUTINE interfsol(itime, klon, dtime, nisurf, knon, &
+     & knindex, rlon, rlat, &
+     & debut, lafin, ok_veget, &
+     & zlev, zlflu, u1_lay, v1_lay, temp_air, spechum, hum_air, ccanopy, & 
+     & tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     & precip_rain, precip_snow, lwdown, swnet, swdown, &
+     & tsurf, p1lay, cal, beta, coef1lay, ps, radsol, dif_grnd, &
+     & evap, fluxsens, fluxlat, &              
+     & tsol_rad, tsurf_new, alb_new, emis_new, z0_new, dflux_l, dflux_s)
+
+! Cette routine sert d'interface entre le modele atmospherique et le 
+! modele de sol continental. Appel a sechiba
+!
+! L. Fairhead 02/2000
+!
+! input:
+!   itime        numero du pas de temps
+!   klon         nombre total de points de grille
+!   dtime        pas de temps de la physique (en s)
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   knon         nombre de points de la surface a traiter
+!   knindex      index des points de la surface a traiter
+!   rlon         longitudes de la grille entiere
+!   rlat         latitudes de la grille entiere
+!   debut        logical: 1er appel a la physique (lire les restart)
+!   lafin        logical: dernier appel a la physique (ecrire les restart)
+!   ok_veget     logical: appel ou non au schema de surface continental
+!                     (si false calcul simplifie des fluxs sur les continents)
+!   zlev         hauteur de la premiere couche
+!   zlflu        
+!   u1_lay       vitesse u 1ere couche
+!   v1_lay       vitesse v 1ere couche
+!   temp_air     temperature de l'air 1ere couche
+!   spechum      humidite specifique 1ere couche
+!   hum_air      humidite de l'air
+!   ccanopy      concentration CO2 canopee
+!   tq_cdrag     cdrag
+!   petAcoef     coeff. A de la resolution de la CL pour t
+!   peqAcoef     coeff. A de la resolution de la CL pour q
+!   petBcoef     coeff. B de la resolution de la CL pour t
+!   peqBcoef     coeff. B de la resolution de la CL pour q
+!   precip_rain  precipitation liquide
+!   precip_snow  precipitation solide
+!   lwdown       flux IR entrant a la surface
+!   swnet        flux solaire net
+!   swdown       flux solaire entrant a la surface
+!   tsurf        temperature de surface
+!   p1lay        pression 1er niveau (milieu de couche)
+!   cal          capacite calorifique du sol
+!   beta         evap reelle
+!   coef1lay     coefficient d'echange
+!   ps           pression au sol
+!   radsol       rayonnement net aus sol (LW + SW)
+!   dif_grnd     coeff. diffusion vers le sol profond      
+!   
+!
+! input/output
+!   run_off      ruissellement total
+!
+! output:
+!   evap         evaporation totale
+!   fluxsens     flux de chaleur sensible
+!   fluxlat      flux de chaleur latente
+!   tsol_rad     
+!   tsurf_new    temperature au sol
+!   alb_new      albedo
+!   emis_new     emissivite
+!   z0_new       surface roughness
+
+! Parametres d'entree
+  integer, intent(IN) :: itime
+  integer, intent(IN) :: klon
+  real, intent(IN)    :: dtime
+  integer, intent(IN) :: nisurf
+  integer, intent(IN) :: knon
+  integer, dimension(knon), intent(IN) :: knindex
+  logical, intent(IN) :: debut, lafin, ok_veget
+  real, dimension(klon), intent(IN) :: rlon, rlat
+  real, dimension(knon), intent(IN) :: zlev, zlflu
+  real, dimension(knon), intent(IN) :: u1_lay, v1_lay
+  real, dimension(knon), intent(IN) :: temp_air, spechum
+  real, dimension(knon), intent(IN) :: hum_air, ccanopy
+  real, dimension(knon), intent(IN) :: tq_cdrag, petAcoef, peqAcoef
+  real, dimension(knon), intent(IN) :: petBcoef, peqBcoef
+  real, dimension(knon), intent(IN) :: precip_rain, precip_snow
+  real, dimension(knon), intent(IN) :: lwdown, swnet, swdown, ps
+  real, dimension(knon), intent(IN) :: tsurf, p1lay, cal, beta, coef1lay
+  real, dimension(knon), intent(IN) :: radsol, dif_grnd
+! Parametres de sortie
+  real, dimension(knon), intent(OUT):: evap, fluxsens, fluxlat
+  real, dimension(knon), intent(OUT):: tsol_rad, tsurf_new, alb_new
+  real, dimension(knon), intent(OUT):: emis_new, z0_new
+  real, dimension(knon), intent(OUT):: dflux_s, dflux_l
+
+! Local
+!
+  integer              :: ii
+  integer              :: error
+  character (len = 20) :: modname = 'interfsol'
+  character (len = 80) :: abort_message
+  logical              :: check = .true.
+! type de couplage dans sechiba
+!  character (len=10)   :: coupling = 'implicit' 
+! drapeaux controlant les appels dans SECHIBA
+!  type(control_type), save   :: control_in
+! coordonnees geographiques
+  real, allocatable, dimension(:,:), save :: lalo
+! pts voisins
+  integer,allocatable, dimension(:,:), save :: neighbours
+! resolution de la grille
+  real, allocatable, dimension (:,:), save :: resolution
+! Identifieurs des fichiers restart et histoire
+  integer, save          :: rest_id, hist_id 
+  integer, save          :: rest_id_stom, hist_id_stom
+
+  if (check) write(*,*)'Entree ', modname
+  if (check) write(*,*)'ok_veget = ',ok_veget
+
+! initialisation
+  if (.not. ok_veget) then
+    call calcul_fluxs( knon, dtime, &
+     &   tsurf, p1lay, cal, beta, coef1lay, ps, &
+     &   radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, &
+     &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     &   tsurf_new, fluxlat, fluxsens, dflux_s, dflux_l)
+  else
+!    if (debut) then
+!      !
+!      ! Configuration de parametres specifiques a la SSL
+!      !
+!      call intsurf_config(control_in)
+!      !
+!      ! Allouer et initialiser le tableau de coordonnees du sol
+!      !
+!      if (( .not. allocated(lalo))) then
+!        allocate(lalo(knon,2), stat = error)
+!        if (error /= 0) then
+!          abort_message='Pb allocation lalo'
+!          call abort_gcm(modname,abort_message,1)
+!        endif      
+!      endif
+!      do ii = 1, knon
+!        lalo(ii,1) = rlat(knindex(ii))
+!        lalo(ii,2) = rlon(knindex(ii))
+!      enddo
+      !-
+      !- Compute variable to help describe the grid
+      !- once the points are gathered.
+      !-
+!      IF ( (.NOT.ALLOCATED(neighbours))) THEN
+!        ALLOCATE(neighbours(knon,4), stat = error)
+!        if (error /= 0) then
+!          abort_message='Pb allocation neighbours'
+!          call abort_gcm(modname,abort_message,1)
+!        endif
+!      ENDIF
+!      IF ( (.NOT.ALLOCATED(resolution))) THEN
+!        ALLOCATE(resolution(knon,2), stat = error)
+!        if (error /= 0) then
+!          abort_message='Pb allocation resolution'
+!          call abort_gcm(modname,abort_message,1)
+!        endif
+!      ENDIF
+
+! call grid_stuff
+! call sechiba_restart_init
+! call sechiba_history_init
+
+!    endif                          ! (fin debut) 
+
+! 
+! Appel a la routine sols continentaux
+!
+
+!    call sechiba_main(itime, klon, knon, knindex, dtime, &
+!     & debut, lafin, coupling, control_in, &
+!     & lalo, neighbours, resolution,&
+!     & zlev, zlflu, u1_lay, v1_lay, spechum, temp_air,hum_air , ccanopy, &
+!     & tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
+!     & precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
+!     & evap, fluxsens, fluxlat, &
+!     & tsol_rad, tsurf_new, alb_new, emis_new, z0_new, &
+!     & rest_id, hist_id, rest_id_stom, hist_id_stom)
+
+!
+! Sauvegarde dans fichiers histoire
+!
+  endif  ! fin ok_veget
+
+  END SUBROUTINE interfsol
+!
+!#########################################################################
+!
+  SUBROUTINE interfoce_cpl(nisurf, ocean)
+
+! Cette routine sert d'interface entre le modele atmospherique et un 
+! coupleur avec un modele d'ocean 'complet'
+!
+! L. Fairhead 02/2000
+!
+! input:
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   ocean        type d'ocean
+!
+! output:
+!
+
+! Parametres d'entree
+  integer, intent(IN) :: nisurf
+  character (len = 6)  :: ocean
+
+! Parametres de sortie
+
+! Variables locales
+
+
+! Initialisation
+! fichier restart et fichiers histoires
+
+! calcul des fluxs a passer
+
+  END SUBROUTINE interfoce_cpl
+!
+!#########################################################################
+!
+  SUBROUTINE interfoce_slab(nisurf)
+
+! Cette routine sert d'interface entre le modele atmospherique et un 
+! modele de 'slab' ocean
+!
+! L. Fairhead 02/2000
+!
+! input:
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!
+! output:
+!
+
+! Parametres d'entree
+  integer, intent(IN) :: nisurf
+
+  END SUBROUTINE interfoce_slab
+!
+!#########################################################################
+!
+  SUBROUTINE interfoce_lim(itime, dtime, jour, &
+     & klon, nisurf, knon, knindex, &
+     & debut,  &
+     & lmt_sst, lmt_alb, lmt_rug, pctsrf_new)
+
+! Cette routine sert d'interface entre le modele atmospherique et un fichier
+! de conditions aux limites
+!
+! L. Fairhead 02/2000
+!
+! input:
+!   itime        numero du pas de temps courant
+!   dtime        pas de temps de la physique (en s)
+!   jour         jour a lire dans l'annee
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   knon         nombre de points dans le domaine a traiter
+!   knindex      index des points de la surface a traiter
+!   klon         taille de la grille
+!   debut        logical: 1er appel a la physique (initialisation)
+!
+! output:
+!   lmt_sst      SST lues dans le fichier de CL
+!   lmt_alb      Albedo lu 
+!   lmt_rug      longueur de rugosité lue
+!   pctsrf_new   sous-maille fractionnelle
+!
+
+
+! Parametres d'entree
+  integer, intent(IN) :: itime
+  real   , intent(IN) :: dtime
+  integer, intent(IN) :: jour
+  integer, intent(IN) :: nisurf
+  integer, intent(IN) :: knon
+  integer, intent(IN) :: klon
+  integer, dimension(knon), intent(in) :: knindex
+  logical, intent(IN) :: debut
+
+! Parametres de sortie
+  real, intent(out), dimension(knon) :: lmt_sst
+  real, intent(out), dimension(knon) :: lmt_alb
+  real, intent(out), dimension(knon) :: lmt_rug
+  real, intent(out), dimension(klon,nbsrf) :: pctsrf_new
+
+! Variables locales
+  integer     :: ii
+  integer     :: lmt_pas     ! frequence de lecture des conditions limites 
+                             ! (en pas de physique)
+  logical,save :: deja_lu    ! pour indiquer que le jour a lire a deja
+                             ! lu pour une surface precedente
+  integer,save :: jour_lu 
+  integer      :: ierr
+  character (len = 20) :: modname = 'interfoce_lim'
+  character (len = 80) :: abort_message
+  character (len = 20) :: fich ='limit'
+  logical     :: newlmt = .false.
+  logical     :: check = .true.
+! Champs lus dans le fichier de CL
+  real, allocatable , save, dimension(:) :: sst_lu, alb_lu, rug_lu, nat_lu
+  real, allocatable , save, dimension(:,:) :: pct_tmp
+!
+! quelques variables pour netcdf
+!
+#include "netcdf.inc"
+  integer              :: nid, nvarid
+  integer, dimension(2) :: start, epais
+!
+! Fin déclaration
+!
+    
+  if (debut) then
+    lmt_pas = nint(86400./dtime * 1.0) ! pour une lecture une fois par jour
+    jour_lu = jour - 1
+    allocate(sst_lu(klon))
+    allocate(alb_lu(klon))
+    allocate(rug_lu(klon))
+    allocate(nat_lu(klon))
+    allocate(pct_tmp(klon,nbsrf))
+  endif
+
+  if ((jour - jour_lu) /= 0) deja_lu = .false.
+  
+  if (check) write(*,*)modname,' :: jour_lu, deja_lu', jour_lu, deja_lu 
+
+! Tester d'abord si c'est le moment de lire le fichier
+  if (mod(itime-1, lmt_pas) == 0 .and. .not. deja_lu) then
+!
+! Ouverture du fichier
+!
+    ierr = NF_OPEN (fich, NF_NOWRITE,nid)
+    if (ierr.NE.NF_NOERR) then
+      abort_message = 'Pb d''ouverture du fichier de conditions aux limites'
+      call abort_gcm(modname,abort_message,1)
+    endif
+! 
+! La tranche de donnees a lire:
+!
+    start(1) = 1
+    start(2) = jour + 1
+    epais(1) = klon
+    epais(2) = 1
+!
+    if (newlmt) then
+!
+! Fraction "ocean" 
+!
+      ierr = NF_INQ_VARID(nid, 'FOCE', nvarid)
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Le champ <FOCE> est absent'
+        call abort_gcm(modname,abort_message,1)
+      endif
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais,pctsrf_new(1,is_oce))
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais,pctsrf_new(1,is_oce))
+#endif
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Lecture echouee pour <FOCE>'
+        call abort_gcm(modname,abort_message,1)
+      endif
+!
+! Fraction "glace de mer" 
+!
+      ierr = NF_INQ_VARID(nid, 'FSIC', nvarid)
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Le champ <FSIC> est absent'
+        call abort_gcm(modname,abort_message,1)
+      endif
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais,pctsrf_new(1,is_sic))
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais,pctsrf_new(1,is_sic))
+#endif
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Lecture echouee pour <FSIC>'
+        call abort_gcm(modname,abort_message,1)
+      endif
+!
+! Fraction "terre" 
+!
+      ierr = NF_INQ_VARID(nid, 'FTER', nvarid)
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Le champ <FTER> est absent'
+        call abort_gcm(modname,abort_message,1)
+      endif
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais,pctsrf_new(1,is_ter))
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais,pctsrf_new(1,is_ter))
+#endif
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Lecture echouee pour <FTER>'
+        call abort_gcm(modname,abort_message,1)
+      endif
+!
+! Fraction "glacier terre" 
+!
+      ierr = NF_INQ_VARID(nid, 'FLIC', nvarid)
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Le champ <FLIC> est absent'
+        call abort_gcm(modname,abort_message,1)
+      endif
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais,pctsrf_new(1,is_lic))
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais,pctsrf_new(1,is_lic))
+#endif
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Lecture echouee pour <FLIC>'
+        call abort_gcm(modname,abort_message,1)
+      endif
+!
+    else  ! on en est toujours a rnatur
+! 
+      ierr = NF_INQ_VARID(nid, 'NAT', nvarid)
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Le champ <NAT> est absent'
+        call abort_gcm(modname,abort_message,1)
+      endif
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais, nat_lu)
+#else
+      ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais, nat_lu)
+#endif
+      if (ierr /= NF_NOERR) then
+        abort_message = 'Lecture echouee pour <NAT>'
+        call abort_gcm(modname,abort_message,1)
+      endif
+!
+! Remplissage des fractions de surface
+! nat = 0, 1, 2, 3 pour ocean, terre, glacier, seaice
+! 
+      pct_tmp = 0.0
+      do ii = 1, klon
+        pct_tmp(ii,nint(nat_lu(ii)) + 1) = 1.
+      enddo
+
+!
+!  On se retrouve avec ocean en 1 et terre en 2 alors qu'on veut le contraire
+!
+      pctsrf_new = pct_tmp
+      pctsrf_new (:,2)= pct_tmp (:,1)
+      pctsrf_new (:,1)= pct_tmp (:,2)
+      pct_tmp = pctsrf_new 
+    endif ! fin test sur newlmt
+!
+! Lecture SST
+!
+    ierr = NF_INQ_VARID(nid, 'SST', nvarid)
+    if (ierr /= NF_NOERR) then
+      abort_message = 'Le champ <SST> est absent'
+      call abort_gcm(modname,abort_message,1)
+    endif
+#ifdef NC_DOUBLE
+    ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais, sst_lu)
+#else
+    ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais, sst_lu)
+#endif
+    if (ierr /= NF_NOERR) then
+      abort_message = 'Lecture echouee pour <SST>'
+      call abort_gcm(modname,abort_message,1)
+    endif    
+!
+! Lecture Albedo
+!
+    ierr = NF_INQ_VARID(nid, 'ALB', nvarid)
+    if (ierr /= NF_NOERR) then
+      abort_message = 'Le champ <ALB> est absent'
+      call abort_gcm(modname,abort_message,1)
+    endif
+#ifdef NC_DOUBLE
+    ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais, alb_lu)
+#else
+    ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais, alb_lu)
+#endif
+    if (ierr /= NF_NOERR) then
+      abort_message = 'Lecture echouee pour <ALB>'
+      call abort_gcm(modname,abort_message,1)
+    endif
+!
+! Lecture rugosité
+!
+    ierr = NF_INQ_VARID(nid, 'RUG', nvarid)
+    if (ierr /= NF_NOERR) then
+      abort_message = 'Le champ <RUG> est absent'
+      call abort_gcm(modname,abort_message,1)
+    endif
+#ifdef NC_DOUBLE
+    ierr = NF_GET_VARA_DOUBLE(nid,nvarid,start,epais, rug_lu)
+#else
+    ierr = NF_GET_VARA_REAL(nid,nvarid,start,epais, rug_lu)
+#endif
+    if (ierr /= NF_NOERR) then
+      abort_message = 'Lecture echouee pour <RUG>'
+      call abort_gcm(modname,abort_message,1)
+    endif
+
+!
+! Fin de lecture
+!
+    ierr = NF_CLOSE(nid)
+    deja_lu = .true.
+    jour_lu = jour
+  endif
+!
+! Recopie des variables dans les champs de sortie
+!
+  do ii = 1, knon
+    lmt_sst(ii) = sst_lu(knindex(ii))
+    lmt_alb(ii) = alb_lu(knindex(ii))
+    lmt_rug(ii) = rug_lu(knindex(ii))
+  enddo
+  pctsrf_new = pct_tmp
+
+  END SUBROUTINE interfoce_lim
+
+!
+!#########################################################################
+!
+
+  SUBROUTINE calcul_fluxs( knon, dtime, &
+     & tsurf, p1lay, cal, beta, coef1lay, ps, &
+     & radsol, dif_grnd, t1lay, q1lay, u1lay, v1lay, &
+     & petAcoef, peqAcoef, petBcoef, peqBcoef, &
+     & tsurf_new, fluxlat, fluxsens, dflux_s, dflux_l)
+
+! Cette routine calcule les fluxs en h et q a l'interface et eventuellement
+! une temperature de surface (au cas ou ok_veget = false)
+!
+! L. Fairhead 4/2000
+!
+! input:
+!   knon         nombre de points a traiter
+!   tsurf        temperature de surface
+!   p1lay        pression 1er niveau (milieu de couche)
+!   cal          capacite calorifique du sol
+!   beta         evap reelle
+!   coef1lay     coefficient d'echange
+!   ps           pression au sol
+!   petAcoef     coeff. A de la resolution de la CL pour t
+!   peqAcoef     coeff. A de la resolution de la CL pour q
+!   petBcoef     coeff. B de la resolution de la CL pour t
+!   peqBcoef     coeff. B de la resolution de la CL pour q
+!   radsol       rayonnement net aus sol (LW + SW)
+!   dif_grnd     coeff. diffusion vers le sol profond
+!
+! output:
+!   tsurf_new    temperature au sol
+!   fluxsens     flux de chaleur sensible
+!   fluxlat      flux de chaleur latente
+!   dflux_s      derivee du flux de chaleur sensible / Ts
+!   dflux_l      derivee du flux de chaleur latente  / Ts
+!
+
+#include "YOMCST.inc"
+#include "YOETHF.inc"
+#include "FCTTRE.inc"
+
+! Parametres d'entree
+  integer, intent(IN) :: knon
+  real   , intent(IN) :: dtime
+  real, dimension(knon), intent(IN) :: petAcoef, peqAcoef
+  real, dimension(knon), intent(IN) :: petBcoef, peqBcoef
+  real, dimension(knon), intent(IN) :: ps, q1lay
+  real, dimension(knon), intent(IN) :: tsurf, p1lay, cal, beta, coef1lay
+  real, dimension(knon), intent(IN) :: radsol, dif_grnd
+  real, dimension(knon), intent(IN) :: t1lay, u1lay, v1lay
+
+! Parametres sorties
+  real, dimension(knon), intent(OUT):: tsurf_new, fluxlat, fluxsens
+  real, dimension(knon), intent(OUT):: dflux_s, dflux_l
+
+! Variables locales
+  integer :: i
+  real, dimension(knon) :: zx_mh, zx_nh, zx_oh
+  real, dimension(knon) :: zx_mq, zx_nq, zx_oq
+  real, dimension(knon) :: zx_pkh, zx_dq_s_dt, zx_qsat, zx_coef
+  real, dimension(knon) :: zx_sl, zx_k1,  zx_dq,  zx_cq,  zx_dh, zx_ch
+  real, dimension(knon) :: zx_h_ts, zx_q_0 , d_ts
+  real                  :: zdelta, zcvm5, zx_qs, zcor, zx_dq_s_dh
+  real, parameter :: t_grnd = 271.35, t_coup = 273.15
+  logical         :: check = .true.
+  character (len = 20)  :: modname = 'calcul_fluxs'
+
+  if (check) write(*,*)'Entree ', modname
+! 
+! Initialisation
+!
+!
+! zx_qs = qsat en kg/kg
+!
+  DO i = 1, knon
+    zx_pkh(i) = (ps(i)/ps(i))**RKAPPA
+  IF (thermcep) THEN
+      zdelta=MAX(0.,SIGN(1.,rtt-tsurf(i)))
+      zcvm5 = R5LES*RLVTT*(1.-zdelta) + R5IES*RLSTT*zdelta
+      zcvm5 = zcvm5 / RCPD / (1.0+RVTMP2*q1lay(i))
+      zx_qs= r2es * FOEEW(tsurf(i),zdelta)/ps(i)
+      zx_qs=MIN(0.5,zx_qs)
+      zcor=1./(1.-retv*zx_qs)
+      zx_qs=zx_qs*zcor
+      zx_dq_s_dh = FOEDE(tsurf(i),zdelta,zcvm5,zx_qs,zcor) &
+     &                 /RLVTT / zx_pkh(i)
+    ELSE
+      IF (tsurf(i).LT.t_coup) THEN
+        zx_qs = qsats(tsurf(i)) / ps(i)
+        zx_dq_s_dh = dqsats(tsurf(i),zx_qs)/RLVTT &
+     &                    / zx_pkh(i)
+      ELSE
+        zx_qs = qsatl(tsurf(i)) / ps(i)
+        zx_dq_s_dh = dqsatl(tsurf(i),zx_qs)/RLVTT &
+     &               / zx_pkh(i)
+      ENDIF
+    ENDIF
+    zx_dq_s_dt(i) = RCPD * zx_pkh(i) * zx_dq_s_dh
+    zx_qsat(i) = zx_qs
+    zx_coef(i) = coef1lay(i) &
+     & * (1.0+SQRT(u1lay(i)**2+v1lay(i)**2)) &
+     & * p1lay(i)/(RD*t1lay(i))
+    
+  ENDDO
+
+
+! === Calcul de la temperature de surface ===
+! 
+! zx_sl = chaleur latente d'evaporation ou de sublimation
+!
+  do i = 1, knon
+    zx_sl(i) = RLVTT
+    if (tsurf(i) .LT. RTT) zx_sl(i) = RLSTT
+    zx_k1(i) = zx_coef(i)
+  enddo
+
+
+  do i = 1, knon
+! Q
+    zx_oq(i) = 1. - (beta(i) * zx_k1(i) * peqBcoef(i) * dtime)
+    zx_mq(i) = beta(i) * zx_k1(i) * &
+     &             (peqAcoef(i) - zx_qsat(i) &
+     &                          + zx_dq_s_dt(i) * tsurf(i)) &
+     &             / zx_oq(i)
+    zx_nq(i) = beta(i) * zx_k1(i) * (-1. * zx_dq_s_dt(i)) &
+     &                              / zx_oq(i)
+
+! H
+    zx_oh(i) = 1. - (zx_k1(i) * petBcoef(i) * dtime)
+    zx_mh(i) = zx_k1(i) * petAcoef(i) / zx_oh(i)
+    zx_nh(i) = - (zx_k1(i) * RCPD * zx_pkh(i))/ zx_oh(i)
+
+! Tsurface
+    tsurf_new(i) = (tsurf(i) + cal(i)/(RCPD * zx_pkh(i)) * dtime * &
+     &             (radsol(i) + zx_mh(i) + zx_sl(i) * zx_mq(i)) & 
+     &                 + dif_grnd(i) * t_grnd * dtime)/ &
+     &          ( 1. - dtime * cal(i)/(RCPD * zx_pkh(i)) * ( &
+     &                       zx_nh(i) + zx_sl(i) * zx_nq(i)) &  
+     &                     + dtime * dif_grnd(i))
+    zx_h_ts(i) = tsurf_new(i) * RCPD * zx_pkh(i)
+    d_ts(i) = tsurf_new(i) - tsurf(i)
+    zx_q_0(i) = zx_qsat(i) + zx_dq_s_dt(i) * d_ts(i)
+!== flux_q est le flux de vapeur d'eau: kg/(m**2 s)  positive vers bas
+!== flux_t est le flux de cpt (energie sensible): j/(m**2 s)
+    fluxlat(i) = zx_mq(i) + zx_nq(i) * tsurf_new(i) 
+    fluxsens(i) = zx_mh(i) + zx_nh(i) * tsurf_new(i)
+! Derives des flux dF/dTs (W m-2 K-1):
+    dflux_s(i) = zx_nh(i)
+    dflux_l(i) = (zx_sl(i) * zx_nq(i))
+  ENDDO
+
+  END SUBROUTINE calcul_fluxs
+!
+!#########################################################################
+!
+
+  END MODULE interface_surf
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/mpiclim.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/mpiclim.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/mpiclim.h	(revision 253)
@@ -0,0 +1,21 @@
+C
+C -- mpiclim.h  26-10-99   Version 2.4   Author: Jean Latour (F.S.E.)
+C    *********
+C@
+C@  Contents : variables related to MPI-2 message passing
+C@  --------
+C@
+C@ -- mpi_totproc: number of processors on which to launch each model
+C@
+C@ -- mpi_nproc: number of processors involved in the coupling for
+C@               each model
+C@ -- cmpi_modnam: models name
+C     -----------------------------------------------------------------
+C
+      INTEGER*4 mpi_totproc(1:CLIM_MaxMod-1),mpi_nproc(0:CLIM_MaxMod-1)
+C
+      CHARACTER*6 cmpi_modnam(1:CLIM_MaxMod-1)
+C
+      common/CLIM_mpiclim/mpi_totproc, mpi_nproc, cmpi_modnam 
+C
+C     -----------------------------------------------------------------
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/nuage.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/nuage.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/nuage.F	(revision 253)
@@ -37,6 +37,8 @@
       REAL zflwp, zradef, zfice, zmsac
 c
-      REAL radius, rad_froid, rad_chaud
-      PARAMETER (rad_chaud=10.0, rad_froid=30.0)
+      REAL radius, rad_froid, rad_chaud, rad_chau1, rad_chau2
+      PARAMETER (rad_chau1=13.0, rad_chau2=9.0, rad_froid=35.0)
+ccc      PARAMETER (rad_chaud=15.0, rad_froid=35.0)
+c sintex initial      PARAMETER (rad_chaud=10.0, rad_froid=30.0)
       REAL coef, coef_froi, coef_chau
       PARAMETER (coef_chau=0.13, coef_froi=0.09)
@@ -51,4 +53,6 @@
       DO k = 1, klev
       DO i = 1, klon
+         rad_chaud = rad_chau1
+         IF (k.LE.3) rad_chaud = rad_chau2
          pclc(i,k) = MAX(pclc(i,k), seuil_neb)
          zflwp = 1000.*pqlwp(i,k)/RG/pclc(i,k)
@@ -127,5 +131,5 @@
       RETURN
       END
-      SUBROUTINE diagcld(paprs,pplay,t,q,rain,snow,kbot,ktop,
+      SUBROUTINE diagcld1(paprs,pplay,rain,snow,kbot,ktop,
      .                   diafra,dialiq)
       IMPLICIT none
@@ -155,11 +159,4 @@
       REAL diafra(klon,klev) ! fraction nuageuse diagnostiquee
       REAL dialiq(klon,klev) ! eau liquide nuageuse
-c
-c Options a choisir:
-      LOGICAL ok_conv ! prendre en compte les nuages convectifs
-      PARAMETER (ok_conv=.TRUE.)
-      LOGICAL ok_inve ! prendre en compte les nuages d'inversion
-CCC      PARAMETER (ok_inve=.TRUE.)
-      PARAMETER (ok_inve=.FALSE.)
 c
 c Constantes ajustables:
@@ -177,23 +174,8 @@
       REAL ZEPSCR
       PARAMETER (ZEPSCR=1.0E-10)
-      REAL CLOIA, CLOIB, CLOIC, CLOID
-ccc      PARAMETER (CLOIA=1.0E+02, CLOIB=-10.00, CLOIC=-0.6, CLOID=5.0)
-      PARAMETER (CLOIA=1.0E+02, CLOIB=-10.00, CLOIC=-0.9, CLOID=5.0)
-      REAL RGAMMAS
-      PARAMETER (RGAMMAS=0.05)
-      REAL CRHL
-ccc      PARAMETER (CRHL=0.15)
-      PARAMETER (CRHL=0.70)
-      REAL t_coup
-      PARAMETER (t_coup=234.0)
 c
 c Variables locales:
-      INTEGER i, k, kb, invb(klon)
-      REAL zcc(klon), zqs, zrhb, zcll, zdthmin(klon), zdthdp
-      REAL zdelta, zcor
-c
-c Fonctions thermodynamiques:
-#include "YOETHF.h"
-#include "FCTTRE.h"
+      INTEGER i, k
+      REAL zcc(klon)
 c
 c Initialisation:
@@ -205,6 +187,4 @@
       ENDDO
       ENDDO
-c
-      IF (ok_conv) THEN
 c
       DO i = 1, klon ! Calculer la fraction nuageuse
@@ -215,13 +195,11 @@
       ENDIF
       ENDDO
-cn
+c
       DO i = 1, klon ! pour traiter les enclumes
-         diafra(i,ktop(i)) = zcc(i) * CCFCT
-ccc      diafra(i,ktop(i)) = MAX(diafra(i,ktop(i)),zcc(i)*CCFCT)
+      diafra(i,ktop(i)) = MAX(diafra(i,ktop(i)),zcc(i)*CCFCT)
       IF ((zcc(i).GE.CANVH) .AND.
      .    (pplay(i,ktop(i)).LE.CETAHB*paprs(i,1)))
-     .   diafra(i,ktop(i)) = MAX(zcc(i)*CCFCT,CANVA*(zcc(i)-CANVB))      
-cc     . diafra(i,ktop(i)) = MAX(diafra(i,ktop(i)),
-cc     .                         MAX(zcc(i)*CCFCT,CANVA*(zcc(i)-CANVB)))
+     . diafra(i,ktop(i)) = MAX(diafra(i,ktop(i)),
+     .                         MAX(zcc(i)*CCFCT,CANVA*(zcc(i)-CANVB)))
       dialiq(i,ktop(i))=CCLWMR*diafra(i,ktop(i))
       ENDDO
@@ -230,6 +208,5 @@
       DO i = 1, klon
       IF (k.LT.ktop(i) .AND. k.GE.kbot(i)) THEN
-           diafra(i,k)=zcc(i)*CCFCT
-cc         diafra(i,k)=MAX(diafra(i,k),zcc(i)*CCFCT)
+         diafra(i,k)=MAX(diafra(i,k),zcc(i)*CCFCT)
          dialiq(i,k)=CCLWMR*diafra(i,k)
       ENDIF
@@ -237,8 +214,54 @@
       ENDDO
 c
-      ENDIF ! ok_conv
-c
-      IF (ok_inve) THEN
-
+      RETURN
+      END
+      SUBROUTINE diagcld2(paprs,pplay,t,q, diafra,dialiq)
+      IMPLICIT none
+c
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+c
+c Arguments d'entree:
+      REAL paprs(klon,klev+1) ! pression (Pa) a inter-couche
+      REAL pplay(klon,klev) ! pression (Pa) au milieu de couche
+      REAL t(klon,klev) ! temperature (K)
+      REAL q(klon,klev) ! humidite specifique (Kg/Kg)
+c
+c Arguments de sortie:
+      REAL diafra(klon,klev) ! fraction nuageuse diagnostiquee
+      REAL dialiq(klon,klev) ! eau liquide nuageuse
+c
+      REAL CETAMB
+      PARAMETER (CETAMB=0.80)
+      REAL CLOIA, CLOIB, CLOIC, CLOID
+      PARAMETER (CLOIA=1.0E+02, CLOIB=-10.00, CLOIC=-0.6, CLOID=5.0)
+ccc      PARAMETER (CLOIA=1.0E+02, CLOIB=-10.00, CLOIC=-0.9, CLOID=5.0)
+      REAL RGAMMAS
+      PARAMETER (RGAMMAS=0.05)
+      REAL CRHL
+      PARAMETER (CRHL=0.15)
+ccc      PARAMETER (CRHL=0.70)
+      REAL t_coup
+      PARAMETER (t_coup=234.0)
+c
+c Variables locales:
+      INTEGER i, k, kb, invb(klon)
+      REAL zqs, zrhb, zcll, zdthmin(klon), zdthdp
+      REAL zdelta, zcor
+c
+c Fonctions thermodynamiques:
+#include "YOETHF.h"
+#include "FCTTRE.h"
+c
+c Initialisation:
+c
+      DO k = 1, klev
+      DO i = 1, klon
+         diafra(i,k) = 0.0
+         dialiq(i,k) = 0.0
+      ENDDO
+      ENDDO
+c
       DO i = 1, klon
          invb(i) = klev
@@ -280,11 +303,8 @@
      .   zcll=zcll*(1.-(CRHL-zrhb)*CLOID)
          zcll=MIN(1.0,MAX(0.0,zcll))
-cc         diafra(i,kb) = MAX(diafra(i,kb),zcll)
-cc         dialiq(i,kb)= diafra(i,kb) * RGAMMAS*zqs
-         diafra(i,kb) = zcll
-         dialiq(i,kb)= zcll* RGAMMAS*zqs        
-      ENDDO
-c
-      ENDIF ! ok_inve
-c
+         diafra(i,kb) = MAX(diafra(i,kb),zcll)
+         dialiq(i,kb)= diafra(i,kb) * RGAMMAS*zqs
+      ENDDO
+c
+      RETURN
       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/oasis.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.F	(revision 253)
@@ -1,9 +1,2 @@
-      SUBROUTINE inicma(kastp,kexch,kstep)
-      IMPLICIT none
-c
-      INTEGER kastp, kexch, kstep
-c
-      INTEGER ime
-      PARAMETER (ime = 1)
 c
 C****
@@ -45,10 +38,14 @@
 C     -----------------------------------------------------------
 C
-      INTEGER imess(4)
-      INTEGER getpid, mknod ! system functions
-      CHARACTER*80 clcmd
-      CHARACTER*8 pipnom, fldnom
-      INTEGER ierror
-C
+      SUBROUTINE inicma(kastp,kexch,kstep)
+c
+      INTEGER kastp, kexch, kstep
+c
+      INTEGER ime
+      PARAMETER (ime = 1)
+
+      INTEGER iparal(3)
+      INTEGER ifcpl, idt, info, imxtag, istep
+c
 #include "dimensions.h"
 #include "dimphy.h"
@@ -56,11 +53,26 @@
 #include "clim.h"
 c
-      INTEGER iparal(3)
-      INTEGER istep, ifcpl, idt, info, imxtag
-c
-      INTEGER mode, iret, isize
+c     Addition for SIPC CASE
+#include "param_sipc.h"
+#include "param_cou.h"
+#include "inc_sipc.h"
+#include "inc_cpl.h"
+      CHARACTER*9 clpoolnam 
+      INTEGER ipoolhandle, imrc, ipoolsize, index, jf
+      CHARACTER*3 cljobnam      ! experiment name
+      CHARACTER*6 clmodnam      ! model name
+      CHARACTER*5 cloasis       ! coupler name (Oasis)
+      INTEGER imess(4), imesso(4)
+      INTEGER getpid, mknod ! system functions
+      CHARACTER*80 clcmd
+      CHARACTER*8 pipnom, fldnom
+      INTEGER ierror, iretcode
 C
       INTEGER nuout
       PARAMETER (nuout = 6)
+c
+C
+c
+
 C     -----------------------------------------------------------
 C
@@ -75,765 +87,421 @@
       WRITE(nuout,*) ' '
 c
-      IF (cchain.EQ."PIPE") THEN
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Making pipes for fields to receive from CPL"
-      WRITE(nuout,*) " "
-c
-c zxli(le17fev97): je ne comprends pas pourquoi il faut
-c                  avoir 2 noms pour un seul pipe
-c
-      pipnom = "SISUTESU"
-      fldnom = "Sisutesu"
-#ifdef CRAY
-      clcmd = "assign -s unblocked -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "SIALBEDO"
-      fldnom = "Sialbedo"
-#ifdef CRAY
-      clcmd = "assign -s unblocked -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "SIICECOV"
-      fldnom = "Siicecov"
-#ifdef CRAY
-      clcmd = "assign -s unblocked -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "SIICEALB"
-      fldnom = "Siicealb"
-#ifdef CRAY
-      clcmd = "assign -s unblocked -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Making pipes for fields to send to CPL"
-      WRITE(nuout,*) " "
-c
-      pipnom = "CONSFTOT"
-      fldnom = "Consftot"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COSSTSST"
-      fldnom = "Cosstsst"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "CODFLXDT"
-      fldnom = "Codflxdt"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COSHFTOT"
-      fldnom = "Coshftot"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COALBSUR"
-      fldnom = "Coalbsur"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COTOSPSU"
-      fldnom = "Cotospsu"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COTOLPSU"
-      fldnom = "Cotolpsu"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COTFSHSU"
-      fldnom = "Cotfshsu"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "CORUNCOA"
-      fldnom = "Coruncoa"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "CORIVFLU"
-      fldnom = "Corivflu"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COZOTAUX"
-      fldnom = "Cozotaux"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COMETAUY"
-      fldnom = "Cometauy"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COZOTAU2"
-      fldnom = "Cozotau2"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      pipnom = "COMETAU2"
-      fldnom = "Cometau2"
-#ifdef CRAY
-      clcmd = "assign -s u -a "//pipnom//" f:"//fldnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-      WRITE(nuout,'(a80)') clcmd
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-      WRITE(nuout,'(a80)') clcmd
-#endif
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "All pipes have been made"
-      WRITE(nuout,*) " "
-      CALL flush(nuout)
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Communication test between ATM and CPL"
-      WRITE(nuout,*) " "
-c
-      WRITE (pipnom,'(a6,i2.2)') "Preadm", ime
-#ifdef CRAY
-      clcmd = "assign -s u f:"//pipnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-#endif
-      WRITE(nuout,'(a80)') clcmd
+c     1.2.1-Define the model name
+c
+      clmodnam = 'lmd.xx'       ! as $NBMODEL in namcouple
+c
+c     1.2.2-Define the coupler name
+c
+      cloasis = 'Oasis'        !  as in coupler
+c
+c
+c     1.3.1-Define symbolic name for fields exchanged from atmos to coupler,
+c         must be the same as (1) of the field  definition in namcouple:
+c
+      cl_writ(1)='CONSFTOT'
+      cl_writ(2)='COSHFTOT'
+      cl_writ(3)='COTOPRSU'
+      cl_writ(4)='COTFSHSU'
+      cl_writ(5)='CORUNCOA'
+      cl_writ(6)='CORIVFLU'
+      cl_writ(7)='COZOTAUX'
+      cl_writ(8)='COZOTAU2'
+      cl_writ(9)='COMETAUY'
+      cl_writ(10)='COMETAU2'
+c
+c     1.3.2-Define files name for fields exchanged from atmos to coupler,
+c         must be the same as (6) of the field  definition in namcouple:
+c
+      cl_f_writ(1)='atmflx'
+      cl_f_writ(2)='atmflx'
+      cl_f_writ(3)='atmflx'
+      cl_f_writ(4)='atmflx'
+      cl_f_writ(5)='atmflx'
+      cl_f_writ(6)='atmflx'
+      cl_f_writ(7)='atmtau'
+      cl_f_writ(8)='atmtau'
+      cl_f_writ(9)='atmtau'
+      cl_f_writ(10)='atmtau'
+c
+c
+c     1.4.1-Define symbolic name for fields exchanged from coupler to atmosphere,
+c         must be the same as (2) of the field  definition in namcouple:
+c
+      cl_read(1)='SISUTESU'
+      cl_read(2)='SIICECOV'
+c
+c     1.4.2-Define files names for fields exchanged from coupler to atmosphere,
+c         must be the same as (7) of the field  definition in namcouple:
+c
+      cl_f_read(1)='atmsst'
+      cl_f_read(2)='atmice'
+c
+c     1.5-Define infos for sending to oasis
+c
       imess(1) = kastp
       imess(2) = kexch
       imess(3) = kstep
       imess(4) = getpid()
-#ifdef CRAY
-      WRITE (pipnom) imess ! send message to pipe
-#else
-      iret=0
-      isize=4
-      CALL pipwrite(pipnom, imess, isize, iret)
-#endif
-      WRITE(nuout,*) "Msg sent to pipe "//pipnom
-      CALL flush(nuout)
-c
-      WRITE (pipnom,'(a6,i2.2)') "Pwritm", ime
-#ifdef CRAY
-      clcmd = "assign -s unblocked f:"//pipnom
-      CALL assign(clcmd, ierror)
-      ierror = mknod (pipnom, 4480, 0)
-#else
-      clcmd = "CALL makepipe("//pipnom//",...,...)"
-      mode = o'010600'
-      iret = 0
-      CALL makepipe(pipnom, mode, iret)
-#endif
-      WRITE(nuout,'(a80)') clcmd
-c
-      WRITE(nuout,*) "Waiting for the pipe "//pipnom
-      CALL flush(nuout)
-#ifdef CRAY
-      READ (pipnom) imess ! read message from pipe
-#else
-      isize=1
-      iret =0
-      CALL pipread(pipnom,imess,isize,iret)
-#endif
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Communication test between ATM and CPL is OK"
-      WRITE(nuout,*) " total simulation time in oasis = ", imess(1)
-      WRITE(nuout,*) " total number of iterations is  = ", imess(2)
-      WRITE(nuout,*) " value of oasis timestep  is    = ", imess(3)
-      WRITE(nuout,*) " process id for oasis  is       = ", imess(4)
-      WRITE(nuout,*) " "
-      CALL flush(nuout)
-c
-      ELSE ! cchain.EQ."CLIM"
-c
-      CALL CLIM_Init ( 'CLI', 'lmd.xx', 3, 7,
+
+c
+c
+      IF (cchan.eq.'PIPE') THEN 
+c
+          ierror=0
+c
+c
+          WRITE(nuout,*) ' '
+          WRITE(nuout,*) 'Making pipes for fields to receive from CPL'
+          WRITE(nuout,*) ' '
+c
+c loop to define pipes (ocean=CPL to atmos)
+c
+          DO jf=1, jpfldo2a
+            CALL PIPE_Model_Define(nuout, cl_read(jf), jpread, iretcode)
+            IF (iretcode.ne.0) ierror=ierror+1
+          END DO 
+c
+          WRITE(nuout,*) ' '
+          WRITE(nuout,*) 'Making pipes for fields to send to CPL'
+          WRITE(nuout,*) ' '
+c
+c loop to define pipes (atmos to ocean=CPL)
+c
+          DO jf=1, jpflda2o
+            CALL PIPE_Model_Define(nuout, cl_writ(jf), jpwrit, iretcode)
+            IF (iretcode.ne.0) ierror=ierror+1
+          END DO 
+c
+          IF (ierror.ne.0) THEN
+              WRITE (nuout,*) 'Error in pipes definitions'
+              WRITE (nuout,*) 'STOP inicma'
+              CALL abort
+          END IF 
+c
+          WRITE(nuout,*) ' '
+          WRITE(nuout,*) 'All pipes have been made'
+          WRITE(nuout,*) ' '
+c
+          WRITE(nuout,*) ' '
+          WRITE(nuout,*) 'Communication test between ATM and CPL'
+          WRITE(nuout,*) ' '
+          CALL flush(nuout)
+c
+          CALL PIPE_Model_Stepi(nuout, imess, ime, imesso, ierror)
+c
+          IF (ierror.ne.0) THEN
+              WRITE (nuout,*)
+     $            'Error in exchange first informations with Oasis' 
+              WRITE (nuout,*) 'STOP inicma'
+              CALL abort
+          END IF 
+c
+          WRITE(nuout,*) ' '
+          WRITE(nuout,*) 'Communication test between ATM and CPL is OK'
+          WRITE(nuout,*) ' total simulation time in oasis = ', imesso(1)
+          WRITE(nuout,*) ' total number of iterations is  = ', imesso(2)
+          WRITE(nuout,*) ' value of oasis timestep  is    = ', imesso(3)
+          WRITE(nuout,*) ' process id for oasis  is       = ', imesso(4)
+          WRITE(nuout,*) ' '
+          CALL flush(nuout)
+c
+      ELSE  IF (cchan.eq.'SIPC') THEN
+c
+c debug for more information
+c
+c          CALL SVIPC_debug(1)
+c  
+c
+c     1.1-Define the experiment name :
+c
+          cljobnam = 'IPC'      ! as $JOBNAM in namcouple
+c
+c         3-Attach to shared memory pool used to exchange initial infos 
+c
+          imrc = 0
+          CALL SIPC_Init_Model (cljobnam, clmodnam, 1, imrc)
+          IF (imrc .NE. 0) THEN 
+            WRITE (nuout,*)'   '
+            WRITE (nuout,*)'WARNING: Problem with attachement to', imrc 
+            WRITE (nuout,*)'         initial memory pool(s) in atmos'
+            WRITE (nuout,*)'   '
+            CALL ABORT('STOP in atmos')
+          ENDIF
+c
+c         4-Attach to pools used to exchange fields from atmos to coupler
+c
+ 	  DO jf = 1, jpflda2o
+c
+C
+c           Pool name:
+            clpoolnam = 'P'//cl_writ(jf)
+C
+            CALL SIPC_Attach(clpoolnam, ipoolhandle)
+c     
+c           Resulting pool handle:
+            mpoolwrit(jf) = ipoolhandle  
+C
+            END DO 
+C
+c         5-Attach to pools used to exchange fields from coupler to atmos
+c
+          DO jf = 1, jpfldo2a
+c
+c           Pool name:
+            clpoolnam = 'P'//cl_read(jf)
+c
+            CALL SIPC_Attach(clpoolnam, ipoolhandle)
+c
+c           Resulting pool handle:
+            mpoolread(jf) = ipoolhandle  
+c
+          END DO 
+c
+c         6-Exchange of initial infos
+c
+c         Write data array isend to pool READ by Oasis
+c
+          imrc = 0
+          ipoolsize = 4*jpbyteint
+          CALL SVIPC_Write(mpoolinitr, imess, ipoolsize, imrc)
+C
+C         Find error if any
+C
+          IF (imrc .LT. 0) THEN
+              WRITE (nuout,*) '   '
+              WRITE (nuout,*) 'Problem in atmos in writing initial' 
+              WRITE (nuout,*) 'infos to the shared memory segment(s)'
+              WRITE (nuout,*) '   '
+          ELSE
+              WRITE (nuout,*) '   '
+              WRITE (nuout,*) 'Initial infos written in atmos'            
+              WRITE (nuout,*) 'to the shared memory segment(s)'
+              WRITE (nuout,*) '   '
+          ENDIF
+C
+C         Read data array irecv from pool written by Oasis
+C
+          imrc = 0
+          ipoolsize = 4*jpbyteint
+          CALL SVIPC_Read(mpoolinitw, imesso, ipoolsize, imrc)
+C
+C*        Find error if any
+C
+          IF (imrc .LT. 0) THEN
+              WRITE (nuout,*) '   '
+              WRITE (nuout,*) 'Problem in atmos in reading initial' 
+              WRITE (nuout,*) 'infos from the shared memory segment(s)'
+              WRITE (nuout,*) '   '
+          ELSE
+              WRITE (nuout,*) '   '
+              WRITE (nuout,*) 'Initial infos read by atmos'                
+              WRITE (nuout,*) 'from the shared memory segment(s)'
+              WRITE (nuout,*) '   '
+              WRITE(*,*) ' ntime, niter, nstep, Oasis pid:'
+              WRITE(*,*) imesso(1), imesso(2), imesso(3), imesso(4) 
+          ENDIF
+C
+C         Detach from shared memory segment(s)
+C
+          imrc = 0
+          CALL SVIPC_close(mpoolinitw, 0, imrc)
+C
+C         Find error if any
+C
+          IF (imrc .LT. 0) THEN
+              WRITE (nuout,*) 
+     $          'Problem in detaching from shared memory segment(s)'
+              WRITE (nuout,*)
+     $          'used by atmos to read initial infos' 
+          ENDIF
+c
+c
+      ELSE IF (cchan.eq.'CLIM') THEN
+
+c
+c     1.1-Define the experiment name :
+c
+          cljobnam = 'CLI'      ! as $JOBNAM in namcouple
+
+          OPEN ( UNIT = 7, FILE = 'trace', STATUS = 'unknown',
+     $          FORM = 'formatted')
+          CALL CLIM_Init ( cljobnam, clmodnam, 3, 7,
      *                 kastp, kexch, kstep,
-     *                 5, 1200, 300, info )
-      IF (info.EQ.CLIM_Ok) THEN
-         WRITE(nuout,*) "inicma: CLIM_Init OK"
-      ELSE
-         WRITE(nuout,*) "inicma: CLIM_Init erreur:", info
-         CALL ABORT("STOP in inicma")
-      ENDIF
-c
-      iparal ( CLIM_Strategy ) = CLIM_Serial
-      iparal ( CLIM_Length   ) = iim*(jjm+1)
-      iparal ( CLIM_Offset   ) = 0
-c
-      CALL CLIM_Define ('SISUTESU', CLIM_In , CLIM_Double, iparal, info)
-      CALL CLIM_Define ('SIALBEDO', CLIM_In , CLIM_Double, iparal, info)
-      CALL CLIM_Define ('SIICECOV', CLIM_In , CLIM_Double, iparal, info)
-      CALL CLIM_Define ('SIICEALB', CLIM_In , CLIM_Double, iparal, info)
-c
-      CALL CLIM_Define ('CONSFTOT', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COSSTSST', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('CODFLXDT', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COSHFTOT', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COALBSUR', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COTOSPSU', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COTOLPSU', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COTFSHSU', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('CORUNCOA', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('CORIVFLU', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COZOTAUX', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COMETAUY', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COZOTAU2', CLIM_Out , CLIM_Double, iparal,info)
-      CALL CLIM_Define ('COMETAU2', CLIM_Out , CLIM_Double, iparal,info)
-      WRITE(nuout,*) 'inicma : CLIM_Define ok '
-c
-      CALL CLIM_Start ( imxtag, info )
-      IF (info.NE.CLIM_Ok) THEN
-          WRITE (nuout,*) "inicma: CLIM_Start pb. ", info
-          CALL ABORT("STOP in inicma")
-      ELSE
-          WRITE (nuout,*)  "inicma: CLIM_Start OK"
-      ENDIF
-c
-      CALL CLIM_Stepi ("oasis", istep, ifcpl, idt, info)
-      IF (info .NE. CLIM_Ok) THEN
-          WRITE (nuout,*) "inicma: CLIM_Stepi pb. ", info
-          CALL ABORT("STOP in inicma")
-      ELSE
-          WRITE (nuout,*) "inicma: CLIM_Stepi OK"
-          WRITE (nuout,*) " number of tstep in oasis ", istep
-          WRITE (nuout,*) " exchange frequency in oasis ", ifcpl
-          WRITE (nuout,*) " length of tstep in oasis ", idt
-      ENDIF
-c
-      ENDIF
-c
-      RETURN
-      END
-      SUBROUTINE fromcpl(jour, imjm, sst, sic, alb_sst, alb_sic)
+     *                 5, 3600, 3600, info )
+c
+          IF (info.ne.clim_ok) THEN
+              WRITE ( nuout, *) ' inicma : pb init clim '
+              WRITE ( nuout, *) ' error code is = ', info
+              CALL abort('STOP in inicma')
+            ELSE
+              WRITE(nuout,*) 'inicma : init clim ok '
+          ENDIF
+c
+          iparal ( clim_strategy ) = clim_serial
+          iparal ( clim_length   ) = iim*(jjm+1)
+          iparal ( clim_offset   ) = 0
+c
+c loop to define messages (CPL=ocean to atmos)
+c
+          DO jf=1, jpfldo2a
+            CALL CLIM_Define (cl_read(jf), clim_in , clim_double, iparal
+     $          , info )  
+          END DO 
+
+c
+c loop to define messages (atmos to ocean=CPL)
+c
+          DO jf=1, jpflda2o
+            CALL CLIM_Define (cl_writ(jf), clim_out , clim_double,
+     $          iparal, info )   
+          END DO 
+
+          WRITE(nuout,*) 'inicma : clim_define ok '
+          CALL CLIM_Start ( imxtag, info )
+          IF (info.ne.clim_ok) THEN
+              WRITE ( nuout, *) 'inicma : pb start clim '
+              WRITE ( nuout, *) ' error code is = ', info
+              CALL abort('stop in inicma')
+            ELSE
+              WRITE ( nuout, *)  'inicma : start clim ok '
+          ENDIF
+c
+          CALL CLIM_Stepi (cloasis, istep, ifcpl, idt, info)
+          IF (info .NE. clim_ok) THEN
+              WRITE ( UNIT = nuout, FMT = *)
+     $            ' warning : problem in getting step info ',
+     $            'from oasis '
+              WRITE (UNIT = nuout, FMT = *)
+     $            ' =======   error code number = ', info
+            ELSE
+              WRITE (UNIT = nuout, FMT = *)
+     $            ' got step information from oasis '
+          ENDIF
+          WRITE ( nuout, *) ' number of tstep in oasis ', istep
+          WRITE ( nuout, *) ' exchange frequency in oasis ', ifcpl
+          WRITE ( nuout, *) ' length of tstep in oasis ', idt
+      ENDIF 
+
+      RETURN
+      END
+
+      SUBROUTINE fromcpl(kt, imjm, sst, gla)
       IMPLICIT none
 c
 c Laurent Z.X Li (Feb. 10, 1997): It reads the SST and Sea-Ice
 c provided by the coupler. Of course, it waits until it receives
-c the signal from the corresponding pipes in the case of utilizing
-c the pipe technique.
-c
-      INTEGER imjm, jour
-      REAL sst(imjm)      ! sea surface temperature
-      REAL alb_sst(imjm)  ! open sea albedo
-      REAL sic(imjm)      ! sea ice cover
-      REAL alb_sic(imjm)  ! sea ice albedo
-c
-      INTEGER nuout   ! listing output unit
+c the signal from the corresponding pipes.
+c 3 techniques:
+c  - pipes and signals (only on Cray C90 and Cray J90)
+c  - CLIM (PVM exchange messages)
+c  - SVIPC shared memory segments and semaphores
+c
+      INTEGER imjm, kt
+      REAL sst(imjm)          ! sea-surface-temperature
+      REAL gla(imjm)          ! sea-ice
+c
+      INTEGER nuout             ! listing output unit
       PARAMETER (nuout=6)
 c
       INTEGER nuread, ios, iflag, icpliter
-      CHARACTER*8 pipnom ! name for the pipe
-      CHARACTER*8 fldnom ! name for the field
-      CHARACTER*8 filnom ! name for the data file
+      CHARACTER*8 pipnom        ! name for the pipe
+      CHARACTER*8 fldnom        ! name for the field
+      CHARACTER*8 filnom        ! name for the data file
+
+      INTEGER info, jf
+
 c
 #include "oasis.h"
 #include "clim.h"
-      INTEGER info, jktm1
-      INTEGER iret, isize
-c
-      WRITE (nuout,*) " "
-      WRITE (nuout,*) "Fromcpl: Read fields from CPL"
-      WRITE (nuout,*) " "
+c
+#include "param_cou.h"
+c
+#include "inc_sipc.h"
+#include "inc_cpl.h"
+c
+c     Addition for SIPC CASE
+      INTEGER index
+      CHARACTER*3 cmodinf       ! Header or not
+      CHARACTER*3 cljobnam_r    ! Experiment name in the field brick, if any 
+      INTEGER infos(3)          ! infos in the field brick, if any
+c
+c
+      WRITE (nuout,*) ' '
+      WRITE (nuout,*) 'Fromcpl: Read fields from CPL, kt=',kt
+      WRITE (nuout,*) ' '
       CALL flush (nuout)
-c
-      IF (cchain.EQ."PIPE") THEN
-c
-c sea-surface-temperature:
-c
-      pipnom = "Sisutesu"
-      fldnom = "SISUTESU"
-      filnom = "atmsst"
-      WRITE (nuout,*) "Waiting for the pipe "//pipnom
-      CALL flush (nuout)
-#ifdef CRAY
-      READ (pipnom) icpliter
-#else
-      iret = 0
-      isize = 1
-      CALL pipread(pipnom, icpliter, isize, iret)
-#endif
-      WRITE (nuout,*) "Ready to read "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      nuread = 99
-      OPEN(nuread, FILE=filnom, FORM='unformatted', IOSTAT=ios)
-      IF (ios .NE. 0) THEN
-          WRITE(nuout,*) "Error while connecting "//filnom, nuread
-          CALL flush (nuout)
-          CALL ABORT("STOP in Fromcpl")
-      ENDIF
-      REWIND (UNIT = nuread)
-      WRITE(nuout,*) "Reading "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      CALL locread(fldnom, sst, imjm, nuread, iflag)
-      IF (iflag .NE. 0) THEN
-          WRITE(nuout,*) "Pb in reading "//fldnom//" from "//filnom
-          WRITE(nuout,*) "jour, iflag = ", jour, iflag
-          CALL flush (nuout)
-          CALL ABORT('STOP in Fromcpl')
-      ENDIF
-      CLOSE(nuread)
-      WRITE(nuout,*) "Succesful for reading "//fldnom
-      CALL flush (nuout)
-c
-c open sea albedo:
-c
-      pipnom = "Sialbedo"
-      fldnom = "SIALBEDO"
-      filnom = "atmice"
-      WRITE (nuout,*) "Waiting for the pipe "//pipnom
-      CALL flush (nuout)
-#ifdef CRAY
-      READ (pipnom) icpliter
-#else
-      iret = 0
-      isize = 1
-      CALL pipread(pipnom, icpliter, isize, iret)
-#endif
-      WRITE (nuout,*) "Ready to read "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      nuread = 99
-      OPEN(nuread, FILE=filnom, FORM='unformatted', IOSTAT=ios)
-      IF (ios .NE. 0) THEN
-          WRITE(nuout,*) "Error while connecting "//filnom, nuread
-          CALL flush (nuout)
-          CALL ABORT("STOP in Fromcpl")
-      ENDIF
-      REWIND (UNIT = nuread)
-      WRITE(nuout,*) "Reading "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      CALL locread(fldnom, alb_sst, imjm, nuread, iflag)
-      IF (iflag .NE. 0) THEN
-          WRITE(nuout,*) "Pb in reading "//fldnom//" from "//filnom
-          WRITE(nuout,*) "jour, iflag = ", jour, iflag
-          CALL flush (nuout)
-          CALL ABORT('STOP in Fromcpl')
-      ENDIF
-      CLOSE(nuread)
-      WRITE(nuout,*) "Succesful for reading "//fldnom
-      CALL flush (nuout)
-c
-c sea-ice cover:
-c
-      pipnom = "Siicecov"
-      fldnom = "SIICECOV"
-      filnom = "atmice"
-      WRITE (nuout,*) "Waiting for the pipe "//pipnom
-      CALL flush (nuout)
-#ifdef CRAY
-      READ (pipnom) icpliter
-#else
-      iret = 0
-      isize = 1
-      CALL pipread(pipnom, icpliter, isize, iret)
-#endif
-      WRITE (nuout,*) "Ready to read "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      nuread = 99
-      OPEN(nuread, FILE=filnom, FORM='unformatted', IOSTAT=ios)
-      IF (ios .NE. 0) THEN
-          WRITE(nuout,*) "Error while connecting "//filnom, nuread
-          CALL flush (nuout)
-          CALL ABORT("STOP in Fromcpl")
-      ENDIF
-      REWIND (UNIT = nuread)
-      WRITE(nuout,*) "Reading "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      CALL locread(fldnom, sic, imjm, nuread, iflag)
-      IF (iflag .NE. 0) THEN
-          WRITE(nuout,*) "Pb in reading "//fldnom//" from "//filnom
-          WRITE(nuout,*) "jour, iflag = ", jour, iflag
-          CALL flush (nuout)
-          CALL ABORT('STOP in Fromcpl')
-      ENDIF
-      CLOSE(nuread)
-      WRITE(nuout,*) "Succesful for reading "//fldnom
-      CALL flush (nuout)
-c
-c sea-ice albedo:
-c
-      pipnom = "Siicealb"
-      fldnom = "SIICEALB"
-      filnom = "atmice"
-      WRITE (nuout,*) "Waiting for the pipe "//pipnom
-      CALL flush (nuout)
-#ifdef CRAY
-      READ (pipnom) icpliter
-#else
-      iret = 0
-      isize = 1
-      CALL pipread(pipnom, icpliter, isize, iret)
-#endif
-      WRITE (nuout,*) "Ready to read "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      nuread = 99
-      OPEN(nuread, FILE=filnom, FORM='unformatted', IOSTAT=ios)
-      IF (ios .NE. 0) THEN
-          WRITE(nuout,*) "Error while connecting "//filnom, nuread
-          CALL flush (nuout)
-          CALL ABORT("STOP in Fromcpl")
-      ENDIF
-      REWIND (UNIT = nuread)
-      WRITE(nuout,*) "Reading "//fldnom//" from "//filnom
-      CALL flush (nuout)
-      CALL locread(fldnom, alb_sic, imjm, nuread, iflag)
-      IF (iflag .NE. 0) THEN
-          WRITE(nuout,*) "Pb in reading "//fldnom//" from "//filnom
-          WRITE(nuout,*) "jour, iflag = ", jour, iflag
-          CALL flush (nuout)
-          CALL ABORT('STOP in Fromcpl')
-      ENDIF
-      CLOSE(nuread)
-      WRITE(nuout,*) "Succesful for reading "//fldnom
-      CALL flush (nuout)
-c
-      ELSE ! cchain.EQ."CLIM"
-c
-      jktm1=jour-1
-c
-      CALL CLIM_Import ('SISUTESU', jktm1, sst, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE(nuout,*)'Pb in reading ', 'SISUTESU'
-         WRITE(nuout,*)'Atmosphere jour is = ',jour
-         WRITE(nuout,*)'Couplage kt is = ',jktm1
-         WRITE(nuout,*)'CLIM error code is = ', info
-         WRITE(nuout,*)'STOP in Fromcpl'
-         CALL abort
-      ENDIF
-c
-      CALL CLIM_Import ('SIALBEDO', jktm1, alb_sst, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE(nuout,*)'Pb in reading ', 'SIALBEDO'
-         WRITE(nuout,*)'Atmosphere jour is = ',jour
-         WRITE(nuout,*)'Couplage kt is = ',jktm1
-         WRITE(nuout,*)'CLIM error code is = ', info
-         WRITE(nuout,*)'STOP in Fromcpl'
-         CALL abort
-      ENDIF
-c
-      CALL CLIM_Import ('SIICECOV', jktm1, sic, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE(nuout,*)'Pb in reading ', 'SIICECOV'
-         WRITE(nuout,*)'Atmosphere jour is = ',jour
-         WRITE(nuout,*)'Couplage kt is = ',jktm1
-         WRITE(nuout,*)'CLIM error code is = ', info
-         WRITE(nuout,*)'STOP in Fromcpl'
-         CALL abort
-      ENDIF
-c
-      CALL CLIM_Import ('SIICEALB', jktm1, alb_sic, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE(nuout,*)'Pb in reading ', 'SIICEALB'
-         WRITE(nuout,*)'Atmosphere jour is = ',jour
-         WRITE(nuout,*)'Couplage kt is = ',jktm1
-         WRITE(nuout,*)'CLIM error code is = ', info
-         WRITE(nuout,*)'STOP in Fromcpl'
-         CALL abort
-      ENDIF
-c
-      ENDIF ! fin de test sur cchain
-c
-      RETURN
-      END
-
-      SUBROUTINE locread (cdfldn, pfield, kdimax, knulre, kflgre)
-      IMPLICIT none
-      INTEGER kdimax, knulre, kflgre
-C****
-C               *****************************
-C               * OASIS ROUTINE  -  LEVEL 0 *
-C               * -------------     ------- *
-C               *****************************
-C
-C**** *locread*  - Read binary field on unit knulre
-C
-C     Purpose:
-C     -------
-C     Find string cdfldn on unit knulre and read array pfield
-C
-C**   Interface:
-C     ---------
-C       *CALL*  *locread (cdfldn, pfield, kdimax, knulre, kflgre)*
-C
-C     Input:
-C     -----
-C                cdfldn : character string locator
-C                kdimax : dimension of field to be read 
-C                knulre : logical unit to be read 
-C
-C     Output:
-C     ------
-C                pfield : field array (real 1D)
-C                kflgre : error status flag
-C
-C     Workspace:
-C     ---------
-C     None
-C
-C     Externals:
-C     ---------
-C     None
-C
-C     Reference:
-C     ---------
-C     See OASIS manual (1995) 
-C
-C     History:
-C     -------
-C       Version   Programmer     Date      Description
-C       -------   ----------     ----      -----------  
-C       2.0       L. Terray      95/09/01  created
-C
-C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-C
-C* ---------------------------- Include files ---------------------------
-C
-C
-C* ---------------------------- Argument declarations -------------------
-C
-      REAL pfield(kdimax)
-      CHARACTER*8 cdfldn
-C
-C* ---------------------------- Local declarations ----------------------
-C
-      CHARACTER*8 clecfl
-      INTEGER nulou
-c
-      nulou = 6
-C
-C* ---------------------------- Poema verses ----------------------------
-C
-C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-C
-C*    1. Initialization
-C        --------------
-C
-c     WRITE (UNIT = nulou,FMT = *) ' '
-c     WRITE (UNIT = nulou,FMT = *) ' '
-c     WRITE (UNIT = nulou,FMT = *) 
-c    $    '           ROUTINE locread  -  Level 0'
-c     WRITE (UNIT = nulou,FMT = *) 
-c    $    '           ***************     *******'
-c     WRITE (UNIT = nulou,FMT = *) ' '
-c     WRITE (UNIT = nulou,FMT = 1001) knulre
-c     WRITE (UNIT = nulou,FMT = *) ' '
-C
-C* Formats
-C
- 1001 FORMAT(5X,' Read binary file connected to unit = ',I3)
-C
-C     2. Find field in file
-C        ------------------
-C
-      REWIND knulre
- 200  CONTINUE
-C* Find string
-      READ (UNIT = knulre, ERR = 210, END = 210) clecfl
-      IF (clecfl .NE. cdfldn) GO TO  200
-C* Read associated field
-      READ (UNIT = knulre, ERR = 210, END = 210) pfield
-C* Reading done and ok
-      kflgre = 0
-      GO TO 220
-C* Problem in reading
- 210  kflgre = 1
- 220  CONTINUE
-C
-C
-C*    3. End of routine
-C        --------------
-C
-c     WRITE (UNIT = nulou,FMT = *) 
-c    $    '          --------- End of routine locread ---------'
-c     WRITE (UNIT = nulou,FMT = *) ' '
-c     CALL FLUSH (nulou)
-      RETURN
-      END
-
-
-      SUBROUTINE intocpl(itau,imjm,
+
+      IF (cchan.eq.'PIPE') THEN 
+c
+c UNIT number for fields
+c
+          nuread = 99
+c
+c exchanges from ocean=CPL to atmosphere
+c
+          DO jf=1,jpfldo2a
+            CALL PIPE_Model_Recv(cl_read(jf), icpliter, nuout)
+            OPEN (nuread, FILE=cl_f_read(jf), FORM='UNFORMATTED')
+            IF (jf.eq.1)
+     $          CALL locread(cl_read(jf), sst, imjm, nuread, iflag,
+     $          nuout)
+            IF (jf.eq.2)
+     $          CALL locread(cl_read(jf), gla, imjm, nuread, iflag,
+     $          nuout)
+            CLOSE (nuread)
+          END DO 
+
+c
+      ELSE IF (cchan.eq.'SIPC') THEN 
+c
+c         Define IF a header must be encapsulated within the field brick :
+          cmodinf = 'NOT'                 ! as $MODINFO in namcouple  
+c 
+c         reading of input field sea-surface-temperature SISUTESU
+c
+c
+c         Index of sst in total number of fields jpfldo2a: 
+          index = 1
+c
+          CALL SIPC_Read_Model(index, imjm, cmodinf, 
+     $              cljobnam_r,infos, sst)
+c
+c         reading of input field sea-ice SIICECOV
+c
+c
+c         Index of sea-ice in total number of fields jpfldo2a: 
+          index = 2
+c
+          CALL SIPC_Read_Model(index, imjm, cmodinf, 
+     $              cljobnam_r,infos, gla)
+c
+c
+      ELSE IF (cchan.eq.'CLIM') THEN 
+
+c
+c exchanges from ocean=CPL to atmosphere
+c
+          DO jf=1,jpfldo2a
+            IF (jf.eq.1) CALL CLIM_Import (cl_read(jf) , kt, sst, info)
+            IF (jf.eq.2) CALL CLIM_Import (cl_read(jf) , kt, gla, info)
+            IF ( info .NE. CLIM_Ok) THEN
+                WRITE(nuout,*)'Pb in reading ', cl_read(jf), jf
+                WRITE(nuout,*)'Couplage kt is = ',kt
+                WRITE(nuout,*)'CLIM error code is = ', info
+                WRITE(nuout,*)'STOP in Fromcpl'
+                STOP 'Fromcpl'
+            ENDIF
+          END DO 
+
+      ENDIF 
+c
+      RETURN
+      END
+
+
+      SUBROUTINE intocpl(kt,imjm,
      .                   fsol, fnsol,
      .                   rain, snow, evap, ruisoce, ruisriv,
-     .                   tsol, fder, albe,
-     .                   taux, tauy)
+     .                   taux, tauy, last)
       IMPLICIT NONE
 c
@@ -841,6 +509,12 @@
 c coupler. Of course, it sends a message to the corresponding pipes
 c after the writting.
-c
-      INTEGER itau, imjm
+c 3 techniques : pipes
+c                clim
+c                svipc
+c IF last time step WRITE output files anway
+c
+#include "oasis.h"
+
+      INTEGER kt, imjm
 c
       REAL fsol(imjm)
@@ -851,458 +525,394 @@
       REAL ruisoce(imjm)
       REAL ruisriv(imjm)
-      REAL tsol(imjm)
-      REAL fder(imjm)
-      REAL albe(imjm)
       REAL taux(imjm)
       REAL tauy(imjm)
+      LOGICAL last
 c
       INTEGER nuout
       PARAMETER (nuout = 6)
+c
+c Additions for SVIPC
+c
+      INTEGER index
+      INTEGER infos(3)
+      CHARACTER*3 cmodinf       ! Header or not
+      CHARACTER*3 cljobnam      ! experiment name
+c
+#include "clim.h"
+c
+#include "param_cou.h"
+c
+#include "inc_sipc.h"
+#include "inc_cpl.h"
+c
 C
       INTEGER nuwrit, ios
       CHARACTER*8 pipnom
       CHARACTER*8 fldnom
-      CHARACTER*8 filnom
-c
-c
-#include "oasis.h"
-#include "clim.h"
-      INTEGER info
-      INTEGER isize, iret
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Intocpl: send fields to CPL, itau= ", itau
-      WRITE(nuout,*) " "
-c
-      IF (cchain.EQ."PIPE") THEN
-c
-      nuwrit = 99
-      filnom = "atmflx"
-      OPEN(nuwrit, FILE=filnom, FORM="unformatted", IOSTAT=ios)
-      IF (ios .NE. 0) THEN
-          WRITE(6,*) "Error while connecting "//filnom
-          CALL ABORT('STOP in intocpl')
-      ENDIF
-      REWIND ( UNIT = nuwrit)
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Writting fields to "//filnom, nuwrit
-      WRITE(nuout,*) " "
-      CALL flush(nuout)
-C
-C            ecriture CONSFTOT (flux non solaire)
-C
-      fldnom = "CONSFTOT"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) fnsol
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture COSHFTOT (solaire)
-C
-      fldnom = "COSHFTOT"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) fsol
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture COTOLPSU (precipitation liquide)
-C
-      fldnom = "COTOLPSU"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) rain
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture COTOSPSU (precipitation solide)
-C
-      fldnom = "COTOSPSU"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) snow
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture COTFSHSU (evaporation)
-C
-      fldnom = "COTFSHSU"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) evap
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture COSSTSST (temperature du sol)
-C
-      fldnom = "COSSTSST"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) tsol
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture CODFLXDT (derivee du flux non-solaire)
-C
-      fldnom = "CODFLXDT"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) fder
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture COALBSUR (albedo moyen)
-C
-      fldnom = "COALBSUR"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) albe
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture CORUNCOA (runoff DIRECT)
-C
-      fldnom = "CORUNCOA"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) ruisoce
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C           ecriture river runoff 'CORIVFLU'
-C
-      fldnom = "CORIVFLU"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) ruisriv
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-c
-      CLOSE(UNIT = nuwrit)
+      CHARACTER*6 file_name(jpmaxfld)
+      INTEGER max_file
+      INTEGER file_unit_max, file_unit(jpmaxfld),
+     $    file_unit_field(jpmaxfld) 
+
+      INTEGER icstep, info, jn, jf, ierror
+      LOGICAL trouve
+c
+c
+      icstep=kt 
+c
+      WRITE(nuout,*) ' '
+      WRITE(nuout,*) 'Intocpl: send fields to CPL, kt= ', kt
+      WRITE(nuout,*) ' '
+
+      IF (last.or.(cchan.eq.'PIPE')) THEN 
+c
+c
+c WRITE fields for coupler with pipe technique or for last time step
+c
+c         initialisation
+c
+          max_file=1
+          file_unit_max=99
+c keeps first file name
+          file_name(max_file)=cl_f_writ(max_file)
+c keeps first file unit
+          file_unit(max_file)=file_unit_max
+c decrements file unit maximum
+          file_unit_max=file_unit_max-1
+c keeps file unit for field
+          file_unit_field(1)=file_unit(max_file)
+c
+c different files names counter
+c
+          
+          DO jf= 2, jpflda2o
+            trouve=.false.
+            DO jn= 1, max_file
+              IF (.not.trouve) THEN
+                  IF (cl_f_writ(jf).EQ.file_name(jn)) THEN
+c keep file unit for field
+                      file_unit_field(jf)=file_unit(jn)
+                      trouve=.true.
+                  END IF 
+              END IF 
+            END DO 
+            IF (.not.trouve) then
+c increment the number of different files
+                max_file=max_file+1
+c keep file name
+                file_name(max_file)=cl_f_writ(jf)
+c keep file unit for file
+                file_unit(max_file)=file_unit_max
+c keep file unit for field
+                file_unit_field(jf)=file_unit(max_file)
+c decrement unit maximum number from 99 to 98, ...
+                file_unit_max=file_unit_max-1
+            END IF 
+          END DO 
+          
+          DO jn=1, max_file 
+            OPEN (file_unit(jn), FILE=file_name(jn), FORM='UNFORMATTED')
+          END DO 
+          
+          DO jf=1, jpflda2o
+            IF (jf.eq.1)
+     $          CALL locwrite(cl_writ(jf),fnsol, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.2)
+     $          CALL locwrite(cl_writ(jf),fsol, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.3)
+     $          CALL locwrite(cl_writ(jf),rain, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.4)
+     $          CALL locwrite(cl_writ(jf),evap, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.5)
+     $          CALL locwrite(cl_writ(jf),ruisoce, imjm,
+     $          file_unit_field(jf),ierror, nuout) 
+            IF (jf.eq.6)
+     $          CALL locwrite(cl_writ(jf),ruisriv, imjm,
+     $          file_unit_field(jf),ierror, nuout) 
+            IF (jf.eq.7)
+     $          CALL locwrite(cl_writ(jf),taux, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.8)
+     $          CALL locwrite(cl_writ(jf),taux, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.9)
+     $          CALL locwrite(cl_writ(jf),tauy, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.10)
+     $          CALL locwrite(cl_writ(jf),tauy, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+          END DO 
 C
 C simulate a FLUSH
 C
-      OPEN(nuwrit, FILE=filnom, FORM='unformatted')
-      CLOSE(UNIT = nuwrit)
-C
-C Send message to pipes:
-c
-      pipnom = 'Consftot'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Coshftot'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cotolpsu'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cotospsu'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cotfshsu'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cosstsst'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Codflxdt'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Coalbsur'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Coruncoa'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Corivflu'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-C
-C Send wind stresses to coupler
-c
-      nuwrit = 99
-      filnom = "atmtau"
-      OPEN(nuwrit, FILE=filnom, FORM="unformatted", IOSTAT=ios)
-      IF (ios .NE. 0) THEN
-          WRITE(6,*) "Error while connecting "//filnom
-          CALL ABORT('STOP in intocpl')
-      ENDIF
-      REWIND ( UNIT = nuwrit)
-c
-      WRITE(nuout,*) " "
-      WRITE(nuout,*) "Writting fields to "//filnom, nuwrit
-      WRITE(nuout,*) " "
-C
-C ecriture COZOTAUX
-c
-      fldnom = "COZOTAUX"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) taux
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-c
-      fldnom = "COZOTAU2"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) taux
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-C
-C ecriture COMETAUY
-C
-      fldnom = "COMETAUY"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) tauy
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-c
-      fldnom = "COMETAU2"
-      WRITE(UNIT = nuwrit) fldnom, 'LMD7246T00000000OAS DA  '
-      WRITE(UNIT = nuwrit) tauy
-      WRITE(nuout,*) fldnom//" recorded to "//filnom, nuwrit
-c
-      CLOSE(UNIT = nuwrit)
-C
-C simulate a FLUSH
-C
-      OPEN(nuwrit, FILE=filnom, FORM='unformatted')
-      CLOSE(UNIT = nuwrit)
-c
-c Send message to pipes:
-c
-      pipnom = 'Cozotaux'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cozotau2'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cometauy'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      pipnom = 'Cometau2'
-#ifdef CRAY
-      WRITE(pipnom) itau
-#else
-      isize=1
-      iret=0
-      CALL pipwrite(pipnom,itau,isize,iret)
-#endif
-      WRITE(nuout,*) "Message sent to pipe "//pipnom
-c
-      ELSE ! cchain.EQ."CLIM"
-c
-      CALL CLIM_Export("CONSFTOT", itau, fnsol, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export fnsol pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COSHFTOT", itau, fsol, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export fsol pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COTOLPSU", itau, rain, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export rain pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COTOSPSU", itau, snow, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export snow pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COTFSHSU", itau, evap, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export evap pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COSSTSST", itau, tsol, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export tsol pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("CODFLXDT", itau, fder, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export fder pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COALBSUR", itau, albe, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export fder pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("CORUNCOA", itau, ruisoce, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export ruisoce pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("CORIVFLU", itau, ruisriv, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export ruisriv pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COZOTAUX", itau, taux, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export taux pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COZOTAU2", itau, taux, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export taux pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COMETAUY", itau, tauy, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export tauy pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      CALL CLIM_Export("COMETAU2", itau, tauy, info)
-      IF (info .NE. CLIM_Ok) THEN
-         WRITE (nuout,*) "intocpl: CLIM_Export tauy pb. ", info
-         CALL ABORT("STOP in intocpl")
-      ENDIF
-c
-      ENDIF
-c
-      RETURN
-      END
+          DO jn=1, max_file 
+            CLOSE (file_unit(jn))
+          END DO 
+c
+c 
+c
+          IF(cchan.eq.'CLIM') THEN 
+c
+c inform PVM daemon, I have finished
+c
+              CALL CLIM_Quit (CLIM_ContPvm, info)
+              IF (info .NE. CLIM_Ok) THEN
+                  WRITE (6, *) 
+     $                'An error occured while leaving CLIM. Error = ',
+     $                info
+              ENDIF
+              
+          END IF 
+          
+      END IF 
+      
+c
+c IF last we have finished
+c
+      IF (last) RETURN 
+      
+      IF (cchan.eq.'PIPE') THEN 
+c
+c Send message to pipes for CPL=ocean
+c
+          DO jf=1, jpflda2o
+            CALL PIPE_Model_Send(cl_writ(jf), kt, nuout)
+          END DO 
+c
+c 
+c
+      ELSE  IF(cchan.eq.'SIPC') THEN 
+c
+c         Define IF a header must be encapsulated within the field brick :
+          cmodinf = 'NOT'                 ! as $MODINFO in namcouple  
+c
+c         IF cmodinf = 'YES', define encapsulated infos to be exchanged
+c		  infos(1) = initial date
+c		  infos(2) = timestep
+c		  infos(3) = actual time
+c
+c         Writing of output field non solar heat flux CONSFTOT
+c
+c         Index of non solar heat flux in total number of fields jpflda2o: 
+          index = 1
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos,fnsol)
+c
+c
+c         Writing of output field solar heat flux COSHFTOT
+c
+c         Index of solar heat flux in total number of fields jpflda2o: 
+          index = 2
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos,fsol)
+c
+c         Writing of output field rain COTOPRSU
+c
+c         Index of rain in total number of fields jpflda2o: 
+          index = 3
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, rain)
+c
+c         Writing of output field evap COTFSHSU
+c
+c         Index of evap in total number of fields jpflda2o: 
+          index = 4
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, evap)
+c
+c         Writing of output field ruisoce CORUNCOA
+c
+c         Index of ruisoce in total number of fields jpflda2o: 
+          index = 5
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, ruisoce)
+c
+c
+c         Writing of output field ruisriv CORIVFLU
+c
+c         Index of ruisriv in total number of fields jpflda2o: 
+          index = 6
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, ruisriv)
+c
+c
+c         Writing of output field zonal wind stress COZOTAUX
+c
+c         Index of runoff in total number of fields jpflda2o: 
+          index = 7
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, taux)
+c
+c         Writing of output field meridional wind stress COMETAUY
+c
+c         Index of runoff in total number of fields jpflda2o: 
+          index = 8
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, taux)
+c
+c
+c         Writing of output field zonal wind stress COMETAU2 (at v point)
+c
+c         Index of runoff in total number of fields jpflda2o: 
+          index = 9
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, tauy)
+c
+c         Writing of output field meridional wind stress COMETAU2
+c
+c         Index of runoff in total number of fields jpflda2o: 
+          index = 10
+c   
+          CALL SIPC_Write_Model(index, imjm, cmodinf,
+     $                          cljobnam,infos, tauy)
+c
+c
+      ELSE IF(cchan.eq.'CLIM') THEN 
+          
+          DO jn=1, jpflda2o
+            
+            IF (jn.eq.1) CALL CLIM_Export(cl_writ(jn), kt, fnsol, info)
+            IF (jn.eq.2) CALL CLIM_Export(cl_writ(jn), kt, fsol, info)
+            IF (jn.eq.3) CALL CLIM_Export(cl_writ(jn), kt, rain, info)
+            IF (jn.eq.4) CALL CLIM_Export(cl_writ(jn), kt, evap, info)
+            IF (jn.eq.5) CALL CLIM_Export(cl_writ(jn), kt, ruisoce, info
+     $          )
+            IF (jn.eq.6) CALL CLIM_Export(cl_writ(jn), kt, ruisriv, info
+     $          )
+            IF (jn.eq.7) CALL CLIM_Export(cl_writ(jn), kt, taux, info)
+            IF (jn.eq.8) CALL CLIM_Export(cl_writ(jn), kt, taux, info)
+            IF (jn.eq.9) CALL CLIM_Export(cl_writ(jn), kt, tauy, info)
+            IF (jn.eq.10) CALL CLIM_Export(cl_writ(jn), kt, tauy, info)
+            
+            IF (info .NE. CLIM_Ok) THEN
+                WRITE (nuout,*) 'STEP : Pb giving ',cl_writ(jn), ':',jn
+                WRITE (nuout,*) ' at timestep = ', icstep,'kt = ',kt
+                WRITE (nuout,*) 'Clim error code is = ',info
+                WRITE (nuout,*) 'STOP in intocpl '
+                CALL abort(' intocpl ')
+            ENDIF
+            
+          END DO 
+          
+      ENDIF 
+c
+      RETURN
+      END
+
+      SUBROUTINE locread
+      print *, 'Attention dans oasis.F, locread est non defini'
+      RETURN
+      END
+
+      SUBROUTINE locwrite
+      print *, 'Attention dans oasis.F, locwrite est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_define
+      print*,'Attention dans oasis.F, pipe_model_define est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_stepi
+      print*,'Attention dans oasis.F, pipe_model_stepi est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_recv
+      print *, 'Attention dans oasis.F, pipe_model_recv est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_send
+      print *, 'Attention dans oasis.F, pipe_model_send est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_stepi
+      print *, 'Attention dans oasis.F, clim_stepi est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_start
+      print *, 'Attention dans oasis.F, clim_start est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_import
+      print *, 'Attention dans oasis.F, clim_import est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_export
+      print *, 'Attention dans oasis.F, clim_export est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_init
+      print *, 'Attention dans oasis.F, clim_init est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_define
+      print *, 'Attention dans oasis.F, clim_define est non defini'
+      RETURN
+      END
+
+      SUBROUTINE clim_quit
+      print *, 'Attention dans oasis.F, clim_quit est non defini'
+      RETURN
+      END
+
+      SUBROUTINE svipc_write
+      print *, 'Attention dans oasis.F, svipc_write est non defini'
+      RETURN
+      END
+
+      SUBROUTINE svipc_close
+      print *, 'Attention dans oasis.F, svipc_close est non defini'
+      RETURN
+      END
+
+      SUBROUTINE svipc_read
+      print *, 'Attention dans oasis.F, svipc_read est non defini'
+      RETURN
+      END
+
       SUBROUTINE quitcpl
-      IMPLICIT none
-c
-c Sortir du coupleur
-c
-      INTEGER nuout   ! listing output unit
-      PARAMETER (nuout=6)
-c
-#include "oasis.h"
-#include "clim.h"
-      INTEGER info
-c
-      IF (cchain.EQ."PIPE") THEN
-c
-         WRITE(nuout,*)"On sort du coupleur sans rien faire"
-c
-      ELSE ! cchain.EQ."CLIM"
-c
-         CALL CLIM_Quit(CLIM_StopPvm,info)
-         IF (info.NE.CLIM_Ok) THEN
-            WRITE(nuout,*)"Erreur pour quiter coupleur:",info
-         ENDIF
-c
-      ENDIF
-c
-      RETURN
-      END
-
-
-      SUBROUTINE makepipe
-      PRINT*, "rien"
-      END
-      SUBROUTINE pipwrite
-      PRINT*, "rien"
-      END
-      SUBROUTINE pipread
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_Init
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_Define
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_Start
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_Stepi
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_Import
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_Export
-      PRINT*, "rien"
-      END
-      SUBROUTINE CLIM_quit
-      PRINT*, "rien"
-      END
+      print *, 'Attention dans oasis.F, quitcpl est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_write_model
+      print *, 'Attention dans oasis.F, sipc_write_model est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_attach
+      print *, 'Attention dans oasis.F, sipc_attach est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_init_model
+      print *, 'Attention dans oasis.F, sipc_init_model est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_read_model
+      print *, 'Attention dans oasis.F, sipc_read_model est non defini'
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/oasis.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.h	(revision 253)
@@ -2,5 +2,8 @@
       PARAMETER (ok_oasis = .FALSE.)
 c
-      CHARACTER*8 cchain
-      PARAMETER (cchain="PIPE")
-c      PARAMETER (cchain="CLIM")
+      CHARACTER*4 cchan
+      PARAMETER (cchan="PIPE")
+c      PARAMETER (cchan="CLIM")
+
+      INTEGER jpmaxfld
+      PARAMETER(jpmaxfld = 20)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.true
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.true	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/oasis.true	(revision 253)
@@ -0,0 +1,546 @@
+C $Id$
+C****
+C
+C**** *INICMA*  - Initialize coupled mode communication for atmosphere
+C                 and exchange some initial information with Oasis
+C
+C     Input:
+C     -----
+C       KASTP  : total number of timesteps in atmospheric model
+C       KEXCH  : frequency of exchange (in time steps)
+C       KSTEP  : length of timestep (in seconds)
+C
+C     -----------------------------------------------------------
+C
+      SUBROUTINE inicma(kastp,kexch,kstep,imjm)
+c
+c     INCLUDE 'param.h'
+c
+      INTEGER kastp, kexch, kstep,imjm
+      INTEGER iparal(3)
+      INTEGER ifcpl, idt, info, imxtag, istep, jf
+c
+      INCLUDE 'param_cou.h'
+      INCLUDE 'inc_cpl.h'
+      CHARACTER*3 cljobnam      ! experiment name
+      CHARACTER*6 clmodnam      ! model name
+c     EM: not used by Oasis2.4
+CEM      CHARACTER*6 clbid(2)      ! for CLIM_Init call (not used)
+CEM                                ! must be dimensioned by the number of models
+CEM      INTEGER nbid(2)           ! for CLIM_Init call (not used)
+CEM                                ! must be dimensioned by the number of models
+      CHARACTER*5 cloasis       ! coupler name (Oasis)
+      INTEGER imess(4)
+      INTEGER getpid            ! system functions
+      INTEGER nuout
+CEM      LOGICAL llmodel
+      PARAMETER (nuout = 6)
+c
+      INCLUDE 'clim.h'
+      INCLUDE 'mpiclim.h'
+c
+      INCLUDE 'oasis.h' ! contains the name of communication technique. Here
+                        ! cchan=CLIM only is possible.
+c			! ctype=MPI2
+c
+C     -----------------------------------------------------------
+C
+C*    1. Initializations
+C        ---------------
+C
+      WRITE(nuout,*) ' '
+      WRITE(nuout,*) ' '
+      WRITE(nuout,*) ' ROUTINE INICMA'
+      WRITE(nuout,*) ' **************'
+      WRITE(nuout,*) ' '
+      WRITE(nuout,*) ' '
+c
+c     Define the model name
+c
+      clmodnam = 'lmdz.x'       ! as in $NBMODEL in Cpl/Nam/namcouple.tmp
+c
+c     Define the coupler name
+c
+      cloasis = 'Oasis'        !  always 'Oasis' as in the coupler
+c
+c
+c     Define symbolic name for fields exchanged from atmos to coupler,
+c         must be the same as (1) of the field  definition in namcouple:
+c
+      cl_writ(1)='COSHFICE'
+      cl_writ(2)='COSHFOCE'
+      cl_writ(3)='CONSFICE'
+      cl_writ(4)='CONSFOCE'
+      cl_writ(5)='CODFLXDT'
+c      cl_writ(6)='COICTEMP'
+      cl_writ(6)='COTFSICE'
+      cl_writ(7)='COTFSOCE'
+      cl_writ(8)='COTOLPSU'
+      cl_writ(9)='COTOSPSU'
+      cl_writ(10)='CORUNCOA'
+      cl_writ(11)='CORIVFLU'
+      cl_writ(12)='COZOTAUX'
+      cl_writ(13)='COZOTAUV'
+      cl_writ(14)='COMETAUY'
+      cl_writ(15)='COMETAUU'
+c
+c     Define files name for fields exchanged from atmos to coupler,
+c         must be the same as (6) of the field  definition in namcouple:
+c
+      cl_f_writ(1)='flxatmos'
+      cl_f_writ(2)='flxatmos'
+      cl_f_writ(3)='flxatmos'
+      cl_f_writ(4)='flxatmos'
+      cl_f_writ(5)='flxatmos'
+      cl_f_writ(6)='flxatmos'
+      cl_f_writ(7)='flxatmos'
+      cl_f_writ(8)='flxatmos'
+      cl_f_writ(9)='flxatmos'
+      cl_f_writ(10)='flxatmos'
+      cl_f_writ(11)='flxatmos'
+      cl_f_writ(12)='flxatmos'
+      cl_f_writ(13)='flxatmos'
+      cl_f_writ(14)='flxatmos'
+      cl_f_writ(15)='flxatmos'
+c      cl_f_writ(16)='flxatmos'
+c
+c
+c     Define symbolic name for fields exchanged from coupler to atmosphere,
+c         must be the same as (2) of the field  definition in namcouple:
+c
+      cl_read(1)='SISUTESW'
+      cl_read(2)='SIICECOV'
+      cl_read(3)='SIICEALW'
+      cl_read(4)='SIICTEMW'
+c
+c     Define files names for fields exchanged from coupler to atmosphere,
+c         must be the same as (7) of the field  definition in namcouple:
+c
+      cl_f_read(1)='sstatmos'
+      cl_f_read(2)='sstatmos'
+      cl_f_read(3)='sstatmos'
+      cl_f_read(4)='sstatmos'
+c
+c
+c     Define the number of processors involved in the coupling for
+c     Oasis (=1) and each model (as last two INTEGER on $CHATYPE line
+c     in the namcouple); they will be stored in a COMMON in mpiclim.h
+c     (used for CLIM/MPI2 only)
+      mpi_nproc(0)=1
+      mpi_nproc(1)=1
+      mpi_nproc(2)=1 
+c
+c     Define infos to be sent initially to oasis
+c
+      imess(1) = kastp      ! total number of timesteps in atmospheric model
+      imess(2) = kexch      ! period of exchange (in time steps)
+      imess(3) = kstep      ! length of atmospheric timestep (in seconds)
+      imess(4) = getpid()   ! PID of atmospheric model
+c
+c     Initialization and exchange of initial info in the CLIM technique
+c
+      IF (cchan.eq.'CLIM') THEN
+c
+c     Define the experiment name :
+c
+          cljobnam = 'CLI'      ! as $JOBNAM in namcouple
+c
+c         Start the coupling 
+c         (see lib/clim/src/CLIM_Init for the definition of input parameters)
+c
+cEM          clbid(1)='      '
+cEM          clbid(2)='      '
+cEM          nbid(1)=0
+cEM          nbid(2)=0
+CEM          llmodel=.true.
+c
+c         Define the number of processors used by each model as in
+c         $CHATYPE line of namcouple (used for CLIM/MPI2 only) 
+          mpi_totproc(1)=1
+          mpi_totproc(2)=1
+c
+c         Define names of each model as in $NBMODEL line of namcouple
+c         (used for CLIM/MPI2 only)        
+          cmpi_modnam(1)='lmdz.x'
+          cmpi_modnam(2)='oce.xx'
+c         Start the coupling 
+c
+          CALL CLIM_Init ( cljobnam, clmodnam, 3, 7,
+     *                 kastp, kexch, kstep,
+     *                 5, 3600, 3600, info )
+c
+          IF (info.ne.CLIM_Ok) THEN
+              WRITE ( nuout, *) ' inicma : pb init clim '
+              WRITE ( nuout, *) ' error code is = ', info
+              CALL halte('STOP in inicma')
+            ELSE
+              WRITE(nuout,*) 'inicma : init clim ok '
+          ENDIF
+c
+c         For each coupling field, association of a port to its symbolic name
+c
+c         -Define the parallel decomposition associated to the port of each
+c          field; here no decomposition for all ports.
+          iparal ( clim_strategy ) = clim_serial 
+          iparal ( clim_length   ) = imjm
+          iparal ( clim_offset   ) = 0
+c
+c         -Loop on total number of coupler-to-atmosphere fields
+c         (see lib/clim/src/CLIM_Define for the definition of input parameters)
+          DO jf=1, jpfldo2a
+            CALL CLIM_Define (cl_read(jf), clim_in , clim_double, iparal
+     $          , info )  
+          END DO 
+c
+c         -Loop on total number of atmosphere-to-coupler fields 
+c         (see lib/clim/src/CLIM_Define for the definition of input parameters)
+          DO jf=1, jpflda2o1+jpflda2o2
+            CALL CLIM_Define (cl_writ(jf), clim_out , clim_double,
+     $          iparal, info )   
+          END DO 
+c
+          WRITE(nuout,*) 'inicma : clim_define ok '
+c
+c         -Join a pvm group, wait for other programs and broadcast usefull 
+c          informations to Oasis and to the ocean (see lib/clim/src/CLIM_Start)
+          CALL CLIM_Start ( imxtag, info )
+          IF (info.ne.clim_ok) THEN
+              WRITE ( nuout, *) 'inicma : pb start clim '
+              WRITE ( nuout, *) ' error code is = ', info
+              CALL halte('stop in inicma')
+            ELSE
+              WRITE ( nuout, *)  'inicma : start clim ok '
+          ENDIF
+c
+c         -Get initial information from Oasis
+c          (see lib/clim/src/CLIM_Stepi)
+          CALL CLIM_Stepi (cloasis, istep, ifcpl, idt, info)
+          IF (info .NE. clim_ok) THEN
+              WRITE ( UNIT = nuout, FMT = *)
+     $            ' warning : problem in getting step info ',
+     $            'from oasis '
+              WRITE (UNIT = nuout, FMT = *)
+     $            ' =======   error code number = ', info
+            ELSE
+              WRITE (UNIT = nuout, FMT = *)
+     $            ' got step information from oasis '
+          ENDIF
+          WRITE ( nuout, *) ' number of tstep in oasis ', istep
+          WRITE ( nuout, *) ' exchange frequency in oasis ', ifcpl
+          WRITE ( nuout, *) ' length of tstep in oasis ', idt
+      ENDIF 
+
+      RETURN
+      END
+
+c $Id$
+      SUBROUTINE fromcpl(kt, imjm, sst, gla, tice, albedo)
+c ======================================================================
+c S. Valcke (02/99) adapted From L.Z.X Li: this subroutine reads the SST 
+c and Sea-Ice provided by the coupler with the CLIM (PVM exchange messages)
+c technique. 
+c======================================================================
+      IMPLICIT none
+      INTEGER imjm, kt
+      REAL sst(imjm)          ! sea-surface-temperature
+      REAL gla(imjm)          ! sea-ice
+      REAL tice(imjm)          ! temp glace
+      REAL albedo(imjm)          ! albedo glace
+c
+      INTEGER nuout             ! listing output unit
+      PARAMETER (nuout=6)
+c
+      INTEGER nuread, ios, iflag, icpliter
+      INTEGER info, jf
+c
+      INCLUDE 'clim.h'
+c
+      INCLUDE 'oasis.h'
+      INCLUDE 'param_cou.h'
+c
+      INCLUDE 'inc_cpl.h'
+c
+c
+      WRITE (nuout,*) ' '
+      WRITE (nuout,*) 'Fromcpl: Reading fields from CPL, kt=',kt
+      WRITE (nuout,*) ' '
+      CALL flush (nuout)
+
+
+      IF (cchan.eq.'CLIM') THEN 
+
+c
+c     -Get interpolated oceanic fields from Oasis
+c
+          DO jf=1,jpfldo2a
+            IF (jf.eq.1) CALL CLIM_Import (cl_read(jf) , kt, sst, info)
+            IF (jf.eq.2) CALL CLIM_Import (cl_read(jf) , kt, gla, info)
+            IF (jf.eq.3) CALL CLIM_Import (cl_read(jf), kt,albedo, info)
+            IF (jf.eq.4) CALL CLIM_Import (cl_read(jf) , kt, tice, info)
+            IF ( info .NE. CLIM_Ok) THEN
+                WRITE(nuout,*)'Pb in reading ', cl_read(jf), jf
+                WRITE(nuout,*)'Couplage kt is = ',kt
+                WRITE(nuout,*)'CLIM error code is = ', info
+                CALL halte('STOP in fromcpl.F')
+            ENDIF
+          END DO 
+
+      ENDIF 
+c
+      RETURN
+      END
+
+c $Id$
+      SUBROUTINE intocpl(kt, imjm, fsolice, fsolwat, fnsolice, fnsolwat,
+     $    fnsicedt, evice, evwat, lpre, spre, dirunoff, rivrunoff,
+     $    tauxu, tauxv, tauyv, tauyu, last) 
+c ======================================================================
+c S. Valcke (02/99) adapted From L.Z.X Li: this subroutine provides the 
+c atmospheric coupling fields to the coupler with the CLIM (PVM exchange 
+c messages) technique. 
+c IF last time step, writes output fields to binary files.
+c ======================================================================
+      IMPLICIT NONE
+      INTEGER kt, imjm
+c
+      REAL fsolice(imjm)
+      REAL fsolwat(imjm)
+      REAL fnsolice(imjm)
+      REAL fnsolwat(imjm)
+      REAL fnsicedt(imjm)
+      REAL ictemp(imjm)
+      REAL evice(imjm)
+      REAL evwat(imjm)
+      REAL lpre(imjm)
+      REAL spre(imjm)
+      REAL dirunoff(imjm)
+      REAL rivrunoff(imjm)
+      REAL tauxu(imjm)
+      REAL tauxv(imjm)
+      REAL tauyu(imjm)
+      REAL tauyv(imjm)
+      LOGICAL last
+c
+      INTEGER nuout
+      PARAMETER (nuout = 6)
+c
+      INCLUDE 'clim.h'
+      INCLUDE 'param_cou.h'
+      INCLUDE 'inc_cpl.h'
+c
+      CHARACTER*8 file_name(jpmaxfld)
+      INTEGER max_file
+      INTEGER file_unit_max, file_unit(jpmaxfld),
+     $    file_unit_field(jpmaxfld) 
+
+      INTEGER icstep, info, jn, jf, ierror
+      LOGICAL trouve
+c
+      INCLUDE 'oasis.h'
+c
+      icstep=kt 
+c
+      WRITE(nuout,*) ' '
+      WRITE(nuout,*) 'Intocpl: sending fields to CPL, kt= ', kt
+      WRITE(nuout,*) ' '
+
+      IF (last) THEN 
+c
+c     -WRITE fields to binary files for coupler restart at last time step
+c
+c         -initialisation and files opening
+c
+          max_file=1
+          file_unit_max=99
+c         -keeps first file name
+          file_name(max_file)=cl_f_writ(max_file)
+c         -keeps first file unit
+          file_unit(max_file)=file_unit_max
+c         -decrements file unit maximum
+          file_unit_max=file_unit_max-1
+c         -keeps file unit for field
+          file_unit_field(1)=file_unit(max_file)
+c
+c         -different files names counter
+c
+          DO jf= 2, jpflda2o1 + jpflda2o2
+            trouve=.false.
+            DO jn= 1, max_file
+              IF (.not.trouve) THEN
+                  IF (cl_f_writ(jf).EQ.file_name(jn)) THEN
+c                 -keep file unit for field
+                      file_unit_field(jf)=file_unit(jn)
+                      trouve=.true.
+                  END IF 
+              END IF 
+            END DO 
+            IF (.not.trouve) then
+c           -increment the number of different files
+                max_file=max_file+1
+c           -keep file name
+                file_name(max_file)=cl_f_writ(jf)
+c           -keep file unit for file
+                file_unit(max_file)=file_unit_max
+c           -keep file unit for field
+                file_unit_field(jf)=file_unit(max_file)
+c           -decrement unit maximum number from 99 to 98, ...
+                file_unit_max=file_unit_max-1
+            END IF 
+          END DO 
+c          
+          DO jn=1, max_file 
+            OPEN (file_unit(jn), FILE=file_name(jn), FORM='UNFORMATTED')
+          END DO
+c 
+c         WRITE fields to files          
+          DO jf=1, jpflda2o1 + jpflda2o2
+            IF (jf.eq.1)
+     $          CALL locwrite(cl_writ(jf),fsolice, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.2)
+     $          CALL locwrite(cl_writ(jf),fsolwat, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.3)
+     $          CALL locwrite(cl_writ(jf),fnsolice, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.4)
+     $          CALL locwrite(cl_writ(jf),fnsolwat, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.5)
+     $          CALL locwrite(cl_writ(jf),fnsicedt, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+c            IF (jf.eq.6)
+c     $          CALL locwrite(cl_writ(jf),ictemp, imjm,
+c     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.6)
+     $          CALL locwrite(cl_writ(jf),evice, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.7)
+     $          CALL locwrite(cl_writ(jf),evwat, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.8)
+     $          CALL locwrite(cl_writ(jf),lpre, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.9)
+     $          CALL locwrite(cl_writ(jf),spre, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.10)
+     $          CALL locwrite(cl_writ(jf),dirunoff, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.11)
+     $          CALL locwrite(cl_writ(jf),rivrunoff, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+            IF (jf.eq.12)
+     $          CALL locwrite(cl_writ(jf),tauxu, imjm,
+     $          file_unit_field(jf),ierror, nuout) 
+            IF (jf.eq.13)
+     $          CALL locwrite(cl_writ(jf),tauxv, imjm,
+     $          file_unit_field(jf),ierror, nuout) 
+            IF (jf.eq.14)
+     $          CALL locwrite(cl_writ(jf),tauyv, imjm,
+     $          file_unit_field(jf),ierror, nuout) 
+            IF (jf.eq.15)
+     $          CALL locwrite(cl_writ(jf),tauyu, imjm,
+     $          file_unit_field(jf), ierror, nuout) 
+          END DO 
+C
+C         -simulate a FLUSH
+C
+          DO jn=1, max_file 
+            CLOSE (file_unit(jn))
+          END DO 
+C
+C
+          IF(cchan.eq.'CLIM') THEN 
+C
+C         -inform PVM daemon that message exchange is finished
+C
+              CALL CLIM_Quit (CLIM_ContPvm, info)
+              IF (info .NE. CLIM_Ok) THEN
+                  WRITE (6, *) 
+     $                'An error occured while leaving CLIM. Error = ',
+     $                info
+              ENDIF
+          END IF 
+          RETURN    
+      END IF 
+C
+      IF(cchan.eq.'CLIM') THEN 
+C
+C     -Give atmospheric fields to Oasis
+C 
+          DO jn=1, jpflda2o1 + jpflda2o2
+C            
+          IF (jn.eq.1) CALL CLIM_Export(cl_writ(jn), kt, fsolice, info)
+          IF (jn.eq.2) CALL CLIM_Export(cl_writ(jn), kt, fsolwat, info)
+          IF (jn.eq.3) CALL CLIM_Export(cl_writ(jn), kt, fnsolice, info)
+          IF (jn.eq.4) CALL CLIM_Export(cl_writ(jn), kt, fnsolwat, info)
+          IF (jn.eq.5) CALL CLIM_Export(cl_writ(jn), kt, fnsicedt, info)
+c          IF (jn.eq.6) CALL CLIM_Export(cl_writ(jn), kt, ictemp, info)
+          IF (jn.eq.6) CALL CLIM_Export(cl_writ(jn), kt, evice, info)
+          IF (jn.eq.7) CALL CLIM_Export(cl_writ(jn), kt, evwat, info)
+          IF (jn.eq.8) CALL CLIM_Export(cl_writ(jn), kt, lpre, info)
+          IF (jn.eq.9) CALL CLIM_Export(cl_writ(jn), kt, spre, info)
+          IF (jn.eq.10) CALL CLIM_Export(cl_writ(jn),kt,dirunoff, info)
+          IF (jn.eq.11) CALL CLIM_Export(cl_writ(jn),kt,rivrunoff,info)
+          IF (jn.eq.12) CALL CLIM_Export(cl_writ(jn), kt, tauxu, info)
+          IF (jn.eq.13) CALL CLIM_Export(cl_writ(jn), kt, tauxv, info)
+          IF (jn.eq.14) CALL CLIM_Export(cl_writ(jn), kt, tauyv, info)
+          IF (jn.eq.15) CALL CLIM_Export(cl_writ(jn), kt, tauyu, info)
+          
+            IF (info .NE. CLIM_Ok) THEN
+                WRITE (nuout,*) 'STEP : Pb giving ',cl_writ(jn), ':',jn
+                WRITE (nuout,*) ' at timestep = ', icstep,'kt = ',kt
+                WRITE (nuout,*) 'Clim error code is = ',info
+                CALL halte('STOP in intocpl ')
+            ENDIF
+          END DO 
+      ENDIF 
+C
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_define
+      print*,'Attention dans oasis.F, pipe_model_define est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_stepi
+      print*,'Attention dans oasis.F, pipe_model_stepi est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_recv
+      print *, 'Attention dans oasis.F, pipe_model_recv est non defini'
+      RETURN
+      END
+
+      SUBROUTINE pipe_model_send
+      print *, 'Attention dans oasis.F, pipe_model_send est non defini'
+      RETURN
+      END
+
+      SUBROUTINE quitcpl
+      print *, 'Attention dans oasis.F, quitcpl est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_write_model
+      print *, 'Attention dans oasis.F, sipc_write_model est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_attach
+      print *, 'Attention dans oasis.F, sipc_attach est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_init_model
+      print *, 'Attention dans oasis.F, sipc_init_model est non defini'
+      RETURN
+      END
+
+      SUBROUTINE sipc_read_model
+      print *, 'Attention dans oasis.F, sipc_read_model est non defini'
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/param_cou.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/param_cou.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/param_cou.h	(revision 253)
@@ -0,0 +1,11 @@
+C
+C -- param_cou.h
+C
+	INTEGER jpflda2o
+	PARAMETER(jpflda2o = 1)          ! Number of fields exchanged from
+                                         ! atmosphere to ocean
+C
+	INTEGER jpfldo2a
+	PARAMETER(jpfldo2a = 1)          ! Number of fields exchanged from
+                                         ! ocean to atmosphere
+C
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/param_sipc.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/param_sipc.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/param_sipc.h	(revision 253)
@@ -0,0 +1,21 @@
+C@
+C@ -- param_sipc.h
+C@
+C@ -- jpbyteint : number of bytes per integer
+C@
+C@ -- jpbyterea : number of bytes per real
+C@
+C@ -- jpbytecha : number of bytes per character
+C@
+	INTEGER jpbyteint,jpbyterea, jpbytecha  
+        PARAMETER (jpbyteint = 4)
+	PARAMETER (jpbyterea = 4)
+	PARAMETER (jpbytecha = 1)
+C@
+C@ -- jptest :  The models will test during 2*jptest seconds if the file 
+C@              DUMMY_SIPC has been created by OASIS, signaling that the
+C@              SHM pools are opened. After, they will abort.
+C@
+        INTEGER jptest
+        PARAMETER(jptest = 100)      
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phyetat0.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/phyetat0.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phyetat0.F	(revision 253)
@@ -2,5 +2,6 @@
      .            rlat,rlon,tsol,tsoil,deltat,qsol,snow,
      .           radsol,rugmer,agesno,clesphy0,
-     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel,tabcntr0)
+     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel,tabcntr0,
+     .           t_ancien,q_ancien,ancien_ok)
       IMPLICIT none
 c======================================================================
@@ -38,4 +39,7 @@
       REAL rugsrel(klon)
 
+      REAL t_ancien(klon,klev), q_ancien(klon,klev)
+      LOGICAL ancien_ok
+
       INTEGER        longcles
       PARAMETER    ( longcles = 20 )
@@ -674,4 +678,41 @@
       PRINT*,'Rugosite relief (ecart-type) rugsrel:', xmin, xmax
 c
+c
+      ancien_ok = .TRUE.
+c
+      ierr = NF_INQ_VARID (nid, "TANCIEN", nvarid)
+      IF (ierr.NE.NF_NOERR) THEN
+         PRINT*, "phyetat0: Le champ <TANCIEN> est absent"
+         PRINT*, "Depart legerement fausse. Mais je continue"
+         ancien_ok = .FALSE.
+      ELSE
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid, nvarid, t_ancien)
+#else
+         ierr = NF_GET_VAR_REAL(nid, nvarid, t_ancien)
+#endif
+         IF (ierr.NE.NF_NOERR) THEN
+            PRINT*, "phyetat0: Lecture echouee pour <TANCIEN>"
+            CALL abort
+         ENDIF
+      ENDIF
+c
+      ierr = NF_INQ_VARID (nid, "QANCIEN", nvarid)
+      IF (ierr.NE.NF_NOERR) THEN
+         PRINT*, "phyetat0: Le champ <QANCIEN> est absent"
+         PRINT*, "Depart legerement fausse. Mais je continue"
+         ancien_ok = .FALSE.
+      ELSE
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid, nvarid, q_ancien)
+#else
+         ierr = NF_GET_VAR_REAL(nid, nvarid, q_ancien)
+#endif
+         IF (ierr.NE.NF_NOERR) THEN
+            PRINT*, "phyetat0: Lecture echouee pour <QANCIEN>"
+            CALL abort
+         ENDIF
+      ENDIF
+c
 c Fermer le fichier:
 c
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phyredem.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/phyredem.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phyredem.F	(revision 253)
@@ -2,5 +2,6 @@
      .           rlat,rlon,tsol,tsoil,deltat,qsol,snow,
      .           radsol,rugmer,agesno,
-     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel)
+     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel,
+     .           t_ancien, q_ancien)
       IMPLICIT none
 c======================================================================
@@ -15,4 +16,5 @@
 #include "clesphys.h"
 #include "control.h"
+#include "temps.h"
 c======================================================================
       CHARACTER*(*) fichnom
@@ -38,6 +40,7 @@
       REAL zval(klon)
       REAL rugsrel(klon)
-c
-      INTEGER nid, nvarid, idim1, idim2
+      REAL t_ancien(klon,klev), q_ancien(klon,klev)
+c
+      INTEGER nid, nvarid, idim1, idim2, idim3
       INTEGER ierr
       INTEGER length
@@ -61,4 +64,5 @@
       ierr = NF_DEF_DIM (nid, "index", length, idim1)
       ierr = NF_DEF_DIM (nid, "points_physiques", klon, idim2)
+      ierr = NF_DEF_DIM (nid, "horizon_vertical", klon*klev, idim3)
 c
       ierr = NF_ENDDEF(nid)
@@ -82,4 +86,6 @@
       tab_cntrl(13) = dayref
       tab_cntrl(14) = anneeref
+      tab_cntrl(13) = day_end
+      tab_cntrl(14) = anne_ini
 c
       ierr = NF_REDEF (nid)
@@ -388,4 +394,30 @@
 #endif
 c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "TANCIEN", NF_DOUBLE, 1, idim3,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "TANCIEN", NF_FLOAT, 1, idim3,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,t_ancien)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,t_ancien)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "QANCIEN", NF_DOUBLE, 1, idim3,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "QANCIEN", NF_FLOAT, 1, idim3,nvarid)
+#endif
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,q_ancien)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,q_ancien)
+#endif
+c
       ierr = NF_CLOSE(nid)
 c
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/physiq.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/physiq.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/physiq.F	(revision 253)
@@ -1,7 +1,8 @@
+c $Header$
+c
       SUBROUTINE physiq (nlon,nlev,nqmax  ,
      .            debut,lafin,rjourvrai,rjour_ecri,gmtime,pdtphys,
      .            paprs,pplay,pphi,pphis,paire,presnivs,clesphy0,
      .            u,v,t,qx,
-     .            d_u_dyn, d_v_dyn,  d_t_dyn, d_qx_dyn,
      .            omega,
      .            d_u, d_v, d_t, d_qx, d_ps)
@@ -40,8 +41,6 @@
 c t-------input-R-temperature (K)
 c qx------input-R-humidite specifique (kg/kg) et d'autres traceurs
-c d_u_dyn-input-R-tendance dynamique pour "u" (m/s/s)
-c d_v_dyn-input-R-tendance dynamique pour "v" (m/s/s)
 c d_t_dyn-input-R-tendance dynamique pour "t" (K/s)
-c d_qx_dyn-input-R-tendance dynamique pour "qx" (kg/kg/s)
+c d_q_dyn-input-R-tendance dynamique pour "q" (kg/kg/s)
 c omega---input-R-vitesse verticale en Pa/s
 c
@@ -53,4 +52,6 @@
 c======================================================================
 #include "dimensions.h"
+      integer jjmp1
+      parameter (jjmp1=jjm+1-1/jjm)
 #include "dimphy.h"
 #include "regdim.h"
@@ -59,7 +60,10 @@
 #include "clesphys.h"
 #include "control.h"
+#include "temps.h"
 c======================================================================
       LOGICAL check ! Verifier la conservation du modele en eau
       PARAMETER (check=.FALSE.)
+      LOGICAL ok_stratus ! Ajouter artificiellement les stratus
+      PARAMETER (ok_stratus=.FALSE.)
 c======================================================================
 c Parametres lies au coupleur OASIS:
@@ -71,5 +75,7 @@
       PARAMETER (nexca=48)
       PARAMETER (itimestep=1800)
-      EXTERNAL intocpl, inicma
+      EXTERNAL fromcpl, intocpl, inicma
+      REAL cpl_sst(iim,jjmp1), cpl_sic(iim,jjmp1)
+      REAL cpl_alb_sst(iim,jjmp1), cpl_alb_sic(iim,jjmp1)
 c======================================================================
 c ok_ocean indique l'utilisation du modele oceanique "slab ocean",
@@ -156,8 +162,13 @@
       REAL qx(klon,klev,nqmax)
 
+      REAL t_ancien(klon,klev), q_ancien(klon,klev)
+      SAVE t_ancien, q_ancien
+      LOGICAL ancien_ok
+      SAVE ancien_ok
+
       REAL d_u_dyn(klon,klev)
       REAL d_v_dyn(klon,klev)
       REAL d_t_dyn(klon,klev)
-      REAL d_qx_dyn(klon,klev,2)
+      REAL d_q_dyn(klon,klev)
 
       REAL omega(klon,klev)
@@ -264,4 +275,33 @@
       REAL alb_neig(klon)
       SAVE alb_neig               ! albedo de la neige
+cKE43
+c Variables liees a la convection de K. Emanuel (sb):
+c
+      REAL ema_workcbmf(klon)   ! cloud base mass flux
+      SAVE ema_workcbmf
+
+      REAL ema_cbmf(klon)       ! cloud base mass flux
+      SAVE ema_cbmf
+
+      REAL ema_pcb(klon)        ! cloud base pressure
+      SAVE ema_pcb
+
+      REAL ema_pct(klon)        ! cloud top pressure
+      SAVE ema_pct
+
+      REAL bas, top             ! cloud base and top levels
+      SAVE bas
+      SAVE top
+
+      REAL Ma(klon,klev)        ! undilute upward mass flux
+      SAVE Ma
+      REAL ema_work1(klon, klev), ema_work2(klon, klev)
+      SAVE ema_work1, ema_work2
+      REAL wdn(klon), tdn(klon), qdn(klon)
+c Variables locales pour la couche limite (al1):
+c
+cAl1      REAL pblh(klon)           ! Hauteur de couche limite
+cAl1      SAVE pblh
+c34EK
 c
 c Variables locales:
@@ -276,5 +316,6 @@
       REAL yv1(klon)            ! vents dans la premiere couche V
       LOGICAL offline           ! Controle du stockage ds "physique"
-      PARAMETER (offline=.TRUE.)
+      PARAMETER (offline=.false.)
+      INTEGER physid
       REAL pfrac_impa(klon,klev)! Produits des coefs lessivage impaction
       save pfrac_impa
@@ -336,5 +377,6 @@
       EXTERNAL condsurf  ! lire les conditions aux limites
       EXTERNAL conlmd    ! convection (schema LMD)
-      EXTERNAL diagcld   ! nuages diagnostiques
+cKE43
+      EXTERNAL conema  ! convect4.3
       EXTERNAL fisrtilp  ! schema de condensation a grande echelle (pluie)
 cAA 
@@ -402,4 +444,8 @@
       CHARACTER*2 iqn
 c
+      REAL qcheck
+      REAL z_avant(klon), z_apres(klon), z_factor(klon)
+      LOGICAL zx_ajustq
+c
       REAL za, zb
       REAL zx_t, zx_qs, zdelta, zcor, zfra, zlvdcp, zlsdcp
@@ -409,7 +455,32 @@
 c
       REAL zphi(klon,klev)
-      REAL zx_tmp_x(iim), zx_tmp_y(jjm+1)
-      REAL zx_relief(iim,jjm+1)
-      REAL zx_aire(iim,jjm+1)
+      REAL zx_tmp_x(iim), zx_tmp_yjjmp1
+      REAL zx_relief(iim,jjmp1)
+      REAL zx_aire(iim,jjmp1)
+cKE43
+c Variables locales pour la convection de K. Emanuel (sb):
+c
+      REAL upwd(klon,klev)      ! saturated updraft mass flux
+      REAL dnwd(klon,klev)      ! saturated downdraft mass flux
+      REAL dnwd0(klon,klev)     ! unsaturated downdraft mass flux
+      REAL tvp(klon,klev)       ! virtual temp of lifted parcel
+      REAL cape(klon)           ! CAPE
+      SAVE cape
+      REAL pbase(klon)          ! cloud base pressure
+      SAVE pbase
+      REAL bbase(klon)          ! cloud base buoyancy
+      SAVE bbase
+      REAL rflag(klon)          ! flag fonctionnement de convect
+c -- convect43:
+      INTEGER ntra              ! nb traceurs pour convect4.3
+      REAL pori_con(klon)    ! pressure at the origin level of lifted parcel
+      REAL plcl_con(klon),dtma_con(klon),dtlcl_con(klon)
+      REAL dtvpdt1(klon,klev), dtvpdq1(klon,klev)
+      REAL dplcldt(klon), dplcldr(klon)
+c?     .     condm_con(klon,klev),conda_con(klon,klev),
+c?     .     mr_con(klon,klev),ep_con(klon,klev)
+c?     .    ,sadiab(klon,klev),wadiab(klon,klev)
+c --
+c34EK
 c
 c Variables du changement
@@ -423,5 +494,5 @@
       REAL d_u_con(klon,klev),d_v_con(klon,klev)
       REAL d_t_lsc(klon,klev),d_q_lsc(klon,klev),d_ql_lsc(klon,klev)
-c      REAL d_t_ajs(klon,klev), d_q_ajs(klon,klev)
+      REAL d_t_ajs(klon,klev), d_q_ajs(klon,klev)
       REAL d_t_eva(klon,klev),d_q_eva(klon,klev)
       REAL rneb(klon,klev)
@@ -432,4 +503,5 @@
       INTEGER kcbot(klon), kctop(klon), kdtop(klon)
       REAL pmflxr(klon,klev+1), pmflxs(klon,klev+1)
+      REAL prfl(klon,klev+1), psfl(klon,klev+1)
 c
       INTEGER ibas_con(klon), itop_con(klon)
@@ -445,4 +517,8 @@
       REAL d_u_lif(klon,klev), d_v_lif(klon,klev)
       REAL d_t_lif(klon,klev)
+
+      REAL ratqs(klon,klev)
+      LOGICAL zpt_conv(klon,klev)
+
 c
 c Variables liees a l'ecriture de la bande histoire physique
@@ -460,29 +536,29 @@
       SAVE ecrit_reg   ! frequence d'ecriture
 c
-      REAL oas_sols(klon), z_sols(iim,jjm+1)
+      REAL oas_sols(klon), z_sols(iim,jjmp1)
       SAVE oas_sols
-      REAL oas_nsol(klon), z_nsol(iim,jjm+1)
+      REAL oas_nsol(klon), z_nsol(iim,jjmp1)
       SAVE oas_nsol
-      REAL oas_rain(klon), z_rain(iim,jjm+1)
+      REAL oas_rain(klon), z_rain(iim,jjmp1)
       SAVE oas_rain
-      REAL oas_snow(klon), z_snow(iim,jjm+1)
+      REAL oas_snow(klon), z_snow(iim,jjmp1)
       SAVE oas_snow
-      REAL oas_evap(klon), z_evap(iim,jjm+1)
+      REAL oas_evap(klon), z_evap(iim,jjmp1)
       SAVE oas_evap
-      REAL oas_ruis(klon), z_ruis(iim,jjm+1)
+      REAL oas_ruis(klon), z_ruis(iim,jjmp1)
       SAVE oas_ruis
-      REAL oas_tsol(klon), z_tsol(iim,jjm+1)
+      REAL oas_tsol(klon), z_tsol(iim,jjmp1)
       SAVE oas_tsol
-      REAL oas_fder(klon), z_fder(iim,jjm+1)
+      REAL oas_fder(klon), z_fder(iim,jjmp1)
       SAVE oas_fder
-      REAL oas_albe(klon), z_albe(iim,jjm+1)
+      REAL oas_albe(klon), z_albe(iim,jjmp1)
       SAVE oas_albe
-      REAL oas_taux(klon), z_taux(iim,jjm+1)
+      REAL oas_taux(klon), z_taux(iim,jjmp1)
       SAVE oas_taux
-      REAL oas_tauy(klon), z_tauy(iim,jjm+1)
+      REAL oas_tauy(klon), z_tauy(iim,jjmp1)
       SAVE oas_tauy
-      REAL oas_ruisoce(klon), z_ruisoce(iim,jjm+1)
+      REAL oas_ruisoce(klon), z_ruisoce(iim,jjmp1)
       SAVE oas_ruisoce
-      REAL oas_ruisriv(klon), z_ruisriv(iim,jjm+1)
+      REAL oas_ruisriv(klon), z_ruisriv(iim,jjmp1)
       SAVE oas_ruisriv
 c
@@ -505,8 +581,8 @@
       REAL tabcntr0( length       )
 c
-      INTEGER ndex(1)
+      INTEGER ndex2d(iim*jjmp1),ndex3d(iim*jjmp1*klev)
       REAL zx_tmp_fi2d(klon)
-      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)
+      REAL zx_tmp_2d(iim,jjmp1), zx_tmp_3d(iim,jjmp1,klev)
+      REAL zx_lon(iim,jjmp1), zx_lat(iim,jjmp1)
 c
       INTEGER nid_day, nid_mth, nid_ins
@@ -579,5 +655,6 @@
      .         rlat,rlon,ftsol,ftsoil,deltat,fqsol,fsnow,
      .        radsol,rugmer,agesno,clesphy0,
-     .       zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro,tabcntr0 )
+     .       zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro,tabcntr0,
+     .       t_ancien, q_ancien, ancien_ok )
 
 c
@@ -612,4 +689,21 @@
          PRINT*, "Clef pour la convection, iflag_con=", iflag_con
 c
+cKE43
+c Initialisation pour la convection de K.E. (sb):
+         IF (iflag_con.EQ.4) THEN
+
+         PRINT*, "*** Convection de Kerry Emanuel 4.3  "
+         PRINT*, "On va utiliser le melange convectif des traceurs qui"
+         PRINT*, "est calcule dans convect4.3"
+         PRINT*, " !!! penser aux logical flags de phytrac"
+
+          DO i = 1, klon
+           ema_cbmf(i) = 0.
+           ema_pcb(i)  = 0.
+           ema_pct(i)  = 0.
+           ema_workcbmf(i) = 0.
+          ENDDO
+         ENDIF
+c34EK
          IF (ok_orodr) THEN
          DO i=1,klon
@@ -659,24 +753,23 @@
       IF (ok_journe) THEN
 c
-C         CALL ymds2ju(1900, 1, 1, 0.0, zjulian)
-         CALL ymds2ju(anneeref, 1, 1, 0.0, zjulian)
-         zjulian = zjulian + dayref
-c
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,zx_lon)
+         CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
+         zjulian = zjulian + day_ini
+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,jjm+1) = rlon(i+1)
+            zx_lon(i,jjmp1) = rlon(i+1)
          ENDDO
          DO ll=1,klev
             znivsig(ll)=float(ll)
          ENDDO
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,zx_lat)
-         CALL histbeg("histday", iim,zx_lon, jjm+1,zx_lat,
-     .                 1,iim,1,jjm+1, 0, zjulian, dtime, 
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+         CALL histbeg("histday", iim,zx_lon, jjmp1,zx_lat,
+     .                 1,iim,1,jjmp1, 0, zjulian, dtime, 
      .                 nhori, nid_day)
-c         CALL histvert(nid_day, "presnivs", "Vertical levels", "mb",
-c     .                 klev, presnivs, nvert)
-         call histvert(nid_day, 'sig_s', 'Niveaux sigma','-',
-     .              klev, znivsig, nvert)
+         CALL histvert(nid_day, "presnivs", "Vertical levels", "mb",
+     .                 klev, presnivs, nvert)
+c        call histvert(nid_day, 'sig_s', 'Niveaux sigma','-',
+c    .              klev, znivsig, nvert)
 c
          zsto = dtime
@@ -684,9 +777,9 @@
 c
          CALL histdef(nid_day, "phis", "Surface geop. height", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "once", zsto,zout)
 c
          CALL histdef(nid_day, "aire", "Grid area", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "once", zsto,zout)
 c
@@ -694,85 +787,85 @@
 c
          CALL histdef(nid_day, "tsol", "Surface Temperature", "K",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "psol", "Surface Pressure", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "rain", "Precipitation", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "snow", "Snow fall", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "evap", "Evaporation", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "tops", "Solar rad. at TOA", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "topl", "IR rad. at TOA", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "sols", "Solar rad. at surf.", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "soll", "IR rad. at surface", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "bils", "Surf. total heat flux", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "sens", "Sensible heat flux", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "fder", "Heat flux derivation", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "frtu", "Zonal wind stress", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "frtv", "Meridional wind stress", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "ruis", "Runoff", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "sicf", "Sea-ice fraction", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "cldl", "Low-level cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "cldm", "Mid-level cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "cldh", "High-level cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "cldt", "Total cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "cldq", "Cloud liquid water path", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
@@ -780,42 +873,35 @@
 c
          CALL histdef(nid_day, "temp", "Air temperature", "K",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "ovap", "Specific humidity", "Kg/Kg",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "geop", "Geopotential height", "m",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "vitu", "Zonal wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "vitv", "Meridional wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "vitw", "Vertical wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_day, "pres", "Air pressure", "Pa",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histend(nid_day)
 c
-         ndex(1) = 0
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-         CALL histwrite(nid_day,"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_day,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+         ndex2d = 0
+         ndex3d = 0
 c
       ENDIF ! fin de test sur ok_journe
@@ -823,24 +909,23 @@
       IF (ok_mensuel) THEN
 c
-c         CALL ymds2ju(1900, 1, 1, 0.0, zjulian)
-         CALL ymds2ju(anneeref, 1, 1, 0.0, zjulian)
-         zjulian = zjulian + dayref
-c
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,zx_lon)
+         CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
+         zjulian = zjulian + day_ini
+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,jjm+1) = rlon(i+1)
+            zx_lon(i,jjmp1) = rlon(i+1)
          ENDDO
          DO ll=1,klev
             znivsig(ll)=float(ll)
          ENDDO
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,zx_lat)
-         CALL histbeg("histmth", iim,zx_lon, jjm+1,zx_lat,
-     .                 1,iim,1,jjm+1, 0, zjulian, dtime, 
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+         CALL histbeg("histmth", iim,zx_lon, jjmp1,zx_lat,
+     .                 1,iim,1,jjmp1, 0, zjulian, dtime, 
      .                 nhori, nid_mth)
-c         CALL histvert(nid_mth, "presnivs", "Vertical levels", "mb",
-c     .                 klev, presnivs, nvert)
-         call histvert(nid_mth, 'sig_s', 'Niveaux sigma','-',
-     .              klev, znivsig, nvert)
+         CALL histvert(nid_mth, "presnivs", "Vertical levels", "mb",
+     .                 klev, presnivs, nvert)
+c        call histvert(nid_mth, 'sig_s', 'Niveaux sigma','-',
+c    .              klev, znivsig, nvert)
 c
          zsto = dtime
@@ -848,9 +933,9 @@
 c
          CALL histdef(nid_mth, "phis", "Surface geop. height", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "once",  zsto,zout)
 c
          CALL histdef(nid_mth, "aire", "Grid area", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "once",  zsto,zout)
 c
@@ -858,268 +943,299 @@
 c
          CALL histdef(nid_mth, "tsol", "Surface Temperature", "K",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "psol", "Surface Pressure", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "qsol", "Surface humidity", "mm",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "rain", "Precipitation", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "plul", "Large-scale Precip.", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "pluc", "Convective Precip.", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "snow", "Snow fall", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "ages", "Snow age", "day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "evap", "Evaporation", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "tops", "Solar rad. at TOA", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "topl", "IR rad. at TOA", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "sols", "Solar rad. at surf.", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "soll", "IR rad. at surface", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "tops0", "Solar rad. at TOA", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "topl0", "IR rad. at TOA", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "sols0", "Solar rad. at surf.", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "soll0", "IR rad. at surface", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "bils", "Surf. total heat flux", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "sens", "Sensible heat flux", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "fder", "Heat flux derivation", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "frtu", "Zonal wind stress", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "frtv", "Meridional wind stress", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "ruis", "Runoff", "mm/day",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "sicf", "Sea-ice fraction", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "albs", "Surface albedo", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cdrm", "Momentum drag coef.", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cdrh", "Heat drag coef.", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cldl", "Low-level cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cldm", "Mid-level cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cldh", "High-level cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cldt", "Total cloudiness", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "cldq", "Cloud liquid water path", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "ue", "Zonal energy transport", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "ve", "Merid energy transport", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "uq", "Zonal humidity transport", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "vq", "Merid humidity transport", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+cKE43
+      IF (iflag_con .EQ. 4) THEN ! sb
+c
+         CALL histdef(nid_mth, "cape", "Conv avlbl pot ener", "J/Kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "pbase", "Cld base pressure", "hPa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "ptop", "Cld top pressure", "hPa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "fbase", "Cld base mass flux", "Kg/m2/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+c
+      ENDIF
+c34EK
 c
 c Champs 3D:
 c
          CALL histdef(nid_mth, "temp", "Air temperature", "K",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "ovap", "Specific humidity", "Kg/Kg",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "geop", "Geopotential height", "m",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "vitu", "Zonal wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "vitv", "Meridional wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "vitw", "Vertical wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "pres", "Air pressure", "Pa",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "rneb", "Cloud fraction", "-",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "rhum", "Relative humidity", "-",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "oliq", "Liquid water content", "kg/kg",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtdyn", "Dynamics dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dqdyn", "Dynamics dQ", "Kg/Kg/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtcon", "Convection dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dqcon", "Convection dQ", "Kg/Kg/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtlsc", "Condensation dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dqlsc", "Condensation dQ", "Kg/Kg/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtvdf", "Boundary-layer dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dqvdf", "Boundary-layer dQ", "Kg/Kg/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dteva", "Reevaporation dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dqeva", "Reevaporation dQ", "Kg/Kg/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-c         CALL histdef(nid_mth, "dtajs", "Dry adjust. dT", "K/s",
-c     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
-c     .                "ave(X)", zsto,zout)
-c
-c         CALL histdef(nid_mth, "dqajs", "Dry adjust. dQ", "Kg/Kg/s",
-c     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
-c     .                "ave(X)", zsto,zout)
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+
+         CALL histdef(nid_mth, "ptconv", "POINTS CONVECTIFS"," ",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+
+         CALL histdef(nid_mth, "ratqs", "RATQS"," ",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+
+c
+         CALL histdef(nid_mth, "dtajs", "Dry adjust. dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+
+         CALL histdef(nid_mth, "dqajs", "Dry adjust. dQ", "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtswr", "SW radiation dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtsw0", "SW radiation dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtlwr", "LW radiation dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtlw0", "LW radiation dT", "K/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "duvdf", "Boundary-layer dU", "m/s2",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dvvdf", "Boundary-layer dV", "m/s2",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          IF (ok_orodr) THEN
          CALL histdef(nid_mth, "duoro", "Orography dU", "m/s2",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dvoro", "Orography dV", "m/s2",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
@@ -1128,14 +1244,14 @@
          IF (ok_orolf) THEN
          CALL histdef(nid_mth, "dulif", "Orography dU", "m/s2",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dvlif", "Orography dV", "m/s2",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
          ENDIF
 C
          CALL histdef(nid_mth, "ozone", "Ozone concentration", "-",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
 c
@@ -1145,5 +1261,5 @@
          WRITE(str2,'(i2.2)') iq
          CALL histdef(nid_mth, "trac"//str2, "Tracer No."//str2, "-",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
          ELSE
@@ -1154,15 +1270,30 @@
          ENDIF
 c
+cKE43
+      IF (iflag_con.EQ.4) THEN ! (sb)
+c
+         CALL histdef(nid_mth, "upwd", "saturated updraft", "Kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "dnwd", "saturated downdraft","Kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "dnwd0", "unsat. downdraft", "Kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth,"Ma","undilute adiab updraft","Kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+c
+      ENDIF
+c34EK
          CALL histend(nid_mth)
 c
-         ndex(1) = 0
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-         CALL histwrite(nid_mth,"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_mth,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+         ndex2d = 0
+         ndex3d = 0
 c
       ENDIF ! fin de test sur ok_mensuel
@@ -1171,24 +1302,23 @@
       IF (ok_instan) THEN
 c
-c         CALL ymds2ju(1900, 1, 1, 0.0, zjulian)
-         CALL ymds2ju(anneeref, 1, 1, 0.0, zjulian)
-         zjulian = zjulian + dayref
-c
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,zx_lon)
+         CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
+         zjulian = zjulian + day_ini
+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,jjm+1) = rlon(i+1)
+            zx_lon(i,jjmp1) = rlon(i+1)
          ENDDO
          DO ll=1,klev
             znivsig(ll)=float(ll)
          ENDDO
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,zx_lat)
-         CALL histbeg("histins", iim,zx_lon, jjm+1,zx_lat,
-     .                 1,iim,1,jjm+1, 0, zjulian, dtime,
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+         CALL histbeg("histins", iim,zx_lon, jjmp1,zx_lat,
+     .                 1,iim,1,jjmp1, 0, zjulian, dtime,
      .                 nhori, nid_ins)
-c         CALL histvert(nid_ins, "presnivs", "Vertical levels", "mb",
-c     .                 klev, presnivs, nvert)
-         call histvert(nid_ins, 'sig_s', 'Niveaux sigma','-',
-     .              klev, znivsig, nvert)
+         CALL histvert(nid_ins, "presnivs", "Vertical levels", "mb",
+     .                 klev, presnivs, nvert)
+c        call histvert(nid_ins, 'sig_s', 'Niveaux sigma','-',
+c    .              klev, znivsig, nvert)
 c
          zsto = dtime * ecrit_ins
@@ -1196,9 +1326,9 @@
 C
          CALL histdef(nid_ins, "phis", "Surface geop. height", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "once", zsto,zout)
 c
          CALL histdef(nid_ins, "aire", "Grid area", "-",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "once", zsto,zout)
 c
@@ -1206,9 +1336,9 @@
 c
          CALL histdef(nid_ins, "psol", "Surface Pressure", "Pa",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "inst(X)", zsto,zout)
 c
          CALL histdef(nid_ins, "topl", "OLR", "W/m2",
-     .                iim,jjm+1,nhori, 1,1,1, -99, 32,
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "inst(X)", zsto,zout)
 c
@@ -1216,34 +1346,27 @@
 c
          CALL histdef(nid_ins, "temp", "Temperature", "K",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "inst(X)", zsto,zout)
 c
          CALL histdef(nid_ins, "vitu", "Zonal wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "inst(X)", zsto,zout)
 c
          CALL histdef(nid_ins, "vitv", "Merid wind", "m/s",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "inst(X)", zsto,zout)
 c
          CALL histdef(nid_ins, "geop", "Geopotential height", "m",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "inst(X)", zsto,zout)
 c
          CALL histdef(nid_ins, "pres", "Air pressure", "Pa",
-     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "inst(X)", zsto,zout)
 c
          CALL histend(nid_ins)
 c
-         ndex(1) = 0
-c
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
-         CALL histwrite(nid_ins,"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_ins,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+         ndex2d = 0
+         ndex3d = 0
 c
       ENDIF
@@ -1328,4 +1451,23 @@
       ENDIF
 c
+c Diagnostiquer la tendance dynamique
+c
+      IF (ancien_ok) THEN
+         DO k = 1, klev
+         DO i = 1, klon
+            d_t_dyn(i,k) = (t_seri(i,k)-t_ancien(i,k))/dtime
+            d_q_dyn(i,k) = (q_seri(i,k)-q_ancien(i,k))/dtime
+         ENDDO
+         ENDDO
+      ELSE
+         DO k = 1, klev
+         DO i = 1, klon
+            d_t_dyn(i,k) = 0.0
+            d_q_dyn(i,k) = 0.0
+         ENDDO
+         ENDDO
+         ancien_ok = .TRUE.
+      ENDIF
+c
 c Ajouter le geopotentiel du sol:
 c
@@ -1351,9 +1493,58 @@
       IF (MOD(itap-1,lmt_pas) .EQ. 0) THEN
          idayvrai = NINT(xjour)
-         PRINT *,' PHYS cond  julien ',julien,idayvrai
+         PRINT *,' PHYS cond  julien ',julien,idayvrai,ok_limitvrai
          CALL condsurf(julien,idayvrai, pctsrf ,
      .                  lmt_sst,lmt_alb,lmt_rug,lmt_bils  )
          CALL ozonecm( FLOAT(julien), rlat, paprs, wo)
       ENDIF
+cccccccccc
+      IF (ok_oasis .AND. MOD(itap-1,nexca).EQ.0) THEN
+C
+         CALL fromcpl(itap,jjmp1*iim,
+     .        cpl_sst,cpl_sic,cpl_alb_sst,cpl_alb_sic)
+         DO i = 1, iim-1 ! un seul point pour le pole nord
+            cpl_sst(i,1) = cpl_sst(iim,1)
+            cpl_sic(i,1) = cpl_sic(iim,1)
+            cpl_alb_sst(i,1) = cpl_alb_sst(iim,1)
+            cpl_alb_sic(i,1) = cpl_alb_sic(iim,1)
+         ENDDO
+         DO i = 2, iim ! un seul point pour le pole sud
+            cpl_sst(i,jjmp1) = cpl_sst(1,jjmp1)
+            cpl_sic(i,jjmp1) = cpl_sic(1,jjmp1)
+            cpl_alb_sst(i,jjmp1) = cpl_alb_sst(1,jjmp1)
+            cpl_alb_sic(i,jjmp1) = cpl_alb_sic(1,jjmp1)
+         ENDDO
+c
+         ig = 1
+         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
+     .       pctsrf(ig,is_sic).GT.epsfra) THEN
+            pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
+     .                        - (cpl_sic(1,1)-pctsrf(ig,is_sic))
+            pctsrf(ig,is_sic) = cpl_sic(1,1)
+            lmt_sst(ig) = cpl_sst(1,1)
+         ENDIF
+         DO j = 2, jjm
+         DO i = 1, iim
+         ig = ig + 1
+         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
+     .       pctsrf(ig,is_sic).GT.epsfra) THEN
+           pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
+     .                       - (cpl_sic(i,j)-pctsrf(ig,is_sic))
+           pctsrf(ig,is_sic) = cpl_sic(i,j)
+           lmt_sst(ig) = cpl_sst(i,j)
+         ENDIF
+         ENDDO
+         ENDDO
+         ig = ig + 1
+         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
+     .       pctsrf(ig,is_sic).GT.epsfra) THEN
+            pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
+     .                        - (cpl_sic(1,jjmp1)-pctsrf(ig,is_sic))
+            pctsrf(ig,is_sic) = cpl_sic(1,jjmp1)
+            lmt_sst(ig) = cpl_sst(1,jjmp1)
+         ENDIF
+c
+      ENDIF ! ok_oasis
+cccccccccc
 c
  
@@ -1436,4 +1627,10 @@
       DO i = 1, klon
          zxtsol(i) = 0.0
+         IF ( abs( pctsrf(i, is_ter) + pctsrf(i, is_lic) + 
+     $       pctsrf(i, is_oce) + pctsrf(i, is_sic)  - 1.) .GT. EPSFRA) 
+     $       THEN 
+             WRITE(*,*) 'physiq : pb sous surface au point ', i, 
+     $           pctsrf(i, 1 : nbsrf)
+         ENDIF 
       ENDDO
       DO nsrf = 1, nbsrf
@@ -1448,7 +1645,7 @@
 c
       DO nsrf = 1, nbsrf
-      DO i = 1, klon
-         IF (pctsrf(i,nsrf).LT.epsfra) ftsol(i,nsrf) = zxtsol(i)
-      ENDDO
+        DO i = 1, klon
+          IF (pctsrf(i,nsrf) .LT. epsfra) ftsol(i,nsrf) = zxtsol(i)
+        ENDDO
       ENDDO
 
@@ -1478,5 +1675,5 @@
       DO k = 1, klev
       DO i = 1, klon
-         conv_q(i,k) = d_qx_dyn(i,k,ivap) 
+         conv_q(i,k) = d_q_dyn(i,k) 
      .               + d_q_vdf(i,k)/dtime
          conv_t(i,k) = d_t_dyn(i,k) 
@@ -1485,5 +1682,19 @@
       ENDDO
       IF (check) THEN
-         CALL qcheck(klon,klev,paprs,q_seri,ql_seri,"avantcon=")
+         za = qcheck(klon,klev,paprs,q_seri,ql_seri,paire)
+         PRINT*, "avantcon=", za
+      ENDIF
+      zx_ajustq = .FALSE.
+      IF (iflag_con.EQ.2) zx_ajustq=.TRUE.
+      IF (zx_ajustq) THEN
+         DO i = 1, klon
+            z_avant(i) = 0.0
+         ENDDO
+         DO k = 1, klev
+         DO i = 1, klon
+            z_avant(i) = z_avant(i) + (q_seri(i,k)+ql_seri(i,k))
+     .                        *(paprs(i,k)-paprs(i,k+1))/RG
+         ENDDO
+         ENDDO
       ENDIF
       IF (iflag_con.EQ.1) THEN
@@ -1507,35 +1718,102 @@
 c    s             d_t_con, d_q_con, 
 c    s             rain_con, snow_con, ibas_con, itop_con)
+cKE43
+      ELSE IF (iflag_con.EQ.4) THEN
+c nb of tracers for the KE convection:
+          if (nqmax .GE. 4) then
+              ntra = nbtr
+          else
+              ntra = 1 
+          endif
+cke43 (arguments inutiles enleves => des SAVE dans conema43?)
+c$$$          CALL conema43(dtime,paprs,pplay,t_seri,q_seri,
+c$$$     $        u_seri,v_seri,tr_seri,nbtr,
+c$$$     .        ema_workcbmf,
+c$$$     .        d_t_con,d_q_con,d_u_con,d_v_con,d_tr,
+c$$$     .        wdn, tdn, qdn,
+c$$$     .        rain_con, snow_con, ibas_con, itop_con,
+c$$$     .        upwd,dnwd,dnwd0,bas,top,Ma,cape,tvp,rflag,
+c$$$     .        pbase
+c$$$     .        ,bbase,dtvpdt1,dtvpdq1,dplcldt,dplcldr,
+c$$$     .        pori_con,plcl_con,dtma_con,dtlcl_con)
+          CALL conema (dtime,paprs,pplay,t_seri,q_seri,
+     $        u_seri,v_seri,tr_seri,nbtr,
+     .        ema_work1,ema_work2,
+     .        d_t_con,d_q_con,d_u_con,d_v_con,d_tr,
+c$$$     .        wdn, tdn, qdn,
+     .        rain_con, snow_con, ibas_con, itop_con,
+     .        upwd,dnwd,dnwd0,bas,top,Ma,cape,tvp,rflag,
+     .        pbase
+     .        ,bbase,dtvpdt1,dtvpdq1,dplcldt,dplcldr)
+c$$$     .        pori_con,plcl_con,dtma_con,dtlcl_con)
+          DO i = 1, klon
+            ema_pcb(i)  = pbase(i)
+          ENDDO
+          DO i = 1, klon
+            ema_pct(i)  = paprs(i,itop_con(i))
+          ENDDO
+          DO i = 1, klon
+            ema_cbmf(i) = ema_workcbmf(i)
+          ENDDO      
       ELSE
-      PRINT*, "iflag_con non-prevu", iflag_con
-      CALL abort
+          PRINT*, "iflag_con non-prevu", iflag_con
+          CALL abort
       ENDIF
       CALL homogene(paprs, q_seri, d_q_con, u_seri,v_seri,
      .              d_u_con, d_v_con)
       DO k = 1, klev
-      DO i = 1, klon
-         t_seri(i,k) = t_seri(i,k) + d_t_con(i,k)
-         q_seri(i,k) = q_seri(i,k) + d_q_con(i,k)
-         u_seri(i,k) = u_seri(i,k) + d_u_con(i,k)
-         v_seri(i,k) = v_seri(i,k) + d_v_con(i,k)
-      ENDDO
+        DO i = 1, klon
+          t_seri(i,k) = t_seri(i,k) + d_t_con(i,k)
+          q_seri(i,k) = q_seri(i,k) + d_q_con(i,k)
+          u_seri(i,k) = u_seri(i,k) + d_u_con(i,k)
+          v_seri(i,k) = v_seri(i,k) + d_v_con(i,k)
+        ENDDO
       ENDDO
       IF (check) THEN
-         CALL qcheck(klon,klev,paprs,q_seri,ql_seri,"aprescon=")
-         zx_t = 0.0
-         DO i = 1, klon
-            zx_t = zx_t + rain_con(i)+snow_con(i)
-         ENDDO
-         zx_t = zx_t/FLOAT(klon)*dtime
-         PRINT*, "Precip=", zx_t
-      ENDIF
+          za = qcheck(klon,klev,paprs,q_seri,ql_seri,paire)
+          PRINT*, "aprescon=", za
+          zx_t = 0.0
+          za = 0.0
+          DO i = 1, klon
+            za = za + paire(i)/FLOAT(klon)
+            zx_t = zx_t + (rain_con(i)+snow_con(i))*paire(i)/FLOAT(klon)
+          ENDDO
+          zx_t = zx_t/za*dtime
+          PRINT*, "Precip=", zx_t
+      ENDIF
+      IF (zx_ajustq) THEN
+          DO i = 1, klon
+            z_apres(i) = 0.0
+          ENDDO
+          DO k = 1, klev
+            DO i = 1, klon
+              z_apres(i) = z_apres(i) + (q_seri(i,k)+ql_seri(i,k))
+     .            *(paprs(i,k)-paprs(i,k+1))/RG
+            ENDDO
+          ENDDO
+          DO i = 1, klon
+            z_factor(i) = (z_avant(i)-(rain_con(i)+snow_con(i))*dtime)
+     .          /z_apres(i)
+          ENDDO
+          DO k = 1, klev
+            DO i = 1, klon
+              IF (z_factor(i).GT.(1.0+1.0E-08) .OR.
+     .            z_factor(i).LT.(1.0-1.0E-08)) THEN
+                  q_seri(i,k) = q_seri(i,k) * z_factor(i)
+              ENDIF
+            ENDDO
+          ENDDO
+      ENDIF
+      zx_ajustq=.FALSE.
 c
       IF (nqmax.GT.2) THEN !--melange convectif de traceurs
 c
-      IF (iflag_con.NE.2) THEN
-         PRINT*, "Pour l instant, seul conflx fonctionne avec traceurs"
-         PRINT*,' Mettre iflag_con = 2  dans  run.def et repasser  !'
-         CALL abort
-      ENDIF
+          IF (iflag_con .NE. 2 .AND.  iflag_con .NE. 4 ) THEN 
+              PRINT*, 'Pour l instant, seul conflx fonctionne ',
+     $            'avec traceurs', iflag_con
+              PRINT*,' Mettre iflag_con', 
+     $            ' = 2  ou 4 dans run.def et repasser'
+              CALL abort
+              ENDIF 
 c
       ENDIF !--nqmax.GT.2
@@ -1543,5 +1821,16 @@
 c Appeler l'ajustement sec
 c
-C appel supprime pour le moment
+      CALL ajsec(paprs, pplay, t_seri, q_seri, d_t_ajs, d_q_ajs)
+      DO k = 1, klev
+      DO i = 1, klon
+         t_seri(i,k) = t_seri(i,k) + d_t_ajs(i,k)
+         q_seri(i,k) = q_seri(i,k) + d_q_ajs(i,k)
+      ENDDO
+      ENDDO
+
+c   RATQS
+      call calcratqs (
+     I            paprs,pplay,q_seri,d_t_con,d_t_ajs
+     O           ,ratqs,zpt_conv)
 c
 c Appeler le processus de condensation a grande echelle
@@ -1549,9 +1838,10 @@
 c
       CALL fisrtilp_tr(dtime,paprs,pplay,
-     .           t_seri, q_seri,
+     .           t_seri, q_seri,ratqs,
      .           d_t_lsc, d_q_lsc, d_ql_lsc, rneb, cldliq,
      .           rain_lsc, snow_lsc,
      .           pfrac_impa, pfrac_nucl, pfrac_1nucl,
-     .           frac_impa, frac_nucl )
+     .           frac_impa, frac_nucl,
+     .           prfl, psfl)
       DO k = 1, klev
       DO i = 1, klon
@@ -1564,10 +1854,13 @@
       ENDDO
       IF (check) THEN
-         CALL qcheck(klon,klev,paprs,q_seri,ql_seri,"apresilp=")
+         za = qcheck(klon,klev,paprs,q_seri,ql_seri,paire)
+         PRINT*, "apresilp=", za
          zx_t = 0.0
+         za = 0.0
          DO i = 1, klon
-            zx_t = zx_t + rain_lsc(i)+snow_lsc(i)
-         ENDDO
-         zx_t = zx_t/FLOAT(klon)*dtime
+            za = za + paire(i)/FLOAT(klon)
+            zx_t = zx_t + (rain_lsc(i)+snow_lsc(i))*paire(i)/FLOAT(klon)
+        ENDDO
+         zx_t = zx_t/za*dtime
          PRINT*, "Precip=", zx_t
       ENDIF
@@ -1576,7 +1869,21 @@
 c
       IF (iflag_con.EQ.2) THEN ! seulement pour Tiedtke
-      CALL diagcld(paprs,pplay,t_seri,q_seri,
+      CALL diagcld1(paprs,pplay,
      .             rain_con,snow_con,ibas_con,itop_con,
      .             diafra,dialiq)
+      DO k = 1, klev
+      DO i = 1, klon
+      IF (diafra(i,k).GT.cldfra(i,k)) THEN
+         cldliq(i,k) = dialiq(i,k)
+         cldfra(i,k) = diafra(i,k)
+      ENDIF
+      ENDDO
+      ENDDO
+      ENDIF
+c
+c Nuages stratus artificiels:
+c
+      IF (ok_stratus) THEN
+      CALL diagcld2(paprs,pplay,t_seri,q_seri, diafra,dialiq)
       DO k = 1, klev
       DO i = 1, klon
@@ -1792,9 +2099,25 @@
 c   Calcul  des tendances traceurs
 c====================================================================
+C Pascale : il faut quand meme apeller phytrac car il gere les sorties
+cKE43       des traceurs => il faut donc mettre des flags a .false.
+      IF (iflag_con.EQ.4) THEN
+c           on ajoute les tendances calculees par KE43
+        DO iq=1, nqmax-2 ! Sandrine a -3 ???
+        DO k = 1, nlev
+        DO i = 1, klon
+          tr_seri(i,k,iq) = tr_seri(i,k,iq) + d_tr(i,k,iq)
+        ENDDO
+        ENDDO
+        WRITE(iqn,'(i2.2)') iq
+        CALL minmaxqfi(tr_seri(1,1,iq),0.,1.e33,'couche lim iq='//iqn)
+        ENDDO
+CMAF modif pour garder info du nombre de traceurs auxquels
+C la physique s'applique
+      ELSE
 CMAF modif pour garder info du nombre de traceurs auxquels
 C la physique s'applique
 C
       call phytrac (rnpb,
-     I                   debut,
+     I                   debut,lafin,
      I                   nqmax-2,
      I                   nlon,nlev,dtime,
@@ -1805,11 +2128,15 @@
      I                   rlon,presnivs,paire,pphis,
      O                   tr_seri)
+      ENDIF 
 
       IF (offline) THEN
-      call phystoke (
-     I                   nlon,nlev,pdtphys,
-     I                   pmfu, pmfd, pen_u, pde_u, pen_d, pde_d,
+
+	 call phystokenc (
+     I                   nlon,nlev,pdtphys,rlon,rlat,
+     I                   t,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d,
      I                   ycoefh,yu1,yv1,ftsol,pctsrf,
-     I                   frac_impa, frac_nucl)
+     I                   frac_impa, frac_nucl,
+     I                   pphis,paire,dtime,itap)
+
 
       ENDIF
@@ -1843,401 +2170,446 @@
       IF (ok_journe) THEN
 c
-      ndex(1) = 0
+      ndex2d = 0
+      ndex3d = 0
 c
 c Champs 2D:
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zxtsol,zx_tmp_2d)
-      CALL histwrite(nid_day,"tsol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_day,"phis",i,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
+         CALL histwrite(nid_day,"aire",i,zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
+      CALL histwrite(nid_day,"tsol",itap,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,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"psol",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"rain",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, snow_fall,zx_tmp_2d)
-      CALL histwrite(nid_day,"snow",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, evap,zx_tmp_2d)
-      CALL histwrite(nid_day,"evap",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, topsw,zx_tmp_2d)
-      CALL histwrite(nid_day,"tops",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_day,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, solsw,zx_tmp_2d)
-      CALL histwrite(nid_day,"sols",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, sollw,zx_tmp_2d)
-      CALL histwrite(nid_day,"soll",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, bils,zx_tmp_2d)
-      CALL histwrite(nid_day,"bils",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, sens,zx_tmp_2d)
-      CALL histwrite(nid_day,"sens",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, fder,zx_tmp_2d)
-      CALL histwrite(nid_day,"fder",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, ruis,zx_tmp_2d)
-      CALL histwrite(nid_day,"ruis",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"rain",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
+      CALL histwrite(nid_day,"snow",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
+      CALL histwrite(nid_day,"evap",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
+      CALL histwrite(nid_day,"tops",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
+      CALL histwrite(nid_day,"topl",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
+      CALL histwrite(nid_day,"sols",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
+      CALL histwrite(nid_day,"soll",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
+      CALL histwrite(nid_day,"bils",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
+      CALL histwrite(nid_day,"sens",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
+      CALL histwrite(nid_day,"fder",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ruis,zx_tmp_2d)
+      CALL histwrite(nid_day,"ruis",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = fluxu(i,1)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"frtu",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"frtu",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = fluxv(i,1)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"frtv",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"frtv",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = pctsrf(i,is_sic)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_day,"sicf",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldl,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldm,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldm",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldh,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldh",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldt,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldt",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldq,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"sicf",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
+      CALL histwrite(nid_day,"cldl",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
+      CALL histwrite(nid_day,"cldm",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
+      CALL histwrite(nid_day,"cldh",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+      CALL histwrite(nid_day,"cldt",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
+      CALL histwrite(nid_day,"cldq",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
 c Champs 3D:
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t_seri, zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
       CALL histwrite(nid_day,"temp",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, qx(1,1,ivap), zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
       CALL histwrite(nid_day,"ovap",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zphi, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
       CALL histwrite(nid_day,"geop",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, u_seri, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
       CALL histwrite(nid_day,"vitu",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, v_seri, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
       CALL histwrite(nid_day,"vitv",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, omega, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
       CALL histwrite(nid_day,"vitw",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, pplay, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
       CALL histwrite(nid_day,"pres",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      if (ok_sync) call histsync
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      if (ok_sync) then
+        call histsync(nid_day)
+      endif
       ENDIF
 C
       IF (ok_mensuel) THEN
 c
-      ndex(1) = 0
+      ndex2d = 0
+      ndex3d = 0
 c
 c Champs 2D:
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zxtsol,zx_tmp_2d)
-      CALL histwrite(nid_mth,"tsol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_mth,"phis",i,zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
+         CALL histwrite(nid_mth,"aire",i,zx_tmp_2d,iim*jjmp1,ndex2d)
+
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tsol",itap,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,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zxqsol,zx_tmp_2d)
-      CALL histwrite(nid_mth,"qsol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"psol",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxqsol,zx_tmp_2d)
+      CALL histwrite(nid_mth,"qsol",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"rain",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"rain",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"plul",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"plul",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"pluc",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, snow_fall,zx_tmp_2d)
-      CALL histwrite(nid_mth,"snow",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, agesno,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ages",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, evap,zx_tmp_2d)
-      CALL histwrite(nid_mth,"evap",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, topsw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"tops",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, solsw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sols",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, sollw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"soll",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, topsw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"tops0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"topl0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, solsw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sols0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, sollw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"soll0",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, bils,zx_tmp_2d)
-      CALL histwrite(nid_mth,"bils",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, sens,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sens",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, fder,zx_tmp_2d)
-      CALL histwrite(nid_mth,"fder",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, ruis,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ruis",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"pluc",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
+      CALL histwrite(nid_mth,"snow",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, agesno,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ages",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
+      CALL histwrite(nid_mth,"evap",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tops",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"topl",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sols",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"soll",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tops0",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"topl0",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sols0",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"soll0",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
+      CALL histwrite(nid_mth,"bils",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sens",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fder",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ruis,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ruis",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = fluxu(i,1)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"frtu",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"frtu",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = fluxv(i,1)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"frtv",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"frtv",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
       DO i = 1, klon
          zx_tmp_fi2d(i) = pctsrf(i,is_sic)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_mth,"sicf",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, albsol,zx_tmp_2d)
-      CALL histwrite(nid_mth,"albs",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cdragm,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cdrm",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cdragh,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cdrh",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldl,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldm,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldm",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldh,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldh",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldt,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldt",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, cldq,zx_tmp_2d)
-      CALL histwrite(nid_mth,"cldq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, ue,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ue",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, ve,zx_tmp_2d)
-      CALL histwrite(nid_mth,"ve",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, uq,zx_tmp_2d)
-      CALL histwrite(nid_mth,"uq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, vq,zx_tmp_2d)
-      CALL histwrite(nid_mth,"vq",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sicf",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsol,zx_tmp_2d)
+      CALL histwrite(nid_mth,"albs",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cdrm",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cdrh",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldl",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldm",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldh",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldt",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldq",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ue",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ve",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, uq,zx_tmp_2d)
+      CALL histwrite(nid_mth,"uq",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vq,zx_tmp_2d)
+      CALL histwrite(nid_mth,"vq",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+cKE43
+      IF (iflag_con .EQ. 4) THEN ! sb
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cape,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cape",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,pbase,zx_tmp_2d)
+      CALL histwrite(nid_mth,"pbase",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_pct,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ptop",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_cbmf,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fbase",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c
+      ENDIF
+c34EK
 c
 c Champs 3D:
 C
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t_seri, zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
       CALL histwrite(nid_mth,"temp",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, qx(1,1,ivap), zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
       CALL histwrite(nid_mth,"ovap",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zphi, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
       CALL histwrite(nid_mth,"geop",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, u_seri, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
       CALL histwrite(nid_mth,"vitu",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, v_seri, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
       CALL histwrite(nid_mth,"vitv",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, omega, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
       CALL histwrite(nid_mth,"vitw",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, pplay, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
       CALL histwrite(nid_mth,"pres",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cldfra, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra, zx_tmp_3d)
       CALL histwrite(nid_mth,"rneb",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zx_rh, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_rh, zx_tmp_3d)
       CALL histwrite(nid_mth,"rhum",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cldliq, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldliq, zx_tmp_3d)
       CALL histwrite(nid_mth,"oliq",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_dyn, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtdyn",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_qx_dyn(1,1,ivap),
-     .                 zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqdyn",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_con, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_con, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtcon",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_con, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_con, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqcon",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_lsc, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_lsc, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtlsc",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_lsc, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_lsc, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqlsc",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_vdf, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_vdf, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_eva, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_eva, zx_tmp_3d)
       CALL histwrite(nid_mth,"dteva",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_eva, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_eva, zx_tmp_3d)
       CALL histwrite(nid_mth,"dqeva",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-C      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_ajs, zx_tmp_3d)
-C      CALL histwrite(nid_mth,"dtajs",itap,zx_tmp_3d,
-C    .                                   iim*(jjm+1)*klev,ndex)
-c
-C      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_ajs, zx_tmp_3d)
-C      CALL histwrite(nid_mth,"dqajs",itap,zx_tmp_3d,
-C     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, heat, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zpt_conv, zx_tmp_3d)
+      CALL histwrite(nid_mth,"ptconv",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, ratqs, zx_tmp_3d)
+      CALL histwrite(nid_mth,"ratqs",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_ajs, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtajs",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_ajs, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqajs",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, heat, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtswr",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, heat0, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, heat0, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtsw0",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cool, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cool, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtlwr",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, cool0, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cool0, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtlw0",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_u_vdf, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"duvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_v_vdf, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_vdf, zx_tmp_3d)
       CALL histwrite(nid_mth,"dvvdf",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*jjmp1*klev,ndex3d)
 c
       IF (ok_orodr) THEN
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_u_oro, zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_oro, zx_tmp_3d)
       CALL histwrite(nid_mth,"duoro",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_v_oro, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_oro, zx_tmp_3d)
       CALL histwrite(nid_mth,"dvoro",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*jjmp1*klev,ndex3d)
 c
       ENDIF
 C
       IF (ok_orolf) THEN
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_u_lif, zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_lif, zx_tmp_3d)
       CALL histwrite(nid_mth,"dulif",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_v_lif, zx_tmp_3d)
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_lif, zx_tmp_3d)
       CALL histwrite(nid_mth,"dvlif",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*jjmp1*klev,ndex3d)
       ENDIF
 C
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, wo, zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
       CALL histwrite(nid_mth,"ozone",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*jjmp1*klev,ndex3d)
 c
       IF (nqmax.GE.3) THEN
       DO iq=1,nqmax-2
       IF (iq.LE.99) THEN
-         CALL gr_fi_ecrit(klev,klon,iim,jjm+1, qx(1,1,iq+2), zx_tmp_3d)
+         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq+2), zx_tmp_3d)
          WRITE(str2,'(i2.2)') iq
          CALL histwrite(nid_mth,"trac"//str2,itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
+     .                                   iim*jjmp1*klev,ndex3d)
       ELSE
          PRINT*, "Trop de traceurs"
@@ -2246,46 +2618,81 @@
       ENDDO
       ENDIF
-c
-      if (ok_sync) call histsync
+cKE43
+      IF (iflag_con.EQ.4) THEN ! (sb)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, upwd, zx_tmp_3d)
+      CALL histwrite(nid_mth,"upwd",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dnwd",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd0, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dnwd0",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
+      CALL histwrite(nid_mth,"Ma",itap,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+c
+      ENDIF
+c34EK
+c
+      if (ok_sync) then
+        call histsync(nid_mth)
+      endif
       ENDIF
 c
       IF (ok_instan) THEN
 c
-      ndex(1) = 0
+      ndex2d = 0
+      ndex3d = 0
 c
 c Champs 2D:
 c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
+         CALL histwrite(nid_ins,"phis",i,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+         i = NINT(zout/zsto)
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
+         CALL histwrite(nid_ins,"aire",i,zx_tmp_2d,iim*jjmp1,ndex2d)
+
       DO i = 1, klon
          zx_tmp_fi2d(i) = paprs(i,1)
       ENDDO
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_ins,"psol",itap,zx_tmp_2d,iim*(jjm+1),ndex)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjm+1, toplw,zx_tmp_2d)
-      CALL histwrite(nid_ins,"topl",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_ins,"psol",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
+      CALL histwrite(nid_ins,"topl",itap,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
 c Champs 3D:
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t_seri, zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
       CALL histwrite(nid_ins,"temp",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, u_seri, 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",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, v_seri, 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",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, zphi, 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",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, pplay, 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",itap,zx_tmp_3d,
-     .                                   iim*(jjm+1)*klev,ndex)
-c
-      if (ok_sync) call histsync
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      if (ok_sync) then
+        call histsync(nid_ins)
+      endif
       ENDIF
 c
@@ -2332,21 +2739,21 @@
          ig = ig + 1
          DO i = 1, iim
-            z_sols(i,jjm+1)    = oas_sols(ig)
-            z_nsol(i,jjm+1)    = oas_nsol(ig)
-            z_rain(i,jjm+1)    = oas_rain(ig)
-            z_snow(i,jjm+1)    = oas_snow(ig)
-            z_evap(i,jjm+1)    = oas_evap(ig)
-            z_ruisoce(i,jjm+1) = oas_ruisoce(ig)
-            z_ruisriv(i,jjm+1) = oas_ruisriv(ig)
-            z_tsol(i,jjm+1)    = oas_tsol(ig)
-            z_fder(i,jjm+1)    = oas_fder(ig)
-            z_albe(i,jjm+1)    = oas_albe(ig)
-            z_taux(i,jjm+1)    = oas_taux(ig)
-            z_tauy(i,jjm+1)    = oas_tauy(ig)
+            z_sols(i,jjmp1)    = oas_sols(ig)
+            z_nsol(i,jjmp1)    = oas_nsol(ig)
+            z_rain(i,jjmp1)    = oas_rain(ig)
+            z_snow(i,jjmp1)    = oas_snow(ig)
+            z_evap(i,jjmp1)    = oas_evap(ig)
+            z_ruisoce(i,jjmp1) = oas_ruisoce(ig)
+            z_ruisriv(i,jjmp1) = oas_ruisriv(ig)
+            z_tsol(i,jjmp1)    = oas_tsol(ig)
+            z_fder(i,jjmp1)    = oas_fder(ig)
+            z_albe(i,jjmp1)    = oas_albe(ig)
+            z_taux(i,jjmp1)    = oas_taux(ig)
+            z_tauy(i,jjmp1)    = oas_tauy(ig)
          ENDDO
 c
 c Passer les champs au coupleur:
 c
-         CALL intocpl(itap,(jjm+1)*iim,
+         CALL intocpl(itap,jjmp1*iim,
      .                   z_sols, z_nsol,
      .                   z_rain, z_snow, z_evap,
@@ -2433,4 +2840,13 @@
       ENDIF
 c
+c Sauvegarder les valeurs de t et q a la fin de la physique:
+c
+      DO k = 1, klev
+      DO i = 1, klon
+         t_ancien(i,k) = t_seri(i,k)
+         q_ancien(i,k) = q_seri(i,k)
+      ENDDO
+      ENDDO
+c
 c====================================================================
 c Si c'est la fin, il faut conserver l'etat de redemarrage
@@ -2438,14 +2854,15 @@
 c
       IF (lafin) THEN
-         IF (ok_oasis) CALL quitcpl
+ccc         IF (ok_oasis) CALL quitcpl
          CALL phyredem ("restartphy.nc",dtime,radpas,co2_ppm,solaire,
      .        rlat,rlon,ftsol,ftsoil,deltat,fqsol,fsnow,
      .        radsol,rugmer,agesno,
-     .        zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro)
+     .        zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro,
+     .        t_ancien, q_ancien)
       ENDIF
 
       RETURN
       END
-      SUBROUTINE qcheck(klon,klev,paprs,q,ql,marque)
+      FUNCTION qcheck(klon,klev,paprs,q,ql,aire)
       IMPLICIT none
 c
@@ -2456,18 +2873,23 @@
       INTEGER klon,klev
       REAL paprs(klon,klev+1), q(klon,klev), ql(klon,klev)
-      CHARACTER *(*) marque
-      REAL qtotal
+      REAL aire(klon)
+      REAL qtotal, zx, qcheck
       INTEGER i, k
 c
+      zx = 0.0
+      DO i = 1, klon
+         zx = zx + aire(i)
+      ENDDO
       qtotal = 0.0
       DO k = 1, klev
       DO i = 1, klon
-         qtotal = qtotal + (q(i,k)+ql(i,k))
+         qtotal = qtotal + (q(i,k)+ql(i,k)) * aire(i)
      .                     *(paprs(i,k)-paprs(i,k+1))/RG
       ENDDO
       ENDDO
 c
-      PRINT*, "Eau totale ",marque, qtotal/FLOAT(klon)
-c
+      qcheck = qtotal/zx
+c
+      RETURN
       END
       SUBROUTINE gr_fi_ecrit(nfield,nlon,iim,jjmp1,fi,ecrit)
@@ -2478,5 +2900,5 @@
 c
       INTEGER nfield,nlon,iim,jjmp1, jjm
-      REAL fi(nlon,nfield), ecrit(iim,jjmp1,nfield)
+      REAL fi(nlon,nfield), ecrit(iim*jjmp1,nfield)
 c
       INTEGER i, j, n, ig
@@ -2485,14 +2907,12 @@
       DO n = 1, nfield
          DO i=1,iim
-            ecrit(i,1,n) = fi(1,n)
-            ecrit(i,jjm+1,n) = fi(nlon,n)
-         ENDDO
-         DO j = 2, jjm
-            ig = 2+(j-2)*iim
-            DO i = 1, iim
-               ecrit(i,j,n) = fi(ig-1+i,n)
-            ENDDO
+            ecrit(i,n) = fi(1,n)
+            ecrit(i+jjm*iim,n) = fi(nlon,n)
+         ENDDO
+         DO ig = 1, nlon - 2
+           ecrit(iim+ig,n) = fi(1+ig,n)
          ENDDO
       ENDDO
       RETURN
       END
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phystoke.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/phystoke.F	(revision 3)
+++ 	(revision )
@@ -1,214 +1,0 @@
-      SUBROUTINE phystoke (
-     I                   nlon,nlev,pdtphys,
-     I                   pmfu, pmfd, pen_u, pde_u, pen_d, pde_d,
-     I                   pcoefh,yu1,yv1,ftsol,pctsrf,
-     I                   frac_impa,frac_nucl)
-      IMPLICIT none
-
-c======================================================================
-c Auteur(s) FH
-c Objet: Moniteur general des tendances traceurs
-c
-
-c======================================================================
-#include "dimensions.h"
-#include "dimphy.h"
-#include "tracstoke.h"
-#include "indicesol.h"
-c======================================================================
-
-c Arguments:
-c
-c   EN ENTREE:
-c   ==========
-c
-c   divers:
-c   -------
-c
-      integer nlon ! nombre de points horizontaux
-      integer nlev ! nombre de couches verticales
-      real pdtphys ! pas d'integration pour la physique (seconde)
-c
-c   convection:
-c   -----------
-c
-      REAL pmfu(klon,klev)  ! flux de masse dans le panache montant
-      REAL pmfd(klon,klev)  ! flux de masse dans le panache descendant
-      REAL pen_u(klon,klev) ! flux entraine dans le panache montant
-      REAL pde_u(klon,klev) ! flux detraine dans le panache montant
-      REAL pen_d(klon,klev) ! flux entraine dans le panache descendant
-      REAL pde_d(klon,klev) ! flux detraine dans le panache descendant
-c
-c   Couche limite:
-c   --------------
-c
-      REAL pcoefh(klon,klev)    ! coeff melange CL
-      REAL yv1(klon)
-      REAL yu1(klon)
-c
-c   Lessivage:
-c   ----------
-c
-      REAL frac_impa(klon,klev)
-      REAL frac_nucl(klon,klev)
-c
-c Arguments necessaires pour les sources et puits de traceur
-C
-      real ftsol(klon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
-      real pctsrf(klon,nbsrf) ! Pourcentage de sol f(nature du sol)
-
-c======================================================================
-c
-      INTEGER i, k
-c
-      REAL mfu(klon,klev)  ! flux de masse dans le panache montant
-      REAL mfd(klon,klev)  ! flux de masse dans le panache descendant
-      REAL en_u(klon,klev) ! flux entraine dans le panache montant
-      REAL de_u(klon,klev) ! flux detraine dans le panache montant
-      REAL en_d(klon,klev) ! flux entraine dans le panache descendant
-      REAL de_d(klon,klev) ! flux detraine dans le panache descendant
-      REAL coefh(klon,klev) ! flux detraine dans le panache descendant
-
-      REAL pyu1(klon),pyv1(klon)
-      REAL pftsol(klon,nbsrf),ppsrf(klon,nbsrf)
-
-      REAL dtcum
-
-      integer iadvtr,irec
-      real zmin,zmax
-
-      save mfu,mfd,en_u,de_u,en_d,de_d,coefh,dtcum
-      save iadvtr,irec
-      save pyu1,pyv1,pftsol,ppsrf
-
-      data iadvtr,irec/0,1/
-c
-c   Couche limite:
-c======================================================================
-
-      print*,'iadvtr= ',iadvtr
-      print*,'istphy= ',istphy
-      print*,'istdyn= ',istdyn
-
-      IF (iadvtr.eq.0) THEN
-#ifdef CRAY
-         CALL ASSIGN("assign -N ieee -F null f:physique")
-#endif
-         open(49,file='physique',form='unformatted',
-     s        access='direct',recl=4*klon*(9*klev+2+2*nbsrf))
-      ENDIF
-c
-      iadvtr=iadvtr+1
-c
-      IF(mod(iadvtr,istphy).eq.0) THEN 
-c
-c   normalisation par le temps cumule
-         do k=1,klev
-            do i=1,klon
-               mfu(i,k)=mfu(i,k)/dtcum
-               mfd(i,k)=mfd(i,k)/dtcum
-               en_u(i,k)=en_u(i,k)/dtcum
-               de_u(i,k)=de_u(i,k)/dtcum
-               en_d(i,k)=en_d(i,k)/dtcum
-               de_d(i,k)=de_d(i,k)/dtcum
-               coefh(i,k)=coefh(i,k)/dtcum
-            enddo
-         enddo
-         do i=1,klon
-            pyv1(i)=pyv1(i)/dtcum
-            pyu1(i)=pyu1(i)/dtcum
-         end do
-         do k=1,nbsrf
-             do i=1,klon
-               pftsol(i,k)=pftsol(i,k)/dtcum
-               ppsrf(i,k)=ppsrf(i,k)/dtcum
-            enddo
-         enddo
-c
-c   ecriture des champs
-c
-         irec=irec+1
-         write(49,rec=1) float(irec),float(istphy),
-     s    float(klon),float(klev)
-         write(49,rec=irec) mfu,mfd,en_u,de_u,en_d,de_d
-     s        ,coefh
-     s        ,frac_impa,frac_nucl
-     s        ,pyu1,pyv1,pftsol,ppsrf
-c
-cAA Test sur la valeur des coefficients de lessivage 
-c
-         zmin=1e33
-         zmax=-1e33
-         do k=1,klev
-            do i=1,klon
-                  zmax=max(zmax,frac_nucl(i,k))
-                  zmin=min(zmin,frac_nucl(i,k))
-            enddo
-         enddo
-         Print*,'------ coefs de lessivage (min et max) --------'
-         Print*,'facteur de nucleation ',zmin,zmax
-         zmin=1e33
-         zmax=-1e33
-         do k=1,klev
-            do i=1,klon
-                  zmax=max(zmax,frac_impa(i,k))
-                  zmin=min(zmin,frac_impa(i,k))
-            enddo
-         enddo
-         Print*,'facteur d impaction ',zmin,zmax
-
-      ENDIF 
-
-c   reinitialisation des champs cumules
-      if (mod(iadvtr,istphy).eq.1) then
-         do k=1,klev
-            do i=1,klon
-               mfu(i,k)=0.
-               mfd(i,k)=0.
-               en_u(i,k)=0.
-               de_u(i,k)=0.
-               en_d(i,k)=0.
-               de_d(i,k)=0.
-               coefh(i,k)=0.
-            enddo
-         enddo
-         do i=1,klon
-            pyv1(i)=0.
-            pyu1(i)=0.
-         end do
-         do k=1,nbsrf
-             do i=1,klon
-               pftsol(i,k)=0.
-               ppsrf(i,k)=0.
-            enddo
-         enddo
-
-         dtcum=0.
-      endif
-
-      do k=1,klev
-         do i=1,klon
-            mfu(i,k)=mfu(i,k)+pmfu(i,k)*pdtphys
-            mfd(i,k)=mfd(i,k)+pmfd(i,k)*pdtphys
-            en_u(i,k)=en_u(i,k)+pen_u(i,k)*pdtphys
-            de_u(i,k)=de_u(i,k)+pde_u(i,k)*pdtphys
-            en_d(i,k)=en_d(i,k)+pen_d(i,k)*pdtphys
-            de_d(i,k)=de_d(i,k)+pde_d(i,k)*pdtphys
-            coefh(i,k)=coefh(i,k)+pcoefh(i,k)*pdtphys
-         enddo
-      enddo
-         do i=1,klon
-            pyv1(i)=pyv1(i)+yv1(i)*pdtphys
-            pyu1(i)=pyu1(i)+yu1(i)*pdtphys
-         end do
-         do k=1,nbsrf
-             do i=1,klon
-               pftsol(i,k)=pftsol(i,k)+ftsol(i,k)*pdtphys
-               ppsrf(i,k)=ppsrf(i,k)+pctsrf(i,k)*pdtphys
-            enddo
-         enddo
-
-      dtcum=dtcum+pdtphys
-
-      RETURN
-      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phystokenc.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phystokenc.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phystokenc.F	(revision 253)
@@ -0,0 +1,341 @@
+c
+c $Header$
+c
+      SUBROUTINE phystokenc (
+     I                   nlon,nlev,pdtphys,rlon,rlat,
+     I                   pt,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d,
+     I                   pcoefh,yu1,yv1,ftsol,pctsrf,
+     I                   pfrac_impa,pfrac_nucl,
+     I                   pphis,paire,dtime,itap)
+      USE ioipsl
+
+      IMPLICIT none
+
+c======================================================================
+c Auteur(s) FH
+c Objet: Moniteur general des tendances traceurs
+c
+
+c======================================================================
+#include "dimensions.h"
+#include "dimphy.h"
+#include "tracstoke.h"
+#include "indicesol.h"
+#include "control.h"
+c======================================================================
+
+c Arguments:
+c
+c   EN ENTREE:
+c   ==========
+c
+c   divers:
+c   -------
+c
+      integer nlon ! nombre de points horizontaux
+      integer nlev ! nombre de couches verticales
+      real pdtphys ! pas d'integration pour la physique (seconde)
+c
+      integer physid, itap,ndex(1)
+
+c   convection:
+c   -----------
+c
+      REAL pmfu(klon,klev)  ! flux de masse dans le panache montant
+      REAL pmfd(klon,klev)  ! flux de masse dans le panache descendant
+      REAL pen_u(klon,klev) ! flux entraine dans le panache montant
+      REAL pde_u(klon,klev) ! flux detraine dans le panache montant
+      REAL pen_d(klon,klev) ! flux entraine dans le panache descendant
+      REAL pde_d(klon,klev) ! flux detraine dans le panache descendant
+	REAL pt(klon,klev)
+c
+      REAL rlon(klon), rlat(klon), dtime
+      REAL zx_tmp_3d(iim,jjm+1,klev),zx_tmp_2d(iim,jjm+1)
+
+c   Couche limite:
+c   --------------
+c
+      REAL pcoefh(klon,klev)    ! coeff melange CL
+      REAL yv1(klon)
+      REAL yu1(klon),pphis(klon),paire(klon)
+c
+c   Lessivage:
+c   ----------
+c
+      REAL pfrac_impa(klon,klev)
+      REAL pfrac_nucl(klon,klev)
+c
+c Arguments necessaires pour les sources et puits de traceur
+C
+      real ftsol(klon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
+      real pctsrf(klon,nbsrf) ! Pourcentage de sol f(nature du sol)
+c======================================================================
+c
+      INTEGER i, k
+c
+      REAL mfu(klon,klev)  ! flux de masse dans le panache montant
+      REAL mfd(klon,klev)  ! flux de masse dans le panache descendant
+      REAL en_u(klon,klev) ! flux entraine dans le panache montant
+      REAL de_u(klon,klev) ! flux detraine dans le panache montant
+      REAL en_d(klon,klev) ! flux entraine dans le panache descendant
+      REAL de_d(klon,klev) ! flux detraine dans le panache descendant
+      REAL coefh(klon,klev) ! flux detraine dans le panache descendant
+	REAL t(klon,klev)
+      REAL frac_impa(klon,klev)
+      REAL frac_nucl(klon,klev)
+      REAL rain(klon)
+
+      REAL pyu1(klon),pyv1(klon)
+      REAL pftsol(klon,nbsrf),ppsrf(klon,nbsrf)
+      real pftsol1(klon),pftsol2(klon),pftsol3(klon),pftsol4(klon)
+      real ppsrf1(klon),ppsrf2(klon),ppsrf3(klon),ppsrf4(klon)
+
+      REAL dtcum
+
+      integer iadvtr,irec
+      real zmin,zmax
+
+      save t,mfu,mfd,en_u,de_u,en_d,de_d,coefh,dtcum
+      save iadvtr,irec
+      save frac_impa,frac_nucl,rain
+      save pyu1,pyv1,pftsol,ppsrf
+
+      data iadvtr,irec/0,1/
+c
+c   Couche limite:
+c======================================================================
+
+      print*,'iadvtr= ',iadvtr
+      print*,'istphy= ',istphy
+      print*,'istdyn= ',istdyn
+
+      IF (iadvtr.eq.0) THEN
+	
+	CALL initphysto('phystoke',
+     . rlon,rlat,dtime, dtime*istphy,dtime*istphy,nqmx,physid)
+  	
+	write(*,*) 'apres initphysto ds phystokenc' 
+
+       ndex(1) = 0
+         i=itap 
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,pphis,zx_tmp_2d)
+         CALL histwrite(physid,"phis",i,zx_tmp_2d,iim*(jjm+1),ndex)
+c
+         i=itap
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1,paire,zx_tmp_2d)
+         CALL histwrite(physid,"aire",i,zx_tmp_2d,iim*(jjm+1),ndex)
+	
+      ENDIF
+c
+      iadvtr=iadvtr+1
+c
+c
+c   reinitialisation des champs cumules
+      if (mod(iadvtr,istphy).eq.1.or.istphy.eq.1) then
+	print*,'reinitialisation des champs cumules 
+     s          a iadvtr=',iadvtr
+         do k=1,klev
+            do i=1,klon
+               frac_impa(i,k)=1.
+               frac_nucl(i,k)=1.
+               mfu(i,k)=0.
+               mfd(i,k)=0.
+               en_u(i,k)=0.
+               de_u(i,k)=0.
+               en_d(i,k)=0.
+               de_d(i,k)=0.
+               coefh(i,k)=0.
+		t(i,k)=0.
+            enddo
+         enddo
+         do i=1,klon
+            rain(i)=0.
+            pyv1(i)=0.
+            pyu1(i)=0.
+         end do
+         do k=1,nbsrf
+             do i=1,klon
+               pftsol(i,k)=0.
+               ppsrf(i,k)=0.
+            enddo
+         enddo
+
+         dtcum=0.
+      endif
+
+      do k=1,klev
+         do i=1,klon
+            frac_impa(i,k)=frac_impa(i,k)*pfrac_impa(i,k)
+            frac_nucl(i,k)=frac_nucl(i,k)*pfrac_nucl(i,k)
+            mfu(i,k)=mfu(i,k)+pmfu(i,k)*pdtphys
+            mfd(i,k)=mfd(i,k)+pmfd(i,k)*pdtphys
+            en_u(i,k)=en_u(i,k)+pen_u(i,k)*pdtphys
+            de_u(i,k)=de_u(i,k)+pde_u(i,k)*pdtphys
+            en_d(i,k)=en_d(i,k)+pen_d(i,k)*pdtphys
+            de_d(i,k)=de_d(i,k)+pde_d(i,k)*pdtphys
+            coefh(i,k)=coefh(i,k)+pcoefh(i,k)*pdtphys
+		t(i,k)=t(i,k)+pt(i,k)*pdtphys
+         enddo
+      enddo
+         do i=1,klon
+            pyv1(i)=pyv1(i)+yv1(i)*pdtphys
+            pyu1(i)=pyu1(i)+yu1(i)*pdtphys
+         end do
+         do k=1,nbsrf
+             do i=1,klon
+               pftsol(i,k)=pftsol(i,k)+ftsol(i,k)*pdtphys
+               ppsrf(i,k)=ppsrf(i,k)+pctsrf(i,k)*pdtphys
+            enddo
+         enddo
+
+      dtcum=dtcum+pdtphys
+c
+      IF(mod(iadvtr,istphy).eq.0) THEN
+c
+c   normalisation par le temps cumule
+         do k=1,klev
+            do i=1,klon
+c              frac_impa=frac_impa : c'est la fraction cumulee qu'on stoke
+c              frac_nucl=frac_nucl : c'est la fraction cumulee qu'on stoke
+               mfu(i,k)=mfu(i,k)/dtcum
+               mfd(i,k)=mfd(i,k)/dtcum
+               en_u(i,k)=en_u(i,k)/dtcum
+               de_u(i,k)=de_u(i,k)/dtcum
+               en_d(i,k)=en_d(i,k)/dtcum
+               de_d(i,k)=de_d(i,k)/dtcum
+               coefh(i,k)=coefh(i,k)/dtcum
+		t(i,k)=t(i,k)/dtcum
+            enddo
+         enddo
+         do i=1,klon
+            rain(i)=rain(i)/dtcum
+            pyv1(i)=pyv1(i)/dtcum
+            pyu1(i)=pyu1(i)/dtcum
+         end do
+c modif abderr 23 11 00         do k=1,nbsrf
+             do i=1,klon
+	      do k=1,nbsrf
+               pftsol(i,k)=pftsol(i,k)/dtcum
+	       ppsrf(i,k)=ppsrf(i,k)/dtcum
+	      enddo
+               pftsol1(i) = pftsol(i,1)
+               pftsol2(i) = pftsol(i,2)
+               pftsol3(i) = pftsol(i,3)
+               pftsol4(i) = pftsol(i,4)
+
+c               ppsrf(i,k)=ppsrf(i,k)/dtcum
+               ppsrf1(i) = ppsrf(i,1)
+               ppsrf2(i) = ppsrf(i,2)
+               ppsrf3(i) = ppsrf(i,3)
+               ppsrf4(i) = ppsrf(i,4)
+
+            enddo
+c         enddo
+c
+c   ecriture des champs
+c
+         irec=irec+1
+
+ccccc
+      print*,'AVANT ECRITURE'
+         CALL gr_fi_ecrit(klev,klon,iim,jjm+1, t, zx_tmp_3d)
+         CALL histwrite(physid,"t",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+      print*,'APRES ECRITURE'
+
+         CALL gr_fi_ecrit(klev,klon,iim,jjm+1, mfu, zx_tmp_3d)
+      CALL histwrite(physid,"mfu",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1, mfd, zx_tmp_3d)
+      CALL histwrite(physid,"mfd",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1, en_u, zx_tmp_3d)
+      CALL histwrite(physid,"en_u",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1, de_u, zx_tmp_3d)
+      CALL histwrite(physid,"de_u",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1, en_d, zx_tmp_3d)
+      CALL histwrite(physid,"en_d",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1, de_d, zx_tmp_3d)
+      CALL histwrite(physid,"de_d",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1, coefh, zx_tmp_3d)
+      CALL histwrite(physid,"coefh",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex)
+cccc
+       CALL gr_fi_ecrit(klev,klon,iim,jjm+1,frac_impa,zx_tmp_3d)
+        CALL histwrite(physid,"frac_impa",itap,zx_tmp_3d,
+     .  iim*(jjm+1)*klev,ndex)
+
+        CALL gr_fi_ecrit(klev,klon,iim,jjm+1,frac_nucl,zx_tmp_3d)
+        CALL histwrite(physid,"frac_nucl",itap,zx_tmp_3d,
+     .  iim*(jjm+1)*klev,ndex)
+
+        CALL gr_fi_ecrit(1, klon,iim,jjm+1, pyu1,zx_tmp_2d)
+      CALL histwrite(physid,"pyu1",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+
+        CALL gr_fi_ecrit(1, klon,iim,jjm+1, pyv1,zx_tmp_2d)
+      CALL histwrite(physid,"pyv1",itap,zx_tmp_2d,iim*(jjm+1),ndex)
+
+        CALL gr_fi_ecrit(1,klon,iim,jjm+1, pftsol1, zx_tmp_2d)
+      CALL histwrite(physid,"ftsol1",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1, pftsol2, zx_tmp_2d)
+      CALL histwrite(physid,"ftsol2",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+          CALL gr_fi_ecrit(1,klon,iim,jjm+1, pftsol3, zx_tmp_2d)
+      CALL histwrite(physid,"ftsol3",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+
+c
+         CALL gr_fi_ecrit(1,klon,iim,jjm+1, pftsol4, zx_tmp_2d)
+      CALL histwrite(physid,"ftsol4",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+
+        CALL gr_fi_ecrit(1,klon,iim,jjm+1, rain, zx_tmp_2d)
+      CALL histwrite(physid,"rain",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+
+        CALL gr_fi_ecrit(1,klon,iim,jjm+1, ppsrf1, zx_tmp_2d)
+      CALL histwrite(physid,"psrf1",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+        CALL gr_fi_ecrit(1,klon,iim,jjm+1, ppsrf2, zx_tmp_2d)
+      CALL histwrite(physid,"psrf2",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+        CALL gr_fi_ecrit(1,klon,iim,jjm+1, ppsrf3, zx_tmp_2d)
+      CALL histwrite(physid,"psrf3",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+        CALL gr_fi_ecrit(1,klon,iim,jjm+1, ppsrf4, zx_tmp_2d)
+      CALL histwrite(physid,"psrf4",itap,zx_tmp_2d,
+     .                                   iim*(jjm+1),ndex)
+
+c
+cAA Test sur la valeur des coefficients de lessivage
+c
+         zmin=1e33
+         zmax=-1e33
+         do k=1,klev
+            do i=1,klon
+                  zmax=max(zmax,frac_nucl(i,k))
+                  zmin=min(zmin,frac_nucl(i,k))
+            enddo
+         enddo
+         Print*,'------ coefs de lessivage (min et max) --------'
+         Print*,'facteur de nucleation ',zmin,zmax
+         zmin=1e33
+         zmax=-1e33
+         do k=1,klev
+            do i=1,klon
+                  zmax=max(zmax,frac_impa(i,k))
+                  zmin=min(zmin,frac_impa(i,k))
+            enddo
+         enddo
+         Print*,'facteur d impaction ',zmin,zmax
+
+      ENDIF
+
+
+      RETURN
+      END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phytrac.F
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/phytrac.F	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/phytrac.F	(revision 253)
@@ -1,4 +1,7 @@
+c
+c $Header$
+c
       SUBROUTINE phytrac (rnpb,
-     I                   debutphy,
+     I                   debutphy,lafin,
      I                   nqmax,
      I                   nlon,nlev,pdtphys,
@@ -27,4 +30,5 @@
 #include "dimphy.h"
 #include "indicesol.h"
+#include "temps.h"
 #include "control.h"
 c======================================================================
@@ -47,8 +51,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
@@ -89,5 +94,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
@@ -130,4 +138,5 @@
       INTEGER nid_tra
       SAVE nid_tra
+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)
@@ -140,4 +149,6 @@
       INTEGER ecrit_tra
       SAVE ecrit_tra   
+      logical ok_sync
+      parameter (ok_sync = .true.)
 C
 C nature du traceur
@@ -156,6 +167,6 @@
 c
 c--modif convection tiedtke
-      INTEGER i, k, it
-
+      INTEGER i, k, it,itap
+	save itap
       REAL delp(klon,klev)
 c--end modif
@@ -201,8 +212,11 @@
          modname='phytrac'
 
-         print*,'DANS PHYTRAC debutphy=',debutphy
-
-         ecrit_tra = NINT(86400./pdtphys *ecritphy)   
+c        print*,'DANS PHYTRAC debutphy=',debutphy
+
          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
@@ -216,7 +230,8 @@
          PRINT*, 'La frequence de sortie traceurs est  ', ecrit_tra
          itra=0
+	 itap=0
 C         
-         CALL ymds2ju(anneeref, 1, 1, 0.0, zjulian)
-         zjulian = zjulian + dayref
+         CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
+         zjulian = zjulian + day_ini
 c
          CALL gr_fi_ecrit(1,klon,iim,jjm+1,xlon,zx_lon)
@@ -225,16 +240,13 @@
             zx_lon(i,jjm+1) = xlon(i+1)
          ENDDO
-         DO ll=1,klev
-            znivsig(ll)=float(ll)
-         ENDDO
+c         DO ll=1,klev
+c            znivsig(ll)=float(ll)
+c         ENDDO
          CALL gr_fi_ecrit(1,klon,iim,jjm+1,xlat,zx_lat)
          CALL histbeg("histrac", iim,zx_lon, jjm+1,zx_lat,
      .                 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)
@@ -247,4 +259,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
@@ -275,5 +349,5 @@
          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
+
 c======================================================================
 c   Initialisation de certaines variables pour le Rn et le Pb 
@@ -282,5 +356,5 @@
 c Initialisation du traceur dans le sol (couche limite radonique)
 c
-         print*,'valeur de debut dans phytrac :',debutphy
+c        print*,'valeur de debut dans phytrac :',debutphy
          do it=1,nqmax
             do i=1,klon
@@ -288,4 +362,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
@@ -321,7 +402,71 @@
          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
@@ -336,17 +481,26 @@
       ENDDO
       ENDDO
-      WRITE(itn,'(i1)') it
-      CALL minmaxqfi(tr_seri(1,1,it),0.,1.e33,'convection it='//itn)
-      ENDDO
-      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======================================================================
-
-      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
 
@@ -359,5 +513,5 @@
 C maf modif pour tenir compte du cas rnpb + traceur
       DO it=1, nqmax
-      print *,'it',it,clsol(it)
+c     print *,'it',it,clsol(it)
       if (clsol(it)) then  ! couche limite avec quantite dans le sol calculee
           CALL cltracrn(it, pdtphys, yu1, yv1,
@@ -407,5 +561,9 @@
       endif ! couche limite
 
-      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======================================================================
@@ -436,7 +594,8 @@
 c======================================================================
 
+      print*,'LESSIVAGE =',lessivage
       IF (lessivage) THEN
 
-      print*,'avant lessivage'
+c     print*,'avant lessivage'
 
        DO it = 1, nqmax
@@ -468,14 +627,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 
@@ -497,5 +662,5 @@
       ENDDO
 c
-      print*,'apres lessivage'
+c     print*,'apres lessivage'
       ENDIF
 Cc
@@ -519,9 +684,9 @@
        CALL histwrite(nid_tra,"tr"//str2,itra,zx_tmp_3d,
      .                                   iim*(jjm+1)*klev,ndex)
-       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,ndex)
-      ENDIF
+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"
@@ -530,4 +695,55 @@
       ENDDO
 
+	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
       END
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.160.98.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.160.98.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.160.98.h	(revision 253)
@@ -0,0 +1,2 @@
+      INTEGER kdlon, kflev
+      PARAMETER (kdlon=78,kflev=klev) ! 78*199
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.192.143.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.192.143.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.192.143.h	(revision 253)
@@ -0,0 +1,2 @@
+       INTEGER kdlon, kflev
+      PARAMETER (kdlon=10,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.32.24.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.32.24.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.32.24.h	(revision 253)
@@ -0,0 +1,2 @@
+      INTEGER kdlon, kflev
+      PARAMETER (kdlon=klon,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.48.32.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.48.32.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.48.32.h	(revision 253)
@@ -0,0 +1,2 @@
+      INTEGER kdlon, kflev
+      PARAMETER (kdlon=149,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.72.46.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.72.46.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.72.46.h	(revision 253)
@@ -0,0 +1,2 @@
+      INTEGER kdlon, kflev
+      PARAMETER (kdlon=1621,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.96.72.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.96.72.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.96.72.h	(revision 253)
@@ -0,0 +1,2 @@
+      INTEGER kdlon, kflev
+      PARAMETER (kdlon=487,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.defaut.h
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.defaut.h	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.defaut.h	(revision 253)
@@ -0,0 +1,2 @@
+      INTEGER kdlon, kflev
+      PARAMETER (kdlon=klon,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.h
===================================================================
--- LMDZ.3.3/branches/LF/libf/phylmd/raddim.h	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/raddim.h	(revision 253)
@@ -1,2 +1,16 @@
       INTEGER kdlon, kflev
-      PARAMETER (kdlon=149,kflev=klev)
+c
+ccc      PARAMETER (kdlon=klon,kflev=klev)
+c
+c resolution 72 45:
+      PARAMETER (kdlon=317,kflev=klev)
+c resolution 64 32:
+ccc      PARAMETER (kdlon=331,kflev=klev)
+c resolution 96 49:
+ccc      PARAMETER (kdlon=461,kflev=klev)
+c resolution 144 73:
+ccc      PARAMETER (kdlon=610,kflev=klev)
+c resolution 96 72:
+c      PARAMETER (kdlon=487,kflev=klev)
+c resolution 128 64:
+ccc       PARAMETER (kdlon=4033,kflev=klev)
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/read_pstoke.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/read_pstoke.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/read_pstoke.F	(revision 253)
@@ -0,0 +1,431 @@
+c
+c $Header$
+c
+	subroutine read_pstoke(irec,
+     .   zrec,zklono,zklevo,airefi,phisfi,
+     .   t,mfu,mfd,en_u,de_u,en_d,de_d,coefh,
+     .   frac_impa,frac_nucl,pyu1,pyv1,ftsol,psrf)
+
+
+       IMPLICIT NONE
+
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "temps.h"
+#include "ener.h"
+#include "logic.h"
+#include "description.h"
+#include "serre.h"
+#include "indicesol.h"
+#include "control.h"
+#include "dimphy.h"
+	
+	  integer*4 klono,klevo,imo,jmo
+	  parameter (imo=iim/2,jmo=(jjm+1)/2)
+	  parameter(klono=(jmo-1)*imo+2,klevo=llm)
+	  REAL*4 phisfi(klono)
+          REAL*4 phisfi2(imo,jmo+1),airefi2(imo,jmo+1)
+
+          REAL*4 mfu(klono,klevo), mfd(klono,klevo)
+          REAL*4 en_u(klono,klevo), de_u(klono,klevo)
+          REAL*4 en_d(klono,klevo), de_d(klono,klevo)
+          REAL*4 coefh(klono,klevo)
+
+          REAL*4 mfu2(imo,jmo+1,klevo), mfd2(imo,jmo+1,klevo)
+          REAL*4 en_u2(imo,jmo+1,klevo), de_u2(imo,jmo+1,klevo)
+          REAL*4 en_d2(imo,jmo+1,klevo), de_d2(imo,jmo+1,klevo)
+          REAL*4 coefh2(imo,jmo+1,klevo)
+
+          REAL*4 pl(klevo)
+          integer irec
+          integer*4 xid,yid,zid,tid
+          real zrec,zklono,zklevo,zim,zjm
+          integer*4 ncrec,ncklono,ncklevo,ncim,ncjm
+
+          real*4 airefi(klono)
+          character namedim
+
+c  !! attention !!
+c attention il y a aussi le pb de def klono
+c dim de phis??
+	  
+	 
+          REAL*4 frac_impa(klono,klevo), frac_nucl(klono,klevo)
+          REAL*4 frac_impa2(imo,jmo+1,klevo), 
+     .     frac_nucl2(imo,jmo+1,klevo)
+          REAL*4 pyu1(klono), pyv1(klono)
+          REAL*4 pyu12(imo,jmo+1), pyv12(imo,jmo+1)
+          REAL*4 ftsol(klono,nbsrf)
+          REAL*4 psrf(klono,nbsrf) 
+	  REAL*4 ftsol1(klono),ftsol2(klono),ftsol3(klono),ftsol4(klono)
+          REAL*4 psrf1(klono),psrf2(klono),psrf3(klono),psrf4(klono)
+          REAL*4 ftsol12(imo,jmo+1),ftsol22(imo,jmo+1),
+     .     ftsol32(imo,jmo+1),
+     .     ftsol42(imo,jmo+1)
+          REAL*4 psrf12(imo,jmo+1),psrf22(imo,jmo+1),psrf32(imo,jmo+1),
+     .     psrf42(imo,jmo+1)
+		REAL*4 t(klono,klevo)
+		REAL*4 t2(imo,jmo+1)	
+	  integer ncidp
+          save ncidp
+		integer varidt
+          integer varidmfu, varidmfd, varidps, varidenu, variddeu	
+          integer varidend,varidded,varidch,varidfi,varidfn
+          integer varidyu1,varidyv1,varidpl,varidai,varididvt
+          integer varidfts1,varidfts2,varidfts3,varidfts4
+          integer varidpsr1,varidpsr2,varidpsr3,varidpsr4
+          save varidmfu, varidmfd, varidps, varidenu, variddeu
+          save varidend,varidded,varidch,varidfi,varidfn
+          save varidyu1,varidyv1,varidpl,varidai,varididvt
+          save varidfts1,varidfts2,varidfts3,varidfts4
+          save varidpsr1,varidpsr2,varidpsr3,varidpsr4
+		save varidt
+
+          integer l, i
+          integer start(4),count(4),status
+          real rcode
+          logical first
+          save first
+          data first/.true./
+
+
+
+c ---------------------------------------------
+c   Initialisation de la lecture des fichiers
+c ---------------------------------------------
+
+      if (irec .eq. 0) then
+
+            ncidp=NCOPN('phystoke.nc',NCNOWRIT,rcode)
+
+            varidps=NCVID(ncidp,'phis',rcode)
+            print*,'ncidp,varidps',ncidp,varidps
+
+            varidpl=NCVID(ncidp,'sig_s',rcode)
+            print*,'ncidp,varidpl',ncidp,varidpl
+
+            varidai=NCVID(ncidp,'aire',rcode)
+            print*,'ncidp,varidai',ncidp,varidai
+
+	        varidt=NCVID(ncidp,'t',rcode)
+                print*,'ncidp,varidt',ncidp,varidt
+            varidmfu=NCVID(ncidp,'mfu',rcode)
+            print*,'ncidp,varidmfu',ncidp,varidmfu
+
+            varidmfd=NCVID(ncidp,'mfd',rcode)
+            print*,'ncidp,varidmfd',ncidp,varidmfd
+
+            varidenu=NCVID(ncidp,'en_u',rcode)
+            print*,'ncidp,varidenu',ncidp,varidenu
+
+            variddeu=NCVID(ncidp,'de_u',rcode)
+            print*,'ncidp,variddeu',ncidp,variddeu
+
+            varidend=NCVID(ncidp,'en_d',rcode)
+            print*,'ncidp,varidend',ncidp,varidend
+	
+            varidded=NCVID(ncidp,'de_d',rcode)
+            print*,'ncidp,varidded',ncidp,varidded
+	
+            varidch=NCVID(ncidp,'coefh',rcode)
+            print*,'ncidp,varidch',ncidp,varidch
+	
+	    varidfi=NCVID(ncidp,'frac_impa',rcode)
+            print*,'ncidp,varidfi',ncidp,varidfi
+	
+	    varidfn=NCVID(ncidp,'frac_nucl',rcode)
+            print*,'ncidp,varidfn',ncidp,varidfn
+	
+            varidyu1=NCVID(ncidp,'pyu1',rcode)
+            print*,'ncidp,varidyu1',ncidp,varidyu1
+	
+            varidyv1=NCVID(ncidp,'pyv1',rcode)
+            print*,'ncidp,varidyv1',ncidp,varidyv1
+	
+            varidfts1=NCVID(ncidp,'ftsol1',rcode)
+            print*,'ncidp,varidfts1',ncidp,varidfts1
+	
+            varidfts2=NCVID(ncidp,'ftsol2',rcode)
+            print*,'ncidp,varidfts2',ncidp,varidfts2
+         
+            varidfts3=NCVID(ncidp,'ftsol3',rcode)
+            print*,'ncidp,varidfts3',ncidp,varidfts3
+  
+            varidfts4=NCVID(ncidp,'ftsol4',rcode)
+            print*,'ncidp,varidfts4',ncidp,varidfts4
+	
+            varidpsr1=NCVID(ncidp,'psrf1',rcode)
+            print*,'ncidp,varidpsr1',ncidp,varidpsr1
+	
+            varidpsr2=NCVID(ncidp,'psrf2',rcode)
+            print*,'ncidp,varidpsr2',ncidp,varidpsr2
+	
+	    varidpsr3=NCVID(ncidp,'psrf3',rcode)
+            print*,'ncidp,varidpsr3',ncidp,varidpsr3
+
+            varidpsr4=NCVID(ncidp,'psrf4',rcode)
+            print*,'ncidp,varidpsr4',ncidp,varidpsr4
+	
+c ID pour les dimensions
+
+            status = nf_inq_dimid(ncidp,'y',yid)
+            status = nf_inq_dimid(ncidp,'x',xid)
+            status = nf_inq_dimid(ncidp,'sig_s',zid)
+            status = nf_inq_dimid(ncidp,'time_counter',tid)
+
+c lecture des dimensions
+
+            status = nf_inq_dim(ncidp,yid,namedim,ncjm)
+            status = nf_inq_dim(ncidp,xid,namedim,ncim)
+            status = nf_inq_dim(ncidp,zid,namedim,ncklevo)
+            status = nf_inq_dim(ncidp,tid,namedim,ncrec)
+	
+            zrec=ncrec
+            zklevo=ncklevo
+            zim=ncim
+            zjm=ncjm
+	
+	    zklono=zim*(zjm-2)+2
+	
+	    write(*,*) 'read_pstoke : zrec = ', zrec
+            write(*,*) 'read_pstoke : zklevo = ', zklevo
+            write(*,*) 'read_pstoke : zim = ', zim 
+            write(*,*) 'read_pstoke : zjm = ', zjm
+            write(*,*) 'read_pstoke : zklono = ', zklono
+
+c niveaux de pression
+
+            status=NF_GET_VARA_REAL(ncidp,varidpl,1,zklevo,pl)
+
+c lecture de aire et phis
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+
+c phis
+      status=NF_GET_VARA_REAL(ncidp,varidps,start,count,phisfi2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,phisfi2)
+c      call dump2d(iip1-1,jjp1,phisfi2,'PHISNC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,phisfi2,phisfi)
+
+c aire
+      status=NF_GET_VARA_REAL(ncidp,varidai,start,count,airefi2)
+c      call correctbid(iim,jjp1*1,airefi2)
+c       call dump2d(iip1-1,jjp1,airefi2,'AIRENC')
+       call gr_ecrit_fi(1,klono,imo,jmo+1,airefi2,airefi)
+      else
+
+      print*,'ok1'
+
+c ---------------------
+c   lecture des champs
+c ---------------------
+	
+	print*,'WARNING!!! Il n y a pas de test de coherence'
+        print*,'sur le nombre de niveaux verticaux dans le fichier nc'
+
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=irec
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=zklevo
+      count(4)=1
+
+c frac_impa 
+
+      status=NF_GET_VARA_REAL(ncidp,varidfi,start,count,frac_impa2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,frac_impa2)
+c      call dump2d(iip1-1,jjp1,frac_impa2,'FINC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,frac_impa2,frac_impa)
+
+c frac_nucl 
+
+      status=NF_GET_VARA_REAL(ncidp,varidfn,start,count,frac_nucl2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,frac_nucl2)
+c      call dump2d(iip1-1,jjp1,frac_nucl2,'FINC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,frac_nucl2,frac_nucl)
+
+c abder t
+      status=NF_GET_VARA_REAL(ncidp,varidt,start,count,t2)
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,t2,t)
+
+c mfu
+      status=NF_GET_VARA_REAL(ncidp,varidmfu,start,count,mfu2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,mfu2)
+c      call dump2d(iip1-1,jjp1,mfu2,'MFUNC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,mfu2,mfu)
+
+c mfd
+      status=NF_GET_VARA_REAL(ncidp,varidmfd,start,count,mfd2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,mfd2)
+c      call dump2d(iip1-1,jjp1,mfd2,'MFDNC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,mfd2,mfd)
+
+c en_u 
+      status=NF_GET_VARA_REAL(ncidp,varidenu,start,count,en_u2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,en_u2)
+c      call dump2d(iip1-1,jjp1,en_u2,'ENUNC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,en_u2,en_u)
+
+c de_u 
+      status=NF_GET_VARA_REAL(ncidp,variddeu,start,count,de_u2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,de_u2)
+c      call dump2d(iip1-1,jjp1,de_u2,'DEUNC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,de_u2,de_u)
+
+c en_d 
+      status=NF_GET_VARA_REAL(ncidp,varidend,start,count,en_d2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,en_d2)
+c      call dump2d(iip1-1,jjp1,en_d2,'ENDNC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,en_d2,en_d)
+
+c de_d 
+      status=NF_GET_VARA_REAL(ncidp,varidded,start,count,de_d2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,de_d2)
+c      call dump2d(iip1-1,jjp1,de_d2,'DEDNC COUCHE 1')
+      call gr_ecrit_fi(klevo,klono,imo,jmo+1,de_d2,de_d)
+
+c coefh 
+      status=NF_GET_VARA_REAL(ncidp,varidch,start,count,coefh2)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*klevo,coefh2)
+c      call dump2d(iip1-1,jjp1,coefh2,'CHNC COUCHE 1')
+       call gr_ecrit_fi(klevo,klono,imo,jmo+1,coefh2,coefh)
+
+      start(3)=irec
+      start(4)=0
+      count(3)=1
+      count(4)=0
+
+c pyu1
+      status=NF_GET_VARA_REAL(ncidp,varidyu1,start,count,pyu12)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,pyu12)
+c      call dump2d(iip1-1,jjp1,pyu12,'PYU1NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,pyu12,pyu1)
+
+c pyv1
+      status=NF_GET_VARA_REAL(ncidp,varidyv1,start,count,pyv12)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,pyv12)
+c      call dump2d(iip1-1,jjp1,pyv12,'PYV1NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,pyv12,pyv1)
+
+c ftsol1
+      status=NF_GET_VARA_REAL(ncidp,varidfts1,start,count,ftsol12)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,ftsol12)
+c      call dump2d(iip1-1,jjp1,ftsol12,'FTS1NC')
+       call gr_ecrit_fi(1,klono,imo,jmo+1,ftsol12,ftsol1)
+
+c ftsol2
+      status=NF_GET_VARA_REAL(ncidp,varidfts2,start,count,ftsol22)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,ftsol22)
+c      call dump2d(iip1-1,jjp1,ftsol22,'FTS2NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,ftsol22,ftsol2)
+
+c ftsol3
+      status=NF_GET_VARA_REAL(ncidp,varidfts3,start,count,ftsol32)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,ftsol32)
+c      call dump2d(iip1-1,jjp1,ftsol32,'FTS3NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,ftsol32,ftsol3)
+
+c ftsol4
+      status=NF_GET_VARA_REAL(ncidp,varidfts4,start,count,ftsol42)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,ftsol42)
+c      call dump2d(iip1-1,jjp1,ftsol42,'FTS4NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,ftsol42,ftsol4)
+
+c psrf1 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr1,start,count,psrf12)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,psrf12)
+c      call dump2d(iip1-1,jjp1,psrf12,'PSRF1NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,psrf12,psrf1)
+
+c psrf2 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr2,start,count,psrf22)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,psrf22)
+c      call dump2d(iip1-1,jjp1,psrf22,'PSRF2NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,psrf22,psrf2)
+
+c psrf3 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr3,start,count,psrf32)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,psrf32)
+c      call dump2d(iip1-1,jjp1,psrf32,'PSRF3NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,psrf32,psrf3)
+
+c psrf4 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr4,start,count,psrf42)
+c      print*,'WARNING!!! Correction bidon pour palier a un '
+c      print*,'probleme dans la creation des fichiers nc'
+c      call correctbid(iim,jjp1*1,psrf42)
+c      call dump2d(iip1-1,jjp1,psrf42,'PSRF4NC')
+      call gr_ecrit_fi(1,klono,imo,jmo+1,psrf42,psrf4)
+	
+          do i = 1,klono
+	
+	psrf(i,1) = psrf1(i)
+        psrf(i,2) = psrf2(i)
+        psrf(i,3) = psrf3(i)
+        psrf(i,4) = psrf4(i)
+  
+        ftsol(i,1) = ftsol1(i)
+        ftsol(i,2) = ftsol2(i)
+        ftsol(i,3) = ftsol3(i)
+        ftsol(i,4) = ftsol4(i)
+	
+          enddo
+	
+	endif
+	
+	return
+	
+	end
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/read_pstoke0.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/read_pstoke0.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/read_pstoke0.F	(revision 253)
@@ -0,0 +1,358 @@
+c
+c $Header$
+c
+	subroutine read_pstoke0(irec,
+     .   zrec,zkon,zkev,airefi,phisfi,
+     .   t,mfu,mfd,en_u,de_u,en_d,de_d,coefh,
+     .   frac_impa,frac_nucl,pyu1,pyv1,ftsol,psrf)
+
+
+       IMPLICIT NONE
+
+#include "netcdf.inc"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "temps.h"
+#include "ener.h"
+#include "logic.h"
+#include "description.h"
+#include "serre.h"
+#include "indicesol.h"
+#include "control.h"
+#include "dimphy.h"
+	  
+	  integer*4 kon,kev,zkon,zkev
+	  parameter(kon=iim*(jjm-1)+2,kev=llm)
+	  REAL*4 phisfi(kon)
+          REAL*4 phisfi2(iim,jjm+1),airefi2(iim,jjm+1)
+
+          REAL*4 mfu(kon,kev), mfd(kon,kev)
+          REAL*4 en_u(kon,kev), de_u(kon,kev)
+          REAL*4 en_d(kon,kev), de_d(kon,kev)
+          REAL*4 coefh(kon,kev)
+		REAL*4 t(kon,kev)
+
+          REAL*4 mfu2(iim,jjm+1,kev), mfd2(iim,jjm+1,kev)
+          REAL*4 en_u2(iim,jjm+1,kev), de_u2(iim,jjm+1,kev)
+          REAL*4 en_d2(iim,jjm+1,kev), de_d2(iim,jjm+1,kev)
+          REAL*4 coefh2(iim,jjm+1,kev)
+		REAL*4 t2(iim,jjm+1,kev)
+
+          REAL*4 pl(kev)
+          integer irec
+          integer*4 xid,yid,zid,tid
+          integer*4 zrec,zim,zjm
+          integer*4 ncrec,nckon,nckev,ncim,ncjm
+
+          real*4 airefi(kon)
+          character namedim
+
+c  !! attention !!
+c attention il y a aussi le pb de def kon
+c dim de phis??
+
+          REAL*4 frac_impa(kon,kev), frac_nucl(kon,kev)
+          REAL*4 frac_impa2(iim,jjm+1,kev), 
+     .     frac_nucl2(iim,jjm+1,kev)
+          REAL*4 pyu1(kon), pyv1(kon)
+          REAL*4 pyu12(iim,jjm+1), pyv12(iim,jjm+1)
+          REAL*4 ftsol(kon,nbsrf)
+          REAL*4 psrf(kon,nbsrf) 
+	  REAL*4 ftsol1(kon),ftsol2(kon),ftsol3(kon),ftsol4(kon)
+          REAL*4 psrf1(kon),psrf2(kon),psrf3(kon),psrf4(kon)
+          REAL*4 ftsol12(iim,jjm+1),ftsol22(iim,jjm+1),
+     .     ftsol32(iim,jjm+1),
+     .     ftsol42(iim,jjm+1)
+          REAL*4 psrf12(iim,jjm+1),psrf22(iim,jjm+1),psrf32(iim,jjm+1),
+     .     psrf42(iim,jjm+1)
+	
+	  integer ncidp
+          save ncidp
+          integer varidmfu, varidmfd, varidps, varidenu, variddeu	
+		integer varidt
+          integer varidend,varidded,varidch,varidfi,varidfn
+          integer varidyu1,varidyv1,varidpl,varidai,varididvt
+          integer varidfts1,varidfts2,varidfts3,varidfts4
+          integer varidpsr1,varidpsr2,varidpsr3,varidpsr4
+          save varidmfu, varidmfd, varidps, varidenu, variddeu
+		save varidt
+          save varidend,varidded,varidch,varidfi,varidfn
+          save varidyu1,varidyv1,varidpl,varidai,varididvt
+          save varidfts1,varidfts2,varidfts3,varidfts4
+          save varidpsr1,varidpsr2,varidpsr3,varidpsr4
+
+          integer l, i
+          integer start(4),count(4),status
+          real rcode
+          logical first
+          save first
+          data first/.true./
+
+
+
+c ---------------------------------------------
+c   Initialisation de la lecture des fichiers
+c ---------------------------------------------
+
+      if (irec .eq. 0) then
+
+            ncidp=NCOPN('phystoke.nc',NCNOWRIT,rcode)
+
+            varidps=NCVID(ncidp,'phis',rcode)
+            print*,'ncidp,varidps',ncidp,varidps
+
+            varidpl=NCVID(ncidp,'sig_s',rcode)
+            print*,'ncidp,varidpl',ncidp,varidpl
+
+            varidai=NCVID(ncidp,'aire',rcode)
+            print*,'ncidp,varidai',ncidp,varidai
+
+            varidmfu=NCVID(ncidp,'mfu',rcode)
+            print*,'ncidp,varidmfu',ncidp,varidmfu
+
+		varidt=NCVID(ncidp,'t',rcode)
+                print*,'ncidp,varidt',ncidp,varidt
+
+            varidmfd=NCVID(ncidp,'mfd',rcode)
+            print*,'ncidp,varidmfd',ncidp,varidmfd
+
+            varidenu=NCVID(ncidp,'en_u',rcode)
+            print*,'ncidp,varidenu',ncidp,varidenu
+
+            variddeu=NCVID(ncidp,'de_u',rcode)
+            print*,'ncidp,variddeu',ncidp,variddeu
+
+            varidend=NCVID(ncidp,'en_d',rcode)
+            print*,'ncidp,varidend',ncidp,varidend
+	
+            varidded=NCVID(ncidp,'de_d',rcode)
+            print*,'ncidp,varidded',ncidp,varidded
+	
+            varidch=NCVID(ncidp,'coefh',rcode)
+            print*,'ncidp,varidch',ncidp,varidch
+	
+	    varidfi=NCVID(ncidp,'frac_impa',rcode)
+            print*,'ncidp,varidfi',ncidp,varidfi
+	
+	    varidfn=NCVID(ncidp,'frac_nucl',rcode)
+            print*,'ncidp,varidfn',ncidp,varidfn
+	
+            varidyu1=NCVID(ncidp,'pyu1',rcode)
+            print*,'ncidp,varidyu1',ncidp,varidyu1
+	
+            varidyv1=NCVID(ncidp,'pyv1',rcode)
+            print*,'ncidp,varidyv1',ncidp,varidyv1
+	
+            varidfts1=NCVID(ncidp,'ftsol1',rcode)
+            print*,'ncidp,varidfts1',ncidp,varidfts1
+	
+            varidfts2=NCVID(ncidp,'ftsol2',rcode)
+            print*,'ncidp,varidfts2',ncidp,varidfts2
+         
+            varidfts3=NCVID(ncidp,'ftsol3',rcode)
+            print*,'ncidp,varidfts3',ncidp,varidfts3
+  
+            varidfts4=NCVID(ncidp,'ftsol4',rcode)
+            print*,'ncidp,varidfts4',ncidp,varidfts4
+	
+            varidpsr1=NCVID(ncidp,'psrf1',rcode)
+            print*,'ncidp,varidpsr1',ncidp,varidpsr1
+	
+            varidpsr2=NCVID(ncidp,'psrf2',rcode)
+            print*,'ncidp,varidpsr2',ncidp,varidpsr2
+	
+	    varidpsr3=NCVID(ncidp,'psrf3',rcode)
+            print*,'ncidp,varidpsr3',ncidp,varidpsr3
+
+            varidpsr4=NCVID(ncidp,'psrf4',rcode)
+            print*,'ncidp,varidpsr4',ncidp,varidpsr4
+	
+c ID pour les dimensions
+
+            status = nf_inq_dimid(ncidp,'y',yid)
+            status = nf_inq_dimid(ncidp,'x',xid)
+            status = nf_inq_dimid(ncidp,'sig_s',zid)
+            status = nf_inq_dimid(ncidp,'time_counter',tid)
+
+c lecture des dimensions
+
+            status = nf_inq_dim(ncidp,yid,namedim,ncjm)
+            status = nf_inq_dim(ncidp,xid,namedim,ncim)
+            status = nf_inq_dim(ncidp,zid,namedim,nckev)
+            status = nf_inq_dim(ncidp,tid,namedim,ncrec)
+	
+            zrec=ncrec
+            zkev=nckev
+            zim=ncim
+            zjm=ncjm
+	
+	    zkon=zim*(zjm-2)+2
+	
+	    write(*,*) 'read_pstoke : zrec = ', zrec
+            write(*,*) 'read_pstoke : kev = ', zkev
+            write(*,*) 'read_pstoke : zim = ', zim 
+            write(*,*) 'read_pstoke : zjm = ', zjm
+            write(*,*) 'read_pstoke : kon = ', zkon
+
+c niveaux de pression
+
+            status=NF_GET_VARA_REAL(ncidp,varidpl,1,kev,pl)
+
+c lecture de aire et phis
+	
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=0
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=1
+      count(4)=0
+
+c 
+c phis
+      status=NF_GET_VARA_REAL(ncidp,varidps,start,count,phisfi2)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,phisfi2,phisfi)
+
+c aire
+      status=NF_GET_VARA_REAL(ncidp,varidai,start,count,airefi2)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,airefi2,airefi)
+      else
+
+      print*,'ok1'
+
+c ---------------------
+c   lecture des champs
+c ---------------------
+	
+	print*,'WARNING!!! Il n y a pas de test de coherence'
+        print*,'sur le nombre de niveaux verticaux dans le fichier nc'
+
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=irec
+
+      count(1)=zim
+      count(2)=zjm
+      count(3)=kev
+      count(4)=1
+
+c frac_impa 
+
+      status=NF_GET_VARA_REAL(ncidp,varidfi,start,count,frac_impa2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,frac_impa2,frac_impa)
+
+c frac_nucl 
+
+      status=NF_GET_VARA_REAL(ncidp,varidfn,start,count,frac_nucl2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,frac_nucl2,frac_nucl)
+
+c abder t
+      status=NF_GET_VARA_REAL(ncidp,varidt,start,count,t2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,t2,t)
+
+c mfu
+      status=NF_GET_VARA_REAL(ncidp,varidmfu,start,count,mfu2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,mfu2,mfu)
+
+c mfd
+      status=NF_GET_VARA_REAL(ncidp,varidmfd,start,count,mfd2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,mfd2,mfd)
+
+c en_u 
+      status=NF_GET_VARA_REAL(ncidp,varidenu,start,count,en_u2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,en_u2,en_u)
+
+c de_u 
+      status=NF_GET_VARA_REAL(ncidp,variddeu,start,count,de_u2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,de_u2,de_u)
+
+c en_d 
+      status=NF_GET_VARA_REAL(ncidp,varidend,start,count,en_d2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,en_d2,en_d)
+
+c de_d 
+      status=NF_GET_VARA_REAL(ncidp,varidded,start,count,de_d2)
+      call gr_ecrit_fi(kev,kon,iim,jjm+1,de_d2,de_d)
+
+c coefh 
+	print*,'LECTURE de coefh a irec =',irec
+       status=NF_GET_VARA_REAL(ncidp,varidch,start,count,coefh2)
+       call gr_ecrit_fi(kev,kon,iim,jjm+1,coefh2,coefh)
+
+      start(3)=irec
+      start(4)=0
+      count(3)=1
+      count(4)=0
+
+c pyu1
+	print*,'LECTURE de yu1 a irec =',irec
+      status=NF_GET_VARA_REAL(ncidp,varidyu1,start,count,pyu12)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,pyu12,pyu1)
+
+c pyv1
+        print*,'LECTURE de yv1 a irec =',irec
+      status=NF_GET_VARA_REAL(ncidp,varidyv1,start,count,pyv12)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,pyv12,pyv1)
+
+c ftsol1
+        print*,'LECTURE de ftsol1 a irec =',irec
+      status=NF_GET_VARA_REAL(ncidp,varidfts1,start,count,ftsol12)
+       call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol12,ftsol1)
+
+c ftsol2
+        print*,'LECTURE de ftsol2 a irec =',irec
+      status=NF_GET_VARA_REAL(ncidp,varidfts2,start,count,ftsol22)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol22,ftsol2)
+
+c ftsol3
+	 print*,'LECTURE de ftsol3 a irec =',irec
+      status=NF_GET_VARA_REAL(ncidp,varidfts3,start,count,ftsol32)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol32,ftsol3)
+
+c ftsol4
+      status=NF_GET_VARA_REAL(ncidp,varidfts4,start,count,ftsol42)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,ftsol42,ftsol4)
+
+c psrf1 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr1,start,count,psrf12)
+c      call dump2d(iip1-1,jjm+1,psrf12,'PSRF1NC')
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf12,psrf1)
+
+c psrf2 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr2,start,count,psrf22)
+c      call dump2d(iip1-1,jjm+1,psrf22,'PSRF2NC')
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf22,psrf2)
+
+c psrf3 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr3,start,count,psrf32)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf32,psrf3)
+
+c psrf4 
+      status=NF_GET_VARA_REAL(ncidp,varidpsr4,start,count,psrf42)
+      call gr_ecrit_fi(1,kon,iim,jjm+1,psrf42,psrf4)
+	
+          do i = 1,kon
+	
+	psrf(i,1) = psrf1(i)
+        psrf(i,2) = psrf2(i)
+        psrf(i,3) = psrf3(i)
+        psrf(i,4) = psrf4(i)
+  
+        ftsol(i,1) = ftsol1(i)
+        ftsol(i,2) = ftsol2(i)
+        ftsol(i,3) = ftsol3(i)
+        ftsol(i,4) = ftsol4(i)
+	
+          enddo
+	
+	endif
+	
+	return
+	
+	end
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/testphys1d.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/testphys1d.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/testphys1d.F	(revision 253)
@@ -0,0 +1,673 @@
+      PROGRAM gcm1d
+      IMPLICIT NONE
+
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+#include "comg1d.h"
+#include "clesphys.h"
+#include "control.h"
+
+c    Arguments :
+c    -----------
+
+      integer ngrid,nlayer,longcles,nqmax
+      parameter (longcles=20,nqmax=3)
+cfleur on  ne se sert pas de nqmax mais de nqmx defini dnas dimensions.h depend de la 
+c      compilation
+      integer radpas
+      integer nday,it,iflag_con,unit,i,itap,n_cooling
+      integer iphys_ver,iadv_tvl,i_cvg,i_hum
+
+      real fnday
+      real h,kappa,z1,z2,sbid,sigbid
+      real plev(klev+1),play(klev), psol
+      real temp(klev),u(klev),v(klev),tsurf,q(klev,nqmx),w(klev+1)
+      real ug(klev),vg(klev)
+      real du(klev),dv(klev),dt(klev),dpsrf,dq(klev,nqmx)
+      real du_dyn(klev),dv_dyn(klev)
+     :    ,dt_dyn(klev),dq_dyn(klev,nqmax)
+      real phis,presnivs(klev),clesphy0(longcles)
+      real time,timestep,ecritphy,day,tho
+      real co2_ppm,solaire
+      real rlat,rlon,tsol,radsol,psol_f,tsol_f,qsol_f,qsol
+      real rugmer,rugsrel,snow,agesno,deltat,zmea,zstd,zsig,sn
+      real zgam,zthe,zpic,zval
+      real ema_sig(klev),ema_w(klev),ncst_cbmf,ema_cbmfz,ema_pcb
+     : ,zz_f(klev),vu_f(klev),vv_f(klev),t_f(klev),q_f(klev,nqmax)
+
+      real temp0(klev),q0(klev,3)
+
+      real dt_cooling(klev),dq_cooling(klev)
+      real d_t_cool(klev),d_q_cool(klev)
+      real d_t_adv(klev),d_q_adv(klev,nqmax)
+      real d_t_cvg(klev),d_q_cvg(klev)
+      real ht(100),hq(100),hw(100)
+
+      real phy_nat(360)
+      real phy_alb(360)
+      real phy_sst(360)
+      real phy_bil(360)
+      real phy_rug(360)
+      real phy_ice(360)
+
+      logical cycle_diurne,soil_model,new_oliq,ok_orodr
+     :       ,ok_orolf,ok_limitvrai
+
+      logical firstcall,lastcall,flag_cool
+      logical itsourcecont
+c      itsourcecont permet de choisir entre les sources pour plus de 5 traceurs
+      character*80 ans,file_forctl, file_fordat, file_start,file
+      character*2 cnbl
+
+c-----------------------------------------------------------------------
+
+      COMMON/comvert/
+     * s(llm),sig(llm+1),ds(llm),dsig(llm),dsig1(llm),sdsig(llm)
+     . ,sig_s(llm)
+
+      REAL s,sig,ds,dsig,dsig1,sdsig,sig_s
+
+c-----------------------------------------------------------------------
+c INCLUDE 'temps.h':
+
+      COMMON/temps/itaufin,dtd,
+     s  day_ini,day_end,anne_ini
+
+      INTEGER  itaufin
+      INTEGER*4 day_ini,day_end,anne_ini
+      REAL     dtd
+
+c-----------------------------------------------------------------------
+c   dynamical tendencies
+
+      INTEGER l,ierr,aslun,nlevel,iq,ll
+
+      REAL longitude,latitude
+      REAL zlay(klev),phi(klev)
+      REAL paire 
+
+      DATA latitude,longitude/0.,0./
+
+c-----------------------------------------------------------------------
+c    Initialisations  des constantes
+c    -------------------------------
+
+c constantes
+c ----------
+
+      time=0.
+      tho=3600. 
+      it=0
+
+      call suphec
+
+c parametres lus dans execution_1D:
+c ---------------------------------
+
+      read(*,*) fnday
+      print*, 'fnday',fnday
+      read(*,*) ecritphy
+      print*, 'ecritphy',ecritphy
+      read(*,*) timestep
+      print*, 'timestep',timestep
+      read(*,*) iflag_con 
+      print*, 'iflag_con',iflag_con
+      read(*,*) flag_cool 
+      print*, 'flag_cool',flag_cool
+      read(*,'(a)') cnbl
+      print*, 'cnbl',cnbl
+      read(*,*) radpas   
+      print*, 'radpas',radpas
+      read(*,*) anne_ini ! sans importance mais il faut qqchose
+      print*, 'anne_ini',anne_ini
+      
+c si ecritphy=0: on ecrit la physique a chaque pas de temps:
+
+      if (ecritphy.eq.0.) then
+       ecritphy = timestep/rday
+      endif
+      write(*,*) 'ECRITPHY = ',ecritphy
+
+      firstcall=.true.
+      lastcall=.false.
+      day=1.
+      itsourcecont=.true.
+
+      open(78,file='transil.dat',form='unformatted',
+     s    access='direct',recl=4*llm*llm)
+
+      ngrid=1
+      IF (ngrid.NE.klon) THEN
+         PRINT*,'STOP in inifis'
+         PRINT*,'Probleme de dimenesions :'
+         PRINT*,'ngrid     = ',ngrid
+         PRINT*,'klon   = ',klon
+         STOP
+      ENDIF
+      nlayer=klev
+      nlevel=nlayer+1
+
+c   -------------------------------------------------------------------
+c   Initialisation de la discretisation verticale
+c   ---------------------------------------------
+c sb      CALL disvert(llm,rkappa,sig,dsig,s,ds,dsig1,sdsig)
+
+c   -------------------------------------------------------------------
+c   Profils initiaux.
+c   -----------------
+
+      unit = 80
+      open(unit,file='start'//cnbl//'.data',form='formatted')
+      read(unit,*) 
+      read(unit,*) 
+      read(unit,*) (play(l),l=1,nlayer)
+      read(unit,*) (plev(l),l=1,nlevel)
+      read(unit,*) (temp(l),l=1,nlayer)
+      read(unit,*) (q(l,1),l=1,nlayer)
+      read(unit,*) (q(l,2),l=1,nlayer)
+      read(unit,*) (ema_sig(l),l=1,nlayer)
+      read(unit,*) (ema_w(l),l=1,nlayer) ! reinitialise + loin???
+      read(unit,*) ncst_cbmf, ema_cbmfz, ema_pcb
+      read(unit,*) (zz_f(l),l=1,nlayer)
+      read(unit,*) (vu_f(l),l=1,nlayer)
+      read(unit,*) (vv_f(l),l=1,nlayer)
+      close(unit)
+      write(*,*) 'Lecture fichier start.data ok'
+
+      DO l = 1, nlayer
+         u(l) = vu_f(l)
+         v(l) = vv_f(l)
+c##################
+cfleur ATTENTION q(3) ce nest plus la glace mais le radon si on active phytrac
+c##################3
+         q(l,3) = 0. ! on initialise la glace a zero
+         PRINT*,plev(l),play(l)
+c on recopie le profil initial dans les champs de forcing:
+         t_f(l) = temp(l)
+         q_f(l,1) = q(l,1)
+         q_f(l,2) = q(l,2)
+         q_f(l,3) = q(l,3)
+      ENDDO
+
+
+c Lecture/creation des conditions aux limites:
+c --------------------------------------------
+
+      unit = 81
+      open(unit,file='startphy.data',form='formatted')
+      read(unit,*)
+      read(unit,*) co2_ppm
+      read(unit,*) solaire
+      read(unit,*) rlat
+      read(unit,*) tsol
+      read(unit,*) radsol
+      close(unit)
+      write(*,*) 'Lecture fichier startphy.data ok'
+
+      unit = 82
+      open(unit,file='condsurf.data',form='formatted')
+      read(unit,*) psol_f
+      read(unit,*) tsol_f
+      read(unit,*) qsol_f
+      close(unit)
+      write(*,*) 'Lecture fichier condsurf.data ok'
+
+      if (play(1).lt.10000.) then
+        do l = 1, nlayer
+         play(l) = play(l)*100.
+        enddo
+      endif
+      if (plev(1).lt.10000.) then
+        do l = 1, nlevel
+         plev(l) = plev(l)*100.
+        enddo
+      endif
+
+      if (abs(psol_f-plev(1)) .gt. 1.) then
+         print *,' Incompatibilite entre psol et profil'
+     :   ,' de pression'
+         print *,' psol = ',psol_f,' plev(1) = ',plev(1)
+         stop
+      endif
+
+      tsol    = tsol_f ! temp au sol prise dans condsurf.data
+      psol    = psol_f ! pression au sol prise dans condsurf.data
+      qsol    = qsol_f
+      rugmer  = 0.0001 ! valeur de cchlim.data
+      rugsrel = 0.0    ! (rugsrel = rugoro)
+      snow    = 0.0
+      sn=0.
+      agesno  = 50.0
+      rlon    = 0.0
+      deltat  = 0.0    ! ne sert que pour les slab_ocean
+      phis = 0.
+      zmea = 0.
+      zstd = 0.
+      zsig = 0.
+      zgam = 0.
+      zthe = 0.
+      zpic = 0.
+      zval = 0.
+
+      do i=1,360
+      phy_sst(i) = tsol
+      phy_nat(i) = 0.0  ! 0=ocean libre, 1=land, 2=glacier, 3=banquise
+      phy_alb(i) = 0.15 ! albedo land only (old value condsurf_jyg=0.3)
+      phy_bil(i) = 1.0  ! ne sert que pour les slab_ocean
+      phy_rug(i) = 0.1  ! longueur rugosite utilisee sur land only 
+      phy_ice(i) = 0.0  ! fraction de glace (?)
+      enddo
+
+      call writelim
+     s   (phy_nat,phy_alb,phy_sst,phy_bil,phy_rug,phy_ice)
+
+
+
+c controles du run (en 3D: lus dans run.def) :
+
+      cycle_diurne = .FALSE.
+      soil_model   = .FALSE.
+      new_oliq     = .FALSE.
+      ok_orodr     = .FALSE.
+      ok_orolf     = .FALSE.
+      ok_limitvrai = .FALSE.
+
+      do i = 1, longcles
+       clesphy0(i) = 0.
+      enddo
+
+      nbapp_rad = NINT(86400./radpas/timestep)
+
+      clesphy0(1) = FLOAT( iflag_con )
+      clesphy0(2) = FLOAT( nbapp_rad )
+      if (cycle_diurne ) clesphy0(3) = 1.
+      if (  soil_model ) clesphy0(4) = 1.
+      if (    new_oliq ) clesphy0(5) = 1.
+      if (    ok_orodr ) clesphy0(6) = 1.
+      if (    ok_orolf ) clesphy0(7) = 1.
+      if ( ok_limitvrai) clesphy0(8) = 1.
+
+
+c -------------------------------------------------------------------
+c Discretisation verticale:
+c -------------------------
+
+c calcul sig,dsig,s,ds,dsig1,sdsig a partir des play, plev lus:
+
+      do l = 1, nlevel
+       sig(l)= plev(l)/plev(1)
+      enddo
+
+      do l = 1, nlayer
+       s(l)= sig(l)**RKAPPA
+      enddo
+
+      do l = 2, nlayer
+       ds(l) = s(l-1) - s(l)
+      enddo
+      ds(1)  = 1. - s(1)
+
+      do l = 1, nlayer
+       dsig(l)  = sig(l)-sig(l+1)
+       sdsig(l) = s(l) * dsig(l)
+       dsig1(l) = 1./dsig(l)
+       presnivs(l) = play(l)/100./100.
+      enddo
+
+      print*,'Diagnostique de la discretisation verticale'
+
+      print*
+      h=7.
+      kappa = RKAPPA
+      print*,'comparaison de sig(l) et (s(l)+s(l+1))/2)**(1/K)'
+      do 14 l=1,llm-1
+         sigbid=(0.5*(s(l)+s(l+1)))**(1./kappa)
+         print*,'sig(',l+1,')  = ',sig(l+1),
+     :           '    valeur approchee :',sigbid,'   ',dsig(l)
+14    continue
+      print*
+      print*,'comparaison de s(l) et (sig(l)+sig(l+1))/2)**K'
+      do 15 l=1,llm
+         sbid=(0.5*(sig(l+1)+sig(l)))**kappa
+         print*,'  s(',l,')  = ',s(l),
+     :           '    valeur approchee :',sbid
+15    continue
+
+      print*,'Altitude approchee z,dz'
+      print*
+      z1=0.
+      print*,'   l       Z      DZ      Ztop   dsig'
+      DO 18 l=1,llm-1
+         z2=-h*log(sig(l+1))
+         write(*,'(i5,3x,4f8.4)') l,-h*log(s(l))/kappa,z2-z1,z2
+     :    ,dsig(l)
+         write(14,'(3x,i5,1f10.4)') l,-h*log(s(l))/kappa
+         z1=z2
+18    CONTINUE
+      write(*,'(i5,3x,3f8.4)') l,-h*log(s(llm))/kappa
+      write(14,'(3x,i5,1f10.4)') l,-h*log(s(llm))/kappa
+
+c      print*,'Correspondance approx pression-altitude:'
+c      z1 = 0.
+c      do l = 1, llm
+c       z1 = z1 + 287.*temp(l)/9.81/play(l)*(plev(l)-plev(l+1))
+c       write(*,*) l,play(l),z1
+c      enddo
+
+c -------------------------------------------------------------------
+c Ecriture de l'etat initial:
+c ---------------------------
+
+c     call ini_fis(timestep,radpas,iflag_con,anne_ini
+c    :            ,co2_ppm,solaire,rlat,rlon,tsol,deltat
+c    :            ,qsol,snow,radsol,rugmer,agesno,zmea,zstd,zsig,zgam
+c    :            ,zthe,zpic,zval,rugsrel
+c    :            ,phy_sst,phy_nat,phy_alb,phy_bil,phy_rug,phy_ice)
+
+      call physdem(rlon, rlat, timestep,radpas,co2_ppm,
+     .                   solaire,tsol, qsol,
+     .                   sn, radsol, deltat, rugmer,
+     .                   agesno, zmea, zstd, zsig,
+     .                   zgam, zthe, zpic, zval,
+     .                   rugsrel)
+
+
+
+c -------------------------------------------------------------------
+c Options de la simulation:
+c -------------------------
+
+      unit = 83
+      open(unit,file='version.data',form='formatted')
+      read(unit,*) iphys_ver,iadv_tvl,i_cvg,i_hum
+      close(unit)
+      write(*,*) 'Lecture fichier version.data ok'
+
+      write(*,*) 'physiq # ',iphys_ver,' (0=std; 1=forced glob cis;
+     : 2=forced loc cis)'
+      write(*,*) 'advection switch : ',iadv_tvl,' (0=no adv ;
+     : 1=forced adv)'
+      write(*,*) 'convergence switch : ',i_cvg,' (0=no conv;
+     : 1=forced conv)'
+
+
+
+c Eventuellement, preparation de la "bulle froide":
+c -------------------------------------------------
+
+      IF (flag_cool) THEN
+      unit = 84
+      open(unit,file='cool_buble.data',form='formatted')
+      read(unit,*) n_cooling
+      do l = 1, nlayer
+      read(unit,*) dt_cooling(l),dq_cooling(l)
+      enddo
+      close(unit)
+      write(*,*) 'Lecture fichier cool_buble.data ok'
+      ENDIF
+
+
+c Eventuellement, preparation du forcage par la convergence:
+c ----------------------------------------------------------
+
+      IF (i_cvg .EQ. 1) THEN
+      file_forctl = 'forcing.ctl'
+      file_fordat = 'forcing.dat'
+      file_start  = 'start'//cnbl//'.data'
+
+      call copie(klev,play,psol,file_forctl)
+      call get_uvd2(itap,file_forctl,file_fordat,file_start
+     :             ,ht,hq,hw)
+      ENDIF
+
+
+c-----------------------------------------------------------------------
+c  initialisation pour GRADS-1D
+c  ----------------------------
+
+      g1d_nlayer=nlayer
+      g1d_nomfich='grads1d.dat'
+      g1d_unitfich=30
+      g1d_nomctl='grads1d.ctl'
+      g1d_unitctl=31
+      g1d_premier=.true.
+
+      file='sort'
+      call inigrads(1,1
+     s  ,0.,1.,-2.,2.,1,0.,-2.,2.,1.
+     s  ,llm,presnivs,1000.
+     s  ,1800.,file,'Diagconvect')
+      print*,'Fin de Initialisation de wrgras'
+
+
+c=======================================================================
+c   DEBUT DE L'INTEGRATION TEMPORELLE:
+c   ==================================
+
+      itap = 1
+
+1     continue
+
+c  calcul du geopotentiel:
+c  -----------------------
+
+      phi(1)=RD*temp(1)*
+     :(plev(1)-play(1))/(.5*(plev(1)+play(1)))
+      do l = 1, nlayer-1
+         phi(l+1)=phi(l)+RD*(temp(l)+temp(l+1))*
+     :   (play(l)-play(l+1))/(play(l)+play(l+1))
+      enddo
+
+c        PRINT*,'altitude km  et T (K)'
+c        WRITE(6,'(2f10.2)') (.001*phi(l)/g,temp(l),l=1,nlayer)
+
+
+c pour etre coherent avec LMDZ.3, on passe 2 arguments 
+c en plus a physiq: phis et aire (pas utilises en 1D):
+      paire = 1. ! aire de la maille
+
+
+c  eventuellement, induction de la convection par chauffage du
+c  bas et refroidissement du haut de la couche limite:
+c  ------------------------------------------------------------
+
+      IF (flag_cool) THEN
+
+      call cool_pool(itap
+     e           ,n_cooling,dt_cooling,dq_cooling
+     s           ,d_t_cool,d_q_cool)
+
+      do l = 1, nlayer
+       temp(l) = temp(l) + d_t_cool(l)
+       q(l,1)  = q(l,1)  + d_q_cool(l)
+      enddo
+
+      ELSE
+
+      do l = 1, nlayer 
+       d_t_cool(l) = 0.
+       d_q_cool(l) = 0.
+      enddo
+
+      ENDIF
+
+
+c  eventuellement, ajouter une tendance relative a une
+c  translation du domaine (ex: pour suivre une ligne de grains):
+c  -------------------------------------------------------------
+
+      IF (iadv_tvl .EQ. 1) THEN
+
+      call advect_tvl(timestep,temp,q,vu_f,vv_f,t_f,q_f
+     :               ,d_t_adv,d_q_adv)
+
+      do l = 1, nlayer
+       temp(l) = temp(l) + d_t_adv(l)
+       q(l,1)  = q(l,1)  + d_q_adv(l,1)
+       q(l,2)  = q(l,2)  + d_q_adv(l,2)
+       q(l,3)  = q(l,3)  + d_q_adv(l,3)
+      enddo
+
+      ELSE
+
+      do l = 1, nlayer 
+       d_t_adv(l) = 0.
+       d_q_adv(l,1) = 0.
+       d_q_adv(l,2) = 0.
+       d_q_adv(l,3) = 0.
+      enddo
+
+      ENDIF
+
+
+c  eventuellement, ajouter une tendance relative a la
+c  convergence de grande echelle:
+c  -------------------------------------------------------------
+
+      IF (i_cvg .EQ. 1) THEN
+
+      call get_uvd(itap,timestep,tsol,qsol,file_fordat,ht,hq,hw)
+
+      do l = 1, nlayer
+
+       temp0(l) = temp(l) ! memoire de "l'avant dynamique"
+       q0(l,1) = q(l,1)
+       q0(l,2) = q(l,2)
+       q0(l,3) = q(l,3)
+
+       d_t_cvg(l) = ht(l) * timestep
+       d_q_cvg(l) = hq(l) * timestep
+       temp(l) = temp(l) + d_t_cvg(l)
+       q(l,1)  = q(l,1)  + d_q_cvg(l)
+c       write(*,*)'d_t_cvg,d_q_cvg:',d_t_cvg(l),d_q_cvg(l) 
+       if (q(l,1).lt.0.) then ! sb
+       print*,'OVAP negative dans main!'
+       print*,'itap,l,q,d_q_cvg:',itap,l,q(l,1),d_q_cvg(l),hq(l)
+       q(l,1)  = MAX(q(l,1),1.e-10) ! evite les humidites negatives
+       endif
+      enddo
+
+      if (itap.ge.30) then
+        print*,'hq(l),ht(l),dq,dt,q:'
+     :  ,hq(16),ht(16),d_q_cvg(16),d_t_cvg(16),q(16,1)
+      endif
+
+      ELSE
+
+      do l = 1, nlayer
+       d_t_cvg(l) = 0.
+       d_q_cvg(l) = 0.
+      enddo
+
+      ENDIF
+
+      do l = 1, nlayer
+       dt_dyn(l) = d_t_cvg(l) / timestep
+       dq_dyn(l,1) = d_q_cvg(l) / timestep
+       dq_dyn(l,2) = 0.0
+       dq_dyn(l,3) = 0.0
+      enddo
+
+
+c   calcul des tendances physiques:
+c   -------------------------------
+
+      if (itsourcecont) then
+        do iq=5,nqmx
+          ll=min(iq-4,18)
+          if(firstcall) then 
+c          q(ll,iq)=5/((plev(ll)-plev(ll+1))/rg)
+c           q(ll,iq)=5 
+c          q(ll,iq)=5*play(ll)/((plev(ll)-plev(ll+1))/rg)/(RD*temp(ll))
+            q(ll,iq)=5*play(ll)/(RD*temp(ll))
+          endif
+        print*,'q ll iq',q(ll,iq),ll,iq
+        enddo
+      else
+        do iq=5,nqmx
+          ll=min(iq-4,18)
+          q(ll,iq)=q(ll,iq)+1
+             do l=1,llm
+               q(l,iq)=q(l,iq)*(1-timestep/tho)
+        print*,'q ll iq',q(ll,iq),ll,iq
+             enddo   
+        enddo
+ 
+      endif
+
+c      CALL physiq(ecritphy,ngrid,nlayer,nqmx,
+c     :            firstcall,lastcall,
+c     :            day,day,time,timestep,
+c     :            plev,play,phi,phis,paire,
+c     :            u,v,temp,q,
+c     :            du_dyn, dv_dyn,  dt_dyn, dq_dyn,
+c     :            w,
+c     :            du,dv,dt,dq,dpsrf)
+
+c     CALL physiq (ecritphy,ngrid,nlayer,nqmx,firstcall,lastcall,
+c    ,   day,day,time,timestep,plev,play,phi,phis,paire,
+c     ,             presnivs,clesphy0,u,v,temp,q,  
+c pour calculer proprement la tendance de cape liee a la
+c dynamique, il faut entrer aussi temp0 et q0:
+c    ,             presnivs,clesphy0,u,v,temp,q,temp0,q0,  
+c    ,             du_dyn,dv_dyn,dt_dyn,dq_dyn,w,
+c - sorties
+c    s             du,dv,dt,dq,dpsrf)
+
+      print*,'PAS DE TEMPS ',timestep
+      print*,'ATTENTION!!! Il faudra passer temp0 et q0'
+      CALL physiq(ngrid,nlayer,nqmx,
+     :            firstcall,lastcall,
+     :            day,day,time,timestep,
+     :            plev,play,phi,phis,paire,presnivs,clesphy0,
+     :            u,v,temp,q,
+     :            w,
+     :            du,dv,dt,dq,dpsrf)
+
+
+
+
+      firstcall=.false.
+
+
+c   Ajout des tendances
+c   -------------------
+      DO l=1,nlayer
+         u(l)=u(l)+timestep*du(l)
+         v(l)=v(l)+timestep*dv(l)
+
+         temp(l)=temp(l)+timestep*dt(l)
+      ENDDO
+
+      do iq=1,nqmx
+         do l=1,nlayer
+            q(l,iq)=q(l,iq)+timestep*dq(l,iq)
+         enddo
+      enddo
+c      write(78,rec=itap) ((q(l,iq),l=1,llm),iq=5,22)
+      write(78,rec=itap) ((q(l,iq),iq=5,22),l=1,llm)
+      itap = itap + 1
+
+
+         time=time+timestep/rday
+         it=it+1
+         if(mod(it,2000).eq.0) print*,'TIME=',time
+         if(time.gt.fnday) then
+            CALL endg1d(1,nlayer,play,int(time/ecritphy),timestep)
+            stop
+         endif
+
+         GOTO 1
+
+      END
+
+c=======================================================================
+c=======================================================================
+c    FIN DU PROGRAMMES
+c    CI-DESSOUS, QUELQUES SOUS-PROGRAMMES UTILS
+c=======================================================================
+c=======================================================================
+
+#include "1DUTILS.h"
+#include "1Dconv.h"
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/tilft43.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/tilft43.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/tilft43.F	(revision 253)
@@ -0,0 +1,93 @@
+c $Header$
+        SUBROUTINE TLIFT43(P,T,Q,QS,GZ,ICB,NK,TVP,TPK,CLW,ND,NL,KK)
+        REAL GZ(ND),TPK(ND),CLW(ND),P(ND)
+        REAL T(ND),Q(ND),QS(ND),TVP(ND),LV0
+C
+C   ***   ASSIGN VALUES OF THERMODYNAMIC CONSTANTS     ***
+C
+c -- sb:
+c!      CPD=1005.7
+c!      CPV=1870.0
+c!      CL=4190.0
+c!      RV=461.5
+c!      RD=287.04
+c!      LV0=2.501E6
+c!      G=9.8
+c!      ROWL=1000.0
+c ajouts:
+#include "YOMCST.h"
+        CPD = RCPD
+        CPV = RCPV
+        CL = RCW
+        LV0 = RLVTT
+        G = RG
+        ROWL= RATM/100.
+        GRAVITY = RG !sb: Pr que gravite ne devienne pas humidite!
+C sb --
+C
+        CPVMCL=CL-CPV
+        EPS=RD/RV
+        EPSI=1./EPS
+C
+C   ***  CALCULATE CERTAIN PARCEL QUANTITIES, INCLUDING STATIC ENERGY   ***
+C
+        AH0=(CPD*(1.-Q(NK))+CL*Q(NK))*T(NK)+Q(NK)*(LV0-CPVMCL*(
+     1   T(NK)-273.15))+GZ(NK)
+        CPP=CPD*(1.-Q(NK))+Q(NK)*CPV
+        CPINV=1./CPP
+C
+        IF(KK.EQ.1)THEN
+C
+C   ***   CALCULATE LIFTED PARCEL QUANTITIES BELOW CLOUD BASE   ***
+C
+        DO 50 I=1,ICB-1
+         CLW(I)=0.0
+   50   CONTINUE
+        DO 100 I=NK,ICB-1
+         TPK(I)=T(NK)-(GZ(I)-GZ(NK))*CPINV
+         TVP(I)=TPK(I)*(1.+Q(NK)*EPSI)
+  100   CONTINUE
+        END IF
+C
+C    ***  FIND LIFTED PARCEL QUANTITIES ABOVE CLOUD BASE    ***
+C
+        NST=ICB
+        NSB=ICB
+        IF(KK.EQ.2)THEN  
+         NST=NL
+         NSB=ICB+1
+        END IF
+        DO 300 I=NSB,NST
+         TG=T(I)
+         QG=QS(I)
+         ALV=LV0-CPVMCL*(T(I)-273.15)
+         DO 200 J=1,2
+          S=CPD+ALV*ALV*QG/(RV*T(I)*T(I))
+          S=1./S
+          AHG=CPD*TG+(CL-CPD)*Q(NK)*T(I)+ALV*QG+GZ(I)
+          TG=TG+S*(AH0-AHG)
+          TG=MAX(TG,35.0)
+          TC=TG-273.15
+          DENOM=243.5+TC
+          IF(TC.GE.0.0)THEN  
+           ES=6.112*EXP(17.67*TC/DENOM)
+          ELSE  
+           ES=EXP(23.33086-6111.72784/TG+0.15215*LOG(TG))
+          END IF  
+          QG=EPS*ES/(P(I)-ES*(1.-EPS))
+  200    CONTINUE
+         ALV=LV0-CPVMCL*(T(I)-273.15)
+         TPK(I)=(AH0-(CL-CPD)*Q(NK)*T(I)-GZ(I)-ALV*QG)/CPD
+         CLW(I)=Q(NK)-QG
+         CLW(I)=MAX(0.0,CLW(I))
+         RG=QG/(1.-Q(NK))
+         TVP(I)=TPK(I)*(1.+RG*EPSI)
+  300   CONTINUE
+
+c -- sb:
+        RG = GRAVITY  ! RG redevient la gravite de YOMCST (sb)
+c sb --
+
+        RETURN
+        END
+
Index: LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/tlift.F
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/tlift.F	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/libf/phylmd/tlift.F	(revision 253)
@@ -0,0 +1,243 @@
+c $Header$
+        SUBROUTINE TLIFT(P,T,RR,RS,GZ,PLCL,ICB,NK,
+     .                  TVP,TPK,CLW,ND,NL,
+     .                  DTVPDT1,DTVPDQ1)
+C
+C     Argument NK ajoute (jyg) = Niveau de depart de la
+C     convection
+C
+        PARAMETER (NA=60)
+        REAL GZ(ND),TPK(ND),CLW(ND)
+        REAL T(ND),RR(ND),RS(ND),TVP(ND),P(ND)
+        REAL DTVPDT1(ND),DTVPDQ1(ND)   ! Derivatives of parcel virtual
+C                                   temperature wrt T1 and Q1
+C
+        REAL CLW_NEW(NA),QI(NA)
+        REAL DTPDT1(NA),DTPDQ1(NA)      ! Derivatives of parcel temperature
+C                                   wrt T1 and Q1
+ 
+C
+        LOGICAL ICE_CONV
+C
+C   ***   ASSIGN VALUES OF THERMODYNAMIC CONSTANTS     ***
+C
+c sb        CPD=1005.7
+c sb      CPV=1870.0
+c sb        CL=4190.0
+c sb        CPVMCL=2320.0
+c sb        RV=461.5
+c sb        RD=287.04
+c sb        EPS=RD/RV
+c sb        ALV0=2.501E6
+ccccccccccccccccccccccc
+c constantes coherentes avec le modele du Centre Europeen
+c sb      RD = 1000.0 * 1.380658E-23 * 6.0221367E+23 / 28.9644
+c sb      RV = 1000.0 * 1.380658E-23 * 6.0221367E+23 / 18.0153
+c sb      CPD = 3.5 * RD
+c sb      CPV = 4.0 * RV
+c sb      CL = 4218.0
+c sb      CI=2090.0
+c sb      CPVMCL=CL-CPV
+c sb      CLMCI=CL-CI
+c sb      EPS=RD/RV
+c sb      ALV0=2.5008E+06
+c sb      ALF0=3.34E+05
+ 
+cccccccccccc
+c on utilise les constantes thermo du Centre Europeen: (SB)
+c
+#include "YOMCST.h"
+       GRAVITY = RG !sb: Pr que gravite ne devienne pas humidite!
+c
+       CPD = RCPD
+       CPV = RCPV
+       CL = RCW
+       CI = RCS
+       CPVMCL = CL-CPV
+       CLMCI = CL-CI
+       EPS = RD/RV
+       ALV0 = RLVTT
+       ALF0 = RLMLT ! (ALF0 = RLSTT-RLVTT)
+c 
+cccccccccccccccccccccc
+C
+C   ***  CALCULATE CERTAIN PARCEL QUANTITIES, INCLUDING STATIC ENERGY   ***
+C
+        ICB1=MAX(ICB,2)
+        ICB1=MIN(ICB,NL)
+C
+Cjyg1
+CC      CPP=CPD*(1.-RR(1))+RR(1)*CPV
+      CPP=CPD*(1.-RR(NK))+RR(NK)*CPV
+Cjyg2
+      CPINV=1./CPP
+Cjyg1
+C         ICB may be below condensation level
+CCC        DO 100 I=1,ICB1-1
+CCC         TPK(I)=T(1)-GZ(I)*CPINV
+CCC         TVP(I)=TPK(I)*(1.+RR(1)/EPS)
+        DO 50 I=1,ICB1
+         CLW(I)=0.0
+50      CONTINUE
+C
+        DO 100 I=NK,ICB1
+         TPK(I)=T(NK)-(GZ(I) - GZ(NK))*CPINV
+Cjyg1
+CCC         TVP(I)=TPK(I)*(1.+RR(NK)/EPS)
+         TVP(I)=TPK(I)*(1.+RR(NK)/EPS-RR(NK))
+Cjyg2
+         DTVPDT1(I) = 1.+RR(NK)/EPS-RR(NK)
+         DTVPDQ1(I) = TPK(I)*(1./EPS-1.)
+C
+Cjyg2
+ 
+  100   CONTINUE
+ 
+C
+C    ***  FIND LIFTED PARCEL TEMPERATURE AND MIXING RATIO    ***
+C
+Cjyg1
+CC        AH0=(CPD*(1.-RR(1))+CL*RR(1))*T(1)
+CC     $     +RR(1)*(ALV0-CPVMCL*(T(1)-273.15))
+        AH0=(CPD*(1.-RR(NK))+CL*RR(NK))*T(NK)
+     $     +RR(NK)*(ALV0-CPVMCL*(T(NK)-273.15)) + GZ(NK)
+Cjyg2
+C
+Cjyg1
+        IMIN = ICB1
+C         If ICB is below LCL, start loop at ICB+1
+        IF (PLCL .LT. P(ICB1)) IMIN = MIN(IMIN+1,NL)
+C
+CCC        DO 300 I=ICB1,NL
+        DO 300 I=IMIN,NL
+Cjyg2
+         ALV=ALV0-CPVMCL*(T(I)-273.15)
+         ALF=ALF0+CLMCI*(T(I)-273.15)
+ 
+        RG=RS(I)
+        TG=T(I)
+C       S=CPD+ALV*ALV*RG/(RV*T(I)*T(I))
+Cjyg1
+CC        S=CPD*(1.-RR(1))+CL*RR(1)+ALV*ALV*RG/(RV*T(I)*T(I))
+        S=CPD*(1.-RR(NK))+CL*RR(NK)+ALV*ALV*RG/(RV*T(I)*T(I))
+Cjyg2
+        S=1./S
+ 
+        DO 200 J=1,2
+Cjyg1
+CC         AHG=CPD*TG+(CL-CPD)*RR(1)*TG+ALV*RG+GZ(I)
+         AHG=CPD*TG+(CL-CPD)*RR(NK)*TG+ALV*RG+GZ(I)
+Cjyg2
+        TG=TG+S*(AH0-AHG)
+        TC=TG-273.15
+        DENOM=243.5+TC
+        DENOM=MAX(DENOM,1.0)
+C
+C       FORMULE DE BOLTON POUR PSAT
+C
+        ES=6.112*EXP(17.67*TC/DENOM)
+        RG=EPS*ES/(P(I)-ES*(1.-EPS))
+ 
+ 
+  200   CONTINUE
+ 
+Cjyg1
+CC        TPK(I)=(AH0-GZ(I)-ALV*RG)/(CPD+(CL-CPD)*RR(1))
+        TPK(I)=(AH0-GZ(I)-ALV*RG)/(CPD+(CL-CPD)*RR(NK))
+Cjyg2
+C       TPK(I)=(AH0-GZ(I)-ALV*RG-(CL-CPD)*T(I)*RR(1))/CPD
+ 
+Cjyg1
+CC        CLW(I)=RR(1)-RG
+        CLW(I)=RR(NK)-RG
+Cjyg2
+        CLW(I)=MAX(0.0,CLW(I))
+Cjyg1
+CCC        TVP(I)=TPK(I)*(1.+RG/EPS)
+        TVP(I)=TPK(I)*(1.+RG/EPS-RR(NK))
+Cjyg2
+C
+Cjyg1       Derivatives
+C
+        DTPDT1(I) = CPD*S
+        DTPDQ1(I) = ALV*S
+C
+         DTVPDT1(I) = DTPDT1(I)*(1. + RG/EPS -
+     .           RR(NK) + ALV*RG/(RD*TPK(I)) )
+        DTVPDQ1(I) = DTPDQ1(I)*(1. + RG/EPS -
+     .           RR(NK) + ALV*RG/(RD*TPK(I)) ) - TPK(I)
+C
+Cjyg2
+ 
+  300   CONTINUE
+C
+      ICE_CONV = .FALSE.
+
+      IF (ICE_CONV) THEN
+C
+CJAM
+C       RAJOUT DE LA PROCEDURE ICEFRAC
+C
+c sb        CALL ICEFRAC(T,CLW,CLW_NEW,QI,ND,NL)
+ 
+        DO 400 I=ICB1,NL
+        IF (T(I).LT.263.15) THEN
+        TG=TPK(I)
+        TC=TPK(I)-273.15
+        DENOM=243.5+TC
+        ES=6.112*EXP(17.67*TC/DENOM)
+        ALV=ALV0-CPVMCL*(T(I)-273.15)
+        ALF=ALF0+CLMCI*(T(I)-273.15)
+ 
+        DO J=1,4
+        ESI=EXP(23.33086-(6111.72784/TPK(I))+0.15215*LOG(TPK(I)))
+        QSAT_NEW=EPS*ESI/(P(I)-ESI*(1.-EPS))
+CCC        SNEW= CPD*(1.-RR(1))+CL*RR(1)+ALV*ALV*QSAT_NEW/(RV*TPK(I)*TPK(I))
+        SNEW= CPD*(1.-RR(NK))+CL*RR(NK)
+     .        +ALV*ALV*QSAT_NEW/(RV*TPK(I)*TPK(I))
+C
+        SNEW=1./SNEW
+        TPK(I)=TG+(ALF*QI(I)+ALV*RG*(1.-(ESI/ES)))*SNEW
+c$$$        PRINT*,'################################'
+c$$$        PRINT*,TPK(I)
+c$$$        PRINT*,(ALF*QI(I)+ALV*RG*(1.-(ESI/ES)))*SNEW
+        ENDDO
+CCC        CLW(I)=RR(1)-QSAT_NEW
+        CLW(I)=RR(NK)-QSAT_NEW
+        CLW(I)=MAX(0.0,CLW(I))
+Cjyg1
+CCC        TVP(I)=TPK(I)*(1.+QSAT_NEW/EPS)
+        TVP(I)=TPK(I)*(1.+QSAT_NEW/EPS-RR(NK))
+Cjyg2
+        ELSE
+        CONTINUE
+        ENDIF
+ 
+  400   CONTINUE
+C
+      ENDIF
+C
+ 
+******************************************************
+** BK :  RAJOUT DE LA TEMPERATURE DES ASCENDANCES
+**   NON DILUES AU  NIVEAU KLEV = ND
+**   POSONS LE ENVIRON EGAL A CELUI DE KLEV-1
+********************************************************
+ 
+      TPK(NL+1)=TPK(NL)
+ 
+*******************************************************
+
+      RG = GRAVITY  ! RG redevient la gravite de YOMCST (sb)
+ 
+ 
+        RETURN
+        END
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
Index: LMDZ.3.3/branches/rel-1-0-patch/makegcm
===================================================================
--- LMDZ.3.3/branches/LF/makegcm	(revision 3)
+++ LMDZ.3.3/branches/rel-1-0-patch/makegcm	(revision 253)
@@ -1,8 +1,9 @@
 #!/bin/csh
+# $Header$
 #set verbose echo
 ########################################################################
 # options par defaut pour la commande make
 ########################################################################
-set dim="48x32x19"
+set dim="72x45x19"
 set physique=lmd
 set phys="PHYS=$physique"
@@ -18,33 +19,64 @@
 # set LMDGCM=$HOME/LMDZ.3.3
 #
-#   a changer  rlmd304/agcm
-#
-###### VERSION LMDZ.3.2
-
-if ( ! $?LMDGCM ) then
-   echo You must initialize the variable LMDGCM in your environnement
-   echo for instance: "setenv LMDGCM /usr/myself/supergcm" in .cshrc
-   exit
-endif
-if ( ! $?LIBOGCM ) then
-   set LIBOGCM=$LMDGCM/libo
-endif
-if ( ! $?IOIPSLDIR ) then
-   echo You must initialize the variable IOIPSLDIR in your environnement
-   echo for instance: "setenv IOIPSLDIR /usr/myself/ioipsl" in .cshrc
-   exit
-endif
-if ( ! $?NCDFLIB ) then
-   echo You must initialize the variable NCDFLIB in your environnement
-   echo for instance: "setenv NCDFLIB /usr/myself/netcdf" in .cshrc
-   exit
-endif
-if ( ! $?NCDFINC ) then
-   echo You must initialize the variable NCDFINC in your environnement
-   echo for instance: "setenv NCDFINC /usr/myself/netcdf" in .cshrc
-   exit
+
+setenv localdir "`pwd`"
+set MODIPSL=0
+echo $localdir | grep modipsl >& /dev/null
+if ( ! $status ) then
+  set MODIPSL=1
+  setenv LMDGCM $localdir
+  cd ../..
+  setenv LIBOGCM "`pwd`/lib"
+  setenv IOIPSLDIR $LIBOGCM
+  cd $localdir
+  if ( `hostname` == rhodes ) then
+    set NCDFINC=`grep sxnec ../../util/AA_make.gdef| grep NCDF_INC|sed -e "s/^.* =//"`
+    set NCDFLIB=`grep sxnec ../../util/AA_make.gdef| grep NCDF_LIB|sed -e 's/^.* =//'`
+  else
+    if ( `hostname` == nymphea0 ) then
+      set NCDFINC=`grep fjvpp ../../util/AA_make.gdef| grep NCDF_INC|sed -e "s/^.* =//"`
+      set NCDFLIB=`grep fjvpp ../../util/AA_make.gdef| grep NCDF_LIB|sed -e 's/^.* =//'`
+    else
+      echo 'Probleme de definition des variables NCDFINC et NCDFLIB'
+    endif 
+  endif 
+  \cp libf/phylmd/oasis.F libf/phylmd/oasis.dummy
+  \cp libf/phylmd/oasis.true libf/phylmd/oasis.F
+else
+  if ( ! $?LMDGCM ) then
+    echo You must initialize the variable LMDGCM in your environnement
+    echo for instance: "setenv LMDGCM /usr/myself/supergcm" in .cshrc
+    exit
+  endif
+  if ( ! $?LIBOGCM ) then
+    set LIBOGCM=$LMDGCM/libo
+  endif
+  if ( ! $?IOIPSLDIR ) then
+    echo You must initialize the variable IOIPSLDIR in your environnement
+    echo for instance: "setenv IOIPSLDIR /usr/myself/ioipsl" in .cshrc
+    exit
+  endif
+  if ( ! $?NCDFLIB ) then
+    echo You must initialize the variable NCDFLIB in your environnement
+    echo for instance: "setenv NCDFLIB /usr/myself/netcdf" in .cshrc
+    exit
+  endif
+  if ( ! $?NCDFINC ) then
+    echo You must initialize the variable NCDFINC in your environnement
+    echo for instance: "setenv NCDFINC /usr/myself/netcdf" in .cshrc
+    exit
+  endif
 endif
 set model=$LMDGCM
 set libo=$LIBOGCM
+
+#Force/couple
+set COUPLE=0
+set ocean=`grep '^      parameter (ocean' libf/phylmd/physiq.F | awk -F\' '{print $2}'`
+banner $ocean
+if ($ocean == couple) then
+  set COUPLE=1
+endif
+
 
 ########################################################################
@@ -60,4 +92,5 @@
 set LINUX=0
 set NEC=0
+set XNEC=0
 if ( `uname` == HP-UX ) then
    set machine=HP
@@ -81,7 +114,10 @@
    set machine=CRAY
    set CRAY=1
-else if ( `hostname` == rhodes ) then
+else if ( `uname` == SUPER-UX ) then
    set machine=NEC
    set NEC=1
+else if ( `hostname` == rhodes) then
+   set machine=XNEC
+   set XNEC=1
 else
    echo Vous travaillez sur une machine non prevue par le reglement
@@ -120,5 +156,5 @@
 set libf=$model/libf
 #setenv localdir "LOCAL_DIR=`pwd`"
-setenv localdir "`pwd`"
+#setenv localdir "`pwd`"
 cd $model
 if $CRAY then
@@ -134,4 +170,5 @@
    set optimbis=" "
    set optim90=" -fast -fixed "
+   set optimtru90=" -fast -free"
    set opt_link="-lf77compat -L$IOIPSLDIR -lioipsl  -L$NCDFLIB -lnetcdf"
    set mod_loc_dir=$localdir
@@ -144,11 +181,15 @@
    set optimbis=" "
 else if $VPP then
-   set optim=" -Ad -Of -Wv,-Of,-ilfunc"
-   set optimbis=" -Psia -Aa -Wv,-m3 -Wp,-DVPP,-DNC_DOUBLE -Z $LMDGCM/listage"
-   set optim=" -Of -Wv,-Of,-ilfunc"
-   set optimbis=" -Psia -Aa -Wv,-m3 -Wp,-DVPP -Z $LMDGCM/listage"
-   set optim90="$optim""$optimbis"" -X9 -w"
-   set opt_link="-L$IOIPSLDIR -lioipsl  -L$NCDFLIB -lnetcdf"
-   set oplink=" "
+#   set optim="-Dasuxm  -On, -g -Ad -Potilax -Eciplume -Si"
+#   set optimbis="  -Wv,-m3 -Wp,-DVPP -Z $LMDGCM/listage"
+   set optimbis=" -Wp,-DNC_DOUBLE -Ad -Z $LMDGCM/listage"
+   set optim90="$optim $optimbis -X9 -w"
+   if $COUPLE then
+     set opt_link="-Wg,-c $IOIPSLDIR/liboasis2.4_mpi2.a /usr/lang/mpi2/lib64/libmpi.a /usr/lang/mpi2/lib64/libmp.a /usr/local/lib/lib64/libnetcdf_cc.a -L$IOIPSLDIR -lioipsl"
+     set oplink="-Wl,-t,-P,-dy "
+   else
+     set opt_link="-Wg,-c /usr/local/lib/lib64/libnetcdf_cc.a -L$IOIPSLDIR -lioipsl"
+     set oplink="-Wl,-t,-dy "
+   endif
    set mod_loc_dir=$IOIPSLDIR
    set mod_suffix=mod
@@ -159,15 +200,34 @@
    set optim="-fast "
    set optim90=" -fast -module $libo"
+   set optimtru90=" -fast -c -Mfree -module /d3/fairhead/sechiba/ioipsl"
    set opt_link=" -Mfree -L/usr/local/pgi/linux86/lib -lpgf90 -lpgftnrtl -lpghpf -lpghpf2 -L$NCDFLIB -lnetcdf -L$IOIPSLDIR -lioipsl -Wl,-Bstatic "
    set mod_loc_dir=$IOIPSLDIR
    set mod_suffix=mod
 else if $NEC then
-set optim90=' -C hopt -float0 -ew -R4 -L nostdout -Wf,"-pvctlfullmsg noassume loopcnt=150000 -L transform"'
-   set optim90=' -C hopt -float0 -ew -R4 -L nostdout '
+   set optim90=' -clear -C hopt -float0 -ew -P static -Wf,"-pvctl fullmsg noassume "'
+   set optimtru90=' -clear -f4 -C hopt -float0 -ew -P static -Wf,"-pvctl fullmsg noassume "'
    set optim="$optim90"
-   set opt_link="-L/u/rech/ces/rces011/ioipsl"
    set optimbis=" "
-   set mod_loc_dir=" "
-   set mod_suffix=" "
+   set opt_link=" -C hopt -float0 -ew -P static -L$IOIPSLDIR -lioipsl  -L/u/rech/psl/rpsl003/IOIPSL -lnetcdf_i8r8_v "
+   set mod_loc_dir="."
+   set mod_suffix="mod"
+else if $XNEC then
+   set optim90=' -clear -R5 -C vopt -float0 -ew -P static -Wf,"-pvctl loopcnt=40000 fullmsg noassume "'
+   set optimtru90=' -clear -R5 -f4 -C vopt -float0 -ew -P static -Wf,"-pvctl loopcnt=40000 fullmsg noassume "'
+   set optim="$optim90"
+   set optimbis=" "
+   if $MODIPSL then
+     if $COUPLE then
+       set opt_link="-L$IOIPSLDIR -lsxioipsl -loasis2.4_mpi2 -float0 -ew -P static -I$NCDFINC $NCDFLIB "
+     else
+       set opt_link="-L$IOIPSLDIR -lsxioipsl -float0 -ew -P static -I$NCDFINC $NCDFLIB "
+     endif
+     set mod_loc_dir="./"
+   else
+     set opt_link=" -C hopt -float0 -ew -P static -L$IOIPSLDIR -lsxioipsl -L /u/rech/psl/rpsl003/IOIPSL -lnetcdf_i8r8_v -I$NCDFINC "
+     set mod_loc_dir="."
+   endif
+   set mod_suffix="mod"
+
 else
    set optim=""
@@ -316,5 +376,5 @@
 
      case -link
-        set opt_link="$2" ; shift ; shift ; goto top
+        set opt_link="$opt_link $2" ; shift ; shift ; goto top
 
      case -debug
@@ -325,4 +385,5 @@
            set optim=" -g -C "
            set optim90=" -fixed -g "
+           set optimtru90=" -free -g "
         else if $CRAY then
            set optim="$optim"" -g "
@@ -342,4 +403,6 @@
    endsw
 endif
+
+echo apres les opts dim $dim
 
 ########################################################################
@@ -388,7 +451,11 @@
    set nomlib=DEC
 endif
+echo dimension avant sed $dim
 if ( $IBM ) then
    set dim=`echo $dim | sed -en 's/[^0-9]/ /g'`
    set dim_=`echo $dim | sed -en 's/[^0-9]/_/g'`
+else if ( $SUN || $XNEC ) then
+   set dim=`echo $dim | sed -e 's/[^0-9]/ /g'` 
+   set dim_=`echo $dim | sed -e 's/[^0-9]/_/g'`
 else
    set dim=`echo $dim | sed -n -e 's/[^0-9]/ /gp'`
@@ -400,5 +467,5 @@
     set nomlib=F90_${dim_}_t${ntrac}
 endif
-if ( $NEC ) then
+if ( $NEC || $XNEC ) then
     set nomlib=F90_${dim_}_t${ntrac}
 endif
@@ -457,5 +524,5 @@
 
 set dimension=`echo $dim | wc -w`
-echo dimension $dimension
+echo dimension $dimension dim $dim
 if ( $dimension == 1 ) then
 echo pas de dynamique
@@ -515,4 +582,5 @@
 find libf -name '*.[Fh]' -print >! tmp77
 find libf -name '*.[Fh]' -exec egrep -i " *use *ioipsl" {} \; -print >! tmp90
+find libf -name '*.[Fh]90' -print >> tmp90
 
 if (    `diff tmp77 liste_des_sources_f77 | wc -w` \
@@ -554,5 +622,5 @@
    set f90=f90
 else if $LINUX then
-   set f77=pgf77
+   set f77=pgf90
    set f90=pgf90
 else if $SUN then
@@ -560,6 +628,9 @@
    set f90=f90
 else if $NEC then
-   set f77=sxf90
-   set f90=sxf90
+   set f77=f90
+   set f90=f90
+else if $XNEC then
+   set f77=sxmpif90
+   set f90=sxmpif90
 else
    set f77=f77
@@ -577,4 +648,7 @@
 else if $LINUX then
 set make="make -k RANLIB=ranlib"
+else if $XNEC then
+set make="/usr/local/bin/gmake RANLIB=ls"
+set make="/usr/freeware/bin/gmake RANLIB=ls"
 else
 set make="make RANLIB=ranlib"
@@ -582,11 +656,4 @@
 
 
-
-set link="$f90 $optim90"
-
-if $NEC then
-  set link="sxld $opt_link"
-  set ar=sxar
-endif
 
 #
@@ -623,6 +690,6 @@
      exit                       
    endif
-   set optim=" -Ad -Wv,-Of,-ilfunc"
-   set optimbis=" -Psia -Aa -Wv,-m3 -Wp,-DVPP,-DNC_DOUBLE -Z $LMDGCM/listage"
+   set optim=" -Wv,-Of,-ilfunc"
+   set optimbis=" -Psia -Aa -Wv,-m3 -Wp,-DVPP -Z $LMDGCM/listage"
    set optim90="$optim""$optimbis"" -X9 -w"
    set opt_link="-L$IOIPSLDIR -lioipsl -L$NCDFLIB -lnetcdf"
@@ -631,4 +698,10 @@
 endif
 
+#
+# etat0_netcdf a besoin d'info de la physique
+# A revoir
+set include="$include"' -I$(LIBF)/phylmd'
+
+
 #################################################################
 # Execution de la comande make... ENFIN!
@@ -637,21 +710,44 @@
 if $VPP then
   set optim90=" $optim90 -Am -M$libo"
+  set optimtru90="$optim90"
  \cp $IOIPSLDIR/*.mod $libo
 else if $SUN then
- set optim90=" $optim90 -M$IOIPSLDIR -M$libo "
+ set optim90=" $optim90 -M$libo "
+ set optimtru90=" $optimtru90 -M$libo "
  set optim="$optim90"
+ \cp /d3/fairhead/sechiba_sun/parameters/*.mod $libo
+ \cp /d3/fairhead/sechiba_sun/sechiba/*.mod $libo
+ \cp /d3/fairhead/sechiba_sun/stomate/*.mod $libo
  \cp $IOIPSLDIR/*.mod $libo
+else if $NEC then
+ set optim90=" $optim90 -I$libo "
+else if $XNEC then
+ set optim90=" $optim90 -I$libo "
+ set optimtru90=" $optimtru90 -I$libo "
 else if $LINUX then
  set optim90=" -fast -module $libo "
+ set optim="$optim90"
  set mod_loc_dir=$libo
+ \cp /d3/fairhead/sechiba/ioipsl/*.mod $libo
  \cp $IOIPSLDIR/*.mod $libo
 endif
 
+set link="$f90 $optim90"
+
+set ar=ar
+
+if $XNEC then
+  set link="sxld $opt_link"
+  set link="$f90 "
+#  set ar=sxar
+endif
+
+
 cd $localdir
-
 
 echo $make -f $LMDGCM/makefile \
 OPTION_DEP="$opt_dep" OPTION_LINK="$opt_link" \
 OPTIM90="$optim90" \
+OPTIMTRU90="$optimtru90" \
 OPTIM="$optim$optimbis" \
 INCLUDE="$include" \
@@ -670,4 +766,5 @@
 MOD_LOC_DIR=$mod_loc_dir \
 MOD_SUFFIX=$mod_suffix \
+AR=$ar \
 PROG=$code
 
@@ -675,4 +772,5 @@
 OPTION_DEP="$opt_dep" OPTION_LINK="$opt_link" \
 OPTIM90="$optim90" \
+OPTIMTRU90="$optimtru90" \
 OPTIM="$optim$optimbis" \
 INCLUDE="$include" \
@@ -691,5 +789,10 @@
 MOD_LOC_DIR=$mod_loc_dir \
 MOD_SUFFIX=$mod_suffix \
+AR=$ar \
 PROG=$code
 
 \rm $libf/grid/dimensions.h
+if $MODIPSL then
+  \cp libf/phylmd/oasis.F libf/phylmd/oasis.true
+  \cp libf/phylmd/oasis.dummy libf/phylmd/oasis.F
+endif
Index: LMDZ.3.3/branches/rel-1-0-patch/run.def
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/run.def	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/run.def	(revision 253)
@@ -0,0 +1,161 @@
+
+----------------------------------------------------------------------- 
+Parametres de controle du run:                                          
+------------------------------                                          
+
+- Jour de l'etat initial ( = 350  si 20 Decembre ,par expl. ,comme ici )
+   dayref
+ 110
+
+-  Annee de l'etat  initial (   avec  4  chiffres   )
+   anneeref
+ 1988
+
+- Nombre de jours d'integration                                         
+    nday
+  1
+
+- nombre de pas par jour (multiple de iperiod)  ( ici , dt= 10 secondes ) 
+ day_step
+ 8640
+
+- periode pour le pas Matsuno (en pas)                                  
+ iperiod
+  5
+
+- periode de sortie des variables de controle (en pas)                 
+ iconser
+  20
+
+- periode d'ecriture du fichier histoire (en jour)                      
+   iecri
+  100
+
+- periode de stockage fichier histmoy (en jour)                         
+ periodav
+  30
+
+- periode de la dissipation (en pas)
+  idissip
+ 5
+
+- choix de l'operateur de dissipation (star ou  non star )
+  lstardis
+  T
+  
+- nombre d'iterations de l'operateur de dissipation   gradiv 
+  nitergdiv
+  1
+
+- nombre d'iterations de l'operateur de dissipation  nxgradrot
+  nitergrot
+  2
+
+- nombre d'iterations de l'operateur de dissipation  divgrad
+  niterh
+  2
+
+- temps de dissipation des plus petites long.d ondes pour u,v (gradiv)
+  tetagdiv
+  1700.
+
+- temps de dissipation des plus petites long.d ondes pour u,v(nxgradrot)
+  tetagrot
+  1700.
+
+- temps de dissipation des plus petites long.d ondes pour  h ( divgrad)
+  tetatemp
+  1700.
+
+- coefficient pour gamdissip
+ coefdis
+  0.
+
+- choix du shema d'integration temporelle (Matsuno ou Matsuno-leapfrog)
+  purmats
+ F
+
+- avec ou sans physique
+   physic
+ T
+
+- periode de la physique (en pas)  ( toutes les 30 minutes )
+ iphysiq
+  180
+
+- frequence (en  jours ) de l'ecriture du fichier histphy               
+  ecritphy
+  1.
+
+-  Cycle diurne  ou non
+ cycle_diurne
+ T
+
+-  Soil Model  ou non
+ soil_model
+ F
+
+-  Choix ou non  de  New oliq
+ new_oliq
+ T
+
+-  Orodr  ou  non   pour l orographie
+  ok_orodr
+ F
+
+-  Orolf  ou  non   pour l orographie
+  ok_orolf
+ F
+
+-   Si = .T. ,  lecture du fichier limit avec la bonne annee
+  ok_limitvrai
+ T
+
+- Nombre  d'appels des routines de rayonnements ( par jour)
+  nbapp_rad
+ 12
+
+-  Flag  pour la convection ( 1 pour LMD,  2 pour Tiedtke, 3  CCM )
+  iflag_con
+ 2
+
+- longitude en degres du centre du zoom
+  clon
+ 75.
+
+ latitude en degres du centre du zoom
+  clat
+ 15.
+
+- facteur de grossissement du zoom,selon longitude
+  grossismx
+  1.0
+
+- facteur de grossissement du zoom ,selon latitude
+  grossismy
+  1.0
+
+-  Fonction  f(y)  hyperbolique ( si .true. )  ou   sinusoidale
+ fxyhypb
+  T
+
+- extension en longitude  de la zone du zoom ( en degres ) ou fraction( <1 ) 
+   dzoomx
+ 0.0
+
+- extension en latitude de la zone  du zoom ( en degres ) ou fraction( <1 )
+   dzoomy
+ 0.0 
+
+-  raideur du zoom en  X
+    taux
+ 3.
+
+-  raideur du zoom en  Y
+    tauy
+ 3.
+
+-  Fonction  f(y) avec y = Sin(latit.) si = .TRUE. ,  Sinon  y = latit.
+  ysinus
+  T
+
Index: LMDZ.3.3/branches/rel-1-0-patch/script/compile
===================================================================
--- LMDZ.3.3/branches/LF/script/compile	(revision 3)
+++ 	(revision )
@@ -1,12 +1,0 @@
-#QSUB -r lmdzt_compile -eo -o /workdir/rech/hou/rhou909/out.lmdzt_compile
-#QSUB -lM 256Mb -ls 8Mb -lP 0 -lT 01:00:00 -lt 01:00:00 -q compil
-
-set -xv
-
-cd $WORKDIR
-date
-
-$HOME/LMDZ.3.3/makegcm_drs etat0_lmd
-$HOME/LMDZ.3.3/makegcm_drs limit_lmd
-$HOME/LMDZ.3.3/makegcm gcm
-
Index: LMDZ.3.3/branches/rel-1-0-patch/script/essai
===================================================================
--- LMDZ.3.3/branches/LF/script/essai	(revision 3)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#QSUB -r lmdz32_essai -eo -o /workdir/rech/ces/rces111/out.lmdz32_essai
-#QSUB -lM 370Mb -ls 8Mb -lP 0 -lT 00:10:00 -lt 00:10:00
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def.2jours run.def
-
-cp $WORKDIR/gcm.e gcm.e ; chmod u+x gcm.e
-#maiaget lmdz32/divers/limit.nc limit7995.nc
-#maiaget lmdz32/divers/start.nc start.nc
-#maiaget lmdz32/divers/startphy.nc startphy.nc
-cp $WORKDIR/limit.nc limit7995.nc
-cp $WORKDIR/start.nc start.nc
-cp $WORKDIR/startphy.nc startphy.nc
-
-timex gcm.e
-ls -lt
-
-cp histday.nc $WORKDIR
-cp histmth.nc $WORKDIR
-cp histins.nc $WORKDIR
-cp histoire.nc $WORKDIR
-cp histmoy.nc $WORKDIR
-cp restart.nc $WORKDIR
-cp restartphy.nc $WORKDIR
Index: LMDZ.3.3/branches/rel-1-0-patch/script/initialisation
===================================================================
--- LMDZ.3.3/branches/LF/script/initialisation	(revision 3)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#!/bin/csh
-
-# en local
-
-set dir=~lmdz/DATA
-set cp="ln -s"
-
-#===================================================================
-# Fichiers necessaires a la creations des etats initiaux
-#===================================================================
-$cp $dir/albedo.g1x1.dat albed.dat          # Albedos de surface
-$cp $dir/albedo.g1x1.dic albed.dic          
-$cp $dir/amip88.g2x2.dat amip.dat           # SST
-$cp $dir/amip88.g2x2.dic amip.dic
-$cp $dir/ecdyn.d880701.h12.dat ecdyn.dat    # Etat initial dynamique
-$cp $dir/ecdyn.d880701.h12.dic ecdyn.dic
-$cp $dir/ecphy.d880701.h12.dat ecphy.dat    # Etat initial physique
-$cp $dir/ecphy.d880701.h12.dic ecphy.dic
-$cp $dir/relief.usnavy.dat relief.dat       # Fichier de relief
-$cp $dir/relief.usnavy.dic relief.dic
-$cp $dir/rugos.g1x1.dat rugos.dat           # Rugosite de la surface
-$cp $dir/rugos.g1x1.dic rugos.dic
-#===================================================================
-
-
-if ( ! -f run.def ) then
-echo Il faut avoir sur le repertoire courant un fichier run.def
-exit
-endif
-
-# Creation des etats initiaux
-# ===========================
-echo "execution de etat0_lmd.e, sortie dans etat0_lmd.l"
-./etat0_lmd.e << EoD >! etat0_lmd.l
-181
-EoD
-
-# Creation des conditions aux limites
-# ===================================
-echo "execution de limit_lmd.e, sortie dans limit_lmd.l"
-./limit_lmd.e >! limit_lmd.l
-
-# Conditions aux limites pour les especes traces
-# ==============================================
-if ( -f limit_tr.e ) then
-$cp $dir/so2_1x1 so2_1x1
-limit_tr.e > limit_tr.l
-else
-echo Vous n avez pas cree le fichier limit_tr utilise par les versions
-echo du modele avec traceurs
-endif
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_LMDZ.3.3
===================================================================
--- LMDZ.3.3/branches/rel-1-0-patch/script/lancer_LMDZ.3.3	(revision 253)
+++ LMDZ.3.3/branches/rel-1-0-patch/script/lancer_LMDZ.3.3	(revision 253)
@@ -0,0 +1,58 @@
+#@$-eo
+#@$-o /workdir/rech/ces/rces011/lmdz_96x72/lancer.out
+#@$-lM 1Gb
+#@$-lT 00:40:00
+#@$-jo
+ 
+set -x 
+
+# Repertoire de sauvegarde des resultats sur gaya 
+GAYADIR=LMDZ.3.3
+rsh gaya "mkdir $GAYADIR"
+
+cd $tmpdir
+
+# Recuperer les fichiers necessaires a la creation des start et limit
+
+mfget ~rces011/LMDZ_Init/Albedo.nc Albedo.nc
+mfget ~rces011/LMDZ_Init/AMIP.nc AMIP.nc
+mfget ~rces011/LMDZ_Init/ECDYN.nc ECDYN.nc
+mfget ~rces011/LMDZ_Init/Relief.nc Relief.nc
+mfget ~rces011/LMDZ_Init/Rugos.nc Rugos.nc
+cp ECDYN.nc ECPHY.nc
+
+cp ~rces011/LMDZ.3.3/run.def.967219 run.def
+
+# Compiler les executables
+$LMDGCM/makegcm -d 96x72x19 create_etat0
+$LMDGCM/makegcm -d 96x72x19 create_limit
+$LMDGCM/makegcm -d 96x72x19 gcm
+
+# On lance tout
+./create_etat0.e
+./create_limit.e
+
+# Pour avoir des details sur le programme (MFlops etc...)
+export  F_PROGINF=detail
+time ./gcm.e
+
+# Sauvegarde des fichier sur gaya
+# Fichiers restart
+mfput restartphy.nc   $GAYADIR/restartphy.nc
+mfput restart.nc      $GAYADIR/restart.nc
+# Fichiers histoire
+mfput dyn_hist.nc     $GAYADIR/dyn_hist.nc
+mfput dyn_histv.nc    $GAYADIR/dyn_histv.nc
+mfput dyn_hist_ave.nc $GAYADIR/dyn_hist_ave.nc
+mfput histmth.nc      $GAYADIR/histmth.nc
+mfput histrac.nc      $GAYADIR/histrac.nc
+# Fichiers Fluxs offline
+mfput fluxstoke.nc    $GAYADIR/fluxstoke.nc
+mfput fluxstokev.nc   $GAYADIR/fluxstokev.nc
+mfput defstoke.nc     $GAYADIR/defstoke.nc
+mfput phystoke.nc     $GAYADIR/phystoke.nc
+
+
+ls -l
+
+exit
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_essai
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_essai	(revision 3)
+++ 	(revision )
@@ -1,22 +1,0 @@
-#QSUB -r lmdz32_essai -eo -o /workdir/rech/ces/rces111/out.lmdz32_essai
-#QSUB -lM 290Mb -ls 8Mb -lP 0 -lT 00:30:00 -lt 00:30:00
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def.10jours run.def
-
-mkdir saves
-maiaget lmdz32/divers/gcm.e gcm.e; chmod u+x gcm.e
-maiaget lmdz32/divers/limit.dat limit7995.dat
-maiaget lmdz32/divers/limit.dic limit7995.dic
-maiaget lmdz32/divers/start.dat start.dat
-maiaget lmdz32/divers/start.dic start.dic
-maiaget lmdz32/divers/startphy.dat startphy.dat
-maiaget lmdz32/divers/startphy.dic startphy.dic
-
-gcm.e
-
-ls -lt
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_etat0
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_etat0	(revision 3)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#QSUB -r lmdz32_etat0 -eo -o /workdir/rech/ces/rces111/out.etat0
-#QSUB -lM 320Mb -ls 8Mb -lP 0 -lT 00:30:00 -lt 00:30:00
-set -x
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def .
-
-maiaget /u/rech/lmd/rlmd001/datadrs/albedo.g1x1.dat albed.dat
-maiaget /u/rech/lmd/rlmd001/datadrs/albedo.g1x1.dic albed.dic
-maiaget /u/rech/lmd/rlmd001/datadrs/rugos.g1x1.dic rugos.dic
-maiaget /u/rech/lmd/rlmd001/datadrs/rugos.g1x1.dat rugos.dat
-maiaget /u/rech/lmd/rlmd001/datadrs/relief.usnavy.dic.Z relief.dic.Z
-maiaget /u/rech/lmd/rlmd001/datadrs/relief.usnavy.dat.Z relief.dat.Z
-maiaget /u/rech/lmd/rlmd001/datadrs/ecphy.d880701.h12.dic ecphy.dic
-maiaget /u/rech/lmd/rlmd001/datadrs/ecphy.d880701.h12.dat ecphy.dat
-maiaget /u/rech/lmd/rlmd001/datadrs/ecdyn.d880701.h12.dic ecdyn.dic
-maiaget /u/rech/lmd/rlmd001/datadrs/ecdyn.d880701.h12.dat ecdyn.dat
-maiaget /u/rech/lmd/rlmd001/datadrs/amip2bc7995.dic.Z amip.dic.Z
-maiaget /u/rech/lmd/rlmd001/datadrs/amip2bc7995.dat.Z amip.dat.Z
-uncompress *.Z
-
-cp $WORKDIR/etat0_lmd.e .
-etat0_lmd.e
-
-cp $WORKDIR/limit_lmd.e .
-limit_lmd.e
-
-ls -lt
-
-for n in start.nc startphy.nc limit.nc
-do
-cp $n $WORKDIR
-maiaput $n lmdz32/divers/$n
-done
-
-
-rsh shine0 qsub lmdz32/script/essai
-
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_sim00
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_sim00	(revision 3)
+++ 	(revision )
@@ -1,49 +1,0 @@
-#QSUB -r lmdz32_sim00 -eo -o /workdir/rech/ces/rces111/out.lmdz32_sim00
-#QSUB -lM 290Mb -ls 8Mb -lP 0 -lT 09:00:00 -lt 03:00:00
-exp=sim00
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def run.def
-
-mkdir saves
-maiaget lmdz32/${exp}/gcm.e saves/gcm.e; chmod u+x saves/gcm.e
-maiaget lmdz32/divers/limit.dat saves/limit.dat
-maiaget lmdz32/divers/limit.dic saves/limit.dic
-mv run.def saves/run.def
-maiaget lmdz32/divers/start.dat saves/start.dat
-maiaget lmdz32/divers/start.dic saves/start.dic
-maiaget lmdz32/divers/startphy.dat saves/startphy.dat
-maiaget lmdz32/divers/startphy.dic saves/startphy.dic
-
-for m in 1 2 3
-do
-cp saves/gcm.e gcm.e
-cp saves/limit.dat limit7995.dat
-cp saves/limit.dic limit7995.dic
-cp saves/run.def run.def
-mv saves/start.dat .
-mv saves/start.dic .
-mv saves/startphy.dat .
-mv saves/startphy.dic .
-mp1=`expr $m + 1`
-gcm.e || exit 1
-maiaput histphy.dat lmdz32/${exp}/histphy.dat.$m
-maiaput histphy.dic lmdz32/${exp}/histphy.dic.$m
-maiaput relief.gdat lmdz32/${exp}/relief.gdat
-maiaput relief.ctl lmdz32/${exp}/relief.ctl
-maiaput restartphy.dat lmdz32/${exp}/startphy.dat.${mp1}
-maiaput restartphy.dic lmdz32/${exp}/startphy.dic.${mp1}
-maiaput restart.dat lmdz32/${exp}/start.dat.${mp1}
-maiaput restart.dic lmdz32/${exp}/start.dic.${mp1}
-mv restartphy.dat saves/startphy.dat
-mv restartphy.dic saves/startphy.dic
-mv restart.dat saves/start.dat
-mv restart.dic saves/start.dic
-ls -lt
-/bin/rm *
-done
-
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_sim01
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_sim01	(revision 3)
+++ 	(revision )
@@ -1,49 +1,0 @@
-#QSUB -r lmdz32_sim01 -eo -o /workdir/rech/ces/rces111/out.lmdz32_sim01
-#QSUB -lM 290Mb -ls 8Mb -lP 0 -lT 09:00:00 -lt 03:00:00
-exp=sim01
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def run.def
-
-mkdir saves
-maiaget lmdz32/${exp}/gcm.e saves/gcm.e; chmod u+x saves/gcm.e
-maiaget lmdz32/divers/limit.dat saves/limit.dat
-maiaget lmdz32/divers/limit.dic saves/limit.dic
-mv run.def saves/run.def
-maiaget lmdz32/divers/start.dat saves/start.dat
-maiaget lmdz32/divers/start.dic saves/start.dic
-maiaget lmdz32/divers/startphy.dat saves/startphy.dat
-maiaget lmdz32/divers/startphy.dic saves/startphy.dic
-
-for m in 1 2 3
-do
-cp saves/gcm.e gcm.e
-cp saves/limit.dat limit7995.dat
-cp saves/limit.dic limit7995.dic
-cp saves/run.def run.def
-mv saves/start.dat .
-mv saves/start.dic .
-mv saves/startphy.dat .
-mv saves/startphy.dic .
-mp1=`expr $m + 1`
-gcm.e || exit 1
-maiaput histphy.dat lmdz32/${exp}/histphy.dat.$m
-maiaput histphy.dic lmdz32/${exp}/histphy.dic.$m
-maiaput relief.gdat lmdz32/${exp}/relief.gdat
-maiaput relief.ctl lmdz32/${exp}/relief.ctl
-maiaput restartphy.dat lmdz32/${exp}/startphy.dat.${mp1}
-maiaput restartphy.dic lmdz32/${exp}/startphy.dic.${mp1}
-maiaput restart.dat lmdz32/${exp}/start.dat.${mp1}
-maiaput restart.dic lmdz32/${exp}/start.dic.${mp1}
-mv restartphy.dat saves/startphy.dat
-mv restartphy.dic saves/startphy.dic
-mv restart.dat saves/start.dat
-mv restart.dic saves/start.dic
-ls -lt
-/bin/rm *
-done
-
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_sim02
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_sim02	(revision 3)
+++ 	(revision )
@@ -1,49 +1,0 @@
-#QSUB -r lmdz32_sim02 -eo -o /workdir/rech/ces/rces111/out.lmdz32_sim02
-#QSUB -lM 290Mb -ls 8Mb -lP 0 -lT 09:00:00 -lt 03:00:00
-exp=sim02
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def run.def
-
-mkdir saves
-maiaget lmdz32/${exp}/gcm.e saves/gcm.e; chmod u+x saves/gcm.e
-maiaget lmdz32/divers/limit.dat saves/limit.dat
-maiaget lmdz32/divers/limit.dic saves/limit.dic
-mv run.def saves/run.def
-maiaget lmdz32/divers/start.dat saves/start.dat
-maiaget lmdz32/divers/start.dic saves/start.dic
-maiaget lmdz32/divers/startphy.dat saves/startphy.dat
-maiaget lmdz32/divers/startphy.dic saves/startphy.dic
-
-for m in 1 2 3
-do
-cp saves/gcm.e gcm.e
-cp saves/limit.dat limit7995.dat
-cp saves/limit.dic limit7995.dic
-cp saves/run.def run.def
-mv saves/start.dat .
-mv saves/start.dic .
-mv saves/startphy.dat .
-mv saves/startphy.dic .
-mp1=`expr $m + 1`
-gcm.e || exit 1
-maiaput histphy.dat lmdz32/${exp}/histphy.dat.$m
-maiaput histphy.dic lmdz32/${exp}/histphy.dic.$m
-maiaput relief.gdat lmdz32/${exp}/relief.gdat
-maiaput relief.ctl lmdz32/${exp}/relief.ctl
-maiaput restartphy.dat lmdz32/${exp}/startphy.dat.${mp1}
-maiaput restartphy.dic lmdz32/${exp}/startphy.dic.${mp1}
-maiaput restart.dat lmdz32/${exp}/start.dat.${mp1}
-maiaput restart.dic lmdz32/${exp}/start.dic.${mp1}
-mv restartphy.dat saves/startphy.dat
-mv restartphy.dic saves/startphy.dic
-mv restart.dat saves/start.dat
-mv restart.dic saves/start.dic
-ls -lt
-/bin/rm *
-done
-
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_sim03
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_sim03	(revision 3)
+++ 	(revision )
@@ -1,49 +1,0 @@
-#QSUB -r lmdz32_sim03 -eo -o /workdir/rech/ces/rces111/out.lmdz32_sim03
-#QSUB -lM 290Mb -ls 8Mb -lP 0 -lT 09:00:00 -lt 03:00:00
-exp=sim03
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def run.def
-
-mkdir saves
-maiaget lmdz32/${exp}/gcm.e saves/gcm.e; chmod u+x saves/gcm.e
-maiaget lmdz32/divers/limit.dat saves/limit.dat
-maiaget lmdz32/divers/limit.dic saves/limit.dic
-mv run.def saves/run.def
-maiaget lmdz32/divers/start.dat saves/start.dat
-maiaget lmdz32/divers/start.dic saves/start.dic
-maiaget lmdz32/divers/startphy.dat saves/startphy.dat
-maiaget lmdz32/divers/startphy.dic saves/startphy.dic
-
-for m in 1 2 3
-do
-cp saves/gcm.e gcm.e
-cp saves/limit.dat limit7995.dat
-cp saves/limit.dic limit7995.dic
-cp saves/run.def run.def
-mv saves/start.dat .
-mv saves/start.dic .
-mv saves/startphy.dat .
-mv saves/startphy.dic .
-mp1=`expr $m + 1`
-gcm.e || exit 1
-maiaput histphy.dat lmdz32/${exp}/histphy.dat.$m
-maiaput histphy.dic lmdz32/${exp}/histphy.dic.$m
-maiaput relief.gdat lmdz32/${exp}/relief.gdat
-maiaput relief.ctl lmdz32/${exp}/relief.ctl
-maiaput restartphy.dat lmdz32/${exp}/startphy.dat.${mp1}
-maiaput restartphy.dic lmdz32/${exp}/startphy.dic.${mp1}
-maiaput restart.dat lmdz32/${exp}/start.dat.${mp1}
-maiaput restart.dic lmdz32/${exp}/start.dic.${mp1}
-mv restartphy.dat saves/startphy.dat
-mv restartphy.dic saves/startphy.dic
-mv restart.dat saves/start.dat
-mv restart.dic saves/start.dic
-ls -lt
-/bin/rm *
-done
-
Index: LMDZ.3.3/branches/rel-1-0-patch/script/lancer_sim04
===================================================================
--- LMDZ.3.3/branches/LF/script/lancer_sim04	(revision 3)
+++ 	(revision )
@@ -1,39 +1,0 @@
-#QSUB -r lmdz32_sim04 -eo -o /workdir/rech/ces/rces111/out.lmdz32_sim04
-#QSUB -lM 290Mb -ls 8Mb -lP 0 -lT 09:00:00 -lt 03:00:00
-exp=sim04
-
-set -xv
-
-cd $TMPDIR
-date
-
-cp $HOME/lmdz32/run.def run.def
-
-mkdir saves
-maiaget lmdz32/${exp}/gcm.e saves/gcm.e; chmod u+x saves/gcm.e
-maiaget lmdz32/divers/limit.nc saves/limit.nc
-mv run.def saves/run.def
-maiaget lmdz32/divers/start.nc saves/start.nc
-maiaget lmdz32/divers/startphy.nc saves/startphy.nc
-
-for m in 1 2 3
-do
-cp saves/gcm.e gcm.e
-cp saves/limit.nc limit7995.nc
-cp saves/run.def run.def
-mv saves/start.nc .
-mv saves/startphy.nc .
-mp1=`expr $m + 1`
-gcm.e || exit 1
-maiaput histphy.nc lmdz32/${exp}/histphy.nc.$m
-maiaput histday.nc lmdz32/${exp}/histday.nc.$m
-maiaput relief.gdat lmdz32/${exp}/relief.gdat
-maiaput relief.ctl lmdz32/${exp}/relief.ctl
-maiaput restartphy.nc lmdz32/${exp}/startphy.nc.${mp1}
-maiaput restart.nc lmdz32/${exp}/start.nc.${mp1}
-mv restartphy.nc saves/startphy.nc
-mv restart.nc saves/start.nc
-ls -lt
-/bin/rm *
-done
-
