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.
bdydta.F90 in branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/BDY – NEMO

source: branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90 @ 3211

Last change on this file since 3211 was 3211, checked in by spickles2, 12 years ago

Stephen Pickles, 11 Dec 2011

Commit to bring the rest of the DCSE NEMO development branch
in line with the latest development version. This includes
array index re-ordering of all OPA_SRC/.

  • Property svn:keywords set to Id
File size: 50.7 KB
Line 
1MODULE bdydta
2   !!======================================================================
3   !!                       ***  MODULE bdydta  ***
4   !! Open boundary data : read the data for the unstructured open boundaries.
5   !!======================================================================
6   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
7   !!             -   !  2007-01  (D. Storkey) Update to use IOM module
8   !!             -   !  2007-07  (D. Storkey) add bdy_dta_fla
9   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
10   !!            3.3  !  2010-09  (E.O'Dea) modifications for Shelf configurations
11   !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
12   !!----------------------------------------------------------------------
13#if defined key_bdy
14   !!----------------------------------------------------------------------
15   !!   'key_bdy'                     Unstructured Open Boundary Conditions
16   !!----------------------------------------------------------------------
17   !!   bdy_dta_frs    : read u, v, t, s data along open boundaries
18   !!   bdy_dta_fla : read depth-mean velocities and elevation along open boundaries       
19   !!----------------------------------------------------------------------
20   USE oce             ! ocean dynamics and tracers
21   USE dom_oce         ! ocean space and time domain
22   USE phycst          ! physical constants
23   USE bdy_oce         ! ocean open boundary conditions
24   USE bdytides        ! tidal forcing at boundaries
25   USE iom
26   USE ioipsl
27   USE in_out_manager  ! I/O logical units
28#if defined key_lim2
29   USE ice_2
30#endif
31
32   IMPLICIT NONE
33   PRIVATE
34
35   PUBLIC   bdy_dta_frs      ! routines called by step.F90
36   PUBLIC   bdy_dta_fla 
37   PUBLIC   bdy_dta_alloc    ! routine called by bdy_init.F90
38
39   INTEGER ::   numbdyt, numbdyu, numbdyv                      ! logical units for T-, U-, & V-points data file, resp.
40   INTEGER ::   ntimes_bdy                                     ! exact number of time dumps in data files
41   INTEGER ::   nbdy_b, nbdy_a                                 ! record of bdy data file for before and after time step
42   INTEGER ::   numbdyt_bt, numbdyu_bt, numbdyv_bt             ! logical unit for T-, U- & V-points data file, resp.
43   INTEGER ::   ntimes_bdy_bt                                  ! exact number of time dumps in data files
44   INTEGER ::   nbdy_b_bt, nbdy_a_bt                           ! record of bdy data file for before and after time step
45
46   INTEGER, DIMENSION (jpbtime) ::   istep, istep_bt           ! time array in seconds in each data file
47
48   REAL(wp) ::  zoffset                                        ! time offset between time origin in file & start time of model run
49
50   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tbdydta, sbdydta   ! time interpolated values of T and S bdy data   
51   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ubdydta, vbdydta   ! time interpolated values of U and V bdy data
52   REAL(wp), DIMENSION(jpbdim,2)     ::   ubtbdydta, vbtbdydta ! Arrays used for time interpolation of bdy data   
53   REAL(wp), DIMENSION(jpbdim,2)     ::   sshbdydta            ! bdy data of ssh
54
55#if defined key_lim2
56   REAL(wp), DIMENSION(jpbdim,2)     ::   frld_bdydta          ! }
57   REAL(wp), DIMENSION(jpbdim,2)     ::   hicif_bdydta         ! } Arrays used for time interp. of ice bdy data
58   REAL(wp), DIMENSION(jpbdim,2)     ::   hsnif_bdydta         ! }
59#endif
60
61   !! * Control permutation of array indices
62#  include "oce_ftrans.h90"
63#  include "dom_oce_ftrans.h90"
64
65   !!----------------------------------------------------------------------
66   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
67   !! $Id$
68   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
69   !!----------------------------------------------------------------------
70CONTAINS
71
72  FUNCTION bdy_dta_alloc()
73     !!----------------------------------------------------------------------
74     USE lib_mpp, ONLY: ctl_warn, mpp_sum
75     !
76     INTEGER :: bdy_dta_alloc
77     !!----------------------------------------------------------------------
78     !
79     ALLOCATE(tbdydta(jpbdim,jpk,2), sbdydta(jpbdim,jpk,2), &
80              ubdydta(jpbdim,jpk,2), vbdydta(jpbdim,jpk,2), Stat=bdy_dta_alloc)
81
82     IF( lk_mpp           ) CALL mpp_sum ( bdy_dta_alloc )
83     IF(bdy_dta_alloc /= 0) CALL ctl_warn('bdy_dta_alloc: failed to allocate arrays')
84
85   END FUNCTION bdy_dta_alloc
86
87
88   SUBROUTINE bdy_dta_frs( kt )
89      !!----------------------------------------------------------------------
90      !!                   ***  SUBROUTINE bdy_dta_frs  ***
91      !!                   
92      !! ** Purpose :   Read unstructured boundary data for FRS condition.
93      !!
94      !! ** Method  :   At the first timestep, read in boundary data for two
95      !!                times from the file and time-interpolate. At other
96      !!                timesteps, check to see if we need another time from
97      !!                the file. If so read it in. Time interpolate.
98      !!----------------------------------------------------------------------
99      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index (for timesplitting option, otherwise zero)
100      !!
101      CHARACTER(LEN=80), DIMENSION(3) ::   clfile               ! names of input files
102      CHARACTER(LEN=70 )              ::   clunits              ! units attribute of time coordinate
103      LOGICAL ::   lect                                         ! flag for reading
104      INTEGER ::   it, ib, ik, igrd                             ! dummy loop indices
105      INTEGER ::   igrd_start, igrd_end                         ! start and end of loops on igrd
106      INTEGER ::   idvar                                        ! netcdf var ID
107      INTEGER ::   iman, i15, imois                             ! Time variables for monthly clim forcing
108      INTEGER ::   ntimes_bdyt, ntimes_bdyu, ntimes_bdyv
109      INTEGER ::   itimer, totime
110      INTEGER ::   ii, ij                                       ! array addresses
111      INTEGER ::   ipi, ipj, ipk, inum                          ! local integers (NetCDF read)
112      INTEGER ::   iyear0, imonth0, iday0
113      INTEGER ::   ihours0, iminutes0, isec0
114      INTEGER ::   iyear, imonth, iday, isecs
115      INTEGER, DIMENSION(jpbtime) ::   istept, istepu, istepv   ! time arrays from data files
116      REAL(wp) ::   dayfrac, zxy, zoffsett
117      REAL(wp) ::   zoffsetu, zoffsetv
118      REAL(wp) ::   dayjul0, zdayjulini
119      REAL(wp), DIMENSION(jpbtime)      ::   zstepr             ! REAL time array from data files
120!! DCSE_NEMO: do not ftrans! Beware!
121      REAL(wp), DIMENSION(jpbdta,1,jpk) ::   zdta               ! temporary array for data fields
122      !!---------------------------------------------------------------------------
123
124
125      IF( ln_dyn_frs .OR. ln_tra_frs    &
126         &               .OR. ln_ice_frs ) THEN  ! If these are both false then this routine does nothing
127
128      ! -------------------- !
129      !    Initialization    !
130      ! -------------------- !
131
132      lect   = .false.           ! If true, read a time record
133
134      ! Some time variables for monthly climatological forcing:
135      ! *******************************************************
136
137!!gm  here  use directely daymod calendar variables
138 
139      iman = INT( raamo )      ! Number of months in a year
140
141      i15 = INT( 2*REAL( nday, wp ) / ( REAL( nmonth_len(nmonth), wp ) + 0.5 ) )
142      ! i15=0 if the current day is in the first half of the month, else i15=1
143
144      imois = nmonth + i15 - 1            ! imois is the first month record
145      IF( imois == 0 )   imois = iman
146
147      ! Time variable for non-climatological forcing:
148      ! *********************************************
149      itimer = (kt-nit000+1)*rdt      ! current time in seconds for interpolation
150
151
152      !                                                !-------------------!
153      IF( kt == nit000 ) THEN                          !  First call only  !
154         !                                             !-------------------!
155         istep(:) = 0
156         nbdy_b   = 0
157         nbdy_a   = 0
158
159         ! Get time information from bdy data file
160         ! ***************************************
161
162         IF(lwp) WRITE(numout,*)
163         IF(lwp) WRITE(numout,*)    'bdy_dta_frs : Initialize unstructured boundary data'
164         IF(lwp) WRITE(numout,*)    '~~~~~~~' 
165
166         IF     ( nn_dtactl == 0 ) THEN
167            !
168            IF(lwp) WRITE(numout,*) '          Bdy data are taken from initial conditions'
169            !
170         ELSEIF (nn_dtactl == 1) THEN
171            !
172            IF(lwp) WRITE(numout,*) '          Bdy data are read in netcdf files'
173            !
174            dayfrac = adatrj  - REAL( itimer, wp ) / 86400.   ! day fraction at time step kt-1
175            dayfrac = dayfrac - INT ( dayfrac )               !
176            totime  = ( nitend - nit000 + 1 ) * rdt           ! Total time of the run to verify that all the
177            !                                                 ! necessary time dumps in file are included
178            !
179            clfile(1) = cn_dta_frs_T
180            clfile(2) = cn_dta_frs_U
181            clfile(3) = cn_dta_frs_V
182            !                                                 
183            ! how many files are we to read in?
184            igrd_start = 1
185            igrd_end   = 3
186            IF(.NOT. ln_tra_frs .AND. .NOT. ln_ice_frs) THEN       ! No T-grid file.
187               igrd_start = 2
188            ELSEIF ( .NOT. ln_dyn_frs ) THEN                           ! No U-grid or V-grid file.
189               igrd_end   = 1         
190            ENDIF
191
192            DO igrd = igrd_start, igrd_end                     !  loop over T, U & V grid  !
193               !                                               !---------------------------!
194               CALL iom_open( clfile(igrd), inum )
195               CALL iom_gettime( inum, zstepr, kntime=ntimes_bdy, cdunits=clunits ) 
196
197               SELECT CASE( igrd )
198                  CASE (1)   ;   numbdyt = inum
199                  CASE (2)   ;   numbdyu = inum
200                  CASE (3)   ;   numbdyv = inum
201               END SELECT
202
203               ! Calculate time offset
204               READ(clunits,7000) iyear0, imonth0, iday0, ihours0, iminutes0, isec0
205               ! Convert time origin in file to julian days
206               isec0 = isec0 + ihours0*60.*60. + iminutes0*60.
207               CALL ymds2ju(iyear0, imonth0, iday0, REAL(isec0, wp), dayjul0)
208               ! Compute model initialization time
209               iyear  = ndastp / 10000
210               imonth = ( ndastp - iyear * 10000 ) / 100
211               iday   = ndastp - iyear * 10000 - imonth * 100
212               isecs  = dayfrac * 86400
213               CALL ymds2ju(iyear, imonth, iday, REAL(isecs, wp) , zdayjulini)
214               ! offset from initialization date:
215               zoffset = (dayjul0-zdayjulini)*86400
216               !
2177000           FORMAT('seconds since ', I4.4,'-',I2.2,'-',I2.2,' ',I2.2,':',I2.2,':',I2.2)
218
219               !! TO BE DONE... Check consistency between calendar from file
220               !! (available optionally from iom_gettime) and calendar in model
221               !! when calendar in model available outside of IOIPSL.
222
223               IF(lwp) WRITE(numout,*) 'number of times: ',ntimes_bdy
224               IF(lwp) WRITE(numout,*) 'offset: ',zoffset
225               IF(lwp) WRITE(numout,*) 'totime: ',totime
226               IF(lwp) WRITE(numout,*) 'zstepr: ',zstepr(1:ntimes_bdy)
227
228               ! Check that there are not too many times in the file.
229               IF( ntimes_bdy > jpbtime ) THEN
230                  WRITE(ctmp1,*) 'Check file: ', clfile(igrd), 'jpbtime= ', jpbtime, ' ntimes_bdy= ', ntimes_bdy
231                  CALL ctl_stop( 'Number of time dumps in files exceed jpbtime parameter', ctmp1 )
232               ENDIF
233
234               ! Check that time array increases:
235               it = 1
236               DO WHILE( zstepr(it+1) > zstepr(it) .AND. it /= ntimes_bdy - 1 ) 
237                  it = it + 1
238               END DO
239               !
240               IF( it /= ntimes_bdy-1 .AND. ntimes_bdy > 1 ) THEN
241                     WRITE(ctmp1,*) 'Check file: ', clfile(igrd)
242                     CALL ctl_stop( 'Time array in unstructured boundary data files',   &
243                        &           'does not continuously increase.'               , ctmp1 )
244               ENDIF
245               !
246               ! Check that times in file span model run time:
247               IF( zstepr(1) + zoffset > 0 ) THEN
248                     WRITE(ctmp1,*) 'Check file: ', clfile(igrd)
249                     CALL ctl_stop( 'First time dump in bdy file is after model initial time', ctmp1 )
250               END IF
251               IF( zstepr(ntimes_bdy) + zoffset < totime ) THEN
252                     WRITE(ctmp1,*) 'Check file: ', clfile(igrd)
253                     CALL ctl_stop( 'Last time dump in bdy file is before model final time', ctmp1 )
254               END IF
255               !
256               SELECT CASE( igrd )
257                  CASE (1)
258                    ntimes_bdyt = ntimes_bdy
259                    zoffsett = zoffset
260                    istept(:) = INT( zstepr(:) + zoffset )
261                    numbdyt = inum
262                  CASE (2)
263                    ntimes_bdyu = ntimes_bdy
264                    zoffsetu = zoffset
265                    istepu(:) = INT( zstepr(:) + zoffset )
266                    numbdyu = inum
267                  CASE (3)
268                    ntimes_bdyv = ntimes_bdy
269                    zoffsetv = zoffset
270                    istepv(:) = INT( zstepr(:) + zoffset )
271                    numbdyv = inum
272               END SELECT
273               !
274            END DO                                         ! end loop over T, U & V grid
275
276            IF (igrd_start == 1 .and. igrd_end == 3) THEN
277               ! Only test differences if we are reading in 3 files
278               ! Verify time consistency between files 
279               IF( ntimes_bdyu /= ntimes_bdyt .OR. ntimes_bdyv /= ntimes_bdyt ) THEN
280                  CALL ctl_stop( 'Bdy data files must have the same number of time dumps',   &
281                  &           'Multiple time frequencies not implemented yet'  )
282               ENDIF
283               ntimes_bdy = ntimes_bdyt
284               !
285               IF( zoffsetu /= zoffsett .OR. zoffsetv /= zoffsett ) THEN
286                  CALL ctl_stop( 'Bdy data files must have the same time origin',   &
287                  &           'Multiple time frequencies not implemented yet' )
288               ENDIF
289               zoffset = zoffsett
290            ENDIF
291
292            IF( igrd_start == 1 ) THEN   ;   istep(:) = istept(:)
293            ELSE                         ;   istep(:) = istepu(:)
294            ENDIF
295
296            ! Check number of time dumps:             
297            IF( ntimes_bdy == 1 .AND. .NOT. ln_clim ) THEN
298              CALL ctl_stop( 'There is only one time dump in data files',   &
299                 &           'Choose ln_clim=.true. in namelist for constant bdy forcing.' )
300            ENDIF
301
302            IF( ln_clim ) THEN
303              IF( ntimes_bdy /= 1 .AND. ntimes_bdy /= 12 ) THEN
304                 CALL ctl_stop( 'For climatological boundary forcing (ln_clim=.true.),',   &
305                    &           'bdy data files must contain 1 or 12 time dumps.' )
306              ELSEIF( ntimes_bdy ==  1 ) THEN
307                IF(lwp) WRITE(numout,*)
308                IF(lwp) WRITE(numout,*) 'We assume constant boundary forcing from bdy data files'
309              ELSEIF( ntimes_bdy == 12 ) THEN
310                IF(lwp) WRITE(numout,*)
311                IF(lwp) WRITE(numout,*) 'We assume monthly (and cyclic) boundary forcing from bdy data files'
312              ENDIF
313            ENDIF
314
315            ! Find index of first record to read (before first model time).
316            it = 1
317            DO WHILE( istep(it+1) <= 0 .AND. it <= ntimes_bdy - 1 )
318               it = it + 1
319            END DO
320            nbdy_b = it
321            !
322            IF(lwp) WRITE(numout,*) 'Time offset is ',zoffset
323            IF(lwp) WRITE(numout,*) 'First record to read is ',nbdy_b
324
325         ENDIF ! endif (nn_dtactl == 1)
326
327
328         ! 1.2  Read first record in file if necessary (ie if nn_dtactl == 1)
329         ! *****************************************************************
330
331         IF( nn_dtactl == 0 ) THEN      ! boundary data arrays are filled with initial conditions
332            !
333            IF (ln_tra_frs) THEN
334               igrd = 1            ! T-points data
335               DO ib = 1, nblen(igrd)
336                  ii = nbi(ib,igrd)
337                  ij = nbj(ib,igrd)
338                  DO ik = 1, jpkm1
339                     tbdy(ib,ik) = tn(ii,ij,ik)
340                     sbdy(ib,ik) = sn(ii,ij,ik)
341                  END DO
342               END DO
343            ENDIF
344
345            IF(ln_dyn_frs) THEN
346               igrd = 2            ! U-points data
347               DO ib = 1, nblen(igrd)
348                  ii = nbi(ib,igrd)
349                  ij = nbj(ib,igrd)
350                  DO ik = 1, jpkm1
351                     ubdy(ib,ik) = un(ii, ij, ik)
352                  END DO
353               END DO
354               !
355               igrd = 3            ! V-points data
356               DO ib = 1, nblen(igrd)           
357                  ii = nbi(ib,igrd)
358                  ij = nbj(ib,igrd)
359                  DO ik = 1, jpkm1
360                     vbdy(ib,ik) = vn(ii, ij, ik)
361                  END DO
362               END DO
363            ENDIF
364            !
365#if defined key_lim2
366            IF( ln_ice_frs ) THEN
367               igrd = 1            ! T-points data
368               DO ib = 1, nblen(igrd)
369                  frld_bdy (ib) =  frld(nbi(ib,igrd), nbj(ib,igrd))
370                  hicif_bdy(ib) = hicif(nbi(ib,igrd), nbj(ib,igrd))
371                  hsnif_bdy(ib) = hsnif(nbi(ib,igrd), nbj(ib,igrd))
372               END DO
373            ENDIF
374#endif
375         ELSEIF( nn_dtactl == 1 ) THEN    ! Set first record in the climatological case:   
376            !
377            IF( ln_clim .AND. ntimes_bdy == 1 ) THEN
378               nbdy_a = 1
379            ELSEIF( ln_clim .AND. ntimes_bdy == iman ) THEN
380               nbdy_b = 0
381               nbdy_a = imois
382            ELSE
383               nbdy_a = nbdy_b
384            ENDIF
385   
386            ! Read first record:
387            ipj  = 1
388            ipk  = jpk
389            igrd = 1
390            ipi  = nblendta(igrd)
391
392            IF(ln_tra_frs) THEN
393               !
394               igrd = 1                                           ! Temperature
395               IF( nblendta(igrd) <=  0 ) THEN
396                  idvar = iom_varid( numbdyt, 'votemper' )
397                  nblendta(igrd) = iom_file(numbdyt)%dimsz(1,idvar)
398               ENDIF
399               IF(lwp) WRITE(numout,*) 'Dim size for votemper is ', nblendta(igrd)
400               ipi = nblendta(igrd)
401               CALL iom_get ( numbdyt, jpdom_unknown, 'votemper', zdta(1:ipi,1:ipj,1:ipk), nbdy_a )
402               !
403               DO ib = 1, nblen(igrd)
404                  DO ik = 1, jpkm1
405                     tbdydta(ib,ik,2) =  zdta(nbmap(ib,igrd),1,ik)
406                  END DO
407               END DO
408               !
409               igrd = 1                                           ! salinity
410               IF( nblendta(igrd) .le. 0 ) THEN
411                  idvar = iom_varid( numbdyt, 'vosaline' )
412                  nblendta(igrd) = iom_file(numbdyt)%dimsz(1,idvar)
413               ENDIF
414               IF(lwp) WRITE(numout,*) 'Dim size for vosaline is ', nblendta(igrd)
415               ipi = nblendta(igrd)
416               CALL iom_get ( numbdyt, jpdom_unknown, 'vosaline', zdta(1:ipi,1:ipj,1:ipk), nbdy_a )
417               !
418               DO ib = 1, nblen(igrd)
419                  DO ik = 1, jpkm1
420                     sbdydta(ib,ik,2) =  zdta(nbmap(ib,igrd),1,ik)
421                  END DO
422               END DO
423            ENDIF  ! ln_tra_frs
424 
425            IF( ln_dyn_frs ) THEN
426               !
427               igrd = 2                                           ! u-velocity
428               IF ( nblendta(igrd) .le. 0 ) THEN
429                 idvar = iom_varid( numbdyu,'vozocrtx' )
430                 nblendta(igrd) = iom_file(numbdyu)%dimsz(1,idvar)
431               ENDIF
432               IF(lwp) WRITE(numout,*) 'Dim size for vozocrtx is ', nblendta(igrd)
433               ipi = nblendta(igrd)
434               CALL iom_get ( numbdyu, jpdom_unknown,'vozocrtx',zdta(1:ipi,1:ipj,1:ipk),nbdy_a )
435               DO ib = 1, nblen(igrd)
436                  DO ik = 1, jpkm1
437                     ubdydta(ib,ik,2) =  zdta(nbmap(ib,igrd),1,ik)
438                  END DO
439               END DO
440               !
441               igrd = 3                                           ! v-velocity
442               IF ( nblendta(igrd) .le. 0 ) THEN
443                 idvar = iom_varid( numbdyv,'vomecrty' )
444                 nblendta(igrd) = iom_file(numbdyv)%dimsz(1,idvar)
445               ENDIF
446               IF(lwp) WRITE(numout,*) 'Dim size for vomecrty is ', nblendta(igrd)
447               ipi = nblendta(igrd)
448               CALL iom_get ( numbdyv, jpdom_unknown,'vomecrty',zdta(1:ipi,1:ipj,1:ipk),nbdy_a )
449               DO ib = 1, nblen(igrd)
450                  DO ik = 1, jpkm1
451                     vbdydta(ib,ik,2) =  zdta(nbmap(ib,igrd),1,ik)
452                  END DO
453               END DO
454            ENDIF ! ln_dyn_frs
455
456#if defined key_lim2
457            IF( ln_ice_frs ) THEN
458              !
459              igrd=1                                              ! leads fraction
460              IF(lwp) WRITE(numout,*) 'Dim size for ildsconc is ',nblendta(igrd)
461              ipi=nblendta(igrd)
462              CALL iom_get ( numbdyt, jpdom_unknown,'ildsconc',zdta(1:ipi,:,1),nbdy_a )
463              DO ib=1, nblen(igrd)
464                frld_bdydta(ib,2) =  zdta(nbmap(ib,igrd),1,1)
465              END DO
466              !
467              igrd=1                                              ! ice thickness
468              IF(lwp) WRITE(numout,*) 'Dim size for iicethic is ',nblendta(igrd)
469              ipi=nblendta(igrd)
470              CALL iom_get ( numbdyt, jpdom_unknown,'iicethic',zdta(1:ipi,:,1),nbdy_a )
471              DO ib=1, nblen(igrd)
472                hicif_bdydta(ib,2) =  zdta(nbmap(ib,igrd),1,1)
473              END DO
474              !
475              igrd=1                                              ! snow thickness
476              IF(lwp) WRITE(numout,*) 'Dim size for isnowthi is ',nblendta(igrd)
477              ipi=nblendta(igrd)
478              CALL iom_get ( numbdyt, jpdom_unknown,'isnowthi',zdta(1:ipi,:,1),nbdy_a )
479              DO ib=1, nblen(igrd)
480                hsnif_bdydta(ib,2) =  zdta(nbmap(ib,igrd),1,1)
481              END DO
482            ENDIF ! just if ln_ice_frs is set
483#endif
484
485            IF( .NOT.ln_clim .AND. istep(1) > 0 ) THEN     ! First data time is after start of run
486               nbdy_b = nbdy_a                                 ! Put first value in both time levels
487               IF( ln_tra_frs ) THEN
488                 tbdydta(:,:,1) = tbdydta(:,:,2)
489                 sbdydta(:,:,1) = sbdydta(:,:,2)
490               ENDIF
491               IF( ln_dyn_frs ) THEN
492                 ubdydta(:,:,1) = ubdydta(:,:,2)
493                 vbdydta(:,:,1) = vbdydta(:,:,2)
494               ENDIF
495#if defined key_lim2
496               IF( ln_ice_frs ) THEN
497                  frld_bdydta (:,1) =  frld_bdydta(:,2)
498                  hicif_bdydta(:,1) = hicif_bdydta(:,2)
499                  hsnif_bdydta(:,1) = hsnif_bdydta(:,2)
500               ENDIF
501#endif
502            END IF
503            !
504         END IF   ! nn_dtactl == 0/1
505 
506         ! In the case of constant boundary forcing fill bdy arrays once for all
507         IF( ln_clim .AND. ntimes_bdy == 1 ) THEN
508            IF( ln_tra_frs ) THEN
509               tbdy  (:,:) = tbdydta  (:,:,2)
510               sbdy  (:,:) = sbdydta  (:,:,2)
511            ENDIF
512            IF( ln_dyn_frs) THEN
513               ubdy  (:,:) = ubdydta  (:,:,2)
514               vbdy  (:,:) = vbdydta  (:,:,2)
515            ENDIF
516#if defined key_lim2
517            IF( ln_ice_frs ) THEN
518               frld_bdy (:) = frld_bdydta (:,2)
519               hicif_bdy(:) = hicif_bdydta(:,2)
520               hsnif_bdy(:) = hsnif_bdydta(:,2)
521            ENDIF
522#endif
523
524            IF( ln_tra_frs .OR. ln_ice_frs) CALL iom_close( numbdyt )
525            IF( ln_dyn_frs                    ) CALL iom_close( numbdyu )
526            IF( ln_dyn_frs                    ) CALL iom_close( numbdyv )
527         END IF
528         !
529      ENDIF                                            ! End if nit000
530
531
532      !                                                !---------------------!
533      IF( nn_dtactl == 1 .AND. ntimes_bdy > 1 ) THEN    !  at each time step  !
534         !                                             !---------------------!
535         ! Read one more record if necessary
536         !**********************************
537
538         IF( ln_clim .AND. imois /= nbdy_b ) THEN      ! remember that nbdy_b=0 for kt=nit000
539            nbdy_b = imois
540            nbdy_a = imois + 1
541            nbdy_b = MOD( nbdy_b, iman )   ;   IF( nbdy_b == 0 ) nbdy_b = iman
542            nbdy_a = MOD( nbdy_a, iman )   ;   IF( nbdy_a == 0 ) nbdy_a = iman
543            lect=.true.
544         ELSEIF( .NOT.ln_clim .AND. itimer >= istep(nbdy_a) ) THEN
545
546            IF( nbdy_a < ntimes_bdy ) THEN
547               nbdy_b = nbdy_a
548               nbdy_a = nbdy_a + 1
549               lect  =.true.
550            ELSE
551               ! We have reached the end of the file
552               ! put the last data time into both time levels
553               nbdy_b = nbdy_a
554               IF(ln_tra_frs) THEN
555                  tbdydta(:,:,1) =  tbdydta(:,:,2)
556                  sbdydta(:,:,1) =  sbdydta(:,:,2)
557               ENDIF
558               IF(ln_dyn_frs) THEN
559                  ubdydta(:,:,1) =  ubdydta(:,:,2)
560                  vbdydta(:,:,1) =  vbdydta(:,:,2)
561               ENDIF
562#if defined key_lim2
563               IF(ln_ice_frs) THEN
564                  frld_bdydta (:,1) =  frld_bdydta (:,2)
565                  hicif_bdydta(:,1) =  hicif_bdydta(:,2)
566                  hsnif_bdydta(:,1) =  hsnif_bdydta(:,2)
567               ENDIF
568#endif
569            END IF ! nbdy_a < ntimes_bdy
570            !
571        END IF
572         
573        IF( lect ) THEN           ! Swap arrays
574           IF( ln_tra_frs ) THEN
575             tbdydta(:,:,1) =  tbdydta(:,:,2)
576             sbdydta(:,:,1) =  sbdydta(:,:,2)
577           ENDIF
578           IF( ln_dyn_frs ) THEN
579             ubdydta(:,:,1) =  ubdydta(:,:,2)
580             vbdydta(:,:,1) =  vbdydta(:,:,2)
581           ENDIF
582#if defined key_lim2
583           IF( ln_ice_frs ) THEN
584             frld_bdydta (:,1) =  frld_bdydta (:,2)
585             hicif_bdydta(:,1) =  hicif_bdydta(:,2)
586             hsnif_bdydta(:,1) =  hsnif_bdydta(:,2)
587           ENDIF
588#endif 
589           ! read another set
590           ipj  = 1
591           ipk  = jpk
592
593           IF( ln_tra_frs ) THEN
594              !
595              igrd = 1                                   ! temperature
596              ipi  = nblendta(igrd)
597              CALL iom_get ( numbdyt, jpdom_unknown, 'votemper', zdta(1:ipi,1:ipj,1:ipk), nbdy_a )
598              DO ib = 1, nblen(igrd)
599                 DO ik = 1, jpkm1
600                    tbdydta(ib,ik,2) = zdta(nbmap(ib,igrd),1,ik)
601                 END DO
602              END DO
603              !
604              igrd = 1                                   ! salinity
605              ipi  = nblendta(igrd)
606              CALL iom_get ( numbdyt, jpdom_unknown, 'vosaline', zdta(1:ipi,1:ipj,1:ipk), nbdy_a )
607              DO ib = 1, nblen(igrd)
608                 DO ik = 1, jpkm1
609                    sbdydta(ib,ik,2) = zdta(nbmap(ib,igrd),1,ik)
610                 END DO
611              END DO
612           ENDIF ! ln_tra_frs
613
614           IF(ln_dyn_frs) THEN
615              !
616              igrd = 2                                   ! u-velocity
617              ipi  = nblendta(igrd)
618              CALL iom_get ( numbdyu, jpdom_unknown,'vozocrtx',zdta(1:ipi,1:ipj,1:ipk),nbdy_a )
619              DO ib = 1, nblen(igrd)
620                DO ik = 1, jpkm1
621                  ubdydta(ib,ik,2) =  zdta(nbmap(ib,igrd),1,ik)
622                END DO
623              END DO
624              !
625              igrd = 3                                   ! v-velocity
626              ipi  = nblendta(igrd)
627              CALL iom_get ( numbdyv, jpdom_unknown,'vomecrty',zdta(1:ipi,1:ipj,1:ipk),nbdy_a )
628              DO ib = 1, nblen(igrd)
629                 DO ik = 1, jpkm1
630                    vbdydta(ib,ik,2) =  zdta(nbmap(ib,igrd),1,ik)
631                 END DO
632              END DO
633           ENDIF ! ln_dyn_frs
634           !
635#if defined key_lim2
636           IF(ln_ice_frs) THEN
637             !
638             igrd = 1                                    ! ice concentration
639             ipi=nblendta(igrd)
640             CALL iom_get ( numbdyt, jpdom_unknown,'ildsconc',zdta(1:ipi,:,1),nbdy_a )
641             DO ib=1, nblen(igrd)
642               frld_bdydta(ib,2) =  zdta( nbmap(ib,igrd), 1, 1 )
643             END DO
644             !
645             igrd=1                                      ! ice thickness
646             ipi=nblendta(igrd)
647             CALL iom_get ( numbdyt, jpdom_unknown,'iicethic',zdta(1:ipi,:,1),nbdy_a )
648             DO ib=1, nblen(igrd)
649               hicif_bdydta(ib,2) =  zdta( nbmap(ib,igrd), 1, 1 )
650             END DO
651             !
652             igrd=1                                      ! snow thickness
653             ipi=nblendta(igrd)
654             CALL iom_get ( numbdyt, jpdom_unknown,'isnowthi',zdta(1:ipi,:,1),nbdy_a )
655             DO ib=1, nblen(igrd)
656               hsnif_bdydta(ib,2) =  zdta( nbmap(ib,igrd), 1, 1 )
657             END DO
658           ENDIF ! ln_ice_frs
659#endif
660           !
661           IF(lwp) WRITE(numout,*) 'bdy_dta_frs : first record file used nbdy_b ',nbdy_b
662           IF(lwp) WRITE(numout,*) '~~~~~~~~  last  record file used nbdy_a ',nbdy_a
663           IF (.NOT.ln_clim) THEN
664              IF(lwp) WRITE(numout,*) 'first  record time (s): ', istep(nbdy_b)
665              IF(lwp) WRITE(numout,*) 'model time (s)        : ', itimer
666              IF(lwp) WRITE(numout,*) 'second record time (s): ', istep(nbdy_a)
667           ENDIF
668           !
669       ENDIF ! end lect=.true.
670
671
672       ! Interpolate linearly
673       ! ********************
674       !
675       IF( ln_clim ) THEN   ;   zxy = REAL( nday                   ) / REAL( nmonth_len(nbdy_b) ) + 0.5 - i15
676       ELSEIF( istep(nbdy_b) == istep(nbdy_a) ) THEN
677                                    zxy = 0.0_wp
678       ELSE                     ;   zxy = REAL( istep(nbdy_b) - itimer ) / REAL( istep(nbdy_b) - istep(nbdy_a) )
679       END IF
680
681          IF(ln_tra_frs) THEN
682             igrd = 1                                   ! temperature & salinity
683             DO ib = 1, nblen(igrd)
684               DO ik = 1, jpkm1
685                 tbdy(ib,ik) = zxy * tbdydta(ib,ik,2) + (1.-zxy) * tbdydta(ib,ik,1)
686                 sbdy(ib,ik) = zxy * sbdydta(ib,ik,2) + (1.-zxy) * sbdydta(ib,ik,1)
687               END DO
688             END DO
689          ENDIF
690
691          IF(ln_dyn_frs) THEN
692             igrd = 2                                   ! u-velocity
693             DO ib = 1, nblen(igrd)
694               DO ik = 1, jpkm1
695                 ubdy(ib,ik) = zxy * ubdydta(ib,ik,2) + (1.-zxy) * ubdydta(ib,ik,1)   
696               END DO
697             END DO
698             !
699             igrd = 3                                   ! v-velocity
700             DO ib = 1, nblen(igrd)
701               DO ik = 1, jpkm1
702                 vbdy(ib,ik) = zxy * vbdydta(ib,ik,2) + (1.-zxy) * vbdydta(ib,ik,1)   
703               END DO
704             END DO
705          ENDIF
706
707#if defined key_lim2
708          IF(ln_ice_frs) THEN
709            igrd=1
710            DO ib=1, nblen(igrd)
711               frld_bdy(ib) = zxy *  frld_bdydta(ib,2) + (1.-zxy) *  frld_bdydta(ib,1)
712              hicif_bdy(ib) = zxy * hicif_bdydta(ib,2) + (1.-zxy) * hicif_bdydta(ib,1)
713              hsnif_bdy(ib) = zxy * hsnif_bdydta(ib,2) + (1.-zxy) * hsnif_bdydta(ib,1)
714            END DO
715          ENDIF ! just if ln_ice_frs is true
716#endif
717
718      END IF                       !end if ((nn_dtactl==1).AND.(ntimes_bdy>1))
719   
720
721      !                                                !---------------------!
722      !                                                !     last call       !
723      !                                                !---------------------!
724      IF( kt == nitend ) THEN
725          IF(ln_tra_frs .or. ln_ice_frs) CALL iom_close( numbdyt )              ! Closing of the 3 files
726          IF(ln_dyn_frs) CALL iom_close( numbdyu )
727          IF(ln_dyn_frs) CALL iom_close( numbdyv )
728      ENDIF
729      !
730      ENDIF ! ln_dyn_frs .OR. ln_tra_frs
731      !
732   END SUBROUTINE bdy_dta_frs
733
734
735   SUBROUTINE bdy_dta_fla( kt, jit, icycl )
736      !!---------------------------------------------------------------------------
737      !!                      ***  SUBROUTINE bdy_dta_fla  ***
738      !!                   
739      !! ** Purpose :   Read unstructured boundary data for Flather condition
740      !!
741      !! ** Method  :  At the first timestep, read in boundary data for two
742      !!               times from the file and time-interpolate. At other
743      !!               timesteps, check to see if we need another time from
744      !!               the file. If so read it in. Time interpolate.
745      !!---------------------------------------------------------------------------
746!!gm DOCTOR names :   argument integer :  start with "k"
747      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
748      INTEGER, INTENT( in ) ::   jit         ! barotropic time step index
749      INTEGER, INTENT( in ) ::   icycl       ! number of cycles need for final file close
750      !                                      ! (for timesplitting option, otherwise zero)
751      !!
752      LOGICAL ::   lect                      ! flag for reading
753      INTEGER ::   it, ib, igrd              ! dummy loop indices
754      INTEGER ::   idvar                     ! netcdf var ID
755      INTEGER ::   iman, i15, imois          ! Time variables for monthly clim forcing
756      INTEGER ::   ntimes_bdyt, ntimes_bdyu, ntimes_bdyv
757      INTEGER ::   itimer, totime
758      INTEGER ::   ipi, ipj, ipk, inum       ! temporary integers (NetCDF read)
759      INTEGER ::   iyear0, imonth0, iday0
760      INTEGER ::   ihours0, iminutes0, isec0
761      INTEGER ::   iyear, imonth, iday, isecs
762      INTEGER, DIMENSION(jpbtime) ::   istept, istepu, istepv   ! time arrays from data files
763      REAL(wp) ::   dayfrac, zxy, zoffsett
764      REAL(wp) ::   zoffsetu, zoffsetv
765      REAL(wp) ::   dayjul0, zdayjulini
766      REAL(wp) ::   zinterval_s, zinterval_e                    ! First and last interval in time axis
767      REAL(wp), DIMENSION(jpbtime)      ::   zstepr             ! REAL time array from data files
768      REAL(wp), DIMENSION(jpbdta,1)     ::   zdta               ! temporary array for data fields
769      CHARACTER(LEN=80), DIMENSION(6)   ::   clfile
770      CHARACTER(LEN=70 )                ::   clunits            ! units attribute of time coordinate
771      !!---------------------------------------------------------------------------
772
773!!gm   add here the same style as in bdy_dta_frs
774!!gm      clearly bdy_dta_fla and bdy_dta_frs  can be combined...   
775!!gm      too many things duplicated in the read of data...   simplification can be done
776
777      ! -------------------- !
778      !    Initialization    !
779      ! -------------------- !
780
781      lect   = .false.           ! If true, read a time record
782
783      ! Some time variables for monthly climatological forcing:
784      ! *******************************************************
785 !!gm  here  use directely daymod variables
786 
787      iman  = INT( raamo ) ! Number of months in a year
788
789      i15 = INT( 2*REAL( nday, wp ) / ( REAL( nmonth_len(nmonth), wp ) + 0.5 ) )
790      ! i15=0 if the current day is in the first half of the month, else i15=1
791
792      imois = nmonth + i15 - 1            ! imois is the first month record
793      IF( imois == 0 ) imois = iman
794
795      ! Time variable for non-climatological forcing:
796      ! *********************************************
797
798      itimer = ((kt-1)-nit000+1)*rdt                      ! current time in seconds for interpolation
799      itimer = itimer + jit*rdt/REAL(nn_baro,wp)      ! in non-climatological case
800
801      IF ( ln_tides ) THEN
802
803         ! -------------------------------------!
804         ! Update BDY fields with tidal forcing !
805         ! -------------------------------------! 
806
807         CALL tide_update( kt, jit ) 
808 
809      ENDIF
810
811      IF ( ln_dyn_fla ) THEN
812
813         ! -------------------------------------!
814         ! Update BDY fields with model data    !
815         ! -------------------------------------! 
816
817      !                                                !-------------------!
818      IF( kt == nit000 .and. jit ==2 ) THEN            !  First call only  !
819         !                                             !-------------------!
820         istep_bt(:) = 0
821         nbdy_b_bt    = 0
822         nbdy_a_bt    = 0
823
824         ! Get time information from bdy data file
825         ! ***************************************
826
827        IF(lwp) WRITE(numout,*)
828        IF(lwp) WRITE(numout,*)    'bdy_dta_fla :Initialize unstructured boundary data for barotropic variables.'
829        IF(lwp) WRITE(numout,*)    '~~~~~~~' 
830
831        IF( nn_dtactl == 0 ) THEN
832          IF(lwp) WRITE(numout,*)  'Bdy data are taken from initial conditions'
833
834        ELSEIF (nn_dtactl == 1) THEN
835          IF(lwp) WRITE(numout,*)  'Bdy data are read in netcdf files'
836
837          dayfrac = adatrj  - REAL(itimer,wp)/86400. ! day fraction at time step kt-1
838          dayfrac = dayfrac - INT (dayfrac)          !
839          totime = (nitend-nit000+1)*rdt             ! Total time of the run to verify that all the
840                                                     ! necessary time dumps in file are included
841
842          clfile(4) = cn_dta_fla_T
843          clfile(5) = cn_dta_fla_U
844          clfile(6) = cn_dta_fla_V
845
846          DO igrd = 4,6
847
848            CALL iom_open( clfile(igrd), inum )
849            CALL iom_gettime( inum, zstepr, kntime=ntimes_bdy_bt, cdunits=clunits ) 
850
851            SELECT CASE( igrd )
852               CASE (4) 
853                  numbdyt_bt = inum
854               CASE (5) 
855                  numbdyu_bt = inum
856               CASE (6) 
857                  numbdyv_bt = inum
858            END SELECT
859
860            ! Calculate time offset
861            READ(clunits,7000) iyear0, imonth0, iday0, ihours0, iminutes0, isec0
862            ! Convert time origin in file to julian days
863            isec0 = isec0 + ihours0*60.*60. + iminutes0*60.
864            CALL ymds2ju(iyear0, imonth0, iday0, REAL(isec0, wp), dayjul0)
865            ! Compute model initialization time
866            iyear  = ndastp / 10000
867            imonth = ( ndastp - iyear * 10000 ) / 100
868            iday   = ndastp - iyear * 10000 - imonth * 100
869            isecs  = dayfrac * 86400
870            CALL ymds2ju(iyear, imonth, iday, REAL(isecs, wp) , zdayjulini)
871            ! zoffset from initialization date:
872            zoffset = (dayjul0-zdayjulini)*86400
873            !
874
8757000 FORMAT('seconds since ', I4.4,'-',I2.2,'-',I2.2,' ',I2.2,':',I2.2,':',I2.2)
876
877            !! TO BE DONE... Check consistency between calendar from file
878            !! (available optionally from iom_gettime) and calendar in model
879            !! when calendar in model available outside of IOIPSL.
880
881            ! Check that there are not too many times in the file.
882            IF (ntimes_bdy_bt > jpbtime) CALL ctl_stop( &
883                 'Number of time dumps in bdy file exceed jpbtime parameter', &
884                 'Check file:' // TRIM(clfile(igrd))  )
885
886            ! Check that time array increases (or interp will fail):
887            DO it = 2, ntimes_bdy_bt
888               IF ( zstepr(it-1) >= zstepr(it) ) THEN
889                  CALL ctl_stop('Time array in unstructured boundary data file', &
890                       'does not continuously increase.',               &
891                       'Check file:' // TRIM(clfile(igrd))  )
892                  EXIT
893               END IF
894            END DO
895
896            IF ( .NOT. ln_clim ) THEN
897               ! Check that times in file span model run time:
898
899               ! Note: the fields may be time means, so we allow nit000 to be before
900               ! first time in the file, provided that it falls inside the meaning
901               ! period of the first field.  Until we can get the meaning period
902               ! from the file, use the interval between fields as a proxy.
903               ! If nit000 is before the first time, use the value at first time
904               ! instead of extrapolating.  This is done by putting time 1 into
905               ! both time levels.
906               ! The same applies to the last time level: see setting of lect below.
907
908               IF ( ntimes_bdy_bt == 1 ) CALL ctl_stop( &
909                    'There is only one time dump in data files', &
910                    'Set ln_clim=.true. in namelist for constant bdy forcing.' )
911
912               zinterval_s = zstepr(2) - zstepr(1)
913               zinterval_e = zstepr(ntimes_bdy_bt) - zstepr(ntimes_bdy_bt-1)
914
915               IF( zstepr(1) + zoffset > 0 ) THEN
916                     WRITE(ctmp1,*) 'Check file: ', clfile(igrd)
917                     CALL ctl_stop( 'First time dump in bdy file is after model initial time', ctmp1 )
918               END IF
919               IF( zstepr(ntimes_bdy_bt) + zoffset < totime ) THEN
920                     WRITE(ctmp1,*) 'Check file: ', clfile(igrd)
921                     CALL ctl_stop( 'Last time dump in bdy file is before model final time', ctmp1 )
922               END IF
923            END IF ! .NOT. ln_clim
924
925            IF ( igrd .EQ. 4) THEN
926              ntimes_bdyt = ntimes_bdy_bt
927              zoffsett = zoffset
928              istept(:) = INT( zstepr(:) + zoffset )
929            ELSE IF (igrd .EQ. 5) THEN
930              ntimes_bdyu = ntimes_bdy_bt
931              zoffsetu = zoffset
932              istepu(:) = INT( zstepr(:) + zoffset )
933            ELSE IF (igrd .EQ. 6) THEN
934              ntimes_bdyv = ntimes_bdy_bt
935              zoffsetv = zoffset
936              istepv(:) = INT( zstepr(:) + zoffset )
937            ENDIF
938
939          ENDDO
940
941      ! Verify time consistency between files 
942
943          IF ( ntimes_bdyu /= ntimes_bdyt .OR. ntimes_bdyv /= ntimes_bdyt ) THEN
944             CALL ctl_stop( &
945             'Time axis lengths differ between bdy data files', &
946             'Multiple time frequencies not implemented yet' )
947          ELSE
948            ntimes_bdy_bt = ntimes_bdyt
949          ENDIF
950
951          IF (zoffsetu.NE.zoffsett .OR. zoffsetv.NE.zoffsett) THEN
952            CALL ctl_stop( & 
953            'Bdy data files must have the same time origin', &
954            'Multiple time frequencies not implemented yet'  )
955          ENDIF
956          zoffset = zoffsett
957
958      !! Check that times are the same in the three files... HERE.
959          istep_bt(:) = istept(:)
960
961      ! Check number of time dumps:             
962          IF (ln_clim) THEN
963            SELECT CASE ( ntimes_bdy_bt )
964            CASE( 1 )
965              IF(lwp) WRITE(numout,*)
966              IF(lwp) WRITE(numout,*) 'We assume constant boundary forcing from bdy data files'
967              IF(lwp) WRITE(numout,*)             
968            CASE( 12 )
969              IF(lwp) WRITE(numout,*)
970              IF(lwp) WRITE(numout,*) 'We assume monthly (and cyclic) boundary forcing from bdy data files'
971              IF(lwp) WRITE(numout,*) 
972            CASE DEFAULT
973              CALL ctl_stop( &
974                'For climatological boundary forcing (ln_clim=.true.),',&
975                'bdy data files must contain 1 or 12 time dumps.' )
976            END SELECT
977          ENDIF
978
979      ! Find index of first record to read (before first model time).
980
981          it=1
982          DO WHILE ( ((istep_bt(it+1)) <= 0 ).AND.(it.LE.(ntimes_bdy_bt-1)))
983            it=it+1
984          END DO
985          nbdy_b_bt = it
986
987          IF(lwp) WRITE(numout,*) 'Time offset is ',zoffset
988          IF(lwp) WRITE(numout,*) 'First record to read is ',nbdy_b_bt
989
990        ENDIF ! endif (nn_dtactl == 1)
991
992      ! 1.2  Read first record in file if necessary (ie if nn_dtactl == 1)
993      ! *****************************************************************
994
995        IF ( nn_dtactl == 0) THEN
996          ! boundary data arrays are filled with initial conditions
997          igrd = 5            ! U-points data
998          DO ib = 1, nblen(igrd)             
999            ubtbdy(ib) = un(nbi(ib,igrd), nbj(ib,igrd), 1)
1000          END DO
1001
1002          igrd = 6            ! V-points data
1003          DO ib = 1, nblen(igrd)             
1004            vbtbdy(ib) = vn(nbi(ib,igrd), nbj(ib,igrd), 1)
1005          END DO
1006
1007          igrd = 4            ! T-points data
1008          DO ib = 1, nblen(igrd)             
1009            sshbdy(ib) = sshn(nbi(ib,igrd), nbj(ib,igrd))
1010          END DO
1011
1012        ELSEIF (nn_dtactl == 1) THEN
1013 
1014        ! Set first record in the climatological case:   
1015          IF ((ln_clim).AND.(ntimes_bdy_bt==1)) THEN
1016            nbdy_a_bt = 1
1017          ELSEIF ((ln_clim).AND.(ntimes_bdy_bt==iman)) THEN
1018            nbdy_b_bt = 0
1019            nbdy_a_bt = imois
1020          ELSE
1021            nbdy_a_bt = nbdy_b_bt
1022          END IF
1023 
1024         ! Open Netcdf files:
1025
1026          CALL iom_open ( cn_dta_fla_T, numbdyt_bt )
1027          CALL iom_open ( cn_dta_fla_U, numbdyu_bt )
1028          CALL iom_open ( cn_dta_fla_V, numbdyv_bt )
1029
1030         ! Read first record:
1031          ipj=1
1032          igrd=4
1033          ipi=nblendta(igrd)
1034
1035          ! ssh
1036          igrd=4
1037          IF ( nblendta(igrd) .le. 0 ) THEN
1038            idvar = iom_varid( numbdyt_bt,'sossheig' )
1039            nblendta(igrd) = iom_file(numbdyt_bt)%dimsz(1,idvar)
1040          ENDIF
1041          WRITE(numout,*) 'Dim size for sossheig is ',nblendta(igrd)
1042          ipi=nblendta(igrd)
1043
1044          CALL iom_get ( numbdyt_bt, jpdom_unknown,'sossheig',zdta(1:ipi,1:ipj),nbdy_a_bt )
1045
1046          DO ib=1, nblen(igrd)
1047            sshbdydta(ib,2) =  zdta(nbmap(ib,igrd),1)
1048          END DO
1049 
1050          ! u-velocity
1051          igrd=5
1052          IF ( nblendta(igrd) .le. 0 ) THEN
1053            idvar = iom_varid( numbdyu_bt,'vobtcrtx' )
1054            nblendta(igrd) = iom_file(numbdyu_bt)%dimsz(1,idvar)
1055          ENDIF
1056          WRITE(numout,*) 'Dim size for vobtcrtx is ',nblendta(igrd)
1057          ipi=nblendta(igrd)
1058
1059          CALL iom_get ( numbdyu_bt, jpdom_unknown,'vobtcrtx',zdta(1:ipi,1:ipj),nbdy_a_bt )
1060
1061          DO ib=1, nblen(igrd)
1062            ubtbdydta(ib,2) =  zdta(nbmap(ib,igrd),1)
1063          END DO
1064
1065          ! v-velocity
1066          igrd=6
1067          IF ( nblendta(igrd) .le. 0 ) THEN
1068            idvar = iom_varid( numbdyv_bt,'vobtcrty' )
1069            nblendta(igrd) = iom_file(numbdyv_bt)%dimsz(1,idvar)
1070          ENDIF
1071          WRITE(numout,*) 'Dim size for vobtcrty is ',nblendta(igrd)
1072          ipi=nblendta(igrd)
1073
1074          CALL iom_get ( numbdyv_bt, jpdom_unknown,'vobtcrty',zdta(1:ipi,1:ipj),nbdy_a_bt )
1075
1076          DO ib=1, nblen(igrd)
1077            vbtbdydta(ib,2) =  zdta(nbmap(ib,igrd),1)
1078          END DO
1079
1080        END IF
1081 
1082        ! In the case of constant boundary forcing fill bdy arrays once for all
1083        IF ((ln_clim).AND.(ntimes_bdy_bt==1)) THEN
1084
1085          ubtbdy  (:) = ubtbdydta  (:,2)
1086          vbtbdy  (:) = vbtbdydta  (:,2)
1087          sshbdy  (:) = sshbdydta  (:,2)
1088
1089          CALL iom_close( numbdyt_bt )
1090          CALL iom_close( numbdyu_bt )
1091          CALL iom_close( numbdyv_bt )
1092
1093        END IF
1094
1095      ENDIF ! End if nit000
1096
1097      ! -------------------- !
1098      ! 2. At each time step !
1099      ! -------------------- !
1100
1101      IF ((nn_dtactl==1).AND.(ntimes_bdy_bt>1)) THEN 
1102
1103      ! 2.1 Read one more record if necessary
1104      !**************************************
1105
1106        IF ( (ln_clim).AND.(imois/=nbdy_b_bt) ) THEN ! remember that nbdy_b_bt=0 for kt=nit000
1107         nbdy_b_bt = imois
1108         nbdy_a_bt = imois+1
1109         nbdy_b_bt = MOD( nbdy_b_bt, iman )
1110         IF( nbdy_b_bt == 0 ) nbdy_b_bt = iman
1111         nbdy_a_bt = MOD( nbdy_a_bt, iman )
1112         IF( nbdy_a_bt == 0 ) nbdy_a_bt = iman
1113         lect=.true.
1114
1115        ELSEIF ((.NOT.ln_clim).AND.(itimer >= istep_bt(nbdy_a_bt))) THEN
1116          nbdy_b_bt=nbdy_a_bt
1117          nbdy_a_bt=nbdy_a_bt+1
1118          lect=.true.
1119        END IF
1120         
1121        IF (lect) THEN
1122
1123        ! Swap arrays
1124          sshbdydta(:,1) =  sshbdydta(:,2)
1125          ubtbdydta(:,1) =  ubtbdydta(:,2)
1126          vbtbdydta(:,1) =  vbtbdydta(:,2)
1127 
1128        ! read another set
1129
1130          ipj=1
1131          ipk=jpk
1132          igrd=4
1133          ipi=nblendta(igrd)
1134
1135         
1136          ! ssh
1137          igrd=4
1138          ipi=nblendta(igrd)
1139
1140          CALL iom_get ( numbdyt_bt, jpdom_unknown,'sossheig',zdta(1:ipi,1:ipj),nbdy_a_bt )
1141
1142          DO ib=1, nblen(igrd)
1143            sshbdydta(ib,2) =  zdta(nbmap(ib,igrd),1)
1144          END DO
1145
1146          ! u-velocity
1147          igrd=5
1148          ipi=nblendta(igrd)
1149
1150          CALL iom_get ( numbdyu_bt, jpdom_unknown,'vobtcrtx',zdta(1:ipi,1:ipj),nbdy_a_bt )
1151
1152          DO ib=1, nblen(igrd)
1153            ubtbdydta(ib,2) =  zdta(nbmap(ib,igrd),1)
1154          END DO
1155
1156          ! v-velocity
1157          igrd=6
1158          ipi=nblendta(igrd)
1159
1160          CALL iom_get ( numbdyv_bt, jpdom_unknown,'vobtcrty',zdta(1:ipi,1:ipj),nbdy_a_bt )
1161
1162          DO ib=1, nblen(igrd)
1163            vbtbdydta(ib,2) =  zdta(nbmap(ib,igrd),1)
1164          END DO
1165
1166
1167         IF(lwp) WRITE(numout,*) 'bdy_dta_fla : first record file used nbdy_b_bt ',nbdy_b_bt
1168         IF(lwp) WRITE(numout,*) '~~~~~~~~  last  record file used nbdy_a_bt ',nbdy_a_bt
1169         IF (.NOT.ln_clim) THEN
1170           IF(lwp) WRITE(numout,*) 'first  record time (s): ', istep_bt(nbdy_b_bt)
1171           IF(lwp) WRITE(numout,*) 'model time (s)        : ', itimer
1172           IF(lwp) WRITE(numout,*) 'second record time (s): ', istep_bt(nbdy_a_bt)
1173         ENDIF
1174        END IF ! end lect=.true.
1175
1176
1177      ! 2.2   Interpolate linearly:
1178      ! ***************************
1179   
1180        IF (ln_clim) THEN
1181          zxy = REAL( nday, wp ) / REAL( nmonth_len(nbdy_b_bt), wp ) + 0.5 - i15
1182        ELSE         
1183          zxy = REAL(istep_bt(nbdy_b_bt)-itimer, wp) / REAL(istep_bt(nbdy_b_bt)-istep_bt(nbdy_a_bt), wp)
1184        END IF
1185
1186          igrd=4
1187          DO ib=1, nblen(igrd)
1188            sshbdy(ib) = zxy      * sshbdydta(ib,2) + &
1189                       (1.-zxy) * sshbdydta(ib,1)   
1190          END DO
1191
1192          igrd=5
1193          DO ib=1, nblen(igrd)
1194            ubtbdy(ib) = zxy      * ubtbdydta(ib,2) + &
1195                         (1.-zxy) * ubtbdydta(ib,1)   
1196          END DO
1197
1198          igrd=6
1199          DO ib=1, nblen(igrd)
1200            vbtbdy(ib) = zxy      * vbtbdydta(ib,2) + &
1201                         (1.-zxy) * vbtbdydta(ib,1)   
1202          END DO
1203
1204
1205      END IF !end if ((nn_dtactl==1).AND.(ntimes_bdy_bt>1))
1206   
1207      ! ------------------- !
1208      ! Last call kt=nitend !
1209      ! ------------------- !
1210
1211      ! Closing of the 3 files
1212      IF( kt == nitend   .and. jit == icycl ) THEN
1213          CALL iom_close( numbdyt_bt )
1214          CALL iom_close( numbdyu_bt )
1215          CALL iom_close( numbdyv_bt )
1216      ENDIF
1217
1218      ENDIF ! ln_dyn_frs
1219
1220      END SUBROUTINE bdy_dta_fla
1221
1222
1223#else
1224   !!----------------------------------------------------------------------
1225   !!   Dummy module                   NO Unstruct Open Boundary Conditions
1226   !!----------------------------------------------------------------------
1227CONTAINS
1228   SUBROUTINE bdy_dta_frs( kt )              ! Empty routine
1229      WRITE(*,*) 'bdy_dta_frs: You should not have seen this print! error?', kt
1230   END SUBROUTINE bdy_dta_frs
1231   SUBROUTINE bdy_dta_fla( kt, kit, icycle )      ! Empty routine
1232      WRITE(*,*) 'bdy_dta_frs: You should not have seen this print! error?', kt, kit
1233   END SUBROUTINE bdy_dta_fla
1234#endif
1235
1236   !!==============================================================================
1237END MODULE bdydta
Note: See TracBrowser for help on using the repository browser.