Skip to content

Commit

Permalink
The convert_to_point_vs30 was added
Browse files Browse the repository at this point in the history
  • Loading branch information
jamm1985 committed Mar 22, 2018
1 parent c0e89b5 commit a9888f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GroundMotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module GroundMotion
Params_mf2013,
# functions
read_vs30_file,
convert_to_point_vs30,
read_vs30_dl_file,
convert_to_float_array,
gmpe_as2008,
Expand Down
14 changes: 14 additions & 0 deletions src/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ function read_vs30_file(filename::String)
end
return B
end
## convert Array{Float64,2} array to Array{GroundMotion.Point_vs30,1}
"""
convert_to_float_array(B::Array{T,N})
where T is Point_{pga,pgv,pgd}_out, Point_vs30
Convert 1-d array of custom type to Array{Float64}(N,X)
"""
function convert_to_point_vs30(A::Array{Float64,2})
vs30_row_num = length(A[:,1])
B = Array{Point_vs30}(0)
for i=1:vs30_row_num
B = push!(B,Point_vs30(A[i,1],A[i,2],A[i,3]))
end
return B
end
## read VS30 file with Dl column
function read_vs30_dl_file(filename::String)
A = readdlm(filename)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ WITH_MINPGA = 8
SIMULATION_ARRAY_SIZE = 1000
# load vs30 grid
grid = read_vs30_file("testvs30.txt")
raw_grid = readdlm("testvs30.txt")
grid_dl = read_vs30_dl_file("testvs30dl.txt")
grid_epicenter = [Point_vs30(143.04,51.92,350)]
# set earthquake location
Expand Down
3 changes: 3 additions & 0 deletions test/test_auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
include("../examples/as2008.conf")
pga_grid = gmpe_as2008(eq_6,config_as2008_pga,grid)
@test typeof(pga_grid) == Array{GroundMotion.Point_pga_out,1}
# convert to Point_vs30
A = convert_to_point_vs30(raw_grid)
@test length(A) == 17
# convert to float array
A = convert_to_float_array(grid)
@test typeof(A) == Array{Float64,2}
Expand Down

0 comments on commit a9888f8

Please sign in to comment.