Index: LMDZ4/branches/V3_test/libf/phylmd/phyetat0.F
===================================================================
--- LMDZ4/branches/V3_test/libf/phylmd/phyetat0.F	(revision 703)
+++ LMDZ4/branches/V3_test/libf/phylmd/phyetat0.F	(revision 704)
@@ -5,13 +5,16 @@
 c
       SUBROUTINE phyetat0 (fichnom,dtime,co2_ppm_etat0,solaire_etat0,
-     .            rlat,rlon, pctsrf, tsol,tsoil,
+     .            rlat_p,rlon_p, pctsrf_p, tsol_p,tsoil_p,
 cIM "slab" ocean
-     .           ocean, tslab,seaice,
-     .           qsurf,qsol,snow,
-     .           albe, alblw, evap, rain_fall, snow_fall, solsw, sollw,
-     .           fder,radsol,frugs,agesno,clesphy0,
-     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel,tabcntr0,
-     .           t_ancien,q_ancien,ancien_ok, rnebcon, ratqs,clwcon,
-     .           run_off_lic_0)
+     .           ocean, tslab_p,seaice_p,
+     .           qsurf_p,qsol_p,snow_p,albe_p, alblw_p, evap_p,
+     .           rain_fall_p, snow_fall_p,solsw_p, sollw_p,
+     .           fder_p,radsol_p,frugs_p,agesno_p,clesphy0,
+     .           zmea_p,zstd_p,zsig_p,zgam_p,zthe_p,zpic_p,zval_p,
+     .           rugsrel_p,tabcntr0,
+     .           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 iophy
       IMPLICIT none
 c======================================================================
@@ -20,5 +23,5 @@
 c======================================================================
 #include "dimensions.h"
-#include "dimphy.h"
+cym#include "dimphy.h"
 #include "netcdf.inc"
 #include "indicesol.h"
@@ -30,7 +33,45 @@
       REAL dtime
       INTEGER radpas
-      REAL rlat(klon), rlon(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)
+cIM BEG alblw
+      REAL alblw_p(klon2,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 t_ancien_p(klon2,klev), q_ancien_p(klon2,klev)
+      real rnebcon_p(klon2,klev),clwcon_p(klon2,klev)
+      real ratqs_p(klon2,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)
@@ -62,8 +103,46 @@
       REAL fractint(klon)
       REAL run_off_lic_0(klon)
-
-      REAL t_ancien(klon,klev), q_ancien(klon,klev)
-      real rnebcon(klon,klev),clwcon(klon,klev),ratqs(klon,klev)
-      LOGICAL ancien_ok
+      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(:,:)
+           
 
       CHARACTER*6 ocean
@@ -80,10 +159,18 @@
       PARAMETER (length=100)
       REAL tab_cntrl(length), tabcntr0(length)
+      REAL,SAVE :: tab_cntrl_omp(length)
       CHARACTER*7 str7
       CHARACTER*2 str2
+      real iolat(jjm+1)
 c
 c Ouvrir le fichier contenant l'etat initial:
 c
-      print*,'fichnom',fichnom
+
+c$OMP MASTER
+      print *,'MASTER -x , omp_rank=',omp_rank
+c$OMP END MASTER
+
+c$OMP MASTER
+      print*,'fichnom ',fichnom
       ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -92,7 +179,9 @@
         CALL ABORT
       ENDIF
+c$OMP END MASTER
 c
 c Lecture des parametres de controle:
 c
+c$OMP MASTER
       ierr = NF_INQ_VARID (nid, "controle", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -101,13 +190,21 @@
       ENDIF
 #ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tab_cntrl)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, tab_cntrl)
+      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tab_cntrl_omp)
+#else
+      ierr = NF_GET_VAR_REAL(nid, nvarid, tab_cntrl_omp)
 #endif
       IF (ierr.NE.NF_NOERR) THEN
          PRINT*, 'phyetat0: Lecture echouee pour <controle>'
          CALL abort
-      ELSE
-c
+      ENDIF
+c$OMP END MASTER
+c$OMP BARRIER
+       
+       DO i = 1, length
+         tab_cntrl( i ) = tab_cntrl_omp( i )
+       ENDDO
+       
+c
+       
          DO i = 1, length
            tabcntr0( i ) = tab_cntrl( i )
@@ -177,5 +274,4 @@
          IF( tab_cntrl(12) .EQ. 1. )     ok_limitvrai = .TRUE.
 
-      ENDIF
 
       itau_phy = tab_cntrl(15)
@@ -184,4 +280,5 @@
 c Lecture des latitudes (coordonnees):
 c
+c$OMP MASTER
       ierr = NF_INQ_VARID (nid, "latitude", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -198,4 +295,5 @@
          CALL abort
       ENDIF
+
 c
 c Lecture des longitudes (coordonnees):
@@ -219,4 +317,5 @@
 C Lecture du masque terre mer
 C
+
       ierr = NF_INQ_VARID (nid, "masque", nvarid)
       IF (ierr .EQ.  NF_NOERR) THEN
@@ -235,4 +334,6 @@
 C      CALL abort
       ENDIF
+
+       
 C Lecture des fractions pour chaque sous-surface
 C
@@ -243,4 +344,5 @@
 C fraction de terre
 C
+
       ierr = NF_INQ_VARID (nid, "FTER", nvarid)
       IF (ierr .EQ.  NF_NOERR) THEN
@@ -256,6 +358,7 @@
       else
           PRINT*, 'phyetat0: Le champ <FTER> est absent'
-c$$$         CALL abort
-      ENDIF
+c@$$         CALL abort
+      ENDIF
+
 C
 C fraction de glace de terre
@@ -274,5 +377,5 @@
       else
           PRINT*, 'phyetat0: Le champ <FLIC> est absent'
-c$$$         CALL abort
+c@$$         CALL abort
       ENDIF
 C
@@ -292,6 +395,7 @@
       else
           PRINT*, 'phyetat0: Le champ <FOCE> est absent'
-c$$$         CALL abort
-      ENDIF
+c@$$         CALL abort
+      ENDIF
+
 C
 C fraction glace de mer
@@ -310,6 +414,7 @@
       else
           PRINT*, 'phyetat0: Le champ <FSIC> est absent'
-c$$$         CALL abort
-      ENDIF
+c@$$         CALL abort
+      ENDIF
+
 C
 C  Verification de l'adequation entre le masque et les sous-surfaces
@@ -333,7 +438,9 @@
         ENDIF 
       END DO 
+
 C
 c Lecture des temperatures du sol:
 c
+
       ierr = NF_INQ_VARID (nid, "TS", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -360,4 +467,5 @@
              CALL abort
            ENDIF
+
            xmin = 1.0E+20
            xmax = -1.0E+20
@@ -393,4 +501,5 @@
          ENDDO
       ENDIF
+
 c
 c Lecture des temperatures du sol profond:
@@ -557,5 +666,5 @@
           PRINT*, '          Valeur par defaut nulle'
           qsol(:)=0.
-c$$$         CALL abort
+c@$$         CALL abort
       ENDIF
       xmin = 1.0E+20
@@ -886,4 +995,9 @@
       PRINT*,'Rayonnement IF au sol sollw:', xmin, xmax
 
+c$OMP END MASTER
+
+
+c$OMP MASTER
+
 c
 c Lecture derive des flux:
@@ -1280,4 +1394,5 @@
       ENDIF
 c
+      clwcon=0.
       ierr = NF_INQ_VARID (nid, "CLWCON", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -1302,4 +1417,5 @@
       PRINT*,'Eau liquide convective (ecart-type) clwcon:', xmin, xmax
 c
+      rnebcon=0.
       ierr = NF_INQ_VARID (nid, "RNEBCON", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -1344,4 +1460,5 @@
 c Lecture ratqs
 c
+       ratqs=0.
       ierr = NF_INQ_VARID (nid, "RATQS", nvarid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -1394,4 +1511,170 @@
       ierr = NF_CLOSE(nid)
 c
+c$OMP END MASTER
+
+c$OMP MASTER
+cym  en attendant mieux
+        iolat(1)=rlat(1)
+	iolat(jjm+1)=rlat(klon)
+	do i=2,jjm
+	  iolat(i)=rlat(2+(i-2)*iim)
+	enddo
+	
+        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))
+      	
+      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
+
       RETURN
       END
