Description Usage Arguments Value Examples
Change parameters in a MACRO simulation, one by one or several at a time, and generate a new list of MACRO Simulation parameters.
1 2 3 4 | rmacroliteChangeParam(x, p, ...)
## S3 method for class 'macroParFile'
rmacroliteChangeParam(x, p, ...)
|
x |
A |
p |
A
|
... |
Additional parameters passed to specific methods. |
Returns a list of macroParFile
objects, with class
macroParFileList
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | library( "rmacrolite" )
# Path to an example par-file
par_file_path <- system.file( "par-files",
"chat_winCer_GW-X_900gHa_d182.par",
package = "rmacrolite" )
# Import the example par-file
par_file <- rmacroliteImportParFile(
file = par_file_path )
# Current value of ZKD (Freundlich sorption)
as.numeric( rmacroliteGet1Param(
x = par_file,
pTag = "ZKD\t%s\t%s",
type = "SOLUTE PARAMETERS" ) )
# Organic matter content profile
oc <- as.numeric( rmacroliteGet1Param(
x = par_file,
pTag = "ORGC\t%s\t%s",
type = "PROPERTIES" ) )
oc_factors <- oc / oc[ 1L ]
# Change ZKD
par_file <- rmacroliteChangeParam(
x = par_file,
p = data.frame(
"tag" = sprintf( "ZKD\t%s\t%s", 1L:6L, "%s" ),
"values" = 1 * oc_factors, # 1 is Kf for topsoil
"type" = rep( "SOLUTE PARAMETERS", 6L ),
"set_id" = rep( 1L, 6L ),
stringsAsFactors = FALSE ) )[[ 1L ]]
# Check new value
new_zkd <- as.numeric( rmacroliteGet1Param(
x = par_file,
pTag = "ZKD\t%s\t%s",
type = "SOLUTE PARAMETERS" ) )
new_zkd
# Parameter variations for several parameter sets
p <- data.frame(
"tag" = c( "ALPHA\t1\t%s", "ALPHA\t2\t%s",
"ZKD\t1\t%s", "ZKD\t2\t%s" ),
"type" = c( "PHYSICAL PARAMETERS", "PHYSICAL PARAMETERS",
"SOLUTE PARAMETERS", "SOLUTE PARAMETERS" ),
"values" = c( 0.02, 0.02, 2, 2 ),
"set_id" = c( 1, 1, 2, 2 ),
stringsAsFactors = FALSE )
par_file_list <- rmacroliteChangeParam( x = par_file, p = p )
class( par_file_list ) # Should be a list
length( par_file_list ) # Should be 2
# # Not run
# rmacroliteRun( x = par_file_list )
# Internal checks
if( !all( abs( (1 * oc_factors) - new_zkd ) < 1e-15 ) ){
stop( "Test of rmacroliteChangeParam() failed" )
}
# Clean-up
rm( par_file_path, par_file, oc, oc_factors, new_zkd, p,
par_file_list )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.