Skip to contents

Define the SWAT output variables that should be extracted after the SWAT model execution and be returned to R. It is required to use this function to pass the desired outputs with the variable output in the function calls run_swat2012 and run_swatplus. See the examples how to use the output definition together with run_swat2012 or run_swatplus. Further, more comprehensive examples are provided on the package's 'Get Started' page in the section 'First SWAT model runs.

Usage

define_output(file, variable = NULL, unit = NULL)

Arguments

file

Character string. The SWAT output file to read. (Valid inputs are 'rch', 'sub', 'hru', and 'sed' for the respective SWAT2012 output files 'output.rch', 'output.sub', output.hru', and 'output.sed'. For the respective SWAT+ output files see the available options in the 'print.prt' file of your SWAT+ project).

variable

Character string. Output variable that is extracted from the respective SWAT output file defined with file. For a correct definition of SWAT2012 output variables please use the variable documented in the SWAT Output Data Documentation. For SWAT+ output variables please use the header names from the respective output table, without the units! Optionally, the column number of a variable in the respective output file can be provided. CAUTION: spaces (e.g. in P TOT) must be replaced with underscores (P_TOT).

unit

Numeric vector. The spatial unit (e.g. the reach, subbasin, or HRU) defined by the columns 'RCH', 'SUB', 'HRU' in the respective SWAT2012 output file or the 'unit' column in the SWAT+ output file for which the outputs should be extracted.

Examples

# A single variable can be defined as follows (e.g. "FLOW_OUT" for
# the reaches 1 and 5):

out_flow <- define_output(file = "rch",
                          variable = "FLOW_OUT",
                          unit = c(1,5))
# In this case the the variable name of the returned output is then
# the same as defined with 'variable', here "FLOW_OUT"

# If a custom variable name is preferred for the returned output,
# the output must be defined as named list:

out_flow <- list(discharge = define_output(file = "rch",
                                           variable = "FLOW_OUT",
                                           unit = c(1,5)))


# Define the discharge for the RCH units 1 to 5 and the
# nitrate-nitrogen load and ET for the unit 5:

out_def <- list(flow = define_output(file = "rch",
                                     variable = "FLOW_OUT",
                                     unit = 1:5),
                no3  = define_output(file = "rch",
                                     variable = "NO3_OUT",
                                     unit = 5),
                et_a = define_output(file = "sub",
                                     variable = "ET",
                                     unit = 5))