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/2013/dev_r3411_CNRS4_IOCRS/NEMOGCM/CONFIG/ORCA2_LIM_CRS/MY_SRC – NEMO

source: branches/2013/dev_r3411_CNRS4_IOCRS/NEMOGCM/CONFIG/ORCA2_LIM_CRS/MY_SRC/iom.F90 @ 3622

Last change on this file since 3622 was 3622, checked in by cetlod, 11 years ago

branch 2013/dev_r3411_CNRS4_IOCRS : 1st inputs of I/O coarsening, see ticket #1009

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