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 trunk/NEMO/OPA_SRC/IOM – NEMO

source: trunk/NEMO/OPA_SRC/IOM/iom.F90 @ 1792

Last change on this file since 1792 was 1792, checked in by rblod, 14 years ago

Add fake agrif_root function, see ticket #628

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 60.1 KB
Line 
1MODULE iom
2   !!=====================================================================
3   !!                    ***  MODULE  iom ***
4   !! Input/Output manager :  Library to read input files
5   !!====================================================================
6   !! History :  9.0  ! 05 12  (J. Belier) Original code
7   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
8   !!             "   ! 07 07  (D. Storkey) Changes to iom_gettime
9   !!--------------------------------------------------------------------
10   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
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 in_out_manager  ! I/O manager
21   USE dom_oce         ! ocean space and time domain
22   USE lbclnk          ! lateal boundary condition / mpp exchanges
23   USE iom_def         ! iom variables definitions
24   USE iom_ioipsl      ! NetCDF format with IOIPSL library
25   USE iom_nf90        ! NetCDF format with native NetCDF library
26   USE iom_rstdimg     ! restarts access direct format "dimg" style...
27
28#if defined key_iomput
29   USE sbc_oce, ONLY :   nn_fsbc         ! ocean space and time domain
30   USE domngb          ! ocean space and time domain
31   USE phycst          ! physical constants
32   USE dianam          ! build name of file
33   USE mod_event_client
34   USE mod_attribut
35# endif
36
37   IMPLICIT NONE
38   PUBLIC   !   must be public to be able to access iom_def through iom
39   
40#if defined key_iomput
41   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.        !: iom_put flag
42#else
43   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
44#endif
45   PUBLIC iom_init, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
46
47   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
48   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
49   PRIVATE iom_p2d, iom_p3d
50#if defined key_iomput
51   PRIVATE set_grid
52# endif
53
54   INTERFACE iom_get
55      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
56   END INTERFACE
57   INTERFACE iom_rstput
58      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
59   END INTERFACE
60  INTERFACE iom_put
61     MODULE PROCEDURE iom_p0d, iom_p2d, iom_p3d
62  END INTERFACE
63#if defined key_iomput
64   INTERFACE iom_setkt
65      MODULE PROCEDURE event__set_timestep
66   END INTERFACE
67# endif
68
69   !!----------------------------------------------------------------------
70   !!  OPA 9.0 , LOCEAN-IPSL (2006)
71   !! $Id$
72   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
73   !!----------------------------------------------------------------------
74
75CONTAINS
76
77   SUBROUTINE iom_init
78      !!----------------------------------------------------------------------
79      !!                     ***  ROUTINE   ***
80      !!
81      !! ** Purpose :   
82      !!
83      !!----------------------------------------------------------------------
84#if defined key_iomput
85      REAL(wp) ::   ztmp
86      !!----------------------------------------------------------------------
87      ! read the xml file
88      CALL event__parse_xml_file( 'iodef.xml' )   ! <- to get from the nameliste (namrun)...
89
90      ! calendar parameters
91      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
92      CASE ( 1)   ;   CALL event__set_calendar('gregorian')
93      CASE ( 0)   ;   CALL event__set_calendar('noleap'   )
94      CASE (30)   ;   CALL event__set_calendar('360d'     )
95      END SELECT
96      ztmp = fjulday - adatrj
97      IF( ABS(ztmp  - REAL(NINT(ztmp),wp)) < 0.1 / rday )   ztmp = REAL(NINT(ztmp),wp)   ! avoid truncation error
98      CALL event__set_time_parameters( nit000 - 1, ztmp, rdt )
99
100      ! horizontal grid definition
101      CALL set_scalar
102      CALL set_grid( "grid_T", glamt, gphit )
103      CALL set_grid( "grid_U", glamu, gphiu )
104      CALL set_grid( "grid_V", glamv, gphiv )
105      CALL set_grid( "grid_W", glamt, gphit )
106
107      ! vertical grid definition
108      CALL event__set_vert_axis( "deptht", gdept_0 )
109      CALL event__set_vert_axis( "depthu", gdept_0 )
110      CALL event__set_vert_axis( "depthv", gdept_0 )
111      CALL event__set_vert_axis( "depthw", gdepw_0 )
112     
113      ! automatic definitions of some of the xml attributs
114      CALL set_xmlatt
115
116      ! end file definition
117      CALL event__close_io_definition
118#endif
119
120   END SUBROUTINE iom_init
121
122
123   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
124      !!---------------------------------------------------------------------
125      !!                   ***  SUBROUTINE  iom_open  ***
126      !!
127      !! ** Purpose :  open an input file (return 0 if not found)
128      !!---------------------------------------------------------------------
129      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
130      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
131      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
132      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
133      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90)
134      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
135      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
136
137      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
138      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
139      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
140      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
141      CHARACTER(LEN=100)    ::   clinfo    ! info character
142      LOGICAL               ::   llok      ! check the existence
143      LOGICAL               ::   llwrt     ! local definition of ldwrt
144      LOGICAL               ::   llnoov    ! local definition to read overlap
145      LOGICAL               ::   llstop    ! local definition of ldstop
146      LOGICAL               ::   lliof     ! local definition of ldiof
147      INTEGER               ::   iolib     ! library do we use to open the file
148      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
149      INTEGER               ::   iln, ils  ! lengths of character
150      INTEGER               ::   idom      ! type of domain
151      INTEGER               ::   istop     !
152      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters:
153      ! local number of points for x,y dimensions
154      ! position of first local point for x,y dimensions
155      ! position of last local point for x,y dimensions
156      ! start halo size for x,y dimensions
157      ! end halo size for x,y dimensions
158      !---------------------------------------------------------------------
159      ! Initializations and control
160      ! =============
161      kiomid = -1
162      clinfo = '                    iom_open ~~~  '
163      istop = nstop
164      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
165      ! (could be done when defining iom_file in f95 but not in f90)
166      IF( Agrif_Root() ) THEN
167         IF( iom_open_init == 0 ) THEN
168            iom_file(:)%nfid = 0
169            iom_open_init = 1
170         ENDIF
171      ENDIF
172      ! do we read or write the file?
173      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
174      ELSE                        ;   llwrt = .FALSE.
175      ENDIF
176      ! do we call ctl_stop if we try to open a non-existing file in read mode?
177      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
178      ELSE                         ;   llstop = .TRUE.
179      ENDIF
180      ! what library do we use to open the file?
181      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
182      ELSE                         ;   iolib = jpnf90
183      ENDIF
184      ! are we using interpolation on the fly?
185      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
186      ELSE                        ;   lliof = .FALSE.
187      ENDIF
188      ! do we read the overlap
189      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
190      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
191      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
192      ! =============
193      clname   = trim(cdname)
194      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
195         iln    = INDEX(clname,'/') 
196         cltmpn = clname(1:iln)
197         clname = clname(iln+1:LEN_TRIM(clname))
198         clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname)
199      ENDIF
200      ! which suffix should we use?
201      SELECT CASE (iolib)
202      CASE (jpioipsl ) ;   clsuffix = '.nc'
203      CASE (jpnf90   ) ;   clsuffix = '.nc'
204      CASE (jprstdimg) ;   clsuffix = '.dimg'
205      CASE DEFAULT     ;   clsuffix = ''
206         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
207      END SELECT
208      ! Add the suffix if needed
209      iln = LEN_TRIM(clname)
210      ils = LEN_TRIM(clsuffix)
211      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
212         &   clname = TRIM(clname)//TRIM(clsuffix)
213      cltmpn = clname   ! store this name
214      ! try to find if the file to be opened already exist
215      ! =============
216      INQUIRE( FILE = clname, EXIST = llok )
217      IF( .NOT.llok ) THEN
218         ! we try to add the cpu number to the name
219         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
220         ELSE                            ;   WRITE(clcpu,*) narea-1
221         ENDIF
222         clcpu  = TRIM(ADJUSTL(clcpu))
223         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
224         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
225         icnt = 0
226         INQUIRE( FILE = clname, EXIST = llok ) 
227         ! we try different formats for the cpu number by adding 0
228         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
229            clcpu  = "0"//trim(clcpu)
230            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
231            INQUIRE( FILE = clname, EXIST = llok )
232            icnt = icnt + 1
233         END DO
234      ENDIF
235      IF( llwrt ) THEN
236         ! check the domain definition
237! JMM + SM: ugly patch before getting the new version of lib_mpp)
238!         idom = jpdom_local_noovlap   ! default definition
239         IF( llnoov ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
240         ELSE                ;   idom = jpdom_local_full      ! default definition
241         ENDIF
242         IF( PRESENT(kdom) )   idom = kdom
243         ! create the domain informations
244         ! =============
245         SELECT CASE (idom)
246         CASE (jpdom_local_full)
247            idompar(:,1) = (/ jpi             , jpj              /)
248            idompar(:,2) = (/ nimpp           , njmpp            /)
249            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
250            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
251            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
252         CASE (jpdom_local_noextra)
253            idompar(:,1) = (/ nlci            , nlcj             /)
254            idompar(:,2) = (/ nimpp           , njmpp            /)
255            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
256            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
257            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
258         CASE (jpdom_local_noovlap)
259            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
260            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
261            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
262            idompar(:,4) = (/ 0               , 0                /)
263            idompar(:,5) = (/ 0               , 0                /)
264         CASE DEFAULT
265            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
266         END SELECT
267      ENDIF
268      ! Open the NetCDF or RSTDIMG file
269      ! =============
270      ! do we have some free file identifier?
271      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
272         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
273      ! if no file was found...
274      IF( .NOT. llok ) THEN
275         IF( .NOT. llwrt ) THEN   ! we are in read mode
276            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
277            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
278            ENDIF
279         ELSE                     ! we are in write mode so we
280            clname = cltmpn       ! get back the file name without the cpu number
281         ENDIF
282      ENDIF
283      IF( istop == nstop ) THEN   ! no error within this routine
284         SELECT CASE (iolib)
285         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
286         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
287         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
288         CASE DEFAULT
289            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
290         END SELECT
291      ENDIF
292      !
293   END SUBROUTINE iom_open
294
295
296   SUBROUTINE iom_close( kiomid )
297      !!--------------------------------------------------------------------
298      !!                   ***  SUBROUTINE  iom_close  ***
299      !!
300      !! ** Purpose : close an input file, or all files opened by iom
301      !!--------------------------------------------------------------------
302      INTEGER, INTENT(inout), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
303      !                                              ! return 0 when file is properly closed
304      !                                              ! No argument: all files opened by iom are closed
305
306      INTEGER ::   jf         ! dummy loop indices
307      INTEGER ::   i_s, i_e   ! temporary integer
308      CHARACTER(LEN=100)    ::   clinfo    ! info character
309      !---------------------------------------------------------------------
310      !
311      clinfo = '                    iom_close ~~~  '
312      IF( PRESENT(kiomid) ) THEN
313         i_s = kiomid
314         i_e = kiomid
315      ELSE
316         i_s = 1
317         i_e = jpmax_files
318#if defined key_iomput
319         CALL event__stop_ioserver
320#endif
321      ENDIF
322
323      IF( i_s > 0 ) THEN
324         DO jf = i_s, i_e
325            IF( iom_file(jf)%nfid > 0 ) THEN
326               SELECT CASE (iom_file(jf)%iolib)
327               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
328               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
329               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
330               CASE DEFAULT
331                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
332               END SELECT
333               iom_file(jf)%nfid       = 0          ! free the id
334               IF( PRESENT(kiomid) )   kiomid = 0   ! return 0 as id to specify that the file was closed
335               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
336            ELSEIF( PRESENT(kiomid) ) THEN
337               WRITE(ctmp1,*) '--->',  kiomid
338               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
339            ENDIF
340         END DO
341      ENDIF
342      !   
343   END SUBROUTINE iom_close
344
345
346   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop ) 
347      !!-----------------------------------------------------------------------
348      !!                  ***  FUNCTION  iom_varid  ***
349      !!
350      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
351      !!-----------------------------------------------------------------------
352      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
353      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
354      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
355      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
356      !
357      INTEGER                        ::   iom_varid, iiv, i_nvd
358      LOGICAL                        ::   ll_fnd
359      CHARACTER(LEN=100)             ::   clinfo                   ! info character
360      LOGICAL                        ::   llstop                   ! local definition of ldstop
361      !!-----------------------------------------------------------------------
362      iom_varid = 0                         ! default definition
363      ! do we call ctl_stop if we look for non-existing variable?
364      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
365      ELSE                         ;   llstop = .TRUE.
366      ENDIF
367      !
368      IF( kiomid > 0 ) THEN
369         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
370         IF( iom_file(kiomid)%nfid == 0 ) THEN
371            CALL ctl_stop( trim(clinfo), 'the file is not open' )
372         ELSE
373            ll_fnd  = .FALSE.
374            iiv = 0
375            !
376            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
377               iiv = iiv + 1
378               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
379            END DO
380            !
381            IF( .NOT.ll_fnd ) THEN
382               iiv = iiv + 1
383               IF( iiv <= jpmax_vars ) THEN
384                  SELECT CASE (iom_file(kiomid)%iolib)
385                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
386                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
387                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
388                  CASE DEFAULT   
389                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
390                  END SELECT
391               ELSE
392                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
393                        &                         'increase the parameter jpmax_vars')
394               ENDIF
395               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
396            ELSE
397               iom_varid = iiv
398               IF( PRESENT(kdimsz) ) THEN
399                  i_nvd = iom_file(kiomid)%ndims(iiv)
400                  IF( i_nvd == size(kdimsz) ) THEN
401                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
402                  ELSE
403                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
404                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
405                  ENDIF
406               ENDIF
407            ENDIF
408         ENDIF
409      ENDIF
410      !
411   END FUNCTION iom_varid
412
413
414   !!----------------------------------------------------------------------
415   !!                   INTERFACE iom_get
416   !!----------------------------------------------------------------------
417   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
418      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
419      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
420      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
421      !
422      INTEGER               :: idvar   ! variable id
423      !
424      IF( kiomid > 0 ) THEN
425         idvar = iom_varid( kiomid, cdvar )
426         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
427            SELECT CASE (iom_file(kiomid)%iolib)
428            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
429            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
430            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
431            CASE DEFAULT   
432               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
433            END SELECT
434         ENDIF
435      ENDIF
436   END SUBROUTINE iom_g0d
437
438   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
439      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
440      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
441      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
442      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
443      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
444      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
445      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
446      !
447      IF( kiomid > 0 ) THEN
448         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
449              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
450      ENDIF
451   END SUBROUTINE iom_g1d
452
453   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
454      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
455      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
456      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
457      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
458      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
459      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading
460      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
461      !
462      IF( kiomid > 0 ) THEN
463         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
464              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
465      ENDIF
466   END SUBROUTINE iom_g2d
467
468   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
469      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
470      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
471      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
472      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
473      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
474      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading
475      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
476      !
477      IF( kiomid > 0 ) THEN
478         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
479              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
480      ENDIF
481   END SUBROUTINE iom_g3d
482   !!----------------------------------------------------------------------
483
484   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
485         &                  pv_r1d, pv_r2d, pv_r3d,   &
486         &                  ktime , kstart, kcount  )
487      !!-----------------------------------------------------------------------
488      !!                  ***  ROUTINE  iom_get_123d  ***
489      !!
490      !! ** Purpose : read a 1D/2D/3D variable
491      !!
492      !! ** Method : read ONE record at each CALL
493      !!-----------------------------------------------------------------------
494      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
495      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
496      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
497      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
498      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
499      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
500      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
501      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis
502      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
503      !
504      LOGICAL                        ::   llnoov      ! local definition to read overlap
505      INTEGER                        ::   jl          ! loop on number of dimension
506      INTEGER                        ::   idom        ! type of domain
507      INTEGER                        ::   idvar       ! id of the variable
508      INTEGER                        ::   inbdim      ! number of dimensions of the variable
509      INTEGER                        ::   idmspc      ! number of spatial dimensions
510      INTEGER                        ::   itime       ! record number
511      INTEGER                        ::   istop       ! temporary value of nstop
512      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
513      INTEGER                        ::   ji, jj      ! loop counters
514      INTEGER                        ::   irankpv       !
515      INTEGER                        ::   ind1, ind2  ! substring index
516      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
517      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis
518      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
519      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
520      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
521      INTEGER                        ::   itmp        ! temporary integer
522      CHARACTER(LEN=100)             ::   clinfo      ! info character
523      CHARACTER(LEN=100)             ::   clname      ! file name
524      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !
525      !---------------------------------------------------------------------
526      !
527      clname = iom_file(kiomid)%name   !   esier to read
528      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
529      ! local definition of the domain ?
530      idom = kdom
531      ! do we read the overlap
532      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
533      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
534      ! check kcount and kstart optionals parameters...
535      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
536      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
537      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
538
539      ! Search for the variable in the data base (eventually actualize data)
540      istop = nstop
541      idvar = iom_varid( kiomid, cdvar )
542      !
543      IF( idvar > 0 ) THEN
544         ! to write iom_file(kiomid)%dimsz in a shorter way !
545         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
546         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
547         idmspc = inbdim                                   ! number of spatial dimensions in the file
548         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
549         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
550         !
551         ! update idom definition...
552         ! Identify the domain in case of jpdom_auto(glo/dta) definition
553         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN           
554            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
555            ELSE                               ;   idom = jpdom_data
556            ENDIF
557            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
558            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
559            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
560         ENDIF
561         ! Identify the domain in case of jpdom_local definition
562         IF( idom == jpdom_local ) THEN
563            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
564            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
565            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
566            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
567            ENDIF
568         ENDIF
569         !
570         ! check the consistency between input array and data rank in the file
571         !
572         ! initializations
573         itime = 1
574         IF( PRESENT(ktime) ) itime = ktime
575
576         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
577         WRITE(clrankpv, fmt='(i1)') irankpv
578         WRITE(cldmspc , fmt='(i1)') idmspc
579         !
580         IF(     idmspc <  irankpv ) THEN
581            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
582               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
583         ELSEIF( idmspc == irankpv ) THEN
584            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
585               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
586         ELSEIF( idmspc >  irankpv ) THEN
587               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
588                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
589                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
590                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
591                  idmspc = idmspc - 1
592               ELSE
593                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
594                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
595                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
596               ENDIF
597         ENDIF
598
599         !
600         ! definition of istart and icnt
601         !
602         icnt  (:) = 1
603         istart(:) = 1
604         istart(idmspc+1) = itime
605
606         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
607         ELSE
608            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
609            ELSE
610               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
611                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
612                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
613                  ENDIF
614                  ! we do not read the overlap                     -> we start to read at nldi, nldj
615! JMM + SM: ugly patch before getting the new version of lib_mpp)
616!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
617                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
618                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej
619! JMM + SM: ugly patch before getting the new version of lib_mpp)
620!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
621                  IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
622                  ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /)
623                  ENDIF
624                  IF( PRESENT(pv_r3d) ) THEN
625                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
626                     ELSE                            ; icnt(3) = jpk
627                     ENDIF
628                  ENDIF
629               ENDIF
630            ENDIF
631         ENDIF
632
633         ! check that istart and icnt can be used with this file
634         !-
635         DO jl = 1, jpmax_dims
636            itmp = istart(jl)+icnt(jl)-1
637            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
638               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
639               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
640               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
641            ENDIF
642         END DO
643
644         ! check that icnt matches the input array
645         !-     
646         IF( idom == jpdom_unknown ) THEN
647            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
648            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
649            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
650            ctmp1 = 'd'
651         ELSE
652            IF( irankpv == 2 ) THEN
653! JMM + SM: ugly patch before getting the new version of lib_mpp)
654!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
655               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
656               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
657               ENDIF
658            ENDIF
659            IF( irankpv == 3 ) THEN 
660! JMM + SM: ugly patch before getting the new version of lib_mpp)
661!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
662               IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
663               ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
664               ENDIF
665            ENDIF
666         ENDIF
667         
668         DO jl = 1, irankpv
669            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
670            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
671         END DO
672
673      ENDIF
674
675      ! read the data
676      !-     
677      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
678         !
679         ! find the right index of the array to be read
680! JMM + SM: ugly patch before getting the new version of lib_mpp)
681!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
682!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
683!         ENDIF
684         IF( llnoov ) THEN
685            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
686            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
687            ENDIF
688         ELSE
689            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
690            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
691            ENDIF
692         ENDIF
693     
694         SELECT CASE (iom_file(kiomid)%iolib)
695         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
696            &                                         pv_r1d, pv_r2d, pv_r3d )
697         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
698            &                                         pv_r1d, pv_r2d, pv_r3d )
699         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
700            &                                         pv_r1d, pv_r2d, pv_r3d )
701         CASE DEFAULT   
702            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
703         END SELECT
704
705         IF( istop == nstop ) THEN   ! no additional errors until this point...
706            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i4,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
707         
708            !--- overlap areas and extra hallows (mpp)
709            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
710               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
711            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
712               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
713               IF( icnt(3) == jpk ) THEN
714                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
715               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
716                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
717                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
718               ENDIF
719            ENDIF
720           
721            !--- Apply scale_factor and offset
722            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
723            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
724            IF(     PRESENT(pv_r1d) ) THEN
725               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
726               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
727            ELSEIF( PRESENT(pv_r2d) ) THEN
728!CDIR COLLAPSE
729               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
730!CDIR COLLAPSE
731               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
732            ELSEIF( PRESENT(pv_r3d) ) THEN
733!CDIR COLLAPSE
734               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
735!CDIR COLLAPSE
736               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
737            ENDIF
738            !
739         ENDIF
740         !
741      ENDIF
742      !
743   END SUBROUTINE iom_get_123d
744
745
746   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
747      !!--------------------------------------------------------------------
748      !!                   ***  SUBROUTINE iom_gettime  ***
749      !!
750      !! ** Purpose : read the time axis cdvar in the file
751      !!--------------------------------------------------------------------
752      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
753      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
754      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
755      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
756      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
757      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of
758      !
759      INTEGER, DIMENSION(1) :: kdimsz
760      INTEGER            ::   idvar    ! id of the variable
761      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
762      CHARACTER(LEN=100) ::   clinfo   ! info character
763      !---------------------------------------------------------------------
764      !
765      IF ( PRESENT(cdvar) ) THEN
766         tname = cdvar
767      ELSE
768         tname = iom_file(kiomid)%uldname
769      ENDIF
770      IF( kiomid > 0 ) THEN
771         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
772         IF ( PRESENT(kntime) ) THEN
773            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
774            kntime = kdimsz(1)
775         ELSE
776            idvar = iom_varid( kiomid, tname )
777         ENDIF
778         !
779         ptime(:) = 0. ! default definition
780         IF( idvar > 0 ) THEN
781            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
782               IF( iom_file(kiomid)%luld(idvar) ) THEN
783                  IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
784                     SELECT CASE (iom_file(kiomid)%iolib)
785                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
786                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
787                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
788                     CASE DEFAULT   
789                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
790                     END SELECT
791                  ELSE
792                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
793                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
794                  ENDIF
795               ELSE
796                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
797               ENDIF
798            ELSE
799               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
800            ENDIF
801         ELSE
802            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
803         ENDIF
804      ENDIF
805      !
806   END SUBROUTINE iom_gettime
807
808
809   !!----------------------------------------------------------------------
810   !!                   INTERFACE iom_rstput
811   !!----------------------------------------------------------------------
812   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
813      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
814      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
815      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
816      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
817      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
818      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
819      INTEGER :: ivid   ! variable id
820      IF( kiomid > 0 ) THEN
821         IF( iom_file(kiomid)%nfid > 0 ) THEN
822            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
823            SELECT CASE (iom_file(kiomid)%iolib)
824            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
825            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
826            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
827            CASE DEFAULT     
828               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
829            END SELECT
830         ENDIF
831      ENDIF
832   END SUBROUTINE iom_rp0d
833
834   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
835      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
836      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
837      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
838      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
839      REAL(wp)        , INTENT(in), DIMENSION(        jpk) ::   pvar     ! written field
840      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
841      INTEGER :: ivid   ! variable id
842      IF( kiomid > 0 ) THEN
843         IF( iom_file(kiomid)%nfid > 0 ) THEN
844            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
845            SELECT CASE (iom_file(kiomid)%iolib)
846            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
847            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
848            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
849            CASE DEFAULT     
850               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
851            END SELECT
852         ENDIF
853      ENDIF
854   END SUBROUTINE iom_rp1d
855
856   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
857      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
858      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
859      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
860      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
861      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj    ) ::   pvar     ! written field
862      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
863      INTEGER :: ivid   ! variable id
864      IF( kiomid > 0 ) THEN
865         IF( iom_file(kiomid)%nfid > 0 ) THEN
866            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
867            SELECT CASE (iom_file(kiomid)%iolib)
868            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
869            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
870            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
871            CASE DEFAULT     
872               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
873            END SELECT
874         ENDIF
875      ENDIF
876   END SUBROUTINE iom_rp2d
877
878   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
879      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
880      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
881      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
882      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
883      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvar     ! written field
884      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
885      INTEGER :: ivid   ! variable id
886      IF( kiomid > 0 ) THEN
887         IF( iom_file(kiomid)%nfid > 0 ) THEN
888            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
889            SELECT CASE (iom_file(kiomid)%iolib)
890            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
891            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
892            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
893            CASE DEFAULT     
894               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
895            END SELECT
896         ENDIF
897      ENDIF
898   END SUBROUTINE iom_rp3d
899
900
901   !!----------------------------------------------------------------------
902   !!                   INTERFACE iom_put
903   !!----------------------------------------------------------------------
904   SUBROUTINE iom_p0d( cdname, pfield0d )
905      CHARACTER(LEN=*), INTENT(in) ::   cdname
906      REAL(wp)        , INTENT(in) ::   pfield0d
907#if defined key_iomput
908      CALL event__write_field2D( cdname, RESHAPE( (/pfield0d/), (/1,1/) ) )
909#else
910      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
911#endif
912   END SUBROUTINE iom_p0d
913
914   SUBROUTINE iom_p2d( cdname, pfield2d )
915      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
916      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pfield2d
917#if defined key_iomput
918      CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
919#else
920      IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
921#endif
922   END SUBROUTINE iom_p2d
923
924   SUBROUTINE iom_p3d( cdname, pfield3d )
925      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
926      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) ::   pfield3d
927#if defined key_iomput
928      CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
929#else
930      IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
931#endif
932   END SUBROUTINE iom_p3d
933   !!----------------------------------------------------------------------
934
935
936#if defined key_iomput
937
938   SUBROUTINE set_grid( cdname, plon, plat )
939      !!----------------------------------------------------------------------
940      !!                     ***  ROUTINE   ***
941      !!
942      !! ** Purpose :   define horizontal grids
943      !!
944      !!----------------------------------------------------------------------
945      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
946      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
947      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
948
949      CALL event__set_grid_dimension( cdname, jpiglo, jpjglo)
950      CALL event__set_grid_domain( cdname, nlei-nldi+1, nlej-nldj+1, nimpp+nldi-1, njmpp+nldj-1, &
951         &                         plon(nldi:nlei, nldj:nlej), plat(nldi:nlei, nldj:nlej) )
952      CALL event__set_grid_type_nemo( cdname )
953
954   END SUBROUTINE set_grid
955
956
957   SUBROUTINE set_scalar
958      !!----------------------------------------------------------------------
959      !!                     ***  ROUTINE   ***
960      !!
961      !! ** Purpose :   define fake grids for scalar point
962      !!
963      !!----------------------------------------------------------------------
964      REAL(wp), DIMENSION(1,1) ::   zz = 1.
965      !!----------------------------------------------------------------------
966      CALL event__set_grid_dimension( 'scalarpoint', jpnij, 1)
967      CALL event__set_grid_domain   ( 'scalarpoint', 1, 1, narea, 1, zz, zz )
968      CALL event__set_grid_type_nemo( 'scalarpoint' )
969
970   END SUBROUTINE set_scalar
971
972
973   SUBROUTINE set_xmlatt
974      !!----------------------------------------------------------------------
975      !!                     ***  ROUTINE   ***
976      !!
977      !! ** Purpose :   automatic definitions of some of the xml attributs...
978      !!
979      !!----------------------------------------------------------------------
980      CHARACTER(len=6),DIMENSION( 8) ::   clsuff                   ! suffix name
981      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
982      CHARACTER(len=50)              ::   clname                   ! file name
983      CHARACTER(len=1)               ::   cl1                      ! 1 character
984      CHARACTER(len=2)               ::   cl2                      ! 1 character
985      INTEGER                        ::   idt                      ! time-step in seconds
986      INTEGER                        ::   iddss, ihhss             ! number of seconds in 1 day, 1 hour and 1 year
987      INTEGER                        ::   iyymo                    ! number of months in 1 year
988      INTEGER                        ::   jg, jh, jd, jm, jy       ! loop counters
989      INTEGER                        ::   ix, iy                   ! i-,j- index
990      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
991      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
992      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
993      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
994      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
995      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
996      !!----------------------------------------------------------------------
997      !
998      idt   = NINT( rdttra(1)     )
999      iddss = NINT( rday          )                                         ! number of seconds in 1 day
1000      ihhss = NINT( rmmss * rhhmm )                                         ! number of seconds in 1 hour
1001      iyymo = NINT( raamo         )                                         ! number of months in 1 year
1002
1003      ! frequency of the call of iom_put (attribut: freq_op)
1004      CALL event__set_attribut( 'field_definition', attr( field__freq_op, idt           ) )    ! model time-step
1005      CALL event__set_attribut( 'SBC'             , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
1006     
1007      ! output file names (attribut: name)
1008      clsuff(:) = (/ 'grid_T', 'grid_U', 'grid_V', 'grid_W', 'icemod', 'ptrc_T', 'diad_T', 'scalar' /)     
1009      DO jg = 1, SIZE(clsuff)                                                                  ! grid type
1010         DO jh = 1, 12                                                                         ! 1, 2, 3, 4, 6, 12 hours
1011            IF( MOD(12,jh) == 0 ) THEN
1012               WRITE(cl2,'(i2)') jh 
1013               CALL dia_nam( clname, jh * ihhss, clsuff(jg), ldfsec = .TRUE. )
1014               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1015            ENDIF
1016         END DO
1017         DO jd = 1, 5, 2                                                                       ! 1, 3, 5 days
1018            WRITE(cl1,'(i1)') jd 
1019            CALL dia_nam( clname, jd * iddss, clsuff(jg), ldfsec = .TRUE. )
1020            CALL event__set_attribut( cl1//'d_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1021         END DO
1022         DO jm = 1, 6                                                                          ! 1, 2, 3, 4, 6 months
1023            IF( MOD(6,jm) == 0 ) THEN
1024               WRITE(cl1,'(i1)') jm 
1025               CALL dia_nam( clname, -jm, clsuff(jg) )
1026               CALL event__set_attribut( cl1//'m_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1027            ENDIF
1028         END DO
1029         DO jy = 1, 10                                                                         ! 1, 2, 5, 10 years 
1030            IF( MOD(10,jy) == 0 ) THEN
1031               WRITE(cl2,'(i2)') jy 
1032               CALL dia_nam( clname, -jy * iyymo, clsuff(jg) )
1033               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1034            ENDIF
1035         END DO
1036      END DO
1037
1038      ! Zooms...
1039      clgrd = (/ 'T', 'U', 'W' /) 
1040      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
1041         cl1 = clgrd(jg)
1042         ! Equatorial section (attributs: jbegin, ni, name_suffix)
1043         CALL dom_ngb( 0., 0., ix, iy, cl1 )
1044         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__jbegin     , iy     ) )
1045         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__ni         , jpiglo ) )
1046         CALL event__set_attribut( 'Eq'//cl1, attr( file__name_suffix, '_Eq'  ) )
1047      END DO
1048      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
1049      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
1050      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
1051      CALL set_mooring( zlontao, zlattao )
1052      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
1053      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
1054      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
1055      CALL set_mooring( zlonrama, zlatrama )
1056      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
1057      zlonpira = (/ -38.0, -23.0, -10.0 /)
1058      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
1059      CALL set_mooring( zlonpira, zlatpira )
1060     
1061   END SUBROUTINE set_xmlatt
1062
1063
1064   SUBROUTINE set_mooring( plon, plat)
1065      !!----------------------------------------------------------------------
1066      !!                     ***  ROUTINE   ***
1067      !!
1068      !! ** Purpose :   automatic definitions of moorings xml attributs...
1069      !!
1070      !!----------------------------------------------------------------------
1071      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
1072      !
1073!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
1074      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
1075      CHARACTER(len=50)             ::   clname                   ! file name
1076      CHARACTER(len=1)              ::   cl1                      ! 1 character
1077      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
1078      INTEGER                       ::   ji, jj, jg               ! loop counters
1079      INTEGER                       ::   ix, iy                   ! i-,j- index
1080      REAL(wp)                      ::   zlon, zlat
1081      !!----------------------------------------------------------------------
1082      DO jg = 1, SIZE(clgrd)
1083         cl1 = clgrd(jg)
1084         DO ji = 1, SIZE(plon)
1085            DO jj = 1, SIZE(plat)
1086               zlon = plon(ji)
1087               zlat = plat(jj)
1088               ! modifications for RAMA moorings
1089               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
1090               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
1091               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
1092               ! modifications for PIRATA moorings
1093               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
1094               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
1095               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
1096               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
1097               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
1098               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
1099               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
1100               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
1101               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
1102               IF( zlon >= 0. ) THEN 
1103                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
1104                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
1105                  ENDIF
1106               ELSE             
1107                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
1108                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
1109                  ENDIF
1110               ENDIF
1111               IF( zlat >= 0. ) THEN 
1112                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
1113                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
1114                  ENDIF
1115               ELSE             
1116                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
1117                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
1118                  ENDIF
1119               ENDIF
1120               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
1121               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__ibegin     , ix                ) )
1122               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__jbegin     , iy                ) )
1123               CALL event__set_attribut( TRIM(clname)//cl1, attr( file__name_suffix, '_'//TRIM(clname) ) )     
1124            END DO
1125         END DO
1126      END DO
1127     
1128   END SUBROUTINE set_mooring
1129
1130#else
1131
1132   SUBROUTINE iom_setkt( kt )
1133      INTEGER, INTENT(in   )::   kt 
1134      IF( .FALSE. )   WRITE(numout,*) kt   ! useless test to avoid compilation warnings
1135   END SUBROUTINE iom_setkt
1136
1137#endif
1138
1139
1140   !!======================================================================
1141END MODULE iom
Note: See TracBrowser for help on using the repository browser.