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.
dtadyn.F90 in NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF – NEMO

source: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/dtadyn.F90 @ 13502

Last change on this file since 13502 was 13427, checked in by techene, 4 years ago

debug in order to pass non linear SETTE test when agrif in not activated see #2385

  • Property svn:keywords set to Id
File size: 42.7 KB
Line 
1MODULE dtadyn
2   !!======================================================================
3   !!                       ***  MODULE  dtadyn  ***
4   !! Off-line : interpolation of the physical fields
5   !!======================================================================
6   !! History :   OPA  ! 1992-01 (M. Imbard) Original code
7   !!             8.0  ! 1998-04 (L.Bopp MA Foujols) slopes for isopyc.
8   !!              -   ! 1998-05 (L. Bopp) read output of coupled run
9   !!             8.2  ! 2001-01 (M. Levy et M. Benjelloul) add netcdf FORMAT
10   !!   NEMO      1.0  ! 2005-03 (O. Aumont and A. El Moussaoui) F90
11   !!              -   ! 2005-12 (C. Ethe) Adapted for DEGINT
12   !!             3.0  ! 2007-06 (C. Ethe) use of iom module
13   !!             3.3  ! 2010-11 (C. Ethe) Full reorganization of the off-line: phasing with the on-line
14   !!             3.4  ! 2011-05 (C. Ethe) Use of fldread
15   !!             4.1  ! 2019-08 (A. Coward, D. Storkey) split dta_dyn_sf_swp -> dta_dyn_sf_atf and dta_dyn_sf_interp
16   !!----------------------------------------------------------------------
17
18   !!----------------------------------------------------------------------
19   !!   dta_dyn_init : initialization, namelist read, and SAVEs control
20   !!   dta_dyn      : Interpolation of the fields
21   !!----------------------------------------------------------------------
22   USE oce             ! ocean dynamics and tracers variables
23   USE c1d             ! 1D configuration: lk_c1d
24   USE dom_oce         ! ocean domain: variables
25#if defined key_qco 
26   USE domqco          ! variable volume
27#else
28   USE domvvl
29#endif
30   USE zdf_oce         ! ocean vertical physics: variables
31   USE sbc_oce         ! surface module: variables
32   USE trc_oce         ! share ocean/biogeo variables
33   USE phycst          ! physical constants
34   USE trabbl          ! active tracer: bottom boundary layer
35   USE ldfslp          ! lateral diffusion: iso-neutral slopes
36   USE sbcrnf          ! river runoffs
37   USE ldftra          ! ocean tracer   lateral physics
38   USE zdfmxl          ! vertical physics: mixed layer depth
39   USE eosbn2          ! equation of state - Brunt Vaisala frequency
40   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
41   USE zpshde          ! z-coord. with partial steps: horizontal derivatives
42   USE in_out_manager  ! I/O manager
43   USE iom             ! I/O library
44   USE lib_mpp         ! distributed memory computing library
45   USE prtctl          ! print control
46   USE fldread         ! read input fields
47   USE timing          ! Timing
48   USE trc, ONLY : ln_rsttr, numrtr, numrtw, lrst_trc
49
50   IMPLICIT NONE
51   PRIVATE
52
53   PUBLIC   dta_dyn_init       ! called by nemo_init
54   PUBLIC   dta_dyn            ! called by nemo_gcm
55   PUBLIC   dta_dyn_sed_init   ! called by nemo_init
56   PUBLIC   dta_dyn_sed        ! called by nemo_gcm
57   PUBLIC   dta_dyn_atf        ! called by nemo_gcm
58#if ! defined key_qco
59   PUBLIC   dta_dyn_sf_interp  ! called by nemo_gcm
60#endif
61
62   CHARACTER(len=100) ::   cn_dir          !: Root directory for location of ssr files
63   LOGICAL            ::   ln_dynrnf       !: read runoff data in file (T) or set to zero (F)
64   LOGICAL            ::   ln_dynrnf_depth       !: read runoff data in file (T) or set to zero (F)
65   REAL(wp)           ::   fwbcorr
66
67
68   INTEGER  , PARAMETER ::   jpfld = 20     ! maximum number of fields to read
69   INTEGER  , SAVE      ::   jf_tem         ! index of temperature
70   INTEGER  , SAVE      ::   jf_sal         ! index of salinity
71   INTEGER  , SAVE      ::   jf_uwd         ! index of u-transport
72   INTEGER  , SAVE      ::   jf_vwd         ! index of v-transport
73   INTEGER  , SAVE      ::   jf_wwd         ! index of w-transport
74   INTEGER  , SAVE      ::   jf_avt         ! index of Kz
75   INTEGER  , SAVE      ::   jf_mld         ! index of mixed layer deptht
76   INTEGER  , SAVE      ::   jf_emp         ! index of water flux
77   INTEGER  , SAVE      ::   jf_empb        ! index of water flux
78   INTEGER  , SAVE      ::   jf_qsr         ! index of solar radiation
79   INTEGER  , SAVE      ::   jf_wnd         ! index of wind speed
80   INTEGER  , SAVE      ::   jf_ice         ! index of sea ice cover
81   INTEGER  , SAVE      ::   jf_rnf         ! index of river runoff
82   INTEGER  , SAVE      ::   jf_fmf         ! index of downward salt flux
83   INTEGER  , SAVE      ::   jf_ubl         ! index of u-bbl coef
84   INTEGER  , SAVE      ::   jf_vbl         ! index of v-bbl coef
85   INTEGER  , SAVE      ::   jf_div         ! index of e3t
86
87
88   TYPE(FLD), ALLOCATABLE, SAVE, DIMENSION(:) :: sf_dyn  ! structure of input fields (file informations, fields read)
89   !                                               !
90   REAL(wp) , ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: uslpdta    ! zonal isopycnal slopes
91   REAL(wp) , ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: vslpdta    ! meridional isopycnal slopes
92   REAL(wp) , ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: wslpidta   ! zonal diapycnal slopes
93   REAL(wp) , ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: wslpjdta   ! meridional diapycnal slopes
94
95   INTEGER, SAVE  :: nprevrec, nsecdyn
96
97   !! * Substitutions
98#  include "do_loop_substitute.h90"
99#  include "domzgr_substitute.h90"
100   
101   !!----------------------------------------------------------------------
102   !! NEMO/OFF 4.0 , NEMO Consortium (2018)
103   !! $Id$
104   !! Software governed by the CeCILL license (see ./LICENSE)
105   !!----------------------------------------------------------------------
106CONTAINS
107
108   SUBROUTINE dta_dyn( kt, Kbb, Kmm, Kaa )
109      !!----------------------------------------------------------------------
110      !!                  ***  ROUTINE dta_dyn  ***
111      !!
112      !! ** Purpose :  Prepares dynamics and physics fields from a NEMO run
113      !!               for an off-line simulation of passive tracers
114      !!
115      !! ** Method : calculates the position of data
116      !!             - computes slopes if needed
117      !!             - interpolates data if needed
118      !!----------------------------------------------------------------------
119      INTEGER, INTENT(in) ::   kt             ! ocean time-step index
120      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa  ! ocean time level indices
121      !
122      INTEGER             ::   ji, jj, jk
123      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   zemp
124      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zhdivtr
125      !!----------------------------------------------------------------------
126      !
127      IF( ln_timing )   CALL timing_start( 'dta_dyn')
128      !
129      nsecdyn = nsec_year + nsec1jan000   ! number of seconds between Jan. 1st 00h of nit000 year and the middle of time step
130      !
131      IF( kt == nit000 ) THEN    ;    nprevrec = 0
132      ELSE                       ;    nprevrec = sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%naa)
133      ENDIF
134      CALL fld_read( kt, 1, sf_dyn )      !=  read data at kt time step   ==!
135      !
136      IF( l_ldfslp .AND. .NOT.lk_c1d )   CALL  dta_dyn_slp( kt, Kbb, Kmm )    ! Computation of slopes
137      !
138      ts(:,:,:,jp_tem,Kmm) = sf_dyn(jf_tem)%fnow(:,:,:)  * tmask(:,:,:)    ! temperature
139      ts(:,:,:,jp_sal,Kmm) = sf_dyn(jf_sal)%fnow(:,:,:)  * tmask(:,:,:)    ! salinity
140      wndm(:,:)         = sf_dyn(jf_wnd)%fnow(:,:,1)  * tmask(:,:,1)    ! wind speed - needed for gas exchange
141      fmmflx(:,:)       = sf_dyn(jf_fmf)%fnow(:,:,1)  * tmask(:,:,1)    ! downward salt flux (v3.5+)
142      fr_i(:,:)         = sf_dyn(jf_ice)%fnow(:,:,1)  * tmask(:,:,1)    ! Sea-ice fraction
143      qsr (:,:)         = sf_dyn(jf_qsr)%fnow(:,:,1)  * tmask(:,:,1)    ! solar radiation
144      emp (:,:)         = sf_dyn(jf_emp)%fnow(:,:,1)  * tmask(:,:,1)    ! E-P
145      IF( ln_dynrnf ) THEN
146         rnf (:,:)      = sf_dyn(jf_rnf)%fnow(:,:,1) * tmask(:,:,1)    ! E-P
147         IF( ln_dynrnf_depth .AND. .NOT. ln_linssh )    CALL  dta_dyn_hrnf(Kmm)
148      ENDIF
149      !
150      uu(:,:,:,Kmm)        = sf_dyn(jf_uwd)%fnow(:,:,:) * umask(:,:,:)    ! effective u-transport
151      vv(:,:,:,Kmm)        = sf_dyn(jf_vwd)%fnow(:,:,:) * vmask(:,:,:)    ! effective v-transport
152      ww(:,:,:)        = sf_dyn(jf_wwd)%fnow(:,:,:) * tmask(:,:,:)    ! effective v-transport
153      !
154      IF( .NOT.ln_linssh ) THEN
155         ALLOCATE( zemp(jpi,jpj) , zhdivtr(jpi,jpj,jpk) )
156         zhdivtr(:,:,:) = sf_dyn(jf_div)%fnow(:,:,:)  * tmask(:,:,:)    ! effective u-transport
157         emp_b  (:,:)   = sf_dyn(jf_empb)%fnow(:,:,1) * tmask(:,:,1)    ! E-P
158         zemp   (:,:)   = ( 0.5_wp * ( emp(:,:) + emp_b(:,:) ) + rnf(:,:) + fwbcorr ) * tmask(:,:,1)
159#if defined key_qco
160         CALL dta_dyn_ssh( kt, zhdivtr, ssh(:,:,Kbb), zemp, ssh(:,:,Kaa) )
161         CALL dom_qco_r3c( ssh(:,:,Kaa), r3t(:,:,Kaa), r3u(:,:,Kaa), r3v(:,:,Kaa) )
162#else
163         CALL dta_dyn_ssh( kt, zhdivtr, ssh(:,:,Kbb), zemp, ssh(:,:,Kaa), e3t(:,:,:,Kaa) )  !=  ssh, vertical scale factor
164#endif
165         DEALLOCATE( zemp , zhdivtr )
166         !                                           Write in the tracer restart file
167         !                                          *********************************
168         IF( lrst_trc ) THEN
169            IF(lwp) WRITE(numout,*)
170            IF(lwp) WRITE(numout,*) 'dta_dyn_ssh : ssh field written in tracer restart file at it= ', kt,' date= ', ndastp
171            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
172            CALL iom_rstput( kt, nitrst, numrtw, 'sshn', ssh(:,:,Kaa) )
173            CALL iom_rstput( kt, nitrst, numrtw, 'sshb', ssh(:,:,Kmm) )
174         ENDIF
175      ENDIF
176      !
177      CALL eos    ( ts(:,:,:,:,Kmm), rhd, rhop, gdept_0(:,:,:) ) ! In any case, we need rhop
178      CALL eos_rab( ts(:,:,:,:,Kmm), rab_n, Kmm )       ! now    local thermal/haline expension ratio at T-points
179      CALL bn2    ( ts(:,:,:,:,Kmm), rab_n, rn2, Kmm )  ! before Brunt-Vaisala frequency need for zdfmxl
180
181      rn2b(:,:,:) = rn2(:,:,:)         ! needed for zdfmxl
182      CALL zdf_mxl( kt, Kmm )          ! In any case, we need mxl
183      !
184      hmld(:,:)       = sf_dyn(jf_mld)%fnow(:,:,1) * tmask(:,:,1)    ! mixed layer depht
185      avt(:,:,:)      = sf_dyn(jf_avt)%fnow(:,:,:) * tmask(:,:,:)    ! vertical diffusive coefficient
186      avs(:,:,:)      = avt(:,:,:)
187      !
188      IF( ln_trabbl .AND. .NOT.lk_c1d ) THEN       ! diffusive Bottom boundary layer param
189         ahu_bbl(:,:) = sf_dyn(jf_ubl)%fnow(:,:,1) * umask(:,:,1)    ! bbl diffusive coef
190         ahv_bbl(:,:) = sf_dyn(jf_vbl)%fnow(:,:,1) * vmask(:,:,1)
191      ENDIF
192      !
193      !
194      CALL eos( ts(:,:,:,:,Kmm), rhd, rhop, gdept_0(:,:,:) ) ! In any case, we need rhop
195      !
196      IF(sn_cfctl%l_prtctl) THEN                 ! print control
197         CALL prt_ctl(tab3d_1=ts(:,:,:,jp_tem,Kmm), clinfo1=' tn      - : ', mask1=tmask,  kdim=jpk   )
198         CALL prt_ctl(tab3d_1=ts(:,:,:,jp_sal,Kmm), clinfo1=' sn      - : ', mask1=tmask,  kdim=jpk   )
199         CALL prt_ctl(tab3d_1=uu(:,:,:,Kmm)               , clinfo1=' uu(:,:,:,Kmm)      - : ', mask1=umask,  kdim=jpk   )
200         CALL prt_ctl(tab3d_1=vv(:,:,:,Kmm)               , clinfo1=' vv(:,:,:,Kmm)      - : ', mask1=vmask,  kdim=jpk   )
201         CALL prt_ctl(tab3d_1=ww               , clinfo1=' ww      - : ', mask1=tmask,  kdim=jpk   )
202         CALL prt_ctl(tab3d_1=avt              , clinfo1=' kz      - : ', mask1=tmask,  kdim=jpk   )
203         CALL prt_ctl(tab3d_1=uslp             , clinfo1=' slp  - u : ', tab3d_2=vslp, clinfo2=' v : ', kdim=jpk)
204         CALL prt_ctl(tab3d_1=wslpi            , clinfo1=' slp  - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk)
205      ENDIF
206      !
207      IF( ln_timing )   CALL timing_stop( 'dta_dyn')
208      !
209   END SUBROUTINE dta_dyn
210
211
212   SUBROUTINE dta_dyn_init( Kbb, Kmm, Kaa )
213      !!----------------------------------------------------------------------
214      !!                  ***  ROUTINE dta_dyn_init  ***
215      !!
216      !! ** Purpose :   Initialisation of the dynamical data     
217      !! ** Method  : - read the data namdta_dyn namelist
218      !!----------------------------------------------------------------------
219      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa  ! ocean time level indices
220      !
221      INTEGER  :: ierr, ierr0, ierr1, ierr2, ierr3   ! return error code
222      INTEGER  :: ifpr                               ! dummy loop indice
223      INTEGER  :: jfld                               ! dummy loop arguments
224      INTEGER  :: inum, idv, idimv                   ! local integer
225      INTEGER  :: ios                                ! Local integer output status for namelist read
226      INTEGER  :: ji, jj, jk
227      REAL(wp) :: zcoef
228      INTEGER  :: nkrnf_max
229      REAL(wp) :: hrnf_max
230      !!
231      CHARACTER(len=100)            ::  cn_dir        !   Root directory for location of core files
232      TYPE(FLD_N), DIMENSION(jpfld) ::  slf_d         ! array of namelist informations on the fields to read
233      TYPE(FLD_N) :: sn_uwd, sn_vwd, sn_wwd, sn_empb, sn_emp  ! informations about the fields to be read
234      TYPE(FLD_N) :: sn_tem , sn_sal , sn_avt   !   "                 "
235      TYPE(FLD_N) :: sn_mld, sn_qsr, sn_wnd , sn_ice , sn_fmf   !   "               "
236      TYPE(FLD_N) :: sn_ubl, sn_vbl, sn_rnf    !   "              "
237      TYPE(FLD_N) :: sn_div  ! informations about the fields to be read
238      !!
239      NAMELIST/namdta_dyn/cn_dir, ln_dynrnf, ln_dynrnf_depth,  fwbcorr, &
240         &                sn_uwd, sn_vwd, sn_wwd, sn_emp,               &
241         &                sn_avt, sn_tem, sn_sal, sn_mld , sn_qsr ,     &
242         &                sn_wnd, sn_ice, sn_fmf,                       &
243         &                sn_ubl, sn_vbl, sn_rnf,                       &
244         &                sn_empb, sn_div 
245      !!----------------------------------------------------------------------
246      !
247      READ  ( numnam_ref, namdta_dyn, IOSTAT = ios, ERR = 901)
248901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist' )
249      READ  ( numnam_cfg, namdta_dyn, IOSTAT = ios, ERR = 902 )
250902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist' )
251      IF(lwm) WRITE ( numond, namdta_dyn )
252      !                                         ! store namelist information in an array
253      !                                         ! Control print
254      IF(lwp) THEN
255         WRITE(numout,*)
256         WRITE(numout,*) 'dta_dyn : offline dynamics '
257         WRITE(numout,*) '~~~~~~~ '
258         WRITE(numout,*) '   Namelist namdta_dyn'
259         WRITE(numout,*) '      runoffs option enabled (T) or not (F)            ln_dynrnf        = ', ln_dynrnf
260         WRITE(numout,*) '      runoffs is spread in vertical                    ln_dynrnf_depth  = ', ln_dynrnf_depth
261         WRITE(numout,*) '      annual global mean of empmr for ssh correction   fwbcorr          = ', fwbcorr
262         WRITE(numout,*)
263      ENDIF
264      !
265      jf_uwd  = 1     ;   jf_vwd  = 2    ;   jf_wwd = 3    ;   jf_emp = 4    ;   jf_avt = 5
266      jf_tem  = 6     ;   jf_sal  = 7    ;   jf_mld = 8    ;   jf_qsr = 9
267      jf_wnd  = 10    ;   jf_ice  = 11   ;   jf_fmf = 12   ;   jfld   = jf_fmf
268      !
269      slf_d(jf_uwd)  = sn_uwd    ;   slf_d(jf_vwd)  = sn_vwd   ;   slf_d(jf_wwd) = sn_wwd
270      slf_d(jf_emp)  = sn_emp    ;   slf_d(jf_avt)  = sn_avt
271      slf_d(jf_tem)  = sn_tem    ;   slf_d(jf_sal)  = sn_sal   ;   slf_d(jf_mld) = sn_mld
272      slf_d(jf_qsr)  = sn_qsr    ;   slf_d(jf_wnd)  = sn_wnd   ;   slf_d(jf_ice) = sn_ice
273      slf_d(jf_fmf)  = sn_fmf
274      !
275      IF( .NOT.ln_linssh ) THEN
276               jf_div  = jfld + 1   ;         jf_empb  = jfld + 2    ;   jfld = jf_empb
277         slf_d(jf_div) = sn_div     ;   slf_d(jf_empb) = sn_empb
278      ENDIF
279      !
280      IF( ln_trabbl ) THEN
281               jf_ubl  = jfld + 1   ;         jf_vbl  = jfld + 2     ;   jfld = jf_vbl
282         slf_d(jf_ubl) = sn_ubl     ;   slf_d(jf_vbl) = sn_vbl
283      ENDIF
284      !
285      IF( ln_dynrnf ) THEN
286               jf_rnf  = jfld + 1   ;     jfld  = jf_rnf
287         slf_d(jf_rnf) = sn_rnf   
288      ELSE
289         rnf(:,:) = 0._wp
290      ENDIF
291
292      ALLOCATE( sf_dyn(jfld), STAT=ierr )         ! set sf structure
293      IF( ierr > 0 )  THEN
294         CALL ctl_stop( 'dta_dyn: unable to allocate sf structure' )   ;   RETURN
295      ENDIF
296      !                                         ! fill sf with slf_i and control print
297      CALL fld_fill( sf_dyn, slf_d, cn_dir, 'dta_dyn_init', 'Data in file', 'namdta_dyn' )
298      sf_dyn(jf_uwd)%cltype = 'U'   ;   sf_dyn(jf_uwd)%zsgn = -1._wp 
299      sf_dyn(jf_vwd)%cltype = 'V'   ;   sf_dyn(jf_vwd)%zsgn = -1._wp 
300      sf_dyn(jf_ubl)%cltype = 'U'   ;   sf_dyn(jf_ubl)%zsgn =  1._wp 
301      sf_dyn(jf_vbl)%cltype = 'V'   ;   sf_dyn(jf_vbl)%zsgn =  1._wp 
302      !
303      ! Open file for each variable to get his number of dimension
304      DO ifpr = 1, jfld
305         CALL fld_def( sf_dyn(ifpr) )
306         CALL iom_open( sf_dyn(ifpr)%clname, sf_dyn(ifpr)%num )
307         idv   = iom_varid( sf_dyn(ifpr)%num , slf_d(ifpr)%clvar )        ! id of the variable sdjf%clvar
308         idimv = iom_file ( sf_dyn(ifpr)%num )%ndims(idv)                 ! number of dimension for variable sdjf%clvar
309         CALL iom_close( sf_dyn(ifpr)%num )                               ! close file if already open
310         ierr1=0
311         IF( idimv == 3 ) THEN    ! 2D variable
312                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,1)    , STAT=ierr0 )
313            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,1,2)  , STAT=ierr1 )
314         ELSE                     ! 3D variable
315                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,jpk)  , STAT=ierr0 )
316            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,jpk,2), STAT=ierr1 )
317         ENDIF
318         IF( ierr0 + ierr1 > 0 ) THEN
319            CALL ctl_stop( 'dta_dyn_init : unable to allocate sf_dyn array structure' )   ;   RETURN
320         ENDIF
321      END DO
322      !
323      IF( l_ldfslp .AND. .NOT.lk_c1d ) THEN                  ! slopes
324         IF( sf_dyn(jf_tem)%ln_tint ) THEN      ! time interpolation
325            ALLOCATE( uslpdta (jpi,jpj,jpk,2), vslpdta (jpi,jpj,jpk,2),    &
326            &         wslpidta(jpi,jpj,jpk,2), wslpjdta(jpi,jpj,jpk,2), STAT=ierr2 )
327            !
328            IF( ierr2 > 0 )  THEN
329               CALL ctl_stop( 'dta_dyn_init : unable to allocate slope arrays' )   ;   RETURN
330            ENDIF
331         ENDIF
332      ENDIF
333      !
334      IF( .NOT.ln_linssh ) THEN
335        IF( .NOT. sf_dyn(jf_uwd)%ln_clim .AND. ln_rsttr .AND.    &                     ! Restart: read in restart file
336           iom_varid( numrtr, 'sshn', ldstop = .FALSE. ) > 0 ) THEN
337           IF(lwp) WRITE(numout,*) ' ssh(:,:,Kmm) forcing fields read in the restart file for initialisation'
338           CALL iom_get( numrtr, jpdom_auto, 'sshn', ssh(:,:,Kmm)   )
339           CALL iom_get( numrtr, jpdom_auto, 'sshb', ssh(:,:,Kbb)   )
340        ELSE
341           IF(lwp) WRITE(numout,*) ' ssh(:,:,Kmm) forcing fields read in the restart file for initialisation'
342           CALL iom_open( 'restart', inum )
343           CALL iom_get( inum, jpdom_auto, 'sshn', ssh(:,:,Kmm)   )
344           CALL iom_get( inum, jpdom_auto, 'sshb', ssh(:,:,Kbb)   )
345           CALL iom_close( inum )                                        ! close file
346        ENDIF
347        !
348#if defined key_qco
349        CALL dom_qco_r3c( ssh(:,:,Kbb), r3t(:,:,Kbb), r3u(:,:,Kbb), r3v(:,:,Kbb) )
350        CALL dom_qco_r3c( ssh(:,:,Kmm), r3t(:,:,Kmm), r3u(:,:,Kmm), r3v(:,:,Kmm) )
351#else
352        DO jk = 1, jpkm1
353           e3t(:,:,jk,Kmm) = e3t_0(:,:,jk) * ( 1._wp + ssh(:,:,Kmm) * r1_ht_0(:,:) * tmask(:,:,jk) )
354        ENDDO
355        e3t(:,:,jpk,Kaa) = e3t_0(:,:,jpk)
356
357        ! Horizontal scale factor interpolations
358        ! --------------------------------------
359        CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
360        CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
361
362        ! Vertical scale factor interpolations
363        ! ------------------------------------
364        CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3w(:,:,:,Kmm), 'W' )
365!!gm this should be computed from ssh(Kbb) 
366        e3t(:,:,:,Kbb)  = e3t(:,:,:,Kmm)
367        e3u(:,:,:,Kbb)  = e3u(:,:,:,Kmm)
368        e3v(:,:,:,Kbb)  = e3v(:,:,:,Kmm)
369
370        ! t- and w- points depth
371        ! ----------------------
372        gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
373        gdepw(:,:,1,Kmm) = 0.0_wp
374
375        DO_3D( 1, 1, 1, 1, 2, jpk )
376          !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere
377          !    tmask = wmask, ie everywhere expect at jk = mikt
378                                                             ! 1 for jk =
379                                                             ! mikt
380           zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
381           gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
382           gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  &
383               &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) + e3w(ji,jj,jk,Kmm))
384        END_3D
385
386        gdept(:,:,:,Kbb) = gdept(:,:,:,Kmm)
387        gdepw(:,:,:,Kbb) = gdepw(:,:,:,Kmm)
388        !
389#endif
390      ENDIF
391      !
392      IF( ln_dynrnf .AND. ln_dynrnf_depth ) THEN       ! read depht over which runoffs are distributed
393         IF(lwp) WRITE(numout,*) 
394         IF(lwp) WRITE(numout,*) ' read in the file depht over which runoffs are distributed'
395         CALL iom_open ( "runoffs", inum )                           ! open file
396         CALL iom_get  ( inum, jpdom_global, 'rodepth', h_rnf )   ! read the river mouth array
397         CALL iom_close( inum )                                        ! close file
398         !
399         nk_rnf(:,:) = 0                               ! set the number of level over which river runoffs are applied
400         DO_2D( 1, 1, 1, 1 )
401            IF( h_rnf(ji,jj) > 0._wp ) THEN
402               jk = 2
403               DO WHILE ( jk /= mbkt(ji,jj) .AND. gdept_0(ji,jj,jk) < h_rnf(ji,jj) ) ;  jk = jk + 1
404               END DO
405               nk_rnf(ji,jj) = jk
406            ELSEIF( h_rnf(ji,jj) == -1._wp   ) THEN   ;  nk_rnf(ji,jj) = 1
407            ELSEIF( h_rnf(ji,jj) == -999._wp ) THEN   ;  nk_rnf(ji,jj) = mbkt(ji,jj)
408            ELSE
409               CALL ctl_stop( 'sbc_rnf_init: runoff depth not positive, and not -999 or -1, rnf value in file fort.999'  )
410               WRITE(999,*) 'ji, jj, h_rnf(ji,jj) :', ji, jj, h_rnf(ji,jj)
411            ENDIF
412         END_2D
413!!st pourquoi on n'utilise pas le gde3w ici plutôt que de faire une boucle ?
414         DO_2D( 1, 1, 1, 1 )
415            h_rnf(ji,jj) = 0._wp
416            DO jk = 1, nk_rnf(ji,jj)
417               h_rnf(ji,jj) = h_rnf(ji,jj) + e3t(ji,jj,jk,Kmm)
418            END DO
419         END_2D
420      ELSE                                       ! runoffs applied at the surface
421         nk_rnf(:,:) = 1
422         h_rnf (:,:) = e3t(:,:,1,Kmm)
423      ENDIF
424      nkrnf_max = MAXVAL( nk_rnf(:,:) )
425      hrnf_max = MAXVAL( h_rnf(:,:) )
426      IF( lk_mpp )  THEN
427         CALL mpp_max( 'dtadyn', nkrnf_max )                 ! max over the  global domain
428         CALL mpp_max( 'dtadyn', hrnf_max )                 ! max over the  global domain
429      ENDIF
430      IF(lwp) WRITE(numout,*) ' '
431      IF(lwp) WRITE(numout,*) ' max depht of runoff : ', hrnf_max,'    max level  : ', nkrnf_max
432      IF(lwp) WRITE(numout,*) ' '
433      !
434      CALL dta_dyn( nit000, Kbb, Kmm, Kaa )
435      !
436   END SUBROUTINE dta_dyn_init
437
438   
439   SUBROUTINE dta_dyn_sed( kt, Kmm )
440      !!----------------------------------------------------------------------
441      !!                  ***  ROUTINE dta_dyn  ***
442      !!
443      !! ** Purpose :  Prepares dynamics and physics fields from a NEMO run
444      !!               for an off-line simulation of passive tracers
445      !!
446      !! ** Method : calculates the position of data
447      !!             - computes slopes if needed
448      !!             - interpolates data if needed
449      !!----------------------------------------------------------------------
450      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
451      INTEGER, INTENT(in) ::   Kmm  ! ocean time level index
452      !
453      !!----------------------------------------------------------------------
454      !
455      IF( ln_timing )   CALL timing_start( 'dta_dyn_sed')
456      !
457      nsecdyn = nsec_year + nsec1jan000   ! number of seconds between Jan. 1st 00h of nit000 year and the middle of time step
458      !
459      IF( kt == nit000 ) THEN    ;    nprevrec = 0
460      ELSE                       ;    nprevrec = sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%naa)
461      ENDIF
462      CALL fld_read( kt, 1, sf_dyn )      !=  read data at kt time step   ==!
463      !
464      ts(:,:,:,jp_tem,Kmm) = sf_dyn(jf_tem)%fnow(:,:,:)  * tmask(:,:,:)    ! temperature
465      ts(:,:,:,jp_sal,Kmm) = sf_dyn(jf_sal)%fnow(:,:,:)  * tmask(:,:,:)    ! salinity
466      !
467      CALL eos    ( ts(:,:,:,:,Kmm), rhd, rhop, gdept_0(:,:,:) ) ! In any case, we need rhop
468
469      IF(sn_cfctl%l_prtctl) THEN                     ! print control
470         CALL prt_ctl(tab3d_1=ts(:,:,:,jp_tem,Kmm), clinfo1=' tn      - : ', mask1=tmask,  kdim=jpk   )
471         CALL prt_ctl(tab3d_1=ts(:,:,:,jp_sal,Kmm), clinfo1=' sn      - : ', mask1=tmask,  kdim=jpk   )
472      ENDIF
473      !
474      IF( ln_timing )   CALL timing_stop( 'dta_dyn_sed')
475      !
476   END SUBROUTINE dta_dyn_sed
477
478
479   SUBROUTINE dta_dyn_sed_init( Kmm )
480      !!----------------------------------------------------------------------
481      !!                  ***  ROUTINE dta_dyn_init  ***
482      !!
483      !! ** Purpose :   Initialisation of the dynamical data
484      !! ** Method  : - read the data namdta_dyn namelist
485      !!----------------------------------------------------------------------
486      INTEGER, INTENT( in ) :: Kmm                   ! ocean time level index
487      !
488      INTEGER  :: ierr, ierr0, ierr1, ierr2, ierr3   ! return error code
489      INTEGER  :: ifpr                               ! dummy loop indice
490      INTEGER  :: jfld                               ! dummy loop arguments
491      INTEGER  :: inum, idv, idimv                   ! local integer
492      INTEGER  :: ios                                ! Local integer output status for namelist read
493      !!
494      CHARACTER(len=100)            ::  cn_dir        !   Root directory for location of core files
495      TYPE(FLD_N), DIMENSION(2) ::  slf_d         ! array of namelist informations on the fields to read
496      TYPE(FLD_N) :: sn_tem , sn_sal   !   "                 "
497      !!
498      NAMELIST/namdta_dyn/cn_dir, ln_dynrnf, ln_dynrnf_depth,  fwbcorr, &
499         &                sn_tem, sn_sal
500      !!----------------------------------------------------------------------
501      !
502      READ  ( numnam_ref, namdta_dyn, IOSTAT = ios, ERR = 901)
503901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist' )
504      READ  ( numnam_cfg, namdta_dyn, IOSTAT = ios, ERR = 902 )
505902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist' )
506      IF(lwm) WRITE ( numond, namdta_dyn )
507      !                                         ! store namelist information in an array
508      !                                         ! Control print
509      IF(lwp) THEN
510         WRITE(numout,*)
511         WRITE(numout,*) 'dta_dyn : offline dynamics '
512         WRITE(numout,*) '~~~~~~~ '
513         WRITE(numout,*) '   Namelist namdta_dyn'
514         WRITE(numout,*) '      runoffs option enabled (T) or not (F)            ln_dynrnf        = ', ln_dynrnf
515         WRITE(numout,*) '      runoffs is spread in vertical                    ln_dynrnf_depth  = ', ln_dynrnf_depth
516         WRITE(numout,*) '      annual global mean of empmr for ssh correction   fwbcorr          = ', fwbcorr
517         WRITE(numout,*)
518      ENDIF
519      !
520      jf_tem  = 1     ;   jf_sal  = 2    ;   jfld   = jf_sal
521      !
522      slf_d(jf_tem)  = sn_tem    ;   slf_d(jf_sal)  = sn_sal
523      !
524      ALLOCATE( sf_dyn(jfld), STAT=ierr )         ! set sf structure
525      IF( ierr > 0 )  THEN
526         CALL ctl_stop( 'dta_dyn: unable to allocate sf structure' )   ;   RETURN
527      ENDIF
528      !                                         ! fill sf with slf_i and control print
529      CALL fld_fill( sf_dyn, slf_d, cn_dir, 'dta_dyn_init', 'Data in file', 'namdta_dyn' )
530      !
531      ! Open file for each variable to get his number of dimension
532      DO ifpr = 1, jfld
533         CALL fld_def( sf_dyn(ifpr) )
534         CALL iom_open( sf_dyn(ifpr)%clname, sf_dyn(ifpr)%num )
535         idv   = iom_varid( sf_dyn(ifpr)%num , slf_d(ifpr)%clvar )        ! id of the variable sdjf%clvar
536         idimv = iom_file ( sf_dyn(ifpr)%num )%ndims(idv)                 ! number of dimension for variable sdjf%clvar
537         CALL iom_close( sf_dyn(ifpr)%num )                               ! close file if already open
538         ierr1=0
539         IF( idimv == 3 ) THEN    ! 2D variable
540                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,1)    , STAT=ierr0 )
541            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,1,2)  , STAT=ierr1 )
542         ELSE                     ! 3D variable
543                                      ALLOCATE( sf_dyn(ifpr)%fnow(jpi,jpj,jpk)  , STAT=ierr0 )
544            IF( slf_d(ifpr)%ln_tint ) ALLOCATE( sf_dyn(ifpr)%fdta(jpi,jpj,jpk,2), STAT=ierr1 )
545         ENDIF
546         IF( ierr0 + ierr1 > 0 ) THEN
547            CALL ctl_stop( 'dta_dyn_init : unable to allocate sf_dyn array structure' )   ;   RETURN
548         ENDIF
549      END DO
550      !
551      CALL dta_dyn_sed( nit000, Kmm )
552      !
553   END SUBROUTINE dta_dyn_sed_init
554
555   
556   SUBROUTINE dta_dyn_atf( kt, Kbb, Kmm, Kaa )
557     !!---------------------------------------------------------------------
558      !!                    ***  ROUTINE dta_dyn_swp  ***
559      !!
560      !! ** Purpose :   Asselin time filter of now SSH
561      !!---------------------------------------------------------------------
562      INTEGER, INTENT(in) :: kt             ! time step
563      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa  ! ocean time level indices
564      !
565      !!---------------------------------------------------------------------
566
567      IF( kt == nit000 ) THEN
568         IF(lwp) WRITE(numout,*)
569         IF(lwp) WRITE(numout,*) 'dta_dyn_atf : Asselin time filter of sea surface height'
570         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
571      ENDIF
572
573      ssh(:,:,Kmm) = ssh(:,:,Kmm) + rn_atfp * ( ssh(:,:,Kbb) - 2 * ssh(:,:,Kmm) + ssh(:,:,Kaa)) 
574
575      !! Do we also need to time filter e3t??
576      !
577   END SUBROUTINE dta_dyn_atf
578   
579   
580#if ! defined key_qco   
581   SUBROUTINE dta_dyn_sf_interp( kt, Kmm )
582      !!---------------------------------------------------------------------
583      !!                    ***  ROUTINE dta_dyn_sf_interp  ***
584      !!
585      !! ** Purpose :   Calculate scale factors at U/V/W points and depths
586      !!                given the after e3t field
587      !!---------------------------------------------------------------------
588      INTEGER, INTENT(in) :: kt   ! time step
589      INTEGER, INTENT(in) :: Kmm  ! ocean time level indices
590      !
591      INTEGER             :: ji, jj, jk
592      REAL(wp)            :: zcoef
593      !!---------------------------------------------------------------------
594
595      ! Horizontal scale factor interpolations
596      ! --------------------------------------
597      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
598      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
599
600      ! Vertical scale factor interpolations
601      ! ------------------------------------
602      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3w (:,:,:,Kmm), 'W' )
603
604      ! t- and w- points depth
605      ! ----------------------
606      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
607      gdepw(:,:,1,Kmm) = 0.0_wp
608      !
609      DO_3D( 1, 1, 1, 1, 2, jpk )
610         zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
611         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
612         gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  &
613            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) + e3w(ji,jj,jk,Kmm))
614      END_3D
615      !
616   END SUBROUTINE dta_dyn_sf_interp
617#endif
618
619
620   SUBROUTINE dta_dyn_ssh( kt, phdivtr, psshb,  pemp, pssha, pe3ta )
621      !!----------------------------------------------------------------------
622      !!                ***  ROUTINE dta_dyn_wzv  ***
623      !!                   
624      !! ** Purpose :   compute the after ssh (ssh(:,:,Kaa)) and the now vertical velocity
625      !!
626      !! ** Method  : Using the incompressibility hypothesis,
627      !!        - the ssh increment is computed by integrating the horizontal divergence
628      !!          and multiply by the time step.
629      !!
630      !!        - compute the after scale factor : repartition of ssh INCREMENT proportionnaly
631      !!                                           to the level thickness ( z-star case )
632      !!
633      !!        - the vertical velocity is computed by integrating the horizontal divergence 
634      !!          from the bottom to the surface minus the scale factor evolution.
635      !!          The boundary conditions are w=0 at the bottom (no flux)
636      !!
637      !! ** action  :   ssh(:,:,Kaa) / e3t(:,:,k,Kaa) / ww
638      !!
639      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
640      !!----------------------------------------------------------------------
641      INTEGER,                                   INTENT(in )    :: kt        !  time-step
642      REAL(wp), DIMENSION(jpi,jpj,jpk)          , INTENT(in )   :: phdivtr   ! horizontal divergence transport
643      REAL(wp), DIMENSION(jpi,jpj)    , OPTIONAL, INTENT(in )   :: psshb     ! now ssh
644      REAL(wp), DIMENSION(jpi,jpj)    , OPTIONAL, INTENT(in )   :: pemp      ! evaporation minus precipitation
645      REAL(wp), DIMENSION(jpi,jpj)    , OPTIONAL, INTENT(inout) :: pssha     ! after ssh
646      REAL(wp), DIMENSION(jpi,jpj,jpk), OPTIONAL, INTENT(out)   :: pe3ta     ! after vertical scale factor
647      !
648      INTEGER                       :: jk
649      REAL(wp), DIMENSION(jpi,jpj)  :: zhdiv 
650      REAL(wp)  :: z2dt 
651      !!----------------------------------------------------------------------
652      !
653      z2dt = 2._wp * rn_Dt
654      !
655      zhdiv(:,:) = 0._wp
656      DO jk = 1, jpkm1
657         zhdiv(:,:) = zhdiv(:,:) +  phdivtr(:,:,jk) * tmask(:,:,jk)
658      END DO
659      !                                                ! Sea surface  elevation time-stepping
660      pssha(:,:) = ( psshb(:,:) - z2dt * ( r1_rho0 * pemp(:,:)  + zhdiv(:,:) ) ) * ssmask(:,:)
661      !
662      IF( PRESENT( pe3ta ) ) THEN                      ! After acale factors at t-points ( z_star coordinate )
663      DO jk = 1, jpkm1
664            pe3ta(:,:,jk) = e3t_0(:,:,jk) * ( 1._wp + pssha(:,:) * r1_ht_0(:,:) * tmask(:,:,jk) )
665      END DO
666      ENDIF
667      !
668   END SUBROUTINE dta_dyn_ssh
669
670
671   SUBROUTINE dta_dyn_hrnf( Kmm )
672      !!----------------------------------------------------------------------
673      !!                  ***  ROUTINE sbc_rnf  ***
674      !!
675      !! ** Purpose :   update the horizontal divergence with the runoff inflow
676      !!
677      !! ** Method  :
678      !!                CAUTION : rnf is positive (inflow) decreasing the
679      !!                          divergence and expressed in m/s
680      !!
681      !! ** Action  :   phdivn   decreased by the runoff inflow
682      !!----------------------------------------------------------------------
683      !!
684      INTEGER, INTENT(in) :: Kmm  ! ocean time level index
685      !
686      INTEGER  ::   ji, jj, jk    ! dummy loop indices
687      !!----------------------------------------------------------------------
688      !
689!!st code dupliqué même remarque que plus haut pourquoi ne pas utiliser gdepw ?
690      DO_2D( 1, 1, 1, 1 )
691         h_rnf(ji,jj) = 0._wp
692         DO jk = 1, nk_rnf(ji,jj)                           ! recalculates h_rnf to be the depth in metres
693             h_rnf(ji,jj) = h_rnf(ji,jj) + e3t(ji,jj,jk,Kmm)   ! to the bottom of the relevant grid box
694         END DO
695      END_2D
696      !
697   END SUBROUTINE dta_dyn_hrnf
698
699
700
701   SUBROUTINE dta_dyn_slp( kt, Kbb, Kmm )
702      !!---------------------------------------------------------------------
703      !!                    ***  ROUTINE dta_dyn_slp  ***
704      !!
705      !! ** Purpose : Computation of slope
706      !!
707      !!---------------------------------------------------------------------
708      INTEGER,  INTENT(in) :: kt       ! time step
709      INTEGER,  INTENT(in) :: Kbb, Kmm ! ocean time level indices
710      !
711      INTEGER  ::   ji, jj     ! dummy loop indices
712      REAL(wp) ::   ztinta     ! ratio applied to after  records when doing time interpolation
713      REAL(wp) ::   ztintb     ! ratio applied to before records when doing time interpolation
714      INTEGER  ::   iswap 
715      REAL(wp), DIMENSION(jpi,jpj,jpk)      ::   zuslp, zvslp, zwslpi, zwslpj
716      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts) ::   zts
717      !!---------------------------------------------------------------------
718      !
719      IF( sf_dyn(jf_tem)%ln_tint ) THEN    ! Computes slopes (here avt is used as workspace)
720         !
721         IF( kt == nit000 ) THEN
722            IF(lwp) WRITE(numout,*) ' Compute new slopes at kt = ', kt
723            zts(:,:,:,jp_tem) = sf_dyn(jf_tem)%fdta(:,:,:,sf_dyn(jf_tem)%nbb) * tmask(:,:,:)   ! temperature
724            zts(:,:,:,jp_sal) = sf_dyn(jf_sal)%fdta(:,:,:,sf_dyn(jf_sal)%nbb) * tmask(:,:,:)   ! salinity
725            avt(:,:,:)        = sf_dyn(jf_avt)%fdta(:,:,:,sf_dyn(jf_avt)%nbb) * tmask(:,:,:)   ! vertical diffusive coef.
726            CALL compute_slopes( kt, zts, zuslp, zvslp, zwslpi, zwslpj, Kbb, Kmm )
727            uslpdta (:,:,:,1) = zuslp (:,:,:) 
728            vslpdta (:,:,:,1) = zvslp (:,:,:) 
729            wslpidta(:,:,:,1) = zwslpi(:,:,:) 
730            wslpjdta(:,:,:,1) = zwslpj(:,:,:) 
731            !
732            zts(:,:,:,jp_tem) = sf_dyn(jf_tem)%fdta(:,:,:,sf_dyn(jf_tem)%naa) * tmask(:,:,:)   ! temperature
733            zts(:,:,:,jp_sal) = sf_dyn(jf_sal)%fdta(:,:,:,sf_dyn(jf_sal)%naa) * tmask(:,:,:)   ! salinity
734            avt(:,:,:)        = sf_dyn(jf_avt)%fdta(:,:,:,sf_dyn(jf_avt)%naa) * tmask(:,:,:)   ! vertical diffusive coef.
735            CALL compute_slopes( kt, zts, zuslp, zvslp, zwslpi, zwslpj, Kbb, Kmm )
736            uslpdta (:,:,:,2) = zuslp (:,:,:) 
737            vslpdta (:,:,:,2) = zvslp (:,:,:) 
738            wslpidta(:,:,:,2) = zwslpi(:,:,:) 
739            wslpjdta(:,:,:,2) = zwslpj(:,:,:) 
740         ELSE
741           !
742           iswap = 0
743           IF( sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%naa) - nprevrec /= 0 )  iswap = 1
744           IF( nsecdyn > sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%nbb) .AND. iswap == 1 )  THEN    ! read/update the after data
745              IF(lwp) WRITE(numout,*) ' Compute new slopes at kt = ', kt
746              uslpdta (:,:,:,1) =  uslpdta (:,:,:,2)         ! swap the data
747              vslpdta (:,:,:,1) =  vslpdta (:,:,:,2) 
748              wslpidta(:,:,:,1) =  wslpidta(:,:,:,2) 
749              wslpjdta(:,:,:,1) =  wslpjdta(:,:,:,2) 
750              !
751              zts(:,:,:,jp_tem) = sf_dyn(jf_tem)%fdta(:,:,:,sf_dyn(jf_tem)%naa) * tmask(:,:,:)   ! temperature
752              zts(:,:,:,jp_sal) = sf_dyn(jf_sal)%fdta(:,:,:,sf_dyn(jf_sal)%naa) * tmask(:,:,:)   ! salinity
753              avt(:,:,:)        = sf_dyn(jf_avt)%fdta(:,:,:,sf_dyn(jf_avt)%naa) * tmask(:,:,:)   ! vertical diffusive coef.
754              CALL compute_slopes( kt, zts, zuslp, zvslp, zwslpi, zwslpj, Kbb, Kmm )
755              !
756              uslpdta (:,:,:,2) = zuslp (:,:,:) 
757              vslpdta (:,:,:,2) = zvslp (:,:,:) 
758              wslpidta(:,:,:,2) = zwslpi(:,:,:) 
759              wslpjdta(:,:,:,2) = zwslpj(:,:,:) 
760            ENDIF
761         ENDIF
762      ENDIF
763      !
764      IF( sf_dyn(jf_tem)%ln_tint )  THEN
765         ztinta =  REAL( nsecdyn - sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%nbb), wp )  &
766            &    / REAL( sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%naa) - sf_dyn(jf_tem)%nrec(2,sf_dyn(jf_tem)%nbb), wp )
767         ztintb =  1. - ztinta
768         IF( l_ldfslp .AND. .NOT.lk_c1d ) THEN    ! Computes slopes (here avt is used as workspace)
769            uslp (:,:,:) = ztintb * uslpdta (:,:,:,1)  + ztinta * uslpdta (:,:,:,2) 
770            vslp (:,:,:) = ztintb * vslpdta (:,:,:,1)  + ztinta * vslpdta (:,:,:,2) 
771            wslpi(:,:,:) = ztintb * wslpidta(:,:,:,1)  + ztinta * wslpidta(:,:,:,2) 
772            wslpj(:,:,:) = ztintb * wslpjdta(:,:,:,1)  + ztinta * wslpjdta(:,:,:,2) 
773         ENDIF
774      ELSE
775         zts(:,:,:,jp_tem) = sf_dyn(jf_tem)%fnow(:,:,:) * tmask(:,:,:)   ! temperature
776         zts(:,:,:,jp_sal) = sf_dyn(jf_sal)%fnow(:,:,:) * tmask(:,:,:)   ! salinity
777         avt(:,:,:)        = sf_dyn(jf_avt)%fnow(:,:,:) * tmask(:,:,:)   ! vertical diffusive coef.
778         CALL compute_slopes( kt, zts, zuslp, zvslp, zwslpi, zwslpj, Kbb, Kmm )
779         !
780         IF( l_ldfslp .AND. .NOT.lk_c1d ) THEN    ! Computes slopes (here avt is used as workspace)
781            uslp (:,:,:) = zuslp (:,:,:)
782            vslp (:,:,:) = zvslp (:,:,:)
783            wslpi(:,:,:) = zwslpi(:,:,:)
784            wslpj(:,:,:) = zwslpj(:,:,:)
785         ENDIF
786      ENDIF
787      !
788   END SUBROUTINE dta_dyn_slp
789
790
791   SUBROUTINE compute_slopes( kt, pts, puslp, pvslp, pwslpi, pwslpj, Kbb, Kmm )
792      !!---------------------------------------------------------------------
793      !!                    ***  ROUTINE dta_dyn_slp  ***
794      !!
795      !! ** Purpose :   Computation of slope
796      !!---------------------------------------------------------------------
797      INTEGER ,                              INTENT(in ) :: kt       ! time step
798      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in ) :: pts      ! temperature/salinity
799      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(out) :: puslp    ! zonal isopycnal slopes
800      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(out) :: pvslp    ! meridional isopycnal slopes
801      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(out) :: pwslpi   ! zonal diapycnal slopes
802      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(out) :: pwslpj   ! meridional diapycnal slopes
803      INTEGER ,                              INTENT(in ) :: Kbb, Kmm ! ocean time level indices
804      !!---------------------------------------------------------------------
805      !
806      IF( l_ldfslp .AND. .NOT.lk_c1d ) THEN    ! Computes slopes (here avt is used as workspace)
807         CALL eos    ( pts, rhd, rhop, gdept_0(:,:,:) )
808         CALL eos_rab( pts, rab_n, Kmm )       ! now local thermal/haline expension ratio at T-points
809         CALL bn2    ( pts, rab_n, rn2, Kmm  ) ! now    Brunt-Vaisala
810
811      ! Partial steps: before Horizontal DErivative
812      IF( ln_zps  .AND. .NOT. ln_isfcav)                            &
813         &            CALL zps_hde    ( kt, Kmm, jpts, pts, gtsu, gtsv,  &  ! Partial steps: before horizontal gradient
814         &                                        rhd, gru , grv    )  ! of t, s, rd at the last ocean level
815      IF( ln_zps .AND.        ln_isfcav)                            &
816         &            CALL zps_hde_isf( kt, Kmm, jpts, pts, gtsu, gtsv, gtui, gtvi, &  ! Partial steps for top cell (ISF)
817         &                                        rhd, gru , grv , grui, grvi )  ! of t, s, rd at the first ocean level
818
819         rn2b(:,:,:) = rn2(:,:,:)                ! needed for zdfmxl
820         CALL zdf_mxl( kt, Kmm )                 ! mixed layer depth
821         CALL ldf_slp( kt, rhd, rn2, Kbb, Kmm )  ! slopes
822         puslp (:,:,:) = uslp (:,:,:)
823         pvslp (:,:,:) = vslp (:,:,:)
824         pwslpi(:,:,:) = wslpi(:,:,:)
825         pwslpj(:,:,:) = wslpj(:,:,:)
826     ELSE
827         puslp (:,:,:) = 0.            ! to avoid warning when compiling
828         pvslp (:,:,:) = 0.
829         pwslpi(:,:,:) = 0.
830         pwslpj(:,:,:) = 0.
831     ENDIF
832      !
833   END SUBROUTINE compute_slopes
834
835   !!======================================================================
836END MODULE dtadyn
Note: See TracBrowser for help on using the repository browser.