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 branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 4409

Last change on this file since 4409 was 4409, checked in by trackstand2, 10 years ago

Changes to allow jpk to be modified to deepest level within a subdomain. jpkorig holds original value.

  • Property svn:keywords set to Id
File size: 70.1 KB
RevLine 
[544]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
[911]8   !!             "   ! 07 07  (D. Storkey) Changes to iom_gettime
[544]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)
[550]16   !!   iom_gettime    : read the time axis cdvar in the file
[544]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 dom_oce         ! ocean space and time domain
[3211]21   USE lbclnk          ! lateral boundary condition / mpp exchanges
[544]22   USE iom_def         ! iom variables definitions
23   USE iom_ioipsl      ! NetCDF format with IOIPSL library
24   USE iom_nf90        ! NetCDF format with native NetCDF library
25   USE iom_rstdimg     ! restarts access direct format "dimg" style...
[2715]26   USE in_out_manager  ! I/O manager
27   USE lib_mpp           ! MPP library
[1412]28#if defined key_iomput
[1725]29   USE sbc_oce, ONLY :   nn_fsbc         ! ocean space and time domain
30   USE domngb          ! ocean space and time domain
31   USE phycst          ! physical constants
32   USE dianam          ! build name of file
[1359]33   USE mod_event_client
[1725]34   USE mod_attribut
[1359]35# endif
[3211]36   USE zpermute, ONLY : permute_z_last   ! Re-order a 3d array back to external (z-last) ordering
[3432]37   USE timing,   ONLY : timing_start, timing_stop
[544]38   IMPLICIT NONE
[556]39   PUBLIC   !   must be public to be able to access iom_def through iom
[550]40   
[1457]41#if defined key_iomput
[1725]42   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.        !: iom_put flag
[1457]43#else
44   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
45#endif
[1793]46   PUBLIC iom_init, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
[2528]47   PUBLIC iom_getatt
[544]48
[752]49   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
50   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
[1359]51   PRIVATE iom_p2d, iom_p3d
[1412]52#if defined key_iomput
[1359]53   PRIVATE set_grid
54# endif
[752]55
[544]56   INTERFACE iom_get
[550]57      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
[544]58   END INTERFACE
[2528]59   INTERFACE iom_getatt
60      MODULE PROCEDURE iom_g0d_intatt
61   END INTERFACE
[544]62   INTERFACE iom_rstput
[550]63      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
[544]64   END INTERFACE
[1359]65  INTERFACE iom_put
[1738]66     MODULE PROCEDURE iom_p0d, iom_p2d, iom_p3d
[1359]67  END INTERFACE
[1412]68#if defined key_iomput
[1359]69   INTERFACE iom_setkt
70      MODULE PROCEDURE event__set_timestep
71   END INTERFACE
72# endif
[544]73
[3211]74   !! * Control permutation of array indices
75#  include "dom_oce_ftrans.h90"
76
[544]77   !!----------------------------------------------------------------------
[2528]78   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
[1152]79   !! $Id$
[2528]80   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
[544]81   !!----------------------------------------------------------------------
82
83CONTAINS
84
[1725]85   SUBROUTINE iom_init
[1359]86      !!----------------------------------------------------------------------
87      !!                     ***  ROUTINE   ***
88      !!
89      !! ** Purpose :   
90      !!
91      !!----------------------------------------------------------------------
[1412]92#if defined key_iomput
[1730]93      REAL(wp) ::   ztmp
[1359]94      !!----------------------------------------------------------------------
95      ! read the xml file
[1793]96      IF( Agrif_Root() ) CALL event__parse_xml_file( 'iodef.xml' )   ! <- to get from the nameliste (namrun)...
97      CALL iom_swap
[1359]98
99      ! calendar parameters
[1725]100      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
101      CASE ( 1)   ;   CALL event__set_calendar('gregorian')
102      CASE ( 0)   ;   CALL event__set_calendar('noleap'   )
103      CASE (30)   ;   CALL event__set_calendar('360d'     )
104      END SELECT
[1730]105      ztmp = fjulday - adatrj
106      IF( ABS(ztmp  - REAL(NINT(ztmp),wp)) < 0.1 / rday )   ztmp = REAL(NINT(ztmp),wp)   ! avoid truncation error
107      CALL event__set_time_parameters( nit000 - 1, ztmp, rdt )
[1359]108
109      ! horizontal grid definition
[1738]110      CALL set_scalar
[1359]111      CALL set_grid( "grid_T", glamt, gphit )
112      CALL set_grid( "grid_U", glamu, gphiu )
113      CALL set_grid( "grid_V", glamv, gphiv )
114      CALL set_grid( "grid_W", glamt, gphit )
115
116      ! vertical grid definition
117      CALL event__set_vert_axis( "deptht", gdept_0 )
118      CALL event__set_vert_axis( "depthu", gdept_0 )
119      CALL event__set_vert_axis( "depthv", gdept_0 )
120      CALL event__set_vert_axis( "depthw", gdepw_0 )
[1725]121     
122      ! automatic definitions of some of the xml attributs
123      CALL set_xmlatt
[1359]124
125      ! end file definition
126      CALL event__close_io_definition
127#endif
128
129   END SUBROUTINE iom_init
130
131
[1793]132   SUBROUTINE iom_swap
133      !!---------------------------------------------------------------------
134      !!                   ***  SUBROUTINE  iom_swap  ***
135      !!
136      !! ** Purpose :  swap context between different agrif grid for xmlio_server
137      !!---------------------------------------------------------------------
138#if defined key_iomput
139
140     IF( TRIM(Agrif_CFixed()) == '0' ) THEN
141        CALL event__swap_context("nemo")
142     ELSE
143        CALL event__swap_context(TRIM(Agrif_CFixed())//"_nemo")
144     ENDIF
145
146#endif
147   END SUBROUTINE iom_swap
148
149
[1319]150   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
[544]151      !!---------------------------------------------------------------------
152      !!                   ***  SUBROUTINE  iom_open  ***
153      !!
154      !! ** Purpose :  open an input file (return 0 if not found)
155      !!---------------------------------------------------------------------
156      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
157      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
158      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
159      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
[547]160      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90)
[679]161      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
[1319]162      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
[544]163
164      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
165      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
166      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
[550]167      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
[544]168      CHARACTER(LEN=100)    ::   clinfo    ! info character
169      LOGICAL               ::   llok      ! check the existence
[679]170      LOGICAL               ::   llwrt     ! local definition of ldwrt
[1200]171      LOGICAL               ::   llnoov    ! local definition to read overlap
[679]172      LOGICAL               ::   llstop    ! local definition of ldstop
[1319]173      LOGICAL               ::   lliof     ! local definition of ldiof
[544]174      INTEGER               ::   iolib     ! library do we use to open the file
175      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
176      INTEGER               ::   iln, ils  ! lengths of character
177      INTEGER               ::   idom      ! type of domain
178      INTEGER               ::   istop     !
179      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters:
180      ! local number of points for x,y dimensions
181      ! position of first local point for x,y dimensions
182      ! position of last local point for x,y dimensions
183      ! start halo size for x,y dimensions
184      ! end halo size for x,y dimensions
185      !---------------------------------------------------------------------
[3432]186
187      CALL timing_start('iom_open')
188
[544]189      ! Initializations and control
190      ! =============
[1341]191      kiomid = -1
[544]192      clinfo = '                    iom_open ~~~  '
193      istop = nstop
194      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
195      ! (could be done when defining iom_file in f95 but not in f90)
[1441]196      IF( Agrif_Root() ) THEN
197         IF( iom_open_init == 0 ) THEN
198            iom_file(:)%nfid = 0
199            iom_open_init = 1
200         ENDIF
[1409]201      ENDIF
[544]202      ! do we read or write the file?
203      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
204      ELSE                        ;   llwrt = .FALSE.
205      ENDIF
[679]206      ! do we call ctl_stop if we try to open a non-existing file in read mode?
207      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
208      ELSE                         ;   llstop = .TRUE.
209      ENDIF
[544]210      ! what library do we use to open the file?
211      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
[547]212      ELSE                         ;   iolib = jpnf90
[544]213      ENDIF
[1319]214      ! are we using interpolation on the fly?
215      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
216      ELSE                        ;   lliof = .FALSE.
217      ENDIF
[1200]218      ! do we read the overlap
219      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
[1202]220      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
[544]221      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
222      ! =============
223      clname   = trim(cdname)
[1319]224      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
[1200]225         iln    = INDEX(clname,'/') 
226         cltmpn = clname(1:iln)
227         clname = clname(iln+1:LEN_TRIM(clname))
228         clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname)
229      ENDIF
[544]230      ! which suffix should we use?
231      SELECT CASE (iolib)
232      CASE (jpioipsl ) ;   clsuffix = '.nc'
233      CASE (jpnf90   ) ;   clsuffix = '.nc'
234      CASE (jprstdimg) ;   clsuffix = '.dimg'
235      CASE DEFAULT     ;   clsuffix = ''
236         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
237      END SELECT
238      ! Add the suffix if needed
239      iln = LEN_TRIM(clname)
240      ils = LEN_TRIM(clsuffix)
[742]241      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
242         &   clname = TRIM(clname)//TRIM(clsuffix)
[544]243      cltmpn = clname   ! store this name
244      ! try to find if the file to be opened already exist
245      ! =============
246      INQUIRE( FILE = clname, EXIST = llok )
247      IF( .NOT.llok ) THEN
248         ! we try to add the cpu number to the name
[679]249         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
250         ELSE                            ;   WRITE(clcpu,*) narea-1
251         ENDIF
[544]252         clcpu  = TRIM(ADJUSTL(clcpu))
[679]253         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
[544]254         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
255         icnt = 0
256         INQUIRE( FILE = clname, EXIST = llok ) 
257         ! we try different formats for the cpu number by adding 0
258         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
259            clcpu  = "0"//trim(clcpu)
260            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
261            INQUIRE( FILE = clname, EXIST = llok )
262            icnt = icnt + 1
263         END DO
264      ENDIF
[679]265      IF( llwrt ) THEN
266         ! check the domain definition
267! JMM + SM: ugly patch before getting the new version of lib_mpp)
268!         idom = jpdom_local_noovlap   ! default definition
[1200]269         IF( llnoov ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
270         ELSE                ;   idom = jpdom_local_full      ! default definition
[679]271         ENDIF
272         IF( PRESENT(kdom) )   idom = kdom
273         ! create the domain informations
274         ! =============
275         SELECT CASE (idom)
276         CASE (jpdom_local_full)
277            idompar(:,1) = (/ jpi             , jpj              /)
278            idompar(:,2) = (/ nimpp           , njmpp            /)
279            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
280            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
281            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
282         CASE (jpdom_local_noextra)
283            idompar(:,1) = (/ nlci            , nlcj             /)
284            idompar(:,2) = (/ nimpp           , njmpp            /)
285            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
286            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
287            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
288         CASE (jpdom_local_noovlap)
289            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
290            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
291            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
292            idompar(:,4) = (/ 0               , 0                /)
293            idompar(:,5) = (/ 0               , 0                /)
294         CASE DEFAULT
295            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
296         END SELECT
297      ENDIF
[544]298      ! Open the NetCDF or RSTDIMG file
299      ! =============
300      ! do we have some free file identifier?
301      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
[679]302         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
303      ! if no file was found...
304      IF( .NOT. llok ) THEN
305         IF( .NOT. llwrt ) THEN   ! we are in read mode
306            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
307            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
308            ENDIF
309         ELSE                     ! we are in write mode so we
310            clname = cltmpn       ! get back the file name without the cpu number
311         ENDIF
[2586]312      ELSE
313         IF( llwrt .AND. .NOT. ln_clobber ) THEN   ! we stop as we want to write in a new file
314            CALL ctl_stop( TRIM(clinfo), 'We want to write in a new file but '//TRIM(clname)//' already exists...' )
315            istop = nstop + 1                      ! make sure that istop /= nstop so we don't open the file
316         ENDIF
[679]317      ENDIF
[544]318      IF( istop == nstop ) THEN   ! no error within this routine
319         SELECT CASE (iolib)
320         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
321         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
322         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
323         CASE DEFAULT
324            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
325         END SELECT
326      ENDIF
327      !
[3432]328      CALL timing_stop('iom_open')
329
[544]330   END SUBROUTINE iom_open
331
332
333   SUBROUTINE iom_close( kiomid )
334      !!--------------------------------------------------------------------
335      !!                   ***  SUBROUTINE  iom_close  ***
336      !!
337      !! ** Purpose : close an input file, or all files opened by iom
338      !!--------------------------------------------------------------------
[1131]339      INTEGER, INTENT(inout), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
340      !                                              ! return 0 when file is properly closed
341      !                                              ! No argument: all files opened by iom are closed
[544]342
343      INTEGER ::   jf         ! dummy loop indices
344      INTEGER ::   i_s, i_e   ! temporary integer
345      CHARACTER(LEN=100)    ::   clinfo    ! info character
346      !---------------------------------------------------------------------
347      !
[3432]348      CALL timing_start('iom_close')
349      !
[544]350      clinfo = '                    iom_close ~~~  '
351      IF( PRESENT(kiomid) ) THEN
352         i_s = kiomid
353         i_e = kiomid
354      ELSE
355         i_s = 1
356         i_e = jpmax_files
[1412]357#if defined key_iomput
[1359]358         CALL event__stop_ioserver
359#endif
[544]360      ENDIF
361
362      IF( i_s > 0 ) THEN
363         DO jf = i_s, i_e
364            IF( iom_file(jf)%nfid > 0 ) THEN
365               SELECT CASE (iom_file(jf)%iolib)
366               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
367               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
368               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
369               CASE DEFAULT
370                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
371               END SELECT
[1131]372               iom_file(jf)%nfid       = 0          ! free the id
373               IF( PRESENT(kiomid) )   kiomid = 0   ! return 0 as id to specify that the file was closed
[679]374               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
[544]375            ELSEIF( PRESENT(kiomid) ) THEN
376               WRITE(ctmp1,*) '--->',  kiomid
377               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
378            ENDIF
379         END DO
380      ENDIF
381      !   
[3432]382      CALL timing_stop('iom_close')
383
[544]384   END SUBROUTINE iom_close
385
386
[745]387   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop ) 
[544]388      !!-----------------------------------------------------------------------
389      !!                  ***  FUNCTION  iom_varid  ***
390      !!
391      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
392      !!-----------------------------------------------------------------------
393      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
394      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
395      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
[745]396      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
[544]397      !
398      INTEGER                        ::   iom_varid, iiv, i_nvd
399      LOGICAL                        ::   ll_fnd
400      CHARACTER(LEN=100)             ::   clinfo                   ! info character
[745]401      LOGICAL                        ::   llstop                   ! local definition of ldstop
[544]402      !!-----------------------------------------------------------------------
[3432]403      CALL timing_start('iom_varid')
404
[544]405      iom_varid = 0                         ! default definition
[745]406      ! do we call ctl_stop if we look for non-existing variable?
407      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
408      ELSE                         ;   llstop = .TRUE.
409      ENDIF
[544]410      !
411      IF( kiomid > 0 ) THEN
[679]412         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
[544]413         IF( iom_file(kiomid)%nfid == 0 ) THEN
414            CALL ctl_stop( trim(clinfo), 'the file is not open' )
415         ELSE
416            ll_fnd  = .FALSE.
417            iiv = 0
418            !
419            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
420               iiv = iiv + 1
421               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
422            END DO
423            !
424            IF( .NOT.ll_fnd ) THEN
425               iiv = iiv + 1
426               IF( iiv <= jpmax_vars ) THEN
427                  SELECT CASE (iom_file(kiomid)%iolib)
428                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
[745]429                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
430                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
[544]431                  CASE DEFAULT   
432                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
433                  END SELECT
434               ELSE
435                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
436                        &                         'increase the parameter jpmax_vars')
437               ENDIF
[745]438               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
[544]439            ELSE
440               iom_varid = iiv
441               IF( PRESENT(kdimsz) ) THEN
442                  i_nvd = iom_file(kiomid)%ndims(iiv)
443                  IF( i_nvd == size(kdimsz) ) THEN
444                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
445                  ELSE
446                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
447                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
448                  ENDIF
449               ENDIF
450            ENDIF
451         ENDIF
452      ENDIF
453      !
[3432]454      CALL timing_stop('iom_varid')
455      !
[544]456   END FUNCTION iom_varid
457
458
459   !!----------------------------------------------------------------------
460   !!                   INTERFACE iom_get
461   !!----------------------------------------------------------------------
[550]462   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
[544]463      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
464      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
465      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
466      !
467      INTEGER               :: idvar   ! variable id
468      !
[679]469      IF( kiomid > 0 ) THEN
[3432]470         CALL timing_start('iom_g0d')
[679]471         idvar = iom_varid( kiomid, cdvar )
472         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
473            SELECT CASE (iom_file(kiomid)%iolib)
474            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
475            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
476            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
477            CASE DEFAULT   
478               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
479            END SELECT
480         ENDIF
[3432]481         CALL timing_stop('iom_g0d')
[679]482      ENDIF
[550]483   END SUBROUTINE iom_g0d
[544]484
[3432]485   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lzfirst )
[544]486      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
487      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
488      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
489      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
490      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
491      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading
492      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
[3432]493      LOGICAL         , INTENT(in   )              , OPTIONAL ::   lzfirst   ! Whether array being read has been
494                                                                             ! ftrans'd to make z index first
[544]495      !
[679]496      IF( kiomid > 0 ) THEN
497         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
[3432]498              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, lzfirst=lzfirst )
[679]499      ENDIF
[550]500   END SUBROUTINE iom_g1d
[544]501
[3432]502   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lzfirst )
[544]503      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
504      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
505      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
506      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
507      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
508      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading
509      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
[3432]510      LOGICAL         , INTENT(in   )                , OPTIONAL ::   lzfirst   ! Whether array being read has been
511                                                                               ! ftrans'd to make z index first
[544]512      !
[679]513      IF( kiomid > 0 ) THEN
514         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
[3432]515              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, lzfirst=lzfirst )
[679]516      ENDIF
[550]517   END SUBROUTINE iom_g2d
[544]518
[3432]519   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lzfirst )
[544]520      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
521      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
522      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
523      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
524      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
525      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading
526      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
[3432]527      LOGICAL                    , INTENT(in   ), OPTIONAL ::   lzfirst    ! Whether array being read has been
528                                                                           ! ftrans'd to make z index first
[544]529      !
[679]530      IF( kiomid > 0 ) THEN
531         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
[3432]532              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, lzfirst=lzfirst )
[679]533      ENDIF
[550]534   END SUBROUTINE iom_g3d
[544]535   !!----------------------------------------------------------------------
536
537   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
[679]538         &                  pv_r1d, pv_r2d, pv_r3d,   &
[3432]539         &                  ktime , kstart, kcount, lzfirst  )
[544]540      !!-----------------------------------------------------------------------
541      !!                  ***  ROUTINE  iom_get_123d  ***
542      !!
543      !! ** Purpose : read a 1D/2D/3D variable
544      !!
545      !! ** Method : read ONE record at each CALL
546      !!-----------------------------------------------------------------------
547      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
548      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
549      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
550      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
551      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
552      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
553      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
554      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis
555      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
[3432]556      LOGICAL                    , INTENT(in   ), OPTIONAL ::   lzfirst    ! Whether array being read has been
557                                                                           ! ftrans'd to make z index first
[544]558      !
[1200]559      LOGICAL                        ::   llnoov      ! local definition to read overlap
[544]560      INTEGER                        ::   jl          ! loop on number of dimension
561      INTEGER                        ::   idom        ! type of domain
562      INTEGER                        ::   idvar       ! id of the variable
563      INTEGER                        ::   inbdim      ! number of dimensions of the variable
564      INTEGER                        ::   idmspc      ! number of spatial dimensions
565      INTEGER                        ::   itime       ! record number
566      INTEGER                        ::   istop       ! temporary value of nstop
[679]567      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
568      INTEGER                        ::   ji, jj      ! loop counters
[3211]569      INTEGER                        ::   irankpv     !
[679]570      INTEGER                        ::   ind1, ind2  ! substring index
[544]571      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
572      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis
573      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
[679]574      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
[544]575      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
576      INTEGER                        ::   itmp        ! temporary integer
577      CHARACTER(LEN=100)             ::   clinfo      ! info character
[679]578      CHARACTER(LEN=100)             ::   clname      ! file name
579      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      !
[3211]580
[3432]581!#if defined key_z_first
[3211]582      !! DCSE_NEMO: need a work array to match layout on disk, which is always z-last
583      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   wpv_r3d         ! copy of pv_r3d with dimensions permuted
584      INTEGER                                 ::   istat_wpv_r3d   ! result of attempt to allocate the above
585      INTEGER, DIMENSION(3)                   ::   ishape_pv_r3d   ! size of the dimensions of pv_r3d
586      INTEGER                                 ::   jk              ! loop counter
[3432]587!#endif
588      LOGICAL                                 ::   lftrans         ! DCSE_NEMO: Whether ftrans is
589                                                                   ! in effect for the array we're reading
590      !---------------------------------------------------------------------
591      !
592      CALL timing_start('iom_get_123d')
593
594#if defined key_z_first
595      IF( PRESENT(lzfirst) )THEN
596         lftrans = lzfirst
597      ELSE
598         ! DCSE_NEMO: If we're built with key_z_first then we assume array
599         ! being read has been ftrans'd in the calling routine unless told
600         ! otherwise
601         lftrans = .TRUE.
602      END IF
603#else
604      ! If we've not been built with key_z_first then we effectively ignore
605      ! the lzfirst argument because ftrans can't have been used.
606      lftrans = .FALSE.
[3211]607#endif
608
[679]609      clname = iom_file(kiomid)%name   !   esier to read
610      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
[544]611      ! local definition of the domain ?
612      idom = kdom
[1200]613      ! do we read the overlap
614      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
[1202]615      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
[544]616      ! check kcount and kstart optionals parameters...
[679]617      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
618      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
619      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
[544]620
621      ! Search for the variable in the data base (eventually actualize data)
622      istop = nstop
623      idvar = iom_varid( kiomid, cdvar )
624      !
625      IF( idvar > 0 ) THEN
626         ! to write iom_file(kiomid)%dimsz in a shorter way !
627         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
628         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
629         idmspc = inbdim                                   ! number of spatial dimensions in the file
630         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
[679]631         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
632         !
633         ! update idom definition...
634         ! Identify the domain in case of jpdom_auto(glo/dta) definition
635         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN           
636            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
637            ELSE                               ;   idom = jpdom_data
[544]638            ENDIF
[679]639            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
640            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
641            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
[544]642         ENDIF
[679]643         ! Identify the domain in case of jpdom_local definition
644         IF( idom == jpdom_local ) THEN
645            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
646            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
647            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
648            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
649            ENDIF
650         ENDIF
[544]651         !
[679]652         ! check the consistency between input array and data rank in the file
[544]653         !
654         ! initializations
655         itime = 1
656         IF( PRESENT(ktime) ) itime = ktime
[679]657
658         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
659         WRITE(clrankpv, fmt='(i1)') irankpv
660         WRITE(cldmspc , fmt='(i1)') idmspc
[544]661         !
[679]662         IF(     idmspc <  irankpv ) THEN
663            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
664               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
665         ELSEIF( idmspc == irankpv ) THEN
666            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
667               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
668         ELSEIF( idmspc >  irankpv ) THEN
669               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
670                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
671                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
672                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
673                  idmspc = idmspc - 1
[544]674               ELSE
[679]675                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
676                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
677                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
[544]678               ENDIF
[679]679         ENDIF
680
681         !
682         ! definition of istart and icnt
683         !
684         icnt  (:) = 1
685         istart(:) = 1
686         istart(idmspc+1) = itime
687
688         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
689         ELSE
690            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
691            ELSE
692               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
[3432]693                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done below
694                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done below
[544]695                  ENDIF
[679]696                  ! we do not read the overlap                     -> we start to read at nldi, nldj
697! JMM + SM: ugly patch before getting the new version of lib_mpp)
698!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
[1200]699                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
[679]700                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej
701! JMM + SM: ugly patch before getting the new version of lib_mpp)
702!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
[1200]703                  IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
704                  ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /)
[544]705                  ENDIF
[679]706                  IF( PRESENT(pv_r3d) ) THEN
707                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
708                     ELSE                            ; icnt(3) = jpk
[544]709                     ENDIF
710                  ENDIF
711               ENDIF
[679]712            ENDIF
[544]713         ENDIF
714
715         ! check that istart and icnt can be used with this file
716         !-
717         DO jl = 1, jpmax_dims
718            itmp = istart(jl)+icnt(jl)-1
[679]719            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
720               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
721               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
[544]722               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
723            ENDIF
724         END DO
725
[3211]726         !! DCSE_NEMO: Allocate 3d work-array with z-index last
[3432]727         !!            to match layout on disk if ftrans in use
728         IF (lftrans .AND. PRESENT(pv_r3d)) THEN
[3211]729            ishape_pv_r3d = SHAPE(pv_r3d)
730            IF (ishape_pv_r3d(1) /= jpk) THEN
731               WRITE( ctmp1, FMT="('leading dimension is ',i5,', not ',i5,' (jpk) as expected')" ) &
732                  &  ishape_pv_r3d(1), jpk
733               CALL ctl_warn( trim(clinfo), 'beware: possible problem with 3d array, ', ctmp1 ) 
734            ENDIF
[3432]735            ! This assumes that the array we're to read has been ftrans'd in the
736            ! calling routine and therefore that it's z/depth index is its 1st
737            ! whereas on disk it will be its 3rd.
738            ALLOCATE(wpv_r3d(ishape_pv_r3d(2),ishape_pv_r3d(3),ishape_pv_r3d(1)),&
739                     STAT=istat_wpv_r3d)
[3211]740            IF (istat_wpv_r3d /= 0) THEN
741               CALL ctl_stop( trim(clinfo), 'failed to allocate wpv_r3d' )
742            ENDIF
743         ENDIF
744
[544]745         ! check that icnt matches the input array
746         !-     
[3211]747
748         !! DCSE_NEMO: beware! want ishape to match wpv_r3d, not pv_r3d
749
[679]750         IF( idom == jpdom_unknown ) THEN
751            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
752            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
[3432]753            IF( irankpv == 3 )THEN
754               IF( lftrans )THEN
755                  ishape(1:3) = SHAPE(wpv_r3d)
756               ELSE
757                  ishape(1:3) = SHAPE(pv_r3d)
758               END IF
759            END IF
[679]760            ctmp1 = 'd'
761         ELSE
762            IF( irankpv == 2 ) THEN
763! JMM + SM: ugly patch before getting the new version of lib_mpp)
764!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
[1200]765               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
766               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
[544]767               ENDIF
[679]768            ENDIF
769            IF( irankpv == 3 ) THEN 
770! JMM + SM: ugly patch before getting the new version of lib_mpp)
771!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
[3432]772               IF( lftrans )THEN
773                  IF( llnoov ) THEN
774                     ishape(1:3)=SHAPE(wpv_r3d(nldi:nlei,nldj:nlej,:))
775                     ctmp1='d(nldi:nlei,nldj:nlej,:)'
776                  ELSE
777                     ishape(1:3)=SHAPE(wpv_r3d(1   :nlci,1   :nlcj,:))
778                     ctmp1='d(1:nlci,1:nlcj,:)'
779                  ENDIF
[3211]780               ELSE
[3432]781                  IF( llnoov ) THEN
782                     ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))
783                     ctmp1='d(nldi:nlei,nldj:nlej,:)'
784                  ELSE
785                     ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:))
786                     ctmp1='d(1:nlci,1:nlcj,:)'
787                  ENDIF
788               ENDIF ! ftrans in use
[679]789            ENDIF
[3432]790         ENDIF ! ipdom == jpdom_unknown
[679]791         
792         DO jl = 1, irankpv
793            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
794            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
795         END DO
796
[544]797      ENDIF
798
799      ! read the data
800      !-     
[679]801      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
[544]802         !
[679]803         ! find the right index of the array to be read
804! JMM + SM: ugly patch before getting the new version of lib_mpp)
805!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
806!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
807!         ENDIF
[1200]808         IF( llnoov ) THEN
[679]809            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
810            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
811            ENDIF
812         ELSE
813            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
814            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
815            ENDIF
816         ENDIF
817     
[544]818         SELECT CASE (iom_file(kiomid)%iolib)
[3211]819         CASE (jpioipsl )
[3432]820            IF  (lftrans) THEN
[3211]821               CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, wpv_r3d )
822            ELSE
[3432]823               CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, pv_r3d )
[3211]824            ENDIF
825         CASE (jpnf90   )
[3432]826            IF (lftrans) THEN
[3211]827               CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, wpv_r3d )
828            ELSE
[3432]829               CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, pv_r3d )
[3211]830            ENDIF
831         CASE (jprstdimg)
[3432]832            IF (lftrans) THEN
[3211]833               CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, wpv_r3d )
834            ELSE
[3432]835               CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, pv_r3d )
[3211]836            ENDIF
837         CASE DEFAULT   
838            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
839         END SELECT
[679]840
[3211]841         !! DCSE_NEMO: if necessary, copy 3d work array back into pv_r3d,
842         !!            and de-allocate the work array
[3432]843         IF (lftrans .AND. PRESENT(pv_r3d)) THEN
844            ! This assumes that pv_r3d is ftrans'd in the calling routine so that
845            ! its first dimension rather than last dimension is 'z'
846            ! wpv_r3d is allocated with SHAPE(ishape_pv_r3d(2),ishape_pv_r3d(3),ishape_pv_r3d(1))
847            DO ji = 1, ishape_pv_r3d(2)
848               DO jj = 1, ishape_pv_r3d(3)
849                  DO jk = 1, ishape_pv_r3d(1)
[3211]850                     pv_r3d(jk, ji, jj) = wpv_r3d(ji, jj, jk)
851                  ENDDO
852               ENDDO
853            ENDDO
854            DEALLOCATE(wpv_r3d)
855         ENDIF
856
[679]857         IF( istop == nstop ) THEN   ! no additional errors until this point...
[1191]858            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i4,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
859         
[3211]860            !--- overlap areas and extra haloes (mpp)
[679]861            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
862               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
863            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
864               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
[4409]865               IF( icnt(3) == jpkorig ) THEN
[679]866                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
867               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
868                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
869                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
870               ENDIF
871            ENDIF
872           
873            !--- Apply scale_factor and offset
874            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
875            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
876            IF(     PRESENT(pv_r1d) ) THEN
877               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
878               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
879            ELSEIF( PRESENT(pv_r2d) ) THEN
[1697]880!CDIR COLLAPSE
[679]881               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
[1697]882!CDIR COLLAPSE
[679]883               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
884            ELSEIF( PRESENT(pv_r3d) ) THEN
[1697]885!CDIR COLLAPSE
[679]886               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
[1697]887!CDIR COLLAPSE
[679]888               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
889            ENDIF
890            !
[544]891         ENDIF
892         !
893      ENDIF
894      !
[3432]895      CALL timing_stop('iom_get_123d')
896
[544]897   END SUBROUTINE iom_get_123d
898
899
[911]900   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
[544]901      !!--------------------------------------------------------------------
902      !!                   ***  SUBROUTINE iom_gettime  ***
903      !!
904      !! ** Purpose : read the time axis cdvar in the file
905      !!--------------------------------------------------------------------
[911]906      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
907      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
908      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
909      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
910      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
911      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of
[544]912      !
[911]913      INTEGER, DIMENSION(1) :: kdimsz
[544]914      INTEGER            ::   idvar    ! id of the variable
[911]915      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
[544]916      CHARACTER(LEN=100) ::   clinfo   ! info character
917      !---------------------------------------------------------------------
918      !
[3432]919      CALL timing_start('iom_gettime')
920
[911]921      IF ( PRESENT(cdvar) ) THEN
922         tname = cdvar
923      ELSE
924         tname = iom_file(kiomid)%uldname
925      ENDIF
[679]926      IF( kiomid > 0 ) THEN
[911]927         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
928         IF ( PRESENT(kntime) ) THEN
929            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
930            kntime = kdimsz(1)
931         ELSE
932            idvar = iom_varid( kiomid, tname )
933         ENDIF
[679]934         !
935         ptime(:) = 0. ! default definition
936         IF( idvar > 0 ) THEN
937            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
938               IF( iom_file(kiomid)%luld(idvar) ) THEN
[2499]939                  IF( iom_file(kiomid)%dimsz(1,idvar) <= size(ptime) ) THEN
[679]940                     SELECT CASE (iom_file(kiomid)%iolib)
[911]941                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
942                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
[679]943                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
944                     CASE DEFAULT   
945                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
946                     END SELECT
947                  ELSE
948                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
949                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
950                  ENDIF
[544]951               ELSE
[679]952                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
[544]953               ENDIF
954            ELSE
[679]955               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
[544]956            ENDIF
957         ELSE
[679]958            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
[544]959         ENDIF
960      ENDIF
961      !
[3432]962      CALL timing_stop('iom_gettime')
963      !
[544]964   END SUBROUTINE iom_gettime
965
966
967   !!----------------------------------------------------------------------
[2528]968   !!                   INTERFACE iom_getatt
969   !!----------------------------------------------------------------------
970   SUBROUTINE iom_g0d_intatt( kiomid, cdatt, pvar )
971      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
972      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute
973      INTEGER         , INTENT(  out)                 ::   pvar      ! read field
974      !
975      IF( kiomid > 0 ) THEN
976         IF( iom_file(kiomid)%nfid > 0 ) THEN
977            SELECT CASE (iom_file(kiomid)%iolib)
978            CASE (jpioipsl )   ;   CALL ctl_stop('iom_getatt: only nf90 available')
979            CASE (jpnf90   )   ;   CALL iom_nf90_getatt( kiomid, cdatt, pvar )
980            CASE (jprstdimg)   ;   CALL ctl_stop('iom_getatt: only nf90 available')
981            CASE DEFAULT   
982               CALL ctl_stop( 'iom_g0d_att: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
983            END SELECT
984         ENDIF
985      ENDIF
986   END SUBROUTINE iom_g0d_intatt
987
988
989   !!----------------------------------------------------------------------
[544]990   !!                   INTERFACE iom_rstput
991   !!----------------------------------------------------------------------
[550]992   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
[544]993      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
994      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
995      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
996      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[556]997      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
[544]998      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
999      INTEGER :: ivid   ! variable id
[679]1000      IF( kiomid > 0 ) THEN
[3432]1001!         CALL timing_start('iom_rp0d')
[679]1002         IF( iom_file(kiomid)%nfid > 0 ) THEN
[745]1003            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[679]1004            SELECT CASE (iom_file(kiomid)%iolib)
1005            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
1006            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
1007            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
1008            CASE DEFAULT     
1009               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1010            END SELECT
1011         ENDIF
[3432]1012!         CALL timing_stop('iom_rp0d')
[679]1013      ENDIF
[550]1014   END SUBROUTINE iom_rp0d
[544]1015
[550]1016   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
[544]1017      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1018      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1019      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1020      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[2715]1021      REAL(wp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
[544]1022      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1023      INTEGER :: ivid   ! variable id
[679]1024      IF( kiomid > 0 ) THEN
[3432]1025!         CALL timing_start('iom_rp1d')
[679]1026         IF( iom_file(kiomid)%nfid > 0 ) THEN
[745]1027            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[679]1028            SELECT CASE (iom_file(kiomid)%iolib)
1029            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
1030            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
1031            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
1032            CASE DEFAULT     
1033               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1034            END SELECT
1035         ENDIF
[3432]1036!         CALL timing_stop('iom_rp1d')
[679]1037      ENDIF
[550]1038   END SUBROUTINE iom_rp1d
[544]1039
[550]1040   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
[544]1041      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1042      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1043      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1044      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[2715]1045      REAL(wp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
[544]1046      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1047      INTEGER :: ivid   ! variable id
[679]1048      IF( kiomid > 0 ) THEN
[3432]1049!         CALL timing_start('iom_rp2d')
[679]1050         IF( iom_file(kiomid)%nfid > 0 ) THEN
[745]1051            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[679]1052            SELECT CASE (iom_file(kiomid)%iolib)
1053            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
1054            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
1055            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
1056            CASE DEFAULT     
1057               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
1058            END SELECT
1059         ENDIF
[3432]1060!         CALL timing_stop('iom_rp2d')
[679]1061      ENDIF
[550]1062   END SUBROUTINE iom_rp2d
[544]1063
[550]1064   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
[544]1065      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
1066      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
1067      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file
1068      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
[2715]1069      REAL(wp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
[544]1070      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
1071      INTEGER :: ivid   ! variable id
[3211]1072#if defined key_z_first
1073      !! DCSE_NEMO: Need to transpose the dimensions of pvar from internal to external orderings
1074      !  We do not use ftrans here
1075      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)              ::   pvar_trans    ! transposed pvar
1076      INTEGER                                              ::   ji, jj, jk    ! Dummy loop indices
[679]1077      IF( kiomid > 0 ) THEN
[3432]1078!         CALL timing_start('iom_rp3d')
[679]1079         IF( iom_file(kiomid)%nfid > 0 ) THEN
[745]1080            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
[3211]1081            IF (      (SIZE(pvar, DIM=1) /= jpk )   &
1082               & .OR. (SIZE(pvar, DIM=2) /= jpi )   &
1083               & .OR. (SIZE(pvar, DIM=3) /= jpj ) ) THEN
1084               CALL ctl_stop( 'iom_rp3d: unexpected shape for variable ', cdvar )
1085            END IF
1086            ALLOCATE( pvar_trans(jpi, jpj, jpk) )
1087            DO jk = 1, jpk
1088               DO jj = 1, jpj
1089                  DO ji = 1, jpi
1090                     pvar_trans(ji, jj, jk) = pvar(jk, ji, jj)
1091                  END DO
1092               END DO
1093            END DO
[679]1094            SELECT CASE (iom_file(kiomid)%iolib)
[3211]1095            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar_trans )
1096            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar_trans )
1097            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar_trans )
1098            CASE DEFAULT     
1099               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
1100            END SELECT
1101            DEALLOCATE( pvar_trans )
1102         ENDIF
[3432]1103!         CALL timing_stop('iom_rp3d')
[3211]1104      ENDIF
1105#else
1106      IF( kiomid > 0 ) THEN
[3432]1107!         CALL timing_start('iom_rp3d')
[3211]1108         IF( iom_file(kiomid)%nfid > 0 ) THEN
1109            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
1110            SELECT CASE (iom_file(kiomid)%iolib)
[679]1111            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
1112            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
1113            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
1114            CASE DEFAULT     
1115               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
1116            END SELECT
1117         ENDIF
[3432]1118!         CALL timing_stop('iom_rp3d')
[679]1119      ENDIF
[3211]1120#endif
[550]1121   END SUBROUTINE iom_rp3d
[1359]1122
1123
[544]1124   !!----------------------------------------------------------------------
[1457]1125   !!                   INTERFACE iom_put
[1359]1126   !!----------------------------------------------------------------------
[1738]1127   SUBROUTINE iom_p0d( cdname, pfield0d )
1128      CHARACTER(LEN=*), INTENT(in) ::   cdname
1129      REAL(wp)        , INTENT(in) ::   pfield0d
1130#if defined key_iomput
1131      CALL event__write_field2D( cdname, RESHAPE( (/pfield0d/), (/1,1/) ) )
1132#else
1133      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
1134#endif
1135   END SUBROUTINE iom_p0d
1136
[1359]1137   SUBROUTINE iom_p2d( cdname, pfield2d )
1138      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
[2715]1139      REAL(wp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
[1412]1140#if defined key_iomput
[1359]1141      CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
[1520]1142#else
1143      IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
[1359]1144#endif
1145   END SUBROUTINE iom_p2d
[544]1146
[1359]1147   SUBROUTINE iom_p3d( cdname, pfield3d )
1148      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
[2715]1149      REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
[1412]1150#if defined key_iomput
[3211]1151#if defined key_z_first
1152!FTRANS ASSERT :z :I
1153!FTRANS pfield3d :I :I :z
1154      CALL event__write_field3D( cdname, permute_z_last(pfield3d(nldi:nlei, nldj:nlej, :)) )
1155#else
1156!FTRANS ASSERT :I :z
[1359]1157      CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
[3211]1158#endif
[1520]1159#else
1160      IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
[1359]1161#endif
1162   END SUBROUTINE iom_p3d
1163   !!----------------------------------------------------------------------
[544]1164
[1359]1165
[1412]1166#if defined key_iomput
[1359]1167
1168   SUBROUTINE set_grid( cdname, plon, plat )
1169      !!----------------------------------------------------------------------
1170      !!                     ***  ROUTINE   ***
1171      !!
[1725]1172      !! ** Purpose :   define horizontal grids
[1359]1173      !!
1174      !!----------------------------------------------------------------------
1175      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
1176      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
1177      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
1178
1179      CALL event__set_grid_dimension( cdname, jpiglo, jpjglo)
1180      CALL event__set_grid_domain( cdname, nlei-nldi+1, nlej-nldj+1, nimpp+nldi-1, njmpp+nldj-1, &
1181         &                         plon(nldi:nlei, nldj:nlej), plat(nldi:nlei, nldj:nlej) )
1182      CALL event__set_grid_type_nemo( cdname )
1183
1184   END SUBROUTINE set_grid
1185
[1725]1186
[1738]1187   SUBROUTINE set_scalar
1188      !!----------------------------------------------------------------------
1189      !!                     ***  ROUTINE   ***
1190      !!
1191      !! ** Purpose :   define fake grids for scalar point
1192      !!
1193      !!----------------------------------------------------------------------
1194      REAL(wp), DIMENSION(1,1) ::   zz = 1.
1195      !!----------------------------------------------------------------------
1196      CALL event__set_grid_dimension( 'scalarpoint', jpnij, 1)
1197      CALL event__set_grid_domain   ( 'scalarpoint', 1, 1, narea, 1, zz, zz )
1198      CALL event__set_grid_type_nemo( 'scalarpoint' )
1199
1200   END SUBROUTINE set_scalar
1201
1202
[1725]1203   SUBROUTINE set_xmlatt
1204      !!----------------------------------------------------------------------
1205      !!                     ***  ROUTINE   ***
1206      !!
1207      !! ** Purpose :   automatic definitions of some of the xml attributs...
1208      !!
1209      !!----------------------------------------------------------------------
[1743]1210      CHARACTER(len=6),DIMENSION( 8) ::   clsuff                   ! suffix name
[1725]1211      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
1212      CHARACTER(len=50)              ::   clname                   ! file name
1213      CHARACTER(len=1)               ::   cl1                      ! 1 character
1214      CHARACTER(len=2)               ::   cl2                      ! 1 character
1215      INTEGER                        ::   idt                      ! time-step in seconds
[1731]1216      INTEGER                        ::   iddss, ihhss             ! number of seconds in 1 day, 1 hour and 1 year
1217      INTEGER                        ::   iyymo                    ! number of months in 1 year
1218      INTEGER                        ::   jg, jh, jd, jm, jy       ! loop counters
[1725]1219      INTEGER                        ::   ix, iy                   ! i-,j- index
1220      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
1221      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
1222      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
1223      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
1224      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
1225      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
1226      !!----------------------------------------------------------------------
1227      !
1228      idt   = NINT( rdttra(1)     )
1229      iddss = NINT( rday          )                                         ! number of seconds in 1 day
1230      ihhss = NINT( rmmss * rhhmm )                                         ! number of seconds in 1 hour
[1731]1231      iyymo = NINT( raamo         )                                         ! number of months in 1 year
[1725]1232
1233      ! frequency of the call of iom_put (attribut: freq_op)
1234      CALL event__set_attribut( 'field_definition', attr( field__freq_op, idt           ) )    ! model time-step
1235      CALL event__set_attribut( 'SBC'             , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
1236     
1237      ! output file names (attribut: name)
[1743]1238      clsuff(:) = (/ 'grid_T', 'grid_U', 'grid_V', 'grid_W', 'icemod', 'ptrc_T', 'diad_T', 'scalar' /)     
[1725]1239      DO jg = 1, SIZE(clsuff)                                                                  ! grid type
1240         DO jh = 1, 12                                                                         ! 1, 2, 3, 4, 6, 12 hours
1241            IF( MOD(12,jh) == 0 ) THEN
1242               WRITE(cl2,'(i2)') jh 
1243               CALL dia_nam( clname, jh * ihhss, clsuff(jg), ldfsec = .TRUE. )
1244               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1245            ENDIF
1246         END DO
1247         DO jd = 1, 5, 2                                                                       ! 1, 3, 5 days
1248            WRITE(cl1,'(i1)') jd 
1249            CALL dia_nam( clname, jd * iddss, clsuff(jg), ldfsec = .TRUE. )
1250            CALL event__set_attribut( cl1//'d_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1251         END DO
[1731]1252         DO jm = 1, 6                                                                          ! 1, 2, 3, 4, 6 months
1253            IF( MOD(6,jm) == 0 ) THEN
1254               WRITE(cl1,'(i1)') jm 
1255               CALL dia_nam( clname, -jm, clsuff(jg) )
1256               CALL event__set_attribut( cl1//'m_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1257            ENDIF
1258         END DO
[1725]1259         DO jy = 1, 10                                                                         ! 1, 2, 5, 10 years 
1260            IF( MOD(10,jy) == 0 ) THEN
1261               WRITE(cl2,'(i2)') jy 
[1731]1262               CALL dia_nam( clname, -jy * iyymo, clsuff(jg) )
[1725]1263               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
1264            ENDIF
1265         END DO
1266      END DO
1267
1268      ! Zooms...
1269      clgrd = (/ 'T', 'U', 'W' /) 
1270      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
1271         cl1 = clgrd(jg)
1272         ! Equatorial section (attributs: jbegin, ni, name_suffix)
1273         CALL dom_ngb( 0., 0., ix, iy, cl1 )
1274         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__jbegin     , iy     ) )
1275         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__ni         , jpiglo ) )
1276         CALL event__set_attribut( 'Eq'//cl1, attr( file__name_suffix, '_Eq'  ) )
1277      END DO
1278      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
1279      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
1280      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
1281      CALL set_mooring( zlontao, zlattao )
1282      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
1283      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
1284      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
1285      CALL set_mooring( zlonrama, zlatrama )
1286      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
1287      zlonpira = (/ -38.0, -23.0, -10.0 /)
1288      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
1289      CALL set_mooring( zlonpira, zlatpira )
1290     
1291   END SUBROUTINE set_xmlatt
1292
1293
1294   SUBROUTINE set_mooring( plon, plat)
1295      !!----------------------------------------------------------------------
1296      !!                     ***  ROUTINE   ***
1297      !!
1298      !! ** Purpose :   automatic definitions of moorings xml attributs...
1299      !!
1300      !!----------------------------------------------------------------------
1301      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
1302      !
1303!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
1304      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
1305      CHARACTER(len=50)             ::   clname                   ! file name
1306      CHARACTER(len=1)              ::   cl1                      ! 1 character
1307      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
1308      INTEGER                       ::   ji, jj, jg               ! loop counters
1309      INTEGER                       ::   ix, iy                   ! i-,j- index
1310      REAL(wp)                      ::   zlon, zlat
1311      !!----------------------------------------------------------------------
1312      DO jg = 1, SIZE(clgrd)
1313         cl1 = clgrd(jg)
1314         DO ji = 1, SIZE(plon)
1315            DO jj = 1, SIZE(plat)
1316               zlon = plon(ji)
1317               zlat = plat(jj)
1318               ! modifications for RAMA moorings
1319               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
1320               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
1321               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
1322               ! modifications for PIRATA moorings
1323               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
1324               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
1325               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
1326               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
1327               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
1328               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
1329               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
1330               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
1331               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
1332               IF( zlon >= 0. ) THEN 
1333                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
1334                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
1335                  ENDIF
1336               ELSE             
1337                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
1338                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
1339                  ENDIF
1340               ENDIF
1341               IF( zlat >= 0. ) THEN 
1342                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
1343                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
1344                  ENDIF
1345               ELSE             
1346                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
1347                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
1348                  ENDIF
1349               ENDIF
1350               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
1351               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__ibegin     , ix                ) )
1352               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__jbegin     , iy                ) )
1353               CALL event__set_attribut( TRIM(clname)//cl1, attr( file__name_suffix, '_'//TRIM(clname) ) )     
1354            END DO
1355         END DO
1356      END DO
1357     
1358   END SUBROUTINE set_mooring
1359
[1359]1360#else
1361
1362   SUBROUTINE iom_setkt( kt )
1363      INTEGER, INTENT(in   )::   kt 
[1520]1364      IF( .FALSE. )   WRITE(numout,*) kt   ! useless test to avoid compilation warnings
[1359]1365   END SUBROUTINE iom_setkt
1366
1367#endif
1368
1369
[544]1370   !!======================================================================
1371END MODULE iom
Note: See TracBrowser for help on using the repository browser.