diff --git a/gama.headless/src/gama/headless/common/HeadLessErrors.java b/gama.headless/src/gama/headless/common/HeadLessErrors.java index aec2d249d2..aa17ad179f 100644 --- a/gama.headless/src/gama/headless/common/HeadLessErrors.java +++ b/gama.headless/src/gama/headless/common/HeadLessErrors.java @@ -29,15 +29,15 @@ public abstract class HeadLessErrors { /** The Constant NOT_EXIST_FILE_ERROR. */ public static final int NOT_EXIST_FILE_ERROR = 4; - - /** The Constant HPC_PARAMETER_ERROR. */ - public static final int HPC_PARAMETER_ERROR = 5; +// +// /** The Constant HPC_PARAMETER_ERROR. */ +// public static final int HPC_PARAMETER_ERROR = 5; /** The Constant INPUT_NOT_DEFINED. */ - public static final int INPUT_NOT_DEFINED = 6; + public static final int INPUT_NOT_DEFINED = 5 /* 6 */; /** The Constant OUTPUT_NOT_DEFINED. */ - public static final int OUTPUT_NOT_DEFINED = 7; + public static final int OUTPUT_NOT_DEFINED = 6 /* 7 */; /** The Constant ERRORS. */ private final static String[] ERRORS = @@ -46,7 +46,7 @@ public abstract class HeadLessErrors { "Launching error... try again", "Unable to create directory at #. Check your file permission!", "Unable to create directory at #. Directory already exist!", - "Unable to read input file #. File not exist!", + "Unable to read input file #. File does not exist!", "Input file is not defined", "Output directory is not defined"}; diff --git a/gama.headless/src/gama/headless/runtime/HeadlessApplication.java b/gama.headless/src/gama/headless/runtime/HeadlessApplication.java index a63e0d308b..5c437ea5a2 100644 --- a/gama.headless/src/gama/headless/runtime/HeadlessApplication.java +++ b/gama.headless/src/gama/headless/runtime/HeadlessApplication.java @@ -121,6 +121,9 @@ private static Injector configureInjector() { /** The Constant THREAD_PARAMETER. */ final public static String THREAD_PARAMETER = "-hpc"; + /** The Constant THREAD_PARAMETER. */ + final public static String STEPS_PARAMETER = "-steps"; + /** The Constant PING_INTERVAL. */ final public static String PING_INTERVAL = "-ping_interval"; @@ -305,6 +308,10 @@ private boolean checkParameters(final List args) { size = size - 4; mustContainInFile = mustContainOutFolder = false; } + + if (args.contains(GAML_PARAMETER)) { + size = size - 2; + } // Runner verification // ======================== @@ -319,11 +326,15 @@ private boolean checkParameters(final List args) { // Check and create output folder Globals.OUTPUT_PATH = args.get(args.size() - 1); final File output = new File(Globals.OUTPUT_PATH); - if (!output.exists()) { output.mkdir(); } + if (!output.exists() && !output.mkdir()) { + return showError(HeadLessErrors.PERMISSION_ERROR, Globals.OUTPUT_PATH); + } // Check and create output image folder Globals.IMAGES_PATH = Globals.OUTPUT_PATH + "/snapshot"; final File images = new File(Globals.IMAGES_PATH); - if (!images.exists()) { images.mkdir(); } + if (!images.exists() && !images.mkdir()) { + return showError(HeadLessErrors.PERMISSION_ERROR, Globals.IMAGES_PATH); + } } if (mustContainInFile) { final int inIndex = args.size() - (mustContainOutFolder ? 2 : 1); @@ -658,14 +669,18 @@ public void runBatchSimulation(final String experimentName, final String pathToM */ public void runGamlSimulation(final List args) throws IOException, GamaCompilationFailedException, InterruptedException { - final String pathToModel = args.get(args.size() - 1); - assertIsAModelFile(pathToModel); - final String argExperimentName = args.get(args.size() - 2); - final String argGamlFile = args.get(args.size() - 1); - Integer numberOfCores = - args.contains(THREAD_PARAMETER) ? Integer.parseInt(after(args, THREAD_PARAMETER)) : null; - final List jb = ExperimentationPlanFactory.buildExperiment(argGamlFile, numberOfCores); + + final String argExperimentName = args.get(args.size() - 3); + final String argGamlFile = args.get(args.size() - 2); + final String argOutDir = args.get(args.size() - 1); + final Integer numberOfSteps = args.contains(STEPS_PARAMETER) ? Integer.parseInt(after(args, STEPS_PARAMETER)) : null; + final Integer numberOfCores = args.contains(THREAD_PARAMETER) ? Integer.parseInt(after(args, THREAD_PARAMETER)) : null; + + assertIsAModelFile(argGamlFile); + + final List jb = ExperimentationPlanFactory.buildExperiment(argGamlFile,numberOfSteps, numberOfCores); + ExperimentJob selectedJob = null; for (final IExperimentJob j : jb) { if (j.getExperimentName().equals(argExperimentName)) { @@ -674,7 +689,7 @@ public void runGamlSimulation(final List args) } } if (selectedJob == null) return; - Globals.OUTPUT_PATH = args.get(args.size() - 3); + Globals.OUTPUT_PATH = argOutDir; selectedJob.setBufferedWriter(new XMLWriter(Globals.OUTPUT_PATH + "/" + Globals.OUTPUT_FILENAME + ".xml")); processorQueue.setNumberOfThreads(numberOfCores != null ? numberOfCores : SimulationRuntime.DEFAULT_NB_THREADS); diff --git a/gama.headless/src/gama/headless/script/ExperimentationPlanFactory.java b/gama.headless/src/gama/headless/script/ExperimentationPlanFactory.java index 1f5249a585..5855a3aeed 100644 --- a/gama.headless/src/gama/headless/script/ExperimentationPlanFactory.java +++ b/gama.headless/src/gama/headless/script/ExperimentationPlanFactory.java @@ -158,17 +158,17 @@ public class ExperimentationPlanFactory { * @param modelFileName * the model file name * @param numberOfCores - * the number of cores passed throuhg the '-hpc' parameter. If null, means that '-hpc' is not set + * the number of cores passed through the '-hpc' parameter. If null, means that '-hpc' is not set * @return the list * @throws IOException * Signals that an I/O exception has occurred. * @throws GamaHeadlessException * the gama headless exception */ - public static List buildExperiment(final String modelFileName, final Integer numberOfCores) + public static List buildExperiment(final String modelFileName, final Integer numberOfSteps, final Integer numberOfCores) throws IOException, GamaCompilationFailedException { final long[] seeds = { DEFAULT_SEED }; - return JobListFactory.constructAllJobs(modelFileName, seeds, DEFAULT_FINAL_STEP, numberOfCores); + return JobListFactory.constructAllJobs(modelFileName, seeds, numberOfSteps == null ? DEFAULT_FINAL_STEP : numberOfSteps, numberOfCores); } /** @@ -184,7 +184,7 @@ public static List buildExperiment(final String modelFileName, f */ public static List buildExperiment(final String modelFileName) throws IOException, GamaCompilationFailedException { - return buildExperiment(modelFileName, null); + return buildExperiment(modelFileName,null, null); } /** diff --git a/gama.headless/src/gama/headless/xml/XMLWriter.java b/gama.headless/src/gama/headless/xml/XMLWriter.java index 3aab8eb409..eedd44c2c6 100644 --- a/gama.headless/src/gama/headless/xml/XMLWriter.java +++ b/gama.headless/src/gama/headless/xml/XMLWriter.java @@ -10,9 +10,12 @@ ********************************************************************************************************/ package gama.headless.xml; -import java.io.*; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; -import gama.headless.core.*; +import gama.headless.common.DataType; import gama.headless.job.ExperimentJob; import gama.headless.job.ListenedVariable; @@ -66,7 +69,9 @@ public void close() { public void writeResultStep(final long step, final ListenedVariable[] vars) { StringBuilder sb = new StringBuilder().append("\t\n"); for ( int i = 0; i < vars.length; i++ ) { - sb.append("\t\t").append(vars[i].getValue()) + sb.append("\t\t").append(vars[i].getValue()) .append("\n"); } sb.append("\t\n");