Skip to content

Commit

Permalink
fix issue writing to file not in folder
Browse files Browse the repository at this point in the history
  • Loading branch information
archermarx committed Sep 14, 2021
1 parent be1adc9 commit 383d0dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LoopFieldCalc"
uuid = "896acac2-5fe1-47fe-8ead-27e3a9bc5c85"
authors = ["Thomas Marks <[email protected]> and contributors"]
version = "0.2.3"
version = "0.2.4"

[deps]
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
Expand Down
10 changes: 8 additions & 2 deletions src/LoopFieldCalc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ end
Write magnetic field to Tecplot ASCII datafile for two-dimensional data
"""
function write_field(filename, xs, ys, Bx, By)
mkpath(joinpath(splitpath(filename)[1:end-1]...))
split_fname = splitpath(filename)
if length(split_fname) > 1 # If file is in folder, make sure that folder exists
mkpath(joinpath(split_fname[1:end-1]...))
end
Nx, Ny= length(xs), length(ys)
open(filename, "w") do f
println(f, "VARIABLES = \"X\" \"Y\" \"Bx\" \"By\"")
Expand All @@ -129,7 +132,10 @@ end
Write magnetic field to Tecplot ASCII datafile for three-dimensional data
"""
function write_field(filename, xs, ys, zs, Bx, By, Bz)
mkpath(joinpath(splitpath(filename)[1:end-1]...))
split_fname = splitpath(filename)
if length(split_fname) > 1 # If file is in folder, make sure that folder exists
mkpath(joinpath(split_fname[1:end-1]...))
end
Nx, Ny, Nz = length(xs), length(ys), length(zs)
open(filename, "w") do f
println(f, "VARIABLES = \"X\" \"Y\" \"Z\" \"Bx\" \"By\" \"Bz\"")
Expand Down

0 comments on commit 383d0dd

Please sign in to comment.