New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
iom.F90 in NEMO/branches/2020/r13916_ticket2377/src/OCE/IOM – NEMO

source: NEMO/branches/2020/r13916_ticket2377/src/OCE/IOM/iom.F90 @ 13954

Last change on this file since 13954 was 13954, checked in by smueller, 4 years ago

Merging of changesets [12591,12602,12608,13082,13094,13096,13950] made in branch /NEMO/branches/2020/ticket_2377 into /NEMO/branches/2020/r13916_ticket2377 (ticket #2377)

  • Property svn:keywords set to Id
File size: 138.4 KB
RevLine 
[544]1MODULE iom
[9019]2   !!======================================================================
[544]3   !!                    ***  MODULE  iom ***
4   !! Input/Output manager :  Library to read input files
[9019]5   !!======================================================================
[3764]6   !! History :  2.0  ! 2005-12  (J. Belier) Original code
7   !!            2.0  ! 2006-02  (S. Masson) Adaptation to NEMO
8   !!            3.0  ! 2007-07  (D. Storkey) Changes to iom_gettime
9   !!            3.4  ! 2012-12  (R. Bourdalle-Badie and G. Reffray)  add C1D case 
[6140]10   !!            3.6  ! 2014-15  DIMG format removed
[7646]11   !!            3.6  ! 2015-15  (J. Harle) Added procedure to read REAL attributes
[9019]12   !!            4.0  ! 2017-11  (M. Andrejczuk) Extend IOM interface to write any 3D fields
13   !!----------------------------------------------------------------------
[544]14
[9019]15   !!----------------------------------------------------------------------
[544]16   !!   iom_open       : open a file read only
17   !!   iom_close      : close a file or all files opened by iom
18   !!   iom_get        : read a field (interfaced to several routines)
19   !!   iom_varid      : get the id of a variable in a file
20   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
[9019]21   !!----------------------------------------------------------------------
[544]22   USE dom_oce         ! ocean space and time domain
[13286]23   USE domutl          !
[3764]24   USE c1d             ! 1D vertical configuration
[3294]25   USE flo_oce         ! floats module declarations
[679]26   USE lbclnk          ! lateal boundary condition / mpp exchanges
[544]27   USE iom_def         ! iom variables definitions
28   USE iom_nf90        ! NetCDF format with native NetCDF library
[2715]29   USE in_out_manager  ! I/O manager
30   USE lib_mpp           ! MPP library
[1412]31#if defined key_iomput
[12377]32   USE sbc_oce  , ONLY :   nn_fsbc, ght_abl, ghw_abl, e3t_abl, e3w_abl, jpka, jpkam1
[9019]33   USE icb_oce  , ONLY :   nclasses, class_num       !  !: iceberg classes
[9570]34#if defined key_si3
[9019]35   USE ice      , ONLY :   jpl
[4691]36#endif
[1725]37   USE phycst          ! physical constants
38   USE dianam          ! build name of file
[3695]39   USE xios
[1359]40# endif
[4148]41   USE ioipsl, ONLY :  ju2ymds    ! for calendar
[4152]42   USE crs             ! Grid coarsening
[10222]43#if defined key_top
44   USE trc, ONLY    :  profsed
45#endif
[9367]46   USE lib_fortran 
[12377]47   USE diu_bulk, ONLY : ln_diurnal_only, ln_diurnal
[1359]48
[544]49   IMPLICIT NONE
[556]50   PUBLIC   !   must be public to be able to access iom_def through iom
[550]51   
[1457]52#if defined key_iomput
[1725]53   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.        !: iom_put flag
[1457]54#else
55   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
56#endif
[12377]57   PUBLIC iom_init, iom_init_closedef, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_get_var
[10522]58   PUBLIC iom_chkatt, iom_getatt, iom_putatt, iom_getszuld, iom_rstput, iom_delay_rst, iom_put
[12377]59   PUBLIC iom_use, iom_context_finalize, iom_update_file_name, iom_miss_val
[544]60
[13226]61   PRIVATE iom_rp0d_sp, iom_rp1d_sp, iom_rp2d_sp, iom_rp3d_sp
62   PRIVATE iom_rp0d_dp, iom_rp1d_dp, iom_rp2d_dp, iom_rp3d_dp
63   PRIVATE iom_get_123d
64   PRIVATE iom_g0d_sp, iom_g1d_sp, iom_g2d_sp, iom_g3d_sp
65   PRIVATE iom_g0d_dp, iom_g1d_dp, iom_g2d_dp, iom_g3d_dp
66   PRIVATE iom_p1d_sp, iom_p2d_sp, iom_p3d_sp, iom_p4d_sp
67   PRIVATE iom_p1d_dp, iom_p2d_dp, iom_p3d_dp, iom_p4d_dp
[1412]68#if defined key_iomput
[4148]69   PRIVATE iom_set_domain_attr, iom_set_axis_attr, iom_set_field_attr, iom_set_file_attr, iom_get_file_attr, iom_set_grid_attr
[12377]70   PRIVATE set_grid, set_grid_bounds, set_scalar, set_xmlatt, set_mooring, iom_sdate
[9367]71   PRIVATE iom_set_rst_context, iom_set_rstw_active, iom_set_rstr_active
[1359]72# endif
[9535]73   PUBLIC iom_set_rstw_var_active, iom_set_rstw_core, iom_set_rst_vars
[752]74
[544]75   INTERFACE iom_get
[13226]76      MODULE PROCEDURE iom_g0d_sp, iom_g1d_sp, iom_g2d_sp, iom_g3d_sp
77      MODULE PROCEDURE iom_g0d_dp, iom_g1d_dp, iom_g2d_dp, iom_g3d_dp
[544]78   END INTERFACE
[2528]79   INTERFACE iom_getatt
[10425]80      MODULE PROCEDURE iom_g0d_iatt, iom_g1d_iatt, iom_g0d_ratt, iom_g1d_ratt, iom_g0d_catt
[2528]81   END INTERFACE
[7646]82   INTERFACE iom_putatt
[10425]83      MODULE PROCEDURE iom_p0d_iatt, iom_p1d_iatt, iom_p0d_ratt, iom_p1d_ratt, iom_p0d_catt
[7646]84   END INTERFACE
[544]85   INTERFACE iom_rstput
[13226]86      MODULE PROCEDURE iom_rp0d_sp, iom_rp1d_sp, iom_rp2d_sp, iom_rp3d_sp
87      MODULE PROCEDURE iom_rp0d_dp, iom_rp1d_dp, iom_rp2d_dp, iom_rp3d_dp
[544]88   END INTERFACE
[9802]89   INTERFACE iom_put
[13226]90      MODULE PROCEDURE iom_p0d_sp, iom_p1d_sp, iom_p2d_sp, iom_p3d_sp, iom_p4d_sp
91      MODULE PROCEDURE iom_p0d_dp, iom_p1d_dp, iom_p2d_dp, iom_p3d_dp, iom_p4d_dp
[9802]92   END INTERFACE iom_put
93 
[12377]94   !! * Substitutions
95#  include "do_loop_substitute.h90"
[544]96   !!----------------------------------------------------------------------
[9598]97   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
[1152]98   !! $Id$
[10068]99   !! Software governed by the CeCILL license (see ./LICENSE)
[544]100   !!----------------------------------------------------------------------
101CONTAINS
102
[13286]103   SUBROUTINE iom_init( cdname, fname, ld_closedef ) 
[1359]104      !!----------------------------------------------------------------------
105      !!                     ***  ROUTINE   ***
106      !!
107      !! ** Purpose :   
108      !!
109      !!----------------------------------------------------------------------
[9903]110      CHARACTER(len=*),           INTENT(in)  :: cdname
[9367]111      CHARACTER(len=*), OPTIONAL, INTENT(in)  :: fname
[12377]112      LOGICAL         , OPTIONAL, INTENT(in)  :: ld_closedef
[1412]113#if defined key_iomput
[9019]114      !
[7646]115      TYPE(xios_duration) :: dtime    = xios_duration(0, 0, 0, 0, 0, 0)
116      TYPE(xios_date)     :: start_date
[9367]117      CHARACTER(len=lc) :: clname
[12276]118      INTEGER             :: irefyear, irefmonth, irefday
[12597]119      INTEGER           :: ji
[9367]120      LOGICAL :: llrst_context              ! is context related to restart
[5415]121      !
[7646]122      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds
[12377]123      REAL(wp), DIMENSION(2,jpkam1)         :: za_bnds   ! ABL vertical boundaries
124      LOGICAL ::   ll_closedef = .TRUE.
[13557]125      LOGICAL ::   ll_exist
[1359]126      !!----------------------------------------------------------------------
[9019]127      !
[12377]128      IF ( PRESENT(ld_closedef) ) ll_closedef = ld_closedef
[9802]129      !
[7646]130      ALLOCATE( zt_bnds(2,jpk), zw_bnds(2,jpk) )
[9019]131      !
[4152]132      clname = cdname
133      IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname)
[9570]134      CALL xios_context_initialize(TRIM(clname), mpi_comm_oce)
[4152]135      CALL iom_swap( cdname )
[9367]136      llrst_context =  (TRIM(cdname) == TRIM(crxios_context) .OR. TRIM(cdname) == TRIM(cwxios_context))
[1359]137
[7646]138      ! Calendar type is now defined in xml file
[12276]139      IF (.NOT.(xios_getvar('ref_year' ,irefyear ))) irefyear  = 1900
140      IF (.NOT.(xios_getvar('ref_month',irefmonth))) irefmonth = 01
141      IF (.NOT.(xios_getvar('ref_day'  ,irefday  ))) irefday   = 01
142
[1725]143      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
[13286]144      CASE ( 1)   ;   CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(irefyear,irefmonth,irefday,0,0,0),   &
145          &                                                          start_date  = xios_date(   nyear,   nmonth,   nday,0,0,0) )
146      CASE ( 0)   ;   CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(irefyear,irefmonth,irefday,0,0,0),   &
147          &                                                          start_date  = xios_date(   nyear,   nmonth,   nday,0,0,0) )
148      CASE (30)   ;   CALL xios_define_calendar( TYPE = "D360"     , time_origin = xios_date(irefyear,irefmonth,irefday,0,0,0),   &
149          &                                                          start_date  = xios_date(   nyear,   nmonth,   nday,0,0,0) )
[1725]150      END SELECT
[1359]151
152      ! horizontal grid definition
[9367]153      IF(.NOT.llrst_context) CALL set_scalar
[9019]154      !
[5407]155      IF( TRIM(cdname) == TRIM(cxios_context) ) THEN 
[9984]156         CALL set_grid( "T", glamt, gphit, .FALSE., .FALSE. ) 
157         CALL set_grid( "U", glamu, gphiu, .FALSE., .FALSE. )
158         CALL set_grid( "V", glamv, gphiv, .FALSE., .FALSE. )
159         CALL set_grid( "W", glamt, gphit, .FALSE., .FALSE. )
[5385]160         CALL set_grid_znl( gphit )
[5415]161         !
162         IF( ln_cfmeta ) THEN   ! Add additional grid metadata
[13286]163            CALL iom_set_domain_attr("grid_T", area = real( e1e2t(Nis0:Nie0, Njs0:Nje0), dp))
164            CALL iom_set_domain_attr("grid_U", area = real( e1e2u(Nis0:Nie0, Njs0:Nje0), dp))
165            CALL iom_set_domain_attr("grid_V", area = real( e1e2v(Nis0:Nie0, Njs0:Nje0), dp))
166            CALL iom_set_domain_attr("grid_W", area = real( e1e2t(Nis0:Nie0, Njs0:Nje0), dp))
[5415]167            CALL set_grid_bounds( "T", glamf, gphif, glamt, gphit )
168            CALL set_grid_bounds( "U", glamv, gphiv, glamu, gphiu )
169            CALL set_grid_bounds( "V", glamu, gphiu, glamv, gphiv )
170            CALL set_grid_bounds( "W", glamf, gphif, glamt, gphit )
171         ENDIF
[4152]172      ENDIF
[9019]173      !
[5407]174      IF( TRIM(cdname) == TRIM(cxios_context)//"_crs" ) THEN 
[4152]175         CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
176         !
[9984]177         CALL set_grid( "T", glamt_crs, gphit_crs, .FALSE., .FALSE. ) 
178         CALL set_grid( "U", glamu_crs, gphiu_crs, .FALSE., .FALSE. ) 
179         CALL set_grid( "V", glamv_crs, gphiv_crs, .FALSE., .FALSE. ) 
180         CALL set_grid( "W", glamt_crs, gphit_crs, .FALSE., .FALSE. ) 
[5385]181         CALL set_grid_znl( gphit_crs )
[4152]182          !
183         CALL dom_grid_glo   ! Return to parent grid domain
[5415]184         !
[9367]185         IF( ln_cfmeta .AND. .NOT. llrst_context) THEN   ! Add additional grid metadata
[13286]186            CALL iom_set_domain_attr("grid_T", area = real(e1e2t_crs(Nis0:Nie0, Njs0:Nje0), dp))
187            CALL iom_set_domain_attr("grid_U", area = real(e1u_crs(Nis0:Nie0, Njs0:Nje0) * e2u_crs(Nis0:Nie0, Njs0:Nje0), dp))
188            CALL iom_set_domain_attr("grid_V", area = real(e1v_crs(Nis0:Nie0, Njs0:Nje0) * e2v_crs(Nis0:Nie0, Njs0:Nje0), dp))
189            CALL iom_set_domain_attr("grid_W", area = real(e1e2t_crs(Nis0:Nie0, Njs0:Nje0), dp))
[5415]190            CALL set_grid_bounds( "T", glamf_crs, gphif_crs, glamt_crs, gphit_crs )
191            CALL set_grid_bounds( "U", glamv_crs, gphiv_crs, glamu_crs, gphiu_crs )
192            CALL set_grid_bounds( "V", glamu_crs, gphiu_crs, glamv_crs, gphiv_crs )
193            CALL set_grid_bounds( "W", glamf_crs, gphif_crs, glamt_crs, gphit_crs )
194         ENDIF
[4152]195      ENDIF
[9019]196      !
[1359]197      ! vertical grid definition
[9367]198      IF(.NOT.llrst_context) THEN
[12377]199          CALL iom_set_axis_attr(  "deptht", paxis = gdept_1d )
200          CALL iom_set_axis_attr(  "depthu", paxis = gdept_1d )
201          CALL iom_set_axis_attr(  "depthv", paxis = gdept_1d )
202          CALL iom_set_axis_attr(  "depthw", paxis = gdepw_1d )
[9367]203
[12377]204          ! ABL
205          IF( .NOT. ALLOCATED(ght_abl) ) THEN   ! force definition for xml files (xios)
206             ALLOCATE( ght_abl(jpka), ghw_abl(jpka), e3t_abl(jpka), e3w_abl(jpka) )   ! default allocation needed by iom
207             ght_abl(:) = -1._wp   ;   ghw_abl(:) = -1._wp
208             e3t_abl(:) = -1._wp   ;   e3w_abl(:) = -1._wp
209          ENDIF
210          CALL iom_set_axis_attr( "ght_abl", ght_abl(2:jpka) )
211          CALL iom_set_axis_attr( "ghw_abl", ghw_abl(2:jpka) )
212         
[9367]213          ! Add vertical grid bounds
[12597]214          zt_bnds(2,:      ) = gdept_1d(:)
215          zt_bnds(1,2:jpk  ) = gdept_1d(1:jpkm1)
216          zt_bnds(1,1      ) = gdept_1d(1) - e3w_1d(1)
217          zw_bnds(1,:      ) = gdepw_1d(:)
218          zw_bnds(2,1:jpkm1) = gdepw_1d(2:jpk)
219          zw_bnds(2,jpk:   ) = gdepw_1d(jpk) + e3t_1d(jpk)
[12377]220          CALL iom_set_axis_attr(  "deptht", bounds=zw_bnds )
221          CALL iom_set_axis_attr(  "depthu", bounds=zw_bnds )
222          CALL iom_set_axis_attr(  "depthv", bounds=zw_bnds )
223          CALL iom_set_axis_attr(  "depthw", bounds=zt_bnds )
224
225          ! ABL
226          za_bnds(1,:) = ghw_abl(1:jpkam1)
227          za_bnds(2,:) = ghw_abl(2:jpka  )
228          CALL iom_set_axis_attr( "ght_abl", bounds=za_bnds )
229          za_bnds(1,:) = ght_abl(2:jpka  )
230          za_bnds(2,:) = ght_abl(2:jpka  ) + e3w_abl(2:jpka)
231          CALL iom_set_axis_attr( "ghw_abl", bounds=za_bnds )
232
[13557]233          CALL iom_set_axis_attr(  "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) )
[9570]234# if defined key_si3
[9367]235          CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
236          ! SIMIP diagnostics (4 main arctic straits)
237          CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) )
[9019]238# endif
[10222]239#if defined key_top
[10817]240          IF( ALLOCATED(profsed) ) CALL iom_set_axis_attr( "profsed", paxis = profsed )
[10222]241#endif
[9367]242          CALL iom_set_axis_attr( "icbcla", class_num )
[10817]243          CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )   ! strange syntaxe and idea...
[12276]244          CALL iom_set_axis_attr( "iax_26C", (/ REAL(26,wp) /) )   ! strange syntaxe and idea...
[10817]245          CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )   ! strange syntaxe and idea...
[13557]246          ! for diaprt, we need to define an axis which size can be 1 (default) or 5 (if the file subbasins.nc exists)
247          INQUIRE( FILE = 'subbasins.nc', EXIST = ll_exist )
248          nbasin = 1 + 4 * COUNT( (/ll_exist/) )
249          CALL iom_set_axis_attr( "basin"  , (/ (REAL(ji,wp), ji=1,nbasin) /) )
[9367]250      ENDIF
251      !
[1725]252      ! automatic definitions of some of the xml attributs
[9367]253      IF( TRIM(cdname) == TRIM(crxios_context) ) THEN
254!set names of the fields in restart file IF using XIOS to read data
[9984]255          CALL iom_set_rst_context(.TRUE.)
[9367]256          CALL iom_set_rst_vars(rst_rfields)
257!set which fields are to be read from restart file
258          CALL iom_set_rstr_active()
259      ELSE IF( TRIM(cdname) == TRIM(cwxios_context) ) THEN
260!set names of the fields in restart file IF using XIOS to write data
[9984]261          CALL iom_set_rst_context(.FALSE.)
[9367]262          CALL iom_set_rst_vars(rst_wfields)
263!set which fields are to be written to a restart file
264          CALL iom_set_rstw_active(fname)
265      ELSE
266          CALL set_xmlatt
267      ENDIF
[9019]268      !
[12377]269      ! set time step length
[12489]270      dtime%second = rn_Dt
[9019]271      CALL xios_set_timestep( dtime )
272      !
[12377]273      ! conditional closure of context definition
274      IF ( ll_closedef ) CALL iom_init_closedef
275      !
[7646]276      DEALLOCATE( zt_bnds, zw_bnds )
[9019]277      !
[1359]278#endif
[9019]279      !
[1359]280   END SUBROUTINE iom_init
281
[12377]282   SUBROUTINE iom_init_closedef
283      !!----------------------------------------------------------------------
284      !!            ***  SUBROUTINE iom_init_closedef  ***
285      !!----------------------------------------------------------------------
286      !!
287      !! ** Purpose : Closure of context definition
288      !!
289      !!----------------------------------------------------------------------
290
291#if defined key_iomput
292      CALL xios_close_context_definition()
293      CALL xios_update_calendar( 0 )
294#else
295      IF( .FALSE. )   WRITE(numout,*) 'iom_init_closedef: should not see this'   ! useless statement to avoid compilation warnings
296#endif
297
298   END SUBROUTINE iom_init_closedef
299
[9367]300   SUBROUTINE iom_set_rstw_var_active(field)
301      !!---------------------------------------------------------------------
302      !!                   ***  SUBROUTINE  iom_set_rstw_var_active  ***
303      !!
304      !! ** Purpose :  enable variable in restart file when writing with XIOS
305      !!---------------------------------------------------------------------
306   CHARACTER(len = *), INTENT(IN) :: field
307   INTEGER :: i
308   LOGICAL :: llis_set
[9535]309   CHARACTER(LEN=256) :: clinfo    ! info character
[1359]310
[9535]311#if defined key_iomput
[9367]312   llis_set = .FALSE.
313
314   DO i = 1, max_rst_fields
315       IF(TRIM(rst_wfields(i)%vname) == field) THEN
316          rst_wfields(i)%active = .TRUE.
317          llis_set = .TRUE.
318          EXIT
319       ENDIF
320   ENDDO
321!Warn if variable is not in defined in rst_wfields
322   IF(.NOT.llis_set) THEN
[10425]323      WRITE(ctmp1,*) 'iom_set_rstw_var_active: variable ', field ,' is available for writing but not defined' 
324      CALL ctl_stop( 'iom_set_rstw_var_active:', ctmp1 )
[9367]325   ENDIF
[9535]326#else
[9536]327        clinfo = 'iom_set_rstw_var_active: key_iomput is needed to use XIOS restart read/write functionality'
328        CALL ctl_stop('STOP', TRIM(clinfo))
[9535]329#endif
[9367]330
331   END SUBROUTINE iom_set_rstw_var_active
332
333   SUBROUTINE iom_set_rstr_active()
334      !!---------------------------------------------------------------------
335      !!                   ***  SUBROUTINE  iom_set_rstr_active  ***
336      !!
337      !! ** Purpose :  define file name in XIOS context for reading restart file,
338      !!               enable variables present in restart file for reading with XIOS
339      !!---------------------------------------------------------------------
340
341!sets enabled = .TRUE. for each field in restart file
342   CHARACTER(len=256) :: rst_file
[9535]343
344#if defined key_iomput
[9367]345   TYPE(xios_field) :: field_hdl
346   TYPE(xios_file) :: file_hdl
347   TYPE(xios_filegroup) :: filegroup_hdl
348   INTEGER :: i
349   CHARACTER(lc)  ::   clpath
350
351        clpath = TRIM(cn_ocerst_indir)
352        IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
353        IF( TRIM(Agrif_CFixed()) == '0' ) THEN
354           rst_file = TRIM(clpath)//TRIM(cn_ocerst_in)
355        ELSE
[13472]356           rst_file = TRIM(clpath)//TRIM(Agrif_CFixed())//'_'//TRIM(cn_ocerst_in)
[9367]357        ENDIF
358!set name of the restart file and enable available fields
359        if(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS) to: ',rst_file
360        CALL xios_get_handle("file_definition", filegroup_hdl )
361        CALL xios_add_child(filegroup_hdl, file_hdl, 'rrestart')
362        CALL xios_set_file_attr( "rrestart", name=trim(rst_file), type="one_file", &
363             par_access="collective", enabled=.TRUE., mode="read",                 &
364             output_freq=xios_timestep)
365!define variables for restart context
366        DO i = 1, max_rst_fields
367         IF( TRIM(rst_rfields(i)%vname) /= "NO_NAME") THEN
368           IF( iom_varid( numror, TRIM(rst_rfields(i)%vname), ldstop = .FALSE. ) > 0 ) THEN
369                CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_rfields(i)%vname))
370                SELECT CASE (TRIM(rst_rfields(i)%grid))
371                 CASE ("grid_N_3D")
372                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
373                        domain_ref="grid_N", axis_ref="nav_lev", operation = "instant")
374                 CASE ("grid_N")
375                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
376                        domain_ref="grid_N", operation = "instant") 
377                CASE ("grid_vector")
378                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
379                         axis_ref="nav_lev", operation = "instant")
380                 CASE ("grid_scalar")
381                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
382                        scalar_ref = "grid_scalar", operation = "instant")
383                END SELECT
384                IF(lwp) WRITE(numout,*) 'XIOS read: ', TRIM(rst_rfields(i)%vname), ' enabled in ', TRIM(rst_file)
385           ENDIF
386         ENDIF
387        END DO
[9535]388#endif
[9367]389   END SUBROUTINE iom_set_rstr_active
390
391   SUBROUTINE iom_set_rstw_core(cdmdl)
392      !!---------------------------------------------------------------------
393      !!                   ***  SUBROUTINE  iom_set_rstw_core  ***
394      !!
395      !! ** Purpose :  set variables which are always in restart file
396      !!---------------------------------------------------------------------
397   CHARACTER (len=*), INTENT (IN) :: cdmdl ! model OPA or SAS
[9535]398   CHARACTER(LEN=256)             :: clinfo    ! info character
399#if defined key_iomput
[9367]400   IF(cdmdl == "OPA") THEN
401!from restart.F90
[12489]402   CALL iom_set_rstw_var_active("rn_Dt")
[9367]403   IF ( .NOT. ln_diurnal_only ) THEN
404        CALL iom_set_rstw_var_active('ub'  )
405        CALL iom_set_rstw_var_active('vb'  )
406        CALL iom_set_rstw_var_active('tb'  )
407        CALL iom_set_rstw_var_active('sb'  )
408        CALL iom_set_rstw_var_active('sshb')
409        !
410        CALL iom_set_rstw_var_active('un'  )
411        CALL iom_set_rstw_var_active('vn'  )
412        CALL iom_set_rstw_var_active('tn'  )
413        CALL iom_set_rstw_var_active('sn'  )
414        CALL iom_set_rstw_var_active('sshn')
415        CALL iom_set_rstw_var_active('rhop')
416      ENDIF
417      IF(ln_diurnal) CALL iom_set_rstw_var_active('Dsst')
418!from trasbc.F90
419         CALL iom_set_rstw_var_active('sbc_hc_b')
420         CALL iom_set_rstw_var_active('sbc_sc_b')
421   ENDIF
[9535]422#else
[9536]423        clinfo = 'iom_set_rstw_core: key_iomput is needed to use XIOS restart read/write functionality'
424        CALL ctl_stop('STOP', TRIM(clinfo))
[9535]425#endif
[9367]426   END SUBROUTINE iom_set_rstw_core
427
428   SUBROUTINE iom_set_rst_vars(fields)
429      !!---------------------------------------------------------------------
[9535]430      !!                   ***  SUBROUTINE iom_set_rst_vars   ***
[9367]431      !!
432      !! ** Purpose :  Fill array fields with the information about all
433      !!               possible variables and corresponding grids definition
434      !!               for reading/writing restart with XIOS
435      !!---------------------------------------------------------------------
436   TYPE(RST_FIELD), INTENT(INOUT) :: fields(max_rst_fields)
[9535]437   INTEGER :: i
[9367]438
439        i = 0
[12489]440        i = i + 1; fields(i)%vname="rn_Dt";            fields(i)%grid="grid_scalar"
[9367]441        i = i + 1; fields(i)%vname="un";             fields(i)%grid="grid_N_3D"
442        i = i + 1; fields(i)%vname="ub";             fields(i)%grid="grid_N_3D"
443        i = i + 1; fields(i)%vname="vn";             fields(i)%grid="grid_N_3D"
444        i = i + 1; fields(i)%vname="vb";             fields(i)%grid="grid_N_3D" 
445        i = i + 1; fields(i)%vname="tn";             fields(i)%grid="grid_N_3D"
446        i = i + 1; fields(i)%vname="tb";             fields(i)%grid="grid_N_3D"
447        i = i + 1; fields(i)%vname="sn";             fields(i)%grid="grid_N_3D"
448        i = i + 1; fields(i)%vname="sb";             fields(i)%grid="grid_N_3D"
449        i = i + 1; fields(i)%vname="sshn";           fields(i)%grid="grid_N"
450        i = i + 1; fields(i)%vname="sshb";           fields(i)%grid="grid_N"
451        i = i + 1; fields(i)%vname="rhop";           fields(i)%grid="grid_N_3D"
452        i = i + 1; fields(i)%vname="kt";             fields(i)%grid="grid_scalar"
453        i = i + 1; fields(i)%vname="ndastp";         fields(i)%grid="grid_scalar"
454        i = i + 1; fields(i)%vname="adatrj";         fields(i)%grid="grid_scalar"
455        i = i + 1; fields(i)%vname="utau_b";         fields(i)%grid="grid_N"
456        i = i + 1; fields(i)%vname="vtau_b";         fields(i)%grid="grid_N"
457        i = i + 1; fields(i)%vname="qns_b";          fields(i)%grid="grid_N"
458        i = i + 1; fields(i)%vname="emp_b";          fields(i)%grid="grid_N"
459        i = i + 1; fields(i)%vname="sfx_b";          fields(i)%grid="grid_N"
460        i = i + 1; fields(i)%vname="en" ;            fields(i)%grid="grid_N_3D" 
461        i = i + 1; fields(i)%vname="avt_k";            fields(i)%grid="grid_N_3D"
462        i = i + 1; fields(i)%vname="avm_k";            fields(i)%grid="grid_N_3D"
463        i = i + 1; fields(i)%vname="dissl";          fields(i)%grid="grid_N_3D"
464        i = i + 1; fields(i)%vname="sbc_hc_b";       fields(i)%grid="grid_N"
465        i = i + 1; fields(i)%vname="sbc_sc_b";       fields(i)%grid="grid_N"
466        i = i + 1; fields(i)%vname="qsr_hc_b";       fields(i)%grid="grid_N_3D"
467        i = i + 1; fields(i)%vname="fraqsr_1lev";    fields(i)%grid="grid_N"
468        i = i + 1; fields(i)%vname="greenland_icesheet_mass"
469                                               fields(i)%grid="grid_scalar"
470        i = i + 1; fields(i)%vname="greenland_icesheet_timelapsed"
471                                               fields(i)%grid="grid_scalar"
472        i = i + 1; fields(i)%vname="greenland_icesheet_mass_roc"
473                                               fields(i)%grid="grid_scalar"
474        i = i + 1; fields(i)%vname="antarctica_icesheet_mass"
475                                               fields(i)%grid="grid_scalar"
476        i = i + 1; fields(i)%vname="antarctica_icesheet_timelapsed"
477                                               fields(i)%grid="grid_scalar"
478        i = i + 1; fields(i)%vname="antarctica_icesheet_mass_roc"
479                                               fields(i)%grid="grid_scalar"
480        i = i + 1; fields(i)%vname="frc_v";          fields(i)%grid="grid_scalar"
481        i = i + 1; fields(i)%vname="frc_t";          fields(i)%grid="grid_scalar"
482        i = i + 1; fields(i)%vname="frc_s";          fields(i)%grid="grid_scalar"
483        i = i + 1; fields(i)%vname="frc_wn_t";       fields(i)%grid="grid_scalar"
484        i = i + 1; fields(i)%vname="frc_wn_s";       fields(i)%grid="grid_scalar"
485        i = i + 1; fields(i)%vname="ssh_ini";        fields(i)%grid="grid_N"
486        i = i + 1; fields(i)%vname="e3t_ini";        fields(i)%grid="grid_N_3D"
487        i = i + 1; fields(i)%vname="hc_loc_ini";     fields(i)%grid="grid_N_3D"
488        i = i + 1; fields(i)%vname="sc_loc_ini";     fields(i)%grid="grid_N_3D"
489        i = i + 1; fields(i)%vname="ssh_hc_loc_ini"; fields(i)%grid="grid_N"
490        i = i + 1; fields(i)%vname="ssh_sc_loc_ini"; fields(i)%grid="grid_N"
491        i = i + 1; fields(i)%vname="tilde_e3t_b";    fields(i)%grid="grid_N"
492        i = i + 1; fields(i)%vname="tilde_e3t_n";    fields(i)%grid="grid_N"
493        i = i + 1; fields(i)%vname="hdiv_lf";        fields(i)%grid="grid_N"
494        i = i + 1; fields(i)%vname="ub2_b";          fields(i)%grid="grid_N"
495        i = i + 1; fields(i)%vname="vb2_b";          fields(i)%grid="grid_N"
496        i = i + 1; fields(i)%vname="sshbb_e";        fields(i)%grid="grid_N"
497        i = i + 1; fields(i)%vname="ubb_e";          fields(i)%grid="grid_N"
498        i = i + 1; fields(i)%vname="vbb_e";          fields(i)%grid="grid_N"
499        i = i + 1; fields(i)%vname="sshb_e";         fields(i)%grid="grid_N"
500        i = i + 1; fields(i)%vname="ub_e";           fields(i)%grid="grid_N"
501        i = i + 1; fields(i)%vname="vb_e";           fields(i)%grid="grid_N"
502        i = i + 1; fields(i)%vname="fwf_isf_b";      fields(i)%grid="grid_N"
503        i = i + 1; fields(i)%vname="isf_sc_b";       fields(i)%grid="grid_N"
504        i = i + 1; fields(i)%vname="isf_hc_b";       fields(i)%grid="grid_N"
505        i = i + 1; fields(i)%vname="ssh_ibb";        fields(i)%grid="grid_N"
506        i = i + 1; fields(i)%vname="rnf_b";          fields(i)%grid="grid_N"
507        i = i + 1; fields(i)%vname="rnf_hc_b";       fields(i)%grid="grid_N"
508        i = i + 1; fields(i)%vname="rnf_sc_b";       fields(i)%grid="grid_N"
509        i = i + 1; fields(i)%vname="nn_fsbc";        fields(i)%grid="grid_scalar"
510        i = i + 1; fields(i)%vname="ssu_m";          fields(i)%grid="grid_N"
511        i = i + 1; fields(i)%vname="ssv_m";          fields(i)%grid="grid_N"
512        i = i + 1; fields(i)%vname="sst_m";          fields(i)%grid="grid_N"
513        i = i + 1; fields(i)%vname="sss_m";          fields(i)%grid="grid_N"
514        i = i + 1; fields(i)%vname="ssh_m";          fields(i)%grid="grid_N"
515        i = i + 1; fields(i)%vname="e3t_m";          fields(i)%grid="grid_N"
516        i = i + 1; fields(i)%vname="frq_m";          fields(i)%grid="grid_N"
517        i = i + 1; fields(i)%vname="avmb";           fields(i)%grid="grid_vector"
518        i = i + 1; fields(i)%vname="avtb";           fields(i)%grid="grid_vector"
519        i = i + 1; fields(i)%vname="ub2_i_b";        fields(i)%grid="grid_N"
520        i = i + 1; fields(i)%vname="vb2_i_b";        fields(i)%grid="grid_N"
521        i = i + 1; fields(i)%vname="ntime";          fields(i)%grid="grid_scalar"
522        i = i + 1; fields(i)%vname="Dsst";           fields(i)%grid="grid_scalar"
523        i = i + 1; fields(i)%vname="tmask";          fields(i)%grid="grid_N_3D"
524        i = i + 1; fields(i)%vname="umask";          fields(i)%grid="grid_N_3D"
525        i = i + 1; fields(i)%vname="vmask";          fields(i)%grid="grid_N_3D"
526        i = i + 1; fields(i)%vname="smask";          fields(i)%grid="grid_N_3D"
527        i = i + 1; fields(i)%vname="gdepw_n";        fields(i)%grid="grid_N_3D"
528        i = i + 1; fields(i)%vname="e3t_n";          fields(i)%grid="grid_N_3D"
529        i = i + 1; fields(i)%vname="e3u_n";          fields(i)%grid="grid_N_3D"
530        i = i + 1; fields(i)%vname="e3v_n";          fields(i)%grid="grid_N_3D"
531        i = i + 1; fields(i)%vname="surf_ini";       fields(i)%grid="grid_N"
532        i = i + 1; fields(i)%vname="e3t_b";          fields(i)%grid="grid_N_3D"
533        i = i + 1; fields(i)%vname="hmxl_n";         fields(i)%grid="grid_N_3D"
534        i = i + 1; fields(i)%vname="un_bf";          fields(i)%grid="grid_N"
535        i = i + 1; fields(i)%vname="vn_bf";          fields(i)%grid="grid_N"
536        i = i + 1; fields(i)%vname="hbl";            fields(i)%grid="grid_N"
537        i = i + 1; fields(i)%vname="hbli";           fields(i)%grid="grid_N"
538        i = i + 1; fields(i)%vname="wn";             fields(i)%grid="grid_N_3D"
[13954]539        i = i + 1; fields(i)%vname="a_fwb";          fields(i)%grid="grid_scalar"
[9367]540
541        IF( i-1 > max_rst_fields) THEN
[10425]542           WRITE(ctmp1,*) 'E R R O R : iom_set_rst_vars SIZE of RST_FIELD array is too small'
543           CALL ctl_stop( 'iom_set_rst_vars:', ctmp1 )
[9367]544        ENDIF
545   END SUBROUTINE iom_set_rst_vars
546
547
548   SUBROUTINE iom_set_rstw_active(cdrst_file)
549      !!---------------------------------------------------------------------
[9535]550      !!                   ***  SUBROUTINE iom_set_rstw_active   ***
[9367]551      !!
552      !! ** Purpose :  define file name in XIOS context for writing restart
553      !!               enable variables present in restart file for writing
554      !!---------------------------------------------------------------------
555!sets enabled = .TRUE. for each field in restart file
556   CHARACTER(len=*) :: cdrst_file
557#if defined key_iomput
558   TYPE(xios_field) :: field_hdl
559   TYPE(xios_file) :: file_hdl
560   TYPE(xios_filegroup) :: filegroup_hdl
561   INTEGER :: i
562   CHARACTER(lc)  ::   clpath
563
564!set name of the restart file and enable available fields
565        IF(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS write) to: ',cdrst_file
566        CALL xios_get_handle("file_definition", filegroup_hdl )
567        CALL xios_add_child(filegroup_hdl, file_hdl, 'wrestart')
568        IF(nxioso.eq.1) THEN
569           CALL xios_set_file_attr( "wrestart", type="one_file", enabled=.TRUE.,& 
570                                    mode="write", output_freq=xios_timestep) 
571           if(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in one_file mode' 
572        ELSE 
573           CALL xios_set_file_attr( "wrestart", type="multiple_file", enabled=.TRUE.,& 
574                                    mode="write", output_freq=xios_timestep) 
575           if(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in multiple_file mode' 
576        ENDIF
577        CALL xios_set_file_attr( "wrestart", name=trim(cdrst_file))
578!define fields for restart context
579        DO i = 1, max_rst_fields
580         IF( rst_wfields(i)%active ) THEN
581                CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_wfields(i)%vname))
582                SELECT CASE (TRIM(rst_wfields(i)%grid))
583                 CASE ("grid_N_3D")
584                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
585                        domain_ref="grid_N", axis_ref="nav_lev", prec = 8, operation = "instant")
586                 CASE ("grid_N")
587                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
588                        domain_ref="grid_N", prec = 8, operation = "instant") 
589                 CASE ("grid_vector")
590                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
591                         axis_ref="nav_lev", prec = 8, operation = "instant")
592                 CASE ("grid_scalar")
593                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
594                        scalar_ref = "grid_scalar", prec = 8, operation = "instant")
595                END SELECT
596         ENDIF
597        END DO
598#endif
599   END SUBROUTINE iom_set_rstw_active
600
[9984]601   SUBROUTINE iom_set_rst_context(ld_rstr) 
[9367]602     !!---------------------------------------------------------------------
[9535]603      !!                   ***  SUBROUTINE  iom_set_rst_context  ***
[9367]604      !!
605      !! ** Purpose : Define domain, axis and grid for restart (read/write)
606      !!              context
607      !!               
608      !!---------------------------------------------------------------------
[9984]609   LOGICAL, INTENT(IN)               :: ld_rstr
610!ld_rstr is true for restart context. There is no need to define grid for
611!restart read, because it's read from file
[9367]612#if defined key_iomput
613   TYPE(xios_domaingroup)            :: domaingroup_hdl 
614   TYPE(xios_domain)                 :: domain_hdl 
615   TYPE(xios_axisgroup)              :: axisgroup_hdl 
616   TYPE(xios_axis)                   :: axis_hdl 
617   TYPE(xios_scalar)                 :: scalar_hdl 
618   TYPE(xios_scalargroup)            :: scalargroup_hdl 
619
620     CALL xios_get_handle("domain_definition",domaingroup_hdl) 
621     CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_N") 
[9984]622     CALL set_grid("N", glamt, gphit, .TRUE., ld_rstr) 
[9367]623 
624     CALL xios_get_handle("axis_definition",axisgroup_hdl) 
625     CALL xios_add_child(axisgroup_hdl, axis_hdl, "nav_lev") 
626!AGRIF fails to compile when unit= is in call to xios_set_axis_attr
627!    CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels",  unit="m", positive="down")
628     CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels in meters", positive="down")
629     CALL iom_set_axis_attr( "nav_lev", paxis = gdept_1d ) 
630
631     CALL xios_get_handle("scalar_definition", scalargroup_hdl) 
632     CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") 
633#endif
634   END SUBROUTINE iom_set_rst_context
635
[4152]636   SUBROUTINE iom_swap( cdname )
[1793]637      !!---------------------------------------------------------------------
638      !!                   ***  SUBROUTINE  iom_swap  ***
639      !!
640      !! ** Purpose :  swap context between different agrif grid for xmlio_server
641      !!---------------------------------------------------------------------
[4152]642      CHARACTER(len=*), INTENT(in) :: cdname
[1793]643#if defined key_iomput
[3695]644      TYPE(xios_context) :: nemo_hdl
[1793]645
[4152]646      IF( TRIM(Agrif_CFixed()) == '0' ) THEN
647        CALL xios_get_handle(TRIM(cdname),nemo_hdl)
648      ELSE
649        CALL xios_get_handle(TRIM(Agrif_CFixed())//"_"//TRIM(cdname),nemo_hdl)
650      ENDIF
651      !
652      CALL xios_set_current_context(nemo_hdl)
[1793]653#endif
[4152]654      !
[1793]655   END SUBROUTINE iom_swap
656
657
[13286]658   SUBROUTINE iom_open( cdname, kiomid, ldwrt, ldstop, ldiof, kdlev, cdcomp )
[544]659      !!---------------------------------------------------------------------
660      !!                   ***  SUBROUTINE  iom_open  ***
661      !!
662      !! ** Purpose :  open an input file (return 0 if not found)
663      !!---------------------------------------------------------------------
664      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
665      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
666      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
[679]667      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
[1319]668      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
[9019]669      INTEGER         , INTENT(in   ), OPTIONAL ::   kdlev    ! number of vertical levels
[12649]670      CHARACTER(len=3), INTENT(in   ), OPTIONAL ::   cdcomp   ! name of component calling iom_nf90_open
[9019]671      !
[4148]672      CHARACTER(LEN=256)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
673      CHARACTER(LEN=256)    ::   cltmpn    ! tempory name to store clname (in writting mode)
[6140]674      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc"
[550]675      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
[4148]676      CHARACTER(LEN=256)    ::   clinfo    ! info character
[544]677      LOGICAL               ::   llok      ! check the existence
[679]678      LOGICAL               ::   llwrt     ! local definition of ldwrt
679      LOGICAL               ::   llstop    ! local definition of ldstop
[1319]680      LOGICAL               ::   lliof     ! local definition of ldiof
[544]681      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
682      INTEGER               ::   iln, ils  ! lengths of character
683      INTEGER               ::   istop     !
684      ! local number of points for x,y dimensions
685      ! position of first local point for x,y dimensions
686      ! position of last local point for x,y dimensions
687      ! start halo size for x,y dimensions
688      ! end halo size for x,y dimensions
689      !---------------------------------------------------------------------
690      ! Initializations and control
691      ! =============
[1341]692      kiomid = -1
[544]693      clinfo = '                    iom_open ~~~  '
694      istop = nstop
695      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
696      ! (could be done when defining iom_file in f95 but not in f90)
[1441]697      IF( Agrif_Root() ) THEN
698         IF( iom_open_init == 0 ) THEN
699            iom_file(:)%nfid = 0
700            iom_open_init = 1
701         ENDIF
[1409]702      ENDIF
[544]703      ! do we read or write the file?
704      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
705      ELSE                        ;   llwrt = .FALSE.
706      ENDIF
[679]707      ! do we call ctl_stop if we try to open a non-existing file in read mode?
708      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
709      ELSE                         ;   llstop = .TRUE.
710      ENDIF
[1319]711      ! are we using interpolation on the fly?
712      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
713      ELSE                        ;   lliof = .FALSE.
714      ENDIF
[544]715      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
716      ! =============
717      clname   = trim(cdname)
[1319]718      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
[12377]719         iln    = INDEX(clname,'/') 
[1200]720         cltmpn = clname(1:iln)
721         clname = clname(iln+1:LEN_TRIM(clname))
722         clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname)
723      ENDIF
[544]724      ! which suffix should we use?
[10425]725      clsuffix = '.nc'
[544]726      ! Add the suffix if needed
727      iln = LEN_TRIM(clname)
728      ils = LEN_TRIM(clsuffix)
[742]729      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
730         &   clname = TRIM(clname)//TRIM(clsuffix)
[544]731      cltmpn = clname   ! store this name
732      ! try to find if the file to be opened already exist
733      ! =============
734      INQUIRE( FILE = clname, EXIST = llok )
735      IF( .NOT.llok ) THEN
736         ! we try to add the cpu number to the name
[6140]737         WRITE(clcpu,*) narea-1
738
[544]739         clcpu  = TRIM(ADJUSTL(clcpu))
[679]740         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
[544]741         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
742         icnt = 0
743         INQUIRE( FILE = clname, EXIST = llok ) 
744         ! we try different formats for the cpu number by adding 0
745         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
746            clcpu  = "0"//trim(clcpu)
747            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
748            INQUIRE( FILE = clname, EXIST = llok )
749            icnt = icnt + 1
750         END DO
[9367]751      ELSE
752         lxios_sini = .TRUE.
[544]753      ENDIF
[6140]754      ! Open the NetCDF file
[544]755      ! =============
756      ! do we have some free file identifier?
757      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
[679]758         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
759      ! if no file was found...
760      IF( .NOT. llok ) THEN
761         IF( .NOT. llwrt ) THEN   ! we are in read mode
762            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
763            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
764            ENDIF
765         ELSE                     ! we are in write mode so we
766            clname = cltmpn       ! get back the file name without the cpu number
767         ENDIF
[2586]768      ELSE
769         IF( llwrt .AND. .NOT. ln_clobber ) THEN   ! we stop as we want to write in a new file
770            CALL ctl_stop( TRIM(clinfo), 'We want to write in a new file but '//TRIM(clname)//' already exists...' )
771            istop = nstop + 1                      ! make sure that istop /= nstop so we don't open the file
[4650]772         ELSEIF( llwrt ) THEN     ! the file exists and we are in write mode with permission to
773            clname = cltmpn       ! overwrite so get back the file name without the cpu number
[2586]774         ENDIF
[679]775      ENDIF
[544]776      IF( istop == nstop ) THEN   ! no error within this routine
[13286]777         CALL iom_nf90_open( clname, kiomid, llwrt, llok, kdlev = kdlev, cdcomp = cdcomp )
[544]778      ENDIF
779      !
780   END SUBROUTINE iom_open
781
782
783   SUBROUTINE iom_close( kiomid )
784      !!--------------------------------------------------------------------
785      !!                   ***  SUBROUTINE  iom_close  ***
786      !!
787      !! ** Purpose : close an input file, or all files opened by iom
788      !!--------------------------------------------------------------------
[1131]789      INTEGER, INTENT(inout), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
790      !                                              ! return 0 when file is properly closed
791      !                                              ! No argument: all files opened by iom are closed
[544]792
793      INTEGER ::   jf         ! dummy loop indices
794      INTEGER ::   i_s, i_e   ! temporary integer
795      CHARACTER(LEN=100)    ::   clinfo    ! info character
796      !---------------------------------------------------------------------
797      !
[12283]798      IF( iom_open_init == 0 )   RETURN   ! avoid to use iom_file(jf)%nfid that us not yet initialized
799      !
[544]800      clinfo = '                    iom_close ~~~  '
801      IF( PRESENT(kiomid) ) THEN
802         i_s = kiomid
803         i_e = kiomid
804      ELSE
805         i_s = 1
806         i_e = jpmax_files
807      ENDIF
808
809      IF( i_s > 0 ) THEN
810         DO jf = i_s, i_e
811            IF( iom_file(jf)%nfid > 0 ) THEN
[10425]812               CALL iom_nf90_close( jf )
[1131]813               iom_file(jf)%nfid       = 0          ! free the id
814               IF( PRESENT(kiomid) )   kiomid = 0   ! return 0 as id to specify that the file was closed
[679]815               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
[544]816            ELSEIF( PRESENT(kiomid) ) THEN
817               WRITE(ctmp1,*) '--->',  kiomid
818               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
819            ENDIF
820         END DO
821      ENDIF
822      !   
823   END SUBROUTINE iom_close
824
825
[11536]826   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, lduld, ldstop ) 
[544]827      !!-----------------------------------------------------------------------
828      !!                  ***  FUNCTION  iom_varid  ***
829      !!
830      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
831      !!-----------------------------------------------------------------------
832      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
833      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
[9540]834      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of each dimension
[11536]835      INTEGER              , INTENT(  out), OPTIONAL ::   kndims   ! number of dimensions
836      LOGICAL              , INTENT(  out), OPTIONAL ::   lduld    ! true if the last dimension is unlimited (time)
[745]837      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
[544]838      !
839      INTEGER                        ::   iom_varid, iiv, i_nvd
840      LOGICAL                        ::   ll_fnd
841      CHARACTER(LEN=100)             ::   clinfo                   ! info character
[745]842      LOGICAL                        ::   llstop                   ! local definition of ldstop
[544]843      !!-----------------------------------------------------------------------
844      iom_varid = 0                         ! default definition
[745]845      ! do we call ctl_stop if we look for non-existing variable?
846      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
847      ELSE                         ;   llstop = .TRUE.
848      ENDIF
[544]849      !
850      IF( kiomid > 0 ) THEN
[679]851         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
[544]852         IF( iom_file(kiomid)%nfid == 0 ) THEN
853            CALL ctl_stop( trim(clinfo), 'the file is not open' )
854         ELSE
855            ll_fnd  = .FALSE.
856            iiv = 0
857            !
858            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
859               iiv = iiv + 1
860               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
861            END DO
862            !
863            IF( .NOT.ll_fnd ) THEN
864               iiv = iiv + 1
865               IF( iiv <= jpmax_vars ) THEN
[11536]866                  iom_varid = iom_nf90_varid( kiomid, cdvar, iiv, kdimsz, kndims, lduld )
[544]867               ELSE
868                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
[10425]869                        &                      'increase the parameter jpmax_vars')
[544]870               ENDIF
[745]871               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
[544]872            ELSE
873               iom_varid = iiv
874               IF( PRESENT(kdimsz) ) THEN
875                  i_nvd = iom_file(kiomid)%ndims(iiv)
[9540]876                  IF( i_nvd <= size(kdimsz) ) THEN
877                     kdimsz(1:i_nvd) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
[544]878                  ELSE
879                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
880                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
881                  ENDIF
882               ENDIF
[4205]883               IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(iiv)
[11536]884               IF( PRESENT( lduld) )  lduld  = iom_file(kiomid)%luld( iiv)
[544]885            ENDIF
886         ENDIF
887      ENDIF
888      !
889   END FUNCTION iom_varid
890
891
892   !!----------------------------------------------------------------------
893   !!                   INTERFACE iom_get
894   !!----------------------------------------------------------------------
[13226]895   SUBROUTINE iom_g0d_sp( kiomid, cdvar, pvar, ktime, ldxios )
[544]896      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
897      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
[13226]898      REAL(sp)        , INTENT(  out)                 ::   pvar      ! read field
899      REAL(dp)                                        ::   ztmp_pvar ! tmp var to read field
[4245]900      INTEGER         , INTENT(in   ),     OPTIONAL   ::   ktime     ! record number
[9367]901      LOGICAL         , INTENT(in   ),     OPTIONAL   ::   ldxios    ! use xios to read restart
[544]902      !
[4245]903      INTEGER                                         ::   idvar     ! variable id
904      INTEGER                                         ::   idmspc    ! number of spatial dimensions
905      INTEGER         , DIMENSION(1)                  ::   itime     ! record number
906      CHARACTER(LEN=100)                              ::   clinfo    ! info character
907      CHARACTER(LEN=100)                              ::   clname    ! file name
908      CHARACTER(LEN=1)                                ::   cldmspc   !
[9367]909      LOGICAL                                         ::   llxios
[544]910      !
[9367]911      llxios = .FALSE.
912      IF( PRESENT(ldxios) ) llxios = ldxios
913
914      IF(.NOT.llxios) THEN  ! read data using default library
915         itime = 1
916         IF( PRESENT(ktime) ) itime = ktime
917         !
918         clname = iom_file(kiomid)%name
919         clinfo = '          iom_g0d, file: '//trim(clname)//', var: '//trim(cdvar)
920         !
921         IF( kiomid > 0 ) THEN
922            idvar = iom_varid( kiomid, cdvar )
923            IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
924               idmspc = iom_file ( kiomid )%ndims( idvar )
925               IF( iom_file(kiomid)%luld(idvar) )  idmspc = idmspc - 1
926               WRITE(cldmspc , fmt='(i1)') idmspc
927               IF( idmspc > 0 )  CALL ctl_stop( TRIM(clinfo), 'When reading to a 0D array, we do not accept data', &
928                                    &                         'with 1 or more spatial dimensions: '//cldmspc//' were found.' , &
929                                    &                         'Use ncwa -a to suppress the unnecessary dimensions' )
[13226]930               CALL iom_nf90_get( kiomid, idvar, ztmp_pvar, itime )
931               pvar = ztmp_pvar
932            ENDIF
933         ENDIF
934      ELSE
935#if defined key_iomput
936         IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
937         CALL iom_swap( TRIM(crxios_context) )
938         CALL xios_recv_field( trim(cdvar), pvar)
939         CALL iom_swap( TRIM(cxios_context) )
940#else
941         WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar)
942         CALL ctl_stop( 'iom_g0d', ctmp1 )
943#endif
944      ENDIF
945   END SUBROUTINE iom_g0d_sp
946
947   SUBROUTINE iom_g0d_dp( kiomid, cdvar, pvar, ktime, ldxios )
948      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
949      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
950      REAL(dp)        , INTENT(  out)                 ::   pvar      ! read field
951      INTEGER         , INTENT(in   ),     OPTIONAL   ::   ktime     ! record number
952      LOGICAL         , INTENT(in   ),     OPTIONAL   ::   ldxios    ! use xios to read restart
953      !
954      INTEGER                                         ::   idvar     ! variable id
955      INTEGER                                         ::   idmspc    ! number of spatial dimensions
956      INTEGER         , DIMENSION(1)                  ::   itime     ! record number
957      CHARACTER(LEN=100)                              ::   clinfo    ! info character
958      CHARACTER(LEN=100)                              ::   clname    ! file name
959      CHARACTER(LEN=1)                                ::   cldmspc   !
960      LOGICAL                                         ::   llxios
961      !
962      llxios = .FALSE.
963      IF( PRESENT(ldxios) ) llxios = ldxios
964
965      IF(.NOT.llxios) THEN  ! read data using default library
966         itime = 1
967         IF( PRESENT(ktime) ) itime = ktime
968         !
969         clname = iom_file(kiomid)%name
970         clinfo = '          iom_g0d, file: '//trim(clname)//', var: '//trim(cdvar)
971         !
972         IF( kiomid > 0 ) THEN
973            idvar = iom_varid( kiomid, cdvar )
974            IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
975               idmspc = iom_file ( kiomid )%ndims( idvar )
976               IF( iom_file(kiomid)%luld(idvar) )  idmspc = idmspc - 1
977               WRITE(cldmspc , fmt='(i1)') idmspc
978               IF( idmspc > 0 )  CALL ctl_stop( TRIM(clinfo), 'When reading to a 0D array, we do not accept data', &
979                                    &                         'with 1 or more spatial dimensions: '//cldmspc//' were found.' , &
980                                    &                         'Use ncwa -a to suppress the unnecessary dimensions' )
[10425]981               CALL iom_nf90_get( kiomid, idvar, pvar, itime )
[9367]982            ENDIF
[679]983         ENDIF
[9367]984      ELSE
[9535]985#if defined key_iomput
[9367]986         IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
987         CALL iom_swap( TRIM(crxios_context) )
988         CALL xios_recv_field( trim(cdvar), pvar)
989         CALL iom_swap( TRIM(cxios_context) )
[9535]990#else
[10425]991         WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar)
992         CALL ctl_stop( 'iom_g0d', ctmp1 )
[9535]993#endif
[679]994      ENDIF
[13226]995   END SUBROUTINE iom_g0d_dp
[544]996
[13226]997   SUBROUTINE iom_g1d_sp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, ldxios )
[544]998      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
999      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
1000      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
[13226]1001      REAL(sp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
1002      REAL(dp)        , ALLOCATABLE  , DIMENSION(:)           ::   ztmp_pvar ! tmp var to read field
[544]1003      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
1004      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
1005      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
[9367]1006      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
[544]1007      !
[679]1008      IF( kiomid > 0 ) THEN
[13226]1009         IF( iom_file(kiomid)%nfid > 0 ) THEN
1010            ALLOCATE(ztmp_pvar(size(pvar,1)))
1011            CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=ztmp_pvar,   &
1012              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
1013              &                                                     ldxios=ldxios )
1014            pvar = ztmp_pvar
1015            DEALLOCATE(ztmp_pvar)
1016         END IF
1017      ENDIF
1018   END SUBROUTINE iom_g1d_sp
1019
1020
1021   SUBROUTINE iom_g1d_dp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, ldxios )
1022      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
1023      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
1024      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
1025      REAL(dp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
1026      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
1027      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
1028      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
1029      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
1030      !
1031      IF( kiomid > 0 ) THEN
[679]1032         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
[9367]1033              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
1034              &                                                     ldxios=ldxios )
[679]1035      ENDIF
[13226]1036   END SUBROUTINE iom_g1d_dp
[544]1037
[13286]1038   SUBROUTINE iom_g2d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios)
1039      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
1040      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
1041      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
1042      REAL(sp)        , INTENT(  out), DIMENSION(:,:)         ::   pvar      ! read field
1043      REAL(dp)        , ALLOCATABLE  , DIMENSION(:,:)         ::   ztmp_pvar ! tmp var to read field
1044      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
1045      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W)
1046      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.): (not) change sign across the north fold
1047      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk
1048      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kstart    ! start axis position of the reading
1049      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kcount    ! number of points in each axis
1050      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
[544]1051      !
[679]1052      IF( kiomid > 0 ) THEN
[13226]1053         IF( iom_file(kiomid)%nfid > 0 ) THEN
1054            ALLOCATE(ztmp_pvar(size(pvar,1), size(pvar,2)))
[13286]1055            CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r2d = ztmp_pvar  , ktime = ktime,   &
1056             &                                                      cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
1057             &                                                      kstart  = kstart , kcount = kcount, ldxios=ldxios  )
[13226]1058            pvar = ztmp_pvar
1059            DEALLOCATE(ztmp_pvar)
[13286]1060         ENDIF
[13226]1061      ENDIF
1062   END SUBROUTINE iom_g2d_sp
1063
[13286]1064   SUBROUTINE iom_g2d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios)
1065      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
1066      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
1067      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
1068      REAL(dp)        , INTENT(  out), DIMENSION(:,:)         ::   pvar      ! read field
1069      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
1070      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W)
1071      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.): (not) change sign across the north fold
1072      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk
1073      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kstart    ! start axis position of the reading
1074      INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kcount    ! number of points in each axis
1075      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
[13226]1076      !
1077      IF( kiomid > 0 ) THEN
[13286]1078         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r2d = pvar  , ktime = ktime,   &
1079            &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
1080            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  )
[679]1081      ENDIF
[13226]1082   END SUBROUTINE iom_g2d_dp
[544]1083
[13286]1084   SUBROUTINE iom_g3d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios )
1085      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
1086      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
1087      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
1088      REAL(sp)        , INTENT(  out), DIMENSION(:,:,:)       ::   pvar      ! read field
1089      REAL(dp)        , ALLOCATABLE  , DIMENSION(:,:,:)       ::   ztmp_pvar ! tmp var to read field
1090      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
1091      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W)
1092      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.) : (not) change sign across the north fold
1093      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk
1094      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kstart    ! start axis position of the reading
1095      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kcount    ! number of points in each axis
1096      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
[544]1097      !
[679]1098      IF( kiomid > 0 ) THEN
[13226]1099         IF( iom_file(kiomid)%nfid > 0 ) THEN
1100            ALLOCATE(ztmp_pvar(size(pvar,1), size(pvar,2), size(pvar,3)))
[13286]1101            CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r3d = ztmp_pvar  , ktime = ktime,   &
1102            &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
1103            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  )
[13226]1104            pvar = ztmp_pvar
1105            DEALLOCATE(ztmp_pvar)
1106         END IF
1107      ENDIF
1108   END SUBROUTINE iom_g3d_sp
1109
[13286]1110   SUBROUTINE iom_g3d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios )
1111      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
1112      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
1113      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
1114      REAL(dp)        , INTENT(  out), DIMENSION(:,:,:)       ::   pvar      ! read field
1115      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
1116      CHARACTER(len=1), INTENT(in   )              , OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W)
1117      REAL(dp)        , INTENT(in   )              , OPTIONAL ::   psgn      ! -1.(1.) : (not) change sign across the north fold
1118      INTEGER         , INTENT(in   )              , OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk
1119      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kstart    ! start axis position of the reading
1120      INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kcount    ! number of points in each axis
1121      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
[13226]1122      !
1123      IF( kiomid > 0 ) THEN
[13286]1124         IF( iom_file(kiomid)%nfid > 0 ) THEN
1125            CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r3d = pvar  , ktime = ktime,   &
1126            &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
1127            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  )
1128         END IF
[679]1129      ENDIF
[13226]1130   END SUBROUTINE iom_g3d_dp
1131
[544]1132   !!----------------------------------------------------------------------
1133
[13286]1134   SUBROUTINE iom_get_123d( kiomid , kdom, cdvar, pv_r1d, pv_r2d, pv_r3d, ktime ,   &
1135         &                  cd_type, psgn, kfill, kstart, kcount, ldxios )
[544]1136      !!-----------------------------------------------------------------------
1137      !!                  ***  ROUTINE  iom_get_123d  ***
1138      !!
1139      !! ** Purpose : read a 1D/2D/3D variable
1140      !!
1141      !! ** Method : read ONE record at each CALL
1142      !!-----------------------------------------------------------------------
[13286]1143      INTEGER                    , INTENT(in   )           ::   kiomid    ! Identifier of the file
1144      INTEGER                    , INTENT(in   )           ::   kdom      ! Type of domain to be read
1145      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar     ! Name of the variable
1146      REAL(dp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d    ! read field (1D case)
1147      REAL(dp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d    ! read field (2D case)
1148      REAL(dp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d    ! read field (3D case)
1149      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime     ! record number
1150      CHARACTER(len=1)           , INTENT(in   ), OPTIONAL ::   cd_type   ! nature of grid-points (T, U, V, F, W)
1151      REAL(dp)                   , INTENT(in   ), OPTIONAL ::   psgn      ! -1.(1.) : (not) change sign across the north fold
1152      INTEGER                    , INTENT(in   ), OPTIONAL ::   kfill     ! value of kfillmode in lbc_lbk
1153      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart    ! start position of the reading in each axis
1154      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount    ! number of points to be read in each axis
1155      LOGICAL                    , INTENT(in   ), OPTIONAL ::   ldxios    ! use XIOS to read restart
[544]1156      !
[13286]1157      LOGICAL                        ::   llok        ! true if ok!
1158      LOGICAL                        ::   llxios      ! local definition for XIOS read
[544]1159      INTEGER                        ::   jl          ! loop on number of dimension
1160      INTEGER                        ::   idom        ! type of domain
1161      INTEGER                        ::   idvar       ! id of the variable
1162      INTEGER                        ::   inbdim      ! number of dimensions of the variable
1163      INTEGER                        ::   idmspc      ! number of spatial dimensions
1164      INTEGER                        ::   itime       ! record number
1165      INTEGER                        ::   istop       ! temporary value of nstop
[679]1166      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
1167      INTEGER                        ::   ji, jj      ! loop counters
[5118]1168      INTEGER                        ::   irankpv     !
[679]1169      INTEGER                        ::   ind1, ind2  ! substring index
[544]1170      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
1171      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis
1172      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
[679]1173      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
[13226]1174      REAL(dp)                       ::   zscf, zofs  ! sacle_factor and add_offset
[13286]1175      REAL(wp)                       ::   zsgn        ! local value of psgn
[544]1176      INTEGER                        ::   itmp        ! temporary integer
[4148]1177      CHARACTER(LEN=256)             ::   clinfo      ! info character
1178      CHARACTER(LEN=256)             ::   clname      ! file name
[679]1179      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !
[13286]1180      CHARACTER(LEN=1)               ::   cl_type     ! local value of cd_type
1181      LOGICAL                        ::   ll_only3rd  ! T => if kstart, kcount present then *only* use values for 3rd spatial dimension.
[9019]1182      INTEGER                        ::   inlev       ! number of levels for 3D data
[13226]1183      REAL(dp)                       ::   gma, gmi
[544]1184      !---------------------------------------------------------------------
1185      !
[9019]1186      inlev = -1
1187      IF( PRESENT(pv_r3d) )   inlev = SIZE(pv_r3d, 3)
[9367]1188      !
1189      llxios = .FALSE.
[13286]1190      IF( PRESENT(ldxios) )   llxios = ldxios
1191      !
[544]1192      idom = kdom
[13286]1193      istop = nstop
[9367]1194      !
1195      IF(.NOT.llxios) THEN
1196         clname = iom_file(kiomid)%name   !   esier to read
1197         clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
1198         ! check kcount and kstart optionals parameters...
[13286]1199         IF( PRESENT(kcount) .AND. .NOT. PRESENT(kstart) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
1200         IF( PRESENT(kstart) .AND. .NOT. PRESENT(kcount) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
1201         IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND. idom /= jpdom_auto_xy ) &
1202            &          CALL ctl_stop(TRIM(clinfo), 'kstart present needs idom = jpdom_unknown or idom = jpdom_auto_xy')
1203         IF( idom == jpdom_auto_xy .AND. .NOT. PRESENT(kstart) ) &
1204            &          CALL ctl_stop(TRIM(clinfo), 'idom = jpdom_auto_xy requires kstart to be present')
1205         !
[9367]1206         ! Search for the variable in the data base (eventually actualize data)
[544]1207         !
[13286]1208         idvar = iom_varid( kiomid, cdvar ) 
[9367]1209         IF( idvar > 0 ) THEN
[13286]1210            !
1211            idimsz(:) = iom_file(kiomid)%dimsz(:, idvar)      ! to write iom_file(kiomid)%dimsz in a shorter way
[9367]1212            inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
1213            idmspc = inbdim                                   ! number of spatial dimensions in the file
1214            IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
1215            IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
1216            !
[13286]1217            ! Identify the domain in case of jpdom_auto definition
1218            IF( idom == jpdom_auto .OR. idom == jpdom_auto_xy ) THEN           
1219               idom = jpdom_global   ! default
1220               ! else: if the file name finishes with _xxxx.nc with xxxx any number
[9367]1221               ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
1222               ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
1223               IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
1224            ENDIF
1225            !
1226            ! check the consistency between input array and data rank in the file
1227            !
1228            ! initializations
1229            itime = 1
1230            IF( PRESENT(ktime) ) itime = ktime
1231            !
1232            irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
1233            WRITE(clrankpv, fmt='(i1)') irankpv
1234            WRITE(cldmspc , fmt='(i1)') idmspc
1235            !
[13286]1236            IF(     idmspc <  irankpv ) THEN                     ! it seems we want to read more than we can...
1237               IF(     irankpv == 3 .AND. idmspc == 2 ) THEN     !   3D input array from 2D spatial data in the file:
1238                  llok = inlev == 1                              !     -> 3rd dimension must be equal to 1
1239               ELSEIF( irankpv == 3 .AND. idmspc == 1 ) THEN     !   3D input array from 1D spatial data in the file:
1240                  llok = inlev == 1 .AND. SIZE(pv_r3d, 2) == 1   !     -> 2nd and 3rd dimensions must be equal to 1
1241               ELSEIF( irankpv == 2 .AND. idmspc == 2 ) THEN     !   2D input array from 1D spatial data in the file:
1242                  llok = SIZE(pv_r2d, 2) == 1                    !     -> 2nd dimension must be equal to 1
1243               ELSE
1244                  llok = .FALSE.
1245               ENDIF
1246               IF( .NOT. llok )   CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
1247                  &                                            '=> cannot read a true '//clrankpv//'D array from this file...' )
1248            ELSEIF( idmspc == irankpv ) THEN
[9367]1249               IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
1250                  &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
[13286]1251            ELSEIF( idmspc >  irankpv ) THEN                     ! it seems we want to read less than we should...
[9367]1252                  IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
[13286]1253                     CALL ctl_warn( trim(clinfo), '2D array input but 3 spatial dimensions in the file...'              ,   &
[9367]1254                           &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
1255                           &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
1256                     idmspc = idmspc - 1
[13214]1257                  !!GS: possibility to read 3D ABL atmopsheric forcing and use 1st level to force BULK simulation
1258                  !ELSE
1259                  !   CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,',   &
1260                  !      &                         'we do not accept data with '//cldmspc//' spatial dimensions'  ,   &
1261                  !      &                         'Use ncwa -a to suppress the unnecessary dimensions' )
[9367]1262                  ENDIF
1263            ENDIF
1264            !
1265            ! definition of istart and icnt
1266            !
[13286]1267            icnt  (:) = 1              ! default definition (simple way to deal with special cases listed above)
1268            istart(:) = 1              ! default definition (simple way to deal with special cases listed above)
1269            istart(idmspc+1) = itime   ! temporal dimenstion
1270            !
1271            IF( idom == jpdom_unknown ) THEN
1272               IF( PRESENT(kstart) .AND. idom /= jpdom_auto_xy ) THEN
1273                  istart(1:idmspc) = kstart(1:idmspc) 
1274                  icnt  (1:idmspc) = kcount(1:idmspc)
1275               ELSE
1276                  icnt  (1:idmspc) = idimsz(1:idmspc)
1277               ENDIF
1278            ELSE   !   not a 1D array as pv_r1d requires jpdom_unknown
1279               ! we do not read the overlap and the extra-halos -> from Nis0 to Nie0 and from Njs0 to Nje0
1280               IF( idom == jpdom_global )   istart(1:2) = (/ mig0(Nis0), mjg0(Njs0) /)
1281               icnt(1:2) = (/ Ni_0, Nj_0 /)
1282               IF( PRESENT(pv_r3d) ) THEN
1283                  IF( idom == jpdom_auto_xy ) THEN
1284                     istart(3) = kstart(3)
1285                     icnt  (3) = kcount(3)
1286                  ELSE
1287                     icnt  (3) = inlev
[544]1288                  ENDIF
1289               ENDIF
[679]1290            ENDIF
[13286]1291            !
[9367]1292            ! check that istart and icnt can be used with this file
1293            !-
1294            DO jl = 1, jpmax_dims
1295               itmp = istart(jl)+icnt(jl)-1
1296               IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
1297                  WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
1298                  WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
1299                  CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
1300               ENDIF
1301            END DO
[13286]1302            !
[9367]1303            ! check that icnt matches the input array
1304            !-     
1305            IF( idom == jpdom_unknown ) THEN
1306               IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
1307               IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
1308               IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
1309               ctmp1 = 'd'
1310            ELSE
1311               IF( irankpv == 2 ) THEN
[13286]1312                  ishape(1:2) = SHAPE(pv_r2d(Nis0:Nie0,Njs0:Nje0  ))   ;   ctmp1 = 'd(Nis0:Nie0,Njs0:Nje0)'
[544]1313               ENDIF
[9367]1314               IF( irankpv == 3 ) THEN
[13286]1315                  ishape(1:3) = SHAPE(pv_r3d(Nis0:Nie0,Njs0:Nje0,:))   ;   ctmp1 = 'd(Nis0:Nie0,Njs0:Nje0,:)'
[544]1316               ENDIF
[13286]1317            ENDIF         
[9367]1318            DO jl = 1, irankpv
1319               WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
1320               IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
1321            END DO
[679]1322
[9367]1323         ENDIF
[544]1324
[9367]1325         ! read the data
1326         !-     
1327         IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
1328            !
[13286]1329            ! find the right index of the array to be read
1330            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = Nis0   ;   ix2 = Nie0      ;   iy1 = Njs0   ;   iy2 = Nje0
1331            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
[679]1332            ENDIF
1333     
[10425]1334            CALL iom_nf90_get( kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, pv_r3d )
[679]1335
[9367]1336            IF( istop == nstop ) THEN   ! no additional errors until this point...
1337               IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
[13286]1338
1339               cl_type = 'T'
1340               IF( PRESENT(cd_type) )   cl_type = cd_type
1341               zsgn = 1._wp
1342               IF( PRESENT(psgn   ) )   zsgn    = psgn
[9367]1343               !--- overlap areas and extra hallows (mpp)
[13286]1344               IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown .AND. cl_type /= 'Z' ) THEN
1345                  CALL lbc_lnk( 'iom', pv_r2d, cl_type, zsgn, kfillmode = kfill )
1346               ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown .AND. cl_type /= 'Z' ) THEN
1347                  CALL lbc_lnk( 'iom', pv_r3d, cl_type, zsgn, kfillmode = kfill )
[679]1348               ENDIF
[9367]1349               !
1350            ELSE
1351               ! return if istop == nstop is false
1352               RETURN
[679]1353            ENDIF
[9367]1354         ELSE
1355            ! return if statment idvar > 0 .AND. istop == nstop is false
1356            RETURN
1357         ENDIF
1358         !
1359      ELSE        ! read using XIOS. Only if KEY_IOMPUT is defined
1360#if defined key_iomput
1361!would be good to be able to check which context is active and swap only if current is not restart
1362         CALL iom_swap( TRIM(crxios_context) ) 
1363         IF( PRESENT(pv_r3d) ) THEN
[13286]1364            IF(lwp) WRITE(numout,*) 'XIOS RST READ (3D): ',TRIM(cdvar)
[9367]1365            CALL xios_recv_field( trim(cdvar), pv_r3d)
[13286]1366            IF(idom /= jpdom_unknown )   CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing)
[9367]1367         ELSEIF( PRESENT(pv_r2d) ) THEN
[13286]1368            IF(lwp) WRITE(numout,*) 'XIOS RST READ (2D): ', TRIM(cdvar)
[9367]1369            CALL xios_recv_field( trim(cdvar), pv_r2d)
[13286]1370            IF(idom /= jpdom_unknown )   CALL lbc_lnk('iom', pv_r2d,'Z',-999., kfillmode = jpfillnothing)
[9367]1371         ELSEIF( PRESENT(pv_r1d) ) THEN
[13286]1372            IF(lwp) WRITE(numout,*) 'XIOS RST READ (1D): ', TRIM(cdvar)
[9367]1373            CALL xios_recv_field( trim(cdvar), pv_r1d)
[544]1374         ENDIF
[9367]1375         CALL iom_swap( TRIM(cxios_context) )
1376#else
1377         istop = istop + 1 
1378         clinfo = 'Can not use XIOS in iom_get_123d, file: '//trim(clname)//', var:'//trim(cdvar)
1379#endif
[544]1380      ENDIF
[9367]1381!some final adjustments
1382      ! C1D case : always call lbc_lnk to replicate the central value over the whole 3X3 domain
[13226]1383      IF( lk_c1d .AND. PRESENT(pv_r2d) )   CALL lbc_lnk( 'iom', pv_r2d,'Z',1.0_wp )
1384      IF( lk_c1d .AND. PRESENT(pv_r3d) )   CALL lbc_lnk( 'iom', pv_r3d,'Z',1.0_wp )
[9367]1385
1386      !--- Apply scale_factor and offset
1387      zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
1388      zofs = iom_file(kiomid)%ofs(idvar)      ! offset
1389      IF(     PRESENT(pv_r1d) ) THEN
1390         IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
1391         IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
1392      ELSEIF( PRESENT(pv_r2d) ) THEN
1393         IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
1394         IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
1395      ELSEIF( PRESENT(pv_r3d) ) THEN
1396         IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
1397         IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
1398      ENDIF
[544]1399      !
1400   END SUBROUTINE iom_get_123d
1401
[12276]1402   SUBROUTINE iom_get_var( cdname, z2d)
1403      CHARACTER(LEN=*), INTENT(in ) ::   cdname
1404      REAL(wp), DIMENSION(jpi,jpj) ::   z2d 
1405#if defined key_iomput
1406      IF( xios_field_is_active( cdname, at_current_timestep_arg = .TRUE. ) ) THEN
1407         z2d(:,:) = 0._wp
1408         CALL xios_recv_field( cdname, z2d)
1409      ENDIF
1410#else
1411      IF( .FALSE. )   WRITE(numout,*) cdname, z2d ! useless test to avoid compilation warnings
1412#endif
1413   END SUBROUTINE iom_get_var
[544]1414
[12276]1415
[10522]1416   FUNCTION iom_getszuld ( kiomid ) 
1417      !!-----------------------------------------------------------------------
1418      !!                  ***  FUNCTION  iom_getszuld  ***
[544]1419      !!
[10522]1420      !! ** Purpose : get the size of the unlimited dimension in a file
1421      !!              (return -1 if not found)
1422      !!-----------------------------------------------------------------------
1423      INTEGER, INTENT(in   ) ::   kiomid   ! file Identifier
[544]1424      !
[10522]1425      INTEGER                ::   iom_getszuld
1426      !!-----------------------------------------------------------------------
1427      iom_getszuld = -1
[679]1428      IF( kiomid > 0 ) THEN
[10523]1429         IF( iom_file(kiomid)%iduld > 0 )   iom_getszuld = iom_file(kiomid)%lenuld
[544]1430      ENDIF
[10522]1431   END FUNCTION iom_getszuld
1432   
[544]1433
1434   !!----------------------------------------------------------------------
[10425]1435   !!                   INTERFACE iom_chkatt
[2528]1436   !!----------------------------------------------------------------------
[10425]1437   SUBROUTINE iom_chkatt( kiomid, cdatt, llok, ksize, cdvar )
[2528]1438      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
1439      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute
[10425]1440      LOGICAL         , INTENT(  out)                 ::   llok      ! Error code
1441      INTEGER         , INTENT(  out), OPTIONAL       ::   ksize     ! Size of the attribute array
[7646]1442      CHARACTER(len=*), INTENT(in   ), OPTIONAL       ::   cdvar     ! Name of the variable
[2528]1443      !
1444      IF( kiomid > 0 ) THEN
[10425]1445         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_chkatt( kiomid, cdatt, llok, ksize=ksize, cdvar=cdvar )
[2528]1446      ENDIF
[10425]1447      !
1448   END SUBROUTINE iom_chkatt
1449
1450   !!----------------------------------------------------------------------
1451   !!                   INTERFACE iom_getatt
1452   !!----------------------------------------------------------------------
1453   SUBROUTINE iom_g0d_iatt( kiomid, cdatt, katt0d, cdvar )
1454      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1455      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1456      INTEGER               , INTENT(  out)           ::   katt0d    ! read field
1457      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
1458      !
1459      IF( kiomid > 0 ) THEN
1460         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_getatt( kiomid, cdatt,  katt0d =  katt0d, cdvar=cdvar )
1461      ENDIF
[7646]1462   END SUBROUTINE iom_g0d_iatt
[2528]1463
[10425]1464   SUBROUTINE iom_g1d_iatt( kiomid, cdatt, katt1d, cdvar )
1465      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1466      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1467      INTEGER, DIMENSION(:) , INTENT(  out)           ::   katt1d    ! read field
1468      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
[7646]1469      !
1470      IF( kiomid > 0 ) THEN
[10425]1471         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_getatt( kiomid, cdatt,  katt1d =  katt1d, cdvar=cdvar )
[7646]1472      ENDIF
[10425]1473   END SUBROUTINE iom_g1d_iatt
1474
1475   SUBROUTINE iom_g0d_ratt( kiomid, cdatt, patt0d, cdvar )
1476      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1477      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1478      REAL(wp)              , INTENT(  out)           ::   patt0d    ! read field
1479      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
1480      !
1481      IF( kiomid > 0 ) THEN
1482         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_getatt( kiomid, cdatt,  patt0d =  patt0d, cdvar=cdvar )
1483      ENDIF
[7646]1484   END SUBROUTINE iom_g0d_ratt
[2528]1485
[10425]1486   SUBROUTINE iom_g1d_ratt( kiomid, cdatt, patt1d, cdvar )
1487      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1488      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1489      REAL(wp), DIMENSION(:), INTENT(  out)           ::   patt1d    ! read field
1490      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
[7646]1491      !
1492      IF( kiomid > 0 ) THEN
[10425]1493         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_getatt( kiomid, cdatt,  patt1d =  patt1d, cdvar=cdvar )
[7646]1494      ENDIF
[10425]1495   END SUBROUTINE iom_g1d_ratt
1496   
1497   SUBROUTINE iom_g0d_catt( kiomid, cdatt, cdatt0d, cdvar )
1498      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1499      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1500      CHARACTER(len=*)      , INTENT(  out)           ::   cdatt0d   ! read field
1501      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
1502      !
1503      IF( kiomid > 0 ) THEN
1504         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_getatt( kiomid, cdatt, cdatt0d = cdatt0d, cdvar=cdvar )
1505      ENDIF
[7646]1506   END SUBROUTINE iom_g0d_catt
1507
[10425]1508
[2528]1509   !!----------------------------------------------------------------------
[7646]1510   !!                   INTERFACE iom_putatt
1511   !!----------------------------------------------------------------------
[10425]1512   SUBROUTINE iom_p0d_iatt( kiomid, cdatt, katt0d, cdvar )
1513      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1514      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1515      INTEGER               , INTENT(in   )           ::   katt0d    ! written field
1516      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
[7646]1517      !
1518      IF( kiomid > 0 ) THEN
[10425]1519         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_putatt( kiomid, cdatt,  katt0d =  katt0d, cdvar=cdvar )
[7646]1520      ENDIF
1521   END SUBROUTINE iom_p0d_iatt
1522
[10425]1523   SUBROUTINE iom_p1d_iatt( kiomid, cdatt, katt1d, cdvar )
1524      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1525      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1526      INTEGER, DIMENSION(:) , INTENT(in   )           ::   katt1d    ! written field
1527      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
[7646]1528      !
1529      IF( kiomid > 0 ) THEN
[10425]1530         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_putatt( kiomid, cdatt,  katt1d =  katt1d, cdvar=cdvar )
[7646]1531      ENDIF
[10425]1532   END SUBROUTINE iom_p1d_iatt
1533
1534   SUBROUTINE iom_p0d_ratt( kiomid, cdatt, patt0d, cdvar )
1535      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1536      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1537      REAL(wp)              , INTENT(in   )           ::   patt0d    ! written field
1538      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
1539      !
1540      IF( kiomid > 0 ) THEN
1541         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_putatt( kiomid, cdatt,  patt0d =  patt0d, cdvar=cdvar )
1542      ENDIF
[7646]1543   END SUBROUTINE iom_p0d_ratt
1544
[10425]1545   SUBROUTINE iom_p1d_ratt( kiomid, cdatt, patt1d, cdvar )
1546      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1547      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1548      REAL(wp), DIMENSION(:), INTENT(in   )           ::   patt1d    ! written field
1549      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
[7646]1550      !
1551      IF( kiomid > 0 ) THEN
[10425]1552         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_putatt( kiomid, cdatt,  patt1d =  patt1d, cdvar=cdvar )
[7646]1553      ENDIF
[10425]1554   END SUBROUTINE iom_p1d_ratt
1555   
1556   SUBROUTINE iom_p0d_catt( kiomid, cdatt, cdatt0d, cdvar )
1557      INTEGER               , INTENT(in   )           ::   kiomid    ! Identifier of the file
1558      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt     ! Name of the attribute
1559      CHARACTER(len=*)      , INTENT(in   )           ::   cdatt0d   ! written field
1560      CHARACTER(len=*)      , INTENT(in   ), OPTIONAL ::   cdvar     ! Name of the variable
1561      !
1562      IF( kiomid > 0 ) THEN
1563         IF( iom_file(kiomid)%nfid > 0 )   CALL iom_nf90_putatt( kiomid, cdatt, cdatt0d = cdatt0d, cdvar=cdvar )
1564      ENDIF
[7646]1565   END SUBROUTINE iom_p0d_catt
1566
[10425]1567
[7646]1568   !!----------------------------------------------------------------------
[544]1569   !!                   INTERFACE iom_rstput
1570   !!----------------------------------------------------------------------
[13226]1571   SUBROUTINE iom_rp0d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
[544]1572      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1573      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1574      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1575      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[13226]1576      REAL(sp)        , INTENT(in)                         ::   pvar     ! written field
[544]1577      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
[9367]1578      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
1579      LOGICAL :: llx                ! local xios write flag
[544]1580      INTEGER :: ivid   ! variable id
[9367]1581
1582      llx = .FALSE.
1583      IF(PRESENT(ldxios)) llx = ldxios
1584      IF( llx ) THEN
1585#ifdef key_iomput
1586      IF( kt == kwrite ) THEN
1587          IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar)
1588          CALL xios_send_field(trim(cdvar), pvar)
1589      ENDIF
1590#endif
1591      ELSE
1592         IF( kiomid > 0 ) THEN
1593            IF( iom_file(kiomid)%nfid > 0 ) THEN
1594               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[13226]1595               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = real(pvar, dp) )
1596            ENDIF
1597         ENDIF
1598      ENDIF
1599   END SUBROUTINE iom_rp0d_sp
1600
1601   SUBROUTINE iom_rp0d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
1602      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1603      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1604      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1605      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1606      REAL(dp)        , INTENT(in)                         ::   pvar     ! written field
1607      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1608      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
1609      LOGICAL :: llx                ! local xios write flag
1610      INTEGER :: ivid   ! variable id
1611
1612      llx = .FALSE.
1613      IF(PRESENT(ldxios)) llx = ldxios
1614      IF( llx ) THEN
1615#ifdef key_iomput
1616      IF( kt == kwrite ) THEN
1617          IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar)
1618          CALL xios_send_field(trim(cdvar), pvar)
1619      ENDIF
1620#endif
1621      ELSE
1622         IF( kiomid > 0 ) THEN
1623            IF( iom_file(kiomid)%nfid > 0 ) THEN
1624               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[10425]1625               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
[9367]1626            ENDIF
[679]1627         ENDIF
1628      ENDIF
[13226]1629   END SUBROUTINE iom_rp0d_dp
[544]1630
[13226]1631
1632   SUBROUTINE iom_rp1d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
[544]1633      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1634      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1635      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1636      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[13226]1637      REAL(sp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
[544]1638      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
[9367]1639      LOGICAL, OPTIONAL                                    ::   ldxios   ! xios write flag
1640      LOGICAL :: llx                ! local xios write flag
[544]1641      INTEGER :: ivid   ! variable id
[9367]1642
1643      llx = .FALSE.
1644      IF(PRESENT(ldxios)) llx = ldxios
1645      IF( llx ) THEN
1646#ifdef key_iomput
1647      IF( kt == kwrite ) THEN
1648         IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar)
1649         CALL xios_send_field(trim(cdvar), pvar)
1650      ENDIF
1651#endif
1652      ELSE
1653         IF( kiomid > 0 ) THEN
1654            IF( iom_file(kiomid)%nfid > 0 ) THEN
1655               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[13226]1656               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = real(pvar, dp) )
1657            ENDIF
1658         ENDIF
1659      ENDIF
1660   END SUBROUTINE iom_rp1d_sp
1661
1662   SUBROUTINE iom_rp1d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
1663      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1664      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1665      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1666      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1667      REAL(dp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
1668      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1669      LOGICAL, OPTIONAL                                    ::   ldxios   ! xios write flag
1670      LOGICAL :: llx                ! local xios write flag
1671      INTEGER :: ivid   ! variable id
1672
1673      llx = .FALSE.
1674      IF(PRESENT(ldxios)) llx = ldxios
1675      IF( llx ) THEN
1676#ifdef key_iomput
1677      IF( kt == kwrite ) THEN
1678         IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar)
1679         CALL xios_send_field(trim(cdvar), pvar)
1680      ENDIF
1681#endif
1682      ELSE
1683         IF( kiomid > 0 ) THEN
1684            IF( iom_file(kiomid)%nfid > 0 ) THEN
1685               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[10425]1686               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
[9367]1687            ENDIF
[679]1688         ENDIF
1689      ENDIF
[13226]1690   END SUBROUTINE iom_rp1d_dp
[544]1691
[13226]1692
1693   SUBROUTINE iom_rp2d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
[544]1694      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1695      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1696      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1697      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[13226]1698      REAL(sp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
[544]1699      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
[9367]1700      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
1701      LOGICAL :: llx
[544]1702      INTEGER :: ivid   ! variable id
[9367]1703
1704      llx = .FALSE.
1705      IF(PRESENT(ldxios)) llx = ldxios
1706      IF( llx ) THEN
1707#ifdef key_iomput
1708      IF( kt == kwrite ) THEN
1709         IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar)
1710         CALL xios_send_field(trim(cdvar), pvar)
1711      ENDIF
1712#endif
1713      ELSE
1714         IF( kiomid > 0 ) THEN
1715            IF( iom_file(kiomid)%nfid > 0 ) THEN
1716               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[13226]1717               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = real(pvar, dp) )
1718            ENDIF
1719         ENDIF
1720      ENDIF
1721   END SUBROUTINE iom_rp2d_sp
1722
1723   SUBROUTINE iom_rp2d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
1724      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1725      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1726      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1727      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1728      REAL(dp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
1729      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1730      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
1731      LOGICAL :: llx
1732      INTEGER :: ivid   ! variable id
1733
1734      llx = .FALSE.
1735      IF(PRESENT(ldxios)) llx = ldxios
1736      IF( llx ) THEN
1737#ifdef key_iomput
1738      IF( kt == kwrite ) THEN
1739         IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar)
1740         CALL xios_send_field(trim(cdvar), pvar)
1741      ENDIF
1742#endif
1743      ELSE
1744         IF( kiomid > 0 ) THEN
1745            IF( iom_file(kiomid)%nfid > 0 ) THEN
1746               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[10425]1747               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
[9367]1748            ENDIF
[679]1749         ENDIF
1750      ENDIF
[13226]1751   END SUBROUTINE iom_rp2d_dp
[544]1752
[13226]1753
1754   SUBROUTINE iom_rp3d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
[544]1755      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1756      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1757      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1758      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[13226]1759      REAL(sp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
[544]1760      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
[9367]1761      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
1762      LOGICAL :: llx                 ! local xios write flag
[544]1763      INTEGER :: ivid   ! variable id
[9367]1764
1765      llx = .FALSE.
1766      IF(PRESENT(ldxios)) llx = ldxios
1767      IF( llx ) THEN
1768#ifdef key_iomput
1769      IF( kt == kwrite ) THEN
1770         IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar)
1771         CALL xios_send_field(trim(cdvar), pvar)
1772      ENDIF
1773#endif
1774      ELSE
1775         IF( kiomid > 0 ) THEN
1776            IF( iom_file(kiomid)%nfid > 0 ) THEN
1777               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[13226]1778               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = real(pvar, dp) )
1779            ENDIF
1780         ENDIF
1781      ENDIF
1782   END SUBROUTINE iom_rp3d_sp
1783
1784   SUBROUTINE iom_rp3d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
1785      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1786      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1787      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1788      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1789      REAL(dp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
1790      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1791      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
1792      LOGICAL :: llx                 ! local xios write flag
1793      INTEGER :: ivid   ! variable id
1794
1795      llx = .FALSE.
1796      IF(PRESENT(ldxios)) llx = ldxios
1797      IF( llx ) THEN
1798#ifdef key_iomput
1799      IF( kt == kwrite ) THEN
1800         IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar)
1801         CALL xios_send_field(trim(cdvar), pvar)
1802      ENDIF
1803#endif
1804      ELSE
1805         IF( kiomid > 0 ) THEN
1806            IF( iom_file(kiomid)%nfid > 0 ) THEN
1807               ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[10425]1808               CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
[9367]1809            ENDIF
[679]1810         ENDIF
1811      ENDIF
[13226]1812   END SUBROUTINE iom_rp3d_dp
[1359]1813
1814
[13226]1815
[10425]1816  SUBROUTINE iom_delay_rst( cdaction, cdcpnt, kncid )
1817      !!---------------------------------------------------------------------
1818      !!   Routine iom_delay_rst: used read/write restart related to mpp_delay
1819      !!
1820      !!---------------------------------------------------------------------
1821      CHARACTER(len=*), INTENT(in   ) ::   cdaction        !
1822      CHARACTER(len=*), INTENT(in   ) ::   cdcpnt
1823      INTEGER         , INTENT(in   ) ::   kncid
1824      !
1825      INTEGER  :: ji
1826      INTEGER  :: indim
1827      LOGICAL  :: llattexist
1828      REAL(wp), ALLOCATABLE, DIMENSION(:) ::   zreal1d
1829      !!---------------------------------------------------------------------
1830      !
1831      !                                      ===================================
1832      IF( TRIM(cdaction) == 'READ' ) THEN   ! read restart related to mpp_delay !
1833         !                                   ===================================
1834         DO ji = 1, nbdelay
1835            IF ( c_delaycpnt(ji) == cdcpnt ) THEN
1836               CALL iom_chkatt( kncid, 'DELAY_'//c_delaylist(ji), llattexist, indim )
1837               IF( llattexist )  THEN
1838                  ALLOCATE( todelay(ji)%z1d(indim) )
1839                  CALL iom_getatt( kncid, 'DELAY_'//c_delaylist(ji), todelay(ji)%z1d(:) )
1840                  ndelayid(ji) = 0   ! set to 0 to specify that the value was read in the restart
1841               ENDIF
1842           ENDIF
1843         END DO
1844         !                                   ====================================
1845      ELSE                                  ! write restart related to mpp_delay !
1846         !                                   ====================================
1847         DO ji = 1, nbdelay   ! save only ocean delayed global communication variables
1848            IF ( c_delaycpnt(ji) == cdcpnt ) THEN
1849               IF( ASSOCIATED(todelay(ji)%z1d) ) THEN
1850                  CALL mpp_delay_rcv(ji)   ! make sure %z1d is received
1851                  CALL iom_putatt( kncid, 'DELAY_'//c_delaylist(ji), todelay(ji)%z1d(:) )
1852               ENDIF
1853            ENDIF
1854         END DO
1855         !
1856      ENDIF
1857     
1858   END SUBROUTINE iom_delay_rst
1859 
1860   
1861
[544]1862   !!----------------------------------------------------------------------
[1457]1863   !!                   INTERFACE iom_put
[1359]1864   !!----------------------------------------------------------------------
[13226]1865   SUBROUTINE iom_p0d_sp( cdname, pfield0d )
[1738]1866      CHARACTER(LEN=*), INTENT(in) ::   cdname
[13226]1867      REAL(sp)        , INTENT(in) ::   pfield0d
[11536]1868!!      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
[1738]1869#if defined key_iomput
[11536]1870!!clem      zz(:,:)=pfield0d
1871!!clem      CALL xios_send_field(cdname, zz)
1872      CALL xios_send_field(cdname, (/pfield0d/)) 
[1738]1873#else
1874      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
1875#endif
[13226]1876   END SUBROUTINE iom_p0d_sp
[1738]1877
[13226]1878   SUBROUTINE iom_p0d_dp( cdname, pfield0d )
1879      CHARACTER(LEN=*), INTENT(in) ::   cdname
1880      REAL(dp)        , INTENT(in) ::   pfield0d
1881!!      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
1882#if defined key_iomput
1883!!clem      zz(:,:)=pfield0d
1884!!clem      CALL xios_send_field(cdname, zz)
1885      CALL xios_send_field(cdname, (/pfield0d/)) 
1886#else
1887      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
1888#endif
1889   END SUBROUTINE iom_p0d_dp
1890
1891
1892   SUBROUTINE iom_p1d_sp( cdname, pfield1d )
[3294]1893      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
[13226]1894      REAL(sp),     DIMENSION(:), INTENT(in) ::   pfield1d
[3294]1895#if defined key_iomput
[3695]1896      CALL xios_send_field( cdname, RESHAPE( (/pfield1d/), (/1,1,SIZE(pfield1d)/) ) )
[3294]1897#else
1898      IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
1899#endif
[13226]1900   END SUBROUTINE iom_p1d_sp
[3294]1901
[13226]1902   SUBROUTINE iom_p1d_dp( cdname, pfield1d )
1903      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
1904      REAL(dp),     DIMENSION(:), INTENT(in) ::   pfield1d
1905#if defined key_iomput
1906      CALL xios_send_field( cdname, RESHAPE( (/pfield1d/), (/1,1,SIZE(pfield1d)/) ) )
1907#else
1908      IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
1909#endif
1910   END SUBROUTINE iom_p1d_dp
1911
1912   SUBROUTINE iom_p2d_sp( cdname, pfield2d )
[1359]1913      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
[13226]1914      REAL(sp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
[13286]1915      IF( iom_use(cdname) ) THEN
[1412]1916#if defined key_iomput
[13747]1917         CALL xios_send_field( cdname, pfield2d )
[1520]1918#else
[13286]1919         WRITE(numout,*) pfield2d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings
[1359]1920#endif
[13286]1921      ENDIF
[13226]1922   END SUBROUTINE iom_p2d_sp
[544]1923
[13226]1924   SUBROUTINE iom_p2d_dp( cdname, pfield2d )
1925      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
1926      REAL(dp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
[13286]1927      IF( iom_use(cdname) ) THEN
[13226]1928#if defined key_iomput
[13747]1929         CALL xios_send_field( cdname, pfield2d )
[13226]1930#else
[13286]1931         WRITE(numout,*) pfield2d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings
[13226]1932#endif
[13286]1933      ENDIF
[13226]1934   END SUBROUTINE iom_p2d_dp
1935
1936   SUBROUTINE iom_p3d_sp( cdname, pfield3d )
[1359]1937      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
[13226]1938      REAL(sp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
[13286]1939      IF( iom_use(cdname) ) THEN
[1412]1940#if defined key_iomput
[13747]1941         CALL xios_send_field( cdname, pfield3d )
[1520]1942#else
[13286]1943         WRITE(numout,*) pfield3d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings
[1359]1944#endif
[13286]1945      ENDIF
[13226]1946   END SUBROUTINE iom_p3d_sp
[544]1947
[13226]1948   SUBROUTINE iom_p3d_dp( cdname, pfield3d )
[12377]1949      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
[13226]1950      REAL(dp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
[13286]1951      IF( iom_use(cdname) ) THEN
[1412]1952#if defined key_iomput
[13747]1953         CALL xios_send_field( cdname, pfield3d )
[13226]1954#else
[13286]1955         WRITE(numout,*) pfield3d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings
[13226]1956#endif
[13286]1957      ENDIF
[13226]1958   END SUBROUTINE iom_p3d_dp
1959
1960   SUBROUTINE iom_p4d_sp( cdname, pfield4d )
1961      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
1962      REAL(sp),       DIMENSION(:,:,:,:), INTENT(in) ::   pfield4d
[13286]1963      IF( iom_use(cdname) ) THEN
[13226]1964#if defined key_iomput
[13747]1965         CALL xios_send_field (cdname, pfield4d )
[12276]1966#else
[13286]1967         WRITE(numout,*) pfield4d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings
[12276]1968#endif
[13286]1969      ENDIF
[13226]1970   END SUBROUTINE iom_p4d_sp
[12276]1971
[13226]1972   SUBROUTINE iom_p4d_dp( cdname, pfield4d )
1973      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
1974      REAL(dp),       DIMENSION(:,:,:,:), INTENT(in) ::   pfield4d
[13286]1975      IF( iom_use(cdname) ) THEN
[13226]1976#if defined key_iomput
[13747]1977         CALL xios_send_field (cdname, pfield4d )
[13226]1978#else
[13286]1979         WRITE(numout,*) pfield4d   ! iom_use(cdname) = .F. -> useless test to avoid compilation warnings
[13226]1980#endif
[13286]1981      ENDIF
[13226]1982   END SUBROUTINE iom_p4d_dp
[12276]1983
1984#if defined key_iomput
[9019]1985   !!----------------------------------------------------------------------
[9802]1986   !!   'key_iomput'                                         XIOS interface
[9019]1987   !!----------------------------------------------------------------------
[1359]1988
[9930]1989   SUBROUTINE iom_set_domain_attr( cdid, ni_glo, nj_glo, ibegin, jbegin, ni, nj,                                               &
[5363]1990      &                                    data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue, mask,     &
[5415]1991      &                                    nvertex, bounds_lon, bounds_lat, area )
[9019]1992      !!----------------------------------------------------------------------
1993      !!----------------------------------------------------------------------
1994      CHARACTER(LEN=*)                  , INTENT(in) ::   cdid
1995      INTEGER                 , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
1996      INTEGER                 , OPTIONAL, INTENT(in) ::   data_dim, data_ibegin, data_ni, data_jbegin, data_nj
[9930]1997      INTEGER                 , OPTIONAL, INTENT(in) ::   nvertex
[13226]1998      REAL(dp), DIMENSION(:)  , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
1999      REAL(dp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat, area
[9019]2000      LOGICAL , DIMENSION(:)  , OPTIONAL, INTENT(in) ::   mask
2001      !!----------------------------------------------------------------------
2002      !
2003      IF( xios_is_valid_domain     (cdid) ) THEN
[4148]2004         CALL xios_set_domain_attr     ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
2005            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
[7646]2006            &    lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon,      &
2007            &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear')
[9367]2008      ENDIF
[9019]2009      IF( xios_is_valid_domaingroup(cdid) ) THEN
[4148]2010         CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
2011            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
[7646]2012            &    lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon,      &
2013            &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear' )
[3695]2014      ENDIF
[9019]2015      !
[4148]2016      CALL xios_solve_inheritance()
[9019]2017      !
[3695]2018   END SUBROUTINE iom_set_domain_attr
2019
2020
[9019]2021   SUBROUTINE iom_set_zoom_domain_attr( cdid, ibegin, jbegin, ni, nj )
2022      !!----------------------------------------------------------------------
2023      !!----------------------------------------------------------------------
[9930]2024      CHARACTER(LEN=*), INTENT(in) ::   cdid
2025      INTEGER         , INTENT(in) ::   ibegin, jbegin, ni, nj
2026      !
2027      TYPE(xios_gridgroup) :: gridgroup_hdl
2028      TYPE(xios_grid)      :: grid_hdl
2029      TYPE(xios_domain)    :: domain_hdl 
2030      TYPE(xios_axis)      :: axis_hdl 
2031      CHARACTER(LEN=64)    :: cldomrefid   ! domain_ref name
2032      CHARACTER(len=1)     :: cl1          ! last character of this name
[9019]2033      !!----------------------------------------------------------------------
[9930]2034      !
2035      IF( xios_is_valid_zoom_domain(cdid) ) THEN
2036         ! define the zoom_domain attributs
2037         CALL xios_set_zoom_domain_attr( cdid, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj )
2038         ! define a new 2D grid with this new domain
2039         CALL xios_get_handle("grid_definition", gridgroup_hdl )
2040         CALL xios_add_child(gridgroup_hdl, grid_hdl, TRIM(cdid)//'_2D' )   ! add a new 2D grid to grid_definition
2041         CALL xios_add_child(grid_hdl, domain_hdl, TRIM(cdid) )             ! add its domain
2042         ! define a new 3D grid with this new domain
2043         CALL xios_add_child(gridgroup_hdl, grid_hdl, TRIM(cdid)//'_3D' )   ! add a new 3D grid to grid_definition
2044         CALL xios_add_child(grid_hdl, domain_hdl, TRIM(cdid) )             ! add its domain
2045         ! vertical axis
2046         cl1 = cdid(LEN_TRIM(cdid):)                                        ! last letter of cdid
2047         cl1 = CHAR(ICHAR(cl1)+32)                                          ! from upper to lower case
2048         CALL xios_add_child(grid_hdl, axis_hdl, 'depth'//cl1)              ! add its axis
2049      ENDIF
2050      !     
[7646]2051   END SUBROUTINE iom_set_zoom_domain_attr
2052
2053
[5415]2054   SUBROUTINE iom_set_axis_attr( cdid, paxis, bounds )
[9019]2055      !!----------------------------------------------------------------------
2056      !!----------------------------------------------------------------------
[4148]2057      CHARACTER(LEN=*)      , INTENT(in) ::   cdid
[5415]2058      REAL(wp), DIMENSION(:)  , OPTIONAL, INTENT(in) ::   paxis
2059      REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds
[9019]2060      !!----------------------------------------------------------------------
2061      IF( PRESENT(paxis) ) THEN
[13226]2062         IF( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, n_glo=SIZE(paxis), value=real(paxis, dp) )
2063         IF( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, n_glo=SIZE(paxis), value=real(paxis, dp) )
[5415]2064      ENDIF
[13226]2065      IF( PRESENT(bounds) ) THEN
2066         IF( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, bounds=real(bounds, dp) )
2067         IF( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, bounds=real(bounds, dp) )
2068      ELSE
2069         IF( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid)
2070         IF( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid)
2071      END IF
[4148]2072      CALL xios_solve_inheritance()
[3737]2073   END SUBROUTINE iom_set_axis_attr
2074
2075
[4148]2076   SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset )
[9019]2077      !!----------------------------------------------------------------------
2078      !!----------------------------------------------------------------------
2079      CHARACTER(LEN=*)             , INTENT(in) ::   cdid
2080      TYPE(xios_duration), OPTIONAL, INTENT(in) ::   freq_op
2081      TYPE(xios_duration), OPTIONAL, INTENT(in) ::   freq_offset
2082      !!----------------------------------------------------------------------
2083      IF( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
2084      IF( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr( cdid, freq_op=freq_op, freq_offset=freq_offset )
[4148]2085      CALL xios_solve_inheritance()
[3695]2086   END SUBROUTINE iom_set_field_attr
2087
2088
[4148]2089   SUBROUTINE iom_set_file_attr( cdid, name, name_suffix )
[9019]2090      !!----------------------------------------------------------------------
2091      !!----------------------------------------------------------------------
[4148]2092      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
[3695]2093      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   name, name_suffix
[9019]2094      !!----------------------------------------------------------------------
2095      IF( xios_is_valid_file     (cdid) )   CALL xios_set_file_attr     ( cdid, name=name, name_suffix=name_suffix )
2096      IF( xios_is_valid_filegroup(cdid) )   CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix )
[4148]2097      CALL xios_solve_inheritance()
[3771]2098   END SUBROUTINE iom_set_file_attr
[3695]2099
2100
[4148]2101   SUBROUTINE iom_get_file_attr( cdid, name, name_suffix, output_freq )
[9019]2102      !!----------------------------------------------------------------------
2103      !!----------------------------------------------------------------------
[4148]2104      CHARACTER(LEN=*)          , INTENT(in ) ::   cdid
[7646]2105      CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::   name, name_suffix
2106      TYPE(xios_duration), OPTIONAL , INTENT(out) :: output_freq
[4148]2107      LOGICAL                                 ::   llexist1,llexist2,llexist3
2108      !---------------------------------------------------------------------
2109      IF( PRESENT( name        ) )   name = ''          ! default values
2110      IF( PRESENT( name_suffix ) )   name_suffix = ''
[7646]2111      IF( PRESENT( output_freq ) )   output_freq = xios_duration(0,0,0,0,0,0)
[9019]2112      IF( xios_is_valid_file     (cdid) ) THEN
[4148]2113         CALL xios_solve_inheritance()
2114         CALL xios_is_defined_file_attr     ( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
2115         IF(llexist1)   CALL xios_get_file_attr     ( cdid, name = name )
2116         IF(llexist2)   CALL xios_get_file_attr     ( cdid, name_suffix = name_suffix )
2117         IF(llexist3)   CALL xios_get_file_attr     ( cdid, output_freq = output_freq )
2118      ENDIF
[9019]2119      IF( xios_is_valid_filegroup(cdid) ) THEN
[4148]2120         CALL xios_solve_inheritance()
2121         CALL xios_is_defined_filegroup_attr( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
2122         IF(llexist1)   CALL xios_get_filegroup_attr( cdid, name = name )
2123         IF(llexist2)   CALL xios_get_filegroup_attr( cdid, name_suffix = name_suffix )
2124         IF(llexist3)   CALL xios_get_filegroup_attr( cdid, output_freq = output_freq )
2125      ENDIF
2126   END SUBROUTINE iom_get_file_attr
2127
2128
2129   SUBROUTINE iom_set_grid_attr( cdid, mask )
[9019]2130      !!----------------------------------------------------------------------
2131      !!----------------------------------------------------------------------
[4148]2132      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
[3771]2133      LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) ::   mask
[9019]2134      !!----------------------------------------------------------------------
2135      IF( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask_3D=mask )
2136      IF( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask_3D=mask )
[4148]2137      CALL xios_solve_inheritance()
[3771]2138   END SUBROUTINE iom_set_grid_attr
[3695]2139
[4152]2140   SUBROUTINE iom_setkt( kt, cdname )
[9019]2141      !!----------------------------------------------------------------------
2142      !!----------------------------------------------------------------------
[4152]2143      INTEGER         , INTENT(in) ::   kt 
2144      CHARACTER(LEN=*), INTENT(in) ::   cdname
[9019]2145      !!----------------------------------------------------------------------
[4152]2146      CALL iom_swap( cdname )   ! swap to cdname context
2147      CALL xios_update_calendar(kt)
[9019]2148      IF( cdname /= TRIM(cxios_context) )   CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
[4152]2149   END SUBROUTINE iom_setkt
[3695]2150
[4152]2151   SUBROUTINE iom_context_finalize( cdname )
[9019]2152      !!----------------------------------------------------------------------
2153      !!----------------------------------------------------------------------
[4152]2154      CHARACTER(LEN=*), INTENT(in) :: cdname
[9367]2155      CHARACTER(LEN=120)           :: clname
[9019]2156      !!----------------------------------------------------------------------
[9367]2157      clname = cdname
2158      IF( TRIM(Agrif_CFixed()) .NE. '0' ) clname = TRIM(Agrif_CFixed())//"_"//clname 
2159      IF( xios_is_valid_context(clname) ) THEN
[4990]2160         CALL iom_swap( cdname )   ! swap to cdname context
2161         CALL xios_context_finalize() ! finalize the context
[5407]2162         IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
[4990]2163      ENDIF
[9367]2164      !
[4152]2165   END SUBROUTINE iom_context_finalize
2166
2167
[9984]2168   SUBROUTINE set_grid( cdgrd, plon, plat, ldxios, ldrxios )
[1359]2169      !!----------------------------------------------------------------------
[4148]2170      !!                     ***  ROUTINE set_grid  ***
[1359]2171      !!
[1725]2172      !! ** Purpose :   define horizontal grids
[1359]2173      !!----------------------------------------------------------------------
[3771]2174      CHARACTER(LEN=1)            , INTENT(in) ::   cdgrd
[1359]2175      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
2176      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
[3771]2177      !
2178      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask
[9984]2179      LOGICAL, INTENT(IN) :: ldxios, ldrxios
[9019]2180      !!----------------------------------------------------------------------
2181      !
[13286]2182      CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=Ni0glo,nj_glo=Nj0glo,ibegin=mig0(Nis0)-1,jbegin=mjg0(Njs0)-1,ni=Ni_0,nj=Nj_0)
[13747]2183      CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = -nn_hls, data_ni = jpi, data_jbegin = -nn_hls, data_nj = jpj)
[9984]2184!don't define lon and lat for restart reading context.
2185      IF ( .NOT.ldrxios ) &
[13286]2186         CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = real(RESHAPE(plon(Nis0:Nie0, Njs0:Nje0),(/ Ni_0*Nj_0 /)),dp),   &
2187         &                                        latvalue = real(RESHAPE(plat(Nis0:Nie0, Njs0:Nje0),(/ Ni_0*Nj_0 /)),dp )) 
[9019]2188      !
[9367]2189      IF ( ln_mskland .AND. (.NOT.ldxios) ) THEN
[3771]2190         ! mask land points, keep values on coast line -> specific mask for U, V and W points
2191         SELECT CASE ( cdgrd )
2192         CASE('T')   ;   zmask(:,:,:)       = tmask(:,:,:)
[13286]2193         CASE('U')   ;   zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)
2194         CASE('V')   ;   zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)
[3771]2195         CASE('W')   ;   zmask(:,:,2:jpk  ) = tmask(:,:,1:jpkm1) + tmask(:,:,2:jpk)   ;   zmask(:,:,1) = tmask(:,:,1)
2196         END SELECT
2197         !
[13286]2198         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(Nis0:Nie0,Njs0:Nje0,1),(/Ni_0*Nj_0    /)) /= 0. )
2199         CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(Nis0:Nie0,Njs0:Nje0,:),(/Ni_0,Nj_0,jpk/)) /= 0. )
[3771]2200      ENDIF
[9019]2201      !
[1359]2202   END SUBROUTINE set_grid
2203
[5415]2204   SUBROUTINE set_grid_bounds( cdgrd, plon_cnr, plat_cnr, plon_pnt, plat_pnt )
[5363]2205      !!----------------------------------------------------------------------
2206      !!                   ***  ROUTINE set_grid_bounds  ***
2207      !!
2208      !! ** Purpose :   define horizontal grid corners
2209      !!
2210      !!----------------------------------------------------------------------
[9019]2211      CHARACTER(LEN=1)                      , INTENT(in) :: cdgrd
2212      REAL(wp), DIMENSION(jpi,jpj)          , INTENT(in) :: plon_cnr, plat_cnr  ! Lat/lon coord. of a contiguous vertex of cell (i,j)
2213      REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt  ! Lat/lon coord. of the point of cell (i,j)
[5363]2214      !
[13286]2215      INTEGER :: ji, jj, jn
[12377]2216      INTEGER :: icnr, jcnr                             ! Offset such that the vertex coordinate (i+icnr,j+jcnr)
[13286]2217      !                                                 ! represents the
2218      !                                                 bottom-left corner of
2219      !                                                 cell (i,j)
[9019]2220      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: z_bnds      ! Lat/lon coordinates of the vertices of cell (i,j)
2221      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: z_fld       ! Working array to determine where to rotate cells
2222      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: z_rot       ! Lat/lon working array for rotation of cells
2223      !!----------------------------------------------------------------------
[5415]2224      !
[9019]2225      ALLOCATE( z_bnds(4,jpi,jpj,2), z_fld(jpi,jpj), z_rot(4,2)  )
[5363]2226      !
[5415]2227      ! Offset of coordinate representing bottom-left corner
[5363]2228      SELECT CASE ( TRIM(cdgrd) )
[9019]2229      CASE ('T', 'W')   ;   icnr = -1   ;   jcnr = -1
2230      CASE ('U')        ;   icnr =  0   ;   jcnr = -1
2231      CASE ('V')        ;   icnr = -1   ;   jcnr =  0
[5363]2232      END SELECT
[9019]2233      !
[5363]2234      z_fld(:,:) = 1._wp
[13226]2235      CALL lbc_lnk( 'iom', z_fld, cdgrd, -1.0_wp )    ! Working array for location of northfold
[9019]2236      !
[5363]2237      ! Cell vertices that can be defined
[13295]2238      DO_2D( 0, 0, 0, 0 )
[13286]2239         z_bnds(1,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left
2240         z_bnds(2,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right
2241         z_bnds(3,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right
2242         z_bnds(4,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr+1) ! Top-left
2243         z_bnds(1,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left
2244         z_bnds(2,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right
2245         z_bnds(3,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right
2246         z_bnds(4,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr+1) ! Top-left
2247      END_2D
[9019]2248      !
[13295]2249      DO_2D( 0, 0, 0, 0 )
[13286]2250         IF( z_fld(ji,jj) == -1. ) THEN
2251            z_rot(1,:) = z_bnds(3,ji,jj,:) ; z_rot(2,:) = z_bnds(4,ji,jj,:)
2252            z_rot(3,:) = z_bnds(1,ji,jj,:) ; z_rot(4,:) = z_bnds(2,ji,jj,:)
2253            z_bnds(:,ji,jj,:) = z_rot(:,:)
[5415]2254         ENDIF
[13286]2255      END_2D
[9019]2256      !
[13286]2257      CALL iom_set_domain_attr("grid_"//cdgrd, bounds_lat = real(RESHAPE(z_bnds(:,Nis0:Nie0,Njs0:Nje0,1),(/ 4,Ni_0*Nj_0 /)), dp),           &
2258          &                                    bounds_lon = real(RESHAPE(z_bnds(:,Nis0:Nie0,Njs0:Nje0,2),(/ 4,Ni_0*Nj_0 /)), dp), nvertex=4 )
[9019]2259      !
[13286]2260      DEALLOCATE( z_bnds, z_fld, z_rot )
[9019]2261      !
[5363]2262   END SUBROUTINE set_grid_bounds
2263
[5385]2264   SUBROUTINE set_grid_znl( plat )
2265      !!----------------------------------------------------------------------
2266      !!                     ***  ROUTINE set_grid_znl  ***
2267      !!
2268      !! ** Purpose :   define grids for zonal mean
2269      !!
2270      !!----------------------------------------------------------------------
2271      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
2272      !
[13286]2273      INTEGER  :: ix, iy
[5385]2274      REAL(wp), DIMENSION(:), ALLOCATABLE  ::   zlon
[9019]2275      !!----------------------------------------------------------------------
2276      !
[13286]2277      ALLOCATE( zlon(Ni_0*Nj_0) )       ;       zlon(:) = 0._wp
[9019]2278      !
[13226]2279!      CALL dom_ngb( -168.53_wp, 65.03_wp, ix, iy, 'T' ) !  i-line that passes through Bering Strait: Reference latitude (used in plots)
2280      CALL dom_ngb( 180.0_wp, 90.0_wp, ix, iy, 'T' ) !  i-line that passes near the North Pole : Reference latitude (used in plots)
[13286]2281      CALL iom_set_domain_attr("gznl", ni_glo=Ni0glo, nj_glo=Nj0glo, ibegin=mig0(Nis0)-1, jbegin=mjg0(Njs0)-1, ni=Ni_0, nj=Nj_0)
[13747]2282      CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = -nn_hls, data_ni = jpi, data_jbegin = -nn_hls, data_nj = jpj)
[13226]2283      CALL iom_set_domain_attr("gznl", lonvalue = real(zlon, dp),   &
[13286]2284         &                             latvalue = real(RESHAPE(plat(Nis0:Nie0, Njs0:Nje0),(/ Ni_0*Nj_0 /)),dp)) 
[13716]2285      CALL iom_set_zoom_domain_attr("ptr", ibegin=ix-1, jbegin=0, ni=1, nj=Nj0glo)
[5385]2286      !
2287      CALL iom_update_file_name('ptr')
2288      !
2289   END SUBROUTINE set_grid_znl
2290
[9019]2291
[1738]2292   SUBROUTINE set_scalar
2293      !!----------------------------------------------------------------------
[4148]2294      !!                     ***  ROUTINE set_scalar  ***
[1738]2295      !!
2296      !! ** Purpose :   define fake grids for scalar point
2297      !!
2298      !!----------------------------------------------------------------------
[13226]2299      REAL(dp), DIMENSION(1)   ::   zz = 1.
[1738]2300      !!----------------------------------------------------------------------
[9019]2301      !
[7646]2302      CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea-1, jbegin=0, ni=1, nj=1)
[5426]2303      CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
[9019]2304      !
2305      zz = REAL( narea, wp )
[5426]2306      CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz)
[9019]2307      !
[1738]2308   END SUBROUTINE set_scalar
2309
2310
[1725]2311   SUBROUTINE set_xmlatt
2312      !!----------------------------------------------------------------------
[4148]2313      !!                     ***  ROUTINE set_xmlatt  ***
[1725]2314      !!
2315      !! ** Purpose :   automatic definitions of some of the xml attributs...
2316      !!
2317      !!----------------------------------------------------------------------
2318      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
[4148]2319      CHARACTER(len=256)             ::   clsuff                   ! suffix name
[1725]2320      CHARACTER(len=1)               ::   cl1                      ! 1 character
[5003]2321      CHARACTER(len=2)               ::   cl2                      ! 2 characters
2322      CHARACTER(len=3)               ::   cl3                      ! 3 characters
[4148]2323      INTEGER                        ::   ji, jg                   ! loop counters
[1725]2324      INTEGER                        ::   ix, iy                   ! i-,j- index
2325      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
2326      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
2327      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
2328      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
2329      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
2330      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
[7646]2331      TYPE(xios_duration)            ::   f_op, f_of
[1725]2332      !!----------------------------------------------------------------------
2333      !
2334      ! frequency of the call of iom_put (attribut: freq_op)
[9019]2335      f_op%timestep = 1        ;  f_of%timestep =  0  ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of)
2336      f_op%timestep = 2        ;  f_of%timestep =  0  ; CALL iom_set_field_attr('trendT_even'     , freq_op=f_op, freq_offset=f_of)
2337      f_op%timestep = 2        ;  f_of%timestep = -1  ; CALL iom_set_field_attr('trendT_odd'      , freq_op=f_op, freq_offset=f_of)
2338      f_op%timestep = nn_fsbc  ;  f_of%timestep =  0  ; CALL iom_set_field_attr('SBC'             , freq_op=f_op, freq_offset=f_of)
2339      f_op%timestep = nn_fsbc  ;  f_of%timestep =  0  ; CALL iom_set_field_attr('SBC_scalar'      , freq_op=f_op, freq_offset=f_of)
[12377]2340      f_op%timestep = nn_fsbc  ;  f_of%timestep =  0  ; CALL iom_set_field_attr('ABL'             , freq_op=f_op, freq_offset=f_of)
[7646]2341
[1725]2342      ! output file names (attribut: name)
[4148]2343      DO ji = 1, 9
2344         WRITE(cl1,'(i1)') ji 
2345         CALL iom_update_file_name('file'//cl1)
[1725]2346      END DO
[4148]2347      DO ji = 1, 99
2348         WRITE(cl2,'(i2.2)') ji 
2349         CALL iom_update_file_name('file'//cl2)
2350      END DO
[5003]2351      DO ji = 1, 999
2352         WRITE(cl3,'(i3.3)') ji 
2353         CALL iom_update_file_name('file'//cl3)
2354      END DO
[1725]2355
2356      ! Zooms...
2357      clgrd = (/ 'T', 'U', 'W' /) 
2358      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
2359         cl1 = clgrd(jg)
2360         ! Equatorial section (attributs: jbegin, ni, name_suffix)
[13226]2361         CALL dom_ngb( 0.0_wp, 0.0_wp, ix, iy, cl1 )
[13286]2362         CALL iom_set_zoom_domain_attr('Eq'//cl1, ibegin=0, jbegin=iy-1, ni=Ni0glo, nj=1 )
[4148]2363         CALL iom_get_file_attr   ('Eq'//cl1, name_suffix = clsuff             )
2364         CALL iom_set_file_attr   ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq')
2365         CALL iom_update_file_name('Eq'//cl1)
[1725]2366      END DO
2367      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
2368      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
2369      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
2370      CALL set_mooring( zlontao, zlattao )
2371      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
2372      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
2373      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
2374      CALL set_mooring( zlonrama, zlatrama )
2375      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
2376      zlonpira = (/ -38.0, -23.0, -10.0 /)
2377      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
2378      CALL set_mooring( zlonpira, zlatpira )
[9019]2379      !
[1725]2380   END SUBROUTINE set_xmlatt
2381
2382
[9019]2383   SUBROUTINE set_mooring( plon, plat )
[1725]2384      !!----------------------------------------------------------------------
[4148]2385      !!                     ***  ROUTINE set_mooring  ***
[1725]2386      !!
2387      !! ** Purpose :   automatic definitions of moorings xml attributs...
2388      !!
2389      !!----------------------------------------------------------------------
[9019]2390      REAL(wp), DIMENSION(:), INTENT(in) ::   plon, plat   ! longitudes/latitudes oft the mooring
[1725]2391      !
2392!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
2393      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
[4148]2394      CHARACTER(len=256)            ::   clname                   ! file name
2395      CHARACTER(len=256)            ::   clsuff                   ! suffix name
[1725]2396      CHARACTER(len=1)              ::   cl1                      ! 1 character
2397      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
2398      INTEGER                       ::   ji, jj, jg               ! loop counters
2399      INTEGER                       ::   ix, iy                   ! i-,j- index
2400      REAL(wp)                      ::   zlon, zlat
2401      !!----------------------------------------------------------------------
2402      DO jg = 1, SIZE(clgrd)
2403         cl1 = clgrd(jg)
2404         DO ji = 1, SIZE(plon)
2405            DO jj = 1, SIZE(plat)
2406               zlon = plon(ji)
2407               zlat = plat(jj)
2408               ! modifications for RAMA moorings
2409               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
2410               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
2411               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
2412               ! modifications for PIRATA moorings
2413               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
2414               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
2415               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
2416               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
2417               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
2418               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
2419               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
2420               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
2421               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
2422               IF( zlon >= 0. ) THEN 
2423                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
2424                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
2425                  ENDIF
2426               ELSE             
2427                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
2428                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
2429                  ENDIF
2430               ENDIF
2431               IF( zlat >= 0. ) THEN 
2432                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
2433                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
2434                  ENDIF
2435               ELSE             
2436                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
2437                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
2438                  ENDIF
2439               ENDIF
2440               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
[9930]2441               CALL iom_set_zoom_domain_attr(TRIM(clname)//cl1, ibegin= ix-1, jbegin= iy-1, ni=1, nj=1)
[7646]2442
[4148]2443               CALL iom_get_file_attr   (TRIM(clname)//cl1, name_suffix = clsuff                         )
2444               CALL iom_set_file_attr   (TRIM(clname)//cl1, name_suffix = TRIM(clsuff)//'_'//TRIM(clname))
2445               CALL iom_update_file_name(TRIM(clname)//cl1)
[1725]2446            END DO
2447         END DO
2448      END DO
2449     
2450   END SUBROUTINE set_mooring
2451
[4148]2452   
2453   SUBROUTINE iom_update_file_name( cdid )
2454      !!----------------------------------------------------------------------
2455      !!                     ***  ROUTINE iom_update_file_name  ***
2456      !!
2457      !! ** Purpose :   
2458      !!
2459      !!----------------------------------------------------------------------
2460      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
2461      !
2462      CHARACTER(LEN=256) ::   clname
2463      CHARACTER(LEN=20)  ::   clfreq
2464      CHARACTER(LEN=20)  ::   cldate
2465      INTEGER            ::   idx
2466      INTEGER            ::   jn
2467      INTEGER            ::   itrlen
2468      INTEGER            ::   iyear, imonth, iday, isec
2469      REAL(wp)           ::   zsec
2470      LOGICAL            ::   llexist
[7646]2471      TYPE(xios_duration)   ::   output_freq 
[4148]2472      !!----------------------------------------------------------------------
[9019]2473      !
2474      DO jn = 1, 2
2475         !
[7646]2476         output_freq = xios_duration(0,0,0,0,0,0)
2477         IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = output_freq )
[4148]2478         IF( jn == 2 )   CALL iom_get_file_attr( cdid, name_suffix = clname )
[9019]2479         !
[4148]2480         IF ( TRIM(clname) /= '' ) THEN 
[9019]2481            !
[4148]2482            idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
2483            DO WHILE ( idx /= 0 ) 
2484               clname = clname(1:idx-1)//TRIM(cexper)//clname(idx+9:LEN_TRIM(clname))
2485               idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
2486            END DO
[9019]2487            !
[4148]2488            idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
2489            DO WHILE ( idx /= 0 ) 
[7646]2490              IF ( output_freq%timestep /= 0) THEN
2491                  WRITE(clfreq,'(I18,A2)')INT(output_freq%timestep),'ts' 
2492                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
[7764]2493              ELSE IF ( output_freq%second /= 0 ) THEN
2494                  WRITE(clfreq,'(I19,A1)')INT(output_freq%second),'s' 
2495                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
2496              ELSE IF ( output_freq%minute /= 0 ) THEN
[7768]2497                  WRITE(clfreq,'(I18,A2)')INT(output_freq%minute),'mi' 
[7764]2498                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
[7646]2499              ELSE IF ( output_freq%hour /= 0 ) THEN
2500                  WRITE(clfreq,'(I19,A1)')INT(output_freq%hour),'h' 
2501                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
2502              ELSE IF ( output_freq%day /= 0 ) THEN
2503                  WRITE(clfreq,'(I19,A1)')INT(output_freq%day),'d' 
2504                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
2505              ELSE IF ( output_freq%month /= 0 ) THEN   
2506                  WRITE(clfreq,'(I19,A1)')INT(output_freq%month),'m' 
2507                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
2508              ELSE IF ( output_freq%year /= 0 ) THEN   
2509                  WRITE(clfreq,'(I19,A1)')INT(output_freq%year),'y' 
2510                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
2511              ELSE
[4148]2512                  CALL ctl_stop('error in the name of file id '//TRIM(cdid),   &
2513                     & ' attribute output_freq is undefined -> cannot replace @freq@ in '//TRIM(clname) )
[7646]2514              ENDIF
2515              clname = clname(1:idx-1)//TRIM(ADJUSTL(clfreq))//clname(idx+6:LEN_TRIM(clname))
2516              idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
[4148]2517            END DO
[9019]2518            !
[4148]2519            idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
2520            DO WHILE ( idx /= 0 ) 
[12489]2521               cldate = iom_sdate( fjulday - rn_Dt / rday )
[4148]2522               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+11:LEN_TRIM(clname))
2523               idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
2524            END DO
[9019]2525            !
[4148]2526            idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
2527            DO WHILE ( idx /= 0 ) 
[12489]2528               cldate = iom_sdate( fjulday - rn_Dt / rday, ldfull = .TRUE. )
[4148]2529               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+15:LEN_TRIM(clname))
2530               idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
2531            END DO
[9019]2532            !
[4148]2533            idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
2534            DO WHILE ( idx /= 0 ) 
[12489]2535               cldate = iom_sdate( fjulday + rn_Dt / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. )
[4148]2536               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+9:LEN_TRIM(clname))
2537               idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
2538            END DO
[9019]2539            !
[4148]2540            idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
2541            DO WHILE ( idx /= 0 ) 
[12489]2542               cldate = iom_sdate( fjulday + rn_Dt / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. )
[4148]2543               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+13:LEN_TRIM(clname))
2544               idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
2545            END DO
[9019]2546            !
[12377]2547            IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
[4148]2548            IF( jn == 1 )   CALL iom_set_file_attr( cdid, name        = clname )
2549            IF( jn == 2 )   CALL iom_set_file_attr( cdid, name_suffix = clname )
[9019]2550            !
[4148]2551         ENDIF
[9019]2552         !
[4148]2553      END DO
[9019]2554      !
[4148]2555   END SUBROUTINE iom_update_file_name
2556
2557
2558   FUNCTION iom_sdate( pjday, ld24, ldfull )
2559      !!----------------------------------------------------------------------
2560      !!                     ***  ROUTINE iom_sdate  ***
2561      !!
2562      !! ** Purpose :   send back the date corresponding to the given julian day
2563      !!----------------------------------------------------------------------
[9019]2564      REAL(wp), INTENT(in   )           ::   pjday    ! julian day
2565      LOGICAL , INTENT(in   ), OPTIONAL ::   ld24     ! true to force 24:00 instead of 00:00
2566      LOGICAL , INTENT(in   ), OPTIONAL ::   ldfull   ! true to get the compleate date: yyyymmdd_hh:mm:ss
[4148]2567      !
2568      CHARACTER(LEN=20) ::   iom_sdate
2569      CHARACTER(LEN=50) ::   clfmt                         !  format used to write the date
2570      INTEGER           ::   iyear, imonth, iday, ihour, iminute, isec
2571      REAL(wp)          ::   zsec
2572      LOGICAL           ::   ll24, llfull
[9019]2573      !!----------------------------------------------------------------------
[4148]2574      !
2575      IF( PRESENT(ld24) ) THEN   ;   ll24 = ld24
2576      ELSE                       ;   ll24 = .FALSE.
2577      ENDIF
[9019]2578      !
[4148]2579      IF( PRESENT(ldfull) ) THEN   ;   llfull = ldfull
2580      ELSE                         ;   llfull = .FALSE.
2581      ENDIF
[9019]2582      !
[4148]2583      CALL ju2ymds( pjday, iyear, imonth, iday, zsec )
2584      isec = NINT(zsec)
[9019]2585      !
[4148]2586      IF ( ll24 .AND. isec == 0 ) THEN   ! 00:00 of the next day -> move to 24:00 of the current day
[13226]2587         CALL ju2ymds( pjday - 1.0_wp, iyear, imonth, iday, zsec )
[4148]2588         isec = 86400
2589      ENDIF
[9019]2590      !
[4148]2591      IF( iyear < 10000 ) THEN   ;   clfmt = "i4.4,2i2.2"                ! format used to write the date
2592      ELSE                       ;   WRITE(clfmt, "('i',i1,',2i2.2')") INT(LOG10(REAL(iyear,wp))) + 1
2593      ENDIF
[9019]2594      !
[5656]2595!$AGRIF_DO_NOT_TREAT     
[9019]2596      ! needed in the conv
[4148]2597      IF( llfull ) THEN
2598         clfmt = TRIM(clfmt)//",'_',i2.2,':',i2.2,':',i2.2"
2599         ihour   = isec / 3600
2600         isec    = MOD(isec, 3600)
2601         iminute = isec / 60
2602         isec    = MOD(isec, 60)
2603         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday, ihour, iminute, isec    ! date of the end of run
2604      ELSE
2605         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday                          ! date of the end of run
2606      ENDIF
[5656]2607!$AGRIF_END_DO_NOT_TREAT     
[9019]2608      !
[4148]2609   END FUNCTION iom_sdate
2610
[1359]2611#else
[9019]2612   !!----------------------------------------------------------------------
2613   !!   NOT 'key_iomput'                               a few dummy routines
2614   !!----------------------------------------------------------------------
[4152]2615   SUBROUTINE iom_setkt( kt, cdname )
2616      INTEGER         , INTENT(in)::   kt 
2617      CHARACTER(LEN=*), INTENT(in) ::   cdname
2618      IF( .FALSE. )   WRITE(numout,*) kt, cdname   ! useless test to avoid compilation warnings
[1359]2619   END SUBROUTINE iom_setkt
2620
[4152]2621   SUBROUTINE iom_context_finalize( cdname )
2622      CHARACTER(LEN=*), INTENT(in) ::   cdname
2623      IF( .FALSE. )   WRITE(numout,*)  cdname   ! useless test to avoid compilation warnings
2624   END SUBROUTINE iom_context_finalize
2625
[12377]2626   SUBROUTINE iom_update_file_name( cdid )
2627      CHARACTER(LEN=*), INTENT(in) ::   cdid
2628      IF( .FALSE. )   WRITE(numout,*)  cdid   ! useless test to avoid compilation warnings
2629   END SUBROUTINE iom_update_file_name
2630
[1359]2631#endif
[4689]2632
2633   LOGICAL FUNCTION iom_use( cdname )
2634      CHARACTER(LEN=*), INTENT(in) ::   cdname
2635#if defined key_iomput
2636      iom_use = xios_field_is_active( cdname )
2637#else
2638      iom_use = .FALSE.
2639#endif
2640   END FUNCTION iom_use
[11536]2641
2642   SUBROUTINE iom_miss_val( cdname, pmiss_val )
2643      CHARACTER(LEN=*), INTENT(in ) ::   cdname
2644      REAL(wp)        , INTENT(out) ::   pmiss_val   
[13226]2645      REAL(dp)                      ::   ztmp_pmiss_val   
[11536]2646#if defined key_iomput
2647      ! get missing value
[13226]2648      CALL xios_get_field_attr( cdname, default_value = ztmp_pmiss_val )
2649      pmiss_val = ztmp_pmiss_val
[11536]2650#else
2651      IF( .FALSE. )   WRITE(numout,*) cdname, pmiss_val   ! useless test to avoid compilation warnings
[12377]2652      IF( .FALSE. )   pmiss_val = 0._wp                   ! useless assignment to avoid compilation warnings
[11536]2653#endif
2654   END SUBROUTINE iom_miss_val
2655 
[544]2656   !!======================================================================
2657END MODULE iom
Note: See TracBrowser for help on using the repository browser.