Index: LMDZ4/trunk/libf/phylmd/phyetat0.F
===================================================================
--- LMDZ4/trunk/libf/phylmd/phyetat0.F	(revision 766)
+++ LMDZ4/trunk/libf/phylmd/phyetat0.F	(revision 776)
@@ -15,5 +15,7 @@
      .           t_ancien_p,q_ancien_p,ancien_ok_p, rnebcon_p, ratqs_p,
      .           clwcon_p,run_off_lic_0_p)
-      USE dimphy,klon=>klon2,klon2=>klon,zmasq_p=>zmasq
+      USE dimphy
+      USE mod_grid_phy_lmdz
+      USE mod_phys_lmdz_para
       USE iophy
       IMPLICIT none
@@ -33,116 +35,80 @@
       REAL dtime
       INTEGER radpas
+      REAL rlat_p(klon), rlon_p(klon)
       REAL rlat_p(klon2), rlon_p(klon2)
       REAL co2_ppm_etat0
       REAL solaire_etat0
-      REAL tsol_p(klon2,nbsrf)
-      REAL tsoil_p(klon2,nsoilmx,nbsrf)
-      REAL tslab_p(klon2), seaice_p(klon2)
-      REAL qsurf_p(klon2,nbsrf)
-      REAL qsol_p(klon2)
-      REAL snow_p(klon2,nbsrf)
-      REAL albe_p(klon2,nbsrf)
+      REAL tsol_p(klon,nbsrf)
+      REAL tsoil_p(klon,nsoilmx,nbsrf)
+      REAL tslab_p(klon), seaice_p(klon)
+      REAL qsurf_p(klon,nbsrf)
+      REAL qsol_p(klon)
+      REAL snow_p(klon,nbsrf)
+      REAL albe_p(klon,nbsrf)
 cIM BEG alblw
-      REAL alblw_p(klon2,nbsrf)
+      REAL alblw_p(klon,nbsrf)
 cIM END alblw
-      REAL evap_p(klon2,nbsrf)
-      REAL radsol_p(klon2)
-      REAL rain_fall_p(klon2)
-      REAL snow_fall_p(klon2)
-      REAL sollw_p(klon2)
-      real solsw_p(klon2)
-      real fder_p(klon2)
-      REAL frugs_p(klon2,nbsrf)
-      REAL agesno_p(klon2,nbsrf)
-      REAL zmea_p(klon2)
-      REAL zstd_p(klon2)
-      REAL zsig_p(klon2)
-      REAL zgam_p(klon2)
-      REAL zthe_p(klon2)
-      REAL zpic_p(klon2)
-      REAL zval_p(klon2)
-      REAL rugsrel_p(klon2)
-      REAL pctsrf_p(klon2, nbsrf)
-      REAL run_off_lic_0_p(klon2)
+      REAL evap_p(klon,nbsrf)
+      REAL radsol_p(klon)
+      REAL rain_fall_p(klon)
+      REAL snow_fall_p(klon)
+      REAL sollw_p(klon)
+      real solsw_p(klon)
+      real fder_p(klon)
+      REAL frugs_p(klon,nbsrf)
+      REAL agesno_p(klon,nbsrf)
+      REAL zmea_p(klon)
+      REAL zstd_p(klon)
+      REAL zsig_p(klon)
+      REAL zgam_p(klon)
+      REAL zthe_p(klon)
+      REAL zpic_p(klon)
+      REAL zval_p(klon)
+      REAL rugsrel_p(klon)
+      REAL pctsrf_p(klon, nbsrf)
+      REAL run_off_lic_0_p(klon)
       
-      REAL t_ancien_p(klon2,klev), q_ancien_p(klon2,klev)
-      real rnebcon_p(klon2,klev),clwcon_p(klon2,klev)
-      real ratqs_p(klon2,klev)
+      REAL t_ancien_p(klon,klev), q_ancien_p(klon,klev)
+      real rnebcon_p(klon,klev),clwcon_p(klon,klev)
+      real ratqs_p(klon,klev)
       LOGICAL,SAVE ::  ancien_ok
       LOGICAL ::  ancien_ok_p
       
-      REAL zmasq(klon)
-      REAL rlat(klon), rlon(klon)
-      REAL tsol(klon,nbsrf)
-      REAL tsoil(klon,nsoilmx,nbsrf)
+      REAL zmasq_glo(klon_glo)
+      REAL rlat(klon_glo), rlon(klon_glo)
+      REAL tsol(klon_glo,nbsrf)
+      REAL tsoil(klon_glo,nsoilmx,nbsrf)
 cIM "slab" ocean
-      REAL tslab(klon), seaice(klon)
-      REAL qsurf(klon,nbsrf)
-      REAL qsol(klon)
-      REAL snow(klon,nbsrf)
-      REAL albe(klon,nbsrf)
-      REAL alblw(klon,nbsrf)
-      REAL evap(klon,nbsrf)
-      REAL radsol(klon)
-      REAL rain_fall(klon)
-      REAL snow_fall(klon)
-      REAL sollw(klon)
-      real solsw(klon)
-      real fder(klon)
-      REAL frugs(klon,nbsrf)
-      REAL agesno(klon,nbsrf)
-      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 pctsrf(klon, nbsrf)
-      REAL fractint(klon)
-      REAL run_off_lic_0(klon)
-      REAL t_ancien(klon,klev)
-      REAL q_ancien(klon,klev)
-      real rnebcon(klon,klev)
-      real clwcon(klon,klev)
-      real ratqs(klon,klev)
-
-      REAL,ALLOCATABLE,SAVE :: zmasq_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: rlat_mpi(:), rlon_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: tsol_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: tsoil_mpi(:,:,:)
-      REAL,ALLOCATABLE,SAVE :: tslab_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: seaice_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: qsurf_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: qsol_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: snow_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: albe_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: alblw_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: evap_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: radsol_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: rain_fall_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: snow_fall_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: sollw_mpi(:)
-      real,ALLOCATABLE,SAVE :: solsw_mpi(:)
-      real,ALLOCATABLE,SAVE :: fder_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: frugs_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: agesno_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: zmea_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: zstd_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: zsig_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: zgam_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: zthe_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: zpic_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: zval_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: rugsrel_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: pctsrf_mpi(:, :)
-      REAL,ALLOCATABLE,SAVE :: run_off_lic_0_mpi(:)
-      REAL,ALLOCATABLE,SAVE :: t_ancien_mpi(:,:)
-      REAL,ALLOCATABLE,SAVE :: q_ancien_mpi(:,:)
-      real,ALLOCATABLE,SAVE :: rnebcon_mpi(:,:)
-      real,ALLOCATABLE,SAVE :: clwcon_mpi(:,:)
-      real,ALLOCATABLE,SAVE :: ratqs_mpi(:,:)
-           
+      REAL tslab(klon_glo), seaice(klon_glo)
+      REAL qsurf(klon_glo,nbsrf)
+      REAL qsol(klon_glo)
+      REAL snow(klon_glo,nbsrf)
+      REAL albe(klon_glo,nbsrf)
+      REAL alblw(klon_glo,nbsrf)
+      REAL evap(klon_glo,nbsrf)
+      REAL radsol(klon_glo)
+      REAL rain_fall(klon_glo)
+      REAL snow_fall(klon_glo)
+      REAL sollw(klon_glo)
+      real solsw(klon_glo)
+      real fder(klon_glo)
+      REAL frugs(klon_glo,nbsrf)
+      REAL agesno(klon_glo,nbsrf)
+      REAL zmea(klon_glo)
+      REAL zstd(klon_glo)
+      REAL zsig(klon_glo)
+      REAL zgam(klon_glo)
+      REAL zthe(klon_glo)
+      REAL zpic(klon_glo)
+      REAL zval(klon_glo)
+      REAL rugsrel(klon_glo)
+      REAL pctsrf(klon_glo, nbsrf)
+      REAL fractint(klon_glo)
+      REAL run_off_lic_0(klon_glo)
+      REAL t_ancien(klon_glo,klev)
+      REAL q_ancien(klon_glo,klev)
+      real rnebcon(klon_glo,klev)
+      real clwcon(klon_glo,klev)
+      real ratqs(klon_glo,klev)
 
       CHARACTER*6 ocean
@@ -172,10 +138,12 @@
 
 c$OMP MASTER
-      print*,'fichnom ',fichnom
-      ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
-      IF (ierr.NE.NF_NOERR) THEN
-        write(6,*)' Pb d''ouverture du fichier '//fichnom
-        write(6,*)' ierr = ', ierr
-        CALL ABORT
+      IF (is_mpi_root) THEN
+        print*,'fichnom ',fichnom
+        ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
+        IF (ierr.NE.NF_NOERR) THEN
+          write(6,*)' Pb d''ouverture du fichier '//fichnom
+          write(6,*)' ierr = ', ierr
+          CALL ABORT
+        ENDIF
       ENDIF
 c$OMP END MASTER
@@ -184,4 +152,6 @@
 c
 c$OMP MASTER
+      IF (is_mpi_root) THEN
+      
       ierr = NF_INQ_VARID (nid, "controle", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -198,10 +168,9 @@
          CALL abort
       ENDIF
+      ENDIF
+
 c$OMP END MASTER
-c$OMP BARRIER
        
-       DO i = 1, length
-         tab_cntrl( i ) = tab_cntrl_omp( i )
-       ENDDO
+       CALL bcast(tab_cntrl)
        
 c
@@ -281,4 +250,6 @@
 c
 c$OMP MASTER
+      IF (is_mpi_root) THEN
+      
       ierr = NF_INQ_VARID (nid, "latitude", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -321,7 +292,7 @@
       IF (ierr .EQ.  NF_NOERR) THEN
 #ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zmasq)
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, zmasq)
+          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, zmasq_glo)
+#else
+          ierr = NF_GET_VAR_REAL(nid, nvarid, zmasq_glo)
 #endif
           IF (ierr.NE.NF_NOERR) THEN
@@ -348,7 +319,9 @@
       IF (ierr .EQ.  NF_NOERR) THEN
 #ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, pctsrf(1 : klon,is_ter))
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, pctsrf(1 : klon,is_ter))
+          ierr = NF_GET_VAR_DOUBLE(nid, nvarid,        
+     .                             pctsrf(1 : klon_glo,is_ter))
+#else
+          ierr = NF_GET_VAR_REAL(nid, nvarid, 
+     .                           pctsrf(1 : klon_glo,is_ter))
 #endif
           IF (ierr.NE.NF_NOERR) THEN
@@ -367,7 +340,9 @@
       IF (ierr .EQ.  NF_NOERR) THEN
 #ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, pctsrf(1 : klon,is_lic))
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, pctsrf(1 : klon,is_lic))
+          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, 
+     .                             pctsrf(1 : klon_glo,is_lic))
+#else
+          ierr = NF_GET_VAR_REAL(nid, nvarid, 
+     .                           pctsrf(1 : klon_glo,is_lic))
 #endif
           IF (ierr.NE.NF_NOERR) THEN
@@ -385,7 +360,9 @@
       IF (ierr .EQ.  NF_NOERR) THEN
 #ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, pctsrf(1 : klon,is_oce))
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, pctsrf(1 : klon,is_oce))
+          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, 
+     .                             pctsrf(1 : klon_glo,is_oce))
+#else
+          ierr = NF_GET_VAR_REAL(nid, nvarid, 
+     .                           pctsrf(1 : klon_glo,is_oce))
 #endif
           IF (ierr.NE.NF_NOERR) THEN
@@ -404,7 +381,9 @@
       IF (ierr .EQ.  NF_NOERR) THEN
 #ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, pctsrf(1 : klon,is_sic))
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, pctsrf(1 : klon, is_sic))
+          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, 
+     .                             pctsrf(1 : klon_glo,is_sic))
+#else
+          ierr = NF_GET_VAR_REAL(nid, nvarid, 
+     .                           pctsrf(1 : klon_glo, is_sic))
 #endif
           IF (ierr.NE.NF_NOERR) THEN
@@ -420,19 +399,19 @@
 C  Verification de l'adequation entre le masque et les sous-surfaces
 C
-      fractint( 1 : klon) = pctsrf(1 : klon, is_ter) 
-     $    + pctsrf(1 : klon, is_lic)
-      DO i = 1 , klon
-        IF ( abs(fractint(i) - zmasq(i) ) .GT. EPSFRA ) THEN
+      fractint( 1 : klon_glo) = pctsrf(1 : klon_glo, is_ter) 
+     $    + pctsrf(1 : klon_glo, is_lic)
+      DO i = 1 , klon_glo
+        IF ( abs(fractint(i) - zmasq_glo(i) ) .GT. EPSFRA ) THEN
             WRITE(*,*) 'phyetat0: attention fraction terre pas ', 
-     $          'coherente ', i, zmasq(i), pctsrf(i, is_ter)
+     $          'coherente ', i, zmasq_glo(i), pctsrf(i, is_ter)
      $          ,pctsrf(i, is_lic)
         ENDIF 
       END DO 
-      fractint (1 : klon) =  pctsrf(1 : klon, is_oce) 
-     $    + pctsrf(1 : klon, is_sic)
-      DO i = 1 , klon
-        IF ( abs( fractint(i) - (1. - zmasq(i))) .GT. EPSFRA ) THEN
+      fractint (1 : klon_glo) =  pctsrf(1 : klon_glo, is_oce) 
+     $    + pctsrf(1 : klon_glo, is_sic)
+      DO i = 1 , klon_glo
+        IF ( abs( fractint(i) - (1. - zmasq_glo(i))) .GT. EPSFRA ) THEN
             WRITE(*,*) 'phyetat0 attention fraction ocean pas ', 
-     $          'coherente ', i, zmasq(i) , pctsrf(i, is_oce)
+     $          'coherente ', i, zmasq_glo(i) , pctsrf(i, is_oce)
      $          ,pctsrf(i, is_sic)
         ENDIF 
@@ -470,5 +449,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(tsol(i,nsrf),xmin)
               xmax = MAX(tsol(i,nsrf),xmax)
@@ -490,5 +469,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(tsol(i,1),xmin)
             xmax = MAX(tsol(i,1),xmax)
@@ -496,5 +475,5 @@
          PRINT*,'Temperature du sol <TS>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             tsol(i,nsrf) = tsol(i,1)
          ENDDO
@@ -516,5 +495,5 @@
          PRINT*, "phyetat0: Le champ <Tsoil"//str7//"> est absent"
          PRINT*, "          Il prend donc la valeur de surface"
-         DO i=1, klon
+         DO i=1, klon_glo
              tsoil(i,isoil,nsrf)=tsol(i,nsrf)
          ENDDO
@@ -554,5 +533,5 @@
         xmin = 1.0E+20
         xmax = -1.0E+20
-        DO i = 1, klon
+        DO i = 1, klon_glo
           xmin = MIN(tslab(i),xmin)
           xmax = MAX(tslab(i),xmax)
@@ -578,5 +557,5 @@
         xmin = 1.0E+20
         xmax = -1.0E+20
-        DO i = 1, klon
+        DO i = 1, klon_glo
           xmin = MIN(seaice(i),xmin)
           xmax = MAX(seaice(i),xmax)
@@ -617,5 +596,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(qsurf(i,nsrf),xmin)
               xmax = MAX(qsurf(i,nsrf),xmax)
@@ -637,5 +616,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(qsurf(i,1),xmin)
             xmax = MAX(qsurf(i,1),xmax)
@@ -643,5 +622,5 @@
          PRINT*,'Humidite pres du sol <QS>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             qsurf(i,nsrf) = qsurf(i,1)
          ENDDO
@@ -670,5 +649,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
         xmin = MIN(qsol(i),xmin)
         xmax = MAX(qsol(i),xmax)
@@ -704,5 +683,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(snow(i,nsrf),xmin)
               xmax = MAX(snow(i,nsrf),xmax)
@@ -724,5 +703,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(snow(i,1),xmin)
             xmax = MAX(snow(i,1),xmax)
@@ -730,5 +709,5 @@
          PRINT*,'Neige du sol <SNOW>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             snow(i,nsrf) = snow(i,1)
          ENDDO
@@ -764,5 +743,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(albe(i,nsrf),xmin)
               xmax = MAX(albe(i,nsrf),xmax)
@@ -784,5 +763,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(albe(i,1),xmin)
             xmax = MAX(albe(i,1),xmax)
@@ -790,5 +769,5 @@
          PRINT*,'Neige du sol <ALBE>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             albe(i,nsrf) = albe(i,1)
          ENDDO
@@ -805,5 +784,5 @@
          PRINT*, '          Mais je vais prendre ALBE**'
          DO nsrf = 1, nbsrf
-           DO i = 1, klon
+           DO i = 1, klon_glo
              alblw(i,nsrf) = albe(i,nsrf)
            ENDDO
@@ -823,5 +802,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(alblw(i,1),xmin)
             xmax = MAX(alblw(i,1),xmax)
@@ -829,5 +808,5 @@
          PRINT*,'Neige du sol <ALBLW>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             alblw(i,nsrf) = alblw(i,1)
          ENDDO
@@ -863,5 +842,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(evap(i,nsrf),xmin)
               xmax = MAX(evap(i,nsrf),xmax)
@@ -883,5 +862,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(evap(i,1),xmin)
             xmax = MAX(evap(i,1),xmax)
@@ -889,5 +868,5 @@
          PRINT*,'Evap du sol <EVAP>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             evap(i,nsrf) = evap(i,1)
          ENDDO
@@ -913,5 +892,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(rain_fall(i),xmin)
          xmax = MAX(rain_fall(i),xmax)
@@ -937,5 +916,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(snow_fall(i),xmin)
          xmax = MAX(snow_fall(i),xmax)
@@ -963,5 +942,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(solsw(i),xmin)
          xmax = MAX(solsw(i),xmax)
@@ -989,15 +968,16 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(sollw(i),xmin)
          xmax = MAX(sollw(i),xmax)
       ENDDO
       PRINT*,'Rayonnement IF au sol sollw:', xmin, xmax
-
+      
+      ENDIF  ! is_mpi_root
 c$OMP END MASTER
 
 
 c$OMP MASTER
-
+      IF (is_mpi_root) THEN
 c
 c Lecture derive des flux:
@@ -1021,5 +1001,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(fder(i),xmin)
          xmax = MAX(fder(i),xmax)
@@ -1046,5 +1026,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(radsol(i),xmin)
          xmax = MAX(radsol(i),xmax)
@@ -1081,5 +1061,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(frugs(i,nsrf),xmin)
               xmax = MAX(frugs(i,nsrf),xmax)
@@ -1101,5 +1081,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(frugs(i,1),xmin)
             xmax = MAX(frugs(i,1),xmax)
@@ -1107,5 +1087,5 @@
          PRINT*,'rugosite <RUG>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             frugs(i,nsrf) = frugs(i,1)
          ENDDO
@@ -1142,5 +1122,5 @@
            xmin = 1.0E+20
            xmax = -1.0E+20
-           DO i = 1, klon
+           DO i = 1, klon_glo
               xmin = MIN(agesno(i,nsrf),xmin)
               xmax = MAX(agesno(i,nsrf),xmax)
@@ -1162,5 +1142,5 @@
          xmin = 1.0E+20
          xmax = -1.0E+20
-         DO i = 1, klon
+         DO i = 1, klon_glo
             xmin = MIN(agesno(i,1),xmin)
             xmax = MAX(agesno(i,1),xmax)
@@ -1168,5 +1148,5 @@
          PRINT*,'Age de la neige <AGESNO>', xmin, xmax
          DO nsrf = 2, nbsrf
-         DO i = 1, klon
+         DO i = 1, klon_glo
             agesno(i,nsrf) = agesno(i,1)
          ENDDO
@@ -1191,5 +1171,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zmea(i),xmin)
          xmax = MAX(zmea(i),xmax)
@@ -1214,5 +1194,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zstd(i),xmin)
          xmax = MAX(zstd(i),xmax)
@@ -1237,5 +1217,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zsig(i),xmin)
          xmax = MAX(zsig(i),xmax)
@@ -1260,5 +1240,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zgam(i),xmin)
          xmax = MAX(zgam(i),xmax)
@@ -1283,5 +1263,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zthe(i),xmin)
          xmax = MAX(zthe(i),xmax)
@@ -1306,5 +1286,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zpic(i),xmin)
          xmax = MAX(zpic(i),xmax)
@@ -1328,5 +1308,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(zval(i),xmin)
          xmax = MAX(zval(i),xmax)
@@ -1351,5 +1331,5 @@
       xmin = 1.0E+20
       xmax = -1.0E+20
-      DO i = 1, klon
+      DO i = 1, klon_glo
          xmin = MIN(rugsrel(i),xmin)
          xmax = MAX(rugsrel(i),xmax)
@@ -1510,4 +1490,5 @@
 c
       ierr = NF_CLOSE(nid)
+      ENDIF ! is_mpi_root
 c
 c$OMP END MASTER
@@ -1516,164 +1497,50 @@
 cym  en attendant mieux
         iolat(1)=rlat(1)
-	iolat(jjm+1)=rlat(klon)
+	iolat(jjm+1)=rlat(klon_glo)
 	do i=2,jjm
 	  iolat(i)=rlat(2+(i-2)*iim)
 	enddo
-	
+	CALL bcast_mpi(iolat)
+	CALL bcast_mpi(rlon)
         call init_iophy(iolat,rlon(2:iim+1))
        
-      print *,'Allocated ??',allocated(zmasq_mpi)
-      print *,'klon_mpi',klon_mpi
-      print *,'omp_rank',omp_rank
-      ALLOCATE( zmasq_mpi(klon_mpi))
-      ALLOCATE( rlat_mpi(klon_mpi), rlon_mpi(klon_mpi))
-      ALLOCATE( tsol_mpi(klon_mpi,nbsrf))
-      ALLOCATE( tsoil_mpi(klon_mpi,nsoilmx,nbsrf))
-      ALLOCATE( tslab_mpi(klon_mpi))
-      ALLOCATE( seaice_mpi(klon_mpi))
-      ALLOCATE( qsurf_mpi(klon_mpi,nbsrf))
-      ALLOCATE( qsol_mpi(klon_mpi))
-      ALLOCATE( snow_mpi(klon_mpi,nbsrf))
-      ALLOCATE( albe_mpi(klon_mpi,nbsrf))
-      ALLOCATE( alblw_mpi(klon_mpi,nbsrf))
-      ALLOCATE( evap_mpi(klon_mpi,nbsrf))
-      ALLOCATE( radsol_mpi(klon_mpi))
-      ALLOCATE( rain_fall_mpi(klon_mpi))
-      ALLOCATE( snow_fall_mpi(klon_mpi))
-      ALLOCATE( sollw_mpi(klon_mpi))
-      ALLOCATE( solsw_mpi(klon_mpi))
-      ALLOCATE( fder_mpi(klon_mpi))
-      ALLOCATE( frugs_mpi(klon_mpi,nbsrf))
-      ALLOCATE( agesno_mpi(klon_mpi,nbsrf))
-      ALLOCATE( zmea_mpi(klon_mpi))
-      ALLOCATE( zstd_mpi(klon_mpi))
-      ALLOCATE( zsig_mpi(klon_mpi))
-      ALLOCATE( zgam_mpi(klon_mpi))
-      ALLOCATE( zthe_mpi(klon_mpi))
-      ALLOCATE( zpic_mpi(klon_mpi))
-      ALLOCATE( zval_mpi(klon_mpi))
-      ALLOCATE( rugsrel_mpi(klon_mpi))
-      ALLOCATE( pctsrf_mpi(klon_mpi, nbsrf))
-      ALLOCATE( run_off_lic_0_mpi(klon_mpi))
-      ALLOCATE( t_ancien_mpi(klon_mpi,klev))
-      ALLOCATE( q_ancien_mpi(klon_mpi,klev))
-      ALLOCATE( rnebcon_mpi(klon_mpi,klev))
-      ALLOCATE( clwcon_mpi(klon_mpi,klev))
-      ALLOCATE( ratqs_mpi(klon_mpi,klev))
+c$OMP END MASTER
       	
-      call ScatterField( rlat,rlat_mpi,1)
-      call ScatterField( rlon,rlon_mpi,1)
-      call ScatterField( tsol,tsol_mpi,nbsrf)
-      call ScatterField( tsoil,tsoil_mpi,nsoilmx*nbsrf)
-      call ScatterField( tslab,tslab_mpi,1)
-      call ScatterField( seaice,seaice_mpi,1)
-      call ScatterField( qsurf,qsurf_mpi,nbsrf)
-      call ScatterField( qsol,qsol_mpi,1)
-      call ScatterField( snow,snow_mpi,nbsrf)
-      call ScatterField( albe,albe_mpi,nbsrf)
-      call ScatterField( alblw,alblw_mpi,nbsrf)
-      call ScatterField( evap,evap_mpi,nbsrf)
-      call ScatterField( radsol,radsol_mpi,1)
-      call ScatterField( rain_fall,rain_fall_mpi,1)
-      call ScatterField( snow_fall,snow_fall_mpi,1)
-      call ScatterField( sollw,sollw_mpi,1)
-      call ScatterField( solsw,solsw_mpi,1)
-      call ScatterField( fder,fder_mpi,1)
-      call ScatterField( frugs,frugs_mpi,nbsrf)
-      call ScatterField( agesno,agesno_mpi,nbsrf)
-      call ScatterField( zmea,zmea_mpi,1)
-      call ScatterField( zstd,zstd_mpi,1)
-      call ScatterField( zsig,zsig_mpi,1)
-      call ScatterField( zgam,zgam_mpi,1)
-      call ScatterField( zthe,zthe_mpi,1)
-      call ScatterField( zpic,zpic_mpi,1)
-      call ScatterField( zval,zval_mpi,1)
-      call ScatterField( rugsrel,rugsrel_mpi,1)
-      call ScatterField( pctsrf,pctsrf_mpi, nbsrf)
-      call ScatterField( run_off_lic_0,run_off_lic_0_mpi,1)
-      call ScatterField( t_ancien,t_ancien_mpi,klev)
-      call ScatterField( q_ancien,q_ancien_mpi,klev)
-      call ScatterField( rnebcon,rnebcon_mpi,klev)
-      call ScatterField( clwcon,clwcon_mpi,klev)
-      call ScatterField( ratqs,ratqs_mpi,klev)
-      call ScatterField( zmasq,zmasq_mpi,1)
-c$OMP END MASTER
-c$OMP BARRIER
-      call ScatterField_omp( rlat_mpi,rlat_p,1)
-      call ScatterField_omp( rlon_mpi,rlon_p,1)
-      call ScatterField_omp( tsol_mpi,tsol_p,nbsrf)
-      call ScatterField_omp( tsoil_mpi,tsoil_p,nsoilmx*nbsrf)
-      call ScatterField_omp( tslab_mpi,tslab_p,1)
-      call ScatterField_omp( seaice_mpi,seaice_p,1)
-      call ScatterField_omp( qsurf_mpi,qsurf_p,nbsrf)
-      call ScatterField_omp( qsol_mpi,qsol_p,1)
-      call ScatterField_omp( snow_mpi,snow_p,nbsrf)
-      call ScatterField_omp( albe_mpi,albe_p,nbsrf)
-      call ScatterField_omp( alblw_mpi,alblw_p,nbsrf)
-      call ScatterField_omp( evap_mpi,evap_p,nbsrf)
-      call ScatterField_omp( radsol_mpi,radsol_p,1)
-      call ScatterField_omp( rain_fall_mpi,rain_fall_p,1)
-      call ScatterField_omp( snow_fall_mpi,snow_fall_p,1)
-      call ScatterField_omp( sollw_mpi,sollw_p,1)
-      call ScatterField_omp( solsw_mpi,solsw_p,1)
-      call ScatterField_omp( fder_mpi,fder_p,1)
-      call ScatterField_omp( frugs_mpi,frugs_p,nbsrf)
-      call ScatterField_omp( agesno_mpi,agesno_p,nbsrf)
-      call ScatterField_omp( zmea_mpi,zmea_p,1)
-      call ScatterField_omp( zstd_mpi,zstd_p,1)
-      call ScatterField_omp( zsig_mpi,zsig_p,1)
-      call ScatterField_omp( zgam_mpi,zgam_p,1)
-      call ScatterField_omp( zthe_mpi,zthe_p,1)
-      call ScatterField_omp( zpic_mpi,zpic_p,1)
-      call ScatterField_omp( zval_mpi,zval_p,1)
-      call ScatterField_omp( rugsrel_mpi,rugsrel_p,1)
-      call ScatterField_omp( pctsrf_mpi,pctsrf_p, nbsrf)
-      call ScatterField_omp( run_off_lic_0_mpi,run_off_lic_0_p,1)
-      call ScatterField_omp( t_ancien_mpi,t_ancien_p,klev)
-      call ScatterField_omp( q_ancien_mpi,q_ancien_p,klev)
-      call ScatterField_omp( rnebcon_mpi,rnebcon_p,klev)
-      call ScatterField_omp( clwcon_mpi,clwcon_p,klev)
-      call ScatterField_omp( ratqs_mpi,ratqs_p,klev)
-      call ScatterField_omp( zmasq_mpi,zmasq_p,1)
-      ancien_ok_p=ancien_ok
-
-c$OMP MASTER
-      DEALLOCATE( zmasq_mpi)
-      DEALLOCATE( rlat_mpi, rlon_mpi)
-      DEALLOCATE( tsol_mpi)
-      DEALLOCATE( tsoil_mpi)
-      DEALLOCATE( tslab_mpi)
-      DEALLOCATE( seaice_mpi)
-      DEALLOCATE( qsurf_mpi)
-      DEALLOCATE( qsol_mpi)
-      DEALLOCATE( snow_mpi)
-      DEALLOCATE( albe_mpi)
-      DEALLOCATE( alblw_mpi)
-      DEALLOCATE( evap_mpi)
-      DEALLOCATE( radsol_mpi)
-      DEALLOCATE( rain_fall_mpi)
-      DEALLOCATE( snow_fall_mpi)
-      DEALLOCATE( sollw_mpi)
-      DEALLOCATE( solsw_mpi)
-      DEALLOCATE( fder_mpi)
-      DEALLOCATE( frugs_mpi)
-      DEALLOCATE( agesno_mpi)
-      DEALLOCATE( zmea_mpi)
-      DEALLOCATE( zstd_mpi)
-      DEALLOCATE( zsig_mpi)
-      DEALLOCATE( zgam_mpi)
-      DEALLOCATE( zthe_mpi)
-      DEALLOCATE( zpic_mpi)
-      DEALLOCATE( zval_mpi)
-      DEALLOCATE( rugsrel_mpi)
-      DEALLOCATE( pctsrf_mpi)
-      DEALLOCATE( run_off_lic_0_mpi)
-      DEALLOCATE( t_ancien_mpi)
-      DEALLOCATE( q_ancien_mpi)
-      DEALLOCATE( rnebcon_mpi)
-      DEALLOCATE( clwcon_mpi)   
-
-c$OMP END MASTER
-c$OMP BARRIER
+      call Scatter( rlat,rlat_p)
+      call Scatter( rlon,rlon_p)
+      call Scatter( tsol,tsol_p)
+      call Scatter( tsoil,tsoil_p)
+      call Scatter( tslab,tslab_p)
+      call Scatter( seaice,seaice_p)
+      call Scatter( qsurf,qsurf_p)
+      call Scatter( qsol,qsol_p)
+      call Scatter( snow,snow_p)
+      call Scatter( albe,albe_p)
+      call Scatter( alblw,alblw_p)
+      call Scatter( evap,evap_p)
+      call Scatter( radsol,radsol_p)
+      call Scatter( rain_fall,rain_fall_p)
+      call Scatter( snow_fall,snow_fall_p)
+      call Scatter( sollw,sollw_p)
+      call Scatter( solsw,solsw_p)
+      call Scatter( fder,fder_p)
+      call Scatter( frugs,frugs_p)
+      call Scatter( agesno,agesno_p)
+      call Scatter( zmea,zmea_p)
+      call Scatter( zstd,zstd_p)
+      call Scatter( zsig,zsig_p)
+      call Scatter( zgam,zgam_p)
+      call Scatter( zthe,zthe_p)
+      call Scatter( zpic,zpic_p)
+      call Scatter( zval,zval_p)
+      call Scatter( rugsrel,rugsrel_p)
+      call Scatter( pctsrf,pctsrf_p)
+      call Scatter( run_off_lic_0,run_off_lic_0_p)
+      call Scatter( t_ancien,t_ancien_p)
+      call Scatter( q_ancien,q_ancien_p)
+      call Scatter( rnebcon,rnebcon_p)
+      call Scatter( clwcon,clwcon_p)
+      call Scatter( ratqs,ratqs_p)
+      call Scatter( zmasq_glo,zmasq)
 
       RETURN
