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/dev_r4028_CNRS_LIM3_MV2014/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/dev_r4028_CNRS_LIM3_MV2014/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90 @ 4525

Last change on this file since 4525 was 4525, checked in by flavoni, 10 years ago

change limwri.F90, use iom_put for all variables

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