Skip to contents

Reads the output.sub file generated by SWAT, allowing users to filter the data by variables, subbasin IDs, and time steps (daily or monthly).

Usage

output_sub(
  file = "output.sub",
  variable = NULL,
  target_id = NULL,
  time_step = "daily",
  output_start_date
)

Arguments

file

Character. Absolute path to the output.sub file. Default is "output.sub".

variable

Character vector with the names of variables to read. Use get_swat_vars("sub") to list all options. If NULL, all variables are read.

target_id

Numeric vector of subbasin IDs to extract. Default NULL retrieves all subbasins.

time_step

Character. Time step of the simulation ("daily" or "monthly"). Default is "daily".

output_start_date

Character. Date when SWAT output generation begins (first day after warm-up), in "yyyy-mm-dd" format.

Value

A data.frame with the selected variables for each subbasin and time step. Columns "SUB" (subbasin ID) and "MON" (Date) are always included.

See also

Other Output readers: get_swat_vars(), output_hru(), output_rch(), read_pcp(), read_tmp()

Examples

# Example with package data
tmpdir <- tempdir()
get_swat_example(tmpdir)
sub_file <- file.path(tmpdir, "TxtInOut", "output.sub")
sub_data <- output_sub(file = sub_file, variable = c("PRECIPmm", "ETmm", "WYLDmm"),
                       target_id = NULL, time_step = "daily",
                       output_start_date = "2011-01-01")
head(sub_data)

if (FALSE) { # \dontrun{
# Example with external SWAT project
sub_data <- output_sub(file = "C:/SWAT_Project/TxtInOut/output.sub",
                       variable = c("WYLDmm"), target_id = c(1, 2),
                       time_step = "daily",
                       output_start_date = "2000-01-01")
} # }