8
|
1 # help : Rscript % --url=https://coby.infosol.inrae.fr:7777/semantify --srcDir=~/CSCL/src/csoprapreprocessor/inst/extdata/carboseq/set001/
|
|
2
|
|
3 # Function to parse command-line arguments
|
|
4 parse_args <- function() {
|
|
5 args <- commandArgs(trailingOnly = TRUE)
|
|
6
|
|
7 # Default values for optional parameters
|
11
|
8 url <- "https://coby.infosol.inrae.fr:8080/semantify/"
|
8
|
9 srcDir <- NULL
|
|
10 part <- "modeltoolbox_sem_sep"
|
|
11 DS <- T
|
|
12 NBCores <- 1
|
|
13 # Parse arguments
|
|
14 for (arg in args) {
|
|
15 if (grepl("^--url=", arg)) {
|
|
16 url <- sub("^--url=", "", arg)
|
|
17 }
|
|
18
|
|
19 if (grepl("^--srcDir=", arg)) {
|
|
20 srcDir <- sub("^--srcDir=", "", arg)
|
|
21 }
|
|
22
|
|
23 if (grepl("^--part=", arg)) {
|
|
24 part <- sub("^--part=", "", arg)
|
|
25 }
|
|
26
|
|
27 if (grepl("^--DS=", arg)) {
|
|
28 DS <- ifelse(sub("^--DS=", "", arg) == "TRUE", TRUE, FALSE)
|
|
29 }
|
|
30
|
|
31 if (grepl("^--NBCores=", arg)) {
|
|
32 NBCores <- as.numeric(sub("^--NBCores=", "", arg))
|
|
33 }
|
|
34
|
|
35 if (grepl("^--srcOut=", arg)) {
|
|
36 srcOut <- sub("^--srcOut=", "", arg)
|
|
37 }
|
11
|
38
|
|
39 if (grepl("^--semPath=", arg)) {
|
|
40 semPath <- sub("^--semPath=", "", arg)
|
|
41 }
|
8
|
42
|
|
43 }
|
|
44
|
11
|
45 list(url = url, srcDir = srcDir, part = part, DS = DS, NBCores = NBCores, srcOut = srcOut, semPath = semPath)
|
8
|
46 }
|
|
47
|
|
48 argus <- parse_args()
|
|
49 url <- argus[["url"]]
|
|
50 srcDir <- argus[["srcDir"]]
|
|
51 part <- argus[["part"]]
|
|
52 DS <- argus[["DS"]]
|
|
53 NBCores <- argus[["NBCores"]]
|
|
54
|
|
55 srcOut <- argus[["srcOut"]]
|
11
|
56 semPath <- argus[["semPath"]]
|
8
|
57
|
|
58 if (!endsWith(srcOut, "/")) {
|
|
59 srcOut <- paste0(srcOut, "/")
|
|
60 }
|
|
61
|
|
62 # url="https://147.100.203.110/semantify "
|
|
63 # srcDir="~/tmp/testFiles/400Sites/"
|
|
64 # part="modeltoolbox"
|
|
65 # part="csoprapreprocessor"
|
|
66 # DS=TRUE
|
|
67 # NBCores=10
|
|
68
|
|
69
|
|
70 # MTB{{{
|
|
71 if (part == "modeltoolbox") {
|
|
72 f0 <- function(){
|
|
73 modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest",
|
|
74 preprocessorInputs = ppi)
|
|
75 modeltoolbox::runSims(maxCores = NBCores)
|
|
76 res <- modeltoolbox::readSocForcingsResults()
|
|
77 fileName <- "resRun.RData"
|
|
78 filePath <- file.path(srcOut, fileName)
|
|
79 save(res, file = filePath)
|
|
80 }
|
|
81 }
|
|
82 #}}}
|
|
83
|
|
84 if (part == "modeltoolbox_sem_sep") {
|
|
85 DS <- F
|
|
86 print("Setting DS to F. Will semantify outside of the csoprapreprocessor functions")
|
|
87 f0 <- function(){
|
|
88 csopratools::semantify(
|
|
89 inputDir = srcDir,
|
|
90 outputDir = srcDir,
|
|
91 name = "carboseq",
|
11
|
92 # use = "service",
|
8
|
93 URL = url,
|
11
|
94 use = "java",
|
|
95 semantifierRootPath = semPath,
|
|
96 extFileNames = paste0(c("crop", "soil", "units"), ".csv")
|
8
|
97 )
|
|
98 print("between semantify and load")
|
|
99 modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest",
|
|
100 preprocessorInputs = ppi)
|
|
101 print("between load an sim")
|
|
102 modeltoolbox::runSims(maxCores = NBCores)
|
|
103 res <- modeltoolbox::getYearlySOCResults()
|
|
104 fileName <- "resRun.RData"
|
|
105 filePath <- file.path(srcOut, fileName)
|
|
106 save(res, file = filePath)
|
|
107 }
|
|
108 }
|
|
109
|
|
110 ppi <- list(
|
|
111 weatherRetrievalMethod = "service",
|
|
112 srcDir = srcDir,
|
|
113 doSemantify = DS,
|
|
114 weatherRetrievalURL = "https://147.100.203.110/climate",
|
|
115 semantifierServiceURL = url
|
|
116 )
|
|
117
|
|
118
|
|
119 print(url)
|
|
120 print(srcDir)
|
|
121 print(srcOut)
|
|
122 print(DS)
|
|
123 print(NBCores)
|
|
124 print(f0)
|
|
125
|
|
126 f0()
|
|
127
|
|
128
|