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 branches/2017/dev_r8600_xios_read_write/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/2017/dev_r8600_xios_read_write/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 8770

Last change on this file since 8770 was 8770, checked in by andmirek, 6 years ago

#1953 and #1962 merged (and some modifications) with write branch

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