-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunmodel_calls.R
More file actions
61 lines (46 loc) · 2.2 KB
/
runmodel_calls.R
File metadata and controls
61 lines (46 loc) · 2.2 KB
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
#options(warn=-1)
#if (!require("GetoptLong")) install.packages("GetoptLong", repos ="https://cran.csiro.au/")
rm(list=ls())
#set defaults
startCell <- 1
endCell <- 1
run <- "rcp26"
maxCores <- 1
VERSION <- "0.01 (25-Aug-2017)"
dryRun <- FALSE
#handle commandline parameters
GetoptLong::GetoptLong(
"startCell=i", "Cell to start processing (1:39567), optional, default (1)",
"endCell=i", "Cell to end processing (1:39567), optional, default (1). Must be >= startCell",
"maxCores=i", "Maximum of cores to be used",
"run=s", "Emissions scenario (rcp26, rcp45, rcp60, rcp85), optional, default (rcp26)",
"inputPath=s", "Path where well-known input files are available, mandatory",
"outputPath=s", "Path where output files can and will be written, mandatory",
"dryRun!", "if set, the long running model code will not be run; all other code will run (default = FALSE, i.e. will run all)"
)
#validations
if (startCell < 1 | startCell > 39567 ) stop(sprintf("value out of range for 'startCell' '%s'", startCell))
if (endCell < 1 | endCell > 39567 ) stop(sprintf("value out of range for 'endCell' '%s'", endCell))
if (startCell > endCell) stop(sprintf("'endCell' ('%s') must be greater than 'startCell ('%s')", endCell, startCell))
if (!exists("inputPath")) stop
if (!exists("outputPath")) stop
# start execution
source('runmodel.R')
source('helpers.R')
cells <- seq(startCell, endCell, by = 1)
cells <- cells[!cells %in% grid_ids_found(outputPath)]
if (length(cells) > 0) {
numCores <- ifelse(length(cells) > maxCores, maxCores, length(cells))
the_cluster <- parallel::makeForkCluster(getOption("cl.cores", numCores))
if(!dryRun) {
discard_output <- parallel::clusterApplyLB(the_cluster
,x=cells
,fun=rungridsep
,gcm="ipsl-cm5a-lr"
,run=run
,output="aggregated"
,input_files_location = inputPath
,output_files_location = outputPath)
}
parallel::stopCluster(the_cluster)
}