-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscan_shots.jl
60 lines (49 loc) · 1.8 KB
/
scan_shots.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
export scan_shots
function scan_shots!(s::IO, mem_chunk::Int, mem_trace::Int,
keys::Array{String,1}, file::AbstractString, scan::Array{BlockScan,1}, fl_eof::Bool)
f = open(file)
swap_bytes = bswap_needed(f)
close(f)
# Load chunk into memory
chunk_start = position(s)
buf = IOBuffer(read(s, mem_chunk))
eof(s) ? (fl_eof=true) : nothing
buf_size = position(seekend(buf)); seekstart(buf)
ntraces = Int(floor(buf_size/mem_trace))
headers = zeros(BinaryTraceHeader, ntraces)
# Get headers from chunk
th = zeros(UInt8, 240)
for i in 1:ntraces
read_traceheader!(buf, keys, SegyIO.th_b2s, headers[i]; swap_bytes=swap_bytes, th=th)
skip(buf, mem_trace-240)
end
# Get all requested header vectors
vals = Dict{String, Array{Int32,1}}()
for k in keys
tmp = Int32.([getfield((headers[i]), Symbol(k)) for i in 1:ntraces])
vals["$k"] = tmp
end # k
# Deliminate to find shots
sx = vals["SourceX"]
sy = vals["SourceY"]
#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
for shot in 1:length(part)-1
start_trace = part[shot]
end_trace = part[shot + 1]-1
start_byte = mem_trace*(start_trace-1) + chunk_start
end_byte = mem_trace*(end_trace) + chunk_start
summary = Dict{String, Array{Int32,1}}()
for k in keys
tmp = vals[k][start_trace:end_trace]
summary["$k"] = [minimum(tmp); maximum(tmp)]
end
push!(scan, BlockScan(file, start_byte, end_byte, summary))
end
seek(s, scan[end].endbyte)
close(buf)
nothing
end