Index: /LMDZ6/trunk/build_gcm
===================================================================
--- /LMDZ6/trunk/build_gcm	(revision 4102)
+++ /LMDZ6/trunk/build_gcm	(revision 4103)
@@ -33,13 +33,9 @@
 ${dirname}fcm build $*
 
-err=$?
-# Check error message from fcm build
-if [ $err != 0 ] ; then
-  # ERROR IN COMPILING
-  echo ERROR IN COMPILING LMDZ : $err
-  exit 1
-fi
+build_command_status=$?
 
 # cleanup
 \rm -f '.lock' 
 
+exit $build_command_status
+
Index: /LMDZ6/trunk/libf/dyn3dmem/gcm.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/gcm.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/dyn3dmem/gcm.F90	(revision 4103)
@@ -454,9 +454,8 @@
 
   !!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
+  !     Copy all threadprivate variables in temps_mod logic_mod 
   !$OMP PARALLEL DEFAULT(SHARED) &
-  !     Copy all threadprivate variables in temps_mod
   !$OMP COPYIN(dt,jD_ref,jH_ref,start_time,hour_ini,day_ini,day_end) &
   !$OMP COPYIN(annee_ref,day_ref,itau_dyn,itau_phy,itaufin,calend) &
-  !     Copy all threadprivate variables from logic_mod
   !$OMP COPYIN(purmats,forward,leapf,apphys,statcl,conser,apdiss,apdelq) &
   !$OMP COPYIN(saison,ecripar,fxyhypb,ysinus,read_start,ok_guide) &
Index: /LMDZ6/trunk/libf/dyn3dmem/vlsplt_loc.F
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/vlsplt_loc.F	(revision 4102)
+++ /LMDZ6/trunk/libf/dyn3dmem/vlsplt_loc.F	(revision 4103)
@@ -1074,5 +1074,5 @@
          ENDDO
        ENDDO
-c$OMP END DO NO WAIT
+c$OMP END DO NOWAIT
 
 c Reindicage vertical en accumulant les flux sur
@@ -1114,5 +1114,5 @@
          ENDDO
       ENDDO
-c$OMP END DO NO WAIT
+c$OMP END DO NOWAIT
 
       ENDDO ! WHILE (countcfl>=1)
Index: /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 4103)
@@ -114,7 +114,6 @@
   
 !!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/)
-!$OMP PARALLEL DEFAULT(SHARED) &
 !	Copy all threadprivate variables in temps_mod
-!$OMP COPYIN(annee_ref, day_ini, day_ref, start_time)
+!$OMP PARALLEL DEFAULT(SHARED) COPYIN(annee_ref,day_ini,day_ref,start_time)
 
   ! Initialize physical constants in physics:
Index: /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_transfert.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_transfert.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_transfert.F90	(revision 4103)
@@ -498,6 +498,5 @@
     REAL,INTENT(OUT),DIMENSION(:) :: VarOut
 
-    CALL Check_buffer_r(size(VarOut))   
-    CALL gather_omp_rgen(VarIn,Varout,1,buffer_r)
+    CALL gather_omp_rgen(VarIn,Varout,1)
     
   END SUBROUTINE gather_omp_r
@@ -509,7 +508,6 @@
     REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
     REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    CALL Check_buffer_r(size(VarOut))   
-    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2),buffer_r)
+ 
+    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2))
         
   END SUBROUTINE gather_omp_r1
@@ -521,7 +519,6 @@
     REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
     REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarOut))   
-    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_r)
+ 
+    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3))
     
   END SUBROUTINE gather_omp_r2
@@ -533,7 +530,6 @@
     REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
     REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    CALL Check_buffer_r(size(VarOut))       
-    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_r)
+     
+    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
     
   END SUBROUTINE gather_omp_r3
@@ -1071,5 +1067,5 @@
 
 
-  SUBROUTINE gather_omp_rgen(VarIn,VarOut,dimsize,Buff)
+  SUBROUTINE gather_omp_rgen(VarIn,VarOut,dimsize)
   USE mod_phys_lmdz_omp_data
   USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
@@ -1078,6 +1074,33 @@
     INTEGER,INTENT(IN) :: dimsize
     REAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-    REAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize),TARGET :: VarOut
+
+    REAL, POINTER, SAVE :: Varout_ptr(:,:) ! Shared between threads NOT THREADPRIVATE
+
+    INTEGER :: i,ij
+    
+    !$omp master
+    Varout_ptr => VarOut
+    !$omp end master
+    !$omp barrier
+
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        Varout_ptr(klon_omp_begin-1+ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    !$omp barrier
+  END SUBROUTINE gather_omp_rgen
+
+
+  SUBROUTINE gather_omp_lgen(VarIn,VarOut,dimsize,Buff)
+  USE mod_phys_lmdz_omp_data
+  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+    LOGICAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
 
     INTEGER :: i,ij
@@ -1100,36 +1123,4 @@
   !$OMP BARRIER
 
-  END SUBROUTINE gather_omp_rgen
-
-
-  SUBROUTINE gather_omp_lgen(VarIn,VarOut,dimsize,Buff)
-  USE mod_phys_lmdz_omp_data
-  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-    LOGICAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
-
-
-  !$OMP MASTER
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=Buff(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
-
   END SUBROUTINE gather_omp_lgen
 
Index: /LMDZ6/trunk/libf/phylmd/cosp/dsd.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp/dsd.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/cosp/dsd.F90	(revision 4103)
@@ -57,5 +57,5 @@
   integer, intent(in) :: nsizes
   integer, intent(in) :: dtype
-  real*8, intent(in)  :: Q,Re,Np,D(nsizes)
+  real*8, intent(in)  :: Q,Re_,Np,D(nsizes)
   real*8, intent(in)  :: rho_a,tk,dmin,dmax,rho_c,p1,p2,p3
     
@@ -78,6 +78,9 @@
   real*8 :: tmp1, tmp2
   real*8 :: pi,rc,tc
+  real*8 :: Re
 
   integer k,lidx,uidx
+
+  Re = Re_
 
   tc = tk - 273.15
Index: /LMDZ6/trunk/libf/phylmd/cosp/radar_simulator.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp/radar_simulator.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/cosp/radar_simulator.F90	(revision 4103)
@@ -96,5 +96,5 @@
   real*8, dimension(hp%nhclass,nprof,ngate), intent(in) :: hm_matrix
   real*8, dimension(hp%nhclass,nprof,ngate), intent(inout) :: re_matrix
-  real*8, dimension(hp%nhclass,nprof,ngate), intent(in)    :: Np_matrix
+  real*8, dimension(hp%nhclass,nprof,ngate), intent(inout)    :: Np_matrix
 
 ! ----- OUTPUTS -----
Index: /LMDZ6/trunk/libf/phylmd/iophy.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/iophy.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/iophy.F90	(revision 4103)
@@ -975,5 +975,5 @@
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured, regular_lonlat
 #ifdef CPP_XIOS
-  USE xios, ONLY: xios_send_field
+  USE xios, ONLY: xios_send_field, xios_field_is_active
 #endif
   USE print_control_mod, ONLY: lunout, prt_level
@@ -996,4 +996,5 @@
   INTEGER :: ip
   REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
+  logical, save :: is_active = .true.
 
   IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite2d_phy for ',trim(var%name)
@@ -1035,4 +1036,14 @@
 
   ELSE
+#ifdef CPP_XIOS
+    IF (ok_all_xml) THEN
+      !$omp barrier
+      !$omp master
+      is_active = xios_field_is_active(var%name, at_current_timestep_arg=.false.)
+      !$omp end master
+      !$omp barrier
+      IF(.not. is_active) RETURN
+    ENDIF
+#endif
 
     !Et sinon on.... écrit
@@ -1176,5 +1187,5 @@
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, regular_lonlat, unstructured
 #ifdef CPP_XIOS
-  USE xios, ONLY: xios_send_field
+  USE xios, ONLY: xios_send_field, xios_field_is_active
 #endif
   USE print_control_mod, ONLY: prt_level,lunout
@@ -1195,4 +1206,5 @@
   INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
   REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
+  logical, save :: is_active = .true.
 
   IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite3d_phy for ', trim(var%name)
@@ -1222,6 +1234,16 @@
       CALL bcast_omp(swaerofree_diag)
   ELSE
+#ifdef CPP_XIOS
+    IF (ok_all_xml) THEN
+      !$omp barrier
+      !$omp master
+      is_active = xios_field_is_active(var%name, at_current_timestep_arg=.false.)
+      !$omp end master
+      !$omp barrier
+      IF(.not. is_active) RETURN
+    ENDIF
+#endif
+
     !Et sinon on.... écrit
-
     IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev .AND. SIZE(field,1)/=klev+1) CALL abort_physic('iophy::histwrite3d_phy','Field first DIMENSION not equal to klon/klev',1)
 
Index: /LMDZ6/trunk/libf/phylmd/mo_simple_plumes.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/mo_simple_plumes.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/mo_simple_plumes.F90	(revision 4103)
@@ -280,5 +280,5 @@
 
     IF ((iweek > ntimes) .OR. (iweek < 1) .OR. (iyear > nyears) .OR. (iyear < 1)) THEN 
-      CALL abort_physic('set_time_weight','Time out of bounds')
+      CALL abort_physic('set_time_weight','Time out of bounds',1)
     ENDIF
 
Index: /LMDZ6/trunk/libf/phylmd/o3_chem_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/o3_chem_m.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/o3_chem_m.F90	(revision 4103)
@@ -85,5 +85,5 @@
     ! Heterogeneous chemistry is only during daytime:
     call orbite(real(julien), earth_long, trash1)
-    call zenang(earth_long, gmtime, pdtphys, rlat, rlon, pmu0, trash2)
+    call zenang(earth_long, gmtime, 0., pdtphys, rlat, rlon, pmu0, trash2)
     forall (k = 1: nbp_lev)
        where (pmu0 <= cos(87. / 180. * pi)) b(:, k) = 0.
Index: /LMDZ6/trunk/libf/phylmd/readaerosol_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/readaerosol_mod.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/readaerosol_mod.F90	(revision 4103)
@@ -10,5 +10,4 @@
 !$OMP THREADPRIVATE(nbp_lat_src)  
   REAL, ALLOCATABLE, SAVE    :: psurf_interp(:,:)
-!$OMP THREADPRIVATE(psurf_interp)  
 
 CONTAINS
@@ -692,5 +691,6 @@
         CALL xios_send_field("load_"//TRIM(varname)//"_in",load_glo2D)
         CALL xios_recv_field("load_"//TRIM(varname)//"_out",load_out_mpi)
-        IF (first) THEN
+        IF (.not. allocated(psurf_interp)) THEN
+         ! psurf_interp is a shared array
           ALLOCATE(psurf_interp(klon_mpi,12))
           CALL xios_send_field("psurf_aerosol_in",psurf_glo2D)
Index: /LMDZ6/trunk/libf/phylmd/rrtm/abor1.intfb.h
===================================================================
--- /LMDZ6/trunk/libf/phylmd/rrtm/abor1.intfb.h	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/rrtm/abor1.intfb.h	(revision 4103)
@@ -1,5 +1,5 @@
 INTERFACE
 SUBROUTINE ABOR1(CDTEXT)
-CHARACTER(LEN=*) :: CDTEXT
+CHARACTER(LEN=*), INTENT(IN) :: CDTEXT
 END SUBROUTINE ABOR1
 END INTERFACE
Index: /LMDZ6/trunk/libf/phylmd/rrtm/tpm_fft.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/rrtm/tpm_fft.F90	(revision 4102)
+++ /LMDZ6/trunk/libf/phylmd/rrtm/tpm_fft.F90	(revision 4103)
@@ -7,6 +7,6 @@
 
 TYPE FFT_TYPE
-  REAL(KIND=JPRB)   ,POINTER :: TRIGS(:,:)
-  INTEGER(KIND=JPIM),POINTER :: NFAX(:,:)
+  REAL(KIND=JPRB)   ,ALLOCATABLE :: TRIGS(:,:)
+  INTEGER(KIND=JPIM),ALLOCATABLE :: NFAX(:,:)
 END TYPE FFT_TYPE
 
Index: /LMDZ6/trunk/makelmdz_fcm
===================================================================
--- /LMDZ6/trunk/makelmdz_fcm	(revision 4102)
+++ /LMDZ6/trunk/makelmdz_fcm	(revision 4103)
@@ -770,6 +770,9 @@
 fi
 
+set +e
+
 rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock
 ./build_gcm ${fcm_path} -j $job $full
+build_status=$?
 
 err=$?
@@ -790,2 +793,4 @@
   \rm -f $LIBFGCM/grid/dimensions.h
 fi
+
+exit $build_status
