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

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

source: branches/UKMO/dev_r6436_linkOasisNoKeys/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 6877

Last change on this file since 6877 was 6877, checked in by stephenhaddad, 8 years ago

crum #160: Update to ensure that NEMO treats xios1.0 and xios2.0 the same when sending the bounds.

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