From 05b3a979e711c97013547f3403ca6939377e07a4 Mon Sep 17 00:00:00 2001 From: orichters Date: Mon, 21 Aug 2023 12:14:19 +0200 Subject: [PATCH] in start_bundle_coupled fail on missing files/dirs, let output.R fail if no folders found --- Makefile | 2 +- output.R | 3 +++ start_bundle_coupled.R | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6bc46bab9..51299b3b7 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ test-coupled: ## Test if the coupling with MAgPIE works. Takes significantly test-coupled-slurm: ## test-coupled, but on slurm $(info Coupling tests take around 75 minutes to run. Sent to slurm, find log in test-coupled.log) - @sbatch --qos=priority --wrap="make test-coupled" --job-name=test-coupled --mail-type=END --output=test-coupled.log + @sbatch --qos=priority --wrap="make test-coupled" --job-name=test-coupled --mail-type=END --output=test-coupled.log --comment="test-coupled.log" test-full: ## Run all tests, including coupling tests and a default ## REMIND scenario. Takes significantly longer than 10 minutes to run. diff --git a/output.R b/output.R index 7aead9105..9db19c779 100755 --- a/output.R +++ b/output.R @@ -133,6 +133,9 @@ if (! exists("outputdir")) { dirnames <- if (length(dir_folder) == 1) basename(dirs) else dirs names(dirnames) <- stringr::str_extract(dirnames, "rem-[0-9]+$") names(dirnames)[is.na(names(dirnames))] <- "" + if (length(dirnames) == 0) { + stop("No directories found containing gdx", if (needingMif) " and mif", " files. Aborting.") + } selectedDirs <- chooseFromList(dirnames, type = "runs to be used for output generation", userinfo = paste0(if ("policyCosts" %in% output) "The reference run will be selected separately! " else NULL, if (needingMif) "Do you miss a run? Check if .mif exists and rerun reporting. " else NULL), diff --git a/start_bundle_coupled.R b/start_bundle_coupled.R index 8c8d79589..a60c96a9f 100755 --- a/start_bundle_coupled.R +++ b/start_bundle_coupled.R @@ -155,16 +155,6 @@ if (length(argv) > 0) { message("") } -message("path_remind: ", if (dir.exists(path_remind)) green else red, path_remind, NC) -message("path_magpie: ", if (dir.exists(path_magpie)) green else red, path_magpie, NC) -message("path_settings_coupled: ", if (file.exists(path_settings_coupled)) green else red, path_settings_coupled, NC) -message("path_settings_remind: ", if (file.exists(path_settings_remind)) green else red, path_settings_remind, NC) -message("path_remind_oldruns: ", if (dir.exists(path_remind_oldruns)) green else red, path_remind_oldruns, NC) -message("path_magpie_oldruns: ", if (dir.exists(path_magpie_oldruns)) green else red, path_magpie_oldruns, NC) -message("prefix_runname: ", prefix_runname) -message("n600_iterations: ", n600_iterations) -message("run_compareScenarios: ", run_compareScenarios) - if (! file.exists("output")) dir.create("output") ensureRequirementsInstalled(rerunPrompt = "start_bundle_coupled.R") @@ -178,6 +168,21 @@ deletedFolders <- 0 stamp <- format(Sys.time(), "_%Y-%m-%d_%H.%M.%S") +message("path_remind: ", if (dir.exists(path_remind)) green else red, path_remind, NC) +message("path_magpie: ", if (dir.exists(path_magpie)) green else red, path_magpie, NC) +message("path_settings_coupled: ", if (file.exists(path_settings_coupled)) green else red, path_settings_coupled, NC) +message("path_settings_remind: ", if (file.exists(path_settings_remind)) green else red, path_settings_remind, NC) +message("path_remind_oldruns: ", if (dir.exists(path_remind_oldruns)) green else red, path_remind_oldruns, NC) +message("path_magpie_oldruns: ", if (dir.exists(path_magpie_oldruns)) green else red, path_magpie_oldruns, NC) +message("prefix_runname: ", prefix_runname) +message("n600_iterations: ", n600_iterations) +message("run_compareScenarios: ", run_compareScenarios) + +if (any(! file.exists(c(path_settings_coupled, path_settings_remind))) || + any(! dir.exists(c(path_remind, path_magpie, path_remind_oldruns, path_magpie_oldruns)))) { + stop("Missing files or directories, see in red above.") +} + if ("--gamscompile" %in% flags && ! file.exists("input/source_files.log")) { message("\n### Input data missing, need to compile REMIND first (2 min.)\n") system("Rscript start.R config/tests/scenario_config_compile.csv")