New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
iom.F90 in trunk/NEMO/OFF_SRC/IOM – NEMO

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

Last change on this file since 1324 was 1324, checked in by cetlod, 15 years ago

update IOM and lib_mpp modules, see ticket:348

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