Index: dynamico_lmdz/simple_physics/phyparam/physics/astronomy.F90
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/astronomy.F90	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/astronomy.F90	(revision 4210)
@@ -14,32 +14,8 @@
  
   SUBROUTINE solarlong(pday,psollong)
-
-!=======================================================================
-!      Calcul de la distance soleil-planete et de la declinaison
-!   en fonction du jour de l'annee.
-!
-!   Methode:
-!   --------
-!      Calcul complet de l'ellipse
-!
-!   Input:
-!   ------
-!   pday          jour de l'annee (le jour 0 correspondant a l'equinoxe)
-!   lwrite        clef logique pour sorties de controle
-!
-!   Output:
-!   -------
-!   pdist_sol     distance entre le soleil et la planete
-!                 ( en unite astronomique pour utiliser la constante 
-!                  solaire terrestre 1370 Wm-2 )
-!   pdecli        declinaison ( en radians )
-!
-!=======================================================================
-
     USE planet
-    REAL, INTENT(IN) :: pday
-    REAL, INTENT(OUT) :: psollong
+    REAL, INTENT(IN) :: pday               ! jour de l'annee (le jour 0 correspondant a l'equinoxe)
+    REAL, INTENT(OUT) :: psollong          ! solar longitude
     LOGICAL, PARAMETER ::  lwrite=.TRUE.
-    REAL pdist_sol, pdecli
 
 ! Local:
@@ -82,8 +58,7 @@
     
     IF (lwrite) THEN
-       WRITELOG(*,*) 'jour de l"annee   :',pday
-       WRITELOG(*,*) 'distance au soleil (en unite astronomique) :',pdist_sol
-       WRITELOG(*,*) 'declinaison (en degres) :',pdecli*180./pi
-       LOG_INFO('solarlong')
+       WRITELOG(*,*) 'day of the year  :',pday
+       WRITELOG(*,*) 'solar longitude : ',psollong
+       LOG_DBG('solarlong')
     ENDIF
     
Index: dynamico_lmdz/simple_physics/phyparam/physics/logging.F90
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/logging.F90	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/logging.F90	(revision 4210)
@@ -25,17 +25,19 @@
 
   ! This module provides a default implementation of flush_plugin but the top-level driver is welcome to override it.  
-  PROCEDURE(plugin), POINTER :: flush_plugin => default_flush
+  PROCEDURE(plugin), POINTER :: flush_plugin => default_flush_plugin
 
   ! The top-level driver MUST provide an implementation for log_gridpoint_plugin
   PROCEDURE(plugin_log_gridpoint), POINTER :: log_gridpoint_plugin => NULL()
 
-  INTEGER, PARAMETER :: bufsize=10000
-  CHARACTER(bufsize) :: logging_buf(100)
+  INTEGER, PARAMETER :: linesize=10000, logging_bufsize=100
+  CHARACTER(linesize) :: logging_buf(logging_bufsize)
 
   INTEGER :: logging_lineno=0
 
-  INTEGER, PARAMETER, PUBLIC :: log_level_fatal=0, log_level_error=1, log_level_warn=2, log_level_info=3, log_level_dbg=4
+  ! messages with a log level higher > max_log_level are not printed 
+  INTEGER, PARAMETER, PUBLIC :: log_level_fatal=1, log_level_error=2, log_level_warn=3, log_level_info=4, log_level_dbg=5
+  INTEGER, PUBLIC :: max_log_level = log_level_info
 
-  PUBLIC :: logging_buf, logging_lineno, flush_log, log_gridpoint, &
+  PUBLIC :: logging_buf, logging_bufsize, logging_lineno, flush_log, log_gridpoint, &
        flush_plugin, log_gridpoint_plugin
 
@@ -45,16 +47,19 @@
     INTEGER, INTENT(IN) :: lev
     CHARACTER(*), INTENT(IN) :: tag
-    CALL flush_plugin(lev, TRIM(tag), logging_buf(1:logging_lineno))
+    IF(logging_lineno>0 .AND. lev<=max_log_level) CALL flush_plugin(lev, TRIM(tag), logging_buf(1:logging_lineno))
     logging_lineno=0
   END SUBROUTINE flush_log
 
-  SUBROUTINE default_flush(lev, tag, buf)
+  SUBROUTINE default_flush_plugin(lev, tag, buf)
     INTEGER, INTENT(IN) :: lev
     CHARACTER(*), INTENT(IN) :: tag, buf(:)
+    CHARACTER(3), DIMENSION(log_level_dbg) :: dbtag = (/ 'FAT', 'ERR', 'WRN', 'INF', 'DBG' /)
+    CHARACTER(100) :: prefix
     INTEGER :: i
+    WRITE(prefix,*) '[', dbtag(lev), ' ', tag, ']'
     DO i=1, SIZE(buf)
-       PRINT *, '[INFO ',tag,']', TRIM(buf(i))
+       PRINT *, TRIM(prefix), TRIM(buf(i))
     END DO
-  END SUBROUTINE default_flush
+  END SUBROUTINE default_flush_plugin
 
   SUBROUTINE log_gridpoint(index)
Index: dynamico_lmdz/simple_physics/phyparam/physics/radiative_sw.F90
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/radiative_sw.F90	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/radiative_sw.F90	(revision 4210)
@@ -1,3 +1,6 @@
 MODULE radiative_sw
+
+#include "use_logging.h"
+
   IMPLICIT NONE
   SAVE
@@ -135,11 +138,11 @@
     IF (lwrite) THEN
        igout=ncount/2+1
-       PRINT*
-       PRINT*,'Diagnostique des transmission dans le spectre solaire'
-       PRINT*,'zfract, zmu, zalb'
-       PRINT*,zfract(igout), zmu(igout), zalb(igout)
-       PRINT*,'Pression, quantite d abs, transmission'
+       WRITELOG(*,*) 
+       WRITELOG(*,*) 'Diagnostique des transmission dans le spectre solaire'
+       WRITELOG(*,*) 'zfract, zmu, zalb'
+       WRITELOG(*,*) zfract(igout), zmu(igout), zalb(igout)
+       WRITELOG(*,*) 'Pression, quantite d abs, transmission'
        DO l=1,nlayer+1
-          PRINT*,zplev(igout,l),zu(igout,l),ztrdir(igout,l)
+          WRITELOG(*,*) zplev(igout,l),zu(igout,l),ztrdir(igout,l)
        ENDDO
     ENDIF
@@ -157,9 +160,9 @@
     ENDDO
     IF (lwrite) THEN
-       PRINT*
-       PRINT*,'Diagnostique des taux de chauffage solaires:'
-       PRINT*,' 1 taux de chauffage lie au ray. solaire  direct'
+       WRITELOG(*,*) 
+       WRITELOG(*,*) 'Diagnostique des taux de chauffage solaires:'
+       WRITELOG(*,*) ' 1 taux de chauffage lie au ray. solaire  direct'
        DO l=1,nlayer
-          PRINT*,zdtsw(igout,l)
+          WRITELOG(*,*) zdtsw(igout,l)
        ENDDO
     ENDIF
@@ -176,8 +179,8 @@
     ENDDO
     IF (lwrite) THEN
-       PRINT*
-       PRINT*,'Diagnostique des taux de chauffage solaires:'
-       PRINT*,' 2 flux solaire net incident sur le sol'
-       PRINT*,zflux(igout)
+       WRITELOG(*,*) 
+       WRITELOG(*,*) 'Diagnostique des taux de chauffage solaires:'
+       WRITELOG(*,*) ' 2 flux solaire net incident sur le sol'
+       WRITELOG(*,*) zflux(igout)
     ENDIF
     
@@ -194,10 +197,10 @@
     
     IF (lwrite) THEN
-       PRINT*
-       PRINT*,'Diagnostique des taux de chauffage solaires'
-       PRINT*,' 3 transmission avec les sol'
-       PRINT*,'niveau     transmission'
+       WRITELOG(*,*) 
+       WRITELOG(*,*) 'Diagnostique des taux de chauffage solaires'
+       WRITELOG(*,*) ' 3 transmission avec les sol'
+       WRITELOG(*,*) 'niveau     transmission'
        DO l=1,nlevel
-          PRINT*,l,ztrref(igout,l)
+          WRITELOG(*,*) l,ztrref(igout,l)
        ENDDO
     ENDIF
@@ -220,9 +223,9 @@
     
     IF (lwrite) THEN
-       PRINT*
-       PRINT*,'Diagnostique des taux de chauffage solaires:'
-       PRINT*,' 3 taux de chauffage total'
+       WRITELOG(*,*) 
+       WRITELOG(*,*) 'Diagnostique des taux de chauffage solaires:'
+       WRITELOG(*,*) ' 3 taux de chauffage total'
        DO l=1,nlayer
-          PRINT*,zdtsw(igout,l)
+          WRITELOG(*,*) zdtsw(igout,l)
        ENDDO
     ENDIF
@@ -236,5 +239,5 @@
        ENDDO
     ELSE
-       print*,'NOT DIURNE'
+       WRITELOG(*,*) 'NOT DIURNE'
        fsrfvis(:)=zflux(:)
        dtsw(:,:)=zdtsw(:,:)
@@ -247,5 +250,5 @@
     !        call dump2d(iim,jjm-1,albedo(2),'albedo     ')
     !        call dump2d(iim,jjm-1,ztrdir(2,1),'ztrdir     ')
-    
+    LOG_INFO('rad_sw')
     
   END SUBROUTINE sw
Index: dynamico_lmdz/simple_physics/phyparam/physics/solar.F90
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/solar.F90	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/solar.F90	(revision 4210)
@@ -1,5 +1,7 @@
 MODULE solar
+
+#include "use_logging.h"
+
   IMPLICIT NONE
-
   PRIVATE
 
@@ -143,5 +145,7 @@
     !                                                                       
     !     incl=R_incl * pi_local / 180.                                     
-    print*,'Obliquite =' ,obliquit 
+    WRITELOG(*,*) 'Obliquite =' ,obliquit
+    LOG_INFO('solar')
+
     incl=obliquit * pi_local / 180. 
     !                                                                       
@@ -303,9 +307,7 @@
     !-----------------------------------------------------------------------
     
-!    print*,'npts,pdeclin',npts,pdeclin
     z = pdeclin
     cz = cos (z)
     sz = sin (z)
-!    print*,'cz,sz',cz,sz
     
     DO j = 1, npts
Index: dynamico_lmdz/simple_physics/phyparam/physics/surface.F90
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/surface.F90	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/surface.F90	(revision 4210)
@@ -1,3 +1,6 @@
 MODULE surface
+
+#include "use_logging.h"
+
   IMPLICIT NONE
   PRIVATE
@@ -34,5 +37,6 @@
     !   --------------------------------------------------------            
     
-    print*,'nsoil,ngrid,firstcall=',nsoil,ngrid, .TRUE.
+    WRITELOG(*,*) 'nsoil,ngrid,firstcall=',nsoil,ngrid, .TRUE.
+
     ALLOCATE(dz1(nsoil),dz2(nsoil)) 
     ALLOCATE(zc(ngrid,nsoil),zd(ngrid,nsoil)) 
@@ -55,13 +59,14 @@
     ENDDO
     lambda=fz(.5)*dz1(1) 
-    PRINT*,'full layers, intermediate layers (secoonds)' 
+    WRITELOG(*,*) 'full layers, intermediate layers (secoonds)' 
     DO jk=1,nsoil 
        rk=jk 
        rk1=jk+.5 
        rk2=jk-.5 
-       PRINT*,fz(rk1)*fz(rk2)*pi,        &
-            &      fz(rk)*fz(rk)*pi                                          
-    ENDDO
-    
+       WRITELOG(*,*) fz(rk1)*fz(rk2)*pi,        &
+            &        fz(rk)*fz(rk)*pi                                          
+    ENDDO
+    
+    LOG_INFO('init_soil')
   END SUBROUTINE init_soil
   
@@ -132,5 +137,4 @@
     REAL zdz2(nsoil),z1(ngrid) 
         
-    print*,'firstcall soil ',firstcall 
     IF (firstcall) THEN 
        CALL init_soil(ngrid, nsoil)
Index: dynamico_lmdz/simple_physics/phyparam/physics/turbulence.F90
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/turbulence.F90	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/turbulence.F90	(revision 4210)
@@ -137,8 +137,4 @@
           ENDIF
           pkh(ig,il)=pkv(ig,il)
-          !           IF(ig.EQ.ngrid/2+1) PRINT*,il,lmix,pkv(ig,il),
-          !    s      zdu,zdv,zdz,zdvodz2,ph(ig,il)+ph(ig,il-1),
-          !    s      lmix*lmix*zdvodz2*(1-zri/.4),emin_turb,zri,ph(ig,il)-ph(ig,il-1),
-          !    s      ph(ig,il),ph(ig,il-1)
        ENDDO
     ENDDO
@@ -290,13 +286,12 @@
     ENDDO
     
-    IF(lwrite) THEN
-       
+    IF(lwrite) THEN       
        WRITELOG(*,*) 'Diagnostique diffusion verticale'
        WRITELOG(*,*) 'LMIXMIN',lmixmin
-       PRINT*,'coefficients Cd pour v et h'
-       PRINT*,zcdv(ngrid/2+1),zcdh(ngrid/2+1)
-       PRINT*,'coefficients K pour v et h'
+       WRITELOG(*,*) 'coefficients Cd pour v et h'
+       WRITELOG(*,*) zcdv(ngrid/2+1),zcdh(ngrid/2+1)
+       WRITELOG(*,*) ,'coefficients K pour v et h'
        DO ilev=1,nlay
-          PRINT*,zkv(ngrid/2+1,ilev),zkh(ngrid/2+1,ilev)
+          WRITELOG(*,*) zkv(ngrid/2+1,ilev),zkh(ngrid/2+1,ilev)
        ENDDO
        LOG_DBG('vdif')
@@ -433,11 +428,12 @@
     
     IF(lwrite) THEN
-       PRINT*
-       PRINT*,'Diagnostique de la diffusion verticale'
-       PRINT*,'h avant et apres diffusion verticale'
-       PRINT*,ptsrf(ngrid/2+1),ztsrf2(ngrid/2+1)
+       WRITELOG(*,*) 
+       WRITELOG(*,*) ,'Diagnostique de la diffusion verticale'
+       WRITELOG(*,*) ,'h avant et apres diffusion verticale'
+       WRITELOG(*,*) ,ptsrf(ngrid/2+1),ztsrf2(ngrid/2+1)
        DO  ilev=1,nlay
-          PRINT*,ph(ngrid/2+1,ilev),zh(ngrid/2+1,ilev)
-       ENDDO
+          WRITELOG(*,*) ph(ngrid/2+1,ilev),zh(ngrid/2+1,ilev)
+       ENDDO
+       LOG_DBG('vdif')
     END IF
 
Index: dynamico_lmdz/simple_physics/phyparam/physics/use_logging.h
===================================================================
--- dynamico_lmdz/simple_physics/phyparam/physics/use_logging.h	(revision 4209)
+++ dynamico_lmdz/simple_physics/phyparam/physics/use_logging.h	(revision 4210)
@@ -1,4 +1,4 @@
    USE logging
-#define WRITELOG(junk, fmt) logging_lineno = logging_lineno+1 ; WRITE(logging_buf(logging_lineno), fmt)
+#define WRITELOG(junk, fmt) logging_lineno = MIN(logging_bufsize, logging_lineno+1) ; WRITE(logging_buf(logging_lineno), fmt)
 #define LOG_WARN(tag) CALL flush_log(log_level_warn, tag)
 #define LOG_INFO(tag) CALL flush_log(log_level_info, tag)
