runCRHM: Runs a CRHM model

View source: R/runCRHM.R

runCRHMR Documentation

Runs a CRHM model

Description

Runs CRHM with a specified .prj file and (optionally) .obs file(s) and .par file(s). Under OSX and Linux, CRHM requires either 1) the program Wine to run CRHM.exe or 2) a native-compiled version. This function will use Wine if it is indicated (the executable file has the extension .exe), and the parameter useWine = TRUE.

Usage

runCRHM(
  CRHMfile = "",
  prjFile = "",
  obsFiles = "",
  parFiles = "",
  outFile = "",
  logfile = "",
  useWine = FALSE
)

Arguments

CRHMfile

Required. CRHM executable file (i.e. CRHM.exe for Windows). If the path to the executable file is not specified, it is assumed that the executable file is on the system path.

prjFile

Required. Name of .prj file. If the file does not contain any displayed observations or variables, or if any of the settings Auto_Run, Auto_Exit or Log_All are missing, then the function will terminate with an error message.

obsFiles

Optional. Name(s) of obs file(s).

parFiles

Optional. Name(s) of parameter file(s).

outFile

Optional. Name(s) of output file(s). If not specified, the original CRHM output file name (e.g. CRHM_output_1.txt) is kept.

logfile

Optional. Name of the file to be used for logging the action. Normally not used.

useWine

Optional. If FALSE (the default) and the executable file has the extension .exe then Wine will be used to run the model under OSX and Linux. Otherwide, a native version of CRHM will be assumed.

Details

Running a CRHM model requires that the .prj file has been setup to run autmatically, as shown in the function automatePrj.

If Wine is required, the function will copy the specified .obs, and .par files to the directory of the .prj file, before execution of CRHM. After the program has finished, the copies will be deleted.

If the CRHM executable file is not located on the system path, and is not found in the specified directory, then an error message will be returned.

Value

If successful, returns TRUE. If unsuccessful, returns FALSE.

Author(s)

Kevin Shook

See Also

automatePrj

Examples

## Not run: 
# Automate the .prj before use
automatePrj("c:/BadLake/BadLake1975.prj")

# Using specified paths - in this case the .obs files reference in
# the .prj must contain the file path.
# It's a good idea to use absolute paths for the .prj and .obs files.
# If you use relative paths, they have to be w.r.t. the CRHM executable file.

setPrjObs("c:/BadLake/BadLake1975.prj", obsFiles = "c:/BadLake/Badlake73_76.obs")
result <- runCRHM("c:/CRHM/CRHM.exe", "c:/BadLake/BadLake1975.prj",
outfile = "c:/BadLake/BadLake1975Output.txt")

# Omitting paths - all files are stored in the current directory.

# Remove paths from the reference to the .obs files in the .prj file
setPrjObs("c:/BadLake/BadLake1975.prj", obsFiles = "Badlake73_76.obs")

# Set the working directory to the one holding the model files.
setwd("c:/BadLake")

# Execute the model.
result <- runCRHM("c:/CRHM/CRHM.exe", "BadLake1975.prj",
outfile = "BadLake1975Output.txt")

# If CRHM is on the system path you can run it without specifying the location.
# This command will show the current path:
Sys.getenv("PATH")

# Execute the model without specifying the path to CRHM.
result <- runCRHM("CRHM.exe", "BadLake1975.prj",
outfile = "BadLake1975Output.txt")
## End(Not run)

CentreForHydrology/CRHMr documentation built on April 6, 2024, 5:27 p.m.