diff --git a/MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala b/MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala index 64c0275..0074746 100644 --- a/MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala +++ b/MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala @@ -45,6 +45,16 @@ abstract class StormSim { */ val printGnu = true + /** + * Tells the simulator if data should be written to disk. + */ + val writeData = true + + /** + * The filename of the output data file. + */ + val fileName = "data.dat" + /** * Overwrite to define the model to be simulated. */ @@ -77,8 +87,8 @@ abstract class StormSim { println(s"""Simulation '${model.title}' took ${time.toDouble / 1000} seconds and resulted in ${endSim.size} data vectors of size ${endSim.head._2.fields.size}.""") // Logging - if (!endSim.isEmpty) { - loggingStrategy.writeStormData(model, endSim) + if (!endSim.isEmpty && writeData) { + loggingStrategy.writeStormData(fileName, model, endSim) } println("Finished logging to disk, starting Gnuplot.") diff --git a/MOISCore/src/main/scala/ed/mois/core/util/DataToFileWriter.scala b/MOISCore/src/main/scala/ed/mois/core/util/DataToFileWriter.scala index 6abb34b..c48f660 100644 --- a/MOISCore/src/main/scala/ed/mois/core/util/DataToFileWriter.scala +++ b/MOISCore/src/main/scala/ed/mois/core/util/DataToFileWriter.scala @@ -14,11 +14,11 @@ import scala.collection.immutable.TreeMap class DataToFileWriter { val fileName = "data.dat" - val clearOutput = Resource.fromOutputStream(new java.io.FileOutputStream(fileName)) - clearOutput.write("") val output: Output = Resource.fromFile("data.dat") def writeDataHeader(dh: Array[String]) { + val clearOutput = Resource.fromOutputStream(new java.io.FileOutputStream(fileName)) + clearOutput.write("") output.write("t " + dh.mkString(" ") + "\n") } def writeDataPoints(t0: Double, dps: Array[Any]) { @@ -28,9 +28,9 @@ class DataToFileWriter { output.write(p._1 + " " + p._2.fields.map(_._2).mkString(" ") + "\n") } - def writeStormData(model: StormModel, d: TreeMap[Double, StormState[_]]) { + def writeStormData(fileN: String, model: StormModel, d: TreeMap[Double, StormState[_]]) { for { - outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileName)).outputProcessor + outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileN)).outputProcessor out = outProcessor.asOutput } { // Write data header diff --git a/MOISModels/src/main/scala/ed/mois/models/storm/SampleODESystem.scala b/MOISModels/src/main/scala/ed/mois/models/storm/SampleODESystem.scala index 1ed375b..28ed23c 100644 --- a/MOISModels/src/main/scala/ed/mois/models/storm/SampleODESystem.scala +++ b/MOISModels/src/main/scala/ed/mois/models/storm/SampleODESystem.scala @@ -19,6 +19,7 @@ object SampleODESimRunner extends App { val sim = new StormSim { override val simulationStrategy = () => new IndepTimeScaleStrategy(50.0, 0.05) {override val debug = false} val model = new SampleODEModel + override val fileName = "sampleODE.dat" } val results = sim.runSim