New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
iom.F90 in branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

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

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

phaze NEMO routines in CRS branch with nemo_v3_6_STABLE branch at rev 7213 (09-09-2016) (merge -r 5519:7213 )

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