Index: trunk/LMDZ.MARS/libf/dyn3d/defrun_new.F
===================================================================
--- trunk/LMDZ.MARS/libf/dyn3d/defrun_new.F	(revision 563)
+++ trunk/LMDZ.MARS/libf/dyn3d/defrun_new.F	(revision 575)
@@ -457,6 +457,16 @@
 
         WRITE(tapeout,*) ""
-        WRITE(tapeout,*) "Sponge:  mode0(u=v=0), mode1(u=umoy,v=0), ",
-     & "mode2(u=umoy,v=vmoy)"
+        WRITE(tapeout,*) "Sponge: number of layers over which",
+     &                    " sponge extends"
+        nsponge=3 ! default value
+        call getin("nsponge",nsponge)
+        WRITE(tapeout,*)" nsponge = ",nsponge
+
+        WRITE(tapeout,*)""
+        WRITE(tapeout,*)"Sponge mode: (forcing is towards ..."
+        WRITE(tapeout,*)"  over upper nsponge layers)"
+        WRITE(tapeout,*)"  0: (h=hmean,u=v=0)"
+        WRITE(tapeout,*)"  1: (h=hmean,u=umean,v=0)"
+        WRITE(tapeout,*)"  2: (h=hmean,u=umean,v=vmean)"
         mode_sponge=2 ! default value
         call getin("mode_sponge",mode_sponge)
@@ -464,12 +474,8 @@
 
         WRITE(tapeout,*) ""
-        WRITE(tapeout,*) "Sponge:  hauteur de sponge (km)"
-        hsponge=90.0 ! default value
-        call getin("hsponge",hsponge)
-        WRITE(tapeout,*)" hsponge = ",hsponge
-
-        WRITE(tapeout,*) ""
-        WRITE(tapeout,*) "Sponge:  tetasponge (secondes)"
-        tetasponge=50000.0
+        WRITE(tapeout,*) "Sponge: characteristice time scale tetasponge"
+        WRITE(tapeout,*) "(seconds) at topmost layer (time scale then "
+        WRITE(tapeout,*) " doubles with decreasing layer index)."
+        tetasponge=30000.0
         call getin("tetasponge",tetasponge)
         WRITE(tapeout,*)" tetasponge = ",tetasponge
Index: trunk/LMDZ.MARS/libf/dyn3d/sponge.F
===================================================================
--- trunk/LMDZ.MARS/libf/dyn3d/sponge.F	(revision 563)
+++ trunk/LMDZ.MARS/libf/dyn3d/sponge.F	(revision 575)
@@ -1,3 +1,14 @@
       subroutine sponge(ucov,vcov,h,pext,dt,mode)
+
+! Sponge routine: Quench ucov, vcov and potential temperature near the
+!                 top of the model
+! Depending on 'mode' relaxation of variables is towards:
+! mode = 0 : h -> h_mean , ucov -> 0 , vcov -> 0
+! mode = 1 : h -> h_mean , ucov -> ucov_mean , vcov -> 0
+! mode >= 2 : h -> h_mean , ucov -> ucov_mean , vcov -> vcov_mean
+! Number of layer over which sponge is applied is 'nsponge' (read from def file)
+! Time scale for quenching at top level is given by 'tetasponge' (read from
+! def file) and doubles as level indexes decrease.
+
       implicit none
 #include "dimensions.h"
@@ -7,71 +18,59 @@
 #include "comgeom2.h"
 #include "sponge.h"
-      real ucov(iip1,jjp1,llm),vcov(iip1,jjm,llm)
-      real h(iip1,jjp1,llm),pext(iip1,jjp1)
-      real dt
-      real sig_s(llm) !sigma au milieu des couches
-      save sig_s
+
+! Arguments:
+!------------
+      real,intent(inout) :: ucov(iip1,jjp1,llm) ! covariant zonal wind
+      real,intent(inout) :: vcov(iip1,jjm,llm) ! covariant meridional wind
+      real,intent(inout) :: h(iip1,jjp1,llm) ! potential temperature
+      real,intent(in) :: pext(iip1,jjp1) ! extensive pressure
+      real,intent(in) :: dt   ! time step
+      integer,intent(in) :: mode  ! sponge mode
 
 c   Local:
 c   ------
 
+      real,save :: sig_s(llm) !sigma au milieu des couches
       REAL vm,um,hm,ptot(jjp1)
-      real cst(llm)
-      integer mode
+      real,save :: cst(llm)
 
-      INTEGER l,i,j,l0
+      INTEGER l,i,j
+      integer,save :: l0 ! layer down to which sponge is applied
 
       real ssum
 
       real echelle,zkm
-      logical firstcall
-      save firstcall,cst,l0
-      data firstcall/.true./
+      logical,save :: firstcall=.true.
+
+
 
       if (firstcall) then
-       do l=1,llm
+
+       ! build approximative sigma levels at midlayer
+        do l=1,llm
           sig_s(l)=((ap(l)+ap(l+1))/preff+bp(l)+bp(l+1))/2.
-       enddo
+        enddo
 
-       IF (mode.eq.3) then
-         l0=llm-2
-         echelle=10.
+        l0=llm-nsponge+1
  
-         PRINT*
-         print*,'sponge mode',mode
-         print*,'hsponge',hsponge
-         print*,'tetasponge n intervient pas'
-         print*,'Constantes de dissipations fixees comme les anglais'
-         print*,'Coeffs pour la couche en eponge'
-         print*,'Z (km)  tau'
-         cst(llm)=dt/(0.5*88775)
-         cst(llm-1)=dt/(88775)
-         cst(l0)=dt/(2*88775)
-         do l=l0,llm
-            zkm=-echelle*log(sig_s(l))
-            print*,zkm,dt/cst(l),cst(l)
-         enddo
-         firstcall=.false.
-         PRINT*
-       ELSE
-         l0=1
-         echelle=10.
- 
-         PRINT*
-         print*,'sponge mode',mode
-         print*,'hsponge tetasponge ',hsponge,tetasponge
-         print*,'Coeffs pour la couche en eponge'
-         print*,'Z (km)  tau'
-         do l=1,llm
-            zkm=-echelle*log(sig_s(l))
-            cst(l)=.5*(1.+tanh((zkm-hsponge)/echelle))
-            cst(l)= max(tetasponge*1.e-15,cst(l))
-            print*,zkm,1./cst(l)*tetasponge,cst(l)*dt/tetasponge
-            cst(l)=cst(l)*dt/tetasponge
-         enddo
-         firstcall=.false.
-         PRINT*
-       ENDIF
-      endif
+        PRINT*
+        print*,'sponge mode',mode
+        print*,'nsponge tetasponge ',nsponge,tetasponge
+        print*,'Coeffs for the sponge layer'
+        print*,'Z (km)     tau      cst'
+        do l=llm,l0,-1
+          ! double time scale with every level, starting from the top
+          cst(l)=dt/(tetasponge*2**(llm-l))
+        enddo
+
+        echelle=10.
+        do l=l0,llm
+           zkm=-echelle*log(sig_s(l))
+           print*,zkm,dt/cst(l),cst(l)
+        enddo
+        PRINT*
+
+        firstcall=.false.
+      endif ! of if (firstcall)
 
 c-----------------------------------------------------------------------
@@ -83,5 +82,5 @@
       enddo
  
-c   temperature potentielle
+c   potential temperature
       do l=l0,llm
          do j=1,jjp1
@@ -98,5 +97,5 @@
       enddo
 
-c   vent zonal
+c   zonal wind
       do l=l0,llm
          do j=2,jjm
@@ -116,5 +115,5 @@
       enddo
 
-c  vent meridien
+c  meridional wind
       do l=l0,llm
          do j=1,jjm
@@ -134,4 +133,3 @@
       enddo
 
-      RETURN
       end
Index: trunk/LMDZ.MARS/libf/dyn3d/sponge.h
===================================================================
--- trunk/LMDZ.MARS/libf/dyn3d/sponge.h	(revision 563)
+++ trunk/LMDZ.MARS/libf/dyn3d/sponge.h	(revision 575)
@@ -2,8 +2,11 @@
 c INCLUDE 'sponge.h'
 
-      COMMON/com_sponge/callsponge,mode_sponge,hsponge,tetasponge
+      COMMON/com_sponge_l/callsponge
+      common/com_sponge_i/mode_sponge,nsponge
+      common/com_sponge_r/tetasponge
 
-      LOGICAL   callsponge
-      INTEGER   mode_sponge
-      REAL   hsponge,tetasponge
+      LOGICAL   callsponge  ! do we use a sponge on upper layers
+      INTEGER   mode_sponge ! sponge mode
+      INTEGER nsponge ! number of sponge layers 
+      REAL  tetasponge  ! sponge time scale (s) at topmost layer
 c-----------------------------------------------------------------------
