management_total_demand Subroutine

public subroutine management_total_demand(sub, day, ida, iyr)

if the current subbasin is a water source for transfer to another subbasin or external destination


add irrigation demand of previous day

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: sub
integer, intent(in) :: day
integer, intent(in) :: ida
integer, intent(in) :: iyr

Calls

proc~~management_total_demand~~CallsGraph proc~management_total_demand management_total_demand proc~management_subbasin_pointer management_subbasin_pointer proc~management_total_demand->proc~management_subbasin_pointer proc~management_user_pointer management_user_pointer proc~management_total_demand->proc~management_user_pointer proc~management_is_transfer_subbasin management_is_transfer_subbasin proc~management_total_demand->proc~management_is_transfer_subbasin proc~management_is_active_period management_is_active_period proc~management_total_demand->proc~management_is_active_period proc~log_warn log_warn proc~management_total_demand->proc~log_warn proc~log_error log_error proc~management_user_pointer->proc~log_error proc~log_message log_message proc~log_warn->proc~log_message proc~log_write log_write proc~log_message->proc~log_write proc~log_format_message log_format_message proc~log_message->proc~log_format_message proc~log_error->proc~log_message proc~to_string to_string proc~log_write->proc~to_string proc~date_time_str date_time_str proc~log_format_message->proc~date_time_str proc~colourise colourise proc~log_format_message->proc~colourise proc~string_index string_index proc~colourise->proc~string_index

Called by

proc~~management_total_demand~~CalledByGraph proc~management_total_demand management_total_demand proc~time_process_day time_process_day proc~time_process_day->proc~management_total_demand proc~time_process_month time_process_month proc~time_process_month->proc~time_process_day proc~time_process_years time_process_years proc~time_process_years->proc~time_process_month program~swim swim program~swim->proc~time_process_years

Contents


Source Code

  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