subroutine reservoir_open_output
!-----------------------------------------------------------------
! open and create reservoir output files (one file per reservoir)
!-----------------------------------------------------------------
use output, only: output_open_file
! initialise variables and arrays
integer :: res, funit
res = 1
do funit = 1, rsv_nReservoirs
rsv_funit(res) = output_open_file("reservoir_"//trim(rsv_ResNames(res))//".out")
! write header line
write(rsv_funit(res), fmt="(a8)", advance="NO") "YEAR DAY "
write(rsv_funit(res), fmt="(a16)", advance="NO") "Precip_m3/s"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Precip_mm"
write(rsv_funit(res), fmt="(a16)", advance="NO") "CWB_m3/s"
write(rsv_funit(res), fmt="(a16)", advance="NO") "CWB_mm"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Area_dry_km2"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Area_wet_km2"
write(rsv_funit(res), fmt="(a18)", advance="NO") "Act_stor_Mio_m3"
write(rsv_funit(res), fmt="(a18)", advance="NO") "Dead_stor_Mio_m3"
write(rsv_funit(res), fmt="(a16)", advance="NO") "WaterLevel_masl"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Inflow_m3/s"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Outflow_m3/s"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Withdrawal_m3"
write(rsv_funit(res), fmt="(a16)", advance="NO") "Seepage_m3/s"
write(rsv_funit(res), fmt="(a16)", advance="NO") "ETpot_water_mm"
write(rsv_funit(res), fmt="(a16)", advance="NO") "ETpot_land_mm"
write(rsv_funit(res), fmt="(a16)", advance="NO") "ETact_mm"
write(rsv_funit(res), fmt="(a17)", advance="NO") "ETact_m3/s"
write(rsv_funit(res), fmt="(a17)", advance="YES") "Energy_MW"
res = res + 1
end do
end subroutine reservoir_open_output