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.
sbcrnf.F90 in branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90 @ 11738

Last change on this file since 11738 was 11738, checked in by marc, 5 years ago

The Dr Hook changes from my perl code.

File size: 31.1 KB
Line 
1MODULE sbcrnf
2   !!======================================================================
3   !!                       ***  MODULE  sbcrnf  ***
4   !! Ocean forcing:  river runoff
5   !!=====================================================================
6   !! History :  OPA  ! 2000-11  (R. Hordoir, E. Durand)  NetCDF FORMAT
7   !!   NEMO     1.0  ! 2002-09  (G. Madec)  F90: Free form and module
8   !!            3.0  ! 2006-07  (G. Madec)  Surface module
9   !!            3.2  ! 2009-04  (B. Lemaire)  Introduce iom_put
10   !!            3.3  ! 2010-10  (R. Furner, G. Madec) runoff distributed over ocean levels
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   sbc_rnf      : monthly runoffs read in a NetCDF file
15   !!   sbc_rnf_init : runoffs initialisation
16   !!   rnf_mouth    : set river mouth mask
17   !!----------------------------------------------------------------------
18   USE dom_oce         ! ocean space and time domain
19   USE phycst          ! physical constants
20   USE sbc_oce         ! surface boundary condition variables
21   USE sbcisf          ! PM we could remove it I think
22   USE closea          ! closed seas
23   USE fldread         ! read input field at current time step
24   USE in_out_manager  ! I/O manager
25   USE iom             ! I/O module
26   USE lib_mpp         ! MPP library
27   USE eosbn2
28   USE wrk_nemo        ! Memory allocation
29   USE timing
30
31   USE yomhook, ONLY: lhook, dr_hook
32   USE parkind1, ONLY: jprb, jpim
33
34   IMPLICIT NONE
35   PRIVATE
36
37   PUBLIC   sbc_rnf       ! routine call in sbcmod module
38   PUBLIC   sbc_rnf_div   ! routine called in divcurl module
39   PUBLIC   sbc_rnf_alloc ! routine call in sbcmod module
40   PUBLIC   sbc_rnf_init  ! (PUBLIC for TAM)
41   !                                                     !!* namsbc_rnf namelist *
42   CHARACTER(len=100)         ::   cn_dir          !: Root directory for location of rnf files
43   LOGICAL                    ::   ln_rnf_depth      !: depth       river runoffs attribute specified in a file
44   LOGICAL                    ::   ln_rnf_depth_ini  !: depth       river runoffs  computed at the initialisation
45   REAL(wp)                   ::   rn_rnf_max        !: maximum value of the runoff climatologie ( ln_rnf_depth_ini = .true )
46   REAL(wp)                   ::   rn_dep_max        !: depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
47   INTEGER                    ::   nn_rnf_depth_file !: create (=1) a runoff depth file or not (=0)
48   LOGICAL                    ::   ln_rnf_tem      !: temperature river runoffs attribute specified in a file
49   LOGICAL           , PUBLIC ::   ln_rnf_sal      !: salinity    river runoffs attribute specified in a file
50   TYPE(FLD_N)       , PUBLIC ::   sn_rnf          !: information about the runoff file to be read
51   TYPE(FLD_N)                ::   sn_cnf          !: information about the runoff mouth file to be read
52   TYPE(FLD_N)                ::   sn_s_rnf        !: information about the salinities of runoff file to be read
53   TYPE(FLD_N)                ::   sn_t_rnf        !: information about the temperatures of runoff file to be read
54   TYPE(FLD_N)                ::   sn_dep_rnf      !: information about the depth which river inflow affects
55   LOGICAL           , PUBLIC ::   ln_rnf_mouth    !: specific treatment in mouths vicinity
56   REAL(wp)                   ::   rn_hrnf         !: runoffs, depth over which enhanced vertical mixing is used
57   REAL(wp)          , PUBLIC ::   rn_avt_rnf      !: runoffs, value of the additional vertical mixing coef. [m2/s]
58   REAL(wp)          , PUBLIC ::   rn_rfact        !: multiplicative factor for runoff
59
60   LOGICAL           , PUBLIC ::   l_rnfcpl = .false.       ! runoffs recieved from oasis
61
62   INTEGER , PUBLIC  ::   nkrnf = 0         !: nb of levels over which Kz is increased at river mouths
63   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rnfmsk              !: river mouth mask (hori.)
64   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)     ::   rnfmsk_z            !: river mouth mask (vert.)
65   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   h_rnf               !: depth of runoff in m
66   INTEGER,  PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   nk_rnf              !: depth of runoff in model levels
67   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   rnf_tsc_b, rnf_tsc  !: before and now T & S runoff contents   [K.m/s & PSU.m/s]   
68
69   TYPE(FLD),        ALLOCATABLE, DIMENSION(:) ::   sf_rnf       ! structure: river runoff (file information, fields read)
70   TYPE(FLD),        ALLOCATABLE, DIMENSION(:) ::   sf_s_rnf     ! structure: river runoff salinity (file information, fields read) 
71   TYPE(FLD),        ALLOCATABLE, DIMENSION(:) ::   sf_t_rnf     ! structure: river runoff temperature (file information, fields read) 
72 
73   !! * Substitutions 
74#  include "domzgr_substitute.h90" 
75   !!----------------------------------------------------------------------
76   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
77   !! $Id$
78   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
79   !!----------------------------------------------------------------------
80CONTAINS
81
82   INTEGER FUNCTION sbc_rnf_alloc()
83   INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
84   INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
85   REAL(KIND=jprb)               :: zhook_handle
86
87   CHARACTER(LEN=*), PARAMETER :: RoutineName='SBC_RNF_ALLOC'
88
89   IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
90
91      !!----------------------------------------------------------------------
92      !!                ***  ROUTINE sbc_rnf_alloc  ***
93      !!----------------------------------------------------------------------
94      ALLOCATE( rnfmsk(jpi,jpj)         , rnfmsk_z(jpk)          ,     &
95         &      h_rnf (jpi,jpj)         , nk_rnf  (jpi,jpj)      ,     &
96         &      rnf_tsc_b(jpi,jpj,jpts) , rnf_tsc (jpi,jpj,jpts) , STAT=sbc_rnf_alloc )
97         !
98      IF( lk_mpp            )   CALL mpp_sum ( sbc_rnf_alloc )
99      IF( sbc_rnf_alloc > 0 )   CALL ctl_warn('sbc_rnf_alloc: allocation of arrays failed')
100   IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
101   END FUNCTION sbc_rnf_alloc
102
103
104   SUBROUTINE sbc_rnf( kt )
105      !!----------------------------------------------------------------------
106      !!                  ***  ROUTINE sbc_rnf  ***
107      !!
108      !! ** Purpose :   Introduce a climatological run off forcing
109      !!
110      !! ** Method  :   Set each river mouth with a monthly climatology
111      !!                provided from different data.
112      !!                CAUTION : upward water flux, runoff forced to be < 0
113      !!
114      !! ** Action  :   runoff updated runoff field at time-step kt
115      !!----------------------------------------------------------------------
116      INTEGER, INTENT(in) ::   kt          ! ocean time step
117      !
118      INTEGER  ::   ji, jj    ! dummy loop indices
119      INTEGER  ::   z_err = 0 ! dummy integer for error handling
120      !!----------------------------------------------------------------------
121      REAL(wp), DIMENSION(:,:), POINTER       ::   ztfrz   ! freezing point used for temperature correction
122      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
123      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
124      REAL(KIND=jprb)               :: zhook_handle
125
126      CHARACTER(LEN=*), PARAMETER :: RoutineName='SBC_RNF'
127
128      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
129
130      !
131      CALL wrk_alloc( jpi,jpj, ztfrz)
132      !
133      !                                            !-------------------!
134      !                                            !   Update runoff   !
135      !                                            !-------------------!
136      !
137      IF( .NOT. l_rnfcpl )   CALL fld_read ( kt, nn_fsbc, sf_rnf   )    ! Read Runoffs data and provide it at kt
138      IF(   ln_rnf_tem   )   CALL fld_read ( kt, nn_fsbc, sf_t_rnf )    ! idem for runoffs temperature if required
139      IF(   ln_rnf_sal   )   CALL fld_read ( kt, nn_fsbc, sf_s_rnf )    ! idem for runoffs salinity    if required
140      !
141      IF( MOD( kt - 1, nn_fsbc ) == 0 ) THEN
142         !
143         IF( .NOT. l_rnfcpl )   rnf(:,:) = rn_rfact * ( sf_rnf(1)%fnow(:,:,1) )       ! updated runoff value at time step kt
144         CALL lbc_lnk(rnf(:,:), 'T', 1._wp)
145         !
146         !                                                     ! set temperature & salinity content of runoffs
147         IF( ln_rnf_tem ) THEN                                       ! use runoffs temperature data
148            rnf_tsc(:,:,jp_tem) = ( sf_t_rnf(1)%fnow(:,:,1) ) * rnf(:,:) * r1_rau0
149            WHERE( sf_t_rnf(1)%fnow(:,:,1) == -999._wp )             ! if missing data value use SST as runoffs temperature
150               rnf_tsc(:,:,jp_tem) = sst_m(:,:) * rnf(:,:) * r1_rau0
151            END WHERE
152            WHERE( sf_t_rnf(1)%fnow(:,:,1) == -222._wp )             ! where fwf comes from melting of ice shelves or iceberg
153               ztfrz(:,:) = -1.9 !tfreez( sss_m(:,:) ) !PM to be discuss (trouble if sensitivity study)
154               rnf_tsc(:,:,jp_tem) = ztfrz(:,:) * rnf(:,:) * r1_rau0 - rnf(:,:) * lfusisf * r1_rau0_rcp
155            END WHERE
156         ELSE                                                        ! use SST as runoffs temperature
157            rnf_tsc(:,:,jp_tem) = sst_m(:,:) * rnf(:,:) * r1_rau0
158         ENDIF
159         !                                                           ! use runoffs salinity data
160         IF( ln_rnf_sal )   rnf_tsc(:,:,jp_sal) = ( sf_s_rnf(1)%fnow(:,:,1) ) * rnf(:,:) * r1_rau0
161         !                                                           ! else use S=0 for runoffs (done one for all in the init)
162         CALL iom_put( "runoffs", rnf )         ! output runoffs arrays
163      ENDIF
164      !
165      !                                                ! ---------------------------------------- !
166      IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
167         !                                             ! ---------------------------------------- !
168         IF( ln_rstart .AND.    &                               !* Restart: read in restart file
169            & iom_varid( numror, 'rnf_b', ldstop = .FALSE. ) > 0 ) THEN
170            IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file'
171            IF(nn_timing == 2)  CALL timing_start('iom_rstget')
172            CALL iom_get( numror, jpdom_autoglo, 'rnf_b', rnf_b )     ! before runoff
173            CALL iom_get( numror, jpdom_autoglo, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem) )   ! before heat content of runoff
174            CALL iom_get( numror, jpdom_autoglo, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal) )   ! before salinity content of runoff
175            IF(nn_timing == 2)  CALL timing_stop('iom_rstget')
176         ELSE                                                   !* no restart: set from nit000 values
177            IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields set to nit000'
178            rnf_b    (:,:  ) = rnf    (:,:  )
179            rnf_tsc_b(:,:,:) = rnf_tsc(:,:,:)
180         ENDIF
181      ENDIF
182      !                                                ! ---------------------------------------- !
183      IF( lrst_oce ) THEN                              !      Write in the ocean restart file     !
184         !                                             ! ---------------------------------------- !
185         IF(lwp) WRITE(numout,*)
186         IF(lwp) WRITE(numout,*) 'sbcrnf : runoff forcing fields written in ocean restart file ',   &
187            &                    'at it= ', kt,' date= ', ndastp
188         IF(lwp) WRITE(numout,*) '~~~~'
189         IF(nn_timing == 2)  CALL timing_start('iom_rstput')
190         CALL iom_rstput( kt, nitrst, numrow, 'rnf_b' , rnf )
191         CALL iom_rstput( kt, nitrst, numrow, 'rnf_hc_b', rnf_tsc(:,:,jp_tem) )
192         CALL iom_rstput( kt, nitrst, numrow, 'rnf_sc_b', rnf_tsc(:,:,jp_sal) )
193         IF(nn_timing == 2)  CALL timing_stop('iom_rstput')
194      ENDIF
195      !
196      CALL wrk_dealloc( jpi,jpj, ztfrz)
197      !
198      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
199   END SUBROUTINE sbc_rnf
200
201
202   SUBROUTINE sbc_rnf_div( phdivn )
203      !!----------------------------------------------------------------------
204      !!                  ***  ROUTINE sbc_rnf  ***
205      !!
206      !! ** Purpose :   update the horizontal divergence with the runoff inflow
207      !!
208      !! ** Method  :
209      !!                CAUTION : rnf is positive (inflow) decreasing the
210      !!                          divergence and expressed in m/s
211      !!
212      !! ** Action  :   phdivn   decreased by the runoff inflow
213      !!----------------------------------------------------------------------
214      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
215      !!
216      INTEGER  ::   ji, jj, jk   ! dummy loop indices
217      REAL(wp) ::   zfact     ! local scalar
218      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
219      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
220      REAL(KIND=jprb)               :: zhook_handle
221
222      CHARACTER(LEN=*), PARAMETER :: RoutineName='SBC_RNF_DIV'
223
224      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
225
226      !!----------------------------------------------------------------------
227      !
228      zfact = 0.5_wp
229      !
230      IF( ln_rnf_depth .OR. ln_rnf_depth_ini ) THEN      !==   runoff distributed over several levels   ==!
231         IF( lk_vvl ) THEN             ! variable volume case
232            DO jj = 1, jpj                   ! update the depth over which runoffs are distributed
233               DO ji = 1, jpi
234                  h_rnf(ji,jj) = 0._wp
235                  DO jk = 1, nk_rnf(ji,jj)                           ! recalculates h_rnf to be the depth in metres
236                     h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)   ! to the bottom of the relevant grid box
237                  END DO
238                  !                          ! apply the runoff input flow
239                  DO jk = 1, nk_rnf(ji,jj)
240                     phdivn(ji,jj,jk) = phdivn(ji,jj,jk) - ( rnf(ji,jj) + rnf_b(ji,jj) ) * zfact * r1_rau0 / h_rnf(ji,jj)
241                  END DO
242               END DO
243            END DO
244         ELSE                          ! constant volume case : just apply the runoff input flow
245            DO jj = 1, jpj
246               DO ji = 1, jpi
247                  DO jk = 1, nk_rnf(ji,jj)
248                     phdivn(ji,jj,jk) = phdivn(ji,jj,jk) - ( rnf(ji,jj) + rnf_b(ji,jj) ) * zfact * r1_rau0 / h_rnf(ji,jj)
249                  END DO
250               END DO
251            END DO
252         ENDIF
253      ELSE                       !==   runoff put only at the surface   ==!
254         IF( lk_vvl ) THEN              ! variable volume case
255            h_rnf(:,:) = fse3t(:,:,1)   ! recalculate h_rnf to be depth of top box
256         ENDIF
257         phdivn(:,:,1) = phdivn(:,:,1) - ( rnf(:,:) + rnf_b(:,:) ) * zfact * r1_rau0 / fse3t(:,:,1)
258      ENDIF
259      !
260      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
261   END SUBROUTINE sbc_rnf_div
262
263
264   SUBROUTINE sbc_rnf_init
265      !!----------------------------------------------------------------------
266      !!                  ***  ROUTINE sbc_rnf_init  ***
267      !!
268      !! ** Purpose :   Initialisation of the runoffs if (ln_rnf=T)
269      !!
270      !! ** Method  : - read the runoff namsbc_rnf namelist
271      !!
272      !! ** Action  : - read parameters
273      !!----------------------------------------------------------------------
274      CHARACTER(len=32) ::   rn_dep_file   ! runoff file name
275      INTEGER           ::   ji, jj, jk, jm    ! dummy loop indices
276      INTEGER           ::   ierror, inum  ! temporary integer
277      INTEGER           ::   ios           ! Local integer output status for namelist read
278      INTEGER           ::   nbrec         ! temporary integer
279      REAL(wp)          ::   zacoef 
280      REAL(wp), DIMENSION(12)                 :: zrec             ! times records
281      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zrnfcl   
282      REAL(wp), DIMENSION(:,:  ), ALLOCATABLE :: zrnf
283      !
284      NAMELIST/namsbc_rnf/ cn_dir            , ln_rnf_depth, ln_rnf_tem, ln_rnf_sal,   &
285         &                 sn_rnf, sn_cnf    , sn_s_rnf    , sn_t_rnf  , sn_dep_rnf,   &
286         &                 ln_rnf_mouth      , rn_hrnf     , rn_avt_rnf, rn_rfact,     &
287         &                 ln_rnf_depth_ini  , rn_dep_max  , rn_rnf_max, nn_rnf_depth_file
288         INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
289         INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
290         REAL(KIND=jprb)               :: zhook_handle
291
292         CHARACTER(LEN=*), PARAMETER :: RoutineName='SBC_RNF_INIT'
293
294         IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
295
296      !!----------------------------------------------------------------------
297      !
298      !                                         !==  allocate runoff arrays
299      IF( sbc_rnf_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_rnf_alloc : unable to allocate arrays' )
300      !
301      IF( .NOT. ln_rnf ) THEN                      ! no specific treatment in vicinity of river mouths
302         ln_rnf_mouth  = .FALSE.                   ! default definition needed for example by sbc_ssr or by tra_adv_muscl
303         nkrnf         = 0
304         rnf     (:,:) = 0.0_wp
305         rnf_b   (:,:) = 0.0_wp
306         rnfmsk  (:,:) = 0.0_wp
307         rnfmsk_z(:)   = 0.0_wp
308         IF (lhook) CALL dr_hook(RoutineName,zhook_out ,zhook_handle)
309         RETURN
310      ENDIF
311      !
312      !                                   ! ============
313      !                                   !   Namelist
314      !                                   ! ============
315      !
316      REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs
317      READ  ( numnam_ref, namsbc_rnf, IOSTAT = ios, ERR = 901)
318901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_rnf in reference namelist', lwp )
319
320      REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
321      READ  ( numnam_cfg, namsbc_rnf, IOSTAT = ios, ERR = 902 )
322902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_rnf in configuration namelist', lwp )
323      IF(lwm) WRITE ( numond, namsbc_rnf )
324      !
325      !                                         ! Control print
326      IF(lwp) THEN
327         WRITE(numout,*)
328         WRITE(numout,*) 'sbc_rnf : runoff '
329         WRITE(numout,*) '~~~~~~~ '
330         WRITE(numout,*) '   Namelist namsbc_rnf'
331         WRITE(numout,*) '      specific river mouths treatment            ln_rnf_mouth = ', ln_rnf_mouth
332         WRITE(numout,*) '      river mouth additional Kz                  rn_avt_rnf   = ', rn_avt_rnf
333         WRITE(numout,*) '      depth of river mouth additional mixing     rn_hrnf      = ', rn_hrnf
334         WRITE(numout,*) '      multiplicative factor for runoff           rn_rfact     = ', rn_rfact
335      ENDIF
336      !                                   ! ==================
337      !                                   !   Type of runoff
338      !                                   ! ==================
339      !
340      IF( .NOT. l_rnfcpl ) THEN                   
341         ALLOCATE( sf_rnf(1), STAT=ierror )         ! Create sf_rnf structure (runoff inflow)
342         IF(lwp) WRITE(numout,*)
343         IF(lwp) WRITE(numout,*) '          runoffs inflow read in a file'
344         IF( ierror > 0 ) THEN
345            CALL ctl_stop( 'sbc_rnf: unable to allocate sf_rnf structure' )   ;   RETURN
346         ENDIF
347         ALLOCATE( sf_rnf(1)%fnow(jpi,jpj,1)   )
348         IF( sn_rnf%ln_tint ) ALLOCATE( sf_rnf(1)%fdta(jpi,jpj,1,2) )
349         CALL fld_fill( sf_rnf, (/ sn_rnf /), cn_dir, 'sbc_rnf_init', 'read runoffs data', 'namsbc_rnf' )
350      ENDIF
351      !
352      IF( ln_rnf_tem ) THEN                      ! Create (if required) sf_t_rnf structure
353         IF(lwp) WRITE(numout,*)
354         IF(lwp) WRITE(numout,*) '          runoffs temperatures read in a file'
355         ALLOCATE( sf_t_rnf(1), STAT=ierror  )
356         IF( ierror > 0 ) THEN
357            CALL ctl_stop( 'sbc_rnf_init: unable to allocate sf_t_rnf structure' )   ;   RETURN
358         ENDIF
359         ALLOCATE( sf_t_rnf(1)%fnow(jpi,jpj,1)   )
360         IF( sn_t_rnf%ln_tint ) ALLOCATE( sf_t_rnf(1)%fdta(jpi,jpj,1,2) )
361         CALL fld_fill (sf_t_rnf, (/ sn_t_rnf /), cn_dir, 'sbc_rnf_init', 'read runoff temperature data', 'namsbc_rnf' )
362      ENDIF
363      !
364      IF( ln_rnf_sal  ) THEN                     ! Create (if required) sf_s_rnf and sf_t_rnf structures
365         IF(lwp) WRITE(numout,*)
366         IF(lwp) WRITE(numout,*) '          runoffs salinities read in a file'
367         ALLOCATE( sf_s_rnf(1), STAT=ierror  )
368         IF( ierror > 0 ) THEN
369            CALL ctl_stop( 'sbc_rnf_init: unable to allocate sf_s_rnf structure' )   ;   RETURN
370         ENDIF
371         ALLOCATE( sf_s_rnf(1)%fnow(jpi,jpj,1)   )
372         IF( sn_s_rnf%ln_tint ) ALLOCATE( sf_s_rnf(1)%fdta(jpi,jpj,1,2) )
373         CALL fld_fill (sf_s_rnf, (/ sn_s_rnf /), cn_dir, 'sbc_rnf_init', 'read runoff salinity data', 'namsbc_rnf' )
374      ENDIF
375      !
376      IF( ln_rnf_depth ) THEN                    ! depth of runoffs set from a file
377         IF(lwp) WRITE(numout,*)
378         IF(lwp) WRITE(numout,*) '          runoffs depth read in a file'
379         rn_dep_file = TRIM( cn_dir )//TRIM( sn_dep_rnf%clname )
380         IF( .NOT. sn_dep_rnf%ln_clim ) THEN   ;   WRITE(rn_dep_file, '(a,"_y",i4)' ) TRIM( rn_dep_file ), nyear    ! add year
381            IF( sn_dep_rnf%cltype == 'monthly' )   WRITE(rn_dep_file, '(a,"m",i2)'  ) TRIM( rn_dep_file ), nmonth   ! add month
382         ENDIF
383         CALL iom_open ( rn_dep_file, inum )                           ! open file
384         CALL iom_get  ( inum, jpdom_data, sn_dep_rnf%clvar, h_rnf )   ! read the river mouth array
385         CALL iom_close( inum )                                        ! close file
386         !
387         nk_rnf(:,:) = 0                               ! set the number of level over which river runoffs are applied
388         DO jj = 1, jpj
389            DO ji = 1, jpi
390               IF( h_rnf(ji,jj) > 0._wp ) THEN
391                  jk = 2
392                  DO WHILE ( jk /= mbkt(ji,jj) .AND. gdept_0(ji,jj,jk) < h_rnf(ji,jj) ) ;  jk = jk + 1
393                  END DO
394                  nk_rnf(ji,jj) = jk
395               ELSEIF( h_rnf(ji,jj) == -1._wp   ) THEN   ;  nk_rnf(ji,jj) = 1
396               ELSEIF( h_rnf(ji,jj) == -999._wp ) THEN   ;  nk_rnf(ji,jj) = mbkt(ji,jj)
397               ELSE
398                  CALL ctl_stop( 'sbc_rnf_init: runoff depth not positive, and not -999 or -1, rnf value in file fort.999'  )
399                  WRITE(999,*) 'ji, jj, h_rnf(ji,jj) :', ji, jj, h_rnf(ji,jj)
400               ENDIF
401            END DO
402         END DO
403         DO jj = 1, jpj                                ! set the associated depth
404            DO ji = 1, jpi
405               h_rnf(ji,jj) = 0._wp
406               DO jk = 1, nk_rnf(ji,jj)
407                  h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)
408               END DO
409            END DO
410         END DO
411         !
412      ELSE IF( ln_rnf_depth_ini ) THEN           ! runoffs applied at the surface
413         !
414         IF(lwp) WRITE(numout,*)
415         IF(lwp) WRITE(numout,*) '    depth of runoff computed once from max value of runoff'
416         IF(lwp) WRITE(numout,*) '    max value of the runoff climatologie (over global domain) rn_rnf_max = ', rn_rnf_max
417         IF(lwp) WRITE(numout,*) '    depth over which runoffs is spread                        rn_dep_max = ', rn_dep_max
418         IF(lwp) WRITE(numout,*) '     create (=1) a runoff depth file or not (=0)      nn_rnf_depth_file  = ', nn_rnf_depth_file
419
420         CALL iom_open( TRIM( sn_rnf%clname ), inum )    !  open runoff file
421         CALL iom_gettime( inum, zrec, kntime=nbrec)
422         ALLOCATE( zrnfcl(jpi,jpj,nbrec) )     ;      ALLOCATE( zrnf(jpi,jpj) )
423         DO jm = 1, nbrec
424            CALL iom_get( inum, jpdom_data, TRIM( sn_rnf%clvar ), zrnfcl(:,:,jm), jm )
425         END DO
426         CALL iom_close( inum )
427         zrnf(:,:) = MAXVAL( zrnfcl(:,:,:), DIM=3 )   !  maximum value in time
428         DEALLOCATE( zrnfcl )
429         !
430         h_rnf(:,:) = 1.
431         !
432         zacoef = rn_dep_max / rn_rnf_max            ! coef of linear relation between runoff and its depth (150m for max of runoff)
433         !
434         WHERE( zrnf(:,:) > 0._wp )  h_rnf(:,:) = zacoef * zrnf(:,:)   ! compute depth for all runoffs
435         !
436         DO jj = 1, jpj                     ! take in account min depth of ocean rn_hmin
437            DO ji = 1, jpi
438               IF( zrnf(ji,jj) > 0._wp ) THEN
439                  jk = mbkt(ji,jj)
440                  h_rnf(ji,jj) = MIN( h_rnf(ji,jj), gdept_0(ji,jj,jk ) )
441               ENDIF
442            END DO
443         END DO
444         !
445         nk_rnf(:,:) = 0                       ! number of levels on which runoffs are distributed
446         DO jj = 1, jpj
447            DO ji = 1, jpi
448               IF( zrnf(ji,jj) > 0._wp ) THEN
449                  jk = 2
450                  DO WHILE ( jk /= mbkt(ji,jj) .AND. gdept_0(ji,jj,jk) < h_rnf(ji,jj) ) ;  jk = jk + 1
451                  END DO
452                  nk_rnf(ji,jj) = jk
453               ELSE
454                  nk_rnf(ji,jj) = 1
455               ENDIF
456            END DO
457         END DO
458         !
459         DEALLOCATE( zrnf )
460         !
461         DO jj = 1, jpj                                ! set the associated depth
462            DO ji = 1, jpi
463               h_rnf(ji,jj) = 0._wp
464               DO jk = 1, nk_rnf(ji,jj)
465                  h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)
466               END DO
467            END DO
468         END DO
469         !
470         IF( nn_rnf_depth_file == 1 ) THEN      !  save  output nb levels for runoff
471            IF(lwp) WRITE(numout,*) '              create runoff depht file'
472            CALL iom_open  ( TRIM( sn_dep_rnf%clname ), inum, ldwrt = .TRUE., kiolib = jprstlib )
473            CALL iom_rstput( 0, 0, inum, 'rodepth', h_rnf )
474            CALL iom_close ( inum )
475         ENDIF
476      ELSE                                       ! runoffs applied at the surface
477         nk_rnf(:,:) = 1
478         h_rnf (:,:) = fse3t(:,:,1)
479      ENDIF
480      !
481      rnf(:,:) =  0._wp                         ! runoff initialisation
482      rnf_tsc(:,:,:) = 0._wp                    ! runoffs temperature & salinty contents initilisation
483      !
484      !                                   ! ========================
485      !                                   !   River mouth vicinity
486      !                                   ! ========================
487      !
488      IF( ln_rnf_mouth ) THEN                   ! Specific treatment in vicinity of river mouths :
489         !                                      !    - Increase Kz in surface layers ( rn_hrnf > 0 )
490         !                                      !    - set to zero SSS damping (ln_ssr=T)
491         !                                      !    - mixed upstream-centered (ln_traadv_cen2=T)
492         !
493         IF ( ln_rnf_depth )   CALL ctl_warn( 'sbc_rnf_init: increased mixing turned on but effects may already',   &
494            &                                              'be spread through depth by ln_rnf_depth'               )
495         !
496         nkrnf = 0                                  ! Number of level over which Kz increase
497         IF( rn_hrnf > 0._wp ) THEN
498            nkrnf = 2
499            DO WHILE( nkrnf /= jpkm1 .AND. gdepw_1d(nkrnf+1) < rn_hrnf )   ;   nkrnf = nkrnf + 1
500            END DO
501            IF( ln_sco )   CALL ctl_warn( 'sbc_rnf: number of levels over which Kz is increased is computed for zco...' )
502         ENDIF
503         IF(lwp) WRITE(numout,*)
504         IF(lwp) WRITE(numout,*) '          Specific treatment used in vicinity of river mouths :'
505         IF(lwp) WRITE(numout,*) '             - Increase Kz in surface layers (if rn_hrnf > 0 )'
506         IF(lwp) WRITE(numout,*) '               by ', rn_avt_rnf,' m2/s  over ', nkrnf, ' w-levels'
507         IF(lwp) WRITE(numout,*) '             - set to zero SSS damping       (if ln_ssr=T)'
508         IF(lwp) WRITE(numout,*) '             - mixed upstream-centered       (if ln_traadv_cen2=T)'
509         !
510         CALL rnf_mouth                             ! set river mouth mask
511         !
512      ELSE                                      ! No treatment at river mouths
513         IF(lwp) WRITE(numout,*)
514         IF(lwp) WRITE(numout,*) '          No specific treatment at river mouths'
515         rnfmsk  (:,:) = 0._wp
516         rnfmsk_z(:)   = 0._wp
517         nkrnf = 0
518      ENDIF
519      !
520         IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
521   END SUBROUTINE sbc_rnf_init
522
523
524   SUBROUTINE rnf_mouth
525      !!----------------------------------------------------------------------
526      !!                  ***  ROUTINE rnf_mouth  ***
527      !!
528      !! ** Purpose :   define the river mouths mask
529      !!
530      !! ** Method  :   read the river mouth mask (=0/1) in the river runoff
531      !!                climatological file. Defined a given vertical structure.
532      !!                CAUTION, the vertical structure is hard coded on the
533      !!                first 5 levels.
534      !!                This fields can be used to:
535      !!                 - set an upstream advection scheme
536      !!                   (ln_rnf_mouth=T and ln_traadv_cen2=T)
537      !!                 - increase vertical on the top nn_krnf vertical levels
538      !!                   at river runoff input grid point (nn_krnf>=2, see step.F90)
539      !!                 - set to zero SSS restoring flux at river mouth grid points
540      !!
541      !! ** Action  :   rnfmsk   set to 1 at river runoff input, 0 elsewhere
542      !!                rnfmsk_z vertical structure
543      !!----------------------------------------------------------------------
544      INTEGER            ::   inum        ! temporary integers
545      CHARACTER(len=140) ::   cl_rnfile   ! runoff file name
546      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
547      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
548      REAL(KIND=jprb)               :: zhook_handle
549
550      CHARACTER(LEN=*), PARAMETER :: RoutineName='RNF_MOUTH'
551
552      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
553
554      !!----------------------------------------------------------------------
555      !
556      IF(lwp) WRITE(numout,*)
557      IF(lwp) WRITE(numout,*) 'rnf_mouth : river mouth mask'
558      IF(lwp) WRITE(numout,*) '~~~~~~~~~ '
559      !
560      cl_rnfile = TRIM( cn_dir )//TRIM( sn_cnf%clname )
561      IF( .NOT. sn_cnf%ln_clim ) THEN   ;   WRITE(cl_rnfile, '(a,"_y",i4)' ) TRIM( cl_rnfile ), nyear    ! add year
562         IF( sn_cnf%cltype == 'monthly' )   WRITE(cl_rnfile, '(a,"m",i2)'  ) TRIM( cl_rnfile ), nmonth   ! add month
563      ENDIF
564      !
565      ! horizontal mask (read in NetCDF file)
566      CALL iom_open ( cl_rnfile, inum )                           ! open file
567      CALL iom_get  ( inum, jpdom_data, sn_cnf%clvar, rnfmsk )    ! read the river mouth array
568      CALL iom_close( inum )                                      ! close file
569      !
570      IF( nn_closea == 1 )   CALL clo_rnf( rnfmsk )               ! closed sea inflow set as ruver mouth
571      !
572      rnfmsk_z(:)   = 0._wp                                       ! vertical structure
573      rnfmsk_z(1)   = 1.0
574      rnfmsk_z(2)   = 1.0                                         ! **********
575      rnfmsk_z(3)   = 0.5                                         ! HARD CODED on the 5 first levels
576      rnfmsk_z(4)   = 0.25                                        ! **********
577      rnfmsk_z(5)   = 0.125
578      !
579      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
580   END SUBROUTINE rnf_mouth
581
582   !!======================================================================
583END MODULE sbcrnf
Note: See TracBrowser for help on using the repository browser.