Index: codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 326)
+++ codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 327)
@@ -40,4 +40,5 @@
   USE write_field
   USE theta2theta_rhodz_mod
+  USE sponge_mod
   IMPLICIT NONE
 
@@ -111,4 +112,6 @@
            f_psm2 => f_phis
         END IF
+      CASE ('none')
+        nb_stage=0
 
     CASE default
@@ -120,10 +123,9 @@
     CALL init_theta2theta_rhodz
     CALL init_dissip
+    CALL init_sponge
     CALL init_caldyn
     CALL init_guided
     CALL init_advect_tracer
     CALL init_check_conserve
-    CALL init_physics
-    
 
     CALL etat0(f_ps,f_mass,f_phis,f_theta_rhodz,f_u, f_q)
@@ -144,4 +146,5 @@
   USE icosa
   USE dissip_gcm_mod
+  USE sponge_mod
   USE disvert_mod
   USE caldyn_mod
@@ -176,10 +179,8 @@
     INTEGER :: rate_clock
     INTEGER :: l
+    LOGICAL,SAVE :: first_physic=.TRUE.
+!$OMP THREADPRIVATE(first_physic)    
     
-    
-!    CALL write_etat0(f_ps, f_phis,f_theta_rhodz,f_u,f_q) 
-!    CALL read_start(f_ps,f_mass,f_phis,f_theta_rhodz,f_u,f_q) 
-!    CALL write_restart(f_ps,f_mass,f_phis,f_theta_rhodz,f_u,f_q) 
-    
+   
     CALL switch_omp_distrib_level
     CALL caldyn_BC(f_phis, f_wflux) ! set constant values in first/last interfaces
@@ -228,9 +229,4 @@
       CALL wait_message(req_q0) 
 
-!      CALL wait_message(req_ps0)
-!      CALL wait_message(req_mass0)
-!      CALL wait_message(req_theta_rhodz0) 
-!      CALL wait_message(req_u0)
-!      CALL wait_message(req_q0) 
     ENDIF
 
@@ -264,6 +260,4 @@
 
     IF (MOD(it,itau_dissip)==0) THEN
-!         CALL send_message(f_ps,req_ps)
-!         CALL wait_message(req_ps)  
        
        IF(caldyn_eta==eta_mass) THEN
@@ -278,11 +272,12 @@
           END DO
        ENDIF
-!       CALL send_message(f_mass,req_mass)
-!       CALL wait_message(req_mass)  
+
        CALL dissip(f_u,f_du,f_mass,f_phis, f_theta_rhodz,f_dtheta_rhodz)
 
-!       CALL send_message(f_mass,req_mass)
-!       CALL wait_message(req_mass)  
        CALL euler_scheme(.FALSE.)  ! update only u, theta
+       IF (iflag_sponge > 0) THEN
+         CALL sponge(f_u,f_du,f_theta_rhodz,f_dtheta_rhodz)
+         CALL euler_scheme(.FALSE.)  ! update only u, theta
+       ENDIF
     END IF
 
@@ -308,8 +303,16 @@
     END IF
 
-    CALL physics(it,f_phis, f_ps, f_theta_rhodz, f_u,  f_q)
 
     IF (MOD(it,itau_check_conserv)==0) THEN
-      CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it)  
+      CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it) 
+    ENDIF
+     
+    IF (MOD(it,itau_physics)==0) THEN
+      CALL physics(it,f_phis, f_ps, f_theta_rhodz, f_u, f_wflux, f_q)
+
+!$OMP MASTER
+   IF (first_physic) CALL SYSTEM_CLOCK(start_clock)
+!$OMP END MASTER   
+      first_physic=.FALSE.
     ENDIF
     
@@ -354,5 +357,5 @@
           ELSE ! update mass
              mass=f_mass(ind) ; dmass=f_dmass(ind) ;              
-             DO l=1,llm
+             DO l=ll_begin,ll_end
 !$SIMD
                 DO ij=ij_begin,ij_end
@@ -606,34 +609,3 @@
   END SUBROUTINE accumulate_fluxes
   
-!  FUNCTION maxval_i(p)
-!    USE icosa
-!    IMPLICIT NONE
-!    REAL(rstd), DIMENSION(iim*jjm) :: p
-!    REAL(rstd) :: maxval_i
-!    INTEGER :: j, ij
-!    
-!    maxval_i=p((jj_begin-1)*iim+ii_begin)
-!    
-!    DO j=jj_begin-1,jj_end+1
-!       ij=(j-1)*iim
-!       maxval_i = MAX(maxval_i, MAXVAL(p(ij+ii_begin:ij+ii_end)))
-!    END DO
-!  END FUNCTION maxval_i
-
-!  FUNCTION maxval_ik(p)
-!    USE icosa
-!    IMPLICIT NONE
-!    REAL(rstd) :: p(iim*jjm, llm)
-!    REAL(rstd) :: maxval_ik(llm)
-!    INTEGER :: l,j, ij
-!    
-!    DO l=1,llm
-!       maxval_ik(l)=p((jj_begin-1)*iim+ii_begin,l)
-!       DO j=jj_begin-1,jj_end+1
-!          ij=(j-1)*iim
-!          maxval_ik(l) = MAX(maxval_ik(l), MAXVAL(p(ij+ii_begin:ij+ii_end,l)))
-!       END DO
-!    END DO
-!  END FUNCTION maxval_ik
-
 END MODULE timeloop_gcm_mod
