tmake JLD optional - Granular.jl - Julia package for granular dynamics simulation (HTM) git clone git://src.adamsgaard.dk/Granular.jl (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 8306704d78dfadc40750669de1fbdfc32d0d99a1 (DIR) parent 679fbb6447fc38b7bd214b3bac2c3c7300817069 (HTM) Author: Anders Damsgaard <andersd@riseup.net> Date: Mon, 12 Jun 2017 15:24:03 -0400 make JLD optional Diffstat: M src/io.jl | 42 +++++++++++++++++++++---------- M test/jld.jl | 25 +++++++++++++++---------- 2 files changed, 44 insertions(+), 23 deletions(-) --- (DIR) diff --git a/src/io.jl b/src/io.jl t@@ -1,6 +1,10 @@ import WriteVTK import NetCDF -import JLD +hasJLD = false +if typeof(Pkg.installed("JLD")) == VersionNumber + import JLD + hasJLD = true +end ## IO functions t@@ -19,17 +23,23 @@ function writeSimulation(simulation::Simulation; filename::String="", folder::String=".", verbose::Bool=true) - if filename == "" - folder = folder * "/" * simulation.id - mkpath(folder) - filename = string(folder, "/", simulation.id, ".", - simulation.file_number, ".jld") - end + if !hasJLD + warn("Package JLD not found. Simulation save/read not supported. " * + "Please install JLD and its " * + "requirements with `Pkg.add(\"JLD\")`.") + else + if filename == "" + folder = folder * "/" * simulation.id + mkpath(folder) + filename = string(folder, "/", simulation.id, ".", + simulation.file_number, ".jld") + end - JLD.save(filename, "simulation", simulation) + JLD.save(filename, "simulation", simulation) - if verbose - info("simulation written to $filename") + if verbose + info("simulation written to $filename") + end end end t@@ -42,10 +52,16 @@ Read all content from `Simulation` from disk in JDL format. """ function readSimulation(filename::String=""; verbose::Bool=true) - if verbose - info("reading simulation from $filename") + if !hasJLD + warn("Package JLD not found. Simulation save/read not supported. " * + "Please install JLD and its " * + "requirements with `Pkg.add(\"JLD\")`.") + else + if verbose + info("reading simulation from $filename") + end + return JLD.load(filename, "simulation") end - return JLD.load(filename, "simulation") end export writeSimulationStatus (DIR) diff --git a/test/jld.jl b/test/jld.jl t@@ -2,15 +2,20 @@ info("#### $(basename(@__FILE__)) ####") -info("Writing simple simulation to JLD file") -sim = SeaIce.createSimulation(id="test") -SeaIce.addIceFloeCylindrical(sim, [ 0., 0.], 10., 1., verbose=false) -SeaIce.addIceFloeCylindrical(sim, [18., 0.], 10., 1., verbose=false) -sim.ocean = SeaIce.createRegularOceanGrid([10, 20, 5], [10., 25., 2.]) -SeaIce.findContacts!(sim, method="all to all") -SeaIce.writeVTK(sim, verbose=false) +info("Determining if JLD is installed") +if typeof(Pkg.installed("JLD")) == VersionNumber + info("JLD found, proceeding with JLD-specific tests") -SeaIce.writeSimulation(sim) + info("Writing simple simulation to JLD file") + sim = SeaIce.createSimulation(id="test") + SeaIce.addIceFloeCylindrical(sim, [ 0., 0.], 10., 1., verbose=false) + SeaIce.addIceFloeCylindrical(sim, [18., 0.], 10., 1., verbose=false) + sim.ocean = SeaIce.createRegularOceanGrid([10, 20, 5], [10., 25., 2.]) + SeaIce.findContacts!(sim, method="all to all") + SeaIce.writeVTK(sim, verbose=false) -sim2 = SeaIce.readSimulation("./test/test.1.jld") -SeaIce.compareSimulations(sim, sim2) + SeaIce.writeSimulation(sim) + + sim2 = SeaIce.readSimulation("./test/test.1.jld") + SeaIce.compareSimulations(sim, sim2) +end