enSight files with Julia

Hello!

Does anyone have experience reading enSight files with Julia? If so, I was mainly wondering if there is any library that can be used for that, or whether one has to write everything!

Thank you,
Thomas

I didn’t see a library (albeit, I did not look hard for a library). I looked around to see if enSight had a text format that was simple to read in, and couldn’t really find one - there seemed to be lots of file formats described in the manual I found.

If you have a sample file, or a website with a description of the format, I’m sure that someone could help you out.

Edit: I have looked at the enSight gold ASCII format (because I had no previous experience parsing text files with Julia, and just wanted to try it out). They don’t look too bad, and niether do the binary files. I’m sure that my attempt is mostly garbage - but I’d share it with you if you wanted.

Hello frylock!

Thank you for the answer! Yeah, I would be interested in your effort, since i have been trying similar things now, and maybe i can learn something from you!

EDIT: My format is indeed enSight gold ASCII!

This is a long way away from being something useful, but I was able to sort-of read in and print some of the enSight Gold ASCII files that were in the manual. I am very unfamiliar with the format … but

here goes nothing:
# ?? = I have no idea what I am supposed to do with this.

# descr
# descr
# ?? node id given
# ?? element id given
# extents ...

# blank line: *ignore*

# part record:
#     + part number ::Int64
#     + description ::String
#     + coordinate ids ::Int64 (one per line)
#     + x-coordinates ::Float64 (one per line)
#     + y-coordinates ::Float64 (one per line)
#     + z-coordinates ::Float64 (one per line)

# element record:
#     + name of element type ::String (? perhaps symbol or enum ?)
#     + number of elements ::Int64
#     + element ids ::Int64 (one per line)
#     + coordinate ids in element :: Vector{Int64} (one per line)

# part:
#     coordinates
#     element(seems rather to be element_list)
#         + number of these types of elements in the list
#         + ids of these elements (per line)
#         + node ids in the element (list per line)

# block iblanked ??


function read_enSightGold(f)
    println(readline(f)) # description
    println(readline(f)) # description
    println(readline(f)) # node id given ??
    println(readline(f)) # element id given ??
    
    println("data extents: $(read_extents(f))")
    println("part number: $(read_part_description(f))")
    println("part description: $(readline(f))")
    println("coordinates ids and locations: $(read_coordinates(f))")
    
end


function read_extents(f)
    readline(f) # extents label
    x_min, x_max = split(readline(f)) .|> x -> parse(Float64, x)
    y_min, y_max = split(readline(f)) .|> x -> parse(Float64, x)
    z_min, z_max = split(readline(f)) .|> x -> parse(Float64, x)
    x_min, x_max, y_min, y_max, z_min, z_max
end


function read_part_description(f)
    readline(f) # 'part'
    parse(Int64, readline(f))
end


function read_coordinates(f)
    function read_array!(b::Vector{T}, N) where {T}
        for ind in 1:N
            push!(b, parse(T, readline(f)))
        end

        nothing
    end

    readline(f) # 'coordinates'
    N = parse(Int64, readline(f))

    ids = Vector{Int64}()
    read_array!(ids, N)

    x_c = Vector{Float64}()
    read_array!(x_c, N)

    y_c = Vector{Float64}()
    read_array!(y_c, N)

    z_c = Vector{Float64}()
    read_array!(z_c, N)

    hcat(ids, x_c, y_c, z_c)
end


function main()
    f = open(ARGS[1])
    read_enSightGold(f)
    close(f)
end

main()