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