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.
sbcwave.F90 in branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90 @ 9117

Last change on this file since 9117 was 9117, checked in by acc, 6 years ago

Branch 2017/dev_merge_2017. Fix uninitialised variables in sbcwave.F90 + 1 efficiency change

  • Property svn:keywords set to Id
File size: 25.3 KB
Line 
1MODULE sbcwave
2   !!======================================================================
3   !!                       ***  MODULE  sbcwave  ***
4   !! Wave module
5   !!======================================================================
6   !! History :  3.3  !  2011-09  (M. Adani)  Original code: Drag Coefficient
7   !!         :  3.4  !  2012-10  (M. Adani)  Stokes Drift
8   !!            3.6  !  2014-09  (E. Clementi,P. Oddo) New Stokes Drift Computation
9   !!             -   !  2016-12  (G. Madec, E. Clementi) update Stoke drift computation
10   !!                                                    + add sbc_wave_ini routine
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   sbc_stokes    : calculate 3D Stokes-drift velocities
15   !!   sbc_wave      : wave data from wave model in netcdf files
16   !!   sbc_wave_init : initialisation fo surface waves
17   !!----------------------------------------------------------------------
18   USE phycst         ! physical constants
19   USE oce            ! ocean variables
20   USE sbc_oce        ! Surface boundary condition: ocean fields
21   USE zdf_oce,  ONLY : ln_zdfswm
22   USE bdy_oce        ! open boundary condition variables
23   USE domvvl         ! domain: variable volume layers
24   !
25   USE iom            ! I/O manager library
26   USE in_out_manager ! I/O manager
27   USE lib_mpp        ! distribued memory computing library
28   USE fldread        ! read input fields
29   USE wrk_nemo       !
30
31   IMPLICIT NONE
32   PRIVATE
33
34   PUBLIC   sbc_stokes      ! routine called in sbccpl
35   PUBLIC   sbc_wstress     ! routine called in sbcmod
36   PUBLIC   sbc_wave        ! routine called in sbcmod
37   PUBLIC   sbc_wave_init   ! routine called in sbcmod
38   
39   ! Variables checking if the wave parameters are coupled (if not, they are read from file)
40   LOGICAL, PUBLIC ::   cpl_hsig   = .FALSE.
41   LOGICAL, PUBLIC ::   cpl_phioc  = .FALSE.
42   LOGICAL, PUBLIC ::   cpl_sdrftx = .FALSE.
43   LOGICAL, PUBLIC ::   cpl_sdrfty = .FALSE.
44   LOGICAL, PUBLIC ::   cpl_wper   = .FALSE.
45   LOGICAL, PUBLIC ::   cpl_wfreq  = .FALSE.
46   LOGICAL, PUBLIC ::   cpl_wnum   = .FALSE.
47   LOGICAL, PUBLIC ::   cpl_tauwoc = .FALSE.
48   LOGICAL, PUBLIC ::   cpl_tauw   = .FALSE.
49   LOGICAL, PUBLIC ::   cpl_wdrag  = .FALSE.
50
51   INTEGER ::   jpfld    ! number of files to read for stokes drift
52   INTEGER ::   jp_usd   ! index of stokes drift  (i-component) (m/s)    at T-point
53   INTEGER ::   jp_vsd   ! index of stokes drift  (j-component) (m/s)    at T-point
54   INTEGER ::   jp_hsw   ! index of significant wave hight      (m)      at T-point
55   INTEGER ::   jp_wmp   ! index of mean wave period            (s)      at T-point
56   INTEGER ::   jp_wfr   ! index of wave peak frequency         (1/s)    at T-point
57
58   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_cd      ! structure of input fields (file informations, fields read) Drag Coefficient
59   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_sd      ! structure of input fields (file informations, fields read) Stokes Drift
60   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_wn      ! structure of input fields (file informations, fields read) wave number for Qiao
61   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_tauwoc  ! structure of input fields (file informations, fields read) normalized wave stress into the ocean
62   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_tauw    ! structure of input fields (file informations, fields read) ocean stress components from wave model
63
64   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   cdn_wave            !:
65   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   hsw, wmp, wnum      !:
66   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   wfreq               !:
67   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   tauoc_wave          !: 
68   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   tauw_x, tauw_y      !: 
69   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   tsd2d               !:
70   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   div_sd              !: barotropic stokes drift divergence
71   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   ut0sd, vt0sd        !: surface Stokes drift velocities at t-point
72   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:) ::   usd  , vsd  , wsd   !: Stokes drift velocities at u-, v- & w-points, resp.
73
74   !! * Substitutions
75#  include "vectopt_loop_substitute.h90"
76   !!----------------------------------------------------------------------
77   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
78   !! $Id$
79   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
80   !!----------------------------------------------------------------------
81CONTAINS
82
83   SUBROUTINE sbc_stokes( )
84      !!---------------------------------------------------------------------
85      !!                     ***  ROUTINE sbc_stokes  ***
86      !!
87      !! ** Purpose :   compute the 3d Stokes Drift according to Breivik et al.,
88      !!                2014 (DOI: 10.1175/JPO-D-14-0020.1)
89      !!
90      !! ** Method  : - Calculate Stokes transport speed
91      !!              - Calculate horizontal divergence
92      !!              - Integrate the horizontal divergenze from the bottom
93      !! ** action 
94      !!---------------------------------------------------------------------
95      INTEGER  ::   jj, ji, jk   ! dummy loop argument
96      INTEGER  ::   ik           ! local integer
97      REAL(wp) ::  ztransp, zfac, zsp0
98      REAL(wp) ::  zdepth, zsqrt_depth,  zexp_depth, z_two_thirds, zsqrtpi !sqrt of pi
99      REAL(wp) ::  zbot_u, zbot_v, zkb_u, zkb_v, zke3_u, zke3_v, zda_u, zda_v
100      REAL(wp) ::  zstokes_psi_u_bot, zstokes_psi_v_bot
101      REAL(wp) ::  zdep_u, zdep_v, zkh_u, zkh_v
102      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   zk_t, zk_u, zk_v, zu0_sd, zv0_sd     ! 2D workspace
103      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   zstokes_psi_u_top, zstokes_psi_v_top ! 2D workspace
104      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3divh                              ! 3D workspace
105      !!---------------------------------------------------------------------
106      !
107      ALLOCATE( ze3divh(jpi,jpj,jpk) )
108      ALLOCATE( zk_t(jpi,jpj), zk_u(jpi,jpj), zk_v(jpi,jpj), zu0_sd(jpi,jpj), zv0_sd(jpi,jpj) )
109      !
110      ! select parameterization for the calculation of vertical Stokes drift
111      ! exp. wave number at t-point
112      IF( ll_st_bv_li ) THEN   ! (Eq. (19) in Breivik et al. (2014) )
113         zfac = 2.0_wp * rpi / 16.0_wp
114         DO jj = 1, jpj
115            DO ji = 1, jpi
116               ! Stokes drift velocity estimated from Hs and Tmean
117               ztransp = zfac * hsw(ji,jj)*hsw(ji,jj) / MAX( wmp(ji,jj), 0.0000001_wp )
118               ! Stokes surface speed
119               tsd2d(ji,jj) = SQRT( ut0sd(ji,jj)*ut0sd(ji,jj) + vt0sd(ji,jj)*vt0sd(ji,jj))
120               ! Wavenumber scale
121               zk_t(ji,jj) = ABS( tsd2d(ji,jj) ) / MAX( ABS( 5.97_wp*ztransp ), 0.0000001_wp )
122            END DO
123         END DO
124         DO jj = 1, jpjm1              ! exp. wave number & Stokes drift velocity at u- & v-points
125            DO ji = 1, jpim1
126               zk_u(ji,jj) = 0.5_wp * ( zk_t(ji,jj) + zk_t(ji+1,jj) )
127               zk_v(ji,jj) = 0.5_wp * ( zk_t(ji,jj) + zk_t(ji,jj+1) )
128               !
129               zu0_sd(ji,jj) = 0.5_wp * ( ut0sd(ji,jj) + ut0sd(ji+1,jj) )
130               zv0_sd(ji,jj) = 0.5_wp * ( vt0sd(ji,jj) + vt0sd(ji,jj+1) )
131            END DO
132         END DO
133      ELSE IF( ll_st_peakfr ) THEN    ! peak wave number calculated from the peak frequency received by the wave model
134         DO jj = 1, jpjm1
135            DO ji = 1, jpim1
136               zk_u(ji,jj) = 0.5_wp * ( wfreq(ji,jj)*wfreq(ji,jj) + wfreq(ji+1,jj)*wfreq(ji+1,jj) ) / grav
137               zk_v(ji,jj) = 0.5_wp * ( wfreq(ji,jj)*wfreq(ji,jj) + wfreq(ji,jj+1)*wfreq(ji,jj+1) ) / grav
138               !
139               zu0_sd(ji,jj) = 0.5_wp * ( ut0sd(ji,jj) + ut0sd(ji+1,jj) )
140               zv0_sd(ji,jj) = 0.5_wp * ( vt0sd(ji,jj) + vt0sd(ji,jj+1) )
141            END DO
142         END DO
143      ENDIF
144      !
145      !                       !==  horizontal Stokes Drift 3D velocity  ==!
146      IF( ll_st_bv2014 ) THEN
147         DO jk = 1, jpkm1
148            DO jj = 2, jpjm1
149               DO ji = 2, jpim1
150                  zdep_u = 0.5_wp * ( gdept_n(ji,jj,jk) + gdept_n(ji+1,jj,jk) )
151                  zdep_v = 0.5_wp * ( gdept_n(ji,jj,jk) + gdept_n(ji,jj+1,jk) )
152                  !                         
153                  zkh_u = zk_u(ji,jj) * zdep_u     ! k * depth
154                  zkh_v = zk_v(ji,jj) * zdep_v
155                  !                                ! Depth attenuation
156                  zda_u = EXP( -2.0_wp*zkh_u ) / ( 1.0_wp + 8.0_wp*zkh_u )
157                  zda_v = EXP( -2.0_wp*zkh_v ) / ( 1.0_wp + 8.0_wp*zkh_v )
158                  !
159                  usd(ji,jj,jk) = zda_u * zu0_sd(ji,jj) * umask(ji,jj,jk)
160                  vsd(ji,jj,jk) = zda_v * zv0_sd(ji,jj) * vmask(ji,jj,jk)
161               END DO
162            END DO
163         END DO
164      ELSE IF( ll_st_li2017 .OR. ll_st_peakfr ) THEN
165         ALLOCATE( zstokes_psi_u_top(jpi,jpj), zstokes_psi_v_top(jpi,jpj) )
166         DO jj = 1, jpjm1              ! exp. wave number & Stokes drift velocity at u- & v-points
167            DO ji = 1, jpim1
168               zstokes_psi_u_top(ji,jj) = 0._wp
169               zstokes_psi_v_top(ji,jj) = 0._wp
170            END DO
171         END DO
172         zsqrtpi = SQRT(rpi)
173         z_two_thirds = 2.0_wp / 3.0_wp
174         DO jk = 1, jpkm1
175            DO jj = 2, jpjm1
176               DO ji = 2, jpim1
177                  zbot_u = ( gdepw_n(ji,jj,jk+1) + gdepw_n(ji+1,jj,jk+1) )  ! 2 * bottom depth
178                  zbot_v = ( gdepw_n(ji,jj,jk+1) + gdepw_n(ji,jj+1,jk+1) )  ! 2 * bottom depth
179                  zkb_u  = zk_u(ji,jj) * zbot_u                             ! 2 * k * bottom depth
180                  zkb_v  = zk_v(ji,jj) * zbot_v                             ! 2 * k * bottom depth
181                  !
182                  zke3_u = MAX(1.e-8_wp, 2.0_wp * zk_u(ji,jj) * e3u_n(ji,jj,jk))     ! 2k * thickness
183                  zke3_v = MAX(1.e-8_wp, 2.0_wp * zk_v(ji,jj) * e3v_n(ji,jj,jk))     ! 2k * thickness
184
185                  ! Depth attenuation .... do u component first..
186                  zdepth      = zkb_u
187                  zsqrt_depth = SQRT(zdepth)
188                  zexp_depth  = EXP(-zdepth)
189                  zstokes_psi_u_bot = 1.0_wp - zexp_depth  &
190                       &              - z_two_thirds * ( zsqrtpi*zsqrt_depth*zdepth*ERFC(zsqrt_depth) &
191                       &              + 1.0_wp - (1.0_wp + zdepth)*zexp_depth )
192                  zda_u                    = ( zstokes_psi_u_bot - zstokes_psi_u_top(ji,jj) ) / zke3_u
193                  zstokes_psi_u_top(ji,jj) =   zstokes_psi_u_bot
194
195                  !         ... and then v component
196                  zdepth      =zkb_v
197                  zsqrt_depth = SQRT(zdepth)
198                  zexp_depth  = EXP(-zdepth)
199                  zstokes_psi_v_bot = 1.0_wp - zexp_depth  &
200                       &              - z_two_thirds * ( zsqrtpi*zsqrt_depth*zdepth*ERFC(zsqrt_depth) &
201                       &              + 1.0_wp - (1.0_wp + zdepth)*zexp_depth )
202                  zda_v                    = ( zstokes_psi_v_bot - zstokes_psi_v_top(ji,jj) ) / zke3_v
203                  zstokes_psi_v_top(ji,jj) =   zstokes_psi_v_bot
204                  !
205                  usd(ji,jj,jk) = zda_u * zu0_sd(ji,jj) * umask(ji,jj,jk)
206                  vsd(ji,jj,jk) = zda_v * zv0_sd(ji,jj) * vmask(ji,jj,jk)
207               END DO
208            END DO
209         END DO
210         DEALLOCATE( zstokes_psi_u_top, zstokes_psi_v_top )
211      ENDIF
212
213      CALL lbc_lnk_multi( usd, 'U', -1., vsd, 'V', -1. )
214
215      !
216      !                       !==  vertical Stokes Drift 3D velocity  ==!
217      !
218      DO jk = 1, jpkm1               ! Horizontal e3*divergence
219         DO jj = 2, jpj
220            DO ji = fs_2, jpi
221               ze3divh(ji,jj,jk) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * usd(ji  ,jj,jk)    &
222                  &                 - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * usd(ji-1,jj,jk)    &
223                  &                 + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vsd(ji,jj  ,jk)    &
224                  &                 - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vsd(ji,jj-1,jk)  ) * r1_e1e2t(ji,jj)
225            END DO
226         END DO
227      END DO
228      !
229#if defined key_agrif
230      IF( .NOT. Agrif_Root() ) THEN
231         IF( nbondi == -1 .OR. nbondi == 2 )   ze3divh( 2:nbghostcells+1,:        ,:) = 0._wp      ! west
232         IF( nbondi ==  1 .OR. nbondi == 2 )   ze3divh( nlci-nbghostcells:nlci-1,:,:) = 0._wp      ! east
233         IF( nbondj == -1 .OR. nbondj == 2 )   ze3divh( :,2:nbghostcells+1        ,:) = 0._wp      ! south
234         IF( nbondj ==  1 .OR. nbondj == 2 )   ze3divh( :,nlcj-nbghostcells:nlcj-1,:) = 0._wp      ! north
235      ENDIF
236#endif
237      !
238      CALL lbc_lnk( ze3divh, 'T', 1. )
239      !
240      IF( ln_linssh ) THEN   ;   ik = 1   ! none zero velocity through the sea surface
241      ELSE                   ;   ik = 2   ! w=0 at the surface (set one for all in sbc_wave_init)
242      ENDIF
243      DO jk = jpkm1, ik, -1          ! integrate from the bottom the hor. divergence (NB: at k=jpk w is always zero)
244         wsd(:,:,jk) = wsd(:,:,jk+1) - ze3divh(:,:,jk)
245      END DO
246      !
247      IF( ln_bdy ) THEN
248         DO jk = 1, jpkm1
249            wsd(:,:,jk) = wsd(:,:,jk) * bdytmask(:,:)
250         END DO
251      ENDIF
252      !                       !==  Horizontal divergence of barotropic Stokes transport  ==!
253      div_sd(:,:) = 0._wp
254      DO jk = 1, jpkm1                                 !
255        div_sd(:,:) = div_sd(:,:) + ze3divh(:,:,jk)
256      END DO
257      !
258      CALL iom_put( "ustokes",  usd  )
259      CALL iom_put( "vstokes",  vsd  )
260      CALL iom_put( "wstokes",  wsd  )
261      !
262      DEALLOCATE( ze3divh )
263      DEALLOCATE( zk_t, zk_u, zk_v, zu0_sd, zv0_sd )
264      !
265   END SUBROUTINE sbc_stokes
266
267
268   SUBROUTINE sbc_wstress( )
269      !!---------------------------------------------------------------------
270      !!                     ***  ROUTINE sbc_wstress  ***
271      !!
272      !! ** Purpose :   Updates the ocean momentum modified by waves
273      !!
274      !! ** Method  : - Calculate u,v components of stress depending on stress
275      !!                model
276      !!              - Calculate the stress module
277      !!              - The wind module is not modified by waves
278      !! ** action 
279      !!---------------------------------------------------------------------
280      INTEGER  ::   jj, ji   ! dummy loop argument
281      !
282      IF( ln_tauwoc ) THEN
283         utau(:,:) = utau(:,:)*tauoc_wave(:,:)
284         vtau(:,:) = vtau(:,:)*tauoc_wave(:,:)
285         taum(:,:) = taum(:,:)*tauoc_wave(:,:)
286      ENDIF
287      !
288      IF( ln_tauw ) THEN
289         DO jj = 1, jpjm1
290            DO ji = 1, jpim1
291               ! Stress components at u- & v-points
292               utau(ji,jj) = 0.5_wp * ( tauw_x(ji,jj) + tauw_x(ji+1,jj) )
293               vtau(ji,jj) = 0.5_wp * ( tauw_y(ji,jj) + tauw_y(ji,jj+1) )
294               !
295               ! Stress module at t points
296               taum(ji,jj) = SQRT( tauw_x(ji,jj)*tauw_x(ji,jj) + tauw_y(ji,jj)*tauw_y(ji,jj) )
297            END DO
298         END DO
299         CALL lbc_lnk_multi( utau(:,:), 'U', -1. , vtau(:,:), 'V', -1. , taum(:,:) , 'T', -1. )
300      ENDIF
301      !
302   END SUBROUTINE sbc_wstress
303
304
305   SUBROUTINE sbc_wave( kt )
306      !!---------------------------------------------------------------------
307      !!                     ***  ROUTINE sbc_wave  ***
308      !!
309      !! ** Purpose :   read wave parameters from wave model  in netcdf files.
310      !!
311      !! ** Method  : - Read namelist namsbc_wave
312      !!              - Read Cd_n10 fields in netcdf files
313      !!              - Read stokes drift 2d in netcdf files
314      !!              - Read wave number in netcdf files
315      !!              - Compute 3d stokes drift using Breivik et al.,2014
316      !!                formulation
317      !! ** action 
318      !!---------------------------------------------------------------------
319      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
320      !!---------------------------------------------------------------------
321      !
322      IF( ln_cdgw .AND. .NOT. cpl_wdrag ) THEN     !==  Neutral drag coefficient  ==!
323         CALL fld_read( kt, nn_fsbc, sf_cd )             ! read from external forcing
324         cdn_wave(:,:) = sf_cd(1)%fnow(:,:,1)
325      ENDIF
326
327      IF( ln_tauwoc .AND. .NOT. cpl_tauwoc ) THEN  !==  Wave induced stress  ==!
328         CALL fld_read( kt, nn_fsbc, sf_tauwoc )         ! read wave norm stress from external forcing
329         tauoc_wave(:,:) = sf_tauwoc(1)%fnow(:,:,1)
330      ENDIF
331
332      IF( ln_tauw .AND. .NOT. cpl_tauw ) THEN      !==  Wave induced stress  ==!
333         CALL fld_read( kt, nn_fsbc, sf_tauw )           ! read ocean stress components from external forcing (T grid)
334         tauw_x(:,:) = sf_tauw(1)%fnow(:,:,1)
335         tauw_y(:,:) = sf_tauw(2)%fnow(:,:,1)
336      ENDIF
337
338      IF( ln_sdw )  THEN                           !==  Computation of the 3d Stokes Drift  ==!
339         !
340         IF( jpfld > 0 ) THEN                            ! Read from file only if the field is not coupled
341            CALL fld_read( kt, nn_fsbc, sf_sd )          ! read wave parameters from external forcing
342            IF( jp_hsw > 0 )   hsw  (:,:) = sf_sd(jp_hsw)%fnow(:,:,1)   ! significant wave height
343            IF( jp_wmp > 0 )   wmp  (:,:) = sf_sd(jp_wmp)%fnow(:,:,1)   ! wave mean period
344            IF( jp_wfr > 0 )   wfreq(:,:) = sf_sd(jp_wfr)%fnow(:,:,1)   ! Peak wave frequency
345            IF( jp_usd > 0 )   ut0sd(:,:) = sf_sd(jp_usd)%fnow(:,:,1)   ! 2D zonal Stokes Drift at T point
346            IF( jp_vsd > 0 )   vt0sd(:,:) = sf_sd(jp_vsd)%fnow(:,:,1)   ! 2D meridional Stokes Drift at T point
347         ENDIF
348         !
349         ! Read also wave number if needed, so that it is available in coupling routines
350         IF( ln_zdfswm .AND. .NOT.cpl_wnum ) THEN
351            CALL fld_read( kt, nn_fsbc, sf_wn )          ! read wave parameters from external forcing
352            wnum(:,:) = sf_wn(1)%fnow(:,:,1)
353         ENDIF
354           
355         ! Calculate only if required fields have been read
356         ! In coupled wave model-NEMO case the call is done after coupling
357         !
358         IF( ( ll_st_bv_li   .AND. jp_hsw>0 .AND. jp_wmp>0 .AND. jp_usd>0 .AND. jp_vsd>0 ) .OR. &
359           & ( ll_st_peakfr  .AND. jp_wfr>0 .AND. jp_usd>0 .AND. jp_vsd>0                ) ) CALL sbc_stokes()
360         !
361      ENDIF
362      !
363   END SUBROUTINE sbc_wave
364
365
366   SUBROUTINE sbc_wave_init
367      !!---------------------------------------------------------------------
368      !!                     ***  ROUTINE sbc_wave_init  ***
369      !!
370      !! ** Purpose :   read wave parameters from wave model  in netcdf files.
371      !!
372      !! ** Method  : - Read namelist namsbc_wave
373      !!              - Read Cd_n10 fields in netcdf files
374      !!              - Read stokes drift 2d in netcdf files
375      !!              - Read wave number in netcdf files
376      !!              - Compute 3d stokes drift using Breivik et al.,2014
377      !!                formulation
378      !! ** action 
379      !!---------------------------------------------------------------------
380      INTEGER ::   ierror, ios   ! local integer
381      INTEGER ::   ifpr
382      !!
383      CHARACTER(len=100)     ::  cn_dir                            ! Root directory for location of drag coefficient files
384      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::   slf_i, slf_j     ! array of namelist informations on the fields to read
385      TYPE(FLD_N)            ::  sn_cdg, sn_usd, sn_vsd,  &
386                             &   sn_hsw, sn_wmp, sn_wfr, sn_wnum, &
387                             &   sn_tauwoc, sn_tauwx, sn_tauwy     ! informations about the fields to be read
388      !
389      NAMELIST/namsbc_wave/  sn_cdg, cn_dir, sn_usd, sn_vsd, sn_hsw, sn_wmp, sn_wfr, &
390                             sn_wnum, sn_tauwoc, sn_tauwx, sn_tauwy
391      !!---------------------------------------------------------------------
392      !
393      REWIND( numnam_ref )              ! Namelist namsbc_wave in reference namelist : File for drag coeff. from wave model
394      READ  ( numnam_ref, namsbc_wave, IOSTAT = ios, ERR = 901)
395901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_wave in reference namelist', lwp )
396         
397      REWIND( numnam_cfg )              ! Namelist namsbc_wave in configuration namelist : File for drag coeff. from wave model
398      READ  ( numnam_cfg, namsbc_wave, IOSTAT = ios, ERR = 902 )
399902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_wave in configuration namelist', lwp )
400      IF(lwm) WRITE ( numond, namsbc_wave )
401      !
402      IF( ln_cdgw ) THEN
403         IF( .NOT. cpl_wdrag ) THEN
404            ALLOCATE( sf_cd(1), STAT=ierror )               !* allocate and fill sf_wave with sn_cdg
405            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_wave structure' )
406            !
407                                   ALLOCATE( sf_cd(1)%fnow(jpi,jpj,1)   )
408            IF( sn_cdg%ln_tint )   ALLOCATE( sf_cd(1)%fdta(jpi,jpj,1,2) )
409            CALL fld_fill( sf_cd, (/ sn_cdg /), cn_dir, 'sbc_wave_init', 'Wave module ', 'namsbc_wave' )
410         ENDIF
411         ALLOCATE( cdn_wave(jpi,jpj) )
412      ENDIF
413
414      IF( ln_tauwoc ) THEN
415         IF( .NOT. cpl_tauwoc ) THEN
416            ALLOCATE( sf_tauwoc(1), STAT=ierror )           !* allocate and fill sf_wave with sn_tauwoc
417            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_wave structure' )
418            !
419                                     ALLOCATE( sf_tauwoc(1)%fnow(jpi,jpj,1)   )
420            IF( sn_tauwoc%ln_tint )  ALLOCATE( sf_tauwoc(1)%fdta(jpi,jpj,1,2) )
421            CALL fld_fill( sf_tauwoc, (/ sn_tauwoc /), cn_dir, 'sbc_wave_init', 'Wave module', 'namsbc_wave' )
422         ENDIF
423         ALLOCATE( tauoc_wave(jpi,jpj) )
424      ENDIF
425
426      IF( ln_tauw ) THEN
427         IF( .NOT. cpl_tauw ) THEN
428            ALLOCATE( sf_tauw(2), STAT=ierror )           !* allocate and fill sf_wave with sn_tauwx/y
429            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_tauw structure' )
430            !
431            ALLOCATE( slf_j(2) )
432            slf_j(1) = sn_tauwx
433            slf_j(2) = sn_tauwy
434                                    ALLOCATE( sf_tauw(1)%fnow(jpi,jpj,1)   )
435                                    ALLOCATE( sf_tauw(2)%fnow(jpi,jpj,1)   )
436            IF( slf_j(1)%ln_tint )  ALLOCATE( sf_tauw(1)%fdta(jpi,jpj,1,2) )
437            IF( slf_j(2)%ln_tint )  ALLOCATE( sf_tauw(2)%fdta(jpi,jpj,1,2) )
438            CALL fld_fill( sf_tauw, (/ slf_j /), cn_dir, 'sbc_wave_init', 'read wave input', 'namsbc_wave' )
439         ENDIF
440         ALLOCATE( tauw_x(jpi,jpj) )
441         ALLOCATE( tauw_y(jpi,jpj) )
442      ENDIF
443
444      IF( ln_sdw ) THEN   ! Find out how many fields have to be read from file if not coupled
445         jpfld=0
446         jp_usd=0   ;   jp_vsd=0   ;   jp_hsw=0   ;   jp_wmp=0   ;   jp_wfr=0
447         IF( .NOT. cpl_sdrftx ) THEN
448            jpfld  = jpfld + 1
449            jp_usd = jpfld
450         ENDIF
451         IF( .NOT. cpl_sdrfty ) THEN
452            jpfld  = jpfld + 1
453            jp_vsd = jpfld
454         ENDIF
455         IF( .NOT. cpl_hsig  .AND. ll_st_bv_li  ) THEN
456            jpfld  = jpfld + 1
457            jp_hsw = jpfld
458         ENDIF
459         IF( .NOT. cpl_wper  .AND. ll_st_bv_li  ) THEN
460            jpfld  = jpfld + 1
461            jp_wmp = jpfld
462         ENDIF
463         IF( .NOT. cpl_wfreq .AND. ll_st_peakfr ) THEN
464            jpfld  = jpfld + 1
465            jp_wfr = jpfld
466         ENDIF
467
468         ! Read from file only the non-coupled fields
469         IF( jpfld > 0 ) THEN
470            ALLOCATE( slf_i(jpfld) )
471            IF( jp_usd > 0 )   slf_i(jp_usd) = sn_usd
472            IF( jp_vsd > 0 )   slf_i(jp_vsd) = sn_vsd
473            IF( jp_hsw > 0 )   slf_i(jp_hsw) = sn_hsw
474            IF( jp_wmp > 0 )   slf_i(jp_wmp) = sn_wmp
475            IF( jp_wfr > 0 )   slf_i(jp_wfr) = sn_wfr
476
477            ALLOCATE( sf_sd(jpfld), STAT=ierror )   !* allocate and fill sf_sd with stokes drift
478            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_wave structure' )
479            !
480            DO ifpr= 1, jpfld
481               ALLOCATE( sf_sd(ifpr)%fnow(jpi,jpj,1) )
482               IF( slf_i(ifpr)%ln_tint )   ALLOCATE( sf_sd(ifpr)%fdta(jpi,jpj,1,2) )
483            END DO
484            !
485            CALL fld_fill( sf_sd, slf_i, cn_dir, 'sbc_wave_init', 'Wave module ', 'namsbc_wave' )
486         ENDIF
487         ALLOCATE( usd  (jpi,jpj,jpk), vsd  (jpi,jpj,jpk), wsd(jpi,jpj,jpk) )
488         ALLOCATE( hsw  (jpi,jpj)    , wmp  (jpi,jpj)     )
489         ALLOCATE( wfreq(jpi,jpj) )
490         ALLOCATE( ut0sd(jpi,jpj)    , vt0sd(jpi,jpj)     )
491         ALLOCATE( div_sd(jpi,jpj) )
492         ALLOCATE( tsd2d (jpi,jpj) )
493
494         ut0sd(:,:) = 0._wp
495         vt0sd(:,:) = 0._wp
496         hsw(:,:) = 0._wp
497         wmp(:,:) = 0._wp
498
499         usd(:,:,:) = 0._wp
500         vsd(:,:,:) = 0._wp
501         wsd(:,:,:) = 0._wp
502         ! Wave number needed only if ln_zdfswm=T
503         IF( .NOT. cpl_wnum ) THEN
504            ALLOCATE( sf_wn(1), STAT=ierror )           !* allocate and fill sf_wave with sn_wnum
505            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable toallocate sf_wave structure' )
506                                   ALLOCATE( sf_wn(1)%fnow(jpi,jpj,1)   )
507            IF( sn_wnum%ln_tint )  ALLOCATE( sf_wn(1)%fdta(jpi,jpj,1,2) )
508            CALL fld_fill( sf_wn, (/ sn_wnum /), cn_dir, 'sbc_wave', 'Wave module', 'namsbc_wave' )
509         ENDIF
510         ALLOCATE( wnum(jpi,jpj) )
511      ENDIF
512      !
513   END SUBROUTINE sbc_wave_init
514
515   !!======================================================================
516END MODULE sbcwave
Note: See TracBrowser for help on using the repository browser.