output_day Subroutine

public subroutine output_day(year, month, day)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: year
integer, intent(in) :: month
integer, intent(in) :: day

Calls

proc~~output_day~~CallsGraph proc~output_day output_day proc~output_hydrotope_to_catchment output_hydrotope_to_catchment proc~output_day->proc~output_hydrotope_to_catchment proc~output_write_daily output_write_daily proc~output_day->proc~output_write_daily proc~output_hydrotope_to_subbasin output_hydrotope_to_subbasin proc~output_day->proc~output_hydrotope_to_subbasin proc~output_subbasin_to_catchment output_subbasin_to_catchment proc~output_day->proc~output_subbasin_to_catchment proc~output_write_time output_write_time proc~output_write_daily->proc~output_write_time proc~output_write_space_time_csv output_write_space_time_csv proc~output_write_time->proc~output_write_space_time_csv proc~output_array_to_bin output_array_to_bin proc~output_write_time->proc~output_array_to_bin proc~output_array_to_csv output_array_to_csv proc~output_write_space_time_csv->proc~output_array_to_csv proc~log_error log_error proc~output_write_space_time_csv->proc~log_error proc~output_array_to_csv->proc~log_error proc~log_message log_message proc~log_error->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~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~~output_day~~CalledByGraph proc~output_day output_day proc~time_process_day time_process_day proc~time_process_day->proc~output_day 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


Source Code

  subroutine output_day(year, month, day)
    ! Aggregate space/time and write to csv/bin, if interval is daily.
    integer, intent(in) :: year, month, day
    integer i, dc, mc
    integer :: sti(3, 3), stb(3, 3)
    real :: hydval(output_nhydrotopes), subval(output_nsubbasins), &
      catval(output_ncatchments)

    dc = output_store_day_counter
    mc = output_store_month_counter
    ! Format day label for csv output
    write(output_day_ix(dc), "(i0.4, '-', i0.2, '-', i0.2)") year, month, day
    ! aggregate day to month
    do i = 1, output_nvars
      ! 0/1 (space, time) for current variable
      stb = output_is_requested(i, :, :)
      ! indeces in aggregation arrays of current variable
      sti = sum(output_is_requested(:i, :, :), dim=1)
      ! current hydrotope/subbasin variables
      if (output_hydrotope_var_ix(i) > 0) then
        hydval = output_storage_hydrotope(output_hydrotope_var_ix(i), :, dc)
        subval = output_hydrotope_to_subbasin(hydval)
        catval = output_hydrotope_to_catchment(hydval)
      end if
      if (output_subbasin_var_ix(i) > 0) then
        hydval = 0
        subval = output_storage_subbasin(output_subbasin_var_ix(i), :, dc)
        catval = output_subbasin_to_catchment(subval)
      end if
      ! Add daily values to aggregation arrays as needed
      if (stb(1, 2) == 1) output_agg_hydrotope_monthly(sti(1, 2), :, mc) = &
        output_agg_hydrotope_monthly(sti(1, 2), :, mc) + hydval
      if (stb(1, 3) == 1) output_agg_hydrotope_annual(sti(1, 3), :, 1) = &
        output_agg_hydrotope_annual(sti(1, 3), :, 1) + hydval
      if (stb(2, 1) == 1) output_agg_subbasin_daily(sti(2, 1), :, dc) = &
        output_agg_subbasin_daily(sti(2, 1), :, dc) + subval
      if (stb(2, 2) == 1) output_agg_subbasin_monthly(sti(2, 2), :, mc) = &
        output_agg_subbasin_monthly(sti(2, 2), :, mc) + subval
      if (stb(2, 3) == 1) output_agg_subbasin_annual(sti(2, 3), :, 1) = &
        output_agg_subbasin_annual(sti(2, 3), :, 1) + subval
      if (stb(3, 1) == 1) output_agg_catchment_daily(sti(3, 1), :, dc) = &
        output_agg_catchment_daily(sti(3, 1), :, dc) + catval
      if (stb(3, 2) == 1) output_agg_catchment_monthly(sti(3, 2), :, mc) = &
        output_agg_catchment_monthly(sti(3, 2), :, mc) + catval
      if (stb(3, 3) == 1) output_agg_catchment_annual(sti(3, 3), :, 1) = &
        output_agg_catchment_annual(sti(3, 3), :, 1) + catval
    end do
    ! Increase/reset day counter
    if (output_write_interval == "D") then
      call output_write_daily
      output_store_day_counter = 0
    end if
    output_store_day_counter = output_store_day_counter + 1
    output_ndays_per_month = output_ndays_per_month + 1
  end subroutine output_day