!WTvnrBXAWIqKuxyqrR:matrix.org

Julia (lang)

307 Members
General help and discussion about the Julia language35 Servers

You have reached the beginning of time (for this room).


SenderMessageTime
26 Jun 2022
@mosullivan93:matrix.orgmosullivan93 read("\0") 16:11:02
@mosullivan93:matrix.orgmosullivan93Will also throw the same error16:11:10
@1awtumleef:matrix.orgacxzyep, the binary file includes NULs which read can't handle16:11:47
@1awtumleef:matrix.orgacxz
In reply to @mosullivan93:matrix.org
The problem seems to be that after you detect you're on the line starting with "(..." you then try to pass in the vector itself to the read function
I believe I'm passing in the String at that point.
16:12:29
@mosullivan93:matrix.orgmosullivan93Yes, that's what I mean, your intention seems to be to simply store these bytes though, so you don't need to pass it back through readagain16:13:34
@mosullivan93:matrix.orgmosullivan93 * Yes, that's what I mean, your intention seems to be to simply store these bytes though, so you don't need to pass it back through read again16:13:40
@1awtumleef:matrix.orgacxzIn the end I'd like a Vector{Int32} from these bytes. So I guess instead of going from bytes to string to vector, i should go from bytes to vector?16:15:31
@mosullivan93:matrix.orgmosullivan93 You can convert the string like so Vector{Int32}(Vector{UInt8}(line[2:end])), I can't seem to find a more succinct way 16:24:36
@mosullivan93:matrix.orgmosullivan93But, the code doesn't detect the ")" at the moment and throws an error later on anyway16:24:50
@mosullivan93:matrix.orgmosullivan93I have to go to bed for now, but hopefully that helps. You could use readline until the "(", and presumably some of the information in the header tells you how many bytes will follow.16:28:17
@1awtumleef:matrix.orgacxzthanks so much for your help!!! Really appreciate the time, enjoy ur sleep! 💤16:28:59
@mosullivan93:matrix.orgmosullivan93Actually, another thing just came to mind, if you mean to internet four consecutive bytes as being part of an Int32, then the sample code I have doesn’t do that. Also since you’re in the binary region of the file, be careful your code isn’t gobbling up any control characters (i.e. '\r' or '\n'). I think you should refactor the code if you can learn more about the structure of the file, because it seems rather convoluted at the moment and can probably be simplified if you make assumptions about the structure.17:11:12
@mosullivan93:matrix.orgmosullivan93 * (null) 17:11:24
@mosullivan93:matrix.orgmosullivan93 * (null) 17:11:37
@mosullivan93:matrix.orgmosullivan93 * (null) 17:11:57
27 Jun 2022
@1awtumleef:matrix.orgacxz

thx for the tips I finally was able to parse my file!
The big things were the casting of Vector{UInt8} and the function reinterpret

Here is the finally snippet I ended up with:

function read_bt_paran(file)
    fh = open(file)

    paran_start = false
    paran_end = false
    paran_end_maybe = false
    bt_paran_str = ""
    num_cells = 0
    format_str = ""

    while !eof(fh)
        line = readline(fh, keep=true)
        if occursin("format", line)
            split_line = split(line)
            format_str = split(split_line[2], ";")[1]
        end
        if occursin("nCells", line)
            split_line = split(line)
            num_cells_str = split(split_line[3], ":")[2]
            num_cells = parse(Int32, num_cells_str)
        end
        if occursin(")\n", line)
            if format_str == "ascii"
                paran_end = true
            end
            paran_end_maybe = true
        end
        if line == "\n" && !paran_end && paran_end_maybe
            paran_end = true
            bt_paran_str = bt_paran_str[1:end-2]
        end
        if paran_start && !paran_end
            bt_paran_str = bt_paran_str * line
        end
        if occursin("(", line) && !paran_start
            paran_start = true
            if format_str == "binary"
                bt_paran_str = bt_paran_str * line[2:end]
            end
        end
    end

    close(fh)

    bt_paran_vec = Vector{Int32}()
    if format_str == "ascii"
        bt_paran_vec = parse.(Int32, split(bt_paran_str))
    end
    if format_str == "binary"
        bt_paran_uint8_vec = Vector{UInt8}(bt_paran_str)
        bt_paran_vec = reinterpret(Int32, bt_paran_uint8_vec)
    end

    bt_paran_vec = bt_paran_vec .+ 1

    return bt_paran_vec, num_cells
end

Def one of the weirdest files I've had to parse haha

03:36:55
@1awtumleef:matrix.orgacxzThe use case for this is to visualize the mesh matrix from openfoam. The final script now at https://github.com/acxz/openfoam-mesh-matrix reproduces the plots shown on the following blog: https://blog.pointwise.com/2020/08/26/its-all-in-the-numbering-mesh-renumbering-may-improve-simulation-speed/03:50:38
@mosullivan93:matrix.orgmosullivan93 I see from the file spec that there's quite a few types of structures that could appear in the output of OpenFOAM, but it looks like it's working on the sample files you provided. 03:51:27
@1awtumleef:matrix.orgacxz Yeah I'm only going to be parsing the polyMesh/neighbour and polyMesh/owner files, which my script seems to be working and displaying the plots properly. 03:53:06
@1awtumleef:matrix.orgacxz * Yeah I'm only going to be parsing the polyMesh/neighbour and polyMesh/owner files, which my script seems to be working on and displaying the plots properly. 03:53:15
@mosullivan93:matrix.orgmosullivan93Sounds good, glad you got it working03:53:21
@andrewellis:matrix.organdrewellis changed their profile picture.10:07:16
@neoabs:matrix.orgneoabs joined the room.12:49:07
@chepyrka:nitro.chat@chepyrka:nitro.chat🔵 Welcome to the new Julia space! 🔴🟢🟣 https://matrix.to/#/#julia:nitro.chat13:36:53
@neoabs:matrix.orgneoabsit consolidates all spaces. Maybe we can jumpstart julia on matrix this time13:46:10
@neoabs:matrix.orgneoabsIt would be nice to have some functional community on matrix13:46:22
28 Jun 2022
@mosullivan93:matrix.orgmosullivan93 changed their profile picture.00:41:25
29 Jun 2022
@johnyr:matrix.orgJohny R joined the room.01:49:43
@vbgl:matrix.orgVincent Laporte joined the room.06:51:55

Show newer messages


Back to Room ListRoom Version: