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

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

source: branches/2013/dev_r4028_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 4345

Last change on this file since 4345 was 4345, checked in by clem, 10 years ago

clean the glob_sum diags and make scalar.nc work

  • Property svn:keywords set to Id
File size: 74.8 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 :   class_num       !  !: iceberg classes
34   USE domngb          ! ocean space and time domain
35   USE phycst          ! physical constants
36   USE dianam          ! build name of file
37   USE xios
38# endif
39   USE ioipsl, ONLY :  ju2ymds    ! for calendar
40
41   IMPLICIT NONE
42   PUBLIC   !   must be public to be able to access iom_def through iom
43   
44#if defined key_iomput
45   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.        !: iom_put flag
46#else
47   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
48#endif
49   PUBLIC iom_init, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
50   PUBLIC iom_getatt
51
52   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
53   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
54   PRIVATE iom_p1d, iom_p2d, iom_p3d
55#if defined key_iomput
56   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
57   PRIVATE set_grid, set_scalar, set_xmlatt, set_mooring, iom_update_file_name, iom_sdate
58# endif
59
60   INTERFACE iom_get
61      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
62   END INTERFACE
63   INTERFACE iom_getatt
64      MODULE PROCEDURE iom_g0d_intatt
65   END INTERFACE
66   INTERFACE iom_rstput
67      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
68   END INTERFACE
69  INTERFACE iom_put
70     MODULE PROCEDURE iom_p0d, iom_p1d, iom_p2d, iom_p3d
71  END INTERFACE
72#if defined key_iomput
73   INTERFACE iom_setkt
74      MODULE PROCEDURE xios_update_calendar
75   END INTERFACE
76# endif
77
78   !!----------------------------------------------------------------------
79   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
80   !! $Id$
81   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
82   !!----------------------------------------------------------------------
83
84CONTAINS
85
86   SUBROUTINE iom_init
87      !!----------------------------------------------------------------------
88      !!                     ***  ROUTINE   ***
89      !!
90      !! ** Purpose :   
91      !!
92      !!----------------------------------------------------------------------
93#if defined key_iomput
94      TYPE(xios_time)   :: dtime    = xios_time(0, 0, 0, 0, 0, 0)
95      CHARACTER(len=19) :: cldate 
96      CHARACTER(len=10) :: clname
97      INTEGER           ::   ji
98      !!----------------------------------------------------------------------
99
100      clname = "nemo"
101      IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
102# if defined key_mpp_mpi
103      CALL xios_context_initialize(TRIM(clname), mpi_comm_opa)
104# else
105      CALL xios_context_initialize(TRIM(clname), 0)
106# endif
107      CALL iom_swap
108
109      ! calendar parameters
110      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
111      CASE ( 1)   ;   CALL xios_set_context_attr(TRIM(clname), calendar_type= "Gregorian")
112      CASE ( 0)   ;   CALL xios_set_context_attr(TRIM(clname), calendar_type= "NoLeap")
113      CASE (30)   ;   CALL xios_set_context_attr(TRIM(clname), calendar_type= "D360")
114      END SELECT
115      WRITE(cldate,"(i4.4,'-',i2.2,'-',i2.2,' 00:00:00')") nyear,nmonth,nday 
116      CALL xios_set_context_attr(TRIM(clname), start_date=cldate )
117
118      ! horizontal grid definition
119      CALL set_scalar
120      CALL set_grid( "T", glamt, gphit ) 
121      CALL set_grid( "U", glamu, gphiu )
122      CALL set_grid( "V", glamv, gphiv )
123      CALL set_grid( "W", glamt, gphit )
124
125      ! vertical grid definition
126      CALL iom_set_axis_attr( "deptht", gdept_0 )
127      CALL iom_set_axis_attr( "depthu", gdept_0 )
128      CALL iom_set_axis_attr( "depthv", gdept_0 )
129      CALL iom_set_axis_attr( "depthw", gdepw_0 )
130# if defined key_floats
131      CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
132# endif
133      CALL iom_set_axis_attr( "icbcla", class_num )
134     
135      ! automatic definitions of some of the xml attributs
136      CALL set_xmlatt
137
138      ! end file definition
139      dtime%second = rdt
140      CALL xios_set_timestep(dtime)
141      CALL xios_close_context_definition()
142     
143      CALL xios_update_calendar(0)
144#endif
145     
146   END SUBROUTINE iom_init
147
148
149   SUBROUTINE iom_swap
150      !!---------------------------------------------------------------------
151      !!                   ***  SUBROUTINE  iom_swap  ***
152      !!
153      !! ** Purpose :  swap context between different agrif grid for xmlio_server
154      !!---------------------------------------------------------------------
155#if defined key_iomput
156      TYPE(xios_context) :: nemo_hdl
157
158     IF( TRIM(Agrif_CFixed()) == '0' ) THEN
159        CALL xios_get_handle("nemo",nemo_hdl)
160     ELSE
161        CALL xios_get_handle(TRIM(Agrif_CFixed())//"_nemo",nemo_hdl)
162     ENDIF
163     CALL xios_set_current_context(nemo_hdl)
164
165#endif
166      !
167   END SUBROUTINE iom_swap
168
169
170   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
171      !!---------------------------------------------------------------------
172      !!                   ***  SUBROUTINE  iom_open  ***
173      !!
174      !! ** Purpose :  open an input file (return 0 if not found)
175      !!---------------------------------------------------------------------
176      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
177      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
178      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
179      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
180      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90)
181      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
182      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
183
184      CHARACTER(LEN=256)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
185      CHARACTER(LEN=256)    ::   cltmpn    ! tempory name to store clname (in writting mode)
186      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
187      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
188      CHARACTER(LEN=256)    ::   clinfo    ! info character
189      LOGICAL               ::   llok      ! check the existence
190      LOGICAL               ::   llwrt     ! local definition of ldwrt
191      LOGICAL               ::   llnoov    ! local definition to read overlap
192      LOGICAL               ::   llstop    ! local definition of ldstop
193      LOGICAL               ::   lliof     ! local definition of ldiof
194      INTEGER               ::   iolib     ! library do we use to open the file
195      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
196      INTEGER               ::   iln, ils  ! lengths of character
197      INTEGER               ::   idom      ! type of domain
198      INTEGER               ::   istop     !
199      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters:
200      ! local number of points for x,y dimensions
201      ! position of first local point for x,y dimensions
202      ! position of last local point for x,y dimensions
203      ! start halo size for x,y dimensions
204      ! end halo size for x,y dimensions
205      !---------------------------------------------------------------------
206      ! Initializations and control
207      ! =============
208      kiomid = -1
209      clinfo = '                    iom_open ~~~  '
210      istop = nstop
211      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
212      ! (could be done when defining iom_file in f95 but not in f90)
213      IF( Agrif_Root() ) THEN
214         IF( iom_open_init == 0 ) THEN
215            iom_file(:)%nfid = 0
216            iom_open_init = 1
217         ENDIF
218      ENDIF
219      ! do we read or write the file?
220      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
221      ELSE                        ;   llwrt = .FALSE.
222      ENDIF
223      ! do we call ctl_stop if we try to open a non-existing file in read mode?
224      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
225      ELSE                         ;   llstop = .TRUE.
226      ENDIF
227      ! what library do we use to open the file?
228      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
229      ELSE                         ;   iolib = jpnf90
230      ENDIF
231      ! are we using interpolation on the fly?
232      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
233      ELSE                        ;   lliof = .FALSE.
234      ENDIF
235      ! do we read the overlap
236      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
237      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
238      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
239      ! =============
240      clname   = trim(cdname)
241      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
242         iln    = INDEX(clname,'/') 
243         cltmpn = clname(1:iln)
244         clname = clname(iln+1:LEN_TRIM(clname))
245         clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname)
246      ENDIF
247      ! which suffix should we use?
248      SELECT CASE (iolib)
249      CASE (jpioipsl ) ;   clsuffix = '.nc'
250      CASE (jpnf90   ) ;   clsuffix = '.nc'
251      CASE (jprstdimg) ;   clsuffix = '.dimg'
252      CASE DEFAULT     ;   clsuffix = ''
253         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
254      END SELECT
255      ! Add the suffix if needed
256      iln = LEN_TRIM(clname)
257      ils = LEN_TRIM(clsuffix)
258      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
259         &   clname = TRIM(clname)//TRIM(clsuffix)
260      cltmpn = clname   ! store this name
261      ! try to find if the file to be opened already exist
262      ! =============
263      INQUIRE( FILE = clname, EXIST = llok )
264      IF( .NOT.llok ) THEN
265         ! we try to add the cpu number to the name
266         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
267         ELSE                            ;   WRITE(clcpu,*) narea-1
268         ENDIF
269         clcpu  = TRIM(ADJUSTL(clcpu))
270         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
271         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
272         icnt = 0
273         INQUIRE( FILE = clname, EXIST = llok ) 
274         ! we try different formats for the cpu number by adding 0
275         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
276            clcpu  = "0"//trim(clcpu)
277            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
278            INQUIRE( FILE = clname, EXIST = llok )
279            icnt = icnt + 1
280         END DO
281      ENDIF
282      IF( llwrt ) THEN
283         ! check the domain definition
284! JMM + SM: ugly patch before getting the new version of lib_mpp)
285!         idom = jpdom_local_noovlap   ! default definition
286         IF( llnoov ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
287         ELSE                ;   idom = jpdom_local_full      ! default definition
288         ENDIF
289         IF( PRESENT(kdom) )   idom = kdom
290         ! create the domain informations
291         ! =============
292         SELECT CASE (idom)
293         CASE (jpdom_local_full)
294            idompar(:,1) = (/ jpi             , jpj              /)
295            idompar(:,2) = (/ nimpp           , njmpp            /)
296            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
297            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
298            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
299         CASE (jpdom_local_noextra)
300            idompar(:,1) = (/ nlci            , nlcj             /)
301            idompar(:,2) = (/ nimpp           , njmpp            /)
302            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
303            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
304            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
305         CASE (jpdom_local_noovlap)
306            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
307            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
308            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
309            idompar(:,4) = (/ 0               , 0                /)
310            idompar(:,5) = (/ 0               , 0                /)
311         CASE DEFAULT
312            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
313         END SELECT
314      ENDIF
315      ! Open the NetCDF or RSTDIMG file
316      ! =============
317      ! do we have some free file identifier?
318      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
319         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
320      ! if no file was found...
321      IF( .NOT. llok ) THEN
322         IF( .NOT. llwrt ) THEN   ! we are in read mode
323            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
324            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
325            ENDIF
326         ELSE                     ! we are in write mode so we
327            clname = cltmpn       ! get back the file name without the cpu number
328         ENDIF
329      ELSE
330         IF( llwrt .AND. .NOT. ln_clobber ) THEN   ! we stop as we want to write in a new file
331            CALL ctl_stop( TRIM(clinfo), 'We want to write in a new file but '//TRIM(clname)//' already exists...' )
332            istop = nstop + 1                      ! make sure that istop /= nstop so we don't open the file
333         ENDIF
334      ENDIF
335      IF( istop == nstop ) THEN   ! no error within this routine
336         SELECT CASE (iolib)
337         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
338         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
339         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
340         CASE DEFAULT
341            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
342         END SELECT
343      ENDIF
344      !
345   END SUBROUTINE iom_open
346
347
348   SUBROUTINE iom_close( kiomid )
349      !!--------------------------------------------------------------------
350      !!                   ***  SUBROUTINE  iom_close  ***
351      !!
352      !! ** Purpose : close an input file, or all files opened by iom
353      !!--------------------------------------------------------------------
354      INTEGER, INTENT(inout), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
355      !                                              ! return 0 when file is properly closed
356      !                                              ! No argument: all files opened by iom are closed
357
358      INTEGER ::   jf         ! dummy loop indices
359      INTEGER ::   i_s, i_e   ! temporary integer
360      CHARACTER(LEN=100)    ::   clinfo    ! info character
361      !---------------------------------------------------------------------
362      !
363      clinfo = '                    iom_close ~~~  '
364      IF( PRESENT(kiomid) ) THEN
365         i_s = kiomid
366         i_e = kiomid
367      ELSE
368         i_s = 1
369         i_e = jpmax_files
370      ENDIF
371
372      IF( i_s > 0 ) THEN
373         DO jf = i_s, i_e
374            IF( iom_file(jf)%nfid > 0 ) THEN
375               SELECT CASE (iom_file(jf)%iolib)
376               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
377               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
378               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
379               CASE DEFAULT
380                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
381               END SELECT
382               iom_file(jf)%nfid       = 0          ! free the id
383               IF( PRESENT(kiomid) )   kiomid = 0   ! return 0 as id to specify that the file was closed
384               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
385            ELSEIF( PRESENT(kiomid) ) THEN
386               WRITE(ctmp1,*) '--->',  kiomid
387               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
388            ENDIF
389         END DO
390      ENDIF
391      !   
392   END SUBROUTINE iom_close
393
394
395   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, ldstop ) 
396      !!-----------------------------------------------------------------------
397      !!                  ***  FUNCTION  iom_varid  ***
398      !!
399      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
400      !!-----------------------------------------------------------------------
401      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
402      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
403      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
404      INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
405      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
406      !
407      INTEGER                        ::   iom_varid, iiv, i_nvd
408      LOGICAL                        ::   ll_fnd
409      CHARACTER(LEN=100)             ::   clinfo                   ! info character
410      LOGICAL                        ::   llstop                   ! local definition of ldstop
411      !!-----------------------------------------------------------------------
412      iom_varid = 0                         ! default definition
413      ! do we call ctl_stop if we look for non-existing variable?
414      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
415      ELSE                         ;   llstop = .TRUE.
416      ENDIF
417      !
418      IF( kiomid > 0 ) THEN
419         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
420         IF( iom_file(kiomid)%nfid == 0 ) THEN
421            CALL ctl_stop( trim(clinfo), 'the file is not open' )
422         ELSE
423            ll_fnd  = .FALSE.
424            iiv = 0
425            !
426            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
427               iiv = iiv + 1
428               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
429            END DO
430            !
431            IF( .NOT.ll_fnd ) THEN
432               iiv = iiv + 1
433               IF( iiv <= jpmax_vars ) THEN
434                  SELECT CASE (iom_file(kiomid)%iolib)
435                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
436                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz, kndims )
437                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
438                  CASE DEFAULT   
439                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
440                  END SELECT
441               ELSE
442                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
443                        &                         'increase the parameter jpmax_vars')
444               ENDIF
445               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
446            ELSE
447               iom_varid = iiv
448               IF( PRESENT(kdimsz) ) THEN
449                  i_nvd = iom_file(kiomid)%ndims(iiv)
450                  IF( i_nvd == size(kdimsz) ) THEN
451                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
452                  ELSE
453                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
454                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
455                  ENDIF
456               ENDIF
457               IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(iiv)
458            ENDIF
459         ENDIF
460      ENDIF
461      !
462   END FUNCTION iom_varid
463
464
465   !!----------------------------------------------------------------------
466   !!                   INTERFACE iom_get
467   !!----------------------------------------------------------------------
468   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
469      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
470      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
471      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
472      !
473      INTEGER               :: idvar   ! variable id
474      !
475      IF( kiomid > 0 ) THEN
476         idvar = iom_varid( kiomid, cdvar )
477         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
478            SELECT CASE (iom_file(kiomid)%iolib)
479            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
480            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
481            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
482            CASE DEFAULT   
483               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
484            END SELECT
485         ENDIF
486      ENDIF
487   END SUBROUTINE iom_g0d
488
489   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
490      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
491      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
492      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
493      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
494      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
495      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
496      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
497      !
498      IF( kiomid > 0 ) THEN
499         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
500              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
501      ENDIF
502   END SUBROUTINE iom_g1d
503
504   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
505      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
506      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
507      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
508      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
509      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
510      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading
511      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
512      !
513      IF( kiomid > 0 ) THEN
514         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
515              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
516      ENDIF
517   END SUBROUTINE iom_g2d
518
519   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
520      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
521      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
522      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
523      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
524      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
525      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading
526      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
527      !
528      IF( kiomid > 0 ) THEN
529         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
530              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
531      ENDIF
532   END SUBROUTINE iom_g3d
533   !!----------------------------------------------------------------------
534
535   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
536         &                  pv_r1d, pv_r2d, pv_r3d,   &
537         &                  ktime , kstart, kcount  )
538      !!-----------------------------------------------------------------------
539      !!                  ***  ROUTINE  iom_get_123d  ***
540      !!
541      !! ** Purpose : read a 1D/2D/3D variable
542      !!
543      !! ** Method : read ONE record at each CALL
544      !!-----------------------------------------------------------------------
545      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
546      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
547      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
548      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
549      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
550      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
551      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
552      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis
553      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
554      !
555      LOGICAL                        ::   llnoov      ! local definition to read overlap
556      INTEGER                        ::   jl          ! loop on number of dimension
557      INTEGER                        ::   idom        ! type of domain
558      INTEGER                        ::   idvar       ! id of the variable
559      INTEGER                        ::   inbdim      ! number of dimensions of the variable
560      INTEGER                        ::   idmspc      ! number of spatial dimensions
561      INTEGER                        ::   itime       ! record number
562      INTEGER                        ::   istop       ! temporary value of nstop
563      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
564      INTEGER                        ::   ji, jj      ! loop counters
565      INTEGER                        ::   irankpv       !
566      INTEGER                        ::   ind1, ind2  ! substring index
567      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
568      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis
569      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
570      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
571      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
572      INTEGER                        ::   itmp        ! temporary integer
573      CHARACTER(LEN=256)             ::   clinfo      ! info character
574      CHARACTER(LEN=256)             ::   clname      ! file name
575      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !
576      !---------------------------------------------------------------------
577      !
578      clname = iom_file(kiomid)%name   !   esier to read
579      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
580      ! local definition of the domain ?
581      idom = kdom
582      ! do we read the overlap
583      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
584      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
585      ! check kcount and kstart optionals parameters...
586      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
587      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
588      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
589
590      ! Search for the variable in the data base (eventually actualize data)
591      istop = nstop
592      idvar = iom_varid( kiomid, cdvar )
593      !
594      IF( idvar > 0 ) THEN
595         ! to write iom_file(kiomid)%dimsz in a shorter way !
596         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
597         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
598         idmspc = inbdim                                   ! number of spatial dimensions in the file
599         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
600         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
601         !
602         ! update idom definition...
603         ! Identify the domain in case of jpdom_auto(glo/dta) definition
604         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN           
605            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
606            ELSE                               ;   idom = jpdom_data
607            ENDIF
608            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
609            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
610            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
611         ENDIF
612         ! Identify the domain in case of jpdom_local definition
613         IF( idom == jpdom_local ) THEN
614            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
615            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
616            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
617            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
618            ENDIF
619         ENDIF
620         !
621         ! check the consistency between input array and data rank in the file
622         !
623         ! initializations
624         itime = 1
625         IF( PRESENT(ktime) ) itime = ktime
626
627         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
628         WRITE(clrankpv, fmt='(i1)') irankpv
629         WRITE(cldmspc , fmt='(i1)') idmspc
630         !
631         IF(     idmspc <  irankpv ) THEN
632            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
633               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
634         ELSEIF( idmspc == irankpv ) THEN
635            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
636               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
637         ELSEIF( idmspc >  irankpv ) THEN
638               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
639                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
640                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
641                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
642                  idmspc = idmspc - 1
643               ELSE
644                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
645                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
646                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
647               ENDIF
648         ENDIF
649
650         !
651         ! definition of istart and icnt
652         !
653         icnt  (:) = 1
654         istart(:) = 1
655         istart(idmspc+1) = itime
656
657         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
658         ELSE
659            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
660            ELSE
661               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
662                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
663                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
664                  ENDIF
665                  ! we do not read the overlap                     -> we start to read at nldi, nldj
666! JMM + SM: ugly patch before getting the new version of lib_mpp)
667!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
668                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
669                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej
670! JMM + SM: ugly patch before getting the new version of lib_mpp)
671!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
672                  IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
673                  ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /)
674                  ENDIF
675                  IF( PRESENT(pv_r3d) ) THEN
676                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
677                     ELSE                            ; icnt(3) = jpk
678                     ENDIF
679                  ENDIF
680               ENDIF
681            ENDIF
682         ENDIF
683
684         ! check that istart and icnt can be used with this file
685         !-
686         DO jl = 1, jpmax_dims
687            itmp = istart(jl)+icnt(jl)-1
688            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
689               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
690               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
691               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
692            ENDIF
693         END DO
694
695         ! check that icnt matches the input array
696         !-     
697         IF( idom == jpdom_unknown ) THEN
698            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
699            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
700            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
701            ctmp1 = 'd'
702         ELSE
703            IF( irankpv == 2 ) THEN
704! JMM + SM: ugly patch before getting the new version of lib_mpp)
705!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
706               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
707               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
708               ENDIF
709            ENDIF
710            IF( irankpv == 3 ) THEN 
711! JMM + SM: ugly patch before getting the new version of lib_mpp)
712!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
713               IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
714               ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
715               ENDIF
716            ENDIF
717         ENDIF
718         
719         DO jl = 1, irankpv
720            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
721            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
722         END DO
723
724      ENDIF
725
726      ! read the data
727      !-     
728      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
729         !
730         ! find the right index of the array to be read
731! JMM + SM: ugly patch before getting the new version of lib_mpp)
732!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
733!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
734!         ENDIF
735         IF( llnoov ) THEN
736            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
737            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
738            ENDIF
739         ELSE
740            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
741            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
742            ENDIF
743         ENDIF
744     
745         SELECT CASE (iom_file(kiomid)%iolib)
746         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
747            &                                         pv_r1d, pv_r2d, pv_r3d )
748         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
749            &                                         pv_r1d, pv_r2d, pv_r3d )
750         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
751            &                                         pv_r1d, pv_r2d, pv_r3d )
752         CASE DEFAULT   
753            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
754         END SELECT
755
756         IF( istop == nstop ) THEN   ! no additional errors until this point...
757            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i4,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
758         
759            !--- overlap areas and extra hallows (mpp)
760            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
761               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
762            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
763               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
764               IF( icnt(3) == jpk ) THEN
765                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
766               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
767                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
768                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
769               ENDIF
770            ENDIF
771           
772            ! C1D case : always call lbc_lnk to replicate the central value over the whole 3X3 domain
773            IF( lk_c1d .AND. PRESENT(pv_r2d) )   CALL lbc_lnk( pv_r2d,'Z',1. )
774            IF( lk_c1d .AND. PRESENT(pv_r3d) )   CALL lbc_lnk( pv_r3d,'Z',1. )
775   
776            !--- Apply scale_factor and offset
777            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
778            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
779            IF(     PRESENT(pv_r1d) ) THEN
780               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
781               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
782            ELSEIF( PRESENT(pv_r2d) ) THEN
783!CDIR COLLAPSE
784               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
785!CDIR COLLAPSE
786               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
787            ELSEIF( PRESENT(pv_r3d) ) THEN
788!CDIR COLLAPSE
789               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
790!CDIR COLLAPSE
791               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
792            ENDIF
793            !
794         ENDIF
795         !
796      ENDIF
797      !
798   END SUBROUTINE iom_get_123d
799
800
801   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
802      !!--------------------------------------------------------------------
803      !!                   ***  SUBROUTINE iom_gettime  ***
804      !!
805      !! ** Purpose : read the time axis cdvar in the file
806      !!--------------------------------------------------------------------
807      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
808      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
809      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
810      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
811      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
812      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of
813      !
814      INTEGER, DIMENSION(1) :: kdimsz
815      INTEGER            ::   idvar    ! id of the variable
816      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
817      CHARACTER(LEN=100) ::   clinfo   ! info character
818      !---------------------------------------------------------------------
819      !
820      IF ( PRESENT(cdvar) ) THEN
821         tname = cdvar
822      ELSE
823         tname = iom_file(kiomid)%uldname
824      ENDIF
825      IF( kiomid > 0 ) THEN
826         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
827         IF ( PRESENT(kntime) ) THEN
828            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
829            kntime = kdimsz(1)
830         ELSE
831            idvar = iom_varid( kiomid, tname )
832         ENDIF
833         !
834         ptime(:) = 0. ! default definition
835         IF( idvar > 0 ) THEN
836            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
837               IF( iom_file(kiomid)%luld(idvar) ) THEN
838                  IF( iom_file(kiomid)%dimsz(1,idvar) <= size(ptime) ) THEN
839                     SELECT CASE (iom_file(kiomid)%iolib)
840                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
841                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
842                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
843                     CASE DEFAULT   
844                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
845                     END SELECT
846                  ELSE
847                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
848                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
849                  ENDIF
850               ELSE
851                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
852               ENDIF
853            ELSE
854               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
855            ENDIF
856         ELSE
857            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
858         ENDIF
859      ENDIF
860      !
861   END SUBROUTINE iom_gettime
862
863
864   !!----------------------------------------------------------------------
865   !!                   INTERFACE iom_getatt
866   !!----------------------------------------------------------------------
867   SUBROUTINE iom_g0d_intatt( kiomid, cdatt, pvar )
868      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
869      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute
870      INTEGER         , INTENT(  out)                 ::   pvar      ! read field
871      !
872      IF( kiomid > 0 ) THEN
873         IF( iom_file(kiomid)%nfid > 0 ) THEN
874            SELECT CASE (iom_file(kiomid)%iolib)
875            CASE (jpioipsl )   ;   CALL ctl_stop('iom_getatt: only nf90 available')
876            CASE (jpnf90   )   ;   CALL iom_nf90_getatt( kiomid, cdatt, pvar )
877            CASE (jprstdimg)   ;   CALL ctl_stop('iom_getatt: only nf90 available')
878            CASE DEFAULT   
879               CALL ctl_stop( 'iom_g0d_att: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
880            END SELECT
881         ENDIF
882      ENDIF
883   END SUBROUTINE iom_g0d_intatt
884
885
886   !!----------------------------------------------------------------------
887   !!                   INTERFACE iom_rstput
888   !!----------------------------------------------------------------------
889   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
890      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
891      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
892      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
893      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
894      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
895      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
896      INTEGER :: ivid   ! variable id
897      IF( kiomid > 0 ) THEN
898         IF( iom_file(kiomid)%nfid > 0 ) THEN
899            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
900            SELECT CASE (iom_file(kiomid)%iolib)
901            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
902            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
903            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
904            CASE DEFAULT     
905               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
906            END SELECT
907         ENDIF
908      ENDIF
909   END SUBROUTINE iom_rp0d
910
911   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
912      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
913      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
914      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
915      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
916      REAL(wp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
917      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
918      INTEGER :: ivid   ! variable id
919      IF( kiomid > 0 ) THEN
920         IF( iom_file(kiomid)%nfid > 0 ) THEN
921            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
922            SELECT CASE (iom_file(kiomid)%iolib)
923            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
924            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
925            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
926            CASE DEFAULT     
927               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
928            END SELECT
929         ENDIF
930      ENDIF
931   END SUBROUTINE iom_rp1d
932
933   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
934      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
935      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
936      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
937      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
938      REAL(wp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
939      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
940      INTEGER :: ivid   ! variable id
941      IF( kiomid > 0 ) THEN
942         IF( iom_file(kiomid)%nfid > 0 ) THEN
943            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
944            SELECT CASE (iom_file(kiomid)%iolib)
945            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
946            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
947            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
948            CASE DEFAULT     
949               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
950            END SELECT
951         ENDIF
952      ENDIF
953   END SUBROUTINE iom_rp2d
954
955   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
956      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
957      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
958      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
959      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
960      REAL(wp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
961      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
962      INTEGER :: ivid   ! variable id
963      IF( kiomid > 0 ) THEN
964         IF( iom_file(kiomid)%nfid > 0 ) THEN
965            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
966            SELECT CASE (iom_file(kiomid)%iolib)
967            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
968            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
969            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
970            CASE DEFAULT     
971               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
972            END SELECT
973         ENDIF
974      ENDIF
975   END SUBROUTINE iom_rp3d
976
977
978   !!----------------------------------------------------------------------
979   !!                   INTERFACE iom_put
980   !!----------------------------------------------------------------------
981   SUBROUTINE iom_p0d( cdname, pfield0d )
982      CHARACTER(LEN=*), INTENT(in) ::   cdname
983      REAL(wp)        , INTENT(in) ::   pfield0d
984      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
985#if defined key_iomput
986      zz(:,:)=pfield0d
987      CALL xios_send_field(cdname, zz)
988      !CALL xios_send_field(cdname, (/pfield0d/))
989#else
990      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
991#endif
992   END SUBROUTINE iom_p0d
993
994   SUBROUTINE iom_p1d( cdname, pfield1d )
995      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
996      REAL(wp),     DIMENSION(:), INTENT(in) ::   pfield1d
997#if defined key_iomput
998      CALL xios_send_field( cdname, RESHAPE( (/pfield1d/), (/1,1,SIZE(pfield1d)/) ) )
999#else
1000      IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
1001#endif
1002   END SUBROUTINE iom_p1d
1003
1004   SUBROUTINE iom_p2d( cdname, pfield2d )
1005      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
1006      REAL(wp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
1007#if defined key_iomput
1008      CALL xios_send_field(cdname, pfield2d)
1009#else
1010      IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
1011#endif
1012   END SUBROUTINE iom_p2d
1013
1014   SUBROUTINE iom_p3d( cdname, pfield3d )
1015      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
1016      REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
1017#if defined key_iomput
1018      CALL xios_send_field(cdname, pfield3d)
1019#else
1020      IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
1021#endif
1022   END SUBROUTINE iom_p3d
1023   !!----------------------------------------------------------------------
1024
1025#if defined key_iomput
1026
1027   SUBROUTINE iom_set_domain_attr( cdid, ni_glo, nj_glo, ibegin, jbegin, ni, nj, zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj,   &
1028      &                                    data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue, mask )
1029      CHARACTER(LEN=*)                 , INTENT(in) ::   cdid
1030      INTEGER                , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
1031      INTEGER                , OPTIONAL, INTENT(in) ::   data_dim, data_ibegin, data_ni, data_jbegin, data_nj
1032      INTEGER                , OPTIONAL, INTENT(in) ::   zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj
1033      REAL(wp), DIMENSION(:) , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
1034      LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(in) ::   mask
1035
1036      IF ( xios_is_valid_domain     (cdid) ) THEN
1037         CALL xios_set_domain_attr     ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
1038            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
1039            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
1040            &    lonvalue=lonvalue, latvalue=latvalue,mask=mask )
1041      ENDIF
1042
1043      IF ( xios_is_valid_domaingroup(cdid) ) THEN
1044         CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
1045            &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
1046            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
1047            &    lonvalue=lonvalue, latvalue=latvalue,mask=mask )
1048      ENDIF
1049      CALL xios_solve_inheritance()
1050
1051   END SUBROUTINE iom_set_domain_attr
1052
1053
1054   SUBROUTINE iom_set_axis_attr( cdid, paxis )
1055      CHARACTER(LEN=*)      , INTENT(in) ::   cdid
1056      REAL(wp), DIMENSION(:), INTENT(in) ::   paxis
1057      IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, size=size(paxis),value=paxis )
1058      IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, size=size(paxis),value=paxis )
1059      CALL xios_solve_inheritance()
1060   END SUBROUTINE iom_set_axis_attr
1061
1062
1063   SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset )
1064      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
1065      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   freq_op
1066      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   freq_offset
1067      IF ( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
1068      IF ( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr( cdid, freq_op=freq_op, freq_offset=freq_offset )
1069      CALL xios_solve_inheritance()
1070   END SUBROUTINE iom_set_field_attr
1071
1072
1073   SUBROUTINE iom_set_file_attr( cdid, name, name_suffix )
1074      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
1075      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   name, name_suffix
1076      IF ( xios_is_valid_file     (cdid) )   CALL xios_set_file_attr     ( cdid, name=name, name_suffix=name_suffix )
1077      IF ( xios_is_valid_filegroup(cdid) )   CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix )
1078      CALL xios_solve_inheritance()
1079   END SUBROUTINE iom_set_file_attr
1080
1081
1082   SUBROUTINE iom_get_file_attr( cdid, name, name_suffix, output_freq )
1083      CHARACTER(LEN=*)          , INTENT(in ) ::   cdid
1084      CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::   name, name_suffix, output_freq
1085      LOGICAL                                 ::   llexist1,llexist2,llexist3
1086      !---------------------------------------------------------------------
1087      IF( PRESENT( name        ) )   name = ''          ! default values
1088      IF( PRESENT( name_suffix ) )   name_suffix = ''
1089      IF( PRESENT( output_freq ) )   output_freq = ''
1090      IF ( xios_is_valid_file     (cdid) ) THEN
1091         CALL xios_solve_inheritance()
1092         CALL xios_is_defined_file_attr     ( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
1093         IF(llexist1)   CALL xios_get_file_attr     ( cdid, name = name )
1094         IF(llexist2)   CALL xios_get_file_attr     ( cdid, name_suffix = name_suffix )
1095         IF(llexist3)   CALL xios_get_file_attr     ( cdid, output_freq = output_freq )
1096      ENDIF
1097      IF ( xios_is_valid_filegroup(cdid) ) THEN
1098         CALL xios_solve_inheritance()
1099         CALL xios_is_defined_filegroup_attr( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
1100         IF(llexist1)   CALL xios_get_filegroup_attr( cdid, name = name )
1101         IF(llexist2)   CALL xios_get_filegroup_attr( cdid, name_suffix = name_suffix )
1102         IF(llexist3)   CALL xios_get_filegroup_attr( cdid, output_freq = output_freq )
1103      ENDIF
1104   END SUBROUTINE iom_get_file_attr
1105
1106
1107   SUBROUTINE iom_set_grid_attr( cdid, mask )
1108      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
1109      LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) ::   mask
1110      IF ( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask=mask )
1111      IF ( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask=mask )
1112      CALL xios_solve_inheritance()
1113   END SUBROUTINE iom_set_grid_attr
1114
1115
1116   SUBROUTINE set_grid( cdgrd, plon, plat )
1117      !!----------------------------------------------------------------------
1118      !!                     ***  ROUTINE set_grid  ***
1119      !!
1120      !! ** Purpose :   define horizontal grids
1121      !!
1122      !!----------------------------------------------------------------------
1123      CHARACTER(LEN=1)            , INTENT(in) ::   cdgrd
1124      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
1125      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
1126      !
1127      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask
1128      INTEGER  :: ni,nj
1129     
1130      ni=nlei-nldi+1 ; nj=nlej-nldj+1
1131
1132      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)
1133      CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
1134      CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)),   &
1135         &                                     latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) 
1136
1137      IF ( ln_mskland ) THEN
1138         ! mask land points, keep values on coast line -> specific mask for U, V and W points
1139         SELECT CASE ( cdgrd )
1140         CASE('T')   ;   zmask(:,:,:)       = tmask(:,:,:)
1141         CASE('U')   ;   zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)   ;   CALL lbc_lnk( zmask, 'U', 1. )
1142         CASE('V')   ;   zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpi,:)   ;   CALL lbc_lnk( zmask, 'V', 1. )
1143         CASE('W')   ;   zmask(:,:,2:jpk  ) = tmask(:,:,1:jpkm1) + tmask(:,:,2:jpk)   ;   zmask(:,:,1) = tmask(:,:,1)
1144         END SELECT
1145         !
1146         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni,nj    /)) /= 0. )
1147         CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. )
1148      ENDIF
1149     
1150   END SUBROUTINE set_grid
1151
1152
1153   SUBROUTINE set_scalar
1154      !!----------------------------------------------------------------------
1155      !!                     ***  ROUTINE set_scalar  ***
1156      !!
1157      !! ** Purpose :   define fake grids for scalar point
1158      !!
1159      !!----------------------------------------------------------------------
1160      REAL(wp), DIMENSION(1) ::   zz = 1.
1161      !!----------------------------------------------------------------------
1162      CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea, jbegin=1, ni=1, nj=1)
1163      CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
1164      zz=REAL(narea,wp)
1165      CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz)
1166
1167   END SUBROUTINE set_scalar
1168
1169
1170   SUBROUTINE set_xmlatt
1171      !!----------------------------------------------------------------------
1172      !!                     ***  ROUTINE set_xmlatt  ***
1173      !!
1174      !! ** Purpose :   automatic definitions of some of the xml attributs...
1175      !!
1176      !!----------------------------------------------------------------------
1177      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
1178      CHARACTER(len=256)             ::   clsuff                   ! suffix name
1179      CHARACTER(len=1)               ::   cl1                      ! 1 character
1180      CHARACTER(len=2)               ::   cl2                      ! 1 character
1181      INTEGER                        ::   ji, jg                   ! loop counters
1182      INTEGER                        ::   ix, iy                   ! i-,j- index
1183      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
1184      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
1185      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
1186      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
1187      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
1188      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
1189      !!----------------------------------------------------------------------
1190      !
1191      ! frequency of the call of iom_put (attribut: freq_op)
1192      WRITE(cl1,'(i1)')        1   ;   CALL iom_set_field_attr('field_definition', freq_op = cl1//'ts', freq_offset='0ts')
1193      WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC'             , freq_op = cl1//'ts', freq_offset='0ts')
1194      WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC_scalar'      , freq_op = cl1//'ts', freq_offset='0ts')
1195      WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('ptrc_T'          , freq_op = cl1//'ts', freq_offset='0ts')
1196      WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('diad_T'          , freq_op = cl1//'ts', freq_offset='0ts')
1197       
1198      ! output file names (attribut: name)
1199      DO ji = 1, 9
1200         WRITE(cl1,'(i1)') ji 
1201         CALL iom_update_file_name('file'//cl1)
1202      END DO
1203      DO ji = 1, 99
1204         WRITE(cl2,'(i2.2)') ji 
1205         CALL iom_update_file_name('file'//cl2)
1206      END DO
1207
1208      ! Zooms...
1209      clgrd = (/ 'T', 'U', 'W' /) 
1210      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
1211         cl1 = clgrd(jg)
1212         ! Equatorial section (attributs: jbegin, ni, name_suffix)
1213         CALL dom_ngb( 0., 0., ix, iy, cl1 )
1214         CALL iom_set_domain_attr ('Eq'//cl1, zoom_jbegin=iy, zoom_ni=jpiglo)
1215         CALL iom_get_file_attr   ('Eq'//cl1, name_suffix = clsuff             )
1216         CALL iom_set_file_attr   ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq')
1217         CALL iom_update_file_name('Eq'//cl1)
1218      END DO
1219      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
1220      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
1221      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
1222      CALL set_mooring( zlontao, zlattao )
1223      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
1224      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
1225      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
1226      CALL set_mooring( zlonrama, zlatrama )
1227      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
1228      zlonpira = (/ -38.0, -23.0, -10.0 /)
1229      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
1230      CALL set_mooring( zlonpira, zlatpira )
1231     
1232   END SUBROUTINE set_xmlatt
1233
1234
1235   SUBROUTINE set_mooring( plon, plat)
1236      !!----------------------------------------------------------------------
1237      !!                     ***  ROUTINE set_mooring  ***
1238      !!
1239      !! ** Purpose :   automatic definitions of moorings xml attributs...
1240      !!
1241      !!----------------------------------------------------------------------
1242      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
1243      !
1244!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
1245      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
1246      CHARACTER(len=256)            ::   clname                   ! file name
1247      CHARACTER(len=256)            ::   clsuff                   ! suffix name
1248      CHARACTER(len=1)              ::   cl1                      ! 1 character
1249      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
1250      INTEGER                       ::   ji, jj, jg               ! loop counters
1251      INTEGER                       ::   ix, iy                   ! i-,j- index
1252      REAL(wp)                      ::   zlon, zlat
1253      !!----------------------------------------------------------------------
1254      DO jg = 1, SIZE(clgrd)
1255         cl1 = clgrd(jg)
1256         DO ji = 1, SIZE(plon)
1257            DO jj = 1, SIZE(plat)
1258               zlon = plon(ji)
1259               zlat = plat(jj)
1260               ! modifications for RAMA moorings
1261               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
1262               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
1263               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
1264               ! modifications for PIRATA moorings
1265               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
1266               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
1267               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
1268               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
1269               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
1270               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
1271               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
1272               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
1273               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
1274               IF( zlon >= 0. ) THEN 
1275                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
1276                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
1277                  ENDIF
1278               ELSE             
1279                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
1280                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
1281                  ENDIF
1282               ENDIF
1283               IF( zlat >= 0. ) THEN 
1284                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
1285                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
1286                  ENDIF
1287               ELSE             
1288                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
1289                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
1290                  ENDIF
1291               ENDIF
1292               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
1293               CALL iom_set_domain_attr (TRIM(clname)//cl1, zoom_ibegin= ix, zoom_jbegin= iy)
1294               CALL iom_get_file_attr   (TRIM(clname)//cl1, name_suffix = clsuff                         )
1295               CALL iom_set_file_attr   (TRIM(clname)//cl1, name_suffix = TRIM(clsuff)//'_'//TRIM(clname))
1296               CALL iom_update_file_name(TRIM(clname)//cl1)
1297            END DO
1298         END DO
1299      END DO
1300     
1301   END SUBROUTINE set_mooring
1302
1303   
1304   SUBROUTINE iom_update_file_name( cdid )
1305      !!----------------------------------------------------------------------
1306      !!                     ***  ROUTINE iom_update_file_name  ***
1307      !!
1308      !! ** Purpose :   
1309      !!
1310      !!----------------------------------------------------------------------
1311      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
1312      !
1313      CHARACTER(LEN=256) ::   clname
1314      CHARACTER(LEN=20)  ::   clfreq
1315      CHARACTER(LEN=20)  ::   cldate
1316      INTEGER            ::   idx
1317      INTEGER            ::   jn
1318      INTEGER            ::   itrlen
1319      INTEGER            ::   iyear, imonth, iday, isec
1320      REAL(wp)           ::   zsec
1321      LOGICAL            ::   llexist
1322      !!----------------------------------------------------------------------
1323
1324      DO jn = 1,2
1325
1326         IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = clfreq )
1327         IF( jn == 2 )   CALL iom_get_file_attr( cdid, name_suffix = clname )
1328
1329         IF ( TRIM(clname) /= '' ) THEN
1330
1331            idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
1332            DO WHILE ( idx /= 0 ) 
1333               clname = clname(1:idx-1)//TRIM(cexper)//clname(idx+9:LEN_TRIM(clname))
1334               idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
1335            END DO
1336
1337            idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
1338            DO WHILE ( idx /= 0 ) 
1339               IF ( TRIM(clfreq) /= '' ) THEN
1340                  itrlen = LEN_TRIM(clfreq)
1341                  IF ( clfreq(itrlen-1:itrlen) == 'mo' ) clfreq = clfreq(1:itrlen-1)
1342                  clname = clname(1:idx-1)//TRIM(clfreq)//clname(idx+6:LEN_TRIM(clname))
1343               ELSE
1344                  CALL ctl_stop('error in the name of file id '//TRIM(cdid),   &
1345                     & ' attribute output_freq is undefined -> cannot replace @freq@ in '//TRIM(clname) )
1346               ENDIF
1347               idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
1348            END DO
1349
1350            idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
1351            DO WHILE ( idx /= 0 ) 
1352               cldate = iom_sdate( fjulday - rdttra(1) / rday )
1353               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+11:LEN_TRIM(clname))
1354               idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
1355            END DO
1356
1357            idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
1358            DO WHILE ( idx /= 0 ) 
1359               cldate = iom_sdate( fjulday - rdttra(1) / rday, ldfull = .TRUE. )
1360               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+15:LEN_TRIM(clname))
1361               idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
1362            END DO
1363
1364            idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
1365            DO WHILE ( idx /= 0 ) 
1366               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. )
1367               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+9:LEN_TRIM(clname))
1368               idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
1369            END DO
1370
1371            idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
1372            DO WHILE ( idx /= 0 ) 
1373               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. )
1374               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+13:LEN_TRIM(clname))
1375               idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
1376            END DO
1377
1378            IF( jn == 1 )   CALL iom_set_file_attr( cdid, name        = clname )
1379            IF( jn == 2 )   CALL iom_set_file_attr( cdid, name_suffix = clname )
1380
1381         ENDIF
1382
1383      END DO
1384
1385   END SUBROUTINE iom_update_file_name
1386
1387
1388   FUNCTION iom_sdate( pjday, ld24, ldfull )
1389      !!----------------------------------------------------------------------
1390      !!                     ***  ROUTINE iom_sdate  ***
1391      !!
1392      !! ** Purpose :   send back the date corresponding to the given julian day
1393      !!
1394      !!----------------------------------------------------------------------
1395      REAL(wp), INTENT(in   )           ::   pjday         ! julian day
1396      LOGICAL , INTENT(in   ), OPTIONAL ::   ld24          ! true to force 24:00 instead of 00:00
1397      LOGICAL , INTENT(in   ), OPTIONAL ::   ldfull        ! true to get the compleate date: yyyymmdd_hh:mm:ss
1398      !
1399      CHARACTER(LEN=20) ::   iom_sdate
1400      CHARACTER(LEN=50) ::   clfmt                         !  format used to write the date
1401      INTEGER           ::   iyear, imonth, iday, ihour, iminute, isec
1402      REAL(wp)          ::   zsec
1403      LOGICAL           ::   ll24, llfull
1404      !
1405      IF( PRESENT(ld24) ) THEN   ;   ll24 = ld24
1406      ELSE                       ;   ll24 = .FALSE.
1407      ENDIF
1408
1409      IF( PRESENT(ldfull) ) THEN   ;   llfull = ldfull
1410      ELSE                         ;   llfull = .FALSE.
1411      ENDIF
1412
1413      CALL ju2ymds( pjday, iyear, imonth, iday, zsec )
1414      isec = NINT(zsec)
1415
1416      IF ( ll24 .AND. isec == 0 ) THEN   ! 00:00 of the next day -> move to 24:00 of the current day
1417         CALL ju2ymds( pjday - 1., iyear, imonth, iday, zsec )
1418         isec = 86400
1419      ENDIF
1420
1421      IF( iyear < 10000 ) THEN   ;   clfmt = "i4.4,2i2.2"                ! format used to write the date
1422      ELSE                       ;   WRITE(clfmt, "('i',i1,',2i2.2')") INT(LOG10(REAL(iyear,wp))) + 1
1423      ENDIF
1424     
1425      IF( llfull ) THEN
1426         clfmt = TRIM(clfmt)//",'_',i2.2,':',i2.2,':',i2.2"
1427         ihour   = isec / 3600
1428         isec    = MOD(isec, 3600)
1429         iminute = isec / 60
1430         isec    = MOD(isec, 60)
1431         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday, ihour, iminute, isec    ! date of the end of run
1432      ELSE
1433         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday                          ! date of the end of run
1434      ENDIF
1435
1436   END FUNCTION iom_sdate
1437
1438#else
1439
1440   SUBROUTINE iom_setkt( kt )
1441      INTEGER, INTENT(in   )::   kt 
1442      IF( .FALSE. )   WRITE(numout,*) kt   ! useless test to avoid compilation warnings
1443   END SUBROUTINE iom_setkt
1444
1445#endif
1446   
1447   !!======================================================================
1448END MODULE iom
Note: See TracBrowser for help on using the repository browser.