sbcrnf.F90 31 KB

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