Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/climoz_mod.f90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/climoz_mod.f90	(revision 3867)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/climoz_mod.f90	(revision 3867)
@@ -0,0 +1,67 @@
+! This module may contains all subroutine and function used
+! for ozone climatology
+! code re-design is needed
+
+MODULE climoz_mod
+
+
+
+
+
+CONTAINS
+
+
+  SUBROUTINE create_climoz(read_climoz)
+  USE mod_grid_phy_lmdz, ONLY :  grid_type, unstructured
+  USE regr_lat_time_climoz_m
+  USE XIOS
+  IMPLICIT NONE
+  INTEGER, INTENT(IN)  :: read_climoz
+
+    !--- OZONE CLIMATOLOGY
+    IF (grid_type==unstructured) THEN
+    
+      IF(read_climoz>=1) THEN 
+        CALL regr_lat_time_climoz(read_climoz,.FALSE.)
+        CALL xios_set_field_attr( "tro3_reg",  enabled=.TRUE.)
+        CALL xios_set_field_attr( "tro3_read", enabled=.TRUE.)
+        IF (read_climoz==2) THEN
+          CALL xios_set_field_attr( "tro3_daylight_reg",  enabled=.TRUE.)
+          CALL xios_set_field_attr( "tro3_daylight_read", enabled=.TRUE.)
+        ENDIF
+      ENDIF
+    
+    ENDIF
+
+  END SUBROUTINE create_climoz
+
+
+  
+  SUBROUTINE get_ozone_var(name,press_in_edg,paprs,v3)
+  USE dimphy
+  USE xios
+  USE regr1_step_av_m, only: regr1_step_av
+  IMPLICIT NONE
+    CHARACTER(LEN=*), INTENT(in):: name(:) ! of the NetCDF variables      
+    REAL, INTENT(IN):: press_in_edg(:)    ! edges of pressure intervals for input data, in Pa, in strictly ascending order
+    REAL, INTENT(IN):: paprs(:, :) ! (klon, klev + 1)
+    REAL, INTENT(OUT):: v3(:, :, :) ! (klon, klev, size(name))
+    
+    REAL  :: v1(klon, size(press_in_edg) - 1, size(name))
+    INTEGER :: m,i
+    
+    DO m=1,size(name)
+      CALL xios_recv_field(name(m),v1(:,:,m))
+   
+      ! Regrid in pressure at each horizontal position:
+      DO i = 1, klon
+         v3(i, klev:1:-1, m) = regr1_step_av(v1(i,:,m), press_in_edg, &
+              paprs(i, klev+1:1:-1))
+         ! (invert order of indices because "paprs" is in descending order)
+      END DO
+    ENDDO
+
+  END SUBROUTINE get_ozone_var  
+  
+
+END MODULE climoz_mod
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_etat0_limit_unstruct.f90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_etat0_limit_unstruct.f90	(revision 3867)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_etat0_limit_unstruct.f90	(revision 3867)
@@ -0,0 +1,83 @@
+MODULE etat0_limit_unstruct_mod
+
+  LOGICAL, SAVE  :: create_etat0_limit
+!$OMP THREADPRIVATE(create_etat0_limit) 
+
+
+
+
+CONTAINS
+  
+  SUBROUTINE init_etat0_limit_unstruct
+  USE xios
+  USE mod_phys_lmdz_para
+  USE mod_grid_phy_lmdz
+  USE ioipsl, ONLY : getin, ioget_year_len
+  USE time_phylmdz_mod, ONLY : annee_ref
+  IMPLICIT NONE
+  
+    INTEGER :: iflag_phys,i
+    INTEGER :: ndays
+    REAL,ALLOCATABLE :: value(:)
+    
+      IF (grid_type==unstructured) THEN
+        IF (is_master) CALL getin("iflag_phys",iflag_phys)
+        CALL bcast(iflag_phys)
+        
+        IF (is_master) CALL getin('create_etat0_limit',create_etat0_limit) 
+        CALL bcast(create_etat0_limit)
+        
+        ndays=ioget_year_len(annee_ref)
+        ALLOCATE(value(ndays))
+        DO i=1,ndays
+          value(i)=i-1
+        ENDDO
+        
+        CALL xios_set_axis_attr("time_year",n_glo=ndays,value=value) 
+        
+        IF (iflag_phys<100) THEN
+
+          IF (create_etat0_limit) THEN
+            CALL xios_set_fieldgroup_attr("etat0_limit_read",read_access=.TRUE.,enabled=.TRUE.)
+            CALL xios_set_filegroup_attr("etat0_limit_read",enabled=.TRUE.)
+          ENDIF
+      
+        ENDIF
+      
+      ENDIF  
+
+  END SUBROUTINE init_etat0_limit_unstruct
+  
+  SUBROUTINE create_etat0_limit_unstruct
+  USE mod_grid_phy_lmdz
+  USE create_etat0_unstruct_mod
+  USE create_limit_unstruct_mod
+  USE phyaqua_mod
+  USE mod_phys_lmdz_para
+  USE ioipsl, ONLY : getin
+  USE dimphy
+  IMPLICIT NONE
+      INTEGER :: iflag_phys
+  
+      IF (grid_type==unstructured) THEN
+  
+        IF (is_master) CALL getin("iflag_phys",iflag_phys)
+        CALL bcast(iflag_phys)
+
+        IF (iflag_phys<100) THEN
+          IF ( create_etat0_limit) THEN
+              CALL create_etat0_unstruct
+              CALL create_limit_unstruct
+              CALL abort_physic ('create_etat0_limit_unstruct','Initial state file are created, all is fine' ,1)
+          ENDIF 
+        ELSE
+          IF (create_etat0_limit) THEN 
+            CALL iniaqua(klon,iflag_phys)
+            CALL abort_physic ('create_etat0_limit_unstruct','Initial state file are created, all is fine' ,1)
+          ENDIF
+        ENDIF
+      ENDIF
+        
+  END SUBROUTINE create_etat0_limit_unstruct
+  
+END MODULE etat0_limit_unstruct_mod
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_etat0_unstruct.f90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_etat0_unstruct.f90	(revision 3867)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_etat0_unstruct.f90	(revision 3867)
@@ -0,0 +1,152 @@
+MODULE create_etat0_unstruct_mod
+
+
+
+
+
+
+CONTAINS
+
+  SUBROUTINE create_etat0_unstruct
+  USE dimphy
+  USE xios
+  USE infotrac_phy
+  USE fonte_neige_mod
+  USE pbl_surface_mod
+  USE phys_state_var_mod
+  USE indice_sol_mod
+  IMPLICIT NONE
+  INCLUDE 'dimsoil.h'
+
+    REAL,    DIMENSION(klon)                 :: tsol
+    REAL,    DIMENSION(klon)                 :: sn
+    REAL,    DIMENSION(klon)                 :: rads
+    REAL,    DIMENSION(klon)                 :: rugmer
+    REAL,    DIMENSION(klon)                 :: run_off_lic_0
+    REAL,    DIMENSION(klon)                 :: lic
+    REAL,    DIMENSION(klon)                 :: fder
+
+    REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf
+    REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
+    INTEGER :: ji,j,i
+ 
+    CALL xios_recv_field("ts",tsol)
+    CALL xios_recv_field("qs",qsol)
+    CALL xios_recv_field("mask",zmasq)
+    CALL xios_recv_field("landice",lic)
+
+    rads(:)   = 0.0
+    rugmer(:) = 0.001
+    sn(:)     = 0
+
+    WHERE(qsol(:)<0) qsol(:)=0 
+        
+    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
+    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
+
+    pctsrf(:,is_lic)=lic
+    WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
+    WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+
+    pctsrf(:,is_ter)=zmasq(:)
+
+!--- Adequation with soil/sea mask
+    DO ji=1,klon
+      IF(zmasq(ji)>EPSFRA) THEN 
+        IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+          pctsrf(ji,is_lic)=zmasq(ji)
+          pctsrf(ji,is_ter)=0.
+        ELSE
+          pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+          IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+            pctsrf(ji,is_ter)=0.
+            pctsrf(ji,is_lic)=zmasq(ji)
+          END IF 
+        END IF 
+      END IF 
+    END DO 
+    
+! sub-surface ocean and sea ice (sea ice set to zero for start)
+!*******************************************************************************
+    pctsrf(:,is_oce)=(1.-zmasq(:))
+    WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
+!!ym  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
+
+    CALL xios_send_field("check_ts",tsol)
+    CALL xios_send_field("check_qs",qsol)
+    CALL xios_send_field("check_zmasq",zmasq)
+    CALL xios_send_field("check_pctsrf1",pctsrf(:,1))
+    CALL xios_send_field("check_pctsrf2",pctsrf(:,2))
+    CALL xios_send_field("check_pctsrf3",pctsrf(:,3))
+    CALL xios_send_field("check_pctsrf4",pctsrf(:,4))
+    
+! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
+!*******************************************************************************
+    DO i=1,nbsrf
+     ftsol(:,i) = tsol
+    END DO
+  
+    DO i=1,nbsrf
+     snsrf(:,i) = sn
+    END DO
+!albedo SB >>>
+    falb_dir(:,is_ter,:)=0.08; falb_dir(:,is_lic,:)=0.6
+    falb_dir(:,is_oce,:)=0.5;  falb_dir(:,is_sic,:)=0.6
+!albedo SB <<<
+    fevap(:,:) = 0.
+    DO i=1,nbsrf
+     qsolsrf(:,i)=150.
+    END DO
+ 
+    DO i=1,nbsrf 
+      DO j=1,nsoilmx
+        tsoil(:,j,i) = tsol
+      END DO
+    END DO
+ 
+    rain_fall = 0.; snow_fall = 0.
+    solsw = 165.;   sollw = -53.
+    t_ancien = 273.15
+    q_ancien = 0.
+    agesno = 0.
+
+    z0m(:,is_oce) = rugmer(:)
+    z0m(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+    z0m(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+    z0m(:,is_sic) = 0.001
+    z0h(:,:)=z0m(:,:)
+
+    fder = 0.0
+    clwcon = 0.0
+    rnebcon = 0.0
+    ratqs = 0.0
+    run_off_lic_0 = 0.0 
+    rugoro = 0.0
+
+! Before phyredem calling, surface modules and values to be saved in startphy.nc
+! are initialized
+!*******************************************************************************
+    pbl_tke(:,:,:) = 1.e-8 
+    zmax0(:) = 40.
+    f0(:) = 1.e-5
+    sig1(:,:) = 0.
+    w01(:,:) = 0.
+    wake_deltat(:,:) = 0.
+    wake_deltaq(:,:) = 0.
+    wake_s(:) = 0.
+    wake_cstar(:) = 0.
+    wake_fip(:) = 0.
+    wake_pe = 0.
+    fm_therm = 0.
+    entr_therm = 0.
+    detr_therm = 0.
+
+    CALL fonte_neige_init(run_off_lic_0)
+    CALL pbl_surface_init( fder, snsrf, qsolsrf, tsoil )
+    CALL phyredem( "startphy.nc" )
+
+
+  END SUBROUTINE create_etat0_unstruct
+
+
+END MODULE create_etat0_unstruct_mod
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_limit_unstruct.f90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_limit_unstruct.f90	(revision 3867)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/create_limit_unstruct.f90	(revision 3867)
@@ -0,0 +1,243 @@
+MODULE create_limit_unstruct_mod
+    PRIVATE
+    INTEGER, PARAMETER                             :: lmdep=12
+
+    PUBLIC create_limit_unstruct
+
+CONTAINS
+
+  SUBROUTINE create_limit_unstruct
+  USE dimphy
+  USE xios
+  USE ioipsl,             ONLY : ioget_year_len
+  USE time_phylmdz_mod, ONLY : annee_ref
+  USE indice_sol_mod
+  USE phys_state_var_mod
+  IMPLICIT NONE
+    INCLUDE "iniprint.h"
+    REAL,    DIMENSION(klon,lmdep)                 :: sic
+    REAL,    DIMENSION(klon,lmdep)                 :: sst
+    REAL,    DIMENSION(klon,lmdep)                 :: rugos
+    REAL,    DIMENSION(klon,lmdep)                 :: albedo
+    INTEGER                                        :: ndays
+    REAL                                           :: fi_ice(klon)
+    REAL, ALLOCATABLE                              :: sic_year(:,:)
+    REAL, ALLOCATABLE                              :: sst_year(:,:)
+    REAL, ALLOCATABLE                              :: rugos_year(:,:)
+    REAL, ALLOCATABLE                              :: albedo_year(:,:)
+    REAL, ALLOCATABLE                              :: pctsrf_t(:,:,:)
+    REAL, ALLOCATABLE                              :: phy_bil(:,:)
+    INTEGER :: l,k
+    INTEGER :: nbad
+    
+    ndays=ioget_year_len(annee_ref)
+    CALL xios_recv_field("sic_limit",sic)
+    CALL xios_recv_field("sst_limit",sst)
+    CALL xios_recv_field("rugos_limit",rugos)
+    CALL xios_recv_field("albedo_limit",albedo)
+  
+    ALLOCATE(sic_year(klon,ndays))
+    ALLOCATE(sst_year(klon,ndays))
+    ALLOCATE(rugos_year(klon,ndays))
+    ALLOCATE(albedo_year(klon,ndays))
+
+! sic
+    CALL time_interpolation(ndays,sic,'gregorian',sic_year)
+    sic_year(:,:)=sic_year(:,:)/100.  ! convert percent to fraction
+    WHERE(sic_year(:,:)>1.0) sic_year(:,:)=1.0    ! Some fractions have some time large negative values
+    WHERE(sic_year(:,:)<0.0) sic_year(:,:)=0.0    ! probably better to apply alse this filter before horizontal interpolation
+    
+! sst
+    CALL time_interpolation(ndays,sst,'gregorian',sst_year)
+    WHERE(sst_year(:,:)<271.38) sst_year(:,:)=271.38
+
+! rugos    
+    DO l=1, lmdep
+      WHERE(NINT(zmasq(:))/=1) rugos(:,l)=0.001
+    ENDDO
+    CALL time_interpolation(ndays,rugos,'360d',rugos_year)
+
+! albedo    
+    CALL time_interpolation(ndays,albedo,'360d',albedo_year)
+
+
+    ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
+    DO k=1,ndays
+      fi_ice=sic_year(:,k)
+      WHERE(fi_ice>=1.0  ) fi_ice=1.0
+      WHERE(fi_ice<EPSFRA) fi_ice=0.0
+      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
+      pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
+
+!!     IF (icefile==trim(fcpldsic)) THEN           ! SIC=pICE*(1-LIC-TER)
+!!        pctsrf_t(:,is_sic,k)=fi_ice(:)*(1.-pctsrf(:,is_lic)-pctsrf(:,is_ter))
+!!     ELSE IF (icefile==trim(fhistsic)) THEN      ! SIC=pICE
+!!        pctsrf_t(:,is_sic,k)=fi_ice(:)
+!!     ELSE ! icefile==famipsic                    ! SIC=pICE-LIC
+        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
+!     END IF
+      WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
+      WHERE(1.0-zmasq<EPSFRA)
+        pctsrf_t(:,is_sic,k)=0.0
+        pctsrf_t(:,is_oce,k)=0.0
+      ELSEWHERE
+        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
+          pctsrf_t(:,is_sic,k)=1.0-zmasq
+          pctsrf_t(:,is_oce,k)=0.0
+        ELSEWHERE
+          pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
+          WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
+             pctsrf_t(:,is_oce,k)=0.0
+             pctsrf_t(:,is_sic,k)=1.0-zmasq
+          END WHERE
+        END WHERE
+      END WHERE
+      nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
+      nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
+    END DO
+    
+    ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
+
+    CALL xios_send_field("foce_limout",pctsrf_t(:,is_oce,:))
+    CALL xios_send_field("fsic_limout",pctsrf_t(:,is_sic,:))
+    CALL xios_send_field("fter_limout",pctsrf_t(:,is_ter,:))
+    CALL xios_send_field("flic_limout",pctsrf_t(:,is_lic,:))
+    CALL xios_send_field("sst_limout", sst_year)
+    CALL xios_send_field("bils_limout",phy_bil)
+    CALL xios_send_field("alb_limout",albedo_year) 
+    CALL xios_send_field("rug_limout",rugos_year) 
+      
+  END SUBROUTINE create_limit_unstruct
+  
+  
+  SUBROUTINE time_interpolation(ndays,field_in,calendar,field_out)
+  USE pchsp_95_m, only: pchsp_95
+  USE pchfe_95_m, only: pchfe_95
+  USE arth_m, only: arth
+  USE dimphy, ONLY : klon
+  USE ioipsl,             ONLY : ioget_year_len
+  USE time_phylmdz_mod, ONLY : annee_ref
+  IMPLICIT NONE
+   INCLUDE "iniprint.h"
+
+   INTEGER,         INTENT(IN)  :: ndays
+   REAL,            INTENT(IN)  :: field_in(klon,lmdep)
+   CHARACTER(LEN=*),INTENT(IN)  :: calendar
+   REAL,            INTENT(OUT) :: field_out(klon,ndays)
+ 
+   INTEGER :: ndays_in
+   REAL    :: timeyear(lmdep)   
+   REAL    :: yder(lmdep)   
+   INTEGER :: ij,ierr, n_extrap
+   LOGICAL :: skip
+   
+   ndays_in=year_len(annee_ref, calendar)
+   timeyear=mid_months(annee_ref, calendar, lmdep)
+    
+   n_extrap = 0
+   skip=.FALSE.
+   DO ij=1,klon
+     yder = pchsp_95(timeyear, field_in(ij, :), ibeg=2, iend=2, vc_beg=0., vc_end=0.)
+     CALL pchfe_95(timeyear, field_in(ij, :), yder, skip, arth(0., real(ndays_in) / ndays, ndays), field_out(ij, :), ierr)
+     if (ierr < 0) stop 1
+     n_extrap = n_extrap + ierr
+   END DO
+   
+   IF (n_extrap /= 0) then
+     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
+   ENDIF 
+  
+  
+  END SUBROUTINE time_interpolation
+  !-------------------------------------------------------------------------------
+  !
+  FUNCTION year_len(y,cal_in)
+  !
+  !-------------------------------------------------------------------------------
+    USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
+    IMPLICIT NONE
+  !-------------------------------------------------------------------------------
+  ! Arguments:
+    INTEGER                       :: year_len
+    INTEGER,           INTENT(IN) :: y
+    CHARACTER(LEN=*),  INTENT(IN) :: cal_in
+  !-------------------------------------------------------------------------------
+  ! Local variables:
+    CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
+  !-------------------------------------------------------------------------------
+  !--- Getting the input calendar to reset at the end of the function
+    CALL ioget_calendar(cal_out)
+  
+  !--- Unlocking calendar and setting it to wanted one
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+  
+  !--- Getting the number of days in this year
+    year_len=ioget_year_len(y)
+  
+  !--- Back to original calendar
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+  
+  END FUNCTION year_len
+  !
+  !-------------------------------------------------------------------------------
+  
+  
+  !-------------------------------------------------------------------------------
+  !
+  FUNCTION mid_months(y,cal_in,nm)
+  !
+  !-------------------------------------------------------------------------------
+    USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
+    IMPLICIT NONE
+  !-------------------------------------------------------------------------------
+  ! Arguments:
+    INTEGER,                INTENT(IN) :: y               ! year
+    CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
+    INTEGER,                INTENT(IN) :: nm              ! months/year number
+    REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
+  !-------------------------------------------------------------------------------
+  ! Local variables:
+    CHARACTER(LEN=99)                  :: mess            ! error message
+    CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
+    INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
+    INTEGER                            :: m               ! months counter
+    INTEGER                            :: nd              ! number of days
+    INTEGER                            :: k
+  !-------------------------------------------------------------------------------
+    nd=year_len(y,cal_in)
+  
+    IF(nm==12) THEN
+  
+    !--- Getting the input calendar to reset at the end of the function
+      CALL ioget_calendar(cal_out)
+  
+    !--- Unlocking calendar and setting it to wanted one
+      CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+  
+    !--- Getting the length of each month
+      DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
+  
+    !--- Back to original calendar
+      CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+  
+    ELSE IF(MODULO(nd,nm)/=0) THEN
+      WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
+        nm,' months/year. Months number should divide days number.'
+      CALL abort_physic('mid_months',TRIM(mess),1)
+  
+    ELSE
+      mnth=(/(m,m=1,nm,nd/nm)/)
+    END IF
+  
+  !--- Mid-months times
+    mid_months(1)=0.5*REAL(mnth(1))
+    DO k=2,nm
+      mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
+    END DO
+  
+  END FUNCTION mid_months
+  
+
+END MODULE create_limit_unstruct_mod
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/limit_read_mod.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/limit_read_mod.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/limit_read_mod.F90	(revision 3867)
@@ -31,4 +31,22 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+
+  SUBROUTINE init_limit_read(first_day)
+  USE mod_grid_phy_lmdz
+  USE surface_data
+  USE XIOS
+  USE etat0_limit_unstruct_mod, ONLY: create_etat0_limit
+  IMPLICIT NONE
+    INTEGER, INTENT(IN) :: first_day
+    
+    
+    IF ( type_ocean /= 'couple') THEN
+      IF (grid_type==unstructured) THEN
+        IF (.NOT. create_etat0_limit) CALL xios_set_file_attr("limit_read",enabled=.TRUE.,record_offset=first_day)
+      ENDIF  
+    ENDIF
+  
+  END SUBROUTINE init_limit_read
+  
   SUBROUTINE limit_read_frac(itime, dtime, jour, pctsrf_new, is_modified)
 !
@@ -148,5 +166,6 @@
     USE netcdf
     USE indice_sol_mod
-
+    USE XIOS
+    
     IMPLICIT NONE
     
@@ -177,4 +196,10 @@
     REAL, DIMENSION(klon_glo)                 :: rug_glo  ! rugosity at global grid
     REAL, DIMENSION(klon_glo)                 :: alb_glo  ! albedo at global grid
+
+    REAL, DIMENSION(klon_mpi,nbsrf)           :: pct_mpi  ! fraction at global grid
+    REAL, DIMENSION(klon_mpi)                 :: sst_mpi  ! sea-surface temperature at global grid
+    REAL, DIMENSION(klon_mpi)                 :: rug_mpi  ! rugosity at global grid
+    REAL, DIMENSION(klon_mpi)                 :: alb_mpi  ! albedo at global grid
+
     CHARACTER(len=20)                         :: modname='limit_read_mod'     
 
@@ -211,60 +236,109 @@
 
     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.
+
+      IF (grid_type==unstructured) THEN
+
 !$OMP MASTER  ! Only master thread
-       IF (is_mpi_root) THEN ! Only master processus
-
-          ierr = NF90_OPEN ('limit.nc', NF90_NOWRITE, nid)
-          IF (ierr /= NF90_NOERR) CALL abort_physic(modname,&
-               'Pb d''ouverture du fichier de conditions aux limites',1)
-          
-          ! La tranche de donnees a lire:
-          start(1) = 1
-          start(2) = jour
-          epais(1) = klon_glo
-          epais(2) = 1
-
-
-!****************************************************************************************
-! 2) Read fraction if not type_ocean=couple
-!
-!****************************************************************************************
-
-          IF ( type_ocean /= 'couple') THEN
-!
-! Ocean fraction
-             ierr = NF90_INQ_VARID(nid, 'FOCE', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname, 'Le champ <FOCE> est absent',1)
-             
-             ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_oce),start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FOCE>' ,1)
-!
-! Sea-ice fraction
-             ierr = NF90_INQ_VARID(nid, 'FSIC', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FSIC> est absent',1)
-
-             ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_sic),start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FSIC>' ,1)
-
-
-! Read land and continentals fraction only if asked for
-             IF (read_continents .OR. itime == 1) THEN
-!
-! Land fraction
-                ierr = NF90_INQ_VARID(nid, 'FTER', nvarid)
-                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FTER> est absent',1)
-                
-                ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_ter),start,epais)
-                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FTER>',1)
-!
-! Continentale ice fraction
-                ierr = NF90_INQ_VARID(nid, 'FLIC', nvarid)
-                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FLIC> est absent',1)
-
-                ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_lic),start,epais)
-                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FLIC>',1)
-             END IF
+
+
+        IF ( type_ocean /= 'couple') THEN
+
+           CALL xios_recv_field("foce_limin",pct_mpi(:,is_oce))
+           CALL xios_recv_field("fsic_limin",pct_mpi(:,is_sic))
+  !         IF (read_continents .OR. itime == 1) THEN
+             CALL xios_recv_field("fter_limin",pct_mpi(:,is_ter))
+             CALL xios_recv_field("flic_limin",pct_mpi(:,is_lic))
+  !         ENDIF
+         ENDIF! type_ocean /= couple
+         
+         IF ( type_ocean /= 'couple') THEN                    
+             CALL xios_recv_field("sst_limin",sst_mpi)
+         ENDIF
+       
+         IF (.NOT. ok_veget) THEN
+           CALL xios_recv_field("alb_limin",alb_mpi)
+           CALL xios_recv_field("rug_limin",rug_mpi)
+         ENDIF
+
+       IF ( type_ocean /= 'couple') THEN
+          CALL Scatter_omp(sst_mpi,sst)
+          CALL Scatter_omp(pct_mpi(:,is_oce),pctsrf(:,is_oce))
+          CALL Scatter_omp(pct_mpi(:,is_sic),pctsrf(:,is_sic))
+!          IF (read_continents .OR. itime == 1) THEN
+             CALL Scatter_omp(pct_mpi(:,is_ter),pctsrf(:,is_ter))
+             CALL Scatter_omp(pct_mpi(:,is_lic),pctsrf(:,is_lic))
+!          END IF
+       END IF
+
+       IF (.NOT. ok_veget) THEN
+          CALL Scatter_omp(alb_mpi, albedo)
+          CALL Scatter_omp(rug_mpi, rugos)
+       END IF
+
+!$OMP END MASTER
+
+ 
+     ELSE      ! grid_type==regular
+
+!$OMP MASTER  ! Only master thread
+
+       IF (is_mpi_root) THEN ! Only master processus!
+
+            ierr = NF90_OPEN ('limit.nc', NF90_NOWRITE, nid)
+            IF (ierr /= NF90_NOERR) CALL abort_physic(modname,&
+                 'Pb d''ouverture du fichier de conditions aux limites',1)
+            
+            ! La tranche de donnees a lire:
+            start(1) = 1
+            start(2) = jour
+            epais(1) = klon_glo
+            epais(2) = 1
+
+
+  !****************************************************************************************
+  ! 2) Read fraction if not type_ocean=couple
+  !
+  !****************************************************************************************
+
+            IF ( type_ocean /= 'couple') THEN
+  !
+  ! Ocean fraction
+               ierr = NF90_INQ_VARID(nid, 'FOCE', nvarid)
+               IF (ierr /= NF90_NOERR) CALL abort_physic(modname, 'Le champ <FOCE> est absent',1)
+               
+               ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_oce),start,epais)
+               IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FOCE>' ,1)
+  !
+  ! Sea-ice fraction
+               ierr = NF90_INQ_VARID(nid, 'FSIC', nvarid)
+               IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FSIC> est absent',1)
+
+               ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_sic),start,epais)
+               IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FSIC>' ,1)
+
+
+  ! Read land and continentals fraction only if asked for
+               IF (read_continents .OR. itime == 1) THEN
+  !
+  ! Land fraction
+                  ierr = NF90_INQ_VARID(nid, 'FTER', nvarid)
+                  IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FTER> est absent',1)
+                  
+                  ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_ter),start,epais)
+                  IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FTER>',1)
+  !
+  ! Continentale ice fraction
+                  ierr = NF90_INQ_VARID(nid, 'FLIC', nvarid)
+                  IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FLIC> est absent',1)
+
+                  ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_lic),start,epais)
+                  IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FLIC>',1)
+               END IF
+
 
           END IF ! type_ocean /= couple
@@ -289,21 +363,21 @@
 !****************************************************************************************
 
-          IF (.NOT. ok_veget) THEN
-!
-! Read albedo
-             ierr = NF90_INQ_VARID(nid, 'ALB', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <ALB> est absent',1)
-
-             ierr = NF90_GET_VAR(nid,nvarid,alb_glo,start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <ALB>',1)
-!
-! Read rugosity
-             ierr = NF90_INQ_VARID(nid, 'RUG', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <RUG> est absent',1)
-
-             ierr = NF90_GET_VAR(nid,nvarid,rug_glo,start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <RUG>',1)
-
-          END IF
+             IF (.NOT. ok_veget) THEN
+   !
+   ! Read albedo
+                ierr = NF90_INQ_VARID(nid, 'ALB', nvarid)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <ALB> est absent',1)
+
+                ierr = NF90_GET_VAR(nid,nvarid,alb_glo,start,epais)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <ALB>',1)
+   !
+   ! Read rugosity
+                ierr = NF90_INQ_VARID(nid, 'RUG', nvarid)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <RUG> est absent',1)
+
+                ierr = NF90_GET_VAR(nid,nvarid,rug_glo,start,epais)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <RUG>',1)
+
+             END IF
 
 !****************************************************************************************
@@ -314,7 +388,8 @@
           IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Pb when closing file', 1)
        ENDIF ! is_mpi_root
-
-!$OMP END MASTER
-!$OMP BARRIER
+    
+
+  !$OMP END MASTER
+  !$OMP BARRIER
 
        IF ( type_ocean /= 'couple') THEN
@@ -332,4 +407,6 @@
           CALL Scatter(rug_glo, rugos)
        END IF
+     
+     ENDIF    ! grid_type
 
     ENDIF ! time to read
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phyaqua_mod.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phyaqua_mod.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phyaqua_mod.F90	(revision 3867)
@@ -235,5 +235,5 @@
     CALL profil_sst(nlon, latitude, type_profil, phy_sst)
 
-    CALL writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, phy_ice, &
+    CALL writelim_unstruct(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, phy_ice, &
       phy_fter, phy_foce, phy_flic, phy_fsic)
 
@@ -332,5 +332,5 @@
 
     PRINT *, 'iniaqua: after phyredem'
-    CALL phys_state_var_end
+!    CALL phys_state_var_end
 
     RETURN
@@ -455,10 +455,10 @@
   ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-  SUBROUTINE writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, &
+  SUBROUTINE writelim_unstruct(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, &
       phy_ice, phy_fter, phy_foce, phy_flic, phy_fsic)
 
-    USE mod_phys_lmdz_para, ONLY: is_master
-    USE mod_grid_phy_lmdz, ONLY: klon_glo
-    USE mod_phys_lmdz_transfert_para, ONLY: gather
+    USE mod_phys_lmdz_para, ONLY: is_omp_master, klon_mpi
+    USE mod_phys_lmdz_transfert_para, ONLY: gather_omp
+    USE xios
     IMPLICIT NONE
 
@@ -477,4 +477,60 @@
     REAL, INTENT (IN) :: phy_fsic(klon, 360)
 
+    REAL :: phy_glo(klon_mpi, 360) ! temporary variable, to store phy_***(:)
+      ! on the whole physics grid
+ 
+
+    PRINT *, 'writelim: Ecriture du fichier limit'
+
+    CALL gather_omp(phy_foce, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('foce_limout',phy_glo)
+
+    CALL gather_omp(phy_fsic, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('fsic_limout',phy_glo)
+      
+    CALL gather_omp(phy_fter, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('fter_limout',phy_glo)
+      
+    CALL gather_omp(phy_flic, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('flic_limout',phy_glo)
+
+    CALL gather_omp(phy_sst, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('sst_limout',phy_glo)
+
+    CALL gather_omp(phy_bil, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('bils_limout',phy_glo)
+
+    CALL gather_omp(phy_alb, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('alb_limout',phy_glo)
+
+    CALL gather_omp(phy_rug, phy_glo)
+    IF (is_omp_master) CALL xios_send_field('rug_limout',phy_glo)
+
+  END SUBROUTINE writelim_unstruct
+
+
+
+  SUBROUTINE writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, &
+      phy_ice, phy_fter, phy_foce, phy_flic, phy_fsic)
+
+    USE mod_phys_lmdz_para, ONLY: is_master
+    USE mod_grid_phy_lmdz, ONLY: klon_glo
+    USE mod_phys_lmdz_transfert_para, ONLY: gather
+    IMPLICIT NONE
+
+    include "netcdf.inc"
+
+    INTEGER, INTENT (IN) :: klon
+    REAL, INTENT (IN) :: phy_nat(klon, 360)
+    REAL, INTENT (IN) :: phy_alb(klon, 360)
+    REAL, INTENT (IN) :: phy_sst(klon, 360)
+    REAL, INTENT (IN) :: phy_bil(klon, 360)
+    REAL, INTENT (IN) :: phy_rug(klon, 360)
+    REAL, INTENT (IN) :: phy_ice(klon, 360)
+    REAL, INTENT (IN) :: phy_fter(klon, 360)
+    REAL, INTENT (IN) :: phy_foce(klon, 360)
+    REAL, INTENT (IN) :: phy_flic(klon, 360)
+    REAL, INTENT (IN) :: phy_fsic(klon, 360)
+
     REAL :: phy_glo(klon_glo, 360) ! temporary variable, to store phy_***(:)
       ! on the whole physics grid
@@ -494,5 +550,5 @@
       PRINT *, 'writelim: Ecriture du fichier limit'
 
-      ierr = nf_create('limit.nc', nf_clobber, nid)
+      ierr = nf_create('limit.nc', NF_NETCDF4, nid)
 
       ierr = nf_put_att_text(nid, nf_global, 'title', 30, &
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phyetat0.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phyetat0.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phyetat0.F90	(revision 3867)
@@ -28,4 +28,6 @@
   USE ocean_slab_mod, ONLY: tslab, seaice, tice, ocean_slab_init
   USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
+  USE create_etat0_unstruct_mod
+  USE wxios
 
   IMPLICIT none
@@ -74,5 +76,5 @@
   
   REAL :: lon_startphy(klon), lat_startphy(klon)
-
+ 
   ! FH1D
   !     real iolat(jjm+1)
@@ -879,5 +881,5 @@
   ENDIF
 
-  CALL init_iophy_new(lat_degrees,lon_degrees)
+!  CALL init_iophy_new(lat_degrees,lon_degrees)
 
   ! Initilialize module fonte_neige_mod      
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_cal_mod.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_cal_mod.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_cal_mod.F90	(revision 3867)
@@ -36,5 +36,5 @@
   
   SUBROUTINE phys_cal_init(annee_ref,day_ref)
-  USE IOIPSL, ONLY:  ymds2ju, getin
+  USE IOIPSL, ONLY:  ymds2ju, getin, ioconf_calendar
   USE mod_phys_lmdz_para, ONLY:  is_master,bcast
   IMPLICIT NONE
@@ -51,4 +51,15 @@
     IF (is_master) CALL getin('calend', calend)
     CALL bcast(calend)
+
+    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
+
 
     CALL ymds2ju(annee_ref, 1, day_ref, 0., jD_ref)
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_output_write_mod.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_output_write_mod.F90	(revision 3867)
@@ -298,5 +298,5 @@
 
     IF(.NOT.vars_defined) THEN
-       iinitend = 2
+       iinitend = 1
     ELSE
        iinitend = 1
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_state_var_mod.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/phys_state_var_mod.F90	(revision 3867)
@@ -397,5 +397,5 @@
       !$OMP THREADPRIVATE(du_gwd_rando, dv_gwd_rando)
       ! tendencies on wind due to gravity waves
-
+      
 CONTAINS
 
@@ -419,4 +419,9 @@
 
 include "clesphys.h"
+      INTEGER,SAVE :: is_initialized=.FALSE.
+!$OMP THREADPRIVATE(is_initialized)    
+
+      IF (is_initialized) RETURN
+      is_initialized=.TRUE.
       ALLOCATE(pctsrf(klon,nbsrf))
       ALLOCATE(ftsol(klon,nbsrf))
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/physiq.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/physiq.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/physiq.F90	(revision 3867)
@@ -50,5 +50,5 @@
                               set_timestep, pdtphys
   USE tracinca_mod, ONLY : config_inca                   
-  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, grid1dTo2d_glo, klon_glo
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, grid1dTo2d_glo, klon_glo, grid_type, unstructured
 #ifdef REPROBUS
   USE CHEM_REP, ONLY : Init_chem_rep_xjour
@@ -64,5 +64,9 @@
   USE CFMIP_point_locations
   use FLOTT_GWD_rando_m, only: FLOTT_GWD_rando
-
+  USE etat0_limit_unstruct_mod
+  USE xios
+  USE regr_lat_time_climoz_m
+  USE climoz_mod
+  USE limit_read_mod, ONLY : init_limit_read
   IMPLICIT none
   !>======================================================================
@@ -247,4 +251,5 @@
   real clw(klon,klev),elij(klon,klev,klev)
   real epmlmMm(klon,klev,klev),eplaMm(klon,klev)
+  real delta_epsilon
   ! RomP <<<
   !IM definition dynamique o_trac dans phys_output_open
@@ -798,5 +803,5 @@
   !     ascending order
 
-  integer, save:: co3i = 0
+  integer, save:: co3i = -1
   !     time index in NetCDF file of current ozone fields
   !$OMP THREADPRIVATE(co3i) 
@@ -876,5 +881,5 @@
   mydebug=.FALSE.
   CALL set_timestep(pdtphys_)
-
+  IF (.NOT. debut)  CALL xios_update_calendar(itap+1)
   !======================================================================
   ! Ecriture eventuelle d'un profil verticale en entree de la physique.
@@ -904,5 +909,7 @@
 
   if (first) then 
-
+     CALL init_etat0_limit_unstruct
+     CALL init_limit_read(days_elapsed)
+     
      !CR:nvelles variables convection/poches froides
 
@@ -1055,5 +1062,66 @@
      radpas = NINT( 86400./pdtphys/nbapp_rad)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+     CALL init_iophy_new(lat_degrees,lon_degrees)
+
+     !=============================================================
+     !   Initialisation des sorties
+     !=============================================================
+
+#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(lon_degrees,lat_degrees,nCFMIP,tabijGCM, &
+          iGCM,jGCM,lonGCM,latGCM, &
+          jjmp1,nlevSTD,clevSTD,rlevSTD, pdtphys,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_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)
+
+     include "ini_histday_seri.h"
+
+     include "ini_paramLMDZ_phy.h"
+
+#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
+     
+!--- OZONE CLIMATOLOGY
+!    create ozone file for unstuctured grid
+     CALL create_climoz(read_climoz)
+
+     CALL phys_output_write(itap, pdtphys, paprs, pphis,                    &
+                             pplay, lmax_th, aerosol_couple,                 &
+                             ok_ade, ok_aie, ivap, new_aod, ok_sync,         &
+                             ptconv, read_climoz, clevSTD,                   &
+                             ptconvth, d_t, qx, d_qx, zmasse,                &
+                             flag_aerosol, flag_aerosol_strat, ok_cdnc)
+
+     CALL xios_update_calendar(1)    
+
+     CALL create_etat0_limit_unstruct
+     
+    
      CALL phyetat0 ("startphy.nc",clesphy0,tabcntr0)
      IF (klon_glo==1) THEN
@@ -1230,47 +1298,5 @@
      !IM cf. AM 081204 END
      !
-     !=============================================================
-     !   Initialisation des sorties
-     !=============================================================
-
-#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(lon_degrees,lat_degrees,nCFMIP,tabijGCM, &
-          iGCM,jGCM,lonGCM,latGCM, &
-          jjmp1,nlevSTD,clevSTD,rlevSTD, pdtphys,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_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)
-
-     include "ini_histday_seri.h"
-
-     include "ini_paramLMDZ_phy.h"
-
-#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
+
      !
      !
@@ -1611,5 +1637,12 @@
      ! Ozone from a file
      ! Update required ozone index:
-     ro3i = int((days_elapsed + jh_cur - jh_1jan) / year_len * 360.) + 1
+!ym     ro3i = int((days_elapsed + jh_cur - jh_1jan) / year_len * 360.) + 1
+!     ro3i = int((days_elapsed + jh_cur - jh_1jan )) + 1
+     
+     delta_epsilon=jh_cur-pdtphys/un_jour
+     if (ABS(delta_epsilon)<1e-6) delta_epsilon=0
+     ro3i = int((days_elapsed+delta_epsilon - jh_1jan ))+1
+     
+             
      if (ro3i == 361) ro3i = 360
      ! (This should never occur, except perhaps because of roundup
@@ -1618,10 +1651,22 @@
         ! Update ozone field:
         if (read_climoz == 1) then
-           call regr_pr_av(ncid_climoz, (/"tro3"/), julien=ro3i, &
+
+          IF (grid_type==unstructured) THEN
+            CALL get_ozone_var((/"tro3_read"/),press_climoz,paprs,wo)
+          ELSE
+             CALL regr_pr_av(ncid_climoz, (/"tro3"/), julien=ro3i, &
                 press_in_edg=press_climoz, paprs=paprs, v3=wo)
+          ENDIF
+      
         else
            ! read_climoz == 2
-           call regr_pr_av(ncid_climoz, (/"tro3         ", "tro3_daylight"/), &
-                julien=ro3i, press_in_edg=press_climoz, paprs=paprs, v3=wo)
+
+          IF (grid_type==unstructured) THEN
+            CALL get_ozone_var((/"tro3_read","tro3_daylight_read"/),press_climoz,paprs,wo)
+          ELSE
+            CALL regr_pr_av(ncid_climoz, (/"tro3         ", "tro3_daylight"/), &
+                 julien=ro3i, press_in_edg=press_climoz, paprs=paprs, v3=wo)
+          ENDIF
+
         end if
         ! Convert from mole fraction of ozone to column density of ozone in a
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/regr_lat_time_climoz_m.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/regr_lat_time_climoz_m.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/regr_lat_time_climoz_m.F90	(revision 3867)
@@ -11,5 +11,5 @@
 contains
 
-  subroutine regr_lat_time_climoz(read_climoz)
+  subroutine regr_lat_time_climoz(read_climoz, regr_lat)
 
     ! "regr_lat_time_climoz" stands for "regrid latitude time
@@ -65,5 +65,5 @@
     ! periodicity for interpolation at the beginning and at the end of the
     ! year.
-    use mod_grid_phy_lmdz, ONLY : nbp_lat
+    use mod_grid_phy_lmdz, ONLY : nbp_lat, grid_type, unstructured
     use regr1_step_av_m, only: regr1_step_av
     use regr3_lint_m, only: regr3_lint
@@ -75,4 +75,6 @@
     use regular_lonlat_mod, only : boundslat_reg, south
     use nrtype, only: pi
+    use regular_lonlat_mod, only : lat_reg
+    implicit none
     integer, intent(in):: read_climoz ! read ozone climatology
     ! Allowed values are 1 and 2
@@ -82,8 +84,10 @@
 
     ! Variables local to the procedure:
+    LOGICAL, intent(in), OPTIONAL :: regr_lat
 
     integer n_plev ! number of pressure levels in the input data
     integer n_lat ! number of latitudes in the input data
     integer n_month ! number of months in the input data
+    integer n_lat_out ! number of latitudes in the output data
 
     real, pointer:: latitude(:)
@@ -158,6 +162,13 @@
     ! (time to middle of day, in days since January 1st 0h, in a
     ! 360-day calendar)
-
+    logical :: regr_lat_
+    REAL,ALLOCATABLE :: lat_out(:)
+    
     !---------------------------------
+    IF (PRESENT(regr_lat)) THEN
+      regr_lat_=regr_lat
+    ELSE
+      regr_lat_=.TRUE.
+    ENDIF
 
     print *, "Call sequence information: regr_lat_time_climoz"
@@ -183,5 +194,4 @@
     forall (j = 2:n_lat) lat_in_edg(j) = (latitude(j - 1) + latitude(j)) / 2
     lat_in_edg(n_lat + 1) = pi / 2
-    deallocate(latitude) ! pointer
 
     call nf95_inq_varid(ncid_in, "plev", varid)
@@ -204,7 +214,19 @@
     end if
 
+    IF (regr_lat_) THEN 
+      n_lat_out=nbp_lat
+      ALLOCATE(lat_out(n_lat_out))
+      lat_out=lat_reg
+    ELSE 
+      n_lat_out=n_lat
+      ALLOCATE(lat_out(n_lat_out))
+      lat_out=latitude
+    ENDIF
+
     ! Create the output file and get the variable IDs:
-    call prepare_out(ncid_in, n_plev, ncid_out, varid_out, varid_plev, &
+    call prepare_out(ncid_in, n_lat_out, lat_out, n_plev, ncid_out, varid_out, varid_plev, &
          varid_time)
+
+    deallocate(latitude) ! pointer
 
     ! Write remaining coordinate variables:
@@ -281,36 +303,48 @@
     call nf95_close(ncid_in)
 
-    allocate(o3_regr_lat(nbp_lat, n_plev, 0:13, read_climoz))
-    allocate(o3_out(nbp_lat, n_plev, 360, read_climoz))
-
-    ! Regrid in latitude:
-    ! We average with respect to sine of latitude, which is
-    ! equivalent to weighting by cosine of latitude:
-    if (n_month == 12) then
-       print *, &
-            "Found 12 months in ozone climatologies, assuming periodicity..."
-       o3_regr_lat(nbp_lat:1:-1, :, 1:12, :) = regr1_step_av(o3_in, &
-            xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
-       ! (invert order of indices in "o3_regr_lat" because "rlatu" is
-       ! in descending order)
-
-       ! Duplicate January and December values, in preparation of time
-       ! interpolation:
-       o3_regr_lat(:, :, 0, :) = o3_regr_lat(:, :, 12, :)
-       o3_regr_lat(:, :, 13, :) = o3_regr_lat(:, :, 1, :)
-    else
-       print *, "Using 14 months in ozone climatologies..."
-       o3_regr_lat(nbp_lat:1:-1, :, :, :) = regr1_step_av(o3_in, &
-            xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
-       ! (invert order of indices in "o3_regr_lat" because "rlatu" is
-       ! in descending order)
-    end if
-
-    ! Regrid in time by linear interpolation:
-    o3_out = regr3_lint(o3_regr_lat, tmidmonth, tmidday)
+    allocate(o3_out(n_lat_out, n_plev, 360, read_climoz))
+    IF (regr_lat) THEN
+      allocate(o3_regr_lat(nbp_lat, n_plev, 0:13, read_climoz))
+
+      ! Regrid in latitude:
+      ! We average with respect to sine of latitude, which is
+      ! equivalent to weighting by cosine of latitude:
+      if (n_month == 12) then
+         print *, &
+              "Found 12 months in ozone climatologies, assuming periodicity..."
+         o3_regr_lat(nbp_lat:1:-1, :, 1:12, :) = regr1_step_av(o3_in, &
+              xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
+         ! (invert order of indices in "o3_regr_lat" because "rlatu" is
+         ! in descending order)
+
+         ! Duplicate January and December values, in preparation of time
+         ! interpolation:
+         o3_regr_lat(:, :, 0, :) = o3_regr_lat(:, :, 12, :)
+         o3_regr_lat(:, :, 13, :) = o3_regr_lat(:, :, 1, :)
+      else
+         print *, "Using 14 months in ozone climatologies..."
+         o3_regr_lat(nbp_lat:1:-1, :, :, :) = regr1_step_av(o3_in, &
+              xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
+         ! (invert order of indices in "o3_regr_lat" because "rlatu" is
+         ! in descending order)
+      end if
+      ! Regrid in time by linear interpolation:
+      o3_out = regr3_lint(o3_in, tmidmonth, tmidday)
+    ELSE
+      ! Regrid in time by linear interpolation:
+      o3_out = regr3_lint(o3_in, tmidmonth, tmidday)
+    ENDIF
 
     ! Write to file:
+
     do m = 1, read_climoz
-       call nf95_put_var(ncid_out, varid_out(m), o3_out(nbp_lat:1:-1, :, :, m))
+       IF (grid_type==unstructured) THEN
+         ! Doing spatial interpolation from XIOS need to have some point in longitude
+         ! waiting zonal mean operation from XIOS
+         call nf95_put_var(ncid_out, varid_out(m), SPREAD(o3_out(n_lat_out:1:-1, :, :, m),1,4))
+       ELSE
+         call nf95_put_var(ncid_out, varid_out(m), o3_out(n_lat_out:1:-1, :, :, m))
+       ENDIF
+       
        ! (The order of "rlatu" is inverted in the output file)
     end do
@@ -322,5 +356,5 @@
   !********************************************
 
-  subroutine prepare_out(ncid_in, n_plev, ncid_out, varid_out, varid_plev, &
+  subroutine prepare_out(ncid_in, n_lat, lat, n_plev, ncid_out, varid_out, varid_plev, &
        varid_time)
 
@@ -328,11 +362,12 @@
     ! dimensions and variables, and writes one of the coordinate variables.
 
-    use mod_grid_phy_lmdz, ONLY : nbp_lat
     use netcdf95, only: nf95_create, nf95_def_dim, nf95_def_var, &
          nf95_put_att, nf95_enddef, nf95_copy_att, nf95_put_var
-    use netcdf, only: nf90_clobber, nf90_float, nf90_global
+    use netcdf, only: nf90_clobber,nf90_netcdf4, nf90_float, nf90_global, nf90_unlimited
     use nrtype, only: pi
-    use regular_lonlat_mod, only : lat_reg
-    integer, intent(in):: ncid_in, n_plev
+    use mod_grid_phy_lmdz, ONLY :  grid_type, unstructured
+
+    integer, intent(in):: ncid_in, n_lat, n_plev
+    real, intent(in):: lat(:)
     integer, intent(out):: ncid_out, varid_plev, varid_time
 
@@ -344,6 +379,6 @@
 
     integer ncerr
-    integer dimid_rlatu, dimid_plev, dimid_time
-    integer varid_rlatu
+    integer dimid_rlatu, dimid_rlonv, dimid_plev, dimid_time
+    integer varid_rlonv, varid_rlatu
 
     !---------------------------
@@ -351,10 +386,11 @@
     print *, "Call sequence information: prepare_out"
 
-    call nf95_create("climoz_LMDZ.nc", nf90_clobber, ncid_out)
+    call nf95_create("climoz_LMDZ.nc", NF90_CLOBBER + NF90_NETCDF4, ncid_out)
 
     ! Dimensions:
-    call nf95_def_dim(ncid_out, "time", 360, dimid_time)
+    call nf95_def_dim(ncid_out, "time",  nf90_unlimited, dimid_time)
     call nf95_def_dim(ncid_out, "plev", n_plev, dimid_plev)
-    call nf95_def_dim(ncid_out, "rlatu", nbp_lat, dimid_rlatu)
+    call nf95_def_dim(ncid_out, "rlatu", n_lat, dimid_rlatu)
+    if (grid_type==unstructured) call nf95_def_dim(ncid_out, "rlonv", 4, dimid_rlonv)
 
     ! Define coordinate variables:
@@ -374,8 +410,20 @@
     call nf95_put_att(ncid_out, varid_rlatu, "standard_name", "latitude")
 
+    if (grid_type==unstructured) then
+      call nf95_def_var(ncid_out, "rlonv", nf90_float, dimid_rlonv, varid_rlonv)
+      call nf95_put_att(ncid_out, varid_rlonv, "units", "degrees_east")
+      call nf95_put_att(ncid_out, varid_rlonv, "standard_name", "longitude")
+    endif
+    
     ! Define the primary variables:
 
-    call nf95_def_var(ncid_out, "tro3", nf90_float, &
+    if (grid_type==unstructured) then
+        call nf95_def_var(ncid_out, "tro3", nf90_float, &
+         (/dimid_rlonv, dimid_rlatu, dimid_plev, dimid_time/), varid_out(1))
+    else
+        call nf95_def_var(ncid_out, "tro3", nf90_float, &
          (/dimid_rlatu, dimid_plev, dimid_time/), varid_out(1))
+    endif  
+    
     call nf95_put_att(ncid_out, varid_out(1), "long_name", &
          "ozone mole fraction")
@@ -384,6 +432,12 @@
 
     if (size(varid_out) == 2) then
-       call nf95_def_var(ncid_out, "tro3_daylight", nf90_float, &
-            (/dimid_rlatu, dimid_plev, dimid_time/), varid_out(2))
+      if (grid_type==unstructured) then
+         call nf95_def_var(ncid_out, "tro3_daylight", nf90_float, &
+             (/dimid_rlonv, dimid_rlatu, dimid_plev, dimid_time/), varid_out(2))
+      else
+         call nf95_def_var(ncid_out, "tro3_daylight", nf90_float, &
+             (/ dimid_rlatu, dimid_plev, dimid_time/), varid_out(2))
+      endif
+       
        call nf95_put_att(ncid_out, varid_out(2), "long_name", &
             "ozone mole fraction in daylight")
@@ -417,6 +471,7 @@
 
     ! Write one of the coordinate variables:
-    call nf95_put_var(ncid_out, varid_rlatu, lat_reg(nbp_lat:1:-1) / pi * 180.)
+    call nf95_put_var(ncid_out, varid_rlatu, lat(n_lat:1:-1) / pi * 180.)
     ! (convert from rad to degrees and sort in ascending order)
+    if (grid_type==unstructured)  call nf95_put_var(ncid_out, varid_rlonv, (/ 0., 90., 180.,270. /))
 
   contains
Index: dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/wxios.F90
===================================================================
--- dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/wxios.F90	(revision 3849)
+++ dynamico_lmdz/aquaplanet/LMDZ5/libf/phylmd/wxios.F90	(revision 3867)
@@ -31,5 +31,5 @@
     SUBROUTINE reformadate(odate, ndate)
         CHARACTER(len=*), INTENT(IN) :: odate
-        CHARACTER(len=100), INTENT(OUT) :: ndate
+        TYPE(xios_duration) :: ndate
         
         INTEGER :: i = 0
@@ -46,15 +46,15 @@
         i = INDEX(odate, "day")
         IF (i > 0) THEN
-            ndate = odate(1:i-1)//"d"
+            read(odate(1:i-1),*) ndate%day
         END IF
 
         i = INDEX(odate, "hr")
         IF (i > 0) THEN
-            ndate = odate(1:i-1)//"h"
+            read(odate(1:i-1),*) ndate%hour
         END IF
 
         i = INDEX(odate, "mth")
         IF (i > 0) THEN
-            ndate = odate(1:i-1)//"mo"
+            read(odate(1:i-1),*) ndate%month
         END IF
         
@@ -135,4 +135,5 @@
     SUBROUTINE wxios_context_init()
         USE print_control_mod, ONLY : prt_level, lunout
+        USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY
         IMPLICIT NONE
 
@@ -141,5 +142,5 @@
 !$OMP MASTER
         !Initialisation du contexte:
-        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
@@ -186,19 +187,19 @@
      
      !Variables pour xios:
-     TYPE(xios_time) :: mdtime
+     TYPE(xios_duration) :: mdtime
      !REAL(kind = 8) :: year=0, month=0, day=0, hour=0, minute=0, second=0
      
-        mdtime = xios_time(0, 0, 0, 0, 0, pasdetemps)
+        mdtime%second=pasdetemps
 
         !Réglage du calendrier:
         SELECT CASE (calendrier)
             CASE('earth_360d')
-                CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "D360")
+                CALL xios_define_calendar("D360")
                 IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 360 jours/an'
             CASE('earth_365d')
-                CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "NoLeap")
+                CALL xios_define_calendar("NoLeap")
                 IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 365 jours/an'
             CASE('earth_366d')
-                CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "Gregorian")
+                CALL xios_define_calendar("Gregorian")
                 IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier gregorien'
             CASE DEFAULT
@@ -211,6 +212,6 @@
         
         IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: Time origin: ", date
-        
-        CALL xios_set_context_attr_hdl(g_ctx, time_origin = date)
+
+        CALL xios_set_time_origin(xios_date(annee,mois,jour,int(heure),0,0))
 
         !Formatage de la date de debut:
@@ -220,5 +221,5 @@
         IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: Start date: ", date
         
-        CALL xios_set_context_attr_hdl(g_ctx, start_date = date)
+        CALL xios_set_start_date(xios_date(ini_an,ini_mois,ini_jour,int(ini_heure),0,0))
         
         !Et enfin,le pas de temps:
@@ -229,7 +230,7 @@
     SUBROUTINE wxios_set_timestep(ts)
         REAL, INTENT(IN) :: ts
-        TYPE(xios_time) :: mdtime     
-
-        mdtime = xios_time(0, 0, 0, 0, 0, ts)
+        TYPE(xios_duration) :: mdtime     
+
+        mdtime%timestep = ts
 
         CALL xios_set_timestep(mdtime)
@@ -285,7 +286,7 @@
         
         !On parametrise le domaine:
-        CALL xios_set_domain_attr_hdl(dom, ni_glo=ni_glo, ibegin=ibegin, ni=ni)
-        CALL xios_set_domain_attr_hdl(dom, nj_glo=nj_glo, jbegin=jbegin, nj=nj, data_dim=2)
-        CALL xios_set_domain_attr_hdl(dom, lonvalue=io_lon(ibegin:iend), latvalue=io_lat(jbegin:jend))
+        CALL xios_set_domain_attr_hdl(dom, ni_glo=ni_glo, ibegin=ibegin-1, ni=ni)
+        CALL xios_set_domain_attr_hdl(dom, nj_glo=nj_glo, jbegin=jbegin-1, nj=nj, data_dim=2)
+        CALL xios_set_domain_attr_hdl(dom, lonvalue_1d=io_lon(ibegin:iend), latvalue_1d=io_lat(jbegin:jend))
 
         IF (.NOT.is_sequential) THEN
@@ -299,5 +300,5 @@
               WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,nj)=",mask(:,nj)
             ENDIF
-            CALL xios_set_domain_attr_hdl(dom, mask=mask)
+            CALL xios_set_domain_attr_hdl(dom, mask_2d=mask)
         END IF
 
@@ -322,5 +323,5 @@
         REAL :: boundslon_mpi(klon_mpi,nvertex)
         REAL :: boundslat_mpi(klon_mpi,nvertex)
-        TYPE(xios_domain) :: dom
+        TYPE(xios_domaingroup) :: dom
 
 
@@ -331,9 +332,9 @@
 
 !$OMP MASTER
-        CALL xios_get_domain_handle("dom_glo", dom)
+        CALL xios_get_domaingroup_handle("dom_glo", dom)
         
         !On parametrise le domaine:
-        CALL xios_set_domain_attr_hdl(dom, ni_glo=klon_glo, ibegin=ij_begin, ni=ij_nb, data_dim=1, type="unstructured")
-        CALL xios_set_domain_attr_hdl(dom, nvertex=nvertex, lonvalue=lon_mpi, latvalue=lat_mpi, bounds_lon=TRANSPOSE(boundslon_mpi), bounds_lat=TRANSPOSE(boundslat_mpi) )
+        CALL xios_set_attr(dom, ni_glo=klon_glo, ibegin=ij_begin-1, ni=ij_nb, type="unstructured")
+        CALL xios_set_attr(dom, nvertex=nvertex, lonvalue_1d=lon_mpi, latvalue_1d=lat_mpi, bounds_lon_1d=TRANSPOSE(boundslon_mpi), bounds_lat_1d=TRANSPOSE(boundslat_mpi) )
 !$OMP END MASTER
 
@@ -375,5 +376,5 @@
         
         ! Ehouarn: New way to declare axis, without axis_group:
-        CALL xios_set_axis_attr(trim(axis_id),size=axis_size,value=axis_value)
+        CALL xios_set_axis_attr(trim(axis_id),n_glo=axis_size,value=axis_value)
         
         !Vérification:
@@ -400,5 +401,6 @@
         TYPE(xios_file) :: x_file
         TYPE(xios_filegroup) :: x_fg
-        CHARACTER(len=100) :: nffreq
+!        CHARACTER(len=100) :: nffreq
+        TYPE(xios_duration) :: nffreq
         
         !On regarde si le fichier n'est pas défini par XML:
@@ -413,14 +415,14 @@
             !On configure:
             CALL xios_set_file_attr_hdl(x_file, name="X"//fname,&
-                output_freq=TRIM(ADJUSTL(nffreq)), output_level=flvl, enabled=.TRUE.)
+                output_freq=nffreq, output_level=flvl, enabled=.TRUE.)
         
             IF (xios_is_valid_file("X"//fname)) THEN
                 IF (prt_level >= 10) THEN
                   WRITE(lunout,*) "wxios_add_file: New file: ", "X"//fname
-                  WRITE(lunout,*) "wxios_add_file: output_freq=",TRIM(ADJUSTL(nffreq)),"; output_lvl=",flvl
+                  WRITE(lunout,*) "wxios_add_file: output_freq=",nffreq,"; output_lvl=",flvl
                 ENDIF
             ELSE
                 WRITE(lunout,*) "wxios_add_file: Error, invalid file: ", "X"//trim(fname)
-                WRITE(lunout,*) "wxios_add_file: output_freq=",TRIM(ADJUSTL(nffreq)),"; output_lvl=",flvl
+                WRITE(lunout,*) "wxios_add_file: output_freq=",nffreq,"; output_lvl=",flvl
             END IF
         ELSE
@@ -492,4 +494,5 @@
         TYPE(xios_field) :: field
         TYPE(xios_fieldgroup) :: fieldgroup
+        TYPE(xios_duration) :: freq_op
         LOGICAL :: bool=.FALSE.
         INTEGER :: lvl =0
@@ -550,5 +553,6 @@
             
             !L'operation, sa frequence:
-            CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op="1ts", prec=4)
+            freq_op%timestep=1
+            CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op=freq_op, prec=4)
 
             
