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

Last change on this file since 1131 was 1131, checked in by smasson, 16 years ago

iom_close return 0 as id, see ticket #217

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