Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Gadget2 read and units #8

Merged
merged 11 commits into from
Oct 29, 2021
16 changes: 8 additions & 8 deletions src/Gadget.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Header
mutable struct HeaderGadget2
npart::MVector{6,Int32} # gas, halo, disk, Bulge, star, blackholw
npart::MVector{6,Int32} # gas, halo, disk, bulge, star, blackhole
mass::MVector{6,Float64}

time::Float64
Expand Down Expand Up @@ -220,7 +220,7 @@ end

function read_HSML!(f::Union{IOStream,Stream{format"Gadget2"}}, data::StructArray, NumGas::Int32, uLength::Units)
temp1 = read(f, Int32)
HSML = data.HSML
HSML = data.Hsml
for i in 1:NumGas
HSML[i] = read(f, Float32) * 1.0 * uLength
end
Expand Down Expand Up @@ -275,18 +275,18 @@ function read_gadget2_particle(f::Union{IOStream,Stream{format"Gadget2"}}, heade
# Read Gas Internal Energy Block
NumGas = header.npart[1]
if NumGas > 0 && header.flag_entropy_instead_u > 0 && !eof(f)
d = data["gases"]
d = data[data.Collection .== GAS]
elehcim marked this conversation as resolved.
Show resolved Hide resolved

if !eof(f)
read_Entropy!(f, data, NumGas, getuEntropy(units))
read_Entropy!(f, d, NumGas, getuEntropy(units))
elehcim marked this conversation as resolved.
Show resolved Hide resolved
end

if !eof(f)
read_Density!(f, data, NumGas, getuDensity(units))
read_Density!(f, d, NumGas, getuDensity(units))
elehcim marked this conversation as resolved.
Show resolved Hide resolved
end

if !eof(f)
read_HSML!(f, data, NumGas, getuLength(units))
read_HSML!(f, d, NumGas, getuLength(units))
elehcim marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down Expand Up @@ -333,9 +333,9 @@ function read_gadget2_particle_format2(f::Union{IOStream,Stream{format"Gadget2"}
elseif name == "MASS"
read_MASS!(f, data, header, getuMass(units))
elseif name == "RHO "
read_Density!(f, data["gases"], NumGas, getuDensity(units))
read_Density!(f, data[data.Collection.==GAS], NumGas, getuDensity(units))
elehcim marked this conversation as resolved.
Show resolved Hide resolved
elseif name == "HSML"
read_HSML!(f, data["gases"], NumGas, getuLength(units))
read_HSML!(f, data[data.Collection.==GAS], NumGas, getuLength(units))
elehcim marked this conversation as resolved.
Show resolved Hide resolved
elseif name == "POT "
read_POT!(f, data, getuEnergy(units))
elseif name == "ACCE"
Expand Down