reservoir_read_month_file Subroutine

public subroutine reservoir_read_month_file()

Uses

  • proc~~reservoir_read_month_file~~UsesGraph proc~reservoir_read_month_file reservoir_read_month_file module~input input proc~reservoir_read_month_file->module~input module~utilities utilities module~input->module~utilities

Arguments

None

Calls

proc~~reservoir_read_month_file~~CallsGraph proc~reservoir_read_month_file reservoir_read_month_file proc~log_warn log_warn proc~reservoir_read_month_file->proc~log_warn proc~input_open_file input_open_file proc~reservoir_read_month_file->proc~input_open_file proc~read_real_column read_real_column proc~reservoir_read_month_file->proc~read_real_column proc~log_message log_message proc~log_warn->proc~log_message proc~open_file open_file proc~input_open_file->proc~open_file proc~input_type_conversion_error input_type_conversion_error proc~read_real_column->proc~input_type_conversion_error proc~move_lines move_lines proc~read_real_column->proc~move_lines proc~log_error log_error proc~read_real_column->proc~log_error proc~check_range check_range proc~read_real_column->proc~check_range proc~read_csv_item read_csv_item proc~read_real_column->proc~read_csv_item proc~header_column_index header_column_index proc~read_real_column->proc~header_column_index proc~input_error_column_not_found input_error_column_not_found proc~read_real_column->proc~input_error_column_not_found proc~input_type_conversion_error->proc~log_error proc~log_error->proc~log_message proc~check_range->proc~log_warn proc~check_range->proc~log_error proc~out_of_range_error out_of_range_error proc~check_range->proc~out_of_range_error proc~open_file->proc~log_error proc~header_column_index->proc~move_lines proc~header_column_index->proc~input_error_column_not_found 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~input_error_column_not_found->proc~log_error 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~out_of_range_error->proc~log_error proc~out_of_range_error->proc~to_string proc~string_index string_index proc~colourise->proc~string_index

Called by

proc~~reservoir_read_month_file~~CalledByGraph proc~reservoir_read_month_file reservoir_read_month_file proc~reservoir_initialise reservoir_initialise proc~reservoir_initialise->proc~reservoir_read_month_file proc~initialise initialise proc~initialise->proc~reservoir_initialise program~swim swim program~swim->proc~initialise

Contents


Source Code

  subroutine reservoir_read_month_file() ! reservoir_monthly.csv
    use input, only : read_real_column, input_open_file

    integer :: i, k, offset, fid
    real(dp), dimension(:), allocatable :: temp
    integer size

    fid = input_open_file(trim(reservoir_monthly_input_file))

    size = rsv_nReservoirs * 12
    allocate(temp(size))

    call read_real_column(fid, "rsv_cap_act", temp, 0.0_dp)
    ! TODO: Cannot seem to pass 0-based arrays as parameters...
    ! call fill_reservoir_array(rsv_Cap_Act, temp)
    ! TODO: Why does the reshape not work? Multi-dimension slice assignment
    !       does not work for 0-based arrays?
    ! write(*, *) "BEFORE", rsv_Cap_Act(1, 1:12)
    ! rsv_Cap_Act(:, 1:12) = reshape(temp, (/ rsv_nReservoirs, 12 /))
    ! write(*, *) "AFTER", rsv_Cap_Act(1, 1:12)
    offset = 1
    do i = 1, rsv_nReservoirs
      rsv_Cap_Act(i, 1:12) = temp(offset:offset+11)
      offset = offset + 12
    end do
    rsv_Cap_Act(:, 0) = rsv_Cap_Act(:, 12)

    call read_real_column(fid, "rsv_fill_min", temp, 0.0_dp)
    offset = 1
    do i = 1, rsv_nReservoirs
      rsv_Fill_Min(i, 1:12) = temp(offset:offset+11)
      offset = offset + 12
    end do
    rsv_Fill_Min(:, 0) = rsv_Fill_Min(:, 12)

    call read_real_column(fid, "rsv_dis_min_fill", temp, 0.0_dp)
    offset = 1
    do i = 1, rsv_nReservoirs
      rsv_Dis_Min_Fill(i, 1:12) = temp(offset:offset+11)
      offset = offset + 12
    end do
    rsv_Dis_Min_Fill(:, 0) = rsv_Dis_Min_Fill(:, 12)

    call read_real_column(fid, "rsv_dis_min_act", temp, 0.0_dp)
    offset = 1
    do i = 1, rsv_nReservoirs
      rsv_Dis_Min_Act(i, 1:12) = temp(offset:offset+11)
      offset = offset + 12
    end do
    rsv_Dis_Min_Act(:, 0) = rsv_Dis_Min_Act(:, 12)

    call read_real_column(fid, "withdr_mon", temp, 0.0_dp)
    offset = 1
    do i = 1, rsv_nReservoirs
      rsv_Withdr_Mon(i, 1:12) = temp(offset:offset+11)
      offset = offset + 12
    end do
    rsv_Withdr_Mon(:, 0) = rsv_Withdr_Mon(:, 12)

    call read_real_column(fid, "ann_cycle", temp, 0.0_dp)
    offset = 1
    do i = 1, rsv_nReservoirs
      rsv_ann_cycle(i, 1:12) = temp(offset:offset+11)
      offset = offset + 12
    end do
    rsv_ann_cycle(:, 0) = rsv_ann_cycle(:, 12)

    do i = 1, rsv_nReservoirs
      do k = 0, 12
        if (rsv_Cap_Act(i, k) > rsv_Capac_Max(i) ) then
          rsv_Cap_Act(i, k) = rsv_Capac_Max(i)
          call log_warn("reservoir_read_month_file", &
            "Reservoir module: storage capacity corrected (reservoir, month)", i1=i, i2=k)
        end if
      end do
    end do

    ! convert million m^3 to m^3
    rsv_Cap_Act = rsv_Cap_Act * 10 ** 6
    rsv_Fill_Min = rsv_Fill_Min * 10 ** 6

    close(fid)

    deallocate(temp)

  end subroutine reservoir_read_month_file