diff --git a/src/IO.jl b/src/IO.jl index d9aa3432..4b196d82 100644 --- a/src/IO.jl +++ b/src/IO.jl @@ -1,7 +1,7 @@ # This provides functions to load and save GeoData structs & friends to file using JLD2, Downloads -export save_GMG, load_GMG +export save_GMG, load_GMG, download_data """ save_GMG(filename::String, data::Union{GeoData, CartDat, UTMData}; dir=pwd()) @@ -71,3 +71,32 @@ function load_GMG(filename::String, dir=pwd()) return data end + + + + +""" + download_data(url::String, local_filename="temp.dat"; dir=pwd() ) + +Downloads a remote dataset with name `url` from a remote location and saves it to the current directory + +Example +==== +```julia +julia> url = "https://seafile.rlp.net/f/10f867e410bb4d95b3fe/?dl=1"; +julia> download_data(url) +"/Users/kausb/.julia/dev/GeophysicalModelGenerator/temp.dat" +``` + +""" +function download_data(url::String, local_filename="temp.dat"; dir=pwd() ) + + if !contains(url,"http") + @warn "the url does not contain http; please double check that it worked" + end + + # download remote file to a local temporary directory + file_ext = Downloads.download(url, joinpath(dir,local_filename)) + + return file_ext +end \ No newline at end of file diff --git a/test/test_IO.jl b/test/test_IO.jl index d760d9a2..a6688574 100644 --- a/test/test_IO.jl +++ b/test/test_IO.jl @@ -16,3 +16,10 @@ data_local = load_GMG(joinpath(pkg_dir,"test")) url = "https://seafile.rlp.net/f/10f867e410bb4d95b3fe/?dl=1" data_remote = load_GMG(url) @test data_remote.fields.MohoDepth[20] ≈ -17.99km + + +# loading remote data +url = "https://seafile.rlp.net/f/10f867e410bb4d95b3fe/?dl=1" +data_remote = download_data(url, "temp1.dat") +@test data_remote[end-8:end] == "temp1.dat" +