Index: LMDZ6/branches/DYNAMICO-conv/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90
===================================================================
--- LMDZ6/branches/DYNAMICO-conv/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 3024)
+++ LMDZ6/branches/DYNAMICO-conv/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 3413)
@@ -2,4 +2,5 @@
 ! $Id: readaerosolstrato2_rrtm.F90 2526 2016-05-26 22:13:40Z oboucher $
 !
+
 SUBROUTINE readaerosolstrato2_rrtm(debut)
 
@@ -9,7 +10,7 @@
 
     USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo, grid_type, unstructured
+    USE mod_phys_lmdz_mpi_data
+    USE mod_phys_lmdz_omp_data
     USE mod_phys_lmdz_para 
     USE phys_state_var_mod
@@ -19,5 +20,5 @@
     USE YOERAD, ONLY : NLW
     USE YOMCST
-
+    USE xios
     IMPLICIT NONE
 
@@ -65,4 +66,8 @@
     REAL, ALLOCATABLE:: cgaerstrat_mois_glo(:, :, :)
     REAL, ALLOCATABLE:: taulwaerstrat_mois_glo(:, :, :)
+    REAL, ALLOCATABLE:: tauaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: pizaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: cgaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: taulwaerstrat_mpi(:, :, :)
 
 ! For NetCDF:
@@ -107,8 +112,11 @@
         CALL nf95_gw_var(ncid_in, varid, latitude)
         n_lat = size(latitude)
-        IF (n_lat.NE.nbp_lat) THEN 
-           print *, 'latitude=', n_lat, nbp_lat
-           abort_message='Le nombre de lat n est pas egal a nbp_lat'
-           CALL abort_physic(modname,abort_message,1)
+
+        IF (grid_type/=unstructured) THEN
+           IF (n_lat.NE.nbp_lat) THEN 
+             print *, 'latitude=', n_lat, nbp_lat
+             abort_message='Le nombre de lat n est pas egal a nbp_lat'
+             CALL abort_physic(modname,abort_message,1)
+           ENDIF
         ENDIF
 
@@ -134,12 +142,4 @@
         ALLOCATE(cgaerstrat(n_lat, n_lev, n_wav, n_month))
 
-        ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-        ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-        ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-
-        ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-        ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-        ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-
 !--reading stratospheric aerosol tau per layer
         CALL nf95_inq_varid(ncid_in, "TAU_SUN", varid)
@@ -159,26 +159,36 @@
         CALL nf95_close(ncid_in)
 
+       
+        IF (grid_type/=unstructured) THEN
+          ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+
+          ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
 !--select the correct month
 !--and copy into 1st longitude
-        tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
-        pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
-        cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
+          tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
+          pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
+          cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
 
 !--copy longitudes
-        DO i=2, n_lon
-         tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
-         pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
-         cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
-        ENDDO
+          DO i=2, n_lon
+           tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
+           pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
+           cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
+          ENDDO
 
 !---reduce to a klon_glo grid 
-        DO band=1, NSW
-          CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
-          CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
-          CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
-        ENDDO
-
+          DO band=1, NSW
+            CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
+          ENDDO
+        ENDIF
 !--Now LW optical properties
 !
+
         CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
 
@@ -194,9 +204,12 @@
         CALL nf95_gw_var(ncid_in, varid, latitude)
         n_lat = size(latitude)
-        IF (n_lat.NE.nbp_lat) THEN 
-           abort_message='Le nombre de lat n est pas egal a nbp_lat'
-           CALL abort_physic(modname,abort_message,1)
-        ENDIF
-
+
+        IF (grid_type/=unstructured) THEN
+          IF (n_lat.NE.nbp_lat) THEN 
+             abort_message='Le nombre de lat n est pas egal a nbp_lat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+        ENDIF
+        
         CALL nf95_inq_varid(ncid_in, "TIME", varid)
         CALL nf95_gw_var(ncid_in, varid, time)
@@ -217,6 +230,4 @@
 
         ALLOCATE(taulwaerstrat(n_lat, n_lev, n_wav, n_month))
-        ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-        ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
 
 !--reading stratospheric aerosol lw tau per layer
@@ -227,17 +238,23 @@
         CALL nf95_close(ncid_in)
 
+        IF (grid_type/=unstructured) THEN
+
+          ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+
 !--select the correct month
 !--and copy into 1st longitude
-        taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
+          taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
 !--copy longitudes
-        DO i=2, n_lon
-          taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
-        ENDDO
+          DO i=2, n_lon
+            taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
+          ENDDO
 
 !---reduce to a klon_glo grid 
-        DO band=1, NLW
-          CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
-        ENDDO
-
+          DO band=1, NLW
+            CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
+          ENDDO
+        ENDIF
+      
       ELSE !--proc other than mpi_root and omp_root
            !--dummy allocation needed for debug mode
@@ -248,4 +265,10 @@
         ALLOCATE(taulwaerstrat_mois_glo(1,1,1))
 
+        ALLOCATE(tauaerstrat(0,0,0,12))
+        ALLOCATE(pizaerstrat(0,0,0,12))
+        ALLOCATE(cgaerstrat(0,0,0,12))
+        ALLOCATE(taulwaerstrat(0,0,0,12))
+
+
       ENDIF !--is_mpi_root and is_omp_root
 
@@ -255,20 +278,47 @@
       mth_pre=mth_cur
 
+      IF (grid_type==unstructured) THEN
+
+        IF (is_omp_master) THEN
+          ALLOCATE(tauaerstrat_mpi(klon_mpi, klev, NSW))
+          ALLOCATE(pizaerstrat_mpi(klon_mpi, klev, NSW))
+          ALLOCATE(cgaerstrat_mpi(klon_mpi, klev, NSW))        
+          ALLOCATE(taulwaerstrat_mpi(klon_mpi, klev, NLW))
+         
+          CALL xios_send_field("tauaerstrat_in",SPREAD(tauaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("tauaerstrat_out",tauaerstrat_mpi)
+          CALL xios_send_field("pizaerstrat_in",SPREAD(pizaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("pizaerstrat_out",pizaerstrat_mpi)
+          CALL xios_send_field("cgaerstrat_in",SPREAD(cgaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("cgaerstrat_out",cgaerstrat_mpi)
+          CALL xios_send_field("taulwaerstrat_in",SPREAD(taulwaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("taulwaerstrat_out",taulwaerstrat_mpi)
+        ELSE
+          ALLOCATE(tauaerstrat_mpi(0, 0, 0))
+          ALLOCATE(pizaerstrat_mpi(0, 0, 0))
+          ALLOCATE(cgaerstrat_mpi(0, 0, 0))        
+          ALLOCATE(taulwaerstrat_mpi(0, 0, 0))
+        ENDIF  
+        
+        CALL scatter_omp(tauaerstrat_mpi,tau_aer_strat)
+        CALL scatter_omp(pizaerstrat_mpi,piz_aer_strat)
+        CALL scatter_omp(cgaerstrat_mpi,cg_aer_strat)
+        CALL scatter_omp(taulwaerstrat_mpi,taulw_aer_strat)
+      ELSE  
+        
 !--scatter on all proc
-      CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
-      CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
-      CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
-      CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
+        CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+        CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
+        CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
+        CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
+
+        DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois)
+        DEALLOCATE(taulwaerstrat_mois)
+      ENDIF 
 
       IF (is_mpi_root.AND.is_omp_root) THEN
-!
-        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat)
-        DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois)
-        DEALLOCATE(taulwaerstrat,taulwaerstrat_mois)
-!
-      ENDIF !--is_mpi_root and is_omp_root
-
-      DEALLOCATE(tauaerstrat_mois_glo,pizaerstrat_mois_glo,cgaerstrat_mois_glo)
-      DEALLOCATE(taulwaerstrat_mois_glo)
+        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat,taulwaerstrat)
+      ENDIF
+      
 
 !$OMP BARRIER
