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/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 6491

Last change on this file since 6491 was 6491, checked in by davestorkey, 8 years ago

Commit remaining changes to UKMO/r5518_GO6_package branch from following branches:
UKMO/dev_r5021_nn_etau_revision@6238
UKMO/dev_r5107_mld_zint@5534
UKMO/dev_r5107_eorca025_closea@6390
UKMO/restart_datestamp@5539
UKMO/icebergs_latent_heat@5821
UKMO/icebergs_restart_single_file_corrected@6480
UKMO/product_diagnostics@5971
UKMO/antarctic_partial_slip@5961
Custom merge into /branches/UKMO/dev_r5518_GO6_package/NEMOGCM: r5961 cf. r5958 of /branches/UKMO/antarctic_partial_slip/NEMOGCM@6490

Custom merge into /branches/UKMO/dev_r5518_GO6_package/NEMOGCM: r6349 cf. r5962 of /branches/UKMO/product_diagnostics/NEMOGCM@6490

Custom merge into /branches/UKMO/dev_r5518_GO6_package/NEMOGCM: r6480 cf. r6479 of /branches/UKMO/icebergs_restart_single_file_corrected/NEMOGCM@6490

Custom merge into /branches/UKMO/dev_r5518_GO6_package/NEMOGCM: r5986 cf. r5852 of /branches/UKMO/icebergs_restart_single_file/NEMOGCM@6490

Custom merge into /branches/UKMO/dev_r5518_GO6_package/NEMOGCM: r5821 cf. r5808 of /branches/UKMO/icebergs_latent_heat/NEMOGCM@6490

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