subroutine output_initialise_storage(hydrotope_input_fid, subbasin_input_fid)
! Initialisation storage after all variables have been registered registration.
integer, intent(in) :: hydrotope_input_fid, subbasin_input_fid
integer :: nd, nm, ny
integer :: nspacetime(3, 3)
call output_initialise_labelled(hydrotope_input_fid, subbasin_input_fid)
call output_check_requested_vars
call output_open_files
call output_initialise_storage_index
nd = output_ndays
nm = output_nmonths
ny = output_nyears
! Raw daily stores
allocate(output_storage_hydrotope(output_id_hydrotope_counter, output_nhydrotopes, nd))
allocate(output_storage_subbasin(output_id_subbasin_counter, output_nsubbasins, nd))
! Total variables requested for (space, time), maxval because [csv, bin] = 1
nspacetime = sum(output_is_requested, dim=1)
allocate(output_agg_hydrotope_monthly(nspacetime(1, 2), output_nhydrotopes, nm))
allocate(output_agg_hydrotope_annual(nspacetime(1, 3), output_nhydrotopes, ny))
allocate(output_agg_subbasin_daily(nspacetime(2, 1), output_nsubbasins, nd))
allocate(output_agg_subbasin_monthly(nspacetime(2, 2), output_nsubbasins, nm))
allocate(output_agg_subbasin_annual(nspacetime(2, 3), output_nsubbasins, ny))
allocate(output_agg_catchment_daily(nspacetime(3, 1), output_ncatchments, nd))
allocate(output_agg_catchment_monthly(nspacetime(3, 2), output_ncatchments, nm))
allocate(output_agg_catchment_annual(nspacetime(3, 3), output_ncatchments, ny))
! set all to 0
output_storage_hydrotope = 0
output_storage_subbasin = 0
output_agg_hydrotope_monthly = 0
output_agg_hydrotope_annual = 0
output_agg_subbasin_daily = 0
output_agg_subbasin_monthly = 0
output_agg_subbasin_annual = 0
output_agg_catchment_daily = 0
output_agg_catchment_monthly = 0
output_agg_catchment_annual = 0
end subroutine output_initialise_storage