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

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

define internal subroutines of iom as PRIVATE, see ticket:32

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