Skip to content

Commit a12fcf7

Browse files
committed
check conversion to km
1 parent e1e139c commit a12fcf7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/IO_ASAGI.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,31 @@ using NCDatasets: nc_create, NC_NETCDF4, NC_CLOBBER, NC_NOWRITE, nc_def_dim, nc_
1111
export write_ASAGI, read_ASAGI
1212

1313
"""
14-
write_ASAGI(fname::String, Data::CartData,
15-
selected_fields::Union{nothing, Tuple}=nothing;
16-
km_to_m = false)
14+
write_ASAGI(fname::String, Data::CartData;
15+
fields::Union{Nothing, Tuple}=nothing,
16+
km_to_m::Bool=false)
1717
1818
Writes a CartData structure `Data` to an ASAGI file, which can be read by SeisSol or ExaHype.
1919
You can optionally pass a tuple with fields to be written. Note that we can only write individual (scalar) fields to disk,
2020
so vector or tensor fields needs to be split first
2121
"""
22-
function write_ASAGI(fname::String, Data::CartData,
23-
selected_fields::Union{Nothing, Tuple}=nothing;
24-
km_to_m=false)
22+
function write_ASAGI(fname::String, Data::CartData;
23+
fields::Union{Nothing, Tuple}=nothing,
24+
km_to_m::Bool=false)
2525

2626
nx,ny,nz = size(Data.x)
2727
x = Data.x.val[:,1,1]
2828
y = Data.y.val[1,:,1]
2929
z = Data.z.val[1,1,:]
30-
if km_to_m
30+
if km_to_m==true
31+
println("convert to meters")
3132
x = x.*1000
3233
y = y.*1000
3334
z = z.*1000
3435
end
3536

3637
# Transfer data to a single array with NamedTuple entries
37-
material = fields_to_namedtuple(Data.fields, selected_fields)
38+
material = fields_to_namedtuple(Data.fields, fields)
3839

3940
fname_asagi = fname*"_ASAGI.nc"
4041

test/test_ASAGI_IO.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ Data_SeisSol = read_ASAGI("test_files/tpv34_rhomulambda-inner.nc")
2323
@test eltype(Data_SeisSol.fields.rho[10]) == Float32
2424

2525
# test that specifying specific field works
26-
fname_asagi = write_ASAGI("test", Data, (:Sxx,))
26+
fname_asagi = write_ASAGI("test", Data, fields=(:Sxx,))
2727
Data_ASAGI2 = read_ASAGI(fname_asagi)
2828
@test sum(Data_ASAGI2.fields.Sxx - Data.fields.Sxx) == 0
2929

30+
# test that converting to meters works
31+
fname_asagi = write_ASAGI("test3", Data, fields=(:Sxx,), km_to_m=true)
32+
Data_ASAGI3 = read_ASAGI(fname_asagi)
33+
@test Data_ASAGI3.x.val[1] 1000.0
34+
3035
# test that it errors if we use a tuple with non-scalar fields
3136
@test_throws "Field Stress is not an Array but instead a NTuple{9, Array{Float64, 3}}; only Arrays are supported" write_ASAGI("test", Data_tuple)
3237

0 commit comments

Comments
 (0)