subroutine nutrient_nitrate_uptake(j, je, nv, dm, flu, frar, g, ida, nn, snup)
!**** PURPOSE: CALCULATES N UPTAKE by PLANTS, calls npstress()
!**** CALLED IN: GROWTH
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! PARAMETERS & VARIABLES
!
! >>>>> COMMON PARAMETERS & VARIABLES
! ano3(j, je, l) = nitrate (NO3-N) content in a layer , kg/ha
! bn1(nv) = normal fraction of N in plant biomass at emergence
! bn3(nv) = normal fraction of N in plant biomass at maturity
! bnu1(nv) = coef used to calculate sp1 - S-curve parameter
! bnu2(nv) = coef used to calculate sp2 - S-curve parameter
! cnb = optimal conc N in biomass, kg/kg
! dflow(j, je, 20) = monthly flows for water and N (see writhru.f)
! dm(j, je) = total biomass, kg/ha
! flu(j) = fraction of subbasin area in the basin
! frar(j, je) = fractional areas of hydrotope in subbasin
! g(j, je) = fraction of heat units to maturity accumulated
! ida = current day
! inuhd = number of hydrotope to print from ncycle(), if inutr=1
! inusb = number of subbasin to print from ncycle(), if inutr=1
! nn = number of soil layers, from subbasin
! sbnup = sum of N uptake for basin
! snup(j, je) = N uptake accumulated, kg/ha
! strsn = N stress factor
! uno3 = N uptake by the crop for a given day, kg/ha (SUPPLY)
! xnflow(1:17) = N flows for a choosen hydrotope to write in nutr.prn
! (see ncycle)
! >>>>>
! >>>>> STATIC PARAMETERS
! l = local par
! sp1 = local par
! sp2 = local par
! uno3pot = optimal N uptake by the crop until given day. kg/ha (DEMAND)
! uu = nutrient stress
! xx = local par
! yy = local par
! >>>>>
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!**** Include common parameters
real(dp), dimension(:, :), intent(in) :: dm
real(dp), dimension(:), intent(in) :: flu
real(dp), dimension(:, :), intent(in) :: frar
real(dp), dimension(:, :), intent(in) :: g
integer, intent(in) :: ida
integer, intent(in) :: nn
real(dp), dimension(:, :), intent(inout) :: snup
integer j, je, nv, l
real(dp) sp1, sp2, uno3pot, uu, xx, yy
logical update_uno3
update_uno3 = .true.
!**** INITIALIZATION
xx = g(j, je)
sp1 = bnu1(nv)
sp2 = bnu2(nv)
!**** CALC N uptake by plants & RECALC pools
!#### CALL nutrient stress
cnb = bn3(nv) + &
(bn1(nv) - bn3(nv)) * (1 - xx / (xx + exp(sp1 - sp2 * xx)))
uno3 = cnb * dm(j, je) - snup(j, je)
if (uno3 .ge. 0) then
if (ida .eq. 1) uno3 = 0.
uno3pot = uno3
xx = uno3
do l = 1, nn
yy = ano3(j, je, l) - xx
if (yy .gt. 0.) then
ano3(j, je, l) = yy
update_uno3 = .false.
exit
else
xx = xx - ano3(j, je, l)
ano3(j, je, l) = 0.
end if
end do
if (update_uno3) uno3 = uno3 - xx
if (uno3 .lt. 0.) uno3 = 0.
snup(j, je) = snup(j, je) + uno3
sbnup = sbnup + uno3 * flu(j) * frar(j, je)
call vegetation_nutrient_stress(uno3, uno3pot, uu)
strsn = uu
else
uno3 = 0.
strsn = 1.
end if
!**** CALC N flows for a choosen hydrotope (output in ncycle)
if (j .eq. inusb .and. je .eq. inuhd) xnflow(8) = uno3
!**** CALC monthly flows for selected HRUs (output in writhru.f)
dflow(j, je, 8) = dflow(j, je, 8) + uno3
return
end subroutine nutrient_nitrate_uptake