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

Last change on this file since 1656 was 1520, checked in by smasson, 15 years ago

remove compilation warning in iom.F90, see ticket:482

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