Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | sub | |||
integer, | intent(in) | :: | day | |||
integer, | intent(in) | :: | ida | |||
integer, | intent(in) | :: | iyr |
subroutine management_total_demand(sub, day, ida, iyr)
integer, intent(in) :: ida
integer, intent(in) :: iyr
! calculate total outputs of all water user(s)
! CALLED FROM MONTHLY (in daily SUBBASIN command)
! current subbasin number
integer, intent(in) :: sub
! current day of simulation
integer, intent(in) :: day
integer :: i
! pointer on current TSub
TYPE (TSubbasin), POINTER :: pS
! pointer on actual TWU
TYPE (TWaterUser), POINTER :: pWU
if (management_is_transfer_subbasin(sub) ) then
pS => management_subbasin_pointer(sub) !wamTSub(sub) % pSub
if (pS % nWUout > 0) then
do i = 1, pS % nWU ! loop over water users in subbasin
pWU => management_user_pointer(pS % pos(i))
!-----------------------------------------------------------------
! if the current subbasin is a water source for transfer to another subbasin or external destination
!-----------------------------------------------------------------
if (pWU % wu_opt <= 2 .AND. pWU % subs == pS % subnr .AND. management_is_active_period(iyr, ida, pWU) ) then
! add demands of water user(s)
pS % totDemand(day) = pS % totDemand(day) + pWU % data(day) ! [m3 / s]
end if
!-----------------------------------------------------------------
! add irrigation demand of previous day
!-----------------------------------------------------------------
if (day > 1) then
! if source is another subbasin
if (pWU % wu_opt == 4 .AND. pWU % subs > 0 .AND. management_is_active_period(iyr, ida, pWU) ) then
! add inputs from input time series
if (pWU % irr_opt == 1) then
pS % totDemand(day) = pS % totDemand(day) + pWU % data(day)
pS % irrDemand(day) = pS % irrDemand(day) + pWU % data(day)
end if
! add irrigation demand of previous day to total demand
if (pWU % irr_opt > 1 .AND. pWU % irrigationDemand(day - 1) > 0. ) then
pS % totDemand(day) = pS % totDemand(day) + pWU % irrigationDemand(day - 1)
pS % irrDemand(day) = pS % irrDemand(day) + pWU % irrigationDemand(day - 1)
end if
end if
end if ! (day > 1)
end do
end if
else
call log_warn("wam", "Water allocation module was called for (subbasin) although it has no water users", i1=sub)
end if
end subroutine management_total_demand