From 3e827f6fc07a2aae1e6ae6942ce41e8fc474f056 Mon Sep 17 00:00:00 2001
From: Alois Dirnaichner <alodi@directbox.com>
Date: Wed, 18 Mar 2020 15:28:01 +0100
Subject: [PATCH] Improve documentation.

---
 scripts/output/comparison/multiComparison.R | 15 +++++++++++++--
 scripts/utils/compareParallel.R             |  8 +++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/scripts/output/comparison/multiComparison.R b/scripts/output/comparison/multiComparison.R
index f9c4b4f..d189f3f 100644
--- a/scripts/output/comparison/multiComparison.R
+++ b/scripts/output/comparison/multiComparison.R
@@ -40,9 +40,18 @@ require(data.table)
 #'   in coupled runs
 #' short: the run should run only on a time range up to 2060
 #'
+#' Eventually, `scripts/utils/compareParallel.R` reads the file
+#' `multi_comparison.csv` and executes `compareScenarios` locally or on the cluster
+#' (depending on the presence of the `sbatch` slurm utils).
+#'
 #' The number of cores to be used in parallel on the cluster is
 #' determined by the variable CORES at the top of the function body.
 #'
+#' The prefix for coupled runs is also defined at the top (COUPLED_PREFIX).
+#'
+#' The scenarioComparison plots are stored in the subfolder
+#' OUTPUT_FOLDER.
+#'
 #' @param listofruns a list of output folders, as given by the
 #'     `output.R` infrastructure
 
@@ -50,6 +59,7 @@ require(data.table)
 compareScenTable <- function(listofruns){
   CORES = 12
   COUPLED_PREFIX = "C_"
+  OUTPUT_FOLDER = "multi_comparison_plots"
 
   scendt <- fread("config/multi_comparison_matrix.csv")
   scendt[
@@ -103,10 +113,11 @@ compareScenTable <- function(listofruns){
 
   if(system("hash sbatch 2>/dev/null") == 0){
     cat("Submitting comparison Jobs:\n")
-    system(sprintf("sbatch --job-name=rem-compare --output=log-%%j.out --mail-type=END --cpus-per-task=%i --qos=priority --wrap=\"Rscript scripts/utils/compareParallel.R \"", CORES))
+    system(sprintf("sbatch --job-name=rem-compare --output=log-%%j.out --mail-type=END --cpus-per-task=%i --qos=priority --wrap=\"Rscript scripts/utils/compareParallel.R %s\"",
+    CORES, OUTPUT_FOLDER))
   }else{
     source("scripts/utils/compareParallel.R")
   }
 }
 
-compareScenTable(outputdirs, CORES)
+compareScenTable(outputdirs)
diff --git a/scripts/utils/compareParallel.R b/scripts/utils/compareParallel.R
index 500c4b1..ffcca65 100644
--- a/scripts/utils/compareParallel.R
+++ b/scripts/utils/compareParallel.R
@@ -8,7 +8,13 @@ require(data.table)
 require(parallel)
 require(remind)
 
-plotfldr <- "multi_comparison_plots/"
+args = commandArgs(trailingOnly=TRUE)
+if (length(args)==0) {
+  plotfldr <- "multi_comparison_plots"
+} else {
+  plotfldr <- args[1]
+}
+
 dir.create(plotfldr, showWarnings = F)
 
 NUM_OF_CPUS_LOCAL <- 2
-- 
GitLab