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

Last change on this file since 1319 was 1319, checked in by rblod, 15 years ago

First try to use IOF with AGRIF, see ticket #341

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