subroutine output_open_files
! Open all needed output files and write csv headers
use utilities, only : open_file
integer fi, fid, rl
type(output_file) :: fl
character(len=path_max_length) :: fname
integer, parameter :: nbytes_per_real = 4
do fi = 1, output_nfiles
fl = output_files(fi)
fname = trim(output_space_dim(fl%space))//"_"//&
trim(output_time_dim(fl%time))//"_"//trim(fl%name)// &
"."//trim(output_format_dim(fl%format))
if (fl%format == 1) then
fid = output_open_file(fname)
else if (fl%format == 2) then
rl = output_nhydrotopes
if (fl%space == 2) rl = output_nsubbasins
if (fl%space == 3) rl = output_ncatchments
if (fl%space == 4) rl = size(output_hydrotope_label_ix)
if (fl%space == 5) rl = size(output_subbasin_label_ix)
rl = rl * nbytes_per_real * fl%nvars
! TODO implement binary open file in open_file
open(fid, file=fname, form="unformatted", access="direct", recl=rl)
end if
output_files(fi)%file_id = fid
! Write header if needed
if (fl%format == 1) &
call output_write_csv_header(fid, output_space_dim(fl%space), &
output_requested_vars(fl%variable_ix(:fl%nvars)))
end do
end subroutine output_open_files