Index: /LMDZ6/branches/DYNAMICO-conv-GC/arch/arch-X64_IRENE.fcm
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/arch/arch-X64_IRENE.fcm	(revision 3406)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/arch/arch-X64_IRENE.fcm	(revision 3406)
@@ -0,0 +1,16 @@
+%COMPILER            mpif90
+%LINK                mpif90
+%AR                  ar
+%MAKE                gmake
+%FPP_FLAGS           -P -traditional
+%FPP_DEF             NC_DOUBLE FFT_MKL
+#%BASE_FFLAGS        -recursive -xHost -i4 -r8 -auto -align all -I$(MKL_INC_DIR) -I$(MKL_INC_DIR)/intel64/lp64
+%BASE_FFLAGS         -i4 -r8 -auto -align all -I$(MKL_INC_DIR) -I$(MKL_INC_DIR)/intel64/lp64 -fp-model strict
+%PROD_FFLAGS         -O2
+%DEV_FFLAGS          -p -g -O2 -traceback -fp-stack-check
+%DEBUG_FFLAGS        -p -g -traceback -fp-stack-check -ftrapuv -init=arrays -init=snan
+%MPI_FFLAGS
+%OMP_FFLAGS          -openmp
+%BASE_LD             -i4 -r8 -auto $MKL_LDFLAGS
+%MPI_LD
+%OMP_LD              -openmp
Index: /LMDZ6/branches/DYNAMICO-conv-GC/arch/arch-X64_IRENE.path
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/arch/arch-X64_IRENE.path	(revision 3406)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/arch/arch-X64_IRENE.path	(revision 3406)
@@ -0,0 +1,12 @@
+NETCDF_LIBDIR="-L$NETCDF_LIB_DIR -lnetcdff -lnetcdf"
+NETCDF_INCDIR=-I$NETCDF_INC_DIR
+IOIPSL_INCDIR=$LMDGCM/../../lib
+IOIPSL_LIBDIR=$LMDGCM/../../lib
+ORCH_INCDIR=$LMDGCM/../../lib
+ORCH_LIBDIR=$LMDGCM/../../lib
+OASIS_INCDIR=$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1
+OASIS_LIBDIR=$LMDGCM/../../oasis3-mct/BLD/lib
+INCA_LIBDIR=$LMDGCM/../INCA/config/lib
+INCA_INCDIR=$LMDGCM/../INCA/config/inc
+XIOS_INCDIR=$LMDGCM/../XIOS/inc
+XIOS_LIBDIR=$LMDGCM/../XIOS/lib
Index: /LMDZ6/branches/DYNAMICO-conv-GC/build_gcm
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/build_gcm	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/build_gcm	(revision 3406)
@@ -45,6 +45,11 @@
 # run "fcm build" command
 ${dirname}fcm build $*
+status=$?
 
 # cleanup
 \rm -f '.lock' 
 
+if [ $status -ne 0 ]; then
+  exit $status
+fi
+
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/caladvtrac_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/caladvtrac_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/caladvtrac_mod.F90	(revision 3406)
@@ -44,5 +44,7 @@
     CALL allocate_u(massem,llm,d)
     CALL allocate_u(pbaruc,llm,d)
+    pbaruc(:,:)=0
     CALL allocate_v(pbarvc,llm,d)
+    pbarvc(:,:)=0
     CALL allocate_u(pbarug,llm,d)
     CALL allocate_v(pbarvg,llm,d)
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/call_calfis_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/call_calfis_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/call_calfis_mod.F90	(revision 3406)
@@ -52,5 +52,7 @@
     CALL allocate_u(p,llmp1,d)
     CALL allocate_u(pks,d)
+    pks(:)=0
     CALL allocate_u(pk,llm,d)
+    pk(:,:)=0
     CALL allocate_u(pkf,llm,d)
     CALL allocate_u(phi,llm,d)
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/call_dissip_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/call_dissip_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/call_dissip_mod.F90	(revision 3406)
@@ -31,5 +31,7 @@
 
     CALL allocate_u(ucov,llm,d)
+    ucov(:,:)=0
     CALL allocate_v(vcov,llm,d)
+    vcov(:,:)=0
     CALL allocate_u(teta,llm,d)
     CALL allocate_u(p,llmp1,d)
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/integrd_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/integrd_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/dyn3dmem/integrd_mod.F90	(revision 3406)
@@ -23,4 +23,5 @@
     CALL allocate_u(deltap,llm,d)
     CALL allocate_u(ps,d)
+    ps(:)=0
 
     
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/misc/wxios.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/misc/wxios.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/misc/wxios.F90	(revision 3406)
@@ -15,5 +15,5 @@
     
     INTEGER, SAVE :: g_comm
-    CHARACTER(len=100), SAVE :: g_ctx_name
+    CHARACTER(len=100), SAVE :: g_ctx_name ="LMDZ"
     TYPE(xios_context), SAVE :: g_ctx
 !$OMP THREADPRIVATE(g_comm,g_cts_name,g_ctx)
@@ -145,5 +145,5 @@
     SUBROUTINE wxios_context_init()
         USE print_control_mod, ONLY : prt_level, lunout
-!        USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY
+        USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY
         IMPLICIT NONE
 
@@ -152,5 +152,6 @@
 !$OMP MASTER
         !Initialisation du contexte:
-        CALL xios_context_initialize(g_ctx_name, g_comm)
+        !!CALL xios_context_initialize(g_ctx_name, g_comm)
+        CALL xios_context_initialize(g_ctx_name, COMM_LMDZ_PHY)
         CALL xios_get_handle(g_ctx_name, xios_ctx)    !Récupération
         CALL xios_set_current_context(xios_ctx)            !Activation
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/coef_diff_turb_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/coef_diff_turb_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/coef_diff_turb_mod.F90	(revision 3406)
@@ -65,4 +65,9 @@
 
 
+    ykmm = 0 !ym missing init
+    ykmn = 0 !ym missing init
+    ykmq = 0 !ym missing init
+    
+    
 !****************************************************************************************    
 ! Calcul de coefficients de diffusion turbulent de l'atmosphere : 
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/cv3_routines.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/cv3_routines.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/cv3_routines.F90	(revision 3406)
@@ -3747,12 +3747,18 @@
     END DO ! cld
 
+!ym BIG Warning : it seems that the k loop is missing !!!
+!ym Strong advice to check this
+!ym add a k loop temporary 
+
 ! (particular case: no detraining level is found)                              ! cld
-    DO il = 1, ncum                                                            ! cld
-      IF (i<=inb(il) .AND. nent(il,i)==0 .AND. iflag(il)<=1) THEN              ! cld
-        qcond(il, i) = qcond(il, i) + (1.-ep(il,i))*clw(il, i)                 ! cld
-        qtment(il, i) = qent(il,k,i) + qtment(il,i)                          ! cld
-        nqcond(il, i) = nqcond(il, i) + 1.                                     ! cld
-      END IF                                                                   ! cld
-    END DO                                                                     ! cld
+    DO k = i + 1, nl
+      DO il = 1, ncum        !ym k loop added                                                      ! cld
+        IF (i<=inb(il) .AND. nent(il,i)==0 .AND. iflag(il)<=1) THEN              ! cld
+          qcond(il, i) = qcond(il, i) + (1.-ep(il,i))*clw(il, i)                 ! cld
+          qtment(il, i) = qent(il,k,i) + qtment(il,i)                          ! cld
+          nqcond(il, i) = nqcond(il, i) + 1.                                     ! cld
+        END IF                                                                   ! cld
+      END DO
+    ENDDO                                                                     ! cld
 
     DO il = 1, ncum                                                            ! cld
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/cva_driver.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/cva_driver.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/cva_driver.F90	(revision 3406)
@@ -613,4 +613,7 @@
   asupmaxmin1(:) = 0.
 
+  tvp(:, :) = 0. !ym missing init, need to have a look by developpers
+  tv(:, :) = 0. !ym missing init, need to have a look by developpers
+   
   DO il = 1, len
     cin1(il) = -100000.
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/limit_read_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/limit_read_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/limit_read_mod.F90	(revision 3406)
@@ -258,5 +258,5 @@
           ENDIF
           ierr=NF90_INQUIRE_DIMENSION(nid, ndimid, len=nn)
-          WRITE(abort_message,'(a,2(i3,a))')'limit.nc records number (',nn,') does no'//&
+          WRITE(abort_message,'(a,2(i0,a))')'limit.nc records number (',nn,') does no'//&
             't match year length (',year_len,')'
           IF(nn/=year_len) CALL abort_physic(modname,abort_message,1)
@@ -288,5 +288,7 @@
 
     is_modified = .FALSE.
-    IF (MOD(itime-1, lmt_pas) == 0 .OR. jour_lu /= jour ) THEN   ! time to read
+!ym    IF (MOD(itime-1, lmt_pas) == 0 .OR. jour_lu /= jour ) THEN   ! time to read
+!  not REALLY PERIODIC
+    IF (MOD(itime-1, lmt_pas) == 0) THEN   ! time to read
        jour_lu = jour
        is_modified = .TRUE.
@@ -334,5 +336,5 @@
 
 !$OMP MASTER  ! Only master thread
-       IF (is_mpi_root) THEN ! Only master processus
+       IF (is_mpi_root) THEN ! Only master processus!
 
           ierr = NF90_OPEN ('limit.nc', NF90_NOWRITE, nid)
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/pbl_surface_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/pbl_surface_mod.F90	(revision 3406)
@@ -1895,5 +1895,5 @@
                ywindsp, rmu0, yfder, yts, &
                itap, dtime, jour, knon, ni, &
-               ypplay(:,1), zgeo1/RG, ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&
+               ypplay(:,1), zgeo1(1:knon)/RG, ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&    ! ym missing init
                AcoefH, AcoefQ, BcoefH, BcoefQ, &
                AcoefU, AcoefV, BcoefU, BcoefV, &
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_cal_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_cal_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_cal_mod.F90	(revision 3406)
@@ -37,5 +37,6 @@
   SUBROUTINE phys_cal_init(annee_ref,day_ref)
 
-    USE IOIPSL, ONLY:  ymds2ju
+    USE IOIPSL, ONLY:  ymds2ju, ioconf_calendar
+    USE mod_phys_lmdz_para, ONLY:  is_master,is_omp_master
     USE ioipsl_getin_p_mod, ONLY: getin_p
 
@@ -47,4 +48,17 @@
     calend = 'earth_360d' ! default
     CALL getin_p("calend",calend)
+
+    IF (is_omp_master) THEN
+      IF (calend == 'earth_360d') THEN
+        CALL ioconf_calendar('360d')
+      ELSE IF (calend == 'earth_365d') THEN
+        CALL ioconf_calendar('noleap')
+      ELSE IF (calend == 'earth_366d') THEN
+        CALL ioconf_calendar('gregorian')
+      ELSE
+        CALL abort_physic('phys_cal_init','Mauvais choix de calendrier',1)
+      ENDIF
+    ENDIF
+!$OMP BARRIER
      
     CALL ymds2ju(annee_ref, 1, day_ref, 0., jD_ref)
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_local_var_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_local_var_mod.F90	(revision 3406)
@@ -573,4 +573,6 @@
       ALLOCATE(dv_gwd_rando(klon,klev),dv_gwd_front(klon,klev))
       ALLOCATE(east_gwstress(klon,klev),west_gwstress(klon,klev))
+      east_gwstress(:,:)=0 !ym missing init
+      west_gwstress(:,:)=0 !ym missing init
       ALLOCATE(d_t_hin(klon,klev))
       ALLOCATE(d_q_ch4(klon,klev))
@@ -688,5 +690,7 @@
 !>jyg
       ALLOCATE(dtvdf_x(klon,klev), dtvdf_w(klon,klev))
+      dtvdf_x = 0 ; dtvdf_w=0 ;   !ym missing init
       ALLOCATE(dqvdf_x(klon,klev), dqvdf_w(klon,klev))
+      dqvdf_x = 0 ; dqvdf_w=0 ;   !ym missing init
       ALLOCATE(pbl_tke_input(klon,klev+1,nbsrf))
       ALLOCATE(t_therm(klon,klev), q_therm(klon,klev),u_therm(klon,klev), v_therm(klon,klev))
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_output_write_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_output_write_mod.F90	(revision 3406)
@@ -348,5 +348,5 @@
     ! ug Pour les sorties XIOS
     USE xios
-    USE wxios, ONLY: wxios_closedef, missing_val
+    USE wxios, ONLY: wxios_closedef, missing_val, wxios_set_context
 #endif
     USE phys_cal_mod, ONLY : mth_len
@@ -417,9 +417,13 @@
     CALL set_itau_iophy(itau_w)
 
-    IF (.NOT.vars_defined) THEN
-       iinitend = 2
-    ELSE
+ !   IF (.NOT.vars_defined) THEN
        iinitend = 1
-    ENDIF
+ !   ELSE
+ !      iinitend = 1
+ !   ENDIF
+
+#ifdef CPP_XIOS
+    CALL wxios_set_context
+#endif
 
     DO ilev=1,klev
@@ -687,6 +691,15 @@
        CALL histwrite_phy(o_fsnow, zfra_o)
        CALL histwrite_phy(o_evap, evap)
-       CALL histwrite_phy(o_tops, topsw*swradcorr)
-       CALL histwrite_phy(o_tops0, topsw0*swradcorr)
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = topsw*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_tops, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = topsw0*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_tops0, zx_tmp_fi2d)
+
        CALL histwrite_phy(o_topl, toplw)
        CALL histwrite_phy(o_topl0, toplw0)
@@ -716,14 +729,41 @@
        ENDIF
        CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
-       CALL histwrite_phy(o_SWup200, SWup200*swradcorr)
-       CALL histwrite_phy(o_SWup200clr, SWup200clr*swradcorr)
-       CALL histwrite_phy(o_SWdn200, SWdn200*swradcorr)
-       CALL histwrite_phy(o_SWdn200clr, SWdn200clr*swradcorr)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWup200*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWup200, zx_tmp_fi2d)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWup200clr*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWup200clr, zx_tmp_fi2d)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWdn200*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWdn200, zx_tmp_fi2d)
+       
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWdn200clr*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWdn200clr, zx_tmp_fi2d)
+       
        CALL histwrite_phy(o_LWup200, LWup200)
        CALL histwrite_phy(o_LWup200clr, LWup200clr)
        CALL histwrite_phy(o_LWdn200, LWdn200)
        CALL histwrite_phy(o_LWdn200clr, LWdn200clr)
-       CALL histwrite_phy(o_sols, solsw*swradcorr)
-       CALL histwrite_phy(o_sols0, solsw0*swradcorr)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = solsw*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_sols, zx_tmp_fi2d)
+       
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = solsw0*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_sols0, zx_tmp_fi2d)
        CALL histwrite_phy(o_soll, sollw)
        CALL histwrite_phy(o_soll0, sollw0)
@@ -896,8 +936,17 @@
        CALL histwrite_phy(o_cldt, cldt)
        CALL histwrite_phy(o_JrNt, JrNt)
-       CALL histwrite_phy(o_cldljn, cldl*JrNt)
-       CALL histwrite_phy(o_cldmjn, cldm*JrNt)
-       CALL histwrite_phy(o_cldhjn, cldh*JrNt)
-       CALL histwrite_phy(o_cldtjn, cldt*JrNt)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldl*JrNt      
+       CALL histwrite_phy(o_cldljn, zx_tmp_fi2d)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldm*JrNt      
+       CALL histwrite_phy(o_cldmjn, zx_tmp_fi2d)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldh*JrNt
+       CALL histwrite_phy(o_cldhjn, zx_tmp_fi2d)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldt*JrNt
+       CALL histwrite_phy(o_cldtjn, zx_tmp_fi2d)
+       
        CALL histwrite_phy(o_cldq, cldq)
        IF (vars_defined)       zx_tmp_fi2d(1:klon) = flwp(1:klon)
@@ -1050,4 +1099,6 @@
              CALL histwrite_phy(o_alp_wk, alp_wake)
              IF (iflag_pbl_split>=1) THEN
+               !ym warning : dtvdf_x, dtvdf_w, dqvdf_x, dqvdf_w are not defined by model
+               !ym => init to 0 in phys_local_var_mod
                IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dtvdf_x(1:klon,1:klev)/pdtphys
                CALL histwrite_phy(o_dtvdf_x    ,zx_tmp_fi3d) 
@@ -1085,5 +1136,5 @@
              IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
              CALL histwrite_phy(o_dqwak, zx_tmp_fi3d)
-             CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+             IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
              CALL histwrite_phy(o_dqwak2d, zx_tmp_fi2d)
           ENDIF ! iflag_wake>=1
@@ -1251,13 +1302,18 @@
 
 ! ThL -- In the following, we assume read_climoz == 1
-       zx_tmp_fi2d = 0.0    ! Computation for strato, added ThL
-       DO k=1, klev
-          zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * stratomask(:,k) * 1.e3
-       END DO
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = 0.0    ! Computation for strato, added ThL
+         DO k=1, klev
+            zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * stratomask(:,k) * 1.e3
+         END DO
+       ENDIF
        CALL histwrite_phy(o_col_O3_strato, zx_tmp_fi2d) ! Added ThL
-       zx_tmp_fi2d = 0.0    ! Computation for tropo, added ThL
-       DO k=1, klev
-          zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * (1.0-stratomask(:,k)) * 1.e3
-       END DO
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = 0.0    ! Computation for tropo, added ThL
+         DO k=1, klev
+            zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * (1.0-stratomask(:,k)) * 1.e3
+         END DO
+       ENDIF
        CALL histwrite_phy(o_col_O3_tropo, zx_tmp_fi2d)   ! Added ThL
 ! end add ThL
@@ -1296,8 +1352,16 @@
 #endif
        IF (ok_ade) THEN
-          CALL histwrite_phy(o_topswad, topswad_aero*swradcorr)
-          CALL histwrite_phy(o_topswad0, topswad0_aero*swradcorr)
-          CALL histwrite_phy(o_solswad, solswad_aero*swradcorr)
-          CALL histwrite_phy(o_solswad0, solswad0_aero*swradcorr)
+          IF (vars_defined) zx_tmp_fi2d(:)=topswad_aero*swradcorr
+          CALL histwrite_phy(o_topswad, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=topswad0_aero*swradcorr
+          CALL histwrite_phy(o_topswad0, zx_tmp_fi2d)
+                    
+          IF (vars_defined) zx_tmp_fi2d(:)=solswad_aero*swradcorr
+          CALL histwrite_phy(o_solswad, zx_tmp_fi2d)
+                    
+          IF (vars_defined) zx_tmp_fi2d(:)=solswad0_aero*swradcorr
+          CALL histwrite_phy(o_solswad0, zx_tmp_fi2d)
+          
           IF (type_trac .ne. 'inca') THEN 
              IF (config_inca .ne. 'aeNP') THEN 
@@ -1310,34 +1374,37 @@
           !====MS forcing diagnostics
           IF (new_aod) THEN
-             zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
+          !ym warning : topsw_aero, solsw_aero, topsw0_aero, solsw0_aero are not defined by model
+          !ym => init to 0 in radlwsw_m.F90 ztopsw_aero, zsolsw_aero, ztopsw0_aero, zsolsw0_aero
+
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swtoaas_nat,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw_aero(:,1)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swsrfas_nat,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=topsw0_aero(:,1)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw0_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swtoacs_nat,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw0_aero(:,1)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw0_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swsrfcs_nat,zx_tmp_fi2d)
              !ant
-             zx_tmp_fi2d(:)=topsw_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swtoaas_ant,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swsrfas_ant,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=topsw0_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw0_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swtoacs_ant,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw0_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw0_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swsrfcs_ant,zx_tmp_fi2d)
              !cf
              IF (.not. aerosol_couple) THEN
-                zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_nat,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=solswcf_aero(:,1)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,1)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_nat,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=topswcf_aero(:,2)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,2)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_ant,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=solswcf_aero(:,2)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,2)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_ant,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=topswcf_aero(:,3)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,3)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_zero,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_zero,zx_tmp_fi2d)
              ENDIF
@@ -1346,8 +1413,15 @@
        ENDIF
        IF (ok_aie) THEN
-          CALL histwrite_phy(o_topswai, topswai_aero*swradcorr)
-          CALL histwrite_phy(o_toplwai, toplwai_aero*swradcorr)
-          CALL histwrite_phy(o_solswai, solswai_aero*swradcorr)
-          CALL histwrite_phy(o_sollwai, sollwai_aero*swradcorr)
+          IF (vars_defined) zx_tmp_fi2d(:)= topswai_aero*swradcorr
+          CALL histwrite_phy(o_topswai, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=toplwai_aero*swradcorr
+          CALL histwrite_phy(o_toplwai, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=solswai_aero*swradcorr
+          CALL histwrite_phy(o_solswai, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=sollwai_aero*swradcorr
+          CALL histwrite_phy(o_sollwai, zx_tmp_fi2d)
        ENDIF
        IF (flag_aerosol.GT.0.AND.ok_cdnc) THEN
@@ -1374,5 +1448,8 @@
        CALL histwrite_phy(o_ovap, q_seri)
        CALL histwrite_phy(o_oliq, ql_seri)
-       CALL histwrite_phy(o_ocond, ql_seri+qs_seri)
+
+       IF (vars_defined) zx_tmp_fi3d = ql_seri+qs_seri
+       CALL histwrite_phy(o_ocond, zx_tmp_fi3d)
+
        CALL histwrite_phy(o_geop, zphi)
        CALL histwrite_phy(o_vitu, u_seri)
@@ -1381,5 +1458,7 @@
        CALL histwrite_phy(o_pres, pplay)
        CALL histwrite_phy(o_paprs, paprs(:,1:klev))
-       CALL histwrite_phy(o_zfull,zphi/RG)
+       
+       IF (vars_defined) zx_tmp_fi3d = zphi/RG
+       CALL histwrite_phy(o_zfull,zx_tmp_fi3d)
 
        IF (flag_aerosol_strat.EQ.2) THEN
@@ -1411,10 +1490,11 @@
        CALL histwrite_phy(o_rnebjn, zx_tmp_fi3d)
        CALL histwrite_phy(o_rhum, zx_rh)
-       CALL histwrite_phy(o_ozone, &
-            wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
+       
+       IF (vars_defined) zx_tmp_fi3d = wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd
+       CALL histwrite_phy(o_ozone, zx_tmp_fi3d)
 
        IF (read_climoz == 2) THEN
-          CALL histwrite_phy(o_ozone_light, &
-               wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
+         IF (vars_defined) zx_tmp_fi3d = wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd 
+         CALL histwrite_phy(o_ozone_light, zx_tmp_fi3d)
        ENDIF
 
@@ -1424,14 +1504,14 @@
 
        CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
-       CALL water_int(klon,klev,d_qx(:,:,ivap),zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,ivap),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqphy2d,  zx_tmp_fi2d)
 
        CALL histwrite_phy(o_dqlphy,  d_qx(:,:,iliq))
-       CALL water_int(klon,klev,d_qx(:,:,iliq),zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,iliq),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqlphy2d,  zx_tmp_fi2d)
 
        IF (nqo.EQ.3) THEN
        CALL histwrite_phy(o_dqsphy,  d_qx(:,:,isol))
-       CALL water_int(klon,klev,d_qx(:,:,isol),zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,isol),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqsphy2d,  zx_tmp_fi2d)
        ELSE 
@@ -1518,5 +1598,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqcon2d, zx_tmp_fi2d)
 
@@ -1540,5 +1620,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqlsc, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqlsc2d, zx_tmp_fi2d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
@@ -1553,9 +1633,9 @@
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
-          CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqlscth2d, zx_tmp_fi2d)
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
-          CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqlscst2d, zx_tmp_fi2d)
           CALL histwrite_phy(o_plulth, plul_th)
@@ -1587,5 +1667,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqvdf, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqvdf2d, zx_tmp_fi2d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
@@ -1593,5 +1673,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqeva, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqeva2d, zx_tmp_fi2d)
        zpt_conv = 0.
@@ -1634,5 +1714,5 @@
           ENDIF
           CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
-          CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqthe2d, zx_tmp_fi2d)
        ENDIF !iflag_thermals
@@ -1641,5 +1721,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqajs2d, zx_tmp_fi2d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys
@@ -1677,6 +1757,10 @@
 
        IF (ok_hines) THEN
-          CALL histwrite_phy(o_du_gwd_hines, du_gwd_hines/pdtphys)
-          CALL histwrite_phy(o_dv_gwd_hines, dv_gwd_hines/pdtphys)
+          IF (vars_defined) zx_tmp_fi3d=du_gwd_hines/pdtphys
+          CALL histwrite_phy(o_du_gwd_hines, zx_tmp_fi3d)
+
+          IF (vars_defined) zx_tmp_fi3d= dv_gwd_hines/pdtphys          
+          CALL histwrite_phy(o_dv_gwd_hines, zx_tmp_fi3d)
+          
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
@@ -1686,6 +1770,10 @@
 
        IF (.not. ok_hines .and. ok_gwd_rando) THEN
-          CALL histwrite_phy(o_du_gwd_front, du_gwd_front / pdtphys)
-          CALL histwrite_phy(o_dv_gwd_front, dv_gwd_front / pdtphys)
+          IF (vars_defined)  zx_tmp_fi3d=du_gwd_front / pdtphys
+          CALL histwrite_phy(o_du_gwd_front, zx_tmp_fi3d)
+          
+          IF (vars_defined)  zx_tmp_fi3d=dv_gwd_front / pdtphys
+          CALL histwrite_phy(o_dv_gwd_front, zx_tmp_fi3d)
+          
           CALL histwrite_phy(o_ustr_gwd_front, zustr_gwd_front)
           CALL histwrite_phy(o_vstr_gwd_front, zvstr_gwd_front)
@@ -1693,6 +1781,9 @@
 
        IF (ok_gwd_rando) THEN
-          CALL histwrite_phy(o_du_gwd_rando, du_gwd_rando / pdtphys)
-          CALL histwrite_phy(o_dv_gwd_rando, dv_gwd_rando / pdtphys)
+          IF (vars_defined)  zx_tmp_fi3d=du_gwd_rando / pdtphys
+          CALL histwrite_phy(o_du_gwd_rando, zx_tmp_fi3d)
+          
+          IF (vars_defined)  zx_tmp_fi3d=dv_gwd_rando / pdtphys
+          CALL histwrite_phy(o_dv_gwd_rando, zx_tmp_fi3d)
           CALL histwrite_phy(o_ustr_gwd_rando, zustr_gwd_rando)
           CALL histwrite_phy(o_vstr_gwd_rando, zvstr_gwd_rando)
@@ -1702,22 +1793,38 @@
 
        IF (ok_qch4) THEN
-          CALL histwrite_phy(o_dqch4, d_q_ch4 / pdtphys)
-       ENDIF
-
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swup(:,k)*swradcorr(:)
-       ENDDO
+          IF (vars_defined) zx_tmp_fi3d=d_q_ch4 / pdtphys
+          CALL histwrite_phy(o_dqch4, zx_tmp_fi3d)
+       ENDIF
+       
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swup(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
+       
        CALL histwrite_phy(o_rsu, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swdn(:,k)*swradcorr(:)
-       ENDDO
+
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swdn(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
+       
        CALL histwrite_phy(o_rsd, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swup0(:,k)*swradcorr(:)
-       ENDDO
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swup0(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
+       
        CALL histwrite_phy(o_rsucs, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swdn0(:,k)*swradcorr(:)
-       ENDDO
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swdn0(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
        CALL histwrite_phy(o_rsdcs, zx_tmp_fi3d1)
 
@@ -1773,5 +1880,6 @@
        ELSE IF (iflag_con == 2) THEN
           CALL histwrite_phy(o_mcd,  pmfd)
-          CALL histwrite_phy(o_dmc,  pmfu + pmfd)
+          IF (vars_defined) zx_tmp_fi3d = pmfu + pmfd
+          CALL histwrite_phy(o_dmc,  zx_tmp_fi3d)
        ENDIF
        CALL histwrite_phy(o_ref_liq, ref_liq)
@@ -1954,20 +2062,20 @@
             IF (type_trac == 'lmdz' .OR. type_trac == 'repr' .OR. type_trac == 'coag') THEN
              !--3D fields
-             CALL histwrite_phy(o_trac(iq-nqo), tr_seri(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_vdf(iq-nqo),d_tr_cl(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_the(iq-nqo),d_tr_th(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_con(iq-nqo),d_tr_cv(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_lessi_impa(iq-nqo),d_tr_lessi_impa(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_lessi_nucl(iq-nqo),d_tr_lessi_nucl(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_insc(iq-nqo),d_tr_insc(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_bcscav(iq-nqo),d_tr_bcscav(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_evapls(iq-nqo),d_tr_evapls(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_ls(iq-nqo),d_tr_ls(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_trsp(iq-nqo),d_tr_trsp(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_sscav(iq-nqo),d_tr_sscav(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_sat(iq-nqo),d_tr_sat(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_uscav(iq-nqo),d_tr_uscav(:,:,iq-nqo))
+!             CALL histwrite_phy(o_trac(iq-nqo), tr_seri(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_vdf(iq-nqo),d_tr_cl(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_the(iq-nqo),d_tr_th(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_con(iq-nqo),d_tr_cv(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_lessi_impa(iq-nqo),d_tr_lessi_impa(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_lessi_nucl(iq-nqo),d_tr_lessi_nucl(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_insc(iq-nqo),d_tr_insc(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_bcscav(iq-nqo),d_tr_bcscav(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_evapls(iq-nqo),d_tr_evapls(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_ls(iq-nqo),d_tr_ls(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_trsp(iq-nqo),d_tr_trsp(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_sscav(iq-nqo),d_tr_sscav(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_sat(iq-nqo),d_tr_sat(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_uscav(iq-nqo),d_tr_uscav(:,:,iq-nqo))
              !--2D fields
-             CALL histwrite_phy(o_dtr_dry(iq-nqo), flux_tr_dry(:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_dry(iq-nqo), flux_tr_dry(:,iq-nqo))
              zx_tmp_fi2d=0.
              IF (vars_defined) THEN
@@ -1976,5 +2084,5 @@
                 ENDDO
              ENDIF
-             CALL histwrite_phy(o_trac_cum(iq-nqo), zx_tmp_fi2d)
+!             CALL histwrite_phy(o_trac_cum(iq-nqo), zx_tmp_fi2d)
             ENDIF
           ENDDO
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_state_var_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/phys_state_var_mod.F90	(revision 3406)
@@ -607,6 +607,8 @@
         du_gwd_rando(:,:)=0.
       ENDIF
-      if (.not. ok_hines .and. ok_gwd_rando) allocate(du_gwd_front(klon, klev))
-
+      IF (.not. ok_hines .and. ok_gwd_rando) THEN
+        ALLOCATE(du_gwd_front(klon, klev))
+        du_gwd_front(:,:) = 0 !ym missing init   
+      ENDIF
 END SUBROUTINE phys_state_var_init
 
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/physiq_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/physiq_mod.F90	(revision 3406)
@@ -25,5 +25,5 @@
     USE dimphy
     USE infotrac_phy, ONLY: nqtot, nbtr, nqo, type_trac
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, klon_glo
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, klon_glo, grid1dTo2d_glo, grid_type, unstructured
     USE mod_phys_lmdz_para
     USE iophy
@@ -252,4 +252,11 @@
     use ACAMA_GWD_rando_m, only: ACAMA_GWD_rando
     USE VERTICAL_LAYERS_MOD, ONLY: aps,bps
+    USE etat0_limit_unstruct_mod
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_update_calendar, xios_context_finalize
+#endif
+    USE climoz_mod
+    USE limit_read_mod, ONLY : init_limit_read
+    USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
 
 
@@ -1129,4 +1136,7 @@
     CALL update_time(pdtphys)
     phys_tstep=NINT(pdtphys)
+#ifdef CPP_XIOS
+    IF (.NOT. debut .AND. is_omp_master) CALL xios_update_calendar(itap+1)
+#endif
 
     !======================================================================
@@ -1161,4 +1171,6 @@
 
     IF (first) THEN 
+       CALL init_etat0_limit_unstruct
+       IF (.NOT. create_etat0_limit) CALL init_limit_read(days_elapsed)
        !CR:nvelles variables convection/poches froides
 
@@ -1184,4 +1196,6 @@
        CALL phys_state_var_init(read_climoz)
        CALL phys_output_var_init
+       IF(read_climoz>=1 .AND. create_etat0_limit) CALL regr_horiz_time_climoz(read_climoz,ok_daily_climoz)
+
        print*, '================================================='
        !
@@ -1394,6 +1408,107 @@
        CALL init_iophy_new(latitude_deg,longitude_deg)
 
-
+          !===================================================================
+          !IM stations CFMIP
+          nCFMIP=npCFMIP
+          OPEN(98,file='npCFMIP_param.data',status='old', &
+               form='formatted',iostat=iostat)
+          IF (iostat == 0) THEN
+             READ(98,*,end=998) nCFMIP
+998          CONTINUE
+             CLOSE(98)
+             CONTINUE
+             IF(nCFMIP.GT.npCFMIP) THEN
+                print*,'nCFMIP > npCFMIP : augmenter npCFMIP et recompiler'
+                CALL abort_physic("physiq", "", 1)
+             ELSE
+                print*,'physiq npCFMIP=',npCFMIP,'nCFMIP=',nCFMIP
+             ENDIF
+
+             !
+             ALLOCATE(tabCFMIP(nCFMIP))
+             ALLOCATE(lonCFMIP(nCFMIP), latCFMIP(nCFMIP))
+             ALLOCATE(tabijGCM(nCFMIP))
+             ALLOCATE(lonGCM(nCFMIP), latGCM(nCFMIP))
+             ALLOCATE(iGCM(nCFMIP), jGCM(nCFMIP))
+             !
+             ! lecture des nCFMIP stations CFMIP, de leur numero 
+             ! et des coordonnees geographiques lonCFMIP, latCFMIP
+             !
+             CALL read_CFMIP_point_locations(nCFMIP, tabCFMIP,  &
+                  lonCFMIP, latCFMIP)
+             !
+             ! identification des
+             ! 1) coordonnees lonGCM, latGCM des points CFMIP dans la
+             ! grille de LMDZ
+             ! 2) indices points tabijGCM de la grille physique 1d sur
+             ! klon points
+             ! 3) indices iGCM, jGCM de la grille physique 2d
+             !
+             CALL LMDZ_CFMIP_point_locations(nCFMIP, lonCFMIP, latCFMIP, &
+                  tabijGCM, lonGCM, latGCM, iGCM, jGCM)
+             !
+          ELSE
+             ALLOCATE(tabijGCM(0))
+             ALLOCATE(lonGCM(0), latGCM(0))
+             ALLOCATE(iGCM(0), jGCM(0))
+          ENDIF
+
+#ifdef CPP_IOIPSL
+
+       !$OMP MASTER
+       ! FH : if ok_sync=.true. , the time axis is written at each time step
+       ! in the output files. Only at the end in the opposite case
+       ok_sync_omp=.false.
+       CALL getin('ok_sync',ok_sync_omp)
+       CALL phys_output_open(longitude_deg,latitude_deg,nCFMIP,tabijGCM, &
+            iGCM,jGCM,lonGCM,latGCM, &
+            jjmp1,nlevSTD,clevSTD,rlevSTD, phys_tstep,ok_veget, &
+            type_ocean,iflag_pbl,iflag_pbl_split,ok_mensuel,ok_journe, &
+            ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, &
+            read_climoz, phys_out_filestations, &
+            new_aod, aerosol_couple, &
+            flag_aerosol_strat, pdtphys, paprs, pphis,  &
+            pplay, lmax_th, ptconv, ptconvth, ivap,  &
+            d_u, d_t, qx, d_qx, zmasse, ok_sync_omp)
+       !$OMP END MASTER
+       !$OMP BARRIER
+       ok_sync=ok_sync_omp
+
+       freq_outNMC(1) = ecrit_files(7)
+       freq_outNMC(2) = ecrit_files(8)
+       freq_outNMC(3) = ecrit_files(9)
+       WRITE(lunout,*)'OK freq_outNMC(1)=',freq_outNMC(1)
+       WRITE(lunout,*)'OK freq_outNMC(2)=',freq_outNMC(2)
+       WRITE(lunout,*)'OK freq_outNMC(3)=',freq_outNMC(3)
+
+#ifndef CPP_XIOS
+       CALL ini_paramLMDZ_phy(phys_tstep,nid_ctesGCM)
+#endif
+
+#endif
+       ecrit_reg = ecrit_reg * un_jour
+       ecrit_tra = ecrit_tra * un_jour
+
+       !XXXPB Positionner date0 pour initialisation de ORCHIDEE
+       date0 = jD_ref 
+       WRITE(*,*) 'physiq date0 : ',date0
+       !
+
+!       CALL create_climoz(read_climoz)
+
+       CALL phys_output_write(itap, pdtphys, paprs, pphis,                    &
+                              pplay, lmax_th, aerosol_couple,                 &
+                              ok_ade, ok_aie, ivap, iliq, isol, new_aod, ok_sync,&
+                              ptconv, read_climoz, clevSTD,                   &
+                              ptconvth, d_u, d_t, qx, d_qx, zmasse,           &
+                              flag_aerosol, flag_aerosol_strat, ok_cdnc)
+
+#ifdef CPP_XIOS
+       IF (is_omp_master) CALL xios_update_calendar(1)
+#endif
+       IF(read_climoz>=1 .AND. create_etat0_limit) CALL regr_horiz_time_climoz(read_climoz,ok_daily_climoz)
+       CALL create_etat0_limit_unstruct
        CALL phyetat0 ("startphy.nc",clesphy0,tabcntr0)
+
 !jyg<
        IF (klon_glo==1) THEN
@@ -1405,4 +1520,6 @@
             ENDDO
           ENDDO
+        ELSE
+          pbl_tke(:,:,is_ave) = 0. !ym missing init : maybe must be initialized in the same way that for klon_glo==1 ??
 !>jyg
        ENDIF
@@ -1421,7 +1538,4 @@
        ENDIF
 
-       CALL printflag( tabcntr0,radpas,ok_journe, &
-            ok_instan, ok_region )
-       !
 !       IF (ABS(phys_tstep-pdtphys).GT.0.001) THEN
 !          WRITE(lunout,*) 'Pas physique n est pas correct',phys_tstep, &
@@ -1506,53 +1620,8 @@
           !        enddo
 
-          !===================================================================
-          !IM stations CFMIP
-          nCFMIP=npCFMIP
-          OPEN(98,file='npCFMIP_param.data',status='old', &
-               form='formatted',iostat=iostat)
-          IF (iostat == 0) THEN
-             READ(98,*,end=998) nCFMIP
-998          CONTINUE
-             CLOSE(98)
-             CONTINUE
-             IF(nCFMIP.GT.npCFMIP) THEN
-                print*,'nCFMIP > npCFMIP : augmenter npCFMIP et recompiler'
-                CALL abort_physic("physiq", "", 1)
-             ELSE
-                print*,'physiq npCFMIP=',npCFMIP,'nCFMIP=',nCFMIP
-             ENDIF
-
-             !
-             ALLOCATE(tabCFMIP(nCFMIP))
-             ALLOCATE(lonCFMIP(nCFMIP), latCFMIP(nCFMIP))
-             ALLOCATE(tabijGCM(nCFMIP))
-             ALLOCATE(lonGCM(nCFMIP), latGCM(nCFMIP))
-             ALLOCATE(iGCM(nCFMIP), jGCM(nCFMIP))
-             !
-             ! lecture des nCFMIP stations CFMIP, de leur numero 
-             ! et des coordonnees geographiques lonCFMIP, latCFMIP
-             !
-             CALL read_CFMIP_point_locations(nCFMIP, tabCFMIP,  &
-                  lonCFMIP, latCFMIP)
-             !
-             ! identification des
-             ! 1) coordonnees lonGCM, latGCM des points CFMIP dans la
-             ! grille de LMDZ
-             ! 2) indices points tabijGCM de la grille physique 1d sur
-             ! klon points
-             ! 3) indices iGCM, jGCM de la grille physique 2d
-             !
-             CALL LMDZ_CFMIP_point_locations(nCFMIP, lonCFMIP, latCFMIP, &
-                  tabijGCM, lonGCM, latGCM, iGCM, jGCM)
-             !
-          ELSE
-             ALLOCATE(tabijGCM(0))
-             ALLOCATE(lonGCM(0), latGCM(0))
-             ALLOCATE(iGCM(0), jGCM(0))
-          ENDIF
-       ELSE
-          ALLOCATE(tabijGCM(0))
-          ALLOCATE(lonGCM(0), latGCM(0))
-          ALLOCATE(iGCM(0), jGCM(0))
+       !ELSE
+       !   ALLOCATE(tabijGCM(0))
+       !   ALLOCATE(lonGCM(0), latGCM(0))
+       !   ALLOCATE(iGCM(0), jGCM(0))
        ENDIF
 
@@ -1642,43 +1711,7 @@
 #endif 
 
-#ifdef CPP_IOIPSL
-
-       !$OMP MASTER
-       ! FH : if ok_sync=.true. , the time axis is written at each time step
-       ! in the output files. Only at the end in the opposite case
-       ok_sync_omp=.false.
-       CALL getin('ok_sync',ok_sync_omp)
-       CALL phys_output_open(longitude_deg,latitude_deg,nCFMIP,tabijGCM, &
-            iGCM,jGCM,lonGCM,latGCM, &
-            jjmp1,nlevSTD,clevSTD,rlevSTD, phys_tstep,ok_veget, &
-            type_ocean,iflag_pbl,iflag_pbl_split,ok_mensuel,ok_journe, &
-            ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, &
-            read_climoz, phys_out_filestations, &
-            new_aod, aerosol_couple, &
-            flag_aerosol_strat, pdtphys, paprs, pphis,  &
-            pplay, lmax_th, ptconv, ptconvth, ivap,  &
-            d_u, d_t, qx, d_qx, zmasse, ok_sync_omp)
-       !$OMP END MASTER
-       !$OMP BARRIER
-       ok_sync=ok_sync_omp
-
-       freq_outNMC(1) = ecrit_files(7)
-       freq_outNMC(2) = ecrit_files(8)
-       freq_outNMC(3) = ecrit_files(9)
-       WRITE(lunout,*)'OK freq_outNMC(1)=',freq_outNMC(1)
-       WRITE(lunout,*)'OK freq_outNMC(2)=',freq_outNMC(2)
-       WRITE(lunout,*)'OK freq_outNMC(3)=',freq_outNMC(3)
-
-#ifndef CPP_XIOS
-       CALL ini_paramLMDZ_phy(phys_tstep,nid_ctesGCM)
-#endif
-
-#endif
-       ecrit_reg = ecrit_reg * un_jour
-       ecrit_tra = ecrit_tra * un_jour
-
-       !XXXPB Positionner date0 pour initialisation de ORCHIDEE
-       date0 = jD_ref 
-       WRITE(*,*) 'physiq date0 : ',date0
+
+       CALL printflag( tabcntr0,radpas,ok_journe, &
+            ok_instan, ok_region )
        !
        !
@@ -2207,4 +2240,7 @@
        !
        !-------gustiness calculation-------!
+       !ym : Warning gustiness non inialized for iflag_gusts=2 & iflag_gusts=3
+       gustiness=0  !ym missing init
+       
        IF (iflag_gusts==0) THEN
           gustiness(1:klon)=0
@@ -4034,4 +4070,5 @@
 
     IF (.not. ok_hines .and. ok_gwd_rando) then
+       ! ym missing init for east_gwstress & west_gwstress -> added in phys_local_var_mod
        CALL acama_GWD_rando(PHYS_TSTEP, pplay, latitude_deg, t_seri, u_seri, &
             v_seri, rot, zustr_gwd_front, zvstr_gwd_front, du_gwd_front, &
@@ -4696,5 +4733,5 @@
        !         write(97) u_seri,v_seri,t_seri,q_seri
        !         close(97)
-       !$OMP MASTER
+!       !$OMP MASTER
        IF (read_climoz >= 1) THEN
           IF (is_mpi_root) THEN
@@ -4704,5 +4741,8 @@
           DEALLOCATE(press_cen_climoz) ! pointer
        ENDIF
-       !$OMP END MASTER
+!       !$OMP END MASTER
+#ifdef CPP_XIOS
+       IF (is_omp_master) CALL xios_context_finalize
+#endif
     ENDIF
 
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/radlwsw_m.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/radlwsw_m.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/radlwsw_m.F90	(revision 3406)
@@ -384,4 +384,9 @@
   cgaero(:,:,:,:)=0.
   lldebug=.FALSE.
+
+  ztopsw_aero(:,:)  = 0. !ym missing init : warning : not initialized in SW_AEROAR4
+  ztopsw0_aero(:,:) = 0. !ym missing init : warning : not initialized in SW_AEROAR4
+  zsolsw_aero(:,:)  = 0. !ym missing init : warning : not initialized in SW_AEROAR4
+  zsolsw0_aero(:,:) = 0. !ym missing init : warning : not initialized in SW_AEROAR4
   
   !
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/regr_horiz_time_climoz_m.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/regr_horiz_time_climoz_m.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/regr_horiz_time_climoz_m.F90	(revision 3406)
@@ -2,5 +2,5 @@
 
   USE interpolation,     ONLY: locate
-  USE mod_grid_phy_lmdz, ONLY: nlon_ou => nbp_lon, nlat_ou => nbp_lat
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, grid_type, unstructured
   USE nrtype,            ONLY: pi
   USE netcdf,   ONLY: NF90_CLOBBER, NF90_FLOAT,     NF90_GET_VAR, NF90_OPEN,   &
@@ -11,4 +11,5 @@
           NF95_CLOSE, NF95_ENDDEF,  NF95_PUT_ATT,   NF95_PUT_VAR, NF95_COPY_ATT
   USE print_control_mod, ONLY: lunout
+  USE dimphy
   IMPLICIT NONE
   PRIVATE
@@ -16,4 +17,6 @@
   REAL, PARAMETER :: deg2rad=pi/180.
   CHARACTER(LEN=13), PARAMETER :: vars_in(2)=['tro3         ','tro3_daylight']
+
+  INTEGER :: nlat_ou, nlon_ou
 
 CONTAINS
@@ -52,5 +55,6 @@
   USE assert_m,           ONLY: assert
   USE cal_tools_m,        ONLY: year_len, mid_month
-  USE control_mod,        ONLY: anneeref
+!!  USE control_mod,        ONLY: anneeref
+  USE time_phylmdz_mod,   ONLY: annee_ref
   USE ioipsl,             ONLY: ioget_year_len, ioget_calendar
   USE regr_conserv_m,     ONLY: regr_conserv
@@ -58,4 +62,7 @@
   USE regular_lonlat_mod, ONLY: boundslon_reg, boundslat_reg, south, west, east
   USE slopes_m,           ONLY: slopes
+  USE xios
+  USE mod_phys_lmdz_mpi_data, only: is_mpi_root
+  USE mod_phys_lmdz_para, ONLY: gather, bcast
 !-------------------------------------------------------------------------------
 ! Arguments:
@@ -83,5 +90,7 @@
   CHARACTER(LEN=20) :: cal_in              ! Calendar
   REAL, ALLOCATABLE :: o3_in3(:,:,:,:,:)   ! Ozone climatologies
+  REAL, ALLOCATABLE :: o3_in3bis(:,:,:,:,:)   ! Ozone climatologies
   REAL, ALLOCATABLE :: o3_in2  (:,:,:,:)   ! Ozone climatologies
+  REAL, ALLOCATABLE :: o3_in2bis(:,:,:,:,:)   ! Ozone climatologies
   ! last index: 1 for the day-night average, 2 for the daylight field.
   REAL :: NaN
@@ -91,6 +100,8 @@
   REAL, ALLOCATABLE :: o3_regr_lonlat(:,:,:,:,:) ! (nlon_ou,nlat_ou,:,0:13   ,:)
   REAL, ALLOCATABLE :: o3_out3       (:,:,:,:,:) ! (nlon_ou,nlat_ou,:,ntim_ou,:)
+  REAL, ALLOCATABLE :: o3_out3_glo   (:,:,:,:) !   (nbp_lat,:,ntim_ou,:)
   REAL, ALLOCATABLE :: o3_regr_lat     (:,:,:,:) !         (nlat_in,:,0:13   ,:)
   REAL, ALLOCATABLE :: o3_out2         (:,:,:,:) !         (nlat_ou,:,ntim_ou,:)
+  REAL, ALLOCATABLE :: o3_out2_glo     (:,:,:,:) !         (nbp_lat,:,ntim_ou,:)
 ! Dimension number  | Interval                | Contains  | For variables:
 !   1 (longitude)   | [rlonu(i-1), rlonu(i)]  | rlonv(i)  | all
@@ -116,105 +127,319 @@
   INTEGER, ALLOCATABLE :: sta(:), cnt(:)
   CHARACTER(LEN=80) :: sub, dim_nam, msg
-!-------------------------------------------------------------------------------
-  sub="regr_horiz_time_climoz"
-  WRITE(lunout,*)"Call sequence information: "//TRIM(sub)
-  CALL assert(read_climoz == 1 .OR. read_climoz == 2, "regr_lat_time_climoz")
-
-  CALL  NF95_OPEN("climoz.nc"  , NF90_NOWRITE, fID_in)
-  lprev=NF90_OPEN("climoz_m.nc", NF90_NOWRITE, fID_in_m)==NF90_NOERR
-  lnext=NF90_OPEN("climoz_p.nc", NF90_NOWRITE, fID_in_p)==NF90_NOERR
-
-  !--- Get coordinates from the input file. Converts lon/lat in radians.
-  !    Few inversions because "regr_conserv" and gcm need ascending vectors.
-  CALL NF95_INQ_VARID(fID_in, vars_in(1), varid)
-  CALL NF95_INQUIRE_VARIABLE(fID_in, varid, dimids=dIDs, ndims=ndims)
-  l3D=ndims==4; l2D=ndims==3
-  IF(l3D) WRITE(lunout,*)"Input files contain full 3D ozone fields."
-  IF(l2D) WRITE(lunout,*)"Input files contain zonal 2D ozone fields."
-  DO i=1,ndims
-    CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), name=dim_nam, nclen=dln)
-    CALL NF95_INQ_VARID(fID_in, dim_nam, varid)
-    ii=i; IF(l2D) ii=i+1                              !--- ndims==3:NO LONGITUDE 
-    SELECT CASE(ii)
-      CASE(1)                                         !--- LONGITUDE
-        CALL NF95_GW_VAR(fID_in, varid, lon_in)
-        ldec_lon=lon_in(1)>lon_in(dln); IF(ldec_lon) lon_in=lon_in(dln:1:-1)
-        nlon_in=dln; lon_in=lon_in*deg2rad
-      CASE(2)                                         !--- LATITUDE
-        CALL NF95_GW_VAR(fID_in, varid, lat_in)
-        ldec_lat=lat_in(1)>lat_in(dln); IF(ldec_lat) lat_in=lat_in(dln:1:-1)
-        nlat_in=dln; lat_in=lat_in*deg2rad
-      CASE(3)                                         !--- PRESSURE LEVELS
-        CALL NF95_GW_VAR(fID_in, varid, lev_in)
-        ldec_lev=lev_in(1)>lev_in(dln); IF(ldec_lev) lev_in=lev_in(dln:1:-1)
-        nlev_in=dln
-        CALL NF95_GET_ATT(fID_in, varid, "units", press_unit)
-        k=LEN_TRIM(press_unit)
-        DO WHILE(ICHAR(press_unit(k:k))==0)
-          press_unit(k:k)=' '; k=LEN_TRIM(press_unit) !--- REMOVE NULL END CHAR
-        END DO
-        IF(press_unit ==  "Pa") THEN
-          lev_in = lev_in/100.                        !--- CONVERT TO hPa
-        ELSE IF(press_unit /= "hPa") THEN
-          CALL abort_physic(sub, "the only recognized units are Pa and hPa.",1)
-        END IF
-      CASE(4)                                         !--- TIME
-        CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), nclen=nmth_in)
-        cal_in='gregorian'
-        IF(NF90_GET_ATT(fID_in, varid, 'calendar', cal_in)/=NF90_NOERR)        &
+  REAL :: null_array(0)
+  LOGICAL,SAVE :: first=.TRUE.
+!$OMP THREADPRIVATE(first)  
+  REAL, ALLOCATABLE :: test_o3_in(:,:)
+  REAL, ALLOCATABLE :: test_o3_out(:)
+  
+  nlat_ou=nbp_lat
+  nlon_ou=nbp_lon
+  
+!-------------------------------------------------------------------------------
+  IF (is_mpi_root) THEN
+    sub="regr_horiz_time_climoz"
+    WRITE(lunout,*)"Call sequence information: "//TRIM(sub)
+    CALL assert(read_climoz == 1 .OR. read_climoz == 2, "regr_lat_time_climoz")
+
+    CALL  NF95_OPEN("climoz.nc"  , NF90_NOWRITE, fID_in)
+    lprev=NF90_OPEN("climoz_m.nc", NF90_NOWRITE, fID_in_m)==NF90_NOERR
+    lnext=NF90_OPEN("climoz_p.nc", NF90_NOWRITE, fID_in_p)==NF90_NOERR
+
+    !--- Get coordinates from the input file. Converts lon/lat in radians.
+    !    Few inversions because "regr_conserv" and gcm need ascending vectors.
+    CALL NF95_INQ_VARID(fID_in, vars_in(1), varid)
+    CALL NF95_INQUIRE_VARIABLE(fID_in, varid, dimids=dIDs, ndims=ndims)
+    l3D=ndims==4; l2D=ndims==3
+    IF(l3D) WRITE(lunout,*)"Input files contain full 3D ozone fields."
+    IF(l2D) WRITE(lunout,*)"Input files contain zonal 2D ozone fields."
+    DO i=1,ndims
+      CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), name=dim_nam, nclen=dln)
+      CALL NF95_INQ_VARID(fID_in, dim_nam, varid)
+      ii=i; IF(l2D) ii=i+1                              !--- ndims==3:NO LONGITUDE 
+      SELECT CASE(ii)
+        CASE(1)                                         !--- LONGITUDE
+          CALL NF95_GW_VAR(fID_in, varid, lon_in)
+          ldec_lon=lon_in(1)>lon_in(dln); IF(ldec_lon) lon_in=lon_in(dln:1:-1)
+          nlon_in=dln; lon_in=lon_in*deg2rad
+        CASE(2)                                         !--- LATITUDE
+          CALL NF95_GW_VAR(fID_in, varid, lat_in)
+          ldec_lat=lat_in(1)>lat_in(dln); IF(ldec_lat) lat_in=lat_in(dln:1:-1)
+          nlat_in=dln; lat_in=lat_in*deg2rad
+        CASE(3)                                         !--- PRESSURE LEVELS
+          CALL NF95_GW_VAR(fID_in, varid, lev_in)
+          ldec_lev=lev_in(1)>lev_in(dln); IF(ldec_lev) lev_in=lev_in(dln:1:-1)
+          nlev_in=dln
+          CALL NF95_GET_ATT(fID_in, varid, "units", press_unit)
+          k=LEN_TRIM(press_unit)
+          DO WHILE(ICHAR(press_unit(k:k))==0)
+            press_unit(k:k)=' '; k=LEN_TRIM(press_unit) !--- REMOVE NULL END CHAR
+          END DO
+          IF(press_unit ==  "Pa") THEN
+            lev_in = lev_in/100.                        !--- CONVERT TO hPa
+          ELSE IF(press_unit /= "hPa") THEN
+            CALL abort_physic(sub, "the only recognized units are Pa and hPa.",1)
+          END IF
+        CASE(4)                                         !--- TIME
+          CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), nclen=nmth_in)
+          cal_in='gregorian'
+          IF(NF90_GET_ATT(fID_in, varid, 'calendar', cal_in)/=NF90_NOERR)        &  
           WRITE(lunout,*)'WARNING: missing "calendar" attribute for "'//       &
           TRIM(dim_nam)//'" in "climoz.nc". Choosing default: "gregorian".'
-        k=LEN_TRIM(cal_in)
-        DO WHILE(ICHAR(cal_in(k:k))==0)
-          cal_in(k:k)=' '; k=LEN_TRIM(cal_in)         !--- REMOVE NULL END CHAR
+          k=LEN_TRIM(cal_in)
+          DO WHILE(ICHAR(cal_in(k:k))==0)
+            cal_in(k:k)=' '; k=LEN_TRIM(cal_in)         !--- REMOVE NULL END CHAR
+          END DO
+      END SELECT
+    END DO
+
+    !--- Prepare quantities for time interpolation
+    tmidmonth=mid_month(annee_ref, cal_in)
+    IF(interpt) THEN
+      ntim_ou=ioget_year_len(annee_ref)
+      ALLOCATE(tmidday(ntim_ou))
+      tmidday=[(REAL(k)-0.5,k=1,ntim_ou)]
+      CALL ioget_calendar(cal_ou)
+    ELSE
+      ntim_ou=14
+      cal_ou=cal_in
+    END IF
+  ENDIF
+
+  IF (grid_type==unstructured) THEN
+    CALL bcast(nlon_in)
+    CALL bcast(nlat_in)
+    CALL bcast(nlev_in)
+    CALL bcast(l3d)
+    CALL bcast(tmidmonth)
+    CALL bcast(tmidday)
+    CALL bcast(ntim_ou)
+  ENDIF  
+  
+  IF (is_mpi_root) THEN
+    CALL xios_set_domain_attr("domain_climoz",nj_glo=nlat_in, nj=nlat_in, jbegin=0, latvalue_1d=lat_in/deg2rad)
+    IF (l3D) THEN
+      CALL xios_set_domain_attr("domain_climoz",ni_glo=nlon_in, ni=nlon_in, ibegin=0, lonvalue_1d=lon_in/deg2rad)
+    ELSE
+      CALL xios_set_domain_attr("domain_climoz",ni_glo=8, ni=8, ibegin=0, lonvalue_1d = (/ 0.,45.,90.,135.,180.,225.,270., 315. /))
+    ENDIF
+  ELSE
+    CALL xios_set_domain_attr("domain_climoz",nj_glo=nlat_in, nj=0, jbegin=0, latvalue_1d=null_array )
+    IF (l3D) THEN
+      CALL xios_set_domain_attr("domain_climoz",ni_glo=nlon_in, ni=0, ibegin=0, lonvalue_1d=null_array)
+    ELSE
+      CALL xios_set_domain_attr("domain_climoz",ni_glo=8, ni=0, ibegin=0, lonvalue_1d=null_array)
+    ENDIF
+  ENDIF
+  CALL  xios_set_axis_attr("axis_climoz", n_glo=nlev_in)
+  CALL  xios_set_axis_attr("time_axis_climoz", n_glo=ntim_ou)
+  CALL  xios_set_axis_attr("time_axis_climoz", n_glo=ntim_ou)
+  CALL  xios_set_axis_attr("tr_climoz", n_glo=read_climoz)
+  CALL  xios_set_field_attr("tro3_out", enabled=.TRUE.)
+  CALL  xios_set_field_attr("tro3_out", enabled=.TRUE.)
+      
+  IF (first .AND. grid_type==unstructured) THEN
+    first=.FALSE.
+    RETURN
+  ENDIF
+  
+  
+  IF (is_mpi_root) THEN     
+    !--- Longitudes management:
+    !    * Need to shift data if the origin of input file longitudes /= -pi
+    !    * Need to add some margin in longitude to ensure input interval contains
+    !      all the output intervals => at least one longitudes slice has to be
+    !      duplicated, possibly more for undersampling.
+    IF(l3D) THEN
+      IF (grid_type==unstructured) THEN
+        dx2=0
+      ELSE
+        !--- Compute input edges longitudes vector (no end point yet)
+        ALLOCATE(v1(nlon_in+1))
+        v1(1)=(lon_in(nlon_in)+lon_in(1))/2.-pi
+        FORALL(i=2:nlon_in) v1(i)=(lon_in(i-1)+lon_in(i))/2.
+        v1(nlon_in+1)=v1(1)+2.*pi
+        DEALLOCATE(lon_in)
+
+        !--- Shift input longitudes vector until it contains first output point boundslon_reg(1,west)
+        v1=v1+2*pi*REAL(FLOOR((boundslon_reg(1,west)-v1(1))/(2.*pi)))
+
+        !--- Ensure first input longitudes interval contains first output point boundslon_reg(1,west)
+        dx1=locate(v1,boundslon_reg(1,west))-1
+        v1=CSHIFT(v1,SHIFT=dx1,DIM=1); v1(nlon_in-dx1+1:)=v1(nlon_in-dx1+1:)+2.*pi
+  
+        !--- Extend input longitudes vector until last interval contains boundslon_reg(nlat_ou,east)
+        dx2=0; DO WHILE(v1(1+dx2)+2.*pi<boundslon_reg(nlon_ou,east)); dx2=dx2+1; END DO
+
+        !--- Final edges longitudes vector (with margin and end point)
+        ALLOCATE(lon_in_edge(nlon_in+dx2+1)); lon_in_edge=[v1,v1(2:1+dx2)+2.*pi]
+        DEALLOCATE(v1)
+      ENDIF
+    END IF
+
+    !--- Compute sinus of intervals edges latitudes:
+    ALLOCATE(sinlat_in_edge(nlat_in+1))
+    sinlat_in_edge(1) = -1. ; sinlat_in_edge(nlat_in+1) = 1.
+    FORALL(j=2:nlat_in) sinlat_in_edge(j)=SIN((lat_in(j-1)+lat_in(j))/2.)
+    DEALLOCATE(lat_in)
+
+
+
+    !--- Check for contiguous years:
+    ib=0; ie=13
+    IF(nmth_in == 14) THEN; lprev=.FALSE.; lnext=.FALSE.
+      WRITE(lunout,*)'Using 14 months ozone climatology "climoz.nc"...'
+    ELSE  
+      IF(     lprev) WRITE(lunout,*)'Using "climoz_m.nc" last record (previous year).'
+      IF(.NOT.lprev) WRITE(lunout,*)"No previous year file ; assuming periodicity."
+      IF(     lnext) WRITE(lunout,*)'Using "climoz_p.nc" first record (next year).'
+      IF(.NOT.lnext) WRITE(lunout,*)"No next year file ; assuming periodicity."
+      IF(.NOT.lprev) ib=1
+      IF(.NOT.lnext) ie=12
+    END IF
+    ALLOCATE(sta(ndims),cnt(ndims)); sta(:)=1  
+    IF(l3D) cnt=[nlon_in,nlat_in,nlev_in,1]
+    IF(l2D) cnt=[        nlat_in,nlev_in,1]  
+    IF(l3D) ALLOCATE(o3_in3(nlon_in+dx2,nlat_in,nlev_in,ib:ie,read_climoz))
+    IF(l2D) ALLOCATE(o3_in2(            nlat_in,nlev_in,ib:ie,read_climoz))
+
+    !--- Read full current file and one record each available contiguous file
+    DO iv=1,read_climoz
+      msg=TRIM(sub)//" NF90_GET_VAR "//TRIM(vars_in(iv))
+      CALL NF95_INQ_VARID(fID_in, vars_in(1), vID_in(iv))
+      IF(l3D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in3(1:nlon_in,:,:,1:12,iv))
+      IF(l2D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in2(          :,:,1:12,iv))
+      CALL handle_err(TRIM(msg), ncerr, fID_in)
+      IF(lprev) THEN; sta(ndims)=12  
+        CALL NF95_INQ_VARID(fID_in_m, vars_in(1), vID_in(iv))
+        IF(l3D) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in3(1:nlon_in,:,:, 0,iv),sta,cnt)
+        IF(l2d) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in2(          :,:, 0,iv),sta,cnt)
+        CALL handle_err(TRIM(msg)//" previous", ncerr, fID_in_m)
+      END IF
+      IF(lnext) THEN; sta(ndims)=1  
+        CALL NF95_INQ_VARID(fID_in_p, vars_in(1), vID_in(iv))
+        IF(l3D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in3(1:nlon_in,:,:,13,iv),sta,cnt)
+        IF(l2D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in2(          :,:,13,iv),sta,cnt)
+        CALL handle_err(TRIM(msg)//" next", ncerr, fID_in_p)
+      END IF
+    END DO
+    IF(lprev.OR.lnext) DEALLOCATE(sta,cnt)
+    IF(lprev) CALL NF95_CLOSE(fID_in_m)
+    IF(lnext) CALL NF95_CLOSE(fID_in_p)
+
+    !--- Revert decreasing coordinates vector
+    IF(l3D) THEN
+      IF(ldec_lon) o3_in3(1:nlon_in,:,:,:,:) = o3_in3(nlon_in:1:-1,:,:,:,:)
+      IF(ldec_lat) o3_in3 = o3_in3(:,nlat_in:1:-1,:,:,:)
+      IF(ldec_lev) o3_in3 = o3_in3(:,:,nlev_in:1:-1,:,:)
+      
+      IF (grid_type /= unstructured) THEN
+        !--- Shift values for longitude and duplicate some longitudes slices
+        o3_in3(1:nlon_in,:,:,:,:)=CSHIFT(o3_in3(1:nlon_in,:,:,:,:),SHIFT=dx1,DIM=1)
+        o3_in3(nlon_in+1:nlon_in+dx2,:,:,:,:)=o3_in3(1:dx2,:,:,:,:)
+      ENDIF
+    ELSE
+      IF(ldec_lat) o3_in2 = o3_in2(  nlat_in:1:-1,:,:,:)
+      IF(ldec_lev) o3_in2 = o3_in2(  :,nlev_in:1:-1,:,:)
+    END IF
+
+   !--- Deal with missing values 
+    DO m=1, read_climoz
+      WRITE(msg,'(a,i0)')"regr_lat_time_climoz: field Nr.",m
+      IF(NF90_GET_ATT(fID_in,vID_in(m),"missing_value",NaN)/= NF90_NOERR) THEN
+        IF(NF90_GET_ATT(fID_in, vID_in(m),"_FillValue",NaN)/= NF90_NOERR) THEN
+          WRITE(lunout,*)TRIM(msg)//": no missing value attribute found."; CYCLE
+        END IF
+      END IF
+      WRITE(lunout,*)TRIM(msg)//": missing value attribute found."
+      WRITE(lunout,*)"Trying to fill in NaNs ; a full field would be better."
+
+      !--- Check top layer contains no NaNs & search NaNs from top to ground
+      msg=TRIM(sub)//": NaNs in top layer !"
+      IF(l3D) THEN
+        IF(ANY(o3_in3(:,:,1,:,m)==NaN)) CALL abort_physic(sub,msg,1)
+        DO k = 2,nlev_in
+          WHERE(o3_in3(:,:,k,:,m)==NaN) o3_in3(:,:,k,:,m)=o3_in3(:,:,k-1,:,m)
         END DO
-    END SELECT
-  END DO
-
-  !--- Longitudes management:
-  !    * Need to shift data if the origin of input file longitudes /= -pi
-  !    * Need to add some margin in longitude to ensure input interval contains
-  !      all the output intervals => at least one longitudes slice has to be
-  !      duplicated, possibly more for undersampling.
-  IF(l3D) THEN
-    !--- Compute input edges longitudes vector (no end point yet)
-    ALLOCATE(v1(nlon_in+1))
-    v1(1)=(lon_in(nlon_in)+lon_in(1))/2.-pi
-    FORALL(i=2:nlon_in) v1(i)=(lon_in(i-1)+lon_in(i))/2.
-    v1(nlon_in+1)=v1(1)+2.*pi
-    DEALLOCATE(lon_in)
-
-    !--- Shift input longitudes vector until it contains first output point boundslon_reg(1,west)
-    v1=v1+2*pi*REAL(FLOOR((boundslon_reg(1,west)-v1(1))/(2.*pi)))
-
-    !--- Ensure first input longitudes interval contains first output point boundslon_reg(1,west)
-    dx1=locate(v1,boundslon_reg(1,west))-1
-    v1=CSHIFT(v1,SHIFT=dx1,DIM=1); v1(nlon_in-dx1+1:)=v1(nlon_in-dx1+1:)+2.*pi
-
-    !--- Extend input longitudes vector until last interval contains boundslon_reg(nlat_ou,east)
-    dx2=0; DO WHILE(v1(1+dx2)+2.*pi<boundslon_reg(nlon_ou,east)); dx2=dx2+1; END DO
-
-    !--- Final edges longitudes vector (with margin and end point)
-    ALLOCATE(lon_in_edge(nlon_in+dx2+1)); lon_in_edge=[v1,v1(2:1+dx2)+2.*pi]
-    DEALLOCATE(v1)
-  END IF
-
-  !--- Compute sinus of intervals edges latitudes:
-  ALLOCATE(sinlat_in_edge(nlat_in+1))
-  sinlat_in_edge(1) = -1. ; sinlat_in_edge(nlat_in+1) = 1.
-  FORALL(j=2:nlat_in) sinlat_in_edge(j)=SIN((lat_in(j-1)+lat_in(j))/2.)
-  DEALLOCATE(lat_in)
-
-  !--- Prepare quantities for time interpolation
-  tmidmonth=mid_month(anneeref, cal_in)
-  IF(interpt) THEN
-    ntim_ou=ioget_year_len(anneeref)
-    ALLOCATE(tmidday(ntim_ou))
-    tmidday=[(REAL(k)-0.5,k=1,ntim_ou)]
-    CALL ioget_calendar(cal_ou)
-  ELSE
-    ntim_ou=14
-    cal_ou=cal_in
-  END IF
+      ELSE
+        IF(ANY(o3_in2(  :,1,:,m)==NaN)) THEN
+          WRITE(lunout,*)msg
+          !--- Fill in latitudes where all values are missing
+          DO l=1,nmth_in
+            !--- Next to south pole
+            j=1;       DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
+            IF(j>1) &
+              o3_in2(:j-1,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=j-1)
+            !--- Next to north pole
+            j=nlat_in; DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
+            IF(j<nlat_in) &
+              o3_in2(j+1:,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=nlat_in-j)
+          END DO
+        END IF
+
+        !--- Fill in high latitudes missing values
+        !--- Highest level been filled-in, so has always valid values.
+        DO k = 2,nlev_in
+          WHERE(o3_in2(:,k,:,m)==NaN) o3_in2(:,k,:,m)=o3_in2(:,k-1,:,m)
+        END DO
+      END IF
+    END DO
+
+  ENDIF
+  
+  !=============================================================================
+  IF(l3D) THEN                                                   !=== 3D FIELDS
+  !=============================================================================
+   IF (grid_type==unstructured) THEN
+     nlat_ou=klon
+     
+     IF (is_mpi_root) THEN 
+       ALLOCATE(o3_in3bis(nlon_in,nlat_in,nlev_in,0:13,read_climoz)) 
+       o3_in3bis(:,:,:,ib:ie,:)=o3_in3(1:nlon_in,:,:,ib:ie,:)
+     ELSE
+       ALLOCATE(o3_in3bis(0,0,0,0,read_climoz))
+     ENDIF
+     ALLOCATE(o3_regr_lonlat(1, nlat_ou, nlev_in, 0:13, read_climoz))
+     
+     CALL xios_send_field("tro3_in",o3_in3bis(:,:,:,:,:))
+     CALL xios_recv_field("tro3_out",o3_regr_lonlat(1,:,:,:,:))
+
+   ELSE
+        
+     !--- Regrid in longitude
+      ALLOCATE(o3_regr_lon(nlon_ou, nlat_in, nlev_in, ie-ib+1, read_climoz))
+      CALL regr_conserv(1, o3_in3, xs = lon_in_edge,                             &
+                          xt = [boundslon_reg(1,west),boundslon_reg(:,east)],    &
+                          vt = o3_regr_lon, slope = slopes(1,o3_in3, lon_in_edge))
+      DEALLOCATE(o3_in3)
+
+      !--- Regrid in latitude: averaging with respect to SIN(lat) is
+      !                        equivalent to weighting by COS(lat)
+      !--- (inverted indices in "o3_regr_lonlat" because "rlatu" is decreasing)
+      ALLOCATE(o3_regr_lonlat(nlon_ou, nlat_ou, nlev_in, 0:13, read_climoz))
+      CALL regr_conserv(2, o3_regr_lon, xs = sinlat_in_edge,                     &
+                      xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
+                      vt = o3_regr_lonlat(:,nlat_ou:1:- 1,:,ib:ie,:),            &
+                 slope = slopes(2,o3_regr_lon, sinlat_in_edge))
+      DEALLOCATE(o3_regr_lon)
+
+   ENDIF
+
+   !--- Duplicate previous/next record(s) if they are not available
+   IF(.NOT.lprev) o3_regr_lonlat(:,:,:, 0,:) = o3_regr_lonlat(:,:,:,12,:)
+   IF(.NOT.lnext) o3_regr_lonlat(:,:,:,13,:) = o3_regr_lonlat(:,:,:, 1,:)
+    
+   !--- Regrid in time by linear interpolation:
+   ALLOCATE(o3_out3(nlon_ou, nlat_ou, nlev_in, ntim_ou, read_climoz))
+   IF(     interpt) CALL regr_lint(4,o3_regr_lonlat,tmidmonth,tmidday,o3_out3)
+   IF(.NOT.interpt) o3_out3=o3_regr_lonlat
+   DEALLOCATE(o3_regr_lonlat)
+
+   nlat_ou=nbp_lat
+   IF (grid_type==unstructured) THEN
+     CALL xios_send_field('o3_out',o3_out3)
+     ndims=3 
+     ALLOCATE(o3_out3_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
+     CALL gather(o3_out3(1,:,:,:,:), o3_out3_glo)
+   ENDIF
 
   !--- Create the output file and get the variable IDs:
@@ -222,159 +447,70 @@
                    ndims, cal_ou)
 
-  !--- Write remaining coordinate variables:
-  CALL NF95_PUT_VAR(fID_ou, levID_ou, lev_in); DEALLOCATE(lev_in)
-  IF(     interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidday)
-  IF(.NOT.interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidmonth)
-
-  !--- Check for contiguous years:
-  ib=0; ie=13
-  IF(nmth_in == 14) THEN; lprev=.FALSE.; lnext=.FALSE.
-    WRITE(lunout,*)'Using 14 months ozone climatology "climoz.nc"...'
-  ELSE
-    IF(     lprev) WRITE(lunout,*)'Using "climoz_m.nc" last record (previous year).'
-    IF(.NOT.lprev) WRITE(lunout,*)"No previous year file ; assuming periodicity."
-    IF(     lnext) WRITE(lunout,*)'Using "climoz_p.nc" first record (next year).'
-    IF(.NOT.lnext) WRITE(lunout,*)"No next year file ; assuming periodicity."
-    IF(.NOT.lprev) ib=1
-    IF(.NOT.lnext) ie=12
-  END IF
-  ALLOCATE(sta(ndims),cnt(ndims)); sta(:)=1
-  IF(l3D) cnt=[nlon_in,nlat_in,nlev_in,1]
-  IF(l2D) cnt=[        nlat_in,nlev_in,1]
-  IF(l3D) ALLOCATE(o3_in3(nlon_in+dx2,nlat_in,nlev_in,ib:ie,read_climoz))
-  IF(l2D) ALLOCATE(o3_in2(            nlat_in,nlev_in,ib:ie,read_climoz))
-
-  !--- Read full current file and one record each available contiguous file
-  DO iv=1,read_climoz
-    msg=TRIM(sub)//" NF90_GET_VAR "//TRIM(vars_in(iv))
-    CALL NF95_INQ_VARID(fID_in, vars_in(1), vID_in(iv))
-    IF(l3D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in3(1:nlon_in,:,:,1:12,iv))
-    IF(l2D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in2(          :,:,1:12,iv))
-    CALL handle_err(TRIM(msg), ncerr, fID_in)
-    IF(lprev) THEN; sta(ndims)=12
-      CALL NF95_INQ_VARID(fID_in_m, vars_in(1), vID_in(iv))
-      IF(l3D) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in3(1:nlon_in,:,:, 0,iv),sta,cnt)
-      IF(l2d) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in2(          :,:, 0,iv),sta,cnt)
-      CALL handle_err(TRIM(msg)//" previous", ncerr, fID_in_m)
-    END IF
-    IF(lnext) THEN; sta(ndims)=1
-      CALL NF95_INQ_VARID(fID_in_p, vars_in(1), vID_in(iv))
-      IF(l3D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in3(1:nlon_in,:,:,13,iv),sta,cnt)
-      IF(l2D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in2(          :,:,13,iv),sta,cnt)
-      CALL handle_err(TRIM(msg)//" next", ncerr, fID_in_p)
-    END IF
-  END DO
-  IF(lprev.OR.lnext) DEALLOCATE(sta,cnt)
-  IF(lprev) CALL NF95_CLOSE(fID_in_m)
-  IF(lnext) CALL NF95_CLOSE(fID_in_p)
-
-  !--- Revert decreasing coordinates vector
-  IF(l3D) THEN
-    IF(ldec_lon) o3_in3(1:nlon_in,:,:,:,:) = o3_in3(nlon_in:1:-1,:,:,:,:)
-    IF(ldec_lat) o3_in3 = o3_in3(:,nlat_in:1:-1,:,:,:)
-    IF(ldec_lev) o3_in3 = o3_in3(:,:,nlev_in:1:-1,:,:)
-    !--- Shift values for longitude and duplicate some longitudes slices
-    o3_in3(1:nlon_in,:,:,:,:)=CSHIFT(o3_in3(1:nlon_in,:,:,:,:),SHIFT=dx1,DIM=1)
-    o3_in3(nlon_in+1:nlon_in+dx2,:,:,:,:)=o3_in3(1:dx2,:,:,:,:)
-  ELSE
-    IF(ldec_lat) o3_in2 = o3_in2(  nlat_in:1:-1,:,:,:)
-    IF(ldec_lev) o3_in2 = o3_in2(  :,nlev_in:1:-1,:,:)
-  END IF
-
- !--- Deal with missing values
-  DO m=1, read_climoz
-    WRITE(msg,'(a,i0)')"regr_lat_time_climoz: field Nr.",m
-    IF(NF90_GET_ATT(fID_in,vID_in(m),"missing_value",NaN)/= NF90_NOERR) THEN
-      IF(NF90_GET_ATT(fID_in, vID_in(m),"_FillValue",NaN)/= NF90_NOERR) THEN
-        WRITE(lunout,*)TRIM(msg)//": no missing value attribute found."; CYCLE
-      END IF
-    END IF
-    WRITE(lunout,*)TRIM(msg)//": missing value attribute found."
-    WRITE(lunout,*)"Trying to fill in NaNs ; a full field would be better."
-
-    !--- Check top layer contains no NaNs & search NaNs from top to ground
-    msg=TRIM(sub)//": NaNs in top layer !"
-    IF(l3D) THEN
-      IF(ANY(o3_in3(:,:,1,:,m)==NaN)) CALL abort_physic(sub,msg,1)
-      DO k = 2,nlev_in
-        WHERE(o3_in3(:,:,k,:,m)==NaN) o3_in3(:,:,k,:,m)=o3_in3(:,:,k-1,:,m)
-      END DO
-    ELSE
-      IF(ANY(o3_in2(  :,1,:,m)==NaN)) THEN
-        WRITE(lunout,*)msg
-        !--- Fill in latitudes where all values are missing
-        DO l=1,nmth_in
-          !--- Next to south pole
-          j=1;       DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
-          IF(j>1) &
-            o3_in2(:j-1,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=j-1)
-          !--- Next to north pole
-          j=nlat_in; DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
-          IF(j<nlat_in) &
-            o3_in2(j+1:,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=nlat_in-j)
+  IF (is_mpi_root) THEN
+    !--- Write remaining coordinate variables:
+    CALL NF95_PUT_VAR(fID_ou, levID_ou, lev_in); DEALLOCATE(lev_in)
+    IF(     interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidday)
+    IF(.NOT.interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidmonth)
+
+    !--- Write to file (the order of "rlatu" is inverted in the output file):
+      IF (grid_type==unstructured) THEN
+        DO m = 1, read_climoz
+          CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out3_glo(nlat_ou:1:-1,:,:,m))
         END DO
-      END IF
-
-      !--- Fill in high latitudes missing values
-      !--- Highest level been filled-in, so has always valid values.
-      DO k = 2,nlev_in
-        WHERE(o3_in2(:,k,:,m)==NaN) o3_in2(:,k,:,m)=o3_in2(:,k-1,:,m)
-      END DO
-    END IF
-  END DO
-  CALL NF95_CLOSE(fID_in)
-
-  !=============================================================================
-  IF(l3D) THEN                                                   !=== 3D FIELDS
-  !=============================================================================
-    !--- Regrid in longitude
-    ALLOCATE(o3_regr_lon(nlon_ou, nlat_in, nlev_in, ie-ib+1, read_climoz))
-    CALL regr_conserv(1, o3_in3, xs = lon_in_edge,                             &
-                        xt = [boundslon_reg(1,west),boundslon_reg(:,east)],    &
-                        vt = o3_regr_lon, slope = slopes(1,o3_in3, lon_in_edge))
-    DEALLOCATE(o3_in3)
-
-    !--- Regrid in latitude: averaging with respect to SIN(lat) is
-    !                        equivalent to weighting by COS(lat)
-    !--- (inverted indices in "o3_regr_lonlat" because "rlatu" is decreasing)
-    ALLOCATE(o3_regr_lonlat(nlon_ou, nlat_ou, nlev_in, 0:13, read_climoz))
-    CALL regr_conserv(2, o3_regr_lon, xs = sinlat_in_edge,                     &
-                    xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
-                    vt = o3_regr_lonlat(:,nlat_ou:1:- 1,:,ib:ie,:),            &
-                 slope = slopes(2,o3_regr_lon, sinlat_in_edge))
-    DEALLOCATE(o3_regr_lon)
-
-    !--- Duplicate previous/next record(s) if they are not available
-    IF(.NOT.lprev) o3_regr_lonlat(:,:,:, 0,:) = o3_regr_lonlat(:,:,:,12,:)
-    IF(.NOT.lnext) o3_regr_lonlat(:,:,:,13,:) = o3_regr_lonlat(:,:,:, 1,:)
-
-    !--- Regrid in time by linear interpolation:
-    ALLOCATE(o3_out3(nlon_ou, nlat_ou, nlev_in, ntim_ou, read_climoz))
-    IF(     interpt) CALL regr_lint(4,o3_regr_lonlat,tmidmonth,tmidday,o3_out3)
-    IF(.NOT.interpt) o3_out3=o3_regr_lonlat
-    DEALLOCATE(o3_regr_lonlat)
-
-    !--- Write to file (the order of "rlatu" is inverted in the output file):
-    DO m = 1, read_climoz
-      CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out3(:,nlat_ou:1:-1,:,:,m))
-    END DO
+      ELSE
+        DO m = 1, read_climoz
+          CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out3(:,nlat_ou:1:-1,:,:,m))
+        END DO
+    ENDIF
+    CALL NF95_CLOSE(fID_ou)
+
+
+  ENDIF
+
+
+
+
+
+
+
+
 
   !=============================================================================
   ELSE                                                         !=== ZONAL FIELDS
   !=============================================================================
-    !--- Regrid in latitude: averaging with respect to SIN(lat) is
-    !                        equivalent to weighting by COS(lat)
-    !--- (inverted indices in "o3_regr_lat" because "rlatu" is decreasing)
-    ALLOCATE(o3_regr_lat(nlat_ou, nlev_in, 0:13, read_climoz))
-    CALL regr_conserv(1, o3_in2, xs = sinlat_in_edge,                          &
-                    xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
-                    vt = o3_regr_lat(nlat_ou:1:- 1,:,ib:ie,:),                 &
-                 slope = slopes(1,o3_in2, sinlat_in_edge))
-    DEALLOCATE(o3_in2)
-
-    !--- Duplicate previous/next record(s) if they are not available
-    IF(.NOT.lprev) o3_regr_lat(:,:, 0,:) = o3_regr_lat(:,:,12,:)
-    IF(.NOT.lnext) o3_regr_lat(:,:,13,:) = o3_regr_lat(:,:, 1,:)
-
+ 
+   IF (grid_type==unstructured) THEN
+     nlat_ou=klon
+
+     IF (is_mpi_root) THEN 
+       ALLOCATE(o3_in2bis(8,nlat_in,nlev_in,0:13,read_climoz)) 
+       o3_in2bis(:,:,:,ib:ie,:)=SPREAD(o3_in2,1,8)
+     ELSE
+       ALLOCATE(o3_in2bis(0,0,0,0,read_climoz))
+     ENDIF
+     ALLOCATE(o3_regr_lat(nlat_ou, nlev_in, 0:13, read_climoz))
+     CALL xios_send_field("tro3_in",o3_in2bis(:,:,:,:,:))
+     CALL xios_recv_field("tro3_out",o3_regr_lat(:,:,:,:))
+     IF(.NOT.lprev) o3_regr_lat(:,:, 0, :) = o3_regr_lat(:,:,12,:)
+     IF(.NOT.lnext) o3_regr_lat(:,:,13, :) = o3_regr_lat(:,:, 1,:)
+     
+   
+   ELSE 
+      !--- Regrid in latitude: averaging with respect to SIN(lat) is
+      !                        equivalent to weighting by COS(lat)
+      !--- (inverted indices in "o3_regr_lat" because "rlatu" is decreasing)
+      ALLOCATE(o3_regr_lat(nlat_ou, nlev_in, 0:13, read_climoz))
+      CALL regr_conserv(1, o3_in2, xs = sinlat_in_edge,                          &
+                      xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
+                      vt = o3_regr_lat(nlat_ou:1:- 1,:,ib:ie,:),                 &
+                   slope = slopes(1,o3_in2, sinlat_in_edge))
+      DEALLOCATE(o3_in2)
+
+      !--- Duplicate previous/next record(s) if they are not available
+      IF(.NOT.lprev) o3_regr_lat(:,:, 0,:) = o3_regr_lat(:,:,12,:)
+      IF(.NOT.lnext) o3_regr_lat(:,:,13,:) = o3_regr_lat(:,:, 1,:)
+
+   ENDIF
+   
     !--- Regrid in time by linear interpolation:
     ALLOCATE(o3_out2(nlat_ou, nlev_in, ntim_ou, read_climoz))
@@ -383,8 +519,40 @@
     DEALLOCATE(o3_regr_lat)
 
-    !--- Write to file (the order of "rlatu" is inverted in the output file):
-    DO m = 1, read_climoz
-      CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out2(nlat_ou:1:-1,:,:,m))
-    END DO
+    nlat_ou=nbp_lat
+!    ALLOCATE(o3_out2_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
+!    CALL gather(o3_out2, o3_out2_glo)
+!    CALL xios_send_field('o3_out',o3_out2)
+  
+    IF (grid_type==unstructured) THEN
+      ndims=3 
+      ALLOCATE(o3_out2_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
+      CALL gather(o3_out2, o3_out2_glo)
+    ENDIF
+    
+    !--- Create the output file and get the variable IDs:
+    CALL prepare_out(fID_in,nlev_in,ntim_ou, fID_ou,levID_ou,timID_ou,vID_ou, &
+                       ndims, cal_ou)
+
+    IF (is_mpi_root) THEN
+    
+      !--- Write remaining coordinate variables:
+      CALL NF95_PUT_VAR(fID_ou, levID_ou, lev_in); DEALLOCATE(lev_in)
+      IF(     interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidday)
+      IF(.NOT.interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidmonth)
+
+      IF (grid_type==unstructured) THEN
+        DO m = 1, read_climoz
+          CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out2_glo(nlat_ou:1:-1,:,:,m))
+        END DO
+      ELSE
+        !--- Write to file (the order of "rlatu" is inverted in the output file):
+        DO m = 1, read_climoz
+          CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out2(nlat_ou:1:-1,:,:,m))
+        END DO
+      ENDIF
+      
+      CALL NF95_CLOSE(fID_ou)
+    
+    ENDIF
 
   !=============================================================================
@@ -392,5 +560,5 @@
   !=============================================================================
 
-  CALL NF95_CLOSE(fID_ou)
+  IF (is_mpi_root) CALL NF95_CLOSE(fID_in)
 
 END SUBROUTINE regr_horiz_time_climoz
@@ -408,4 +576,10 @@
 !-------------------------------------------------------------------------------
   USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
+  USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
+  USE geometry_mod, ONLY : latitude_deg
+  USE mod_grid_phy_lmdz, ONLY: klon_glo
+  USE mod_phys_lmdz_mpi_data, only: is_mpi_root
+  USE mod_phys_lmdz_para, ONLY: gather
+!
 !-------------------------------------------------------------------------------
 ! Arguments:
@@ -420,67 +594,78 @@
   INTEGER :: vlonID, vlatID, ncerr,  is
   CHARACTER(LEN=80) :: sub
-!-------------------------------------------------------------------------------
-  sub="prepare_out"
-  WRITE(lunout,*)"CALL sequence information: "//TRIM(sub)
-  CALL NF95_CREATE("climoz_LMDZ.nc", NF90_clobber, fID_ou)
+  REAL :: latitude_glo(klon_glo)
+
+!-------------------------------------------------------------------------------
+
+  IF (grid_type==unstructured) CALL gather(latitude_deg,  latitude_glo)
+  
+  IF (is_mpi_root) THEN  
+    sub="prepare_out"
+    WRITE(lunout,*)"CALL sequence information: "//TRIM(sub)
+    CALL NF95_CREATE("climoz_LMDZ.nc", NF90_clobber, fID_ou)
 
   !--- Dimensions:
-  IF(ndims==4) &
-  CALL NF95_DEF_DIM(fID_ou, "rlonv", nlon_ou, dlonID)
-  CALL NF95_DEF_DIM(fID_ou, "rlatu", nlat_ou, dlatID)
-  CALL NF95_DEF_DIM(fID_ou, "plev",  nlev_in, dlevID)
-  CALL NF95_DEF_DIM(fID_ou, "time",  ntim_ou, dtimID)
-
-  !--- Define coordinate variables:
-  IF(ndims==4) &
-  CALL NF95_DEF_VAR(fID_ou, "rlonv", NF90_FLOAT, dlonID, vlonID)
-  CALL NF95_DEF_VAR(fID_ou, "rlatu", NF90_FLOAT, dlatID, vlatID)
-  CALL NF95_DEF_VAR(fID_ou, "plev",  NF90_FLOAT, dlevID, vlevID)
-  CALL NF95_DEF_VAR(fID_ou, "time",  NF90_FLOAT, dtimID, vtimID)
-  IF(ndims==4) &
-  CALL NF95_PUT_ATT(fID_ou, vlonID, "units", "degrees_east")
-  CALL NF95_PUT_ATT(fID_ou, vlatID, "units", "degrees_north")
-  CALL NF95_PUT_ATT(fID_ou, vlevID, "units", "millibar")
-  CALL NF95_PUT_ATT(fID_ou, vtimID, "units", "days since 2000-1-1")
-  IF(ndims==4) &
-  CALL NF95_PUT_ATT(fID_ou, vlonID, "standard_name", "longitude")
-  CALL NF95_PUT_ATT(fID_ou, vlatID, "standard_name", "latitude")
-  CALL NF95_PUT_ATT(fID_ou, vlevID, "standard_name", "air_pressure")
-  CALL NF95_PUT_ATT(fID_ou, vtimID, "standard_name", "time")
-  CALL NF95_PUT_ATT(fID_ou, vlevID, "long_name",     "air pressure")
-  CALL NF95_PUT_ATT(fID_ou, vtimID, "calendar",      cal_ou)
+    IF(ndims==4) &
+    CALL NF95_DEF_DIM(fID_ou, "rlonv", nlon_ou, dlonID)
+    CALL NF95_DEF_DIM(fID_ou, "rlatu", nlat_ou, dlatID)
+    CALL NF95_DEF_DIM(fID_ou, "plev",  nlev_in, dlevID)
+    CALL NF95_DEF_DIM(fID_ou, "time",  ntim_ou, dtimID)
+
+    !--- Define coordinate variables:
+    IF(ndims==4) &
+    CALL NF95_DEF_VAR(fID_ou, "rlonv", NF90_FLOAT, dlonID, vlonID)
+    CALL NF95_DEF_VAR(fID_ou, "rlatu", NF90_FLOAT, dlatID, vlatID)
+    CALL NF95_DEF_VAR(fID_ou, "plev",  NF90_FLOAT, dlevID, vlevID)
+    CALL NF95_DEF_VAR(fID_ou, "time",  NF90_FLOAT, dtimID, vtimID)
+    IF(ndims==4) &
+    CALL NF95_PUT_ATT(fID_ou, vlonID, "units", "degrees_east")
+    CALL NF95_PUT_ATT(fID_ou, vlatID, "units", "degrees_north")
+    CALL NF95_PUT_ATT(fID_ou, vlevID, "units", "millibar")
+    CALL NF95_PUT_ATT(fID_ou, vtimID, "units", "days since 2000-1-1")
+    IF(ndims==4) &
+    CALL NF95_PUT_ATT(fID_ou, vlonID, "standard_name", "longitude")
+    CALL NF95_PUT_ATT(fID_ou, vlatID, "standard_name", "latitude")
+    CALL NF95_PUT_ATT(fID_ou, vlevID, "standard_name", "air_pressure")
+    CALL NF95_PUT_ATT(fID_ou, vtimID, "standard_name", "time")
+    CALL NF95_PUT_ATT(fID_ou, vlevID, "long_name",     "air pressure")
+    CALL NF95_PUT_ATT(fID_ou, vtimID, "calendar",      cal_ou)
 
   !--- Define the main variables:
-  IF(ndims==3) dIDs(1:3) = [ dlatID, dlevID, dtimID]
-  IF(ndims==4) dIDs=[dlonID, dlatID, dlevID, dtimID]
-  CALL NF95_DEF_VAR(fID_ou, vars_in(1), NF90_FLOAT, dIDs(1:ndims), vID_ou(1))
-  CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "long_name", "ozone mole fraction")
-  CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "standard_name", "mole_fraction_of_ozone&
+    IF(ndims==3) dIDs(1:3) = [ dlatID, dlevID, dtimID]
+    IF(ndims==4) dIDs=[dlonID, dlatID, dlevID, dtimID]
+    CALL NF95_DEF_VAR(fID_ou, vars_in(1), NF90_FLOAT, dIDs(1:ndims), vID_ou(1))
+    CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "long_name", "ozone mole fraction")
+    CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "standard_name", "mole_fraction_of_ozone&
       &_in_air")
-  IF(SIZE(vID_ou) == 2) THEN
-    CALL NF95_DEF_VAR(fID_ou, vars_in(2), NF90_FLOAT, dIDs(1:ndims), vID_ou(2))
-    CALL NF95_PUT_ATT(fID_ou, vID_ou(2), "long_name","ozone mole fraction in da&
-      &ylight")
-  END IF
+    IF(SIZE(vID_ou) == 2) THEN
+      CALL NF95_DEF_VAR(fID_ou, vars_in(2), NF90_FLOAT, dIDs(1:ndims), vID_ou(2))
+      CALL NF95_PUT_ATT(fID_ou, vID_ou(2), "long_name","ozone mole fraction in da&
+        &ylight")
+    END IF
 
   !--- Global attributes:
   ! The following commands, copying attributes, may fail. That is OK.
   ! It should just mean that the attribute is not defined in the input file.
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"Conventions",fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("Conventions")
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"title",      fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("title")
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"institution",fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("institution")
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"source",     fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("source")
-  CALL NF95_PUT_ATT (fID_ou,NF90_GLOBAL,"comment", "Regridded for LMDZ")
-  CALL NF95_ENDDEF(fID_ou)
-
-  !--- Write one of the coordinate variables:
-  IF(ndims==4) CALL NF95_PUT_VAR(fID_ou, vlonID, lon_reg/deg2rad)
-  CALL NF95_PUT_VAR(fID_ou, vlatID, lat_reg(nlat_ou:1:-1)/deg2rad)
-  !    (convert from rad to degrees and sort in ascending order)
-
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"Conventions",fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("Conventions")
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"title",      fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("title")
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"institution",fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("institution")
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"source",     fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("source")
+    CALL NF95_PUT_ATT (fID_ou,NF90_GLOBAL,"comment", "Regridded for LMDZ")
+    CALL NF95_ENDDEF(fID_ou)
+
+    IF (grid_type==unstructured) THEN
+      CALL NF95_PUT_VAR(fID_ou, vlatID, latitude_glo)
+    ELSE
+      !--- Write one of the coordinate variables:
+      IF(ndims==4) CALL NF95_PUT_VAR(fID_ou, vlonID, lon_reg/deg2rad)
+      CALL NF95_PUT_VAR(fID_ou, vlatID, lat_reg(nlat_ou:1:-1)/deg2rad)
+    !    (convert from rad to degrees and sort in ascending order)
+    ENDIF
+  ENDIF
+  
 CONTAINS
 
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/regr_pr_time_av_m.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/regr_pr_time_av_m.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/regr_pr_time_av_m.F90	(revision 3406)
@@ -106,5 +106,5 @@
   USE assert_m,       ONLY: assert
   USE assert_eq_m,    ONLY: assert_eq
-  USE comvert_mod,    ONLY: scaleheight
+!!  USE comvert_mod,    ONLY: scaleheight
   USE interpolation,  ONLY: locate
   USE regr_conserv_m, ONLY: regr_conserv
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/rrtm/suinit.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/rrtm/suinit.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/rrtm/suinit.F90	(revision 3406)
@@ -126,5 +126,7 @@
 ALLOCATE(VDELA  (MAX(JPMXLE,NFLEVG)))
 ALLOCATE(VDELB  (MAX(JPMXLE,NFLEVG)))
+VDELB = 0  !ym missing init
 ALLOCATE( VC      (NFLEVG) )
+VC = 0    !ym missing init
 ALLOCATE( NLOEN   (NPROMA) )
 ALLOCATE( NLOENG   (NPROMA) )
Index: /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/slab_heat_transp_mod.F90
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/slab_heat_transp_mod.F90	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/libf/phylmd/slab_heat_transp_mod.F90	(revision 3406)
@@ -84,5 +84,5 @@
                                   aire_,apoln_,apols_, &
                                   aireu_,airev_,rlatv)
-    USE comconst_mod, ONLY: omeg, rad
+    !!USE comconst_mod, ONLY: omeg, rad
     ! number of points in lon, lat
     IMPLICIT NONE
@@ -104,4 +104,6 @@
     REAL,INTENT(IN) :: airev_(ip1jm)
     REAL,INTENT(IN) :: rlatv(nbp_lat-1)
+    REAL            :: omeg = 7.272205e-05
+    REAL            :: rad = 6371229.
 
     ! Sanity check on dimensions
Index: /LMDZ6/branches/DYNAMICO-conv-GC/makelmdz_fcm
===================================================================
--- /LMDZ6/branches/DYNAMICO-conv-GC/makelmdz_fcm	(revision 3405)
+++ /LMDZ6/branches/DYNAMICO-conv-GC/makelmdz_fcm	(revision 3406)
@@ -267,6 +267,8 @@
   fi
   # source architecture PATH and ENV files
+  set +e
   source arch.env
   source arch.path
+  set -e
 else
   echo "You must define a target architecture"
@@ -324,5 +326,5 @@
    CPP_KEY="$CPP_KEY INCA"
    INCLUDE="$INCLUDE -I${INCA_INCDIR}"
-   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
+   LIB="$LIB -L${INCA_LIBDIR} ${INCA_LIB}"
 fi
 
@@ -335,9 +337,9 @@
 	export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
 	INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
-	LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.MPI1 -lmpp_io"
+	LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
     else
 	CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
 	INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
-	LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.MPI1 -lscrip -lmct -lmpeu"
+	LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
     fi
 fi
@@ -372,5 +374,5 @@
 #    For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments
 #    option orchidee1.9 : Compile with ORCHIDEE version up to the inclusion of OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
-   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
+   INCLUDE="${INCLUDE} ${ORCHIDEE_INCDIR}"
    CPP_KEY="$CPP_KEY CPP_VEGET"
 # temporary, for Orchidee versions 1.9.* (before openmp activation)
@@ -383,10 +385,5 @@
       orch_libs="sechiba parameters stomate parallel orglob"
    fi
-   LIB="${LIB} -L${ORCH_LIBDIR}"
-   for lib in ${orch_libs} ; do
-      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
-         LIB="${LIB} -l${LIBPREFIX}$lib "
-      fi
-   done
+   LIB="${LIB} -L${ORCHIDEE_LIBDIR} ${ORCHIDEE_LIB}"
 elif [[ "$veget" != "false" ]] ; then
    echo "Option -v $veget does not exist"
@@ -422,18 +419,18 @@
 then
    CPP_KEY="$CPP_KEY CPP_IOIPSL"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB}"
 elif [[ $io == mix ]]
 then
    # For now, xios implies also using ioipsl
    CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
 elif [[ $io == xios ]]
 then
    # For now, xios implies also using ioipsl
    CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
 fi
 
@@ -445,6 +442,7 @@
 fi
 
+# NETCDF library include/library paths
 INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
-LIB="$LIB ${NETCDF_LIBDIR}"
+LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}"
 
 ########################################################################
@@ -671,5 +669,7 @@
 
 rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock
+set +e
 ./build_gcm ${fcm_path} -j $job $full
+status=$?
 
 rm -rf tmp_src
@@ -684,2 +684,6 @@
   \rm -f $LIBFGCM/grid/dimensions.h
 fi
+
+if [ $status -ne 0 ]; then
+  exit $status
+fi
