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/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 7398

Last change on this file since 7398 was 7398, checked in by cbricaud, 7 years ago

coarsening branch: first implementation of coarsening in PISCES

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