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

source: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 7069

Last change on this file since 7069 was 7069, checked in by clem, 8 years ago

agrif+lim3 update + trunk update

  • Property svn:keywords set to Id
File size: 98.7 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, jkmin
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      jkmin = MIN(2,jpk)  ! in case jpk=1 (i.e. sas2D)
193#if ! defined key_xios2
194      z_bnds(:      ,1) = gdepw_1d(:)
195      z_bnds(1:jpkm1,2) = gdepw_1d(jkmin:jpk)
196      z_bnds(jpk:   ,2) = gdepw_1d(jpk) + e3t_1d(jpk)
197#else
198      z_bnds(1      ,:) = gdepw_1d(:)
199      z_bnds(2,1:jpkm1) = gdepw_1d(jkmin:jpk)
200      z_bnds(2,jpk:   ) = gdepw_1d(jpk) + e3t_1d(jpk)
201#endif
202
203      CALL iom_set_axis_attr( "deptht", bounds=z_bnds )
204      CALL iom_set_axis_attr( "depthu", bounds=z_bnds )
205      CALL iom_set_axis_attr( "depthv", bounds=z_bnds )
206
207#if ! defined key_xios2
208      z_bnds(:        ,2) = gdept_1d(:)
209      z_bnds(jkmin:jpk,1) = gdept_1d(1:jpkm1)
210      z_bnds(1        ,1) = gdept_1d(1) - e3w_1d(1)
211#else
212      z_bnds(2,:        ) = gdept_1d(:)
213      z_bnds(1,jkmin:jpk) = gdept_1d(1:jpkm1)
214      z_bnds(1,1        ) = gdept_1d(1) - e3w_1d(1)
215#endif
216      CALL iom_set_axis_attr( "depthw", bounds=z_bnds )
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      !---------------------------------------------------------------------
711      !
712      clname = iom_file(kiomid)%name   !   esier to read
713      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
714      ! local definition of the domain ?
715      idom = kdom
716      ! do we read the overlap
717      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
718      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
719      ! check kcount and kstart optionals parameters...
720      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
721      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
722      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
723
724      luse_jattr = .false.
725      IF( PRESENT(lrowattr) ) THEN
726         IF( lrowattr .AND. idom /= jpdom_data   ) CALL ctl_stop(trim(clinfo), 'lrowattr present and true needs kdom = jpdom_data')
727         IF( lrowattr .AND. idom == jpdom_data   ) luse_jattr = .true.
728      ENDIF
729      IF( luse_jattr ) THEN
730         SELECT CASE (iom_file(kiomid)%iolib)
731         CASE (jpioipsl, jprstdimg )
732             CALL ctl_warn(trim(clinfo), 'lrowattr present and true but this only works with netcdf (jpnf90)')
733             luse_jattr = .false.
734         CASE (jpnf90   )   
735             ! Ok
736         CASE DEFAULT   
737            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
738         END SELECT
739      ENDIF
740
741      ! Search for the variable in the data base (eventually actualize data)
742      istop = nstop
743      idvar = iom_varid( kiomid, cdvar )
744      !
745      IF( idvar > 0 ) THEN
746         ! to write iom_file(kiomid)%dimsz in a shorter way !
747         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
748         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
749         idmspc = inbdim                                   ! number of spatial dimensions in the file
750         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
751         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
752         !
753         ! update idom definition...
754         ! Identify the domain in case of jpdom_auto(glo/dta) definition
755         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN           
756            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
757            ELSE                               ;   idom = jpdom_data
758            ENDIF
759            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
760            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
761            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
762         ENDIF
763         ! Identify the domain in case of jpdom_local definition
764         IF( idom == jpdom_local ) THEN
765            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
766            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
767            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
768            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
769            ENDIF
770         ENDIF
771         !
772         ! check the consistency between input array and data rank in the file
773         !
774         ! initializations
775         itime = 1
776         IF( PRESENT(ktime) ) itime = ktime
777
778         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
779         WRITE(clrankpv, fmt='(i1)') irankpv
780         WRITE(cldmspc , fmt='(i1)') idmspc
781         !
782         IF(     idmspc <  irankpv ) THEN
783            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
784               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
785         ELSEIF( idmspc == irankpv ) THEN
786            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
787               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
788         ELSEIF( idmspc >  irankpv ) THEN
789               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
790                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
791                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
792                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
793                  idmspc = idmspc - 1
794               ELSE
795                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
796                     &                         'we do not accept data with '//cldmspc//' spatial dimensions',   &
797                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
798               ENDIF
799         ENDIF
800
801         !
802         ! definition of istart and icnt
803         !
804         icnt  (:) = 1
805         istart(:) = 1
806         istart(idmspc+1) = itime
807
808         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
809         ELSE
810            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
811            ELSE
812               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
813                  IF(     idom == jpdom_data    ) THEN
814                     jstartrow = 1
815                     IF( luse_jattr ) THEN
816                        CALL iom_getatt(kiomid, 'open_ocean_jstart', jstartrow ) ! -999 is returned if the attribute is not found
817                        jstartrow = MAX(1,jstartrow)
818                     ENDIF
819                     istart(1:2) = (/ mig(1), mjg(1) + jstartrow - 1 /)  ! icnt(1:2) done below
820                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done below
821                  ENDIF
822                  ! we do not read the overlap                     -> we start to read at nldi, nldj
823! JMM + SM: ugly patch before getting the new version of lib_mpp)
824!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
825                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
826                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej
827! JMM + SM: ugly patch before getting the new version of lib_mpp)
828!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
829                  IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
830                  ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /)
831                  ENDIF
832                  IF( PRESENT(pv_r3d) ) THEN
833                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
834                     ELSE                            ; icnt(3) = jpk
835                     ENDIF
836                  ENDIF
837               ENDIF
838            ENDIF
839         ENDIF
840
841         ! check that istart and icnt can be used with this file
842         !-
843         DO jl = 1, jpmax_dims
844            itmp = istart(jl)+icnt(jl)-1
845            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
846               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
847               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
848               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
849            ENDIF
850         END DO
851
852         ! check that icnt matches the input array
853         !-     
854         IF( idom == jpdom_unknown ) THEN
855            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
856            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
857            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
858            ctmp1 = 'd'
859         ELSE
860            IF( irankpv == 2 ) THEN
861! JMM + SM: ugly patch before getting the new version of lib_mpp)
862!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
863               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
864               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
865               ENDIF
866            ENDIF
867            IF( irankpv == 3 ) THEN 
868! JMM + SM: ugly patch before getting the new version of lib_mpp)
869!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
870               IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
871               ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
872               ENDIF
873            ENDIF
874         ENDIF
875         
876         DO jl = 1, irankpv
877            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
878            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
879         END DO
880
881      ENDIF
882
883      ! read the data
884      !-     
885      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
886         !
887         ! find the right index of the array to be read
888! JMM + SM: ugly patch before getting the new version of lib_mpp)
889!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
890!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
891!         ENDIF
892         IF( llnoov ) THEN
893            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
894            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
895            ENDIF
896         ELSE
897            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
898            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
899            ENDIF
900         ENDIF
901     
902         SELECT CASE (iom_file(kiomid)%iolib)
903         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
904            &                                         pv_r1d, pv_r2d, pv_r3d )
905         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
906            &                                         pv_r1d, pv_r2d, pv_r3d )
907         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
908            &                                         pv_r1d, pv_r2d, pv_r3d )
909         CASE DEFAULT   
910            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
911         END SELECT
912
913         IF( istop == nstop ) THEN   ! no additional errors until this point...
914            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
915         
916            !--- overlap areas and extra hallows (mpp)
917            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
918               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
919            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
920               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
921               IF( icnt(3) == jpk ) THEN
922                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
923               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
924                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
925                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
926               ENDIF
927            ENDIF
928           
929            ! C1D case : always call lbc_lnk to replicate the central value over the whole 3X3 domain
930            IF( lk_c1d .AND. PRESENT(pv_r2d) )   CALL lbc_lnk( pv_r2d,'Z',1. )
931            IF( lk_c1d .AND. PRESENT(pv_r3d) )   CALL lbc_lnk( pv_r3d,'Z',1. )
932   
933            !--- Apply scale_factor and offset
934            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
935            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
936            IF(     PRESENT(pv_r1d) ) THEN
937               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
938               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
939            ELSEIF( PRESENT(pv_r2d) ) THEN
940!CDIR COLLAPSE
941               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
942!CDIR COLLAPSE
943               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
944            ELSEIF( PRESENT(pv_r3d) ) THEN
945!CDIR COLLAPSE
946               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
947!CDIR COLLAPSE
948               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
949            ENDIF
950            !
951         ENDIF
952         !
953      ENDIF
954      !
955   END SUBROUTINE iom_get_123d
956
957
958   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
959      !!--------------------------------------------------------------------
960      !!                   ***  SUBROUTINE iom_gettime  ***
961      !!
962      !! ** Purpose : read the time axis cdvar in the file
963      !!--------------------------------------------------------------------
964      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
965      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
966      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
967      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
968      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
969      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of
970      !
971      INTEGER, DIMENSION(1) :: kdimsz
972      INTEGER            ::   idvar    ! id of the variable
973      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
974      CHARACTER(LEN=100) ::   clinfo   ! info character
975      !---------------------------------------------------------------------
976      !
977      IF ( PRESENT(cdvar) ) THEN
978         tname = cdvar
979      ELSE
980         tname = iom_file(kiomid)%uldname
981      ENDIF
982      IF( kiomid > 0 ) THEN
983         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
984         IF ( PRESENT(kntime) ) THEN
985            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
986            kntime = kdimsz(1)
987         ELSE
988            idvar = iom_varid( kiomid, tname )
989         ENDIF
990         !
991         ptime(:) = 0. ! default definition
992         IF( idvar > 0 ) THEN
993            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
994               IF( iom_file(kiomid)%luld(idvar) ) THEN
995                  IF( iom_file(kiomid)%dimsz(1,idvar) <= size(ptime) ) THEN
996                     SELECT CASE (iom_file(kiomid)%iolib)
997                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
998                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
999                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
1000                     CASE DEFAULT   
1001                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1002                     END SELECT
1003                  ELSE
1004                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
1005                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
1006                  ENDIF
1007               ELSE
1008                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
1009               ENDIF
1010            ELSE
1011               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
1012            ENDIF
1013         ELSE
1014            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
1015         ENDIF
1016      ENDIF
1017      !
1018   END SUBROUTINE iom_gettime
1019
1020
1021   !!----------------------------------------------------------------------
1022   !!                   INTERFACE iom_getatt
1023   !!----------------------------------------------------------------------
1024   SUBROUTINE iom_g0d_intatt( kiomid, cdatt, pvar )
1025      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
1026      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute
1027      INTEGER         , INTENT(  out)                 ::   pvar      ! read field
1028      !
1029      IF( kiomid > 0 ) THEN
1030         IF( iom_file(kiomid)%nfid > 0 ) THEN
1031            SELECT CASE (iom_file(kiomid)%iolib)
1032            CASE (jpioipsl )   ;   CALL ctl_stop('iom_getatt: only nf90 available')
1033            CASE (jpnf90   )   ;   CALL iom_nf90_getatt( kiomid, cdatt, pvar )
1034            CASE (jprstdimg)   ;   CALL ctl_stop('iom_getatt: only nf90 available')
1035            CASE DEFAULT   
1036               CALL ctl_stop( 'iom_g0d_att: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1037            END SELECT
1038         ENDIF
1039      ENDIF
1040   END SUBROUTINE iom_g0d_intatt
1041
1042
1043   !!----------------------------------------------------------------------
1044   !!                   INTERFACE iom_rstput
1045   !!----------------------------------------------------------------------
1046   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
1047      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1048      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1049      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1050      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1051      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
1052      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1053      INTEGER :: ivid   ! variable id
1054      IF( kiomid > 0 ) THEN
1055         IF( iom_file(kiomid)%nfid > 0 ) THEN
1056            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
1057            SELECT CASE (iom_file(kiomid)%iolib)
1058            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
1059            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
1060            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
1061            CASE DEFAULT     
1062               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1063            END SELECT
1064         ENDIF
1065      ENDIF
1066   END SUBROUTINE iom_rp0d
1067
1068   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
1069      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1070      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1071      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1072      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1073      REAL(wp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
1074      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1075      INTEGER :: ivid   ! variable id
1076      IF( kiomid > 0 ) THEN
1077         IF( iom_file(kiomid)%nfid > 0 ) THEN
1078            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
1079            SELECT CASE (iom_file(kiomid)%iolib)
1080            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
1081            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
1082            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
1083            CASE DEFAULT     
1084               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1085            END SELECT
1086         ENDIF
1087      ENDIF
1088   END SUBROUTINE iom_rp1d
1089
1090   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
1091      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1092      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1093      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1094      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1095      REAL(wp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
1096      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1097      INTEGER :: ivid   ! variable id
1098      IF( kiomid > 0 ) THEN
1099         IF( iom_file(kiomid)%nfid > 0 ) THEN
1100            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
1101            SELECT CASE (iom_file(kiomid)%iolib)
1102            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
1103            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
1104            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
1105            CASE DEFAULT     
1106               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1107            END SELECT
1108         ENDIF
1109      ENDIF
1110   END SUBROUTINE iom_rp2d
1111
1112   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
1113      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1114      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1115      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1116      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
1117      REAL(wp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
1118      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1119      INTEGER :: ivid   ! variable id
1120      IF( kiomid > 0 ) THEN
1121         IF( iom_file(kiomid)%nfid > 0 ) THEN
1122            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
1123            SELECT CASE (iom_file(kiomid)%iolib)
1124            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
1125            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
1126            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
1127            CASE DEFAULT     
1128               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
1129            END SELECT
1130         ENDIF
1131      ENDIF
1132   END SUBROUTINE iom_rp3d
1133
1134
1135   !!----------------------------------------------------------------------
1136   !!                   INTERFACE iom_put
1137   !!----------------------------------------------------------------------
1138   SUBROUTINE iom_p0d( cdname, pfield0d )
1139      CHARACTER(LEN=*), INTENT(in) ::   cdname
1140      REAL(wp)        , INTENT(in) ::   pfield0d
1141      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
1142#if defined key_iomput
1143      zz(:,:)=pfield0d
1144      CALL xios_send_field(cdname, zz)
1145      !CALL xios_send_field(cdname, (/pfield0d/))
1146#else
1147      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
1148#endif
1149   END SUBROUTINE iom_p0d
1150
1151   SUBROUTINE iom_p1d( cdname, pfield1d )
1152      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
1153      REAL(wp),     DIMENSION(:), INTENT(in) ::   pfield1d
1154#if defined key_iomput
1155      CALL xios_send_field( cdname, RESHAPE( (/pfield1d/), (/1,1,SIZE(pfield1d)/) ) )
1156#else
1157      IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
1158#endif
1159   END SUBROUTINE iom_p1d
1160
1161   SUBROUTINE iom_p2d( cdname, pfield2d )
1162      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
1163      REAL(wp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
1164#if defined key_iomput
1165      CALL xios_send_field(cdname, pfield2d)
1166#else
1167      IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
1168#endif
1169   END SUBROUTINE iom_p2d
1170
1171   SUBROUTINE iom_p3d( cdname, pfield3d )
1172      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
1173      REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
1174#if defined key_iomput
1175      CALL xios_send_field(cdname, pfield3d)
1176#else
1177      IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
1178#endif
1179   END SUBROUTINE iom_p3d
1180   !!----------------------------------------------------------------------
1181
1182#if defined key_iomput
1183
1184   SUBROUTINE iom_set_domain_attr( cdid, ni_glo, nj_glo, ibegin, jbegin, ni, nj, zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj,   &
1185      &                                    data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue, mask,     &
1186      &                                    nvertex, bounds_lon, bounds_lat, area )
1187      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
1188      INTEGER                  , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
1189      INTEGER                  , OPTIONAL, INTENT(in) ::   data_dim, data_ibegin, data_ni, data_jbegin, data_nj
1190      INTEGER                  , OPTIONAL, INTENT(in) ::   zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj, nvertex
1191      REAL(wp), DIMENSION(:)   , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
1192      REAL(wp), DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat, area
1193#if ! defined key_xios2
1194     LOGICAL,  DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   mask
1195#else
1196      LOGICAL,  DIMENSION(:) , OPTIONAL, INTENT(in) ::   mask
1197#endif
1198
1199#if ! defined key_xios2
1200      IF ( xios_is_valid_domain     (cdid) ) THEN
1201         CALL xios_set_domain_attr     ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
1202            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
1203            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
1204            &    lonvalue=lonvalue, latvalue=latvalue, mask=mask, nvertex=nvertex, bounds_lon=bounds_lon,                  &
1205            &    bounds_lat=bounds_lat, area=area )
1206     ENDIF
1207      IF ( xios_is_valid_domaingroup(cdid) ) THEN
1208         CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
1209            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
1210            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
1211            &    lonvalue=lonvalue, latvalue=latvalue, mask=mask, nvertex=nvertex, bounds_lon=bounds_lon,                  &
1212            &    bounds_lat=bounds_lat, area=area )
1213      ENDIF
1214
1215#else
1216      IF ( xios_is_valid_domain     (cdid) ) THEN
1217         CALL xios_set_domain_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            &    lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon,                  &
1220            &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear')
1221     ENDIF
1222      IF ( xios_is_valid_domaingroup(cdid) ) THEN
1223         CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
1224            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
1225            &    lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon,                  &
1226            &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear' )
1227      ENDIF
1228#endif
1229      CALL xios_solve_inheritance()
1230
1231   END SUBROUTINE iom_set_domain_attr
1232
1233#if defined key_xios2
1234  SUBROUTINE iom_set_zoom_domain_attr( cdid, ibegin, jbegin, ni, nj)
1235     CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
1236     INTEGER                  , OPTIONAL, INTENT(in) ::   ibegin, jbegin, ni, nj
1237
1238     IF ( xios_is_valid_zoom_domain     (cdid) ) THEN
1239         CALL xios_set_zoom_domain_attr     ( cdid, ibegin=ibegin, jbegin=jbegin, ni=ni,    &
1240           &   nj=nj)
1241    ENDIF
1242  END SUBROUTINE iom_set_zoom_domain_attr
1243#endif
1244
1245
1246   SUBROUTINE iom_set_axis_attr( cdid, paxis, bounds )
1247      CHARACTER(LEN=*)      , INTENT(in) ::   cdid
1248      REAL(wp), DIMENSION(:)  , OPTIONAL, INTENT(in) ::   paxis
1249      REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds
1250      IF ( PRESENT(paxis) ) THEN
1251#if ! defined key_xios2
1252         IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, size=SIZE(paxis), value=paxis )
1253         IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, size=SIZE(paxis), value=paxis )
1254#else
1255         IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, n_glo=SIZE(paxis), value=paxis )
1256         IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, n_glo=SIZE(paxis), value=paxis )
1257#endif
1258      ENDIF
1259      IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, bounds=bounds )
1260      IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, bounds=bounds )
1261      CALL xios_solve_inheritance()
1262   END SUBROUTINE iom_set_axis_attr
1263
1264   SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset )
1265      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
1266#if ! defined key_xios2
1267      CHARACTER(LEN=*)   ,OPTIONAL , INTENT(in) ::   freq_op
1268      CHARACTER(LEN=*)   ,OPTIONAL , INTENT(in) ::   freq_offset
1269#else
1270      TYPE(xios_duration),OPTIONAL , INTENT(in) ::   freq_op
1271      TYPE(xios_duration),OPTIONAL , INTENT(in) ::   freq_offset
1272#endif
1273      IF ( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr       &
1274    &     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
1275      IF ( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr  &
1276    &                    ( cdid, freq_op=freq_op, freq_offset=freq_offset )
1277      CALL xios_solve_inheritance()
1278   END SUBROUTINE iom_set_field_attr
1279
1280   SUBROUTINE iom_set_file_attr( cdid, name, name_suffix )
1281      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
1282      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   name, name_suffix
1283      IF ( xios_is_valid_file     (cdid) )   CALL xios_set_file_attr     ( cdid, name=name, name_suffix=name_suffix )
1284      IF ( xios_is_valid_filegroup(cdid) )   CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix )
1285      CALL xios_solve_inheritance()
1286   END SUBROUTINE iom_set_file_attr
1287
1288
1289   SUBROUTINE iom_get_file_attr( cdid, name, name_suffix, output_freq )
1290      CHARACTER(LEN=*)          , INTENT(in ) ::   cdid
1291      CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::   name, name_suffix
1292#if ! defined key_xios2
1293      CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::    output_freq
1294#else
1295      TYPE(xios_duration)   ,OPTIONAL , INTENT(out) :: output_freq
1296#endif 
1297      LOGICAL                                 ::   llexist1,llexist2,llexist3
1298      !---------------------------------------------------------------------
1299      IF( PRESENT( name        ) )   name = ''          ! default values
1300      IF( PRESENT( name_suffix ) )   name_suffix = ''
1301#if ! defined key_xios2
1302      IF( PRESENT( output_freq ) )   output_freq = ''
1303#else
1304      IF( PRESENT( output_freq ) )   output_freq = xios_duration(0,0,0,0,0,0)
1305#endif
1306      IF ( xios_is_valid_file     (cdid) ) THEN
1307         CALL xios_solve_inheritance()
1308         CALL xios_is_defined_file_attr     ( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
1309         IF(llexist1)   CALL xios_get_file_attr     ( cdid, name = name )
1310         IF(llexist2)   CALL xios_get_file_attr     ( cdid, name_suffix = name_suffix )
1311         IF(llexist3)   CALL xios_get_file_attr     ( cdid, output_freq = output_freq )
1312      ENDIF
1313      IF ( xios_is_valid_filegroup(cdid) ) THEN
1314         CALL xios_solve_inheritance()
1315         CALL xios_is_defined_filegroup_attr( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
1316         IF(llexist1)   CALL xios_get_filegroup_attr( cdid, name = name )
1317         IF(llexist2)   CALL xios_get_filegroup_attr( cdid, name_suffix = name_suffix )
1318         IF(llexist3)   CALL xios_get_filegroup_attr( cdid, output_freq = output_freq )
1319      ENDIF
1320   END SUBROUTINE iom_get_file_attr
1321
1322
1323   SUBROUTINE iom_set_grid_attr( cdid, mask )
1324      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
1325      LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) ::   mask
1326#if ! defined key_xios2
1327      IF ( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask=mask )
1328      IF ( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask=mask )
1329#else
1330      IF ( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask_3D=mask )
1331      IF ( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask_3D=mask )
1332#endif
1333      CALL xios_solve_inheritance()
1334   END SUBROUTINE iom_set_grid_attr
1335
1336   SUBROUTINE iom_setkt( kt, cdname )
1337      INTEGER         , INTENT(in) ::   kt 
1338      CHARACTER(LEN=*), INTENT(in) ::   cdname
1339      !     
1340      CALL iom_swap( cdname )   ! swap to cdname context
1341      CALL xios_update_calendar(kt)
1342      IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
1343      !
1344   END SUBROUTINE iom_setkt
1345
1346   SUBROUTINE iom_context_finalize( cdname )
1347      CHARACTER(LEN=*), INTENT(in) :: cdname
1348      !
1349      IF( xios_is_valid_context(cdname) ) THEN
1350         CALL iom_swap( cdname )   ! swap to cdname context
1351         CALL xios_context_finalize() ! finalize the context
1352         IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
1353      ENDIF
1354      !
1355   END SUBROUTINE iom_context_finalize
1356
1357
1358   SUBROUTINE set_grid( cdgrd, plon, plat )
1359      !!----------------------------------------------------------------------
1360      !!                     ***  ROUTINE set_grid  ***
1361      !!
1362      !! ** Purpose :   define horizontal grids
1363      !!
1364      !!----------------------------------------------------------------------
1365      CHARACTER(LEN=1)            , INTENT(in) ::   cdgrd
1366      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
1367      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
1368      !
1369      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask
1370      INTEGER  :: ni,nj
1371     
1372      ni=nlei-nldi+1 ; nj=nlej-nldj+1
1373
1374#if ! defined key_xios2
1375     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)
1376#else
1377     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)
1378#endif     
1379      CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
1380      CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)),   &
1381         &                                     latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) 
1382
1383      IF ( ln_mskland ) THEN
1384         ! mask land points, keep values on coast line -> specific mask for U, V and W points
1385         SELECT CASE ( cdgrd )
1386         CASE('T')   ;   zmask(:,:,:)       = tmask(:,:,:)
1387         CASE('U')   ;   zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)   ;   CALL lbc_lnk( zmask, 'U', 1. )
1388         CASE('V')   ;   zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)   ;   CALL lbc_lnk( zmask, 'V', 1. )
1389         CASE('W')   ;   zmask(:,:,2:jpk  ) = tmask(:,:,1:jpkm1) + tmask(:,:,2:jpk)   ;   zmask(:,:,1) = tmask(:,:,1)
1390         END SELECT
1391         !
1392#if ! defined key_xios2
1393         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni,nj    /)) /= 0. )
1394#else
1395         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni*nj    /)) /= 0. )
1396#endif 
1397         CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. )
1398      ENDIF
1399     
1400   END SUBROUTINE set_grid
1401
1402
1403   SUBROUTINE set_grid_bounds( cdgrd, plon_cnr, plat_cnr, plon_pnt, plat_pnt )
1404      !!----------------------------------------------------------------------
1405      !!                   ***  ROUTINE set_grid_bounds  ***
1406      !!
1407      !! ** Purpose :   define horizontal grid corners
1408      !!
1409      !!----------------------------------------------------------------------
1410      CHARACTER(LEN=1) , INTENT(in) :: cdgrd
1411      !
1412      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)           :: plon_cnr, plat_cnr  ! Lat/lon coordinates of a contiguous vertex of cell (i,j)
1413      REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt  ! Lat/lon coordinates of the point of cell (i,j)
1414      !
1415      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)   :: z_bnds      ! Lat/lon coordinates of the vertices of cell (i,j)
1416      REAL(wp), ALLOCATABLE, DIMENSION(:,:)       :: z_fld       ! Working array to determine where to rotate cells
1417      REAL(wp), ALLOCATABLE, DIMENSION(:,:)       :: z_rot       ! Lat/lon working array for rotation of cells
1418      !
1419      INTEGER :: icnr, jcnr                                      ! Offset such that the vertex coordinate (i+icnr,j+jcnr)
1420      !                                                          ! represents the bottom-left corner of cell (i,j)
1421      INTEGER :: ji, jj, jn, ni, nj
1422
1423      ALLOCATE( z_bnds(4,jpi,jpj,2), z_fld(jpi,jpj), z_rot(4,2)  )
1424
1425      ! Offset of coordinate representing bottom-left corner
1426      SELECT CASE ( TRIM(cdgrd) )
1427         CASE ('T', 'W')
1428            icnr = -1 ; jcnr = -1
1429         CASE ('U')
1430            icnr =  0 ; jcnr = -1
1431         CASE ('V')
1432            icnr = -1 ; jcnr =  0
1433      END SELECT
1434
1435      ni = nlei-nldi+1 ; nj = nlej-nldj+1  ! Dimensions of subdomain interior
1436
1437      z_fld(:,:) = 1._wp
1438      CALL lbc_lnk( z_fld, cdgrd, -1. )    ! Working array for location of northfold
1439
1440      ! Cell vertices that can be defined
1441      DO jj = 2, jpjm1
1442         DO ji = 2, jpim1
1443            z_bnds(1,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left
1444            z_bnds(2,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right
1445            z_bnds(3,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right
1446            z_bnds(4,ji,jj,1) = plat_cnr(ji+icnr,  jj+jcnr+1) ! Top-left
1447            z_bnds(1,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr  ) ! Bottom-left
1448            z_bnds(2,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr  ) ! Bottom-right
1449            z_bnds(3,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right
1450            z_bnds(4,ji,jj,2) = plon_cnr(ji+icnr,  jj+jcnr+1) ! Top-left
1451         END DO
1452      END DO
1453
1454      ! Cell vertices on boundries
1455      DO jn = 1, 4
1456         CALL lbc_lnk( z_bnds(jn,:,:,1), cdgrd, 1., pval=999._wp )
1457         CALL lbc_lnk( z_bnds(jn,:,:,2), cdgrd, 1., pval=999._wp )
1458      END DO
1459
1460      ! Zero-size cells at closed boundaries if cell points provided,
1461      ! otherwise they are closed cells with unrealistic bounds
1462      IF( PRESENT(plon_pnt) .AND. PRESENT(plat_pnt) ) THEN
1463         IF( (nbondi == -1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN
1464            DO jn = 1, 4        ! (West or jpni = 1), closed E-W
1465               z_bnds(jn,1,:,1) = plat_pnt(1,:)  ;  z_bnds(jn,1,:,2) = plon_pnt(1,:)
1466            END DO
1467         ENDIF
1468         IF( (nbondi == 1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN
1469            DO jn = 1, 4        ! (East or jpni = 1), closed E-W
1470               z_bnds(jn,nlci,:,1) = plat_pnt(nlci,:)  ;  z_bnds(jn,nlci,:,2) = plon_pnt(nlci,:)
1471            END DO
1472         ENDIF
1473         IF( nbondj == -1 .OR. (nbondj == 2 .AND. jperio /= 2) ) THEN
1474            DO jn = 1, 4        ! South or (jpnj = 1, not symmetric)
1475               z_bnds(jn,:,1,1) = plat_pnt(:,1)  ;  z_bnds(jn,:,1,2) = plon_pnt(:,1)
1476            END DO
1477         ENDIF
1478         IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio  < 3 ) THEN
1479            DO jn = 1, 4        ! (North or jpnj = 1), no north fold
1480               z_bnds(jn,:,nlcj,1) = plat_pnt(:,nlcj)  ;  z_bnds(jn,:,nlcj,2) = plon_pnt(:,nlcj)
1481            END DO
1482         ENDIF
1483      ENDIF
1484
1485      ! Rotate cells at the north fold
1486      IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio >= 3 ) THEN
1487         DO jj = 1, jpj
1488            DO ji = 1, jpi
1489               IF( z_fld(ji,jj) == -1. ) THEN
1490                  z_rot(1,:) = z_bnds(3,ji,jj,:) ; z_rot(2,:) = z_bnds(4,ji,jj,:)
1491                  z_rot(3,:) = z_bnds(1,ji,jj,:) ; z_rot(4,:) = z_bnds(2,ji,jj,:)
1492                  z_bnds(:,ji,jj,:) = z_rot(:,:)
1493               ENDIF
1494            END DO
1495         END DO
1496
1497      ! Invert cells at the symmetric equator
1498      ELSE IF( nbondj == 2 .AND. jperio == 2 ) THEN
1499         DO ji = 1, jpi
1500            z_rot(1:2,:) = z_bnds(3:4,ji,1,:)
1501            z_rot(3:4,:) = z_bnds(1:2,ji,1,:)
1502            z_bnds(:,ji,1,:) = z_rot(:,:)
1503         END DO
1504      ENDIF
1505
1506      CALL iom_set_domain_attr("grid_"//cdgrd, bounds_lat = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,1),(/ 4,ni*nj /)),           &
1507                                               bounds_lon = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,2),(/ 4,ni*nj /)), nvertex=4 )
1508
1509      DEALLOCATE( z_bnds, z_fld, z_rot ) 
1510
1511   END SUBROUTINE set_grid_bounds
1512
1513
1514   SUBROUTINE set_grid_znl( plat )
1515      !!----------------------------------------------------------------------
1516      !!                     ***  ROUTINE set_grid_znl  ***
1517      !!
1518      !! ** Purpose :   define grids for zonal mean
1519      !!
1520      !!----------------------------------------------------------------------
1521      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
1522      !
1523      REAL(wp), DIMENSION(:), ALLOCATABLE  ::   zlon
1524      INTEGER  :: ni,nj, ix, iy
1525
1526     
1527      ni=nlei-nldi+1 ; nj=nlej-nldj+1            ! define zonal mean domain (jpj*jpk)
1528      ALLOCATE( zlon(ni*nj) )       ;       zlon(:) = 0.
1529
1530      CALL dom_ngb( 180., 90., ix, iy, 'T' ) !  i-line that passes near the North Pole : Reference latitude (used in plots)
1531#if ! defined key_xios2
1532      CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-1, jbegin=njmpp+nldj-1, ni=ni, nj=nj)
1533      CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
1534      CALL iom_set_domain_attr("gznl", lonvalue = zlon,   &
1535         &                             latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) 
1536      !
1537      CALL iom_set_domain_attr ('ptr', zoom_ibegin=ix, zoom_nj=jpjglo)
1538#else
1539! Pas teste : attention aux indices !
1540      CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
1541      CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
1542      CALL iom_set_domain_attr("gznl", lonvalue = zlon,   &
1543         &                             latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) 
1544       CALL iom_set_zoom_domain_attr ("ptr", ibegin=ix-1, jbegin=0, ni=1, nj=jpjglo)
1545#endif
1546
1547      CALL iom_update_file_name('ptr')
1548      !
1549   END SUBROUTINE set_grid_znl
1550
1551   SUBROUTINE set_scalar
1552      !!----------------------------------------------------------------------
1553      !!                     ***  ROUTINE set_scalar  ***
1554      !!
1555      !! ** Purpose :   define fake grids for scalar point
1556      !!
1557      !!----------------------------------------------------------------------
1558      REAL(wp), DIMENSION(1)   ::   zz = 1.
1559      !!----------------------------------------------------------------------
1560#if ! defined key_xios2
1561      CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea, jbegin=1, ni=1, nj=1)
1562#else
1563      CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea-1, jbegin=0, ni=1, nj=1)
1564#endif
1565      CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
1566     
1567      zz=REAL(narea,wp)
1568      CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz)
1569     
1570   END SUBROUTINE set_scalar
1571
1572
1573   SUBROUTINE set_xmlatt
1574      !!----------------------------------------------------------------------
1575      !!                     ***  ROUTINE set_xmlatt  ***
1576      !!
1577      !! ** Purpose :   automatic definitions of some of the xml attributs...
1578      !!
1579      !!----------------------------------------------------------------------
1580      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
1581      CHARACTER(len=256)             ::   clsuff                   ! suffix name
1582      CHARACTER(len=1)               ::   cl1                      ! 1 character
1583      CHARACTER(len=2)               ::   cl2                      ! 2 characters
1584      CHARACTER(len=3)               ::   cl3                      ! 3 characters
1585      INTEGER                        ::   ji, jg                   ! loop counters
1586      INTEGER                        ::   ix, iy                   ! i-,j- index
1587      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
1588      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
1589      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
1590      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
1591      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
1592      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
1593#if  defined key_xios2
1594      TYPE(xios_duration)            ::   f_op, f_of
1595#endif
1596 
1597      !!----------------------------------------------------------------------
1598      !
1599      ! frequency of the call of iom_put (attribut: freq_op)
1600#if ! defined key_xios2
1601      WRITE(cl1,'(i1)')        1   ;   CALL iom_set_field_attr('field_definition', freq_op=cl1//'ts', freq_offset='0ts')
1602      WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC'             , freq_op=cl1//'ts', freq_offset='0ts')
1603      WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC_scalar'      , freq_op=cl1//'ts', freq_offset='0ts')
1604      WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('ptrc_T'          , freq_op=cl1//'ts', freq_offset='0ts')
1605      WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('diad_T'          , freq_op=cl1//'ts', freq_offset='0ts')
1606#else
1607      f_op%timestep = 1        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of)
1608      f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC'             , freq_op=f_op, freq_offset=f_of)
1609      f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC_scalar'      , freq_op=f_op, freq_offset=f_of)
1610      f_op%timestep = nn_dttrc ;  f_of%timestep = 0  ; CALL iom_set_field_attr('ptrc_T'          , freq_op=f_op, freq_offset=f_of)
1611      f_op%timestep = nn_dttrc ;  f_of%timestep = 0  ; CALL iom_set_field_attr('diad_T'          , freq_op=f_op, freq_offset=f_of)
1612#endif
1613       
1614      ! output file names (attribut: name)
1615      DO ji = 1, 9
1616         WRITE(cl1,'(i1)') ji 
1617         CALL iom_update_file_name('file'//cl1)
1618      END DO
1619      DO ji = 1, 99
1620         WRITE(cl2,'(i2.2)') ji 
1621         CALL iom_update_file_name('file'//cl2)
1622      END DO
1623      DO ji = 1, 999
1624         WRITE(cl3,'(i3.3)') ji 
1625         CALL iom_update_file_name('file'//cl3)
1626      END DO
1627
1628      ! Zooms...
1629      clgrd = (/ 'T', 'U', 'W' /) 
1630      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
1631         cl1 = clgrd(jg)
1632         ! Equatorial section (attributs: jbegin, ni, name_suffix)
1633         CALL dom_ngb( 0., 0., ix, iy, cl1 )
1634#if ! defined key_xios2
1635         CALL iom_set_domain_attr ('Eq'//cl1, zoom_jbegin=iy, zoom_ni=jpiglo)
1636#else
1637         CALL iom_set_zoom_domain_attr ('Eq'//cl1, jbegin=iy-1, ni=jpiglo)
1638#endif
1639         CALL iom_get_file_attr   ('Eq'//cl1, name_suffix = clsuff             )
1640         CALL iom_set_file_attr   ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq')
1641         CALL iom_update_file_name('Eq'//cl1)
1642      END DO
1643      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
1644      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
1645      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
1646      CALL set_mooring( zlontao, zlattao )
1647      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
1648      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
1649      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
1650      CALL set_mooring( zlonrama, zlatrama )
1651      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
1652      zlonpira = (/ -38.0, -23.0, -10.0 /)
1653      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
1654      CALL set_mooring( zlonpira, zlatpira )
1655
1656     
1657   END SUBROUTINE set_xmlatt
1658
1659
1660   SUBROUTINE set_mooring( plon, plat)
1661      !!----------------------------------------------------------------------
1662      !!                     ***  ROUTINE set_mooring  ***
1663      !!
1664      !! ** Purpose :   automatic definitions of moorings xml attributs...
1665      !!
1666      !!----------------------------------------------------------------------
1667      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
1668      !
1669!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
1670      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
1671      CHARACTER(len=256)            ::   clname                   ! file name
1672      CHARACTER(len=256)            ::   clsuff                   ! suffix name
1673      CHARACTER(len=1)              ::   cl1                      ! 1 character
1674      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
1675      INTEGER                       ::   ji, jj, jg               ! loop counters
1676      INTEGER                       ::   ix, iy                   ! i-,j- index
1677      REAL(wp)                      ::   zlon, zlat
1678      !!----------------------------------------------------------------------
1679      DO jg = 1, SIZE(clgrd)
1680         cl1 = clgrd(jg)
1681         DO ji = 1, SIZE(plon)
1682            DO jj = 1, SIZE(plat)
1683               zlon = plon(ji)
1684               zlat = plat(jj)
1685               ! modifications for RAMA moorings
1686               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
1687               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
1688               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
1689               ! modifications for PIRATA moorings
1690               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
1691               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
1692               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
1693               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
1694               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
1695               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
1696               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
1697               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
1698               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
1699               IF( zlon >= 0. ) THEN 
1700                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
1701                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
1702                  ENDIF
1703               ELSE             
1704                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
1705                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
1706                  ENDIF
1707               ENDIF
1708               IF( zlat >= 0. ) THEN 
1709                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
1710                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
1711                  ENDIF
1712               ELSE             
1713                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
1714                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
1715                  ENDIF
1716               ENDIF
1717               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
1718#if ! defined key_xios2
1719               CALL iom_set_domain_attr (TRIM(clname)//cl1, zoom_ibegin= ix, zoom_jbegin= iy)
1720#else
1721               CALL iom_set_zoom_domain_attr  (TRIM(clname)//cl1, ibegin= ix-1, jbegin= iy-1)
1722#endif
1723               CALL iom_get_file_attr   (TRIM(clname)//cl1, name_suffix = clsuff                         )
1724               CALL iom_set_file_attr   (TRIM(clname)//cl1, name_suffix = TRIM(clsuff)//'_'//TRIM(clname))
1725               CALL iom_update_file_name(TRIM(clname)//cl1)
1726            END DO
1727         END DO
1728      END DO
1729     
1730   END SUBROUTINE set_mooring
1731
1732   
1733   SUBROUTINE iom_update_file_name( cdid )
1734      !!----------------------------------------------------------------------
1735      !!                     ***  ROUTINE iom_update_file_name  ***
1736      !!
1737      !! ** Purpose :   
1738      !!
1739      !!----------------------------------------------------------------------
1740      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
1741      !
1742      CHARACTER(LEN=256) ::   clname
1743      CHARACTER(LEN=20)  ::   clfreq
1744      CHARACTER(LEN=20)  ::   cldate
1745      INTEGER            ::   idx
1746      INTEGER            ::   jn
1747      INTEGER            ::   itrlen
1748      INTEGER            ::   iyear, imonth, iday, isec
1749      REAL(wp)           ::   zsec
1750      LOGICAL            ::   llexist
1751#if  defined key_xios2
1752      TYPE(xios_duration)   ::   output_freq 
1753#endif     
1754      !!----------------------------------------------------------------------
1755
1756
1757      DO jn = 1,2
1758#if ! defined key_xios2
1759         IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = clfreq )
1760#else
1761         output_freq = xios_duration(0,0,0,0,0,0)
1762         IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = output_freq )
1763#endif
1764         IF( jn == 2 )   CALL iom_get_file_attr( cdid, name_suffix = clname )
1765
1766         IF ( TRIM(clname) /= '' ) THEN
1767
1768            idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
1769            DO WHILE ( idx /= 0 ) 
1770               clname = clname(1:idx-1)//TRIM(cexper)//clname(idx+9:LEN_TRIM(clname))
1771               idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
1772            END DO
1773
1774#if ! defined key_xios2
1775            idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
1776            DO WHILE ( idx /= 0 ) 
1777               IF ( TRIM(clfreq) /= '' ) THEN
1778                  itrlen = LEN_TRIM(clfreq)
1779                  IF ( clfreq(itrlen-1:itrlen) == 'mo' ) clfreq = clfreq(1:itrlen-1)
1780                  clname = clname(1:idx-1)//TRIM(clfreq)//clname(idx+6:LEN_TRIM(clname))
1781               ELSE
1782                  CALL ctl_stop('error in the name of file id '//TRIM(cdid),   &
1783                     & ' attribute output_freq is undefined -> cannot replace @freq@ in '//TRIM(clname) )
1784               ENDIF
1785               idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
1786            END DO
1787#else
1788            idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
1789            DO WHILE ( idx /= 0 ) 
1790              IF ( output_freq%timestep /= 0) THEN
1791                  WRITE(clfreq,'(I18,A2)')INT(output_freq%timestep),'ts' 
1792                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
1793              ELSE IF ( output_freq%hour /= 0 ) THEN
1794                  WRITE(clfreq,'(I19,A1)')INT(output_freq%hour),'h' 
1795                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
1796              ELSE IF ( output_freq%day /= 0 ) THEN
1797                  WRITE(clfreq,'(I19,A1)')INT(output_freq%day),'d' 
1798                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
1799              ELSE IF ( output_freq%month /= 0 ) THEN   
1800                  WRITE(clfreq,'(I19,A1)')INT(output_freq%month),'m' 
1801                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
1802              ELSE IF ( output_freq%year /= 0 ) THEN   
1803                  WRITE(clfreq,'(I19,A1)')INT(output_freq%year),'y' 
1804                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
1805              ELSE
1806                  CALL ctl_stop('error in the name of file id '//TRIM(cdid),   &
1807                     & ' attribute output_freq is undefined -> cannot replace @freq@ in '//TRIM(clname) )
1808              ENDIF
1809              clname = clname(1:idx-1)//TRIM(ADJUSTL(clfreq))//clname(idx+6:LEN_TRIM(clname))
1810              idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
1811            END DO
1812#endif
1813            idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
1814            DO WHILE ( idx /= 0 ) 
1815               cldate = iom_sdate( fjulday - rdttra(1) / rday )
1816               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+11:LEN_TRIM(clname))
1817               idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
1818            END DO
1819
1820            idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
1821            DO WHILE ( idx /= 0 ) 
1822               cldate = iom_sdate( fjulday - rdttra(1) / rday, ldfull = .TRUE. )
1823               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+15:LEN_TRIM(clname))
1824               idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
1825            END DO
1826
1827            idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
1828            DO WHILE ( idx /= 0 ) 
1829               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. )
1830               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+9:LEN_TRIM(clname))
1831               idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
1832            END DO
1833
1834            idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
1835            DO WHILE ( idx /= 0 ) 
1836               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. )
1837               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+13:LEN_TRIM(clname))
1838               idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
1839            END DO
1840
1841            IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
1842            IF( jn == 1 )   CALL iom_set_file_attr( cdid, name        = clname )
1843            IF( jn == 2 )   CALL iom_set_file_attr( cdid, name_suffix = clname )
1844
1845         ENDIF
1846
1847      END DO
1848
1849   END SUBROUTINE iom_update_file_name
1850
1851
1852   FUNCTION iom_sdate( pjday, ld24, ldfull )
1853      !!----------------------------------------------------------------------
1854      !!                     ***  ROUTINE iom_sdate  ***
1855      !!
1856      !! ** Purpose :   send back the date corresponding to the given julian day
1857      !!
1858      !!----------------------------------------------------------------------
1859      REAL(wp), INTENT(in   )           ::   pjday         ! julian day
1860      LOGICAL , INTENT(in   ), OPTIONAL ::   ld24          ! true to force 24:00 instead of 00:00
1861      LOGICAL , INTENT(in   ), OPTIONAL ::   ldfull        ! true to get the compleate date: yyyymmdd_hh:mm:ss
1862      !
1863      CHARACTER(LEN=20) ::   iom_sdate
1864      CHARACTER(LEN=50) ::   clfmt                         !  format used to write the date
1865      INTEGER           ::   iyear, imonth, iday, ihour, iminute, isec
1866      REAL(wp)          ::   zsec
1867      LOGICAL           ::   ll24, llfull
1868      !
1869      IF( PRESENT(ld24) ) THEN   ;   ll24 = ld24
1870      ELSE                       ;   ll24 = .FALSE.
1871      ENDIF
1872
1873      IF( PRESENT(ldfull) ) THEN   ;   llfull = ldfull
1874      ELSE                         ;   llfull = .FALSE.
1875      ENDIF
1876
1877      CALL ju2ymds( pjday, iyear, imonth, iday, zsec )
1878      isec = NINT(zsec)
1879
1880      IF ( ll24 .AND. isec == 0 ) THEN   ! 00:00 of the next day -> move to 24:00 of the current day
1881         CALL ju2ymds( pjday - 1., iyear, imonth, iday, zsec )
1882         isec = 86400
1883      ENDIF
1884
1885      IF( iyear < 10000 ) THEN   ;   clfmt = "i4.4,2i2.2"                ! format used to write the date
1886      ELSE                       ;   WRITE(clfmt, "('i',i1,',2i2.2')") INT(LOG10(REAL(iyear,wp))) + 1
1887      ENDIF
1888     
1889!$AGRIF_DO_NOT_TREAT     
1890! Should be fixed in the conv
1891      IF( llfull ) THEN
1892         clfmt = TRIM(clfmt)//",'_',i2.2,':',i2.2,':',i2.2"
1893         ihour   = isec / 3600
1894         isec    = MOD(isec, 3600)
1895         iminute = isec / 60
1896         isec    = MOD(isec, 60)
1897         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday, ihour, iminute, isec    ! date of the end of run
1898      ELSE
1899         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday                          ! date of the end of run
1900      ENDIF
1901!$AGRIF_END_DO_NOT_TREAT     
1902
1903   END FUNCTION iom_sdate
1904
1905#else
1906
1907
1908   SUBROUTINE iom_setkt( kt, cdname )
1909      INTEGER         , INTENT(in)::   kt 
1910      CHARACTER(LEN=*), INTENT(in) ::   cdname
1911      IF( .FALSE. )   WRITE(numout,*) kt, cdname   ! useless test to avoid compilation warnings
1912   END SUBROUTINE iom_setkt
1913
1914   SUBROUTINE iom_context_finalize( cdname )
1915      CHARACTER(LEN=*), INTENT(in) ::   cdname
1916      IF( .FALSE. )   WRITE(numout,*)  cdname   ! useless test to avoid compilation warnings
1917   END SUBROUTINE iom_context_finalize
1918
1919#endif
1920
1921   LOGICAL FUNCTION iom_use( cdname )
1922      CHARACTER(LEN=*), INTENT(in) ::   cdname
1923#if defined key_iomput
1924      iom_use = xios_field_is_active( cdname )
1925#else
1926      iom_use = .FALSE.
1927#endif
1928   END FUNCTION iom_use
1929   
1930   !!======================================================================
1931END MODULE iom
Note: See TracBrowser for help on using the repository browser.