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/dev_r12558_HPC-08_epico_Extra_Halo/src/OCE/IOM – NEMO

source: NEMO/branches/2020/dev_r12558_HPC-08_epico_Extra_Halo/src/OCE/IOM/iom.F90 @ 13130

Last change on this file since 13130 was 13130, checked in by smasson, 4 years ago

Extra_Halo: supress halos from outputs and coupling, see #2366

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