Skip to content

Commit

Permalink
Revised logic to find column offsets, enables reading more files
Browse files Browse the repository at this point in the history
  • Loading branch information
jaakkor2 committed Jan 21, 2024
1 parent 5e5a2c7 commit f2ff299
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JMPReader"
uuid = "d9f7e686-cf87-4d12-8d7a-0e9b8c9fba29"
authors = ["Jaakko Ruohio <jaakkor2@gmail.com>"]
version = "0.1.3"
version = "0.1.4"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
16 changes: 12 additions & 4 deletions src/metadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ function metadata(a)
colidxlist == 0:ncols-1 || @warn("`offset_colinfo`-variable probably has a wrong value")

colformatting = _read_reals!(a, offset, UInt16, ncols) # ??
_read_reals!(a, offset, UInt32, 7) # ??

colnames, coloffsets = column_info(a, offset, ncols)

colnames, coloffsets = column_info(a, offset[1], ncols)

Info(buildstring, savetime, nrows, ncols, Column(colnames, colformatting, coloffsets))
end

Expand All @@ -30,8 +31,15 @@ end
Return column names and offsets to column data.
"""
function column_info(data, offset, ncols)
hacky_offset = data[offset + 31] + 42 # TODO needs improvement
coloffsets = reinterpret(Int64, data[offset + hacky_offset .+ (1:8*ncols)])
if _read_reals!(data, offset, UInt8, 2) == [0xfd, 0xff] # ?? hacky
n = _read_real!(data, offset, Int64)
_read_reals!(data, offset, UInt8, n) # ??
else
offset .-= 2 # [0xfd, 0xff] was not found, go back
end
ncols2 = _read_real!(data, offset, Int32)
ncols == ncols2 || throw(ErrorException("Number of columns read from two locations do not match. Likely a problem in `column_info`-function."))
coloffsets = _read_reals!(data, offset, Int64, ncols)
colnames = String[]
for i in coloffsets
push!(colnames, _read_string!(data, [i], 2))
Expand Down

0 comments on commit f2ff299

Please sign in to comment.