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

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

by default stop if variable doesn't exist, see ticket:21

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