Skip to contents

Configures a SWAT project by editing the file.cio file. Sets the simulation period, time step, warm-up years, and output variables for reaches, subbasins, and HRUs.

Usage

setup_swat(
  sim_start_date,
  sim_end_date,
  time_step,
  NYSKIP,
  rch_vars = NULL,
  sub_vars = NULL,
  hru_vars = NULL,
  hrus = NULL
)

Arguments

sim_start_date

character. Simulation start date ("YYYY-MM-DD").

sim_end_date

character. Simulation end date ("YYYY-MM-DD").

time_step

character. Simulation time step: "daily" or "monthly".

NYSKIP

integer. Years to skip as warm-up before outputs are written.

rch_vars

character or NULL. Reach variables to output (see Details for limits and valid names). If NULL, zeros are written and SWAT prints all reach variables by default.

sub_vars

character or NULL. Subbasin variables to output (see Details for limits and valid names). If NULL, zeros are written and SWAT prints all subbasin variables by default.

hru_vars

character or NULL. HRU variables to output (see Details for limits and valid names). If NULL, zeros are written and SWAT prints all HRU variables by default.

hrus

integer or NULL. HRU IDs to include. If NULL, zeros are written and SWAT prints all HRUs by default.

Value

A list summarizing the applied configuration with fields:

  • output_start_date: first date with outputs after warm-up.

  • time_step: the selected time step.

  • rch_vars, sub_vars, hru_vars: the user selections (or NULL if all by default).

  • hrus: selected HRU IDs (or NULL if all by default).

Details

The working directory must contain a valid SWAT TxtInOut project.

Variable limits. In custom mode SWAT allows up to 20 variables for reaches, up to 15 for subbasins, and up to 20 for HRUs. Exceeding these limits throws an error.

Available variables. Use get_swat_vars to list valid names per element:

  • Reaches: get_swat_vars("rch")

  • Subbasins: get_swat_vars("sub")

  • HRUs: get_swat_vars("hru")

Use exact SWAT variable names as returned by get_swat_vars().

Metadata columns (COLNAME, SUB, RCH, GIS, MON, AREAkm2, LULC, HRU, MGT) are always printed and must not be included in the selection.

Note

This function overwrites file.cio. Back up your project if needed.

See also

Other Project setup and execution: download_swat_exe(), get_swat_example(), run_swat(), run_swat_exe()

Examples

# \donttest{
  old_wd <- getwd()
  on.exit(setwd(old_wd), add = TRUE)

  tmpdir <- tempdir()
  get_swat_example(tmpdir)
  setwd(file.path(tmpdir, "TxtInOut"))

  # List available variables
  get_swat_vars("rch")

  # Configure project
  setup_swat(
    sim_start_date = "2010-01-01",
    sim_end_date   = "2015-12-31",
    time_step      = "daily",
    NYSKIP         = 1,
    rch_vars       = c("FLOW_OUTcms", "SEDCONCmg/L"),
    sub_vars       = c("PRECIPmm", "ETmm"),
    hru_vars       = c("PRECIPmm"),
    hrus           = c(1, 2, 3)
  )
# }