Skip to content

Commit

Permalink
fix array definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpjones76 committed Aug 13, 2018
1 parent 74af608 commit 9774222
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
26 changes: 13 additions & 13 deletions src/Formats/SEGY.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function trid(i::Int16; fs=2000.0::Float64)
return string(getbandcode(fs, fc=10.0), S[i])
end

function auto_coords(xy::Array{Int32,1}, c::Array{Int16,1})
function auto_coords(xy::Array{Int32, 1}, c::Array{Int16, 1})
xy == Int32[0,0] && return (0.0, 0.0)
lon = xy[1]
lat = xy[2]
Expand All @@ -31,20 +31,20 @@ function auto_coords(xy::Array{Int32,1}, c::Array{Int16,1})
return lat, lon
end

function do_trace(f::IO; full=false::Bool, passcal=false::Bool, fh=zeros(Int16,3)::Array{Int16,1}, src=""::String)
ftypes = Array{DataType,1}([UInt32, Int32, Int16, Any, Float32, Any, Any, Int8]) # Note: type 1 is IBM Float32
function do_trace(f::IO; full=false::Bool, passcal=false::Bool, fh=zeros(Int16, 3)::Array{Int16, 1}, src=""::String)
ftypes = Array{DataType, 1}([UInt32, Int32, Int16, Any, Float32, Any, Any, Int8]) # Note: type 1 is IBM Float32
shorts = Array{Int16, 1}(undef, 53)
ints = Array{Int32, 1}(undef, 19)

# First part of trace header is quite standard
ints[1:7] = read!(f, Array{Int32, 1}(undef, 7))
shorts[1:4] = read!(f, Array{Int16,1}(undef, 4))
ints[8:15] = read!(f, Array{Int32,1}(undef, 8))
shorts[5:6] = read!(f, Array{Int16,1}(undef, 2))
ints[16:19] = read!(f, Array{Int32,1}(undef, 4))
shorts[7:52]= read!(f, Array{Int16,1}(undef, 46))
shorts[1:4] = read!(f, Array{Int16, 1}(undef, 4))
ints[8:15] = read!(f, Array{Int32, 1}(undef, 8))
shorts[5:6] = read!(f, Array{Int16, 1}(undef, 2))
ints[16:19] = read!(f, Array{Int32, 1}(undef, 4))
shorts[7:52]= read!(f, Array{Int16, 1}(undef, 46))
if passcal
chars = read!(f, Array{UInt8,1}(undef, 20))
chars = read!(f, Array{UInt8, 1}(undef, 20))
dt = read(f, Int32)
fmt = read(f, Int16)
shorts[53] = read(f, Int16)
Expand Down Expand Up @@ -79,9 +79,9 @@ function do_trace(f::IO; full=false::Bool, passcal=false::Bool, fh=zeros(Int16,3
skip(f, 22)
trace_unit = bswap(read(f, Int16))
trans_mant = bswap(read(f, Int32))
shorts2 = [bswap(i) for i in read!(f, Array{Int16,1}(undef,5))]
shorts2 = [bswap(i) for i in read!(f, Array{Int16, 1}(undef, 5))]
skip(f, 22)
x = map(Float64, [bswap(i) for i in read!(f, Array{ftypes[fmt],1}(undef,n))])
x = map(Float64, [bswap(i) for i in read!(f, Array{ftypes[fmt], 1}(undef, n))])

# not sure about this; where did this formula come from...?
gain = Float64(trans_mant) * 10.0^(Float64(shorts2[1]+sum(shorts[23:24]))/10.0) # *2.0^shorts[47]
Expand Down Expand Up @@ -155,7 +155,7 @@ function readsegy(fname::String; passcal=false::Bool, full=false::Bool)
# My sample files have the Int16s in little endian order...?
fh = [bswap(i) for i in fh]
skip(f, 240)
fh[25:27] = read!(f, Array{Int16,1}(undef,3))
fh[25:27] = read!(f, Array{Int16, 1}(undef, 3))
skip(f, 94)

# Process file header
Expand All @@ -168,7 +168,7 @@ function readsegy(fname::String; passcal=false::Bool, full=false::Bool)
skip(f, 3200*nh)
else
fhd = Dict{String,Any}()
fhd["exthdr"] = [replace(join(read!(f, Array{Cchar,1 }(undef, 3200))), "\0" => " ") for i = 1:nh]
fhd["exthdr"] = [replace(join(read!(f, Array{Cchar, 1}(undef, 3200))), "\0" => " ") for i = 1:nh]
merge!(fhd, Dict{String,Any}(zip(["jobid", "lineid", "reelid", "ntr", "naux", "filedt", "origdt", "filenx",
"orignx", "fmt", "cdpfold", "trasort", "vsum", "swst", "swen0", "swlen", "swtyp", "tapnum", "swtapst", "swtapen",
"taptyp", "corrtra", "bgainrec", "amprec", "msys", "zupdn", "vibpol", "segyver", "isfixed", "ntxthdr"],
Expand Down
49 changes: 30 additions & 19 deletions src/Formats/Win32.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
using DelimitedFiles: readdlm
# =======================================================
# Auxiliary functions not for export

# stupid, but effective
function int4_2c(s::Array{Int32,1})
function int4_2c(s::Array{Int32, 1})
p = Int32[-8,4,2,1]
return dot(p, s[1:4]), dot(p, s[5:8])
end

function win32dict(Nh::UInt16, cinfo::String, hexID::String, StartTime::Float64, orgID::String, netID::String)
k = Dict{String,Any}("hexID" => hexID, "orgID" => orgID, "netID" => netID, "data" => Array{Int32,1}(),
"OldTime" => 0, "seisSum" => 0, "seisN" => 0, "seisNN" => 0, "startTime" => StartTime,
"locID" => @sprintf("%i%i", Meta.parse(orgID), Meta.parse(netID)), "gapStart" => Array{Int64,1}(0), "gapEnd" => Array{Int64,1}(0), "fs" => Float32(Nh))
D = Dict{String,Any}( "hexID" => hexID,
"orgID" => orgID,
"netID" => netID,
"data" => Array{Int32, 1}(undef, 0),
"OldTime" => 0,
"seisSum" => 0,
"seisN" => 0,
"seisNN" => 0,
"startTime" => StartTime,
"locID" => @sprintf("%i%i", Base.parse(Int64, orgID), Base.parse(Int64, netID)),
"gapStart" => Array{Int64, 1}(undef, 0),
"gapEnd" => Array{Int64, 1}(undef, 0),
"fs" => Float32(Nh) )

# Ensure my locID kluge doesn't produce garbage
Meta.parse(k["locID"]) > 99 && (@warn(string("For hexID = ", hexID, ", locID > 99; location ID unset.")); k["locID"] = "")
Meta.parse(D["locID"]) > 99 && (@warn(string("For hexID = ", hexID, ", locID > 99; location ID unset.")); D["locID"] = "")

# Get local (Japanese) network and subnet
nets = readdlm(string(Pkg.dir(),"/SeisIO/src/Formats/jpcodes.csv"), ';')
i = findall((nets[:,1].==orgID).*(nets[:,2].==netID))
k["netName"] = isempty(i) ? "Unknown" : nets[i[1],:]
D["netName"] = isempty(i) ? "Unknown" : nets[i[1],:]

# Entries from channel line
c = split(cinfo)
k["scale"] = Float64(Meta.parse(c[13]) / (Meta.parse(c[8]) * 10^(Meta.parse(c[12])/20)))
k["lineDelay"] = Float32(Meta.parse(c[3])/1000)
k["unit"] = String(c[9])
k["fc"] = Float32(1.0 / Meta.parse(c[10]))
k["hc"] = Float32(Meta.parse(c[11]))
k["loc"] = [Meta.parse(c[14]), Meta.parse(c[15]), Meta.parse(c[16])]
k["pCorr"] = Float32(Meta.parse(c[17]))
k["sCorr"] = Float32(Meta.parse(c[18]))
k["comment"] = length(c) > 18 ? String(c[19]) : ""
return k
D["scale"] = Float64(Meta.parse(c[13]) / (Meta.parse(c[8]) * 10.0^(Meta.parse(c[12])/20.0)))
D["lineDelay"] = Base.parse(Float32,c[3]) / 1000.0f0
D["unit"] = String(c[9])
D["fc"] = 1.0f0 / Base.parse(Float32, c[10])
D["hc"] = Base.parse(Float32, c[11])
D["loc"] = Float32[Base.parse(Float32, c[14]), Base.parse(Float32, c[15]), Base.parse(Float32, c[16])]
D["pCorr"] = Base.parse(Float32, c[17])
D["sCorr"] = Base.parse(Float32, c[18])
D["comment"] = length(c) > 18 ? String(c[19]) : ""
return D
end

function getcid(Chans::Array{String,1}, hexID::String)
function getcid(Chans::Array{String, 1}, hexID::String)
for i = 1:length(Chans)
L = split(Chans[i])
if L[1] == hexID
Expand Down Expand Up @@ -74,7 +85,7 @@ function readwin32(filestr::String, cf::String; v=0::Int)
c = string(bits(read(fid, UInt8)),bits(read(fid, UInt8)))
C = parse(UInt8, c[1:4], 2)
N = parse(UInt16, c[5:end], 2)
x = Array{Int32,1}(N)
x = Array{Int32, 1}(undef, N)
Nh = copy(N)

# Increment bytes read (this file), decrement N if not 4-bit
Expand Down Expand Up @@ -171,7 +182,7 @@ function readwin32(filestr::String, cf::String; v=0::Int)
if units == "m/s"
resp = map(Complex{Float64}, fctopz(seis[k]["fc"], hc=seis[k]["hc"], units=units))
else
resp = Array{Complex{Float64},2}(0,2)
resp = Array{Complex{Float64}, 2}(undef, 0, 2)
end

# There will be issues here. Japanese files use NIED or local station
Expand Down

0 comments on commit 9774222

Please sign in to comment.