# enSight files with Julia

**URL:** <https://discourse.julialang.org/t/ensight-files-with-julia/99371>\
**Category:** General Usage\
**Tags:** data\
**Created:** [May 25, 2023, 10:28am UTC](https://discourse.julialang.org/t/ensight-files-with-julia/99371 "2023-05-25T10:28:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomaskroi1996](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomaskroi1996/32/49392_2.png) [@thomaskroi1996](https://discourse.julialang.org/u/thomaskroi1996)\
**Post date:** [May 25, 2023, 10:28am UTC](https://discourse.julialang.org/t/ensight-files-with-julia/99371/1 "2023-05-25T10:28:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [May 25, 2023, 1:09pm UTC](https://discourse.julialang.org/t/ensight-files-with-julia/99371/2 "2023-05-25T13:09:51Z")

</div>

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](https://dav.lbl.gov/archive/NERSC/Software/ensight/doc/Manuals/UserManual.pdf).

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.

---

<div class="post-metadata">

**Author:** ![thomaskroi1996](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomaskroi1996/32/49392_2.png) [@thomaskroi1996](https://discourse.julialang.org/u/thomaskroi1996)\
**Post date:** [May 29, 2023, 3:49pm UTC](https://discourse.julialang.org/t/ensight-files-with-julia/99371/3 "2023-05-29T15:49:26Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [May 30, 2023, 11:57am UTC](https://discourse.julialang.org/t/ensight-files-with-julia/99371/4 "2023-05-30T11:57:43Z")

</div>

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:**
>
> ```julia
> # ?? = 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()
> 
> ```
