Index: codes/icosagcm/trunk/src/check_conserve.f90
===================================================================
--- codes/icosagcm/trunk/src/check_conserve.f90	(revision 151)
+++ codes/icosagcm/trunk/src/check_conserve.f90	(revision 160)
@@ -10,6 +10,6 @@
   PUBLIC init_check_conserve, check_conserve 
     REAL(rstd),SAVE:: mtot0,ztot0,etot0,ang0,stot0,rmsv0
-    REAL(rstd),SAVE::rmsdpdt,etot,ang,stot,rmsv
-    REAL(rstd),SAVE:: ztot,mtot
+    REAL(rstd),SAVE:: etot,ang,stot,rmsv
+    REAL(rstd),SAVE:: ztot
 	
      
@@ -34,5 +34,5 @@
   USE caldyn_gcm_mod
   USE exner_mod 
-  USE mpipara
+  USE mpipara, ONLY : is_mpi_root, comm_icosa
   IMPLICIT NONE
     TYPE(t_field),POINTER :: f_ps(:)
@@ -41,10 +41,12 @@
     TYPE(t_field),POINTER :: f_theta_rhodz(:)
     TYPE(t_field),POINTER :: f_phis(:)
-    INTEGER::it 
+    INTEGER::it
+
     REAL(rstd),POINTER :: p(:,:),rhodz(:,:) 
-    INTEGER::ind 
+    INTEGER::ind,ierr
+    REAL(rstd) :: mtot, rmsdpdt
 
     etot=0.0; ang=0.0;stot=0.0;rmsv=0.0 
-    mtot=0.0 ; rmsdpdt=0.0 ; ztot = 0.0 
+    ztot = 0.0 
 
     CALL pression(f_ps,f_p)
@@ -53,30 +55,30 @@
       CALL swap_dimensions(ind)
       CALL swap_geometry(ind)
-        p=f_p(ind) 
-       rhodz=f_rhodz(ind)
+      p=f_p(ind) 
+      rhodz=f_rhodz(ind)
       CALL compute_rhodz(p,rhodz) 
-    END DO 
+    END DO
 
     CALL vorticity(f_ue,f_vort)
-    CALL check_mass_conserve(f_ps,f_dps)
+    CALL check_mass_conserve(f_ps,f_dps,mtot,rmsdpdt)
     CALL check_PV 
     CALL exner(f_ps,f_p,f_pks,f_pk)
     CALL check_EN(f_ue,f_theta_rhodz,f_phis) 
+
+    IF (is_mpi_root) THEN 
        
-     IF ( it == 0  ) Then 
-       ztot0 = ztot
-       mtot0 = mtot
-       etot0 = etot 
-       ang0  = ang 
-       stot0 = stot 
-     END IF 
-
-     rmsv=SQRT(rmsv/mtot) 
-     ztot=ztot/ztot0 ; mtot=mtot/mtot0 
-     etot=etot/etot0 ; ang=ang/ang0 ; stot=stot/stot0 
-     rmsdpdt= daysec*1.e-2*sqrt(rmsdpdt/ncell_glo)  
-
-
-     IF (is_mpi_root) THEN 
+       IF ( it == 0  ) Then 
+          ztot0 = ztot
+          mtot0 = mtot
+          etot0 = etot 
+          ang0  = ang 
+          stot0 = stot 
+       END IF
+
+       rmsv=SQRT(rmsv/mtot) 
+       ztot=ztot/ztot0-1. ; mtot=mtot/mtot0-1. 
+       etot=etot/etot0-1. ; ang=ang/ang0-1. ; stot=stot/stot0-1. 
+       rmsdpdt= daysec*1.e-2*sqrt(rmsdpdt/ncell_glo)  
+       
        OPEN(134,file="checkconsicosa.txt",position='append')
        WRITE(134,4000)mtot,rmsdpdt,etot,ztot,stot,rmsv,ang
@@ -84,15 +86,17 @@
        WRITE(134,*)"=================================================="
        WRITE(*,4000)mtot,rmsdpdt,etot,ztot,stot,rmsv,ang
-
+       
 4000   FORMAT(10x,'masse',4x,'rmsdpdt',7x,'energie',2x,'enstrophie'  &
-     ,2x,'entropie',3x,'rmsv',4x,'mt.ang',/,'GLOB  '                &
-      ,f10.6,e13.6,5f10.3/)     
+            ,2x,'entropie',3x,'rmsv',4x,'mt.ang',/,'GLOB  '                &
+            ,e10.3,e13.6,5e10.3/)     
        close(134) 
-     END IF 
+    END IF
   END SUBROUTINE check_conserve
   
 !---------------------------------------------------------------------
 
-  SUBROUTINE check_mass_conserve(f_ps,f_dps)
+  SUBROUTINE check_mass_conserve(f_ps,f_dps,mtot,rmsdpdt)
+  USE mpi_mod
+  USE mpipara
   USE icosa
   IMPLICIT NONE
@@ -100,6 +104,10 @@
     TYPE(t_field),POINTER :: f_dps(:)
     REAL(rstd),POINTER :: ps(:),dps(:) 
+    REAL(rstd), INTENT(OUT) :: mtot, rmsdpdt
+
     INTEGER :: ind,i,j,ij  
-
+    REAL :: mloc, rmsloc
+
+    mloc=0.0; rmsloc=0.0
     DO ind=1,ndomain
       CALL swap_dimensions(ind)
@@ -111,10 +119,14 @@
           ij=(j-1)*iim+i
           IF (domain(ind)%own(i,j)) THEN
-            mtot=mtot+ps(ij)*Ai(ij)
-	       rmsdpdt=rmsdpdt+dps(ij)*dps(ij)
+             mloc=mloc+ps(ij)*Ai(ij)
+             rmsloc=rmsloc+dps(ij)*dps(ij)
 	  ENDIF
         ENDDO
       ENDDO
     ENDDO
+
+    CALL MPI_REDUCE(mloc, mtot, 1, MPI_REAL8, MPI_SUM, 0, comm_icosa, ierr)
+    CALL MPI_REDUCE(rmsloc, rmsdpdt, 1, MPI_REAL8, MPI_SUM, 0, comm_icosa, ierr)
+
   END SUBROUTINE check_mass_conserve
 
