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

source: branches/UKMO/dev_r5518_GO6_package_XIOS_read/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 7918

Last change on this file since 7918 was 6498, checked in by timgraham, 8 years ago

Merge head of nemo_v3_6_STABLE into package branch

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