Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
yjf committed Apr 10, 2023
1 parent 92fe302 commit 1ba3233
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
53 changes: 50 additions & 3 deletions src/read/segy_read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ export segy_read
block = segy_read(file::String)
"""
function segy_read(file::AbstractString; buffer::Bool = true, warn_user::Bool = true)

println("read")
if buffer
s = IOBuffer(read(open(file)))
else
s = open(file)
end

read_file(s, warn_user)
seisblock=read_file(s, warn_user)
seisblock=Float32(seisblock)
end


"""
block = segy_read(file::String, keys::Array{String,1})
"""
Expand All @@ -25,5 +27,50 @@ function segy_read(file::AbstractString, keys::Array{String,1}; buffer::Bool = t
s = open(file)
end

read_file(s, keys, warn_user)
seisblock=read_file(s, keys, warn_user)
seisblock=Float32(seisblock)
end

"""
block = segy_read(file::String, indexs::Array{Int,1})
"""
function segy_read(file::AbstractString, indexs::Array{Int,1},ns::Integer;buffer::Bool = false, warn_user::Bool = true)

if buffer
s = IOBuffer(read(open(file))) #读数据道缓冲区,可以read
else
s = open(file)
end

ntraces = size(indexs,1)

# 寻找相应的道头index,通过index来寻找就行
#

seisblock=[]
for t in 1:ntraces
offset=(indexs[t]-1)*(ns*4+240) +3600 #寻找相应的字节数
# 寻找相应的道头index,通过index来寻找就行
trace_start=offset
trace_end=offset+(ns*4+240)
temseisblock=read_file(s, warn_user,start_byte=trace_start,end_byte=trace_end)
if t==1
seisblock=temseisblock
else
seisblock=merge([seisblock;temseisblock])
end
# write_trace(seekend(s), block, t)
end
close(s)
seisblock=Float32(seisblock)
return seisblock
end


function segy_read(file::AbstractString,indexs::AbstractRange,ns::Integer;buffer::Bool = false, warn_user::Bool = true)
segy_read(file, Array(indexs),ns,buffer, warn_user)
end

function segy_read(file::AbstractString,indexs::Integer,ns::Integer;buffer::Bool = false, warn_user::Bool = true)
segy_read(file,[indexs],ns,buffer, warn_user)
end
22 changes: 22 additions & 0 deletions src/types/Float32.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export Float32

"""
get_sources(con::SeisCon)
Returns an array of the source location coordinate pairs, NOT the minimum and maximum values.
Unlike `get_headers`, `get_sources` checks to make sure that SourceX and SourceY are consistant
throughout each block, that is `min == max`.
Column 1 of the returned array is SourceX, and Column 2 is SourceY.
# Example
sx = get_sources(s)
"""
function Float32(con::SeisBlock)
blocktraces11 = SeisBlock(Float32.(con.data)) #用float矩阵建立seisbloc floatk 格式
blocktraces11.fileheader = con.fileheader
blocktraces11.traceheaders = con.traceheaders
return blocktraces11
end
2 changes: 1 addition & 1 deletion src/write/check_fileheader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function check_fileheader(s::IO, fh_new::FileHeader)
# Check first section of assigned values

for field in fieldnames(typeof(fh.bfh))[1:end]
if(getfield(fh.bfh, field) != getfield(fh_new.bfh, field)) @error "The existing fileheaders are different from the new SeisBlock" end
if(getfield(fh.bfh, field) != getfield(fh_new.bfh, field)) @error "The existing fileheaders are different from the new SeisBlock,请检查这个文件头字段",field,"旧:",getfield(fh.bfh, field),"新:",getfield(fh_new.bfh, field) end
end

end
2 changes: 1 addition & 1 deletion src/write/segy_change.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function segy_change(file::String, block::SeisBlock,indexs::AbstractVector )
# 寻找相应的道头index,通过index来寻找就行
#

ll=int(ntraces/20)
ll=floor(ntraces/20)

for t in 1:ntraces
if ntraces<=10
Expand Down
1 change: 1 addition & 0 deletions src/yjfSegyIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module yjfSegyIO
include("types/SeisBlock.jl")
include("types/BlockScan.jl")
include("types/SeisCon.jl")
include("types/Float32.jl")

#Reader
include("read/read_fileheader.jl")
Expand Down

0 comments on commit 1ba3233

Please sign in to comment.