readSWAT: Read output.* files from SWAT200*

Description Usage Arguments Author(s) Examples

View source: R/readSWAT.R

Description

A function to read output.* files from SWAT200* runs.

Usage

1
readSWAT(outfile_type)

Arguments

outfile_type

outfile_type ie. "sub","rch",etc.

Author(s)

Daniel R. Fuka

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## The function is currently defined as
function(outfile){

if (outfile=="sub"){
   varformat="x6,a4,1x,a8,1x,a4,a10,30a10"
   dataformat="x6,i4,1x,i8,1x,i4,f10,30f10"
  } else if (outfile=="rch"){
   varformat="x6,a4,1x,a8,1x,a5,30a12"
   dataformat="x6,i4,1x,i8,1x,i5,30f12"
  } else { print ("You need to add your file type to this function if it is not output.sub or output.rch")}
  print(varformat)
  print(dataformat)
  vfrformat = unlist(strsplit(as.character(varformat), ","))
  dfrformat = unlist(strsplit(as.character(dataformat), ","))
  outvars=read.fortran(paste("output.",outfile,sep=""),vfrformat,skip=8,nrows=1)
  outdata=read.fortran(paste("output.",outfile,sep=""),dfrformat,skip=9,col.names=outvars)
  return(outdata)
  }

Example output

Loading required package: EcoHydRology
Loading required package: operators

Attaching package: 'operators'

The following objects are masked from 'package:base':

    options, strrep

Loading required package: topmodel
Loading required package: DEoptim
Loading required package: parallel

DEoptim package
Differential Evolution algorithm in R
Authors: D. Ardia, K. Mullen, B. Peterson and J. Ulrich

Loading required package: XML
function (outfile) 
{
    if (outfile == "sub") {
        varformat = "x6,a4,1x,a8,1x,a4,a10,30a10"
        dataformat = "x6,i4,1x,i8,1x,i4,f10,30f10"
    }
    else if (outfile == "rch") {
        varformat = "x6,a4,1x,a8,1x,a5,30a12"
        dataformat = "x6,i4,1x,i8,1x,i5,30f12"
    }
    else {
        print("You need to add your file type to this function if it is not output.sub or output.rch")
    }
    print(varformat)
    print(dataformat)
    vfrformat = unlist(strsplit(as.character(varformat), ","))
    dfrformat = unlist(strsplit(as.character(dataformat), ","))
    outvars = read.fortran(paste("output.", outfile, sep = ""), 
        vfrformat, skip = 8, nrows = 1)
    outdata = read.fortran(paste("output.", outfile, sep = ""), 
        dfrformat, skip = 9, col.names = outvars)
    return(outdata)
}

SWATmodel documentation built on May 1, 2019, 10:29 p.m.