source: CONFIG/UNIFORM/v6/IPSLCM5A2CHT.2/SOURCES/NEMO/PALEO/iom.F90 @ 6035

Last change on this file since 6035 was 6035, checked in by acosce, 2 years ago

in IPSLCM5A2CHT configuration :

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