-
Notifications
You must be signed in to change notification settings - Fork 31
/
adjust_gday_param_file.R
50 lines (43 loc) · 1.24 KB
/
adjust_gday_param_file.R
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
# Change various params in a G'DAY input file.
# Author: Martin De Kauwe
# Date: 12.05.2016
# Email: mdekauwe@gmail.com
#
# e.g....
#
# in_fname <- "base_start.cfg"
# out_fname <- "test.ini"
#
# replacements <- list("ncycle" = "true",
# "modeljm" = "3",
# "print_options" = "end",
# "jmax" = "110.0",
# "vcmax" = "55.0")
#
# adjust_gday_params(in_fname, out_fname, replacements)
adjust_gday_params <- function(in_fname, out_fname, replacements) {
if (!require("ini")){
install.packages("ini")
library(ini)
}
g <- read.ini(in_fname)
for (key in names(replacements)) {
match_git <- key %in% names(g$git)
match_files <- key %in% names(g$files)
match_params <- key %in% names(g$params)
match_state <- key %in% names(g$state)
match_control <- key %in% names(g$control)
if (match_git) {
g$git[key] <- replacements[key]
} else if (match_files) {
g$files[key] <- replacements[key]
} else if (match_params) {
g$params[key] <- replacements[key]
} else if (match_state) {
g$state[key] <- replacements[key]
} else if (match_control) {
g$control[key] <- replacements[key]
}
}
write.ini(g, out_fname)
}