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

source: trunk/NEMO/OFF_SRC/IOM/iom.F90 @ 975

Last change on this file since 975 was 975, checked in by cetlod, 16 years ago

Update IOM modules, see ticket 150

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.2 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(in), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
215      !                                           ! No argument : all the files opened by iom are closed
216
217      INTEGER ::   jf         ! dummy loop indices
218      INTEGER ::   i_s, i_e   ! temporary integer
219      CHARACTER(LEN=100)    ::   clinfo    ! info character
220      !---------------------------------------------------------------------
221      !
222      clinfo = '                    iom_close ~~~  '
223      IF( PRESENT(kiomid) ) THEN
224         i_s = kiomid
225         i_e = kiomid
226      ELSE
227         i_s = 1
228         i_e = jpmax_files
229      ENDIF
230
231      IF( i_s > 0 ) THEN
232         DO jf = i_s, i_e
233            IF( iom_file(jf)%nfid > 0 ) THEN
234               SELECT CASE (iom_file(jf)%iolib)
235               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
236               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
237               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
238               CASE DEFAULT
239                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
240               END SELECT
241               iom_file(jf)%nfid       = 0   ! free the id
242               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
243            ELSEIF( PRESENT(kiomid) ) THEN
244               WRITE(ctmp1,*) '--->',  kiomid
245               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
246            ENDIF
247         END DO
248      ENDIF
249      !   
250   END SUBROUTINE iom_close
251
252
253   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop ) 
254      !!-----------------------------------------------------------------------
255      !!                  ***  FUNCTION  iom_varid  ***
256      !!
257      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
258      !!-----------------------------------------------------------------------
259      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
260      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
261      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
262      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
263      !
264      INTEGER                        ::   iom_varid, iiv, i_nvd
265      LOGICAL                        ::   ll_fnd
266      CHARACTER(LEN=100)             ::   clinfo                   ! info character
267      LOGICAL                        ::   llstop                   ! local definition of ldstop
268      !!-----------------------------------------------------------------------
269      iom_varid = 0                         ! default definition
270      ! do we call ctl_stop if we look for non-existing variable?
271      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
272      ELSE                         ;   llstop = .TRUE.
273      ENDIF
274      !
275      IF( kiomid > 0 ) THEN
276         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
277         IF( iom_file(kiomid)%nfid == 0 ) THEN
278            CALL ctl_stop( trim(clinfo), 'the file is not open' )
279         ELSE
280            ll_fnd  = .FALSE.
281            iiv = 0
282            !
283            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
284               iiv = iiv + 1
285               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
286            END DO
287            !
288            IF( .NOT.ll_fnd ) THEN
289               iiv = iiv + 1
290               IF( iiv <= jpmax_vars ) THEN
291                  SELECT CASE (iom_file(kiomid)%iolib)
292                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
293                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
294                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
295                  CASE DEFAULT   
296                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
297                  END SELECT
298               ELSE
299                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
300                        &                         'increase the parameter jpmax_vars')
301               ENDIF
302               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
303            ELSE
304               iom_varid = iiv
305               IF( PRESENT(kdimsz) ) THEN
306                  i_nvd = iom_file(kiomid)%ndims(iiv)
307                  IF( i_nvd == size(kdimsz) ) THEN
308                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
309                  ELSE
310                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
311                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
312                  ENDIF
313               ENDIF
314            ENDIF
315         ENDIF
316      ENDIF
317      !
318   END FUNCTION iom_varid
319
320
321   !!----------------------------------------------------------------------
322   !!                   INTERFACE iom_get
323   !!----------------------------------------------------------------------
324   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
325      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
326      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
327      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
328      !
329      INTEGER               :: idvar   ! variable id
330      !
331      IF( kiomid > 0 ) THEN
332         idvar = iom_varid( kiomid, cdvar )
333         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
334            SELECT CASE (iom_file(kiomid)%iolib)
335            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
336            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
337            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
338            CASE DEFAULT   
339               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
340            END SELECT
341         ENDIF
342      ENDIF
343   END SUBROUTINE iom_g0d
344
345   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
346      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
347      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
348      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
349      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
350      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
351      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
352      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
353      !
354      IF( kiomid > 0 ) THEN
355         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
356              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
357      ENDIF
358   END SUBROUTINE iom_g1d
359
360   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
361      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
362      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
363      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
364      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
365      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
366      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading
367      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
368      !
369      IF( kiomid > 0 ) THEN
370         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
371              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
372      ENDIF
373   END SUBROUTINE iom_g2d
374
375   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
376      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
377      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
378      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
379      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
380      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
381      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading
382      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
383      !
384      IF( kiomid > 0 ) THEN
385         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
386              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
387      ENDIF
388   END SUBROUTINE iom_g3d
389   !!----------------------------------------------------------------------
390
391   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
392         &                  pv_r1d, pv_r2d, pv_r3d,   &
393         &                  ktime , kstart, kcount  )
394      !!-----------------------------------------------------------------------
395      !!                  ***  ROUTINE  iom_get_123d  ***
396      !!
397      !! ** Purpose : read a 1D/2D/3D variable
398      !!
399      !! ** Method : read ONE record at each CALL
400      !!-----------------------------------------------------------------------
401      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
402      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
403      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
404      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
405      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
406      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
407      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
408      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis
409      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
410      !
411      INTEGER                        ::   jl          ! loop on number of dimension
412      INTEGER                        ::   idom        ! type of domain
413      INTEGER                        ::   idvar       ! id of the variable
414      INTEGER                        ::   inbdim      ! number of dimensions of the variable
415      INTEGER                        ::   idmspc      ! number of spatial dimensions
416      INTEGER                        ::   itime       ! record number
417      INTEGER                        ::   istop       ! temporary value of nstop
418      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
419      INTEGER                        ::   ji, jj      ! loop counters
420      INTEGER                        ::   irankpv       !
421      INTEGER                        ::   ind1, ind2  ! substring index
422      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
423      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis
424      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
425      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
426      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
427      INTEGER                        ::   itmp        ! temporary integer
428      CHARACTER(LEN=100)             ::   clinfo      ! info character
429      CHARACTER(LEN=100)             ::   clname      ! file name
430      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !
431      !---------------------------------------------------------------------
432      !
433      clname = iom_file(kiomid)%name   !   esier to read
434      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
435      ! local definition of the domain ?
436      idom = kdom
437      ! check kcount and kstart optionals parameters...
438      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
439      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
440      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
441
442      ! Search for the variable in the data base (eventually actualize data)
443      istop = nstop
444      idvar = iom_varid( kiomid, cdvar )
445      !
446      IF( idvar > 0 ) THEN
447         ! to write iom_file(kiomid)%dimsz in a shorter way !
448         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
449         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
450         idmspc = inbdim                                   ! number of spatial dimensions in the file
451         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
452         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
453         !
454         ! update idom definition...
455         ! Identify the domain in case of jpdom_auto(glo/dta) definition
456         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN           
457            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
458            ELSE                               ;   idom = jpdom_data
459            ENDIF
460            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
461            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
462            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
463         ENDIF
464         ! Identify the domain in case of jpdom_local definition
465         IF( idom == jpdom_local ) THEN
466            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
467            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
468            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
469            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
470            ENDIF
471         ENDIF
472         !
473         ! check the consistency between input array and data rank in the file
474         !
475         ! initializations
476         itime = 1
477         IF( PRESENT(ktime) ) itime = ktime
478
479         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
480         WRITE(clrankpv, fmt='(i1)') irankpv
481         WRITE(cldmspc , fmt='(i1)') idmspc
482         !
483         IF(     idmspc <  irankpv ) THEN
484            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
485               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
486         ELSEIF( idmspc == irankpv ) THEN
487            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
488               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
489         ELSEIF( idmspc >  irankpv ) THEN
490               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
491                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
492                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
493                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
494                  idmspc = idmspc - 1
495               ELSE
496                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
497                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
498                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
499               ENDIF
500         ENDIF
501
502         !
503         ! definition of istart and icnt
504         !
505         icnt  (:) = 1
506         istart(:) = 1
507         istart(idmspc+1) = itime
508
509         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
510         ELSE
511            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
512            ELSE
513               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
514                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
515                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
516                  ENDIF
517                  ! we do not read the overlap                     -> we start to read at nldi, nldj
518! JMM + SM: ugly patch before getting the new version of lib_mpp)
519!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
520                  IF( jpni*jpnj == jpnij .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
521                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej
522! JMM + SM: ugly patch before getting the new version of lib_mpp)
523!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
524                  IF( jpni*jpnj == jpnij ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
525                  ELSE                            ;   icnt(1:2) = (/ nlci           , nlcj            /)
526                  ENDIF
527                  IF( PRESENT(pv_r3d) ) THEN
528                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
529                     ELSE                            ; icnt(3) = jpk
530                     ENDIF
531                  ENDIF
532               ENDIF
533            ENDIF
534         ENDIF
535
536         ! check that istart and icnt can be used with this file
537         !-
538         DO jl = 1, jpmax_dims
539            itmp = istart(jl)+icnt(jl)-1
540            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
541               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
542               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
543               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
544            ENDIF
545         END DO
546
547         ! check that icnt matches the input array
548         !-     
549         IF( idom == jpdom_unknown ) THEN
550            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
551            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
552            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
553            ctmp1 = 'd'
554         ELSE
555            IF( irankpv == 2 ) THEN
556! JMM + SM: ugly patch before getting the new version of lib_mpp)
557!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
558               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
559               ELSE                          ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
560               ENDIF
561            ENDIF
562            IF( irankpv == 3 ) THEN 
563! JMM + SM: ugly patch before getting the new version of lib_mpp)
564!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
565               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
566               ELSE                          ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
567               ENDIF
568            ENDIF
569         ENDIF
570         
571         DO jl = 1, irankpv
572            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
573            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
574         END DO
575
576      ENDIF
577
578      ! read the data
579      !-     
580      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
581         !
582         ! find the right index of the array to be read
583! JMM + SM: ugly patch before getting the new version of lib_mpp)
584!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
585!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
586!         ENDIF
587         IF( jpni*jpnj == jpnij ) THEN
588            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
589            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
590            ENDIF
591         ELSE
592            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
593            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
594            ENDIF
595         ENDIF
596     
597         SELECT CASE (iom_file(kiomid)%iolib)
598         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
599            &                                         pv_r1d, pv_r2d, pv_r3d )
600         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
601            &                                         pv_r1d, pv_r2d, pv_r3d )
602         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
603            &                                         pv_r1d, pv_r2d, pv_r3d )
604         CASE DEFAULT   
605            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
606         END SELECT
607
608         IF( istop == nstop ) THEN   ! no additional errors until this point...
609            IF(lwp) WRITE(numout,*) '           read '//TRIM(cdvar)//' in '//TRIM(iom_file(kiomid)%name)//' ok'
610           
611            !--- overlap areas and extra hallows (mpp)
612            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
613               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
614            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
615               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
616               IF( icnt(3) == jpk ) THEN
617                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
618               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
619                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
620                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
621               ENDIF
622            ENDIF
623           
624            !--- Apply scale_factor and offset
625            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
626            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
627            IF(     PRESENT(pv_r1d) ) THEN
628               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
629               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
630            ELSEIF( PRESENT(pv_r2d) ) THEN
631               !CDIR COLLAPSE
632               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
633               !CDIR COLLAPSE
634               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
635            ELSEIF( PRESENT(pv_r3d) ) THEN
636               !CDIR COLLAPSE
637               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
638               !CDIR COLLAPSE
639               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
640            ENDIF
641            !
642         ENDIF
643         !
644      ENDIF
645      !
646   END SUBROUTINE iom_get_123d
647
648
649   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
650      !!--------------------------------------------------------------------
651      !!                   ***  SUBROUTINE iom_gettime  ***
652      !!
653      !! ** Purpose : read the time axis cdvar in the file
654      !!--------------------------------------------------------------------
655      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
656      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
657      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
658      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
659      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
660      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of
661      !
662      INTEGER, DIMENSION(1) :: kdimsz
663      INTEGER            ::   idvar    ! id of the variable
664      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
665      CHARACTER(LEN=100) ::   clinfo   ! info character
666      !---------------------------------------------------------------------
667      !
668      IF ( PRESENT(cdvar) ) THEN
669         tname = cdvar
670      ELSE
671         tname = iom_file(kiomid)%uldname
672      ENDIF
673      IF( kiomid > 0 ) THEN
674         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
675         IF ( PRESENT(kntime) ) THEN
676            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
677            kntime = kdimsz(1)
678         ELSE
679            idvar = iom_varid( kiomid, tname )
680         ENDIF
681         !
682         ptime(:) = 0. ! default definition
683         IF( idvar > 0 ) THEN
684            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
685               IF( iom_file(kiomid)%luld(idvar) ) THEN
686                  IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
687                     SELECT CASE (iom_file(kiomid)%iolib)
688                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
689                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
690                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
691                     CASE DEFAULT   
692                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
693                     END SELECT
694                  ELSE
695                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
696                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
697                  ENDIF
698               ELSE
699                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
700               ENDIF
701            ELSE
702               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
703            ENDIF
704         ELSE
705            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
706         ENDIF
707      ENDIF
708      !
709   END SUBROUTINE iom_gettime
710
711
712   !!----------------------------------------------------------------------
713   !!                   INTERFACE iom_rstput
714   !!----------------------------------------------------------------------
715   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
716      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
717      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
718      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
719      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
720      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
721      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
722      INTEGER :: ivid   ! variable id
723      IF( kiomid > 0 ) THEN
724         IF( iom_file(kiomid)%nfid > 0 ) THEN
725            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
726            SELECT CASE (iom_file(kiomid)%iolib)
727            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
728            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
729            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
730            CASE DEFAULT     
731               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
732            END SELECT
733         ENDIF
734      ENDIF
735   END SUBROUTINE iom_rp0d
736
737   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
738      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
739      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
740      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
741      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
742      REAL(wp)        , INTENT(in), DIMENSION(        jpk) ::   pvar     ! written field
743      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
744      INTEGER :: ivid   ! variable id
745      IF( kiomid > 0 ) THEN
746         IF( iom_file(kiomid)%nfid > 0 ) THEN
747            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
748            SELECT CASE (iom_file(kiomid)%iolib)
749            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
750            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
751            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
752            CASE DEFAULT     
753               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
754            END SELECT
755         ENDIF
756      ENDIF
757   END SUBROUTINE iom_rp1d
758
759   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
760      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
761      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
762      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
763      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
764      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj    ) ::   pvar     ! written field
765      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
766      INTEGER :: ivid   ! variable id
767      IF( kiomid > 0 ) THEN
768         IF( iom_file(kiomid)%nfid > 0 ) THEN
769            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
770            SELECT CASE (iom_file(kiomid)%iolib)
771            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
772            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
773            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
774            CASE DEFAULT     
775               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
776            END SELECT
777         ENDIF
778      ENDIF
779   END SUBROUTINE iom_rp2d
780
781   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
782      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
783      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
784      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
785      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
786      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvar     ! written field
787      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
788      INTEGER :: ivid   ! variable id
789      IF( kiomid > 0 ) THEN
790         IF( iom_file(kiomid)%nfid > 0 ) THEN
791            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
792            SELECT CASE (iom_file(kiomid)%iolib)
793            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
794            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
795            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
796            CASE DEFAULT     
797               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
798            END SELECT
799         ENDIF
800      ENDIF
801   END SUBROUTINE iom_rp3d
802   !!----------------------------------------------------------------------
803
804
805   !!======================================================================
806END MODULE iom
Note: See TracBrowser for help on using the repository browser.