-
Notifications
You must be signed in to change notification settings - Fork 13
/
json_io.jl
37 lines (31 loc) · 1.22 KB
/
json_io.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"Export a [`ClimateModel`](@ref) instance to a `.json` file.
This `.json` file can be shared with others, you can import it using "
function export_state(filename::AbstractString, m::ClimateModel)
open(filename, "w") do io
JSON2.write(io, m)
end
end
function import_state(filename::String)::ClimateModel
open(filename, "r") do io
return JSON2.read(io, ClimateModel)
end
end
function export_parameters(filename::AbstractString, params::ClimateModelParameters)
open(filename, "w") do io
JSON2.write(io, params)
end
end
function import_parameters(filename::AbstractString)::ClimateModelParameters
open(filename, "r") do io
return JSON2.read(io, ClimateModelParameters)
end
end
"""The [`ClimateModelParameters`](@ref) included with this package.
Currently `included_configurations["default"]` is the only included set."""
const included_configurations = let
# find the config dir relative to this .jl file
config_dir = joinpath(@__DIR__, "..", "..", "configurations")
config_files = [file for file in readdir(config_dir) if occursin(".json", file)]
loaded = [import_parameters(joinpath(config_dir, file)) for file in config_files]
Dict(p.name => p for p in loaded)
end