rmacroliteChangeParam-methods: Change parameters in a MACRO simulation

Description Usage Arguments Value Examples

Description

Change parameters in a MACRO simulation, one by one or several at a time, and generate a new list of MACRO Simulation parameters.

Usage

1
2
3
4
rmacroliteChangeParam(x, p, ...)

## S3 method for class 'macroParFile'
rmacroliteChangeParam(x, p, ...)

Arguments

x

A macroParFile object, containing one simulations whose parameters should be changed.

p

A data.frame with one row per parameter (value), with the following columns:

  • tag: a text (character) string containing the parameter value that should be searched and replaced in the PAR file, with the parameter value replaced by the string %s. NOTE: CASE SENSITIVE!

  • values: The new value of the parameter (one value per row in p).

  • type: a character string. Parameter category (category's header in the PAR file).

  • set_id: the simulation identifier: all parameters (rows) that have the same set_id will be changed simultaneously, while parameters (rows) that have a different set_id will be in different simulations (parameter sets). If set_id is missing, it is assumed that all rows in p are different simulations (they will be attributed different set_id). Notice that set_id is not the RUNID and the RUNID in the simulation will therefore not be changed to the value of set_id.

  • tagNb (optional): an integer values. If several rows have the same pTag (without an index), indicates which one to change (1 for the 1st, 2 for the 2nd, etc.). Typically needed for some irrigation parameters in MACRO.

...

Additional parameters passed to specific methods.

Value

Returns a list of macroParFile objects, with class macroParFileList.

Examples

 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 )

julienmoeys/rmacrolite documentation built on May 22, 2019, 6:31 p.m.