-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfParser.jl
72 lines (57 loc) · 1.68 KB
/
ConfParser.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
abstract type IOConfig end
struct IOConfigGadget2 <: IOConfig
filename::String
format2::Bool
iofields::Vector{String}
end
function Base.show(io::IO, ioconfig::IOConfigGadget2)
print(io,
"""
Gadget2 I/O config:
filename: $(ioconfig.filename)
format2: $(ioconfig.format2)
iofields: $(ioconfig.iofields)
"""
)
end
function loadfromconfig(ioconfig::IOConfigGadget2)
#TODO how to construct Gadget2Block from iofields
end
struct IOConfigJLD2 <: IOConfig
filename::String
label::String
end
function Base.show(io::IO, ioconfig::IOConfigJLD2)
print(io,
"""
JLD2 I/O config:
filename: $(ioconfig.filename)
data label: $(ioconfig.label)
"""
)
end
function loadfromconfig(ioconfig::IOConfigJLD2)
return FileIO.load(ioconfig.filename, ioconfig.label)
end
function loadconfig(ConfFile::String)
conf = ConfParse(ConfFile)
parse_conf!(conf)
filename = retrieve(conf, "io", "filename")
format = retrieve(conf, "io", "format")
if format == "gadget2"
format2 = retrieve(conf, "io", "format2", Bool)
iofields = retrieve(conf, "io", "iofields")
# append to 4 Char
for i in eachindex(iofields)
Len = length(iofields[i])
@assert 1 <= Len <= 4 "Field names must have 1~4 characters!"
iofields[i] *= " "^(4 - Len)
end
return IOConfigGadget2(filename, format2, iofields)
elseif format == "jld2"
label = retrieve(conf, "io", "label")
return IOConfigJLD2(filename, label)
else
error("Unsupported snapshot format!")
end
end