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
 
