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

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

source: NEMO/branches/2020/r12377_ticket2386/src/OCE/IOM/iom.F90 @ 13694

Last change on this file since 13694 was 13694, checked in by andmirek, 3 years ago

Ticket #2386: merge with trunk rev 13688

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