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

Add a more general way to read gadget2 file blocks #9

Open
elehcim opened this issue Oct 27, 2021 · 1 comment
Open

Add a more general way to read gadget2 file blocks #9

elehcim opened this issue Oct 27, 2021 · 1 comment

Comments

@elehcim
Copy link
Contributor

elehcim commented Oct 27, 2021

If a non standard block is present into the file, read it and put it into the relative StructArray with the correct Collection label.

For example blocks relative to the chemical composition of the gas particles...

@islent
Copy link
Member

islent commented Oct 29, 2021

Could you provide a test file?

I've got an unrefined idea to read non-standard blocks if not eof, in

AstroIO.jl/src/Gadget.jl

Lines 312 to 347 in d219923

function read_gadget2_particle_format2(f::Union{IOStream,Stream{format"Gadget2"}}, header::HeaderGadget2, units = uAstro)
NumGas = header.npart[1]
data = StructArray(Star(units))
empty!(data)
for k in 1:6
append!(data, StructArray([Star(units, collection = GadgetTypes[k]) for i = 1:header.npart[k]]))
end
while !eof(f)
temp1 = read(f, Int32)
name = String(read(f, 4))
temp2 = read(f, Int32)
skippoint = read(f, Int32)
if name == "POS "
read_POS!(f, data, getuLength(units))
elseif name == "VEL "
read_VEL!(f, data, getuVel(units))
elseif name == "ID "
read_ID!(f, data)
elseif name == "MASS"
read_MASS!(f, data, header, getuMass(units))
elseif name == "RHO "
read_Density!(f, data["gases"], NumGas, getuDensity(units))
elseif name == "HSML"
read_HSML!(f, data["gases"], NumGas, getuLength(units))
elseif name == "POT "
read_POT!(f, data, getuEnergy(units))
elseif name == "ACCE"
read_ACCE!(f, data, getuAcc(units))
end
end
return data
end

However, these non-standard data would be orgnized outside the particle array. It also need users to define the data type.

So I suggest that, user should provide two things, which could be packed in a Dict for multiple non-standard fields:

    function read_CHEM!(...)   # constrain data type here
        ...
    end

    arg = Dict("CHEM" => read_CHEM!, ...)  # provide to read_gadget2_particle_format2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants