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/trunk/src/OCE/IOM – NEMO

source: NEMO/trunk/src/OCE/IOM/iom.F90 @ 13497

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

trunk: commit changes from r4.0-HEAD from 13284 to 13449, see #2523

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