Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/DOM/dtatsd.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/DOM/dtatsd.F90	(revision 11405)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/DOM/dtatsd.F90	(revision 11482)
@@ -22,4 +22,6 @@
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
+   USE iom, ONLY : iom_swap, iom_setkt, iom_context_finalize
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
 
    IMPLICIT NONE
@@ -28,10 +30,13 @@
    PUBLIC   dta_tsd_init   ! called by opa.F90
    PUBLIC   dta_tsd        ! called by istate.F90 and tradmp.90
+   PUBLIC   iom_dta_tsd_init
 
    !                                  !!* namtsd  namelist : Temperature & Salinity Data *
    LOGICAL , PUBLIC ::   ln_tsd_init   !: T & S data flag
    LOGICAL , PUBLIC ::   ln_tsd_dmp    !: internal damping toward input data flag
+   LOGICAL , PRIVATE::   ln_tsd_xios
 
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_tsd   ! structure of input SST (file informations, fields read)
+   CHARACTER(lc), PUBLIC                ::   cinit_context    !: context name used in xios
 
    !!----------------------------------------------------------------------
@@ -59,5 +64,5 @@
       TYPE(FLD_N)                   ::   sn_tem, sn_sal
       !!
-      NAMELIST/namtsd/   ln_tsd_init, ln_tsd_dmp, cn_dir, sn_tem, sn_sal
+      NAMELIST/namtsd/   ln_tsd_init, ln_tsd_dmp, cn_dir, sn_tem, sn_sal, ln_tsd_xios
       !!----------------------------------------------------------------------
       !
@@ -114,4 +119,6 @@
          slf_i(jp_tem) = sn_tem   ;   slf_i(jp_sal) = sn_sal
          CALL fld_fill( sf_tsd, slf_i, cn_dir, 'dta_tsd', 'Temperature & Salinity data', 'namtsd', no_print )
+         cinit_context = 'dta_tsd_init'
+         IF( ln_tsd_xios) CALL iom_dta_tsd_init( cinit_context )
          !
       ENDIF
@@ -121,4 +128,7 @@
 
    SUBROUTINE dta_tsd( kt, ptsd )
+#if defined key_iomput
+      use xios, ONLY : xios_recv_field
+#endif
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE dta_tsd  ***
@@ -144,5 +154,8 @@
       !!----------------------------------------------------------------------
       !
-      CALL fld_read( kt, 1, sf_tsd )      !==   read T & S data at kt time step   ==!
+      IF(ln_tsd_xios) CALL iom_swap(cinit_context) 
+      CALL fld_read( kt, 1, sf_tsd, ldxios = ln_tsd_xios)      !==   read T & S data at kt time step   ==!
+      IF(kt == nitend .OR. (.NOT.ln_tsd_dmp) .AND. ln_tsd_xios)  CALL iom_context_finalize( cinit_context )
+      CALL iom_swap( cxios_context )
       !
       !
@@ -253,4 +266,139 @@
    END SUBROUTINE dta_tsd
 
+   SUBROUTINE iom_dta_tsd_init( cdname, ld_tmppatch ) 
+#if defined key_iomput
+      use xios
+#endif
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   initialize context for reading T & S input data
+      !!                to replace fld_ intrerface with XIOS to read initial
+      !!                conditions. Have it separated from other conditions
+      !!                because initialization happens before model starts
+      !!                time stepping.
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*),           INTENT(in)  :: cdname
+      LOGICAL         , OPTIONAL, INTENT(in)  :: ld_tmppatch
+#if defined key_iomput
+      !
+      CHARACTER(len=lc) :: clname
+      INTEGER, PARAMETER :: lstr = 256  !: length of the string set to 256 
+      INTEGER           :: ji, jkmin
+      LOGICAL ::   ll_tmppatch = .TRUE.    !: seb: patch before we remove periodicity
+      INTEGER ::   nldi_save, nlei_save    !:      and close boundaries in output files
+      INTEGER ::   nldj_save, nlej_save    !:
+      LOGICAL ::   ll_global = .FALSE.     !: do we have variable on model grid
+      CHARACTER(len=lc), DIMENSION( jpts) :: cg_name(jpts)
+      CHARACTER(len=1), DIMENSION( 5)   :: cname
+      CHARACTER(len=lstr)               :: cfname ! file name without .nc
+      TYPE(xios_duration)               :: dtime    = xios_duration(0, 0, 0, 0, 0, 0), &
+                                           outp_frq = xios_duration(0, 0, 0, 0, 0, 0)
+      TYPE(xios_domaingroup)            :: domaingroup_hdl
+      TYPE(xios_domain)                 :: domain_hdl
+      TYPE(xios_axisgroup)              :: axisgroup_hdl
+      TYPE(xios_axis)                   :: axis_hdl
+      TYPE(xios_scalar)                 :: scalar_hdl
+      TYPE(xios_scalargroup)            :: scalargroup_hdl
+      TYPE(xios_file)                   :: file_hdl
+      TYPE(xios_filegroup)              :: filegroup_hdl
+      TYPE(xios_field)                  :: field_hdl
+      INTEGER                           :: jf, ni, nj, ipos
+
+      cname(1)='a'
+      cname(2)='b'
+      cname(3)='c'
+      cname(4)='d'
+      cname(5)='e'
+      !!----------------------------------------------------------------------
+      !
+      ! seb: patch before we remove periodicity and close boundaries in output files
+      IF ( ll_tmppatch ) THEN
+         nldi_save = nldi   ;   nlei_save = nlei
+         nldj_save = nldj   ;   nlej_save = nlej
+         IF( nimpp           ==      1 ) nldi = 1
+         IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi
+         IF( njmpp           ==      1 ) nldj = 1
+         IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj
+      ENDIF
+      !
+      clname = cdname
+      IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname)
+      CALL xios_context_initialize(TRIM(clname), mpi_comm_oce)
+      CALL iom_swap( cdname )
+      ! Calendar type is now defined in xml file 
+      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+      CASE ( 1)   ; CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(1976,01,01,00,00,00), &
+          &                                    start_date = xios_date(1976,02,15,00,00,00) )
+      CASE ( 0)   ; CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(1976,01,01,00,00,00), &
+          &                                    start_date = xios_date(1976,02,15,00,00,00) )
+      CASE (30)   ; CALL xios_define_calendar( TYPE = "D360"     , time_origin = xios_date(1976,01,01,00,00,00), &
+          &                                    start_date = xios_date(nyear, nmonth, nday, 00, 00, 00) )
+      END SELECT
+
+      DO jf = 1, SIZE(sf_tsd)
+         IF( LEN( TRIM(sf_tsd(jf)%wgtname) ) > 0) THEN
+            STOP 'IMPLEMENTATION NOT FINISHED'
+         ELSE
+            IF(.NOT. ll_global) THEN
+               CALL xios_get_handle("domain_definition",domaingroup_hdl)
+               CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_global")
+               ni = nlei-nldi+1
+               nj = nlej-nldj+1
+               CALL xios_set_domain_attr("grid_global", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
+               CALL xios_set_domain_attr("grid_global", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
+               CALL xios_set_domain_attr("grid_global", type='curvilinear')
+               ll_global = .TRUE.
+            ENDIF
+         ENDIF
+      ENDDO
+
+      CALL xios_get_handle("axis_definition",axisgroup_hdl)
+      CALL xios_add_child(axisgroup_hdl, axis_hdl, "depth")
+      CALL xios_set_axis_attr     ("depth" , n_glo= jpk)
+
+
+      CALL xios_get_handle("file_definition", filegroup_hdl )
+ 
+      DO jf = 1, SIZE(sf_tsd)
+
+         IF(sf_tsd(jf)%nfreqh < 0 ) THEN
+           outp_frq%month = -sf_tsd(jf)%nfreqh
+         ELSE
+           outp_frq%hour = sf_tsd(jf)%nfreqh
+         ENDIF
+         CALL xios_add_child(filegroup_hdl, file_hdl, cname(jf))
+         ipos = index(sf_tsd(jf)%clrootname,'.nc')
+         cfname(1:lstr) = " "
+         IF(ipos > 0) THEN
+          cfname(1:ipos-1) = sf_tsd(jf)%clrootname(1:ipos-1)
+         ELSE
+          cfname(1:lstr) = sf_tsd(jf)%clrootname(1:lstr)
+         ENDIF
+         CALL xios_set_file_attr( cname(jf), name=TRIM(cfname),  &
+                type="one_file", time_counter_name="time", &
+                par_access="collective", enabled=.TRUE., mode="read", &
+                output_freq=outp_frq, time_units = "days")
+         CALL xios_add_child(file_hdl, field_hdl, TRIM(sf_tsd(jf)%clvar))
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., &
+                          name = TRIM(sf_tsd(jf)%clvar), domain_ref="grid_global", &
+                          axis_ref="depth", operation = "instant") 
+      ENDDO
+
+      dtime%month = 1
+      CALL xios_set_timestep( dtime )
+      CALL xios_close_context_definition()
+      CALL xios_update_calendar( 0 )
+
+      IF ( ll_tmppatch ) THEN
+         nldi = nldi_save   ;   nlei = nlei_save
+         nldj = nldj_save   ;   nlej = nlej_save
+      ENDIF
+#endif
+      !
+   END SUBROUTINE iom_dta_tsd_init
+
+
    !!======================================================================
 END MODULE dtatsd
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/IOM/iom.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/IOM/iom.F90	(revision 11405)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/IOM/iom.F90	(revision 11482)
@@ -1305,4 +1305,8 @@
       ELSE        ! read using XIOS. Only if KEY_IOMPUT is defined
 #if defined key_iomput
+         IF( PRESENT(ktime) ) THEN
+           if(lwp) write(numout, *) 'XIOS BDRY READ itime = ', ktime
+           CALL xios_update_calendar( ktime - 1 )
+         ENDIF
          IF( PRESENT(pv_r3d) ) THEN
             pv_r3d(:, :, :) = 0.
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/fldread.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/fldread.F90	(revision 11405)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/fldread.F90	(revision 11482)
@@ -129,5 +129,5 @@
 CONTAINS
 
-   SUBROUTINE fld_read( kt, kn_fsbc, sd, map, kit, kt_offset, jpk_bdy, fvl )
+   SUBROUTINE fld_read( kt, kn_fsbc, sd, map, kit, kt_offset, jpk_bdy, fvl, ldxios )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_read  ***
@@ -152,4 +152,5 @@
       INTEGER  , INTENT(in   ), OPTIONAL     ::   jpk_bdy   ! number of vertical levels in the BDY data
       LOGICAL  , INTENT(in   ), OPTIONAL     ::   fvl   ! number of vertical levels in the BDY data
+      LOGICAL  , INTENT(in   ), OPTIONAL     ::   ldxios    ! use xios to read data
       !!
       INTEGER  ::   itmp         ! local variable
@@ -167,5 +168,10 @@
       CHARACTER(LEN=1000) ::   clfmt  ! write format
       TYPE(MAP_POINTER)   ::   imap   ! global-to-local mapping indices
-      !!---------------------------------------------------------------------
+      LOGICAL  ::   luxios       ! temporary variable to hold ldxios
+      !!---------------------------------------------------------------------
+
+      luxios = .FALSE.
+      IF( PRESENT(ldxios) ) luxios = ldxios
+
       ll_firstcall = kt == nit000
       IF( PRESENT(kit) )   ll_firstcall = ll_firstcall .and. kit == 1
@@ -190,7 +196,7 @@
             IF( PRESENT(map) ) imap = map(jf)
                IF( PRESENT(jpk_bdy) ) THEN
-                  CALL fld_init( kn_fsbc, sd(jf), imap, jpk_bdy, fvl )  ! read each before field (put them in after as they will be swapped)
+                  CALL fld_init( kn_fsbc, sd(jf), imap, jpk_bdy, fvl, ldxios = luxios)  ! read each before field (put them in after as they will be swapped)
                ELSE
-                  CALL fld_init( kn_fsbc, sd(jf), imap )  ! read each before field (put them in after as they will be swapped)
+                  CALL fld_init( kn_fsbc, sd(jf), imap, ldxios = luxios)  ! read each before field (put them in after as they will be swapped)
                ENDIF
          END DO
@@ -211,5 +217,5 @@
                IF( sd(jf)%ln_tint )   sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! swap before record field
 
-               CALL fld_rec( kn_fsbc, sd(jf), kt_offset = it_offset, kit = kit )    ! update after record informations
+               CALL fld_rec( kn_fsbc, sd(jf), kt_offset = it_offset, kit = kit)    ! update after record informations
 
                ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
@@ -222,5 +228,5 @@
                   itmp = sd(jf)%nrec_a(1)                       ! temporary storage
                   sd(jf)%nrec_a(1) = sd(jf)%nreclast            ! read the last record of the file currently opened
-                  CALL fld_get( sd(jf), imap )                  ! read after data
+                  CALL fld_get( sd(jf), imap, ldxios = luxios)  ! read after data
                   sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! re-swap before record field
                   sd(jf)%nrec_b(1) = sd(jf)%nrec_a(1)           ! update before record informations
@@ -240,5 +246,5 @@
                      &                   .AND. sd(jf)%nrec_b(1) /= sd(jf)%nrec_a(1) - 1 ) THEN   
                      sd(jf)%nrec_a(1) = sd(jf)%nrec_a(1) - 1       ! move back to before record
-                     CALL fld_get( sd(jf), imap )                  ! read after data
+                     CALL fld_get( sd(jf), imap, ldxios = luxios)  ! read after data
                      sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! re-swap before record field
                      sd(jf)%nrec_b(1) = sd(jf)%nrec_a(1)           ! update before record informations
@@ -286,7 +292,7 @@
                ! read after data
                IF( PRESENT(jpk_bdy) ) THEN
-                  CALL fld_get( sd(jf), imap, jpk_bdy, fvl)
+                  CALL fld_get( sd(jf), imap, jpk_bdy, fvl, ldxios = luxios)
                ELSE
-                  CALL fld_get( sd(jf), imap )
+                  CALL fld_get( sd(jf), imap, ldxios = luxios )
                ENDIF
             ENDIF   ! read new data?
@@ -327,5 +333,5 @@
 
 
-   SUBROUTINE fld_init( kn_fsbc, sdjf, map , jpk_bdy, fvl)
+   SUBROUTINE fld_init( kn_fsbc, sdjf, map , jpk_bdy, fvl, ldxios)
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_init  ***
@@ -339,4 +345,5 @@
       INTEGER  , INTENT(in), OPTIONAL :: jpk_bdy ! number of vertical levels in the BDY data
       LOGICAL  , INTENT(in), OPTIONAL :: fvl     ! number of vertical levels in the BDY data
+      LOGICAL  ,             OPTIONAL :: ldxios  ! use xios for I/O 
       !!
       LOGICAL :: llprevyr              ! are we reading previous year  file?
@@ -350,4 +357,5 @@
       INTEGER :: isec_week             ! number of seconds since start of the weekly file
       CHARACTER(LEN=1000) ::   clfmt   ! write format
+      LOGICAL :: luxios                ! local variable to keep ldxios info
       !!---------------------------------------------------------------------
       llprevyr   = .FALSE.
@@ -356,4 +364,7 @@
       llprevday  = .FALSE.
       isec_week  = 0
+      luxios = .FALSE.
+      IF( PRESENT(ldxios)) luxios = ldxios
+
       !
       ! define record informations
@@ -365,4 +376,8 @@
          !
          IF( sdjf%nrec_a(1) == 0  ) THEN   ! we redefine record sdjf%nrec_a(1) with the last record of previous year file
+            IF(luxios) THEN
+               IF(lwp) write(numout, *) 'Can not use XIOS to read data. Switching to old functionality' 
+               luxios = .FALSE.               ! we can not use XIOS in this case
+            ENDIF
             IF    ( sdjf%nfreqh == -12 ) THEN   ! yearly mean
                IF( sdjf%cltype == 'yearly' ) THEN             ! yearly file
@@ -436,5 +451,5 @@
             CALL fld_get( sdjf, map, jpk_bdy, fvl )
          ELSE
-            CALL fld_get( sdjf, map )
+            CALL fld_get( sdjf, map, ldxios = luxios)
          ENDIF
          !
@@ -613,5 +628,5 @@
 
 
-   SUBROUTINE fld_get( sdjf, map, jpk_bdy, fvl )
+   SUBROUTINE fld_get( sdjf, map, jpk_bdy, fvl, ldxios)
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_get  ***
@@ -623,4 +638,5 @@
       INTEGER  , INTENT(in), OPTIONAL  ::   jpk_bdy ! number of vertical levels in the bdy data
       LOGICAL  , INTENT(in), OPTIONAL  ::   fvl     ! number of vertical levels in the bdy data
+      LOGICAL  ,             OPTIONAL  ::   ldxios  ! xios I/O
       !
       INTEGER ::   ipk      ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
@@ -630,6 +646,11 @@
       INTEGER ::   idmspc   ! number of spatial dimensions
       LOGICAL ::   lmoor    ! C1D case: point data
-      !!---------------------------------------------------------------------
-      !
+      LOGICAL ::   luxios   ! local variable for ldxios
+      REAL(wp)::   amaxval, aminval
+      !!---------------------------------------------------------------------
+      !
+
+      luxios = .FALSE.
+      IF( PRESENT(ldxios) ) luxios = ldxios
       ipk = SIZE( sdjf%fnow, 3 )
       !
@@ -668,13 +689,13 @@
             IF( lk_c1d .AND. lmoor ) THEN
                IF( sdjf%ln_tint ) THEN
-                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fdta(2,2,1,2), sdjf%nrec_a(1) )
+                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fdta(2,2,1,2), sdjf%nrec_a(1), ldxios = luxios )
                   CALL lbc_lnk( 'fldread', sdjf%fdta(:,:,1,2),'Z',1. )
                ELSE
-                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fnow(2,2,1  ), sdjf%nrec_a(1) )
+                  CALL iom_get( sdjf%num, sdjf%clvar, sdjf%fnow(2,2,1  ), sdjf%nrec_a(1), ldxios = luxios )
                   CALL lbc_lnk( 'fldread', sdjf%fnow(:,:,1  ),'Z',1. )
                ENDIF
             ELSE
-               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,1,2), sdjf%nrec_a(1) )
-               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,1  ), sdjf%nrec_a(1) )
+               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,1,2), sdjf%nrec_a(1), ldxios = luxios )
+               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,1  ), sdjf%nrec_a(1), ldxios = luxios )
                ENDIF
             ENDIF
@@ -682,13 +703,13 @@
             IF (lk_c1d .AND. lmoor ) THEN
                IF( sdjf%ln_tint ) THEN
-                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fdta(2,2,:,2), sdjf%nrec_a(1) )
+                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fdta(2,2,:,2), sdjf%nrec_a(1), ldxios = luxios)
                   CALL lbc_lnk( 'fldread', sdjf%fdta(:,:,:,2),'Z',1. )
                ELSE
-                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fnow(2,2,:  ), sdjf%nrec_a(1) )
+                  CALL iom_get( sdjf%num, jpdom_unknown, sdjf%clvar, sdjf%fnow(2,2,:  ), sdjf%nrec_a(1), ldxios = luxios)
                   CALL lbc_lnk( 'fldread', sdjf%fnow(:,:,:  ),'Z',1. )
                ENDIF
             ELSE
-               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1) )
-               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1) )
+               IF( sdjf%ln_tint ) THEN   ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1), ldxios = luxios )
+               ELSE                      ;   CALL iom_get( sdjf%num, ipdom, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1), ldxios = luxios )
                ENDIF
             ENDIF
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/sbcblk.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/sbcblk.F90	(revision 11405)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/sbcblk.F90	(revision 11482)
@@ -827,8 +827,14 @@
                           name = TRIM(aname), domain_ref="grid_global", &
                           operation = "instant")
+            WRITE(aname,'(a3,i2.2)') 'dst',jn
             CALL xios_add_child(file_hdl, field_hdl, TRIM(aname)//TRIM(sf(jf)%wgtname))
             CALL xios_set_attr (field_hdl, enabled = .TRUE., &
                           name = TRIM(aname), domain_ref="grid_global", &
-                          operation = "instant") 
+                          operation = "instant")
+            WRITE(aname,'(a3,i2.2)') 'wgt',jn
+            CALL xios_add_child(file_hdl, field_hdl, TRIM(aname)//TRIM(sf(jf)%wgtname))
+            CALL xios_set_attr (field_hdl, enabled = .TRUE., &
+                          name = TRIM(aname), domain_ref="grid_global", &
+                          operation = "instant")
          ENDDO 
       ENDDO   
