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

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

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

Last change on this file since 1697 was 1697, checked in by smasson, 14 years ago

\!CDIR commands on the first column

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