Skip to content

Commit

Permalink
Fix auto_extension for short filenames (#3749)
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan authored Aug 30, 2024
1 parent bf04295 commit 3c95e7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/OutputWriters/output_writer_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ show_array_type(a::Type{Array{T}}) where T = "Array{$T}"
If `filename` ends in `ext`, return `filename`. Otherwise return `filename * ext`.
"""
function auto_extension(filename, ext)
Next = length(ext)
filename[end-Next+1:end] == ext || (filename *= ext)
return filename
if endswith(filename, ext)
return filename
else
return filename * ext
end
end
10 changes: 5 additions & 5 deletions test/test_jld2_output_writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function test_jld2_time_file_splitting(arch)
end
ow = JLD2OutputWriter(model, (; u=model.velocities.u);
dir = ".",
filename = "test.jld2",
filename = "test",
schedule = IterationInterval(1),
init = fake_bc_init,
including = [:grid],
Expand Down Expand Up @@ -214,7 +214,7 @@ for arch in archs
simulation.output_writers[:velocities] = JLD2OutputWriter(model, vanilla_outputs,
schedule = IterationInterval(1),
dir = ".",
filename = "vanilla_jld2_test.jld2",
filename = "vanilla_jld2_test",
indices = (:, :, :),
with_halos = false,
overwrite_existing = true)
Expand All @@ -224,7 +224,7 @@ for arch in archs
indices = (1:2, 1:4, :),
with_halos = false,
dir = ".",
filename = "sliced_jld2_test.jld2",
filename = "sliced_jld2_test",
overwrite_existing = true)

func_outputs = (u = model -> u, v = model -> v, w = model -> w)
Expand All @@ -234,7 +234,7 @@ for arch in archs
indices = (1:2, 1:4, :),
with_halos = false,
dir = ".",
filename = "sliced_funcs_jld2_test.jld2",
filename = "sliced_funcs_jld2_test",
overwrite_existing = true)


Expand All @@ -243,7 +243,7 @@ for arch in archs
indices = (1:2, 1:4, :),
with_halos = false,
dir = ".",
filename = "sliced_func_fields_jld2_test.jld2",
filename = "sliced_func_fields_jld2_test",
overwrite_existing = true)


Expand Down

0 comments on commit 3c95e7e

Please sign in to comment.