Skip to content

Commit

Permalink
Fix and tests for issues #87, #88
Browse files Browse the repository at this point in the history
  • Loading branch information
jpjones76 committed Jan 7, 2022
1 parent 52e4330 commit 5e57f21
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/CoreUtils/IO/read_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ is_u8_digit(u::UInt8) = u > 0x2f && u < 0x3a
# id = targ vector
# cv = char vector
# i = starting index in cv
# imax = max index in cv
# i_max = max index in cv
# j = starting index in id
# jmax = max index in id
# j_max = max index in id
function fill_id!(id::Array{UInt8,1}, cv::Array{UInt8,1}, i::T, i_max::T, j::T, j_max::T) where T<:Integer
o = one(T)
while true
c = getindex(cv, i)
i = i+o
c < 0x2f && continue
setindex!(id, c, j)
j = j+o
(i > i_max || j > jmax) && break
if c > 0x2e
setindex!(id, c, j)
j = j+o
end
(i > i_max || j > j_max) && break
end
if j_max < T(15)
id[j_max+1] = 0x2e
Expand Down
35 changes: 35 additions & 0 deletions test/DataFormats/test_sac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,38 @@ C = read_data("sac", sacv7_out, full=true)[1]
@test C.fs == test_fs
@test C.loc.lat == test_lat
@test C.loc.lon == test_lon

printstyled(" Issues #87, #88\n", color=:light_green)
ts = round(Int64, sμ*d2u(DateTime("2020-03-01T00:00:00")))
fs = 100.0
gain = 32.0
id = "XX.STA..BHZ"
loc = GeoLoc( lat = 45.560121, lon = -122.617068, el = 53.04 )
fname = "test.sac"
C = SeisChannel(id = id,
gain = gain,
loc = loc,
fs = fs,
t = [1 ts; 1024 0],
x = randn(Float32, 1024)
)
writesac(C, fname=fname)
S = SeisData()
# Read with characters at start of each string
read_data!(S, "sac", fname)

# Move characters to end of each string
tmp_sac_buf = read(fname)
charbuf = tmp_sac_buf[441:632]
charbuf[1:3] .= 0x20
charbuf[6:8] .= [0x53, 0x54, 0x41] # "STA"
charbuf[161:163] .= 0x20
charbuf[166:168] .= [0x42, 0x48, 0x5a] # BHZ
charbuf[169:170] .= 0x20
charbuf[175:176] .= 0x58
tmp_sac_buf[441:632] .= charbuf
io = open("fname", "w")
write(io, tmp_sac_buf)
close(io)
S2 = read_data("sac", fname)
@test S.id[1] == S2.id[1]

0 comments on commit 5e57f21

Please sign in to comment.