Skip to content

Commit

Permalink
Add test cov; rename tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Nov 10, 2024
1 parent 569900d commit 513952a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ function getfilesize(fileID::IOStream, lenstr::Int32, ::Val{Real4Bat})

skip(fileID, TAG + lenstr + 2*TAG + sizeof(Int32) + sizeof(Float32))
ndim = abs(read(fileID, Int32))
tmp = read(fileID, Int32)
nt = read(fileID, Int32)
nw = read(fileID, Int32)
skip(fileID, 2*TAG)
nx = Vector{Int32}(undef, ndim)
read!(fileID, nx)
skip(fileID, 2*TAG)
if tmp > 0
tmp2 = zeros(Float32, tmp)
read!(fileID, tmp2)
if nt > 0
tmp = zeros(Float32, nt)
read!(fileID, tmp)
skip(fileID, 2*TAG)
end
read(fileID, lenstr)
Expand All @@ -350,15 +350,15 @@ function getfilesize(fileID::IOStream, lenstr::Int32, ::Val{Real8Bat})

skip(fileID, TAG + lenstr + 2*TAG + sizeof(Int32) + sizeof(Float32))
ndim = abs(read(fileID, Int32))
tmp = read(fileID, Int32)
nt = read(fileID, Int32)
nw = read(fileID, Int32)
skip(fileID, 2*TAG)
nx = Vector{Int32}(undef, ndim)
read!(fileID, nx)
skip(fileID, 2*TAG)
if tmp > 0
tmp2 = zeros(Float32, tmp)
read!(fileID, tmp2)
if nt > 0
tmp = zeros(Float32, nt)
read!(fileID, tmp)
skip(fileID, 2*TAG)
end
read(fileID, lenstr)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ end

@testset "Reading 2D structured binary" begin
file = "z=0_raw_1_t25.60000_n00000258.out"
@test_throws ArgumentError load(joinpath(datapath, file), npict=2)
bd = load(joinpath(datapath, file))
@test bd.head.time == 25.6f0
@test extrema(bd.x) == (-127.5f0, 127.5f0)
Expand All @@ -53,6 +54,7 @@ end
@test w[1,end] == 0.6848635077476501
@test bd["B"][:,end,end] == Float32[1.118034, -0.559017, 0.0]
@test bd["Bmag"][128,2] == 0.9223745f0
@test bd["B2"][128,2] == 0.8507747f0
# Linear interpolation at a given point
d = interp1d(bd, "rho", Float32[0.0, 0.0])
@test d == 0.6936918f0
Expand All @@ -67,6 +69,11 @@ end

file = "z=0_fluid_region0_0_t00001640_n00010142.out"
bd = load(joinpath(datapath, file))
@test bd["Emag"][2,1] == 2655.4805f0
@test bd["E2"][2,1] == 7.051577f6
@test bd["E"][:,2,1] == Float32[-241.05942, -2644.2058, -40.53219]
@test bd["Ue2"][2,1] == 33784.973f0
@test bd["Ui2"][2,1] == bd["Ui2"][2,1]
@test bd["Anisotropy0"][1:2,1] Float32[1.2630985, 2.4700143]
@test bd["Anisotropy1"][1:2,1] Float32[1.2906302, 2.6070855]
end
Expand All @@ -78,6 +85,7 @@ end
x, y, w = interp2d(bd, "rho", plotrange, useMatplotlib=false)
@test w[1,2] == 5.000018304080387
@test bd["Umag"][2] == 71.85452748407637
@test bd["U2"][2] == 5163.073119959886
end

@testset "Reading 3D structured binary" begin
Expand Down

0 comments on commit 513952a

Please sign in to comment.