Skip to content

Commit

Permalink
Merge pull request #13 from slimgroup/misc-bugs
Browse files Browse the repository at this point in the history
Fix undef access
  • Loading branch information
mloubout committed Jun 7, 2023
2 parents 9fa1dfd + 81fa020 commit 274afd0
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SegyIO"
uuid = "157a0f19-4d44-4de5-a0d0-07e2f0ac4dfa"
authors = ["Henryk Modzelewski <henryk_modzelewski@mac.com>"]
version = "0.8.2"
version = "0.8.3"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
2 changes: 1 addition & 1 deletion src/read/extract_con_headers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function extractor(con, keys, block)
headers = read_con_headers(con, copy(keys), block, prealloc_traces = 10000000)
ntraces = length(headers)
nkeys = length(keys)
header_array = Array{Int32,2}(undef, ntraces, nkeys)
header_array = Array{Int32, 2}(undef, ntraces, nkeys)

for cur_key in 1:nkeys
header_array[:,cur_key] = get_header(headers, Symbol(keys[cur_key]), scale=false)
Expand Down
6 changes: 4 additions & 2 deletions src/read/read_block_headers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ function read_block_headers!(b::BlockScan, keys::Array{String, 1}, ns::Int, dsf:
s = IOBuffer(read(f, brange))
ntraces = Int((brange)/(240 + ns*4))
fh = FileHeader()
fh.bfh.ns = ns; fh.bfh.DataSampleFormat = dsf
fh.bfh.ns = ns
fh.bfh.DataSampleFormat = dsf

# Check dsf
datatype = Float32
Expand All @@ -19,9 +20,10 @@ function read_block_headers!(b::BlockScan, keys::Array{String, 1}, ns::Int, dsf:
end

th_b2s = th_byte2sample()
tmph = zeros(UInt8, 240)
# Read each traceheader
for trace in 1:ntraces
read_traceheader!(s, keys, th_b2s, headers[trace])
read_traceheader!(s, keys, th_b2s, headers[trace]; th=tmph)
skip(s, ns*4)
end

Expand Down
11 changes: 6 additions & 5 deletions src/read/read_con.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function read_con(con::SeisCon, blocks::Array{Int,1};

# Pre-allocate
data = Array{datatype,2}(undef, con.ns, prealloc_traces)
headers = [BinaryTraceHeader() for _=1:prealloc_traces]
fh = FileHeader(); set_fileheader!(fh.bfh, :ns, con.ns)
headers = zeros(BinaryTraceHeader, prealloc_traces)
fh = FileHeader()
set_fileheader!(fh.bfh, :ns, con.ns)
set_fileheader!(fh.bfh, :DataSampleFormat, con.dsf)

trace_count = 0
Expand All @@ -42,7 +43,7 @@ function read_con(con::SeisCon, blocks::Array{Int,1};
println("Expanding preallocated memory")
prealloc_traces *= 2
data = hcat(data, Array{datatype,2}(undef, con.ns, ntraces+prealloc_traces))
append!(headers, Array{BinaryTraceHeader,1}(undef, ntraces+prealloc_traces))
append!(headers, zeros(BinaryTraceHeader, ntraces+prealloc_traces))
end
tmp_data = view(data, :,(trace_count+1):(trace_count+ntraces))
tmp_headers = view(headers, (trace_count+1):(trace_count+ntraces))
Expand Down Expand Up @@ -73,7 +74,7 @@ function read_con(con::SeisCon, keys::Array{String,1}, blocks::Array{Int,1};

# Pre-allocate
data = Array{datatype,2}(undef, con.ns, prealloc_traces)
headers = [BinaryTraceHeader() for _=1:prealloc_traces]
headers = zeros(BinaryTraceHeader, prealloc_traces)
fh = FileHeader(); set_fileheader!(fh.bfh, :ns, con.ns)
set_fileheader!(fh.bfh, :DataSampleFormat, con.dsf)

Expand All @@ -90,7 +91,7 @@ function read_con(con::SeisCon, keys::Array{String,1}, blocks::Array{Int,1};
if ~isroom
println("Expanding preallocated memory")
data = hcat(data, Array{datatype,2}(undef, con.ns, ntraces+prealloc_traces))
append!(headers, Array{BinaryTraceHeader,1}(undef, ntraces+prealloc_traces))
append!(headers, zeros(BinaryTraceHeader, ntraces+prealloc_traces))
prealloc_traces *= 2
end
tmp_data = view(data, :,(trace_count+1):(trace_count+ntraces))
Expand Down
8 changes: 5 additions & 3 deletions src/read/read_con_headers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function read_con_headers(con::SeisCon, keys::Array{String,1}, blocks::Array{Int
in("ElevationScalar", keys) ? nothing : push!(keys, "ElevationScalar")

# Pre-allocate
headers = Array{BinaryTraceHeader,1}(undef, prealloc_traces)
fh = FileHeader(); set_fileheader!(fh.bfh, :ns, con.ns)
headers = zeros(BinaryTraceHeader, prealloc_traces)
fh = FileHeader()
set_fileheader!(fh.bfh, :ns, con.ns)
set_fileheader!(fh.bfh, :DataSampleFormat, con.dsf)

# Read all blocks
Expand All @@ -45,7 +46,8 @@ function read_con_headers(con::SeisCon, keys::Array{String,1}, blocks::Array{Int
println("Expanding preallocated memory")
prealloc_traces *= 2
prealloc_traces += ntraces
append!(headers, Array{BinaryTraceHeader,1}(undef, ntraces+prealloc_traces))
prealloc_headers = zeros(BinaryTraceHeader, ntraces+prealloc_traces)
append!(headers, prealloc_headers)
end
tmp_headers = view(headers, (trace_count+1):(trace_count+ntraces))

Expand Down
2 changes: 1 addition & 1 deletion src/read/read_file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function read_file(s::IO, keys::Array{String, 1}, warn_user::Bool;
ntraces = Int((end_byte - start_byte)/trace_size)

# Preallocate memory
headers = [BinaryTraceHeader() for _ = 1:ntraces]
headers = zeros(BinaryTraceHeader, ntraces)
data = Array{datatype, 2}(undef, fh.bfh.ns, ntraces)
th_b2s = th_byte2sample()

Expand Down
2 changes: 1 addition & 1 deletion src/scan/scan_block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function scan_block(buf::IO, mem_block::Int, mem_trace::Int, keys::Array{String,
# Calc info about this block
startbyte = position(buf) + chunk_start
ntraces_block = Int(mem_block/mem_trace)
headers = [BinaryTraceHeader() for _ = 1:ntraces_block]
headers = zeros(BinaryTraceHeader, ntraces_block)
count = 0

# Read all headers and record end byte
Expand Down
3 changes: 2 additions & 1 deletion src/scan/scan_shots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function scan_shots!(s::IO, mem_chunk::Int, mem_trace::Int,
eof(s) ? (fl_eof=true) : nothing
buf_size = position(seekend(buf)); seekstart(buf)
ntraces = Int(floor(buf_size/mem_trace))
headers = [BinaryTraceHeader() for _ = 1:ntraces]
headers = zeros(BinaryTraceHeader, ntraces)

# Get headers from chunk
th = zeros(UInt8, 240)
Expand All @@ -31,6 +31,7 @@ function scan_shots!(s::IO, mem_chunk::Int, mem_trace::Int,
#combo = [[view(sx,i) view(sy,i)] for i in 1:ntraces]
combo = [[sx[i] sy[i]] for i in 1:ntraces]
part = delim_vector(combo, 1)

fl_eof ? push!(part, length(combo) + 1) : push!(part, ntraces + 1)

# Summarise each shot
Expand Down
2 changes: 2 additions & 0 deletions src/types/BinaryTraceHeader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ function BinaryTraceHeader()
0,0,0,0,0,0,0,0,0,0,0)
end

Base.zeros(::Type{BinaryTraceHeader}, n::Integer) = [BinaryTraceHeader() for _=1:n]

function show(io::IO, bth::BinaryTraceHeader)

println("BinaryTraceHeader:")
Expand Down
2 changes: 1 addition & 1 deletion src/types/SeisBlock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function SeisBlock(data::Matrix{DT}) where {DT<:Union{Float32, IBMFloat32}}
DT==Float32 ? fh.bfh.DataSampleFormat=5 : fh.bfh.DataSampleFormat=1

# Construct TraceHeaders
traceheaders = [BinaryTraceHeader() for i in 1:ntraces]
traceheaders = zeros(BinaryTraceHeader, ntraces)
set_traceheader!(traceheaders, :ns, ns*ones(Int16, ntraces))

# Construct Block
Expand Down

0 comments on commit 274afd0

Please sign in to comment.