subroutine output_write_time(timeix, time_label, hydrotope, subbasin, catchment)
! Abstraction of write out storage/agg arrays
integer, intent(in) :: timeix
character(len=*), dimension(:), intent(in) :: time_label
real, dimension(:, :, :), intent(in) :: hydrotope, subbasin, catchment
type(output_file) :: fl
integer i, t, nv, ntm, osix(output_nvars)
ntm = size(time_label)
do i = 1, output_nfiles
fl = output_files(i)
! Only continue with files of the timeix frequency
if (fl%time /= timeix) cycle
! Abbreviations
nv = fl%nvars
osix = output_storage_index(i, :)
! CSV output
if (fl%format == 1) then
select case (fl%space)
case (1)
call output_write_space_time_csv(fl%file_id, hydrotope(osix(:nv), :, :), &
output_hydrotope_id, time_label)
case (2)
call output_write_space_time_csv(fl%file_id, subbasin(osix(:nv), :, :), &
output_subbasin_id, time_label)
case (3)
call output_write_space_time_csv(fl%file_id, catchment(osix(:nv), :, :), &
output_catchment_id, time_label)
case (4)
call output_write_space_time_csv(fl%file_id, hydrotope(osix(:nv), &
output_hydrotope_label_ix, :), time_label=time_label, &
space_label=output_hydrotope_label(output_hydrotope_label_ix))
case (5)
call output_write_space_time_csv(fl%file_id, subbasin(osix(:nv), &
output_subbasin_label_ix, :), time_label=time_label, &
space_label=output_subbasin_label(output_subbasin_label_ix))
end select
! Binary output
else if (fl%format == 2) then
select case (fl%space)
case (1)
do t = 1, ntm
call output_array_to_bin(fl%file_id, hydrotope(osix(:nv), :, t), fl%current_record)
output_files(i)%current_record = output_files(i)%current_record + 1
end do
case (2)
do t = 1, ntm
call output_array_to_bin(fl%file_id, subbasin(osix(:nv), :, t), fl%current_record)
output_files(i)%current_record = output_files(i)%current_record + 1
end do
case (3)
do t = 1, ntm
call output_array_to_bin(fl%file_id, catchment(osix(:nv), :, t), fl%current_record)
output_files(i)%current_record = output_files(i)%current_record + 1
end do
case (4)
do t = 1, ntm
call output_array_to_bin(fl%file_id, hydrotope(osix(:nv), &
output_hydrotope_label_ix, t), fl%current_record)
output_files(i)%current_record = output_files(i)%current_record + 1
end do
case (5)
do t = 1, ntm
call output_array_to_bin(fl%file_id, subbasin(osix(:nv), &
output_subbasin_label_ix, t), fl%current_record)
output_files(i)%current_record = output_files(i)%current_record + 1
end do
end select
end if
end do
end subroutine output_write_time