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 @ 1488

Last change on this file since 1488 was 1487, checked in by smasson, 15 years ago

suppress useless iom_init_chkcpp, see ticket:469

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 48.9 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 mod_event_client
30# endif
31
32   IMPLICIT NONE
33   PUBLIC   !   must be public to be able to access iom_def through iom
34   
35#if defined key_iomput
36   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.       !: iom_put flag
37#else
38   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
39#endif
40   PUBLIC iom_init, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
41
42   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
43   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
44   PRIVATE iom_p2d, iom_p3d
45#if defined key_iomput
46   PRIVATE set_grid
47# endif
48
49   INTERFACE iom_get
50      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
51   END INTERFACE
52   INTERFACE iom_rstput
53      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
54   END INTERFACE
55  INTERFACE iom_put
56     MODULE PROCEDURE iom_p2d, iom_p3d
57  END INTERFACE
58#if defined key_iomput
59   INTERFACE iom_setkt
60      MODULE PROCEDURE event__set_timestep
61   END INTERFACE
62# endif
63
64   !!----------------------------------------------------------------------
65   !!  OPA 9.0 , LOCEAN-IPSL (2006)
66   !! $Id$
67   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
68   !!----------------------------------------------------------------------
69
70CONTAINS
71
72   SUBROUTINE iom_init( pjulian )
73      !!----------------------------------------------------------------------
74      !!                     ***  ROUTINE   ***
75      !!
76      !! ** Purpose :   
77      !!
78      !!----------------------------------------------------------------------
79      REAL(wp), INTENT(in) ::  pjulian   !: julian day at nit000 = 0
80#if defined key_iomput
81      !!----------------------------------------------------------------------
82      ! read the xml file
83      CALL event__parse_xml_file( 'iodef.xml' )   ! <- to get from the nameliste (namrun)...
84
85      ! calendar parameters
86      CALL event__set_time_parameters( nit000 - 1, pjulian, rdt )
87
88      ! horizontal grid definition
89      CALL set_grid( "grid_T", glamt, gphit )
90      CALL set_grid( "grid_U", glamu, gphiu )
91      CALL set_grid( "grid_V", glamv, gphiv )
92      CALL set_grid( "grid_W", glamt, gphit )
93
94      ! vertical grid definition
95      CALL event__set_vert_axis( "deptht", gdept_0 )
96      CALL event__set_vert_axis( "depthu", gdept_0 )
97      CALL event__set_vert_axis( "depthv", gdept_0 )
98      CALL event__set_vert_axis( "depthw", gdepw_0 )
99
100      ! end file definition
101      CALL event__close_io_definition
102#endif
103
104   END SUBROUTINE iom_init
105
106
107   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
108      !!---------------------------------------------------------------------
109      !!                   ***  SUBROUTINE  iom_open  ***
110      !!
111      !! ** Purpose :  open an input file (return 0 if not found)
112      !!---------------------------------------------------------------------
113      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
114      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
115      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
116      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
117      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90)
118      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
119      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
120
121      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
122      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
123      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
124      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
125      CHARACTER(LEN=100)    ::   clinfo    ! info character
126      LOGICAL               ::   llok      ! check the existence
127      LOGICAL               ::   llwrt     ! local definition of ldwrt
128      LOGICAL               ::   llnoov    ! local definition to read overlap
129      LOGICAL               ::   llstop    ! local definition of ldstop
130      LOGICAL               ::   lliof     ! local definition of ldiof
131      INTEGER               ::   iolib     ! library do we use to open the file
132      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
133      INTEGER               ::   iln, ils  ! lengths of character
134      INTEGER               ::   idom      ! type of domain
135      INTEGER               ::   istop     !
136      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters:
137      ! local number of points for x,y dimensions
138      ! position of first local point for x,y dimensions
139      ! position of last local point for x,y dimensions
140      ! start halo size for x,y dimensions
141      ! end halo size for x,y dimensions
142      !---------------------------------------------------------------------
143      ! Initializations and control
144      ! =============
145      kiomid = -1
146      clinfo = '                    iom_open ~~~  '
147      istop = nstop
148      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
149      ! (could be done when defining iom_file in f95 but not in f90)
150#if ! defined key_agrif
151      IF( iom_open_init == 0 ) THEN
152         iom_file(:)%nfid = 0
153         iom_open_init = 1
154      ENDIF
155#else
156      IF( Agrif_Root() ) THEN
157         IF( iom_open_init == 0 ) THEN
158            iom_file(:)%nfid = 0
159            iom_open_init = 1
160         ENDIF
161      ENDIF
162#endif
163      ! do we read or write the file?
164      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
165      ELSE                        ;   llwrt = .FALSE.
166      ENDIF
167      ! do we call ctl_stop if we try to open a non-existing file in read mode?
168      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
169      ELSE                         ;   llstop = .TRUE.
170      ENDIF
171      ! what library do we use to open the file?
172      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
173      ELSE                         ;   iolib = jpnf90
174      ENDIF
175      ! are we using interpolation on the fly?
176      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
177      ELSE                        ;   lliof = .FALSE.
178      ENDIF
179      ! do we read the overlap
180      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
181      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
182      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
183      ! =============
184      clname   = trim(cdname)
185#if defined key_agrif
186      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
187         iln    = INDEX(clname,'/') 
188         cltmpn = clname(1:iln)
189         clname = clname(iln+1:LEN_TRIM(clname))
190         clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname)
191      ENDIF
192#endif   
193      ! which suffix should we use?
194      SELECT CASE (iolib)
195      CASE (jpioipsl ) ;   clsuffix = '.nc'
196      CASE (jpnf90   ) ;   clsuffix = '.nc'
197      CASE (jprstdimg) ;   clsuffix = '.dimg'
198      CASE DEFAULT     ;   clsuffix = ''
199         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
200      END SELECT
201      ! Add the suffix if needed
202      iln = LEN_TRIM(clname)
203      ils = LEN_TRIM(clsuffix)
204      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
205         &   clname = TRIM(clname)//TRIM(clsuffix)
206      cltmpn = clname   ! store this name
207      ! try to find if the file to be opened already exist
208      ! =============
209      INQUIRE( FILE = clname, EXIST = llok )
210      IF( .NOT.llok ) THEN
211         ! we try to add the cpu number to the name
212         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
213         ELSE                            ;   WRITE(clcpu,*) narea-1
214         ENDIF
215         clcpu  = TRIM(ADJUSTL(clcpu))
216         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
217         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
218         icnt = 0
219         INQUIRE( FILE = clname, EXIST = llok ) 
220         ! we try different formats for the cpu number by adding 0
221         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
222            clcpu  = "0"//trim(clcpu)
223            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
224            INQUIRE( FILE = clname, EXIST = llok )
225            icnt = icnt + 1
226         END DO
227      ENDIF
228      IF( llwrt ) THEN
229         ! check the domain definition
230! JMM + SM: ugly patch before getting the new version of lib_mpp)
231!         idom = jpdom_local_noovlap   ! default definition
232         IF( llnoov ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
233         ELSE                ;   idom = jpdom_local_full      ! default definition
234         ENDIF
235         IF( PRESENT(kdom) )   idom = kdom
236         ! create the domain informations
237         ! =============
238         SELECT CASE (idom)
239         CASE (jpdom_local_full)
240            idompar(:,1) = (/ jpi             , jpj              /)
241            idompar(:,2) = (/ nimpp           , njmpp            /)
242            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
243            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
244            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
245         CASE (jpdom_local_noextra)
246            idompar(:,1) = (/ nlci            , nlcj             /)
247            idompar(:,2) = (/ nimpp           , njmpp            /)
248            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
249            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
250            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
251         CASE (jpdom_local_noovlap)
252            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
253            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
254            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
255            idompar(:,4) = (/ 0               , 0                /)
256            idompar(:,5) = (/ 0               , 0                /)
257         CASE DEFAULT
258            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
259         END SELECT
260      ENDIF
261      ! Open the NetCDF or RSTDIMG file
262      ! =============
263      ! do we have some free file identifier?
264      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
265         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
266      ! if no file was found...
267      IF( .NOT. llok ) THEN
268         IF( .NOT. llwrt ) THEN   ! we are in read mode
269            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
270            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
271            ENDIF
272         ELSE                     ! we are in write mode so we
273            clname = cltmpn       ! get back the file name without the cpu number
274         ENDIF
275      ENDIF
276      IF( istop == nstop ) THEN   ! no error within this routine
277         SELECT CASE (iolib)
278         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
279         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
280         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
281         CASE DEFAULT
282            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
283         END SELECT
284      ENDIF
285      !
286   END SUBROUTINE iom_open
287
288
289   SUBROUTINE iom_close( kiomid )
290      !!--------------------------------------------------------------------
291      !!                   ***  SUBROUTINE  iom_close  ***
292      !!
293      !! ** Purpose : close an input file, or all files opened by iom
294      !!--------------------------------------------------------------------
295      INTEGER, INTENT(inout), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
296      !                                              ! return 0 when file is properly closed
297      !                                              ! No argument: all files opened by iom are closed
298
299      INTEGER ::   jf         ! dummy loop indices
300      INTEGER ::   i_s, i_e   ! temporary integer
301      CHARACTER(LEN=100)    ::   clinfo    ! info character
302      !---------------------------------------------------------------------
303      !
304      clinfo = '                    iom_close ~~~  '
305      IF( PRESENT(kiomid) ) THEN
306         i_s = kiomid
307         i_e = kiomid
308      ELSE
309         i_s = 1
310         i_e = jpmax_files
311#if defined key_iomput
312         CALL event__stop_ioserver
313#endif
314      ENDIF
315
316      IF( i_s > 0 ) THEN
317         DO jf = i_s, i_e
318            IF( iom_file(jf)%nfid > 0 ) THEN
319               SELECT CASE (iom_file(jf)%iolib)
320               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
321               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
322               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
323               CASE DEFAULT
324                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
325               END SELECT
326               iom_file(jf)%nfid       = 0          ! free the id
327               IF( PRESENT(kiomid) )   kiomid = 0   ! return 0 as id to specify that the file was closed
328               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
329            ELSEIF( PRESENT(kiomid) ) THEN
330               WRITE(ctmp1,*) '--->',  kiomid
331               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
332            ENDIF
333         END DO
334      ENDIF
335      !   
336   END SUBROUTINE iom_close
337
338
339   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop ) 
340      !!-----------------------------------------------------------------------
341      !!                  ***  FUNCTION  iom_varid  ***
342      !!
343      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
344      !!-----------------------------------------------------------------------
345      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
346      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
347      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
348      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
349      !
350      INTEGER                        ::   iom_varid, iiv, i_nvd
351      LOGICAL                        ::   ll_fnd
352      CHARACTER(LEN=100)             ::   clinfo                   ! info character
353      LOGICAL                        ::   llstop                   ! local definition of ldstop
354      !!-----------------------------------------------------------------------
355      iom_varid = 0                         ! default definition
356      ! do we call ctl_stop if we look for non-existing variable?
357      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
358      ELSE                         ;   llstop = .TRUE.
359      ENDIF
360      !
361      IF( kiomid > 0 ) THEN
362         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
363         IF( iom_file(kiomid)%nfid == 0 ) THEN
364            CALL ctl_stop( trim(clinfo), 'the file is not open' )
365         ELSE
366            ll_fnd  = .FALSE.
367            iiv = 0
368            !
369            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
370               iiv = iiv + 1
371               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
372            END DO
373            !
374            IF( .NOT.ll_fnd ) THEN
375               iiv = iiv + 1
376               IF( iiv <= jpmax_vars ) THEN
377                  SELECT CASE (iom_file(kiomid)%iolib)
378                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
379                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
380                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
381                  CASE DEFAULT   
382                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
383                  END SELECT
384               ELSE
385                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
386                        &                         'increase the parameter jpmax_vars')
387               ENDIF
388               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
389            ELSE
390               iom_varid = iiv
391               IF( PRESENT(kdimsz) ) THEN
392                  i_nvd = iom_file(kiomid)%ndims(iiv)
393                  IF( i_nvd == size(kdimsz) ) THEN
394                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
395                  ELSE
396                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
397                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
398                  ENDIF
399               ENDIF
400            ENDIF
401         ENDIF
402      ENDIF
403      !
404   END FUNCTION iom_varid
405
406
407   !!----------------------------------------------------------------------
408   !!                   INTERFACE iom_get
409   !!----------------------------------------------------------------------
410   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
411      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
412      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
413      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
414      !
415      INTEGER               :: idvar   ! variable id
416      !
417      IF( kiomid > 0 ) THEN
418         idvar = iom_varid( kiomid, cdvar )
419         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
420            SELECT CASE (iom_file(kiomid)%iolib)
421            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
422            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
423            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
424            CASE DEFAULT   
425               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
426            END SELECT
427         ENDIF
428      ENDIF
429   END SUBROUTINE iom_g0d
430
431   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
432      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
433      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
434      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
435      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
436      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
437      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
438      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
439      !
440      IF( kiomid > 0 ) THEN
441         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
442              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
443      ENDIF
444   END SUBROUTINE iom_g1d
445
446   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
447      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
448      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
449      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
450      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
451      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
452      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading
453      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
454      !
455      IF( kiomid > 0 ) THEN
456         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
457              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
458      ENDIF
459   END SUBROUTINE iom_g2d
460
461   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
462      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
463      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
464      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
465      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
466      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
467      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading
468      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
469      !
470      IF( kiomid > 0 ) THEN
471         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
472              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
473      ENDIF
474   END SUBROUTINE iom_g3d
475   !!----------------------------------------------------------------------
476
477   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
478         &                  pv_r1d, pv_r2d, pv_r3d,   &
479         &                  ktime , kstart, kcount  )
480      !!-----------------------------------------------------------------------
481      !!                  ***  ROUTINE  iom_get_123d  ***
482      !!
483      !! ** Purpose : read a 1D/2D/3D variable
484      !!
485      !! ** Method : read ONE record at each CALL
486      !!-----------------------------------------------------------------------
487      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
488      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
489      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
490      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
491      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
492      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
493      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
494      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis
495      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
496      !
497      LOGICAL                        ::   llnoov      ! local definition to read overlap
498      INTEGER                        ::   jl          ! loop on number of dimension
499      INTEGER                        ::   idom        ! type of domain
500      INTEGER                        ::   idvar       ! id of the variable
501      INTEGER                        ::   inbdim      ! number of dimensions of the variable
502      INTEGER                        ::   idmspc      ! number of spatial dimensions
503      INTEGER                        ::   itime       ! record number
504      INTEGER                        ::   istop       ! temporary value of nstop
505      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
506      INTEGER                        ::   ji, jj      ! loop counters
507      INTEGER                        ::   irankpv       !
508      INTEGER                        ::   ind1, ind2  ! substring index
509      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
510      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis
511      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
512      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
513      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
514      INTEGER                        ::   itmp        ! temporary integer
515      CHARACTER(LEN=100)             ::   clinfo      ! info character
516      CHARACTER(LEN=100)             ::   clname      ! file name
517      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !
518      !---------------------------------------------------------------------
519      !
520      clname = iom_file(kiomid)%name   !   esier to read
521      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
522      ! local definition of the domain ?
523      idom = kdom
524      ! do we read the overlap
525      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
526      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
527      ! check kcount and kstart optionals parameters...
528      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
529      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
530      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
531
532      ! Search for the variable in the data base (eventually actualize data)
533      istop = nstop
534      idvar = iom_varid( kiomid, cdvar )
535      !
536      IF( idvar > 0 ) THEN
537         ! to write iom_file(kiomid)%dimsz in a shorter way !
538         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
539         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
540         idmspc = inbdim                                   ! number of spatial dimensions in the file
541         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
542         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
543         !
544         ! update idom definition...
545         ! Identify the domain in case of jpdom_auto(glo/dta) definition
546         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN           
547            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
548            ELSE                               ;   idom = jpdom_data
549            ENDIF
550            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
551            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
552            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
553         ENDIF
554         ! Identify the domain in case of jpdom_local definition
555         IF( idom == jpdom_local ) THEN
556            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
557            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
558            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
559            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
560            ENDIF
561         ENDIF
562         !
563         ! check the consistency between input array and data rank in the file
564         !
565         ! initializations
566         itime = 1
567         IF( PRESENT(ktime) ) itime = ktime
568
569         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
570         WRITE(clrankpv, fmt='(i1)') irankpv
571         WRITE(cldmspc , fmt='(i1)') idmspc
572         !
573         IF(     idmspc <  irankpv ) THEN
574            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
575               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
576         ELSEIF( idmspc == irankpv ) THEN
577            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
578               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
579         ELSEIF( idmspc >  irankpv ) THEN
580               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
581                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
582                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
583                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
584                  idmspc = idmspc - 1
585               ELSE
586                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
587                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
588                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
589               ENDIF
590         ENDIF
591
592         !
593         ! definition of istart and icnt
594         !
595         icnt  (:) = 1
596         istart(:) = 1
597         istart(idmspc+1) = itime
598
599         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
600         ELSE
601            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
602            ELSE
603               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
604                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
605                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
606                  ENDIF
607                  ! we do not read the overlap                     -> we start to read at nldi, nldj
608! JMM + SM: ugly patch before getting the new version of lib_mpp)
609!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
610                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
611                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej
612! JMM + SM: ugly patch before getting the new version of lib_mpp)
613!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
614                  IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
615                  ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /)
616                  ENDIF
617                  IF( PRESENT(pv_r3d) ) THEN
618                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
619                     ELSE                            ; icnt(3) = jpk
620                     ENDIF
621                  ENDIF
622               ENDIF
623            ENDIF
624         ENDIF
625
626         ! check that istart and icnt can be used with this file
627         !-
628         DO jl = 1, jpmax_dims
629            itmp = istart(jl)+icnt(jl)-1
630            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
631               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
632               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
633               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
634            ENDIF
635         END DO
636
637         ! check that icnt matches the input array
638         !-     
639         IF( idom == jpdom_unknown ) THEN
640            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
641            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
642            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
643            ctmp1 = 'd'
644         ELSE
645            IF( irankpv == 2 ) THEN
646! JMM + SM: ugly patch before getting the new version of lib_mpp)
647!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
648               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
649               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
650               ENDIF
651            ENDIF
652            IF( irankpv == 3 ) THEN 
653! JMM + SM: ugly patch before getting the new version of lib_mpp)
654!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
655               IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
656               ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
657               ENDIF
658            ENDIF
659         ENDIF
660         
661         DO jl = 1, irankpv
662            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
663            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
664         END DO
665
666      ENDIF
667
668      ! read the data
669      !-     
670      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
671         !
672         ! find the right index of the array to be read
673! JMM + SM: ugly patch before getting the new version of lib_mpp)
674!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
675!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
676!         ENDIF
677         IF( llnoov ) THEN
678            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
679            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
680            ENDIF
681         ELSE
682            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
683            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
684            ENDIF
685         ENDIF
686     
687         SELECT CASE (iom_file(kiomid)%iolib)
688         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
689            &                                         pv_r1d, pv_r2d, pv_r3d )
690         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
691            &                                         pv_r1d, pv_r2d, pv_r3d )
692         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
693            &                                         pv_r1d, pv_r2d, pv_r3d )
694         CASE DEFAULT   
695            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
696         END SELECT
697
698         IF( istop == nstop ) THEN   ! no additional errors until this point...
699            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i4,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
700         
701            !--- overlap areas and extra hallows (mpp)
702            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
703               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
704            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
705               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
706               IF( icnt(3) == jpk ) THEN
707                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
708               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
709                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
710                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
711               ENDIF
712            ENDIF
713           
714            !--- Apply scale_factor and offset
715            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
716            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
717            IF(     PRESENT(pv_r1d) ) THEN
718               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
719               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
720            ELSEIF( PRESENT(pv_r2d) ) THEN
721               !CDIR COLLAPSE
722               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
723               !CDIR COLLAPSE
724               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
725            ELSEIF( PRESENT(pv_r3d) ) THEN
726               !CDIR COLLAPSE
727               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
728               !CDIR COLLAPSE
729               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
730            ENDIF
731            !
732         ENDIF
733         !
734      ENDIF
735      !
736   END SUBROUTINE iom_get_123d
737
738
739   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
740      !!--------------------------------------------------------------------
741      !!                   ***  SUBROUTINE iom_gettime  ***
742      !!
743      !! ** Purpose : read the time axis cdvar in the file
744      !!--------------------------------------------------------------------
745      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
746      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
747      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
748      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
749      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
750      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of
751      !
752      INTEGER, DIMENSION(1) :: kdimsz
753      INTEGER            ::   idvar    ! id of the variable
754      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
755      CHARACTER(LEN=100) ::   clinfo   ! info character
756      !---------------------------------------------------------------------
757      !
758      IF ( PRESENT(cdvar) ) THEN
759         tname = cdvar
760      ELSE
761         tname = iom_file(kiomid)%uldname
762      ENDIF
763      IF( kiomid > 0 ) THEN
764         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
765         IF ( PRESENT(kntime) ) THEN
766            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
767            kntime = kdimsz(1)
768         ELSE
769            idvar = iom_varid( kiomid, tname )
770         ENDIF
771         !
772         ptime(:) = 0. ! default definition
773         IF( idvar > 0 ) THEN
774            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
775               IF( iom_file(kiomid)%luld(idvar) ) THEN
776                  IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
777                     SELECT CASE (iom_file(kiomid)%iolib)
778                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
779                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
780                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
781                     CASE DEFAULT   
782                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
783                     END SELECT
784                  ELSE
785                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
786                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
787                  ENDIF
788               ELSE
789                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
790               ENDIF
791            ELSE
792               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
793            ENDIF
794         ELSE
795            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
796         ENDIF
797      ENDIF
798      !
799   END SUBROUTINE iom_gettime
800
801
802   !!----------------------------------------------------------------------
803   !!                   INTERFACE iom_rstput
804   !!----------------------------------------------------------------------
805   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
806      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
807      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
808      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
809      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
810      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
811      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
812      INTEGER :: ivid   ! variable id
813      IF( kiomid > 0 ) THEN
814         IF( iom_file(kiomid)%nfid > 0 ) THEN
815            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
816            SELECT CASE (iom_file(kiomid)%iolib)
817            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
818            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
819            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
820            CASE DEFAULT     
821               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
822            END SELECT
823         ENDIF
824      ENDIF
825   END SUBROUTINE iom_rp0d
826
827   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
828      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
829      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
830      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
831      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
832      REAL(wp)        , INTENT(in), DIMENSION(        jpk) ::   pvar     ! written field
833      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
834      INTEGER :: ivid   ! variable id
835      IF( kiomid > 0 ) THEN
836         IF( iom_file(kiomid)%nfid > 0 ) THEN
837            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
838            SELECT CASE (iom_file(kiomid)%iolib)
839            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
840            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
841            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
842            CASE DEFAULT     
843               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
844            END SELECT
845         ENDIF
846      ENDIF
847   END SUBROUTINE iom_rp1d
848
849   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
850      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
851      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
852      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
853      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
854      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj    ) ::   pvar     ! written field
855      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
856      INTEGER :: ivid   ! variable id
857      IF( kiomid > 0 ) THEN
858         IF( iom_file(kiomid)%nfid > 0 ) THEN
859            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
860            SELECT CASE (iom_file(kiomid)%iolib)
861            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
862            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
863            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
864            CASE DEFAULT     
865               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
866            END SELECT
867         ENDIF
868      ENDIF
869   END SUBROUTINE iom_rp2d
870
871   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
872      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
873      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
874      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
875      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
876      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvar     ! written field
877      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
878      INTEGER :: ivid   ! variable id
879      IF( kiomid > 0 ) THEN
880         IF( iom_file(kiomid)%nfid > 0 ) THEN
881            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
882            SELECT CASE (iom_file(kiomid)%iolib)
883            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
884            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
885            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
886            CASE DEFAULT     
887               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
888            END SELECT
889         ENDIF
890      ENDIF
891   END SUBROUTINE iom_rp3d
892
893
894   !!----------------------------------------------------------------------
895   !!                   INTERFACE iom_put
896   !!----------------------------------------------------------------------
897   SUBROUTINE iom_p2d( cdname, pfield2d )
898      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
899      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pfield2d
900#if defined key_iomput
901      CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
902#endif
903   END SUBROUTINE iom_p2d
904
905   SUBROUTINE iom_p3d( cdname, pfield3d )
906      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
907      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) ::   pfield3d
908#if defined key_iomput
909      CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
910#endif
911   END SUBROUTINE iom_p3d
912   !!----------------------------------------------------------------------
913
914
915#if defined key_iomput
916
917   SUBROUTINE set_grid( cdname, plon, plat )
918      !!----------------------------------------------------------------------
919      !!                     ***  ROUTINE   ***
920      !!
921      !! ** Purpose :   
922      !!
923      !!----------------------------------------------------------------------
924      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
925      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
926      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
927
928      CALL event__set_grid_dimension( cdname, jpiglo, jpjglo)
929      CALL event__set_grid_domain( cdname, nlei-nldi+1, nlej-nldj+1, nimpp+nldi-1, njmpp+nldj-1, &
930         &                         plon(nldi:nlei, nldj:nlej), plat(nldi:nlei, nldj:nlej) )
931      CALL event__set_grid_type_nemo( cdname )
932
933   END SUBROUTINE set_grid
934
935#else
936
937   SUBROUTINE iom_setkt( kt )
938      INTEGER, INTENT(in   )::   kt 
939   END SUBROUTINE iom_setkt
940
941#endif
942
943
944   !!======================================================================
945END MODULE iom
Note: See TracBrowser for help on using the repository browser.