Skip to content

Commit

Permalink
Remove Vars type to avoid further issues
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Apr 20, 2021
1 parent 3694696 commit b501e73
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Batsrus"
uuid = "e74ebddf-6ac1-4047-a0e5-c32c99e57753"
authors = ["Hongyang Zhou <[email protected]>"]
version = "0.2.8"
version = "0.2.9"

[deps]
FortranFiles = "c58ffaec-ab22-586d-bfc5-781a99fd0b10"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/man/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ head, data = readlogdata(logfilename)
## Derived variables
```
v = getvars(data, ["Bx", "By", "Bz"])
B = @. sqrt(v.Bx^2 + v.By^2 + v.Bz^2)
B = @. sqrt(v["Bx"]^2 + v["By"]^2 + v["Bz"]^2)
```

## Output format conversion
Expand Down
8 changes: 2 additions & 6 deletions src/Batsrus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Batsrus

using Printf

export Data, Vars
export Data

"""
FileList
Expand All @@ -21,7 +21,7 @@ struct FileList
end

"""
Data
Data
Primary data storage type, with fields `head` of header info, grid `x`, value
`w`, and file info `list`.
Expand All @@ -33,10 +33,6 @@ struct Data{T<:AbstractFloat}
list::FileList
end

struct Vars
data::Dict{String, Array{Float32}}
end

include("io.jl")
include("select.jl")
include("vtk.jl")
Expand Down
18 changes: 10 additions & 8 deletions src/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ function subvolume(x, y, z, u, v, w, limits)
end

"""
subdata(data, xind, yind, sz)
subdata(data, xind, yind, zind, sz)
subdata(data, xind, yind, sz)
subdata(data, xind, yind, zind, sz)
Return the sliced data based on indexes.
"""
Expand Down Expand Up @@ -234,24 +234,26 @@ function getvar(data::Data, var::T) where T<:AbstractString
w
end

"Return variables' data from string vector. See also: [`getvar`](@ref)"
"""
getvars(data::Data, Names::Vector) -> Dict
Return variables' data as a dictionary from string vector.
See also: [`getvar`](@ref).
"""
function getvars(data::Data, Names::Vector{T}) where T<:AbstractString

dict = Dict()
for name in Names
dict[name] = getvar(data, name)
end

Vars(dict)
dict
end

Base.getproperty(p::Vars, name::Symbol) = getfield(p, :data)[String(name)]


const variables_predefined = Dict(
"B" => data -> sqrt.(getvar(data, "Bx").^2 .+ getvar(data, "By").^2 .+ getvar(data, "Bz").^2),
"E" => data -> sqrt.(getvar(data, "Ex").^2 .+ getvar(data, "Ey").^2 .+ getvar(data, "Ez").^2),
"U" => data -> sqrt.(getvar(data, "Ux").^2 .+ getvar(data, "Uy").^2 .+ getvar(data, "Uz").^2),
#"beta" => data -> getvar(data, "P") ./ getvar(data, "B").^2 * 2μ,
)

)
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
@test p[1] 0.560976f0
@test p[2] 0.53704995f0
vars = getvars(data, ["p"])
@test size(vars.p) == (8,8,8)
@test size(vars["p"]) == (8,8,8)
end

@testset "log" begin
Expand Down

0 comments on commit b501e73

Please sign in to comment.