From 0d6c590061be74106f7075dbef36cca32a27920e Mon Sep 17 00:00:00 2001 From: Mo8it Date: Mon, 24 Jan 2022 21:27:43 +0100 Subject: [PATCH] Better bundle paths --- src/data.jl | 20 ++++++++++---------- src/run.jl | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/data.jl b/src/data.jl index ff13118..20a1156 100644 --- a/src/data.jl +++ b/src/data.jl @@ -76,7 +76,7 @@ function save_bundle(dir::String, bundle::Bundle, n_bundle::Int64, T::Float64) bundles_dir = "$dir/bundles" mkpath(bundles_dir) - JLD2.save_object("$bundles_dir/bundle_$n_bundle.jld2", bundle) + JLD2.save_object("$bundles_dir/$n_bundle.jld2", bundle) JLD2.save_object("$dir/sim_state.jld2", SimState(n_bundle, round(T; digits=3))) @@ -84,18 +84,18 @@ function save_bundle(dir::String, bundle::Bundle, n_bundle::Int64, T::Float64) end function sorted_bundle_paths(dir::String; rev::Bool=false) - bundle_paths = readdir("$dir/bundles"; join=true, sort=false) + bundles_dir = "$dir/bundles" + bundle_paths = readdir(bundles_dir; join=true, sort=false) n_bundles = length(bundle_paths) bundle_nums = Vector{Int64}(undef, n_bundles) - extension_length = 5 # == length(".jld2") - - for i in 1:n_bundles - bundle_path = bundle_paths[i] - bundle_num_string = bundle_path[(findfirst("bundle_", bundle_path).stop + 1):(end - extension_length)] - bundle_nums[i] = parse(Int64, bundle_num_string) + @simd for bundle_ind in 1:n_bundles + bundle_path = bundle_paths[bundle_ind] + bundle_name = splitdir(bundle_path)[2] + bundle_num_string = splitext(bundle_name)[1] + bundle_nums[bundle_ind] = parse(Int64, bundle_num_string) end sort_perm = sortperm(bundle_nums; rev=rev) @@ -113,8 +113,8 @@ function append_bundle_properties!( ) where {N} bundle_paths = ReCo.sorted_bundle_paths(sim_dir) - for i in first_bundle:length(bundle_paths) - bundle::ReCo.Bundle = JLD2.load_object(bundle_paths[i]) + for bundle_ind in first_bundle:length(bundle_paths) + bundle::ReCo.Bundle = JLD2.load_object(bundle_paths[bundle_ind]) for (v_ind, v) in enumerat(vs) property = properties[v_ind] diff --git a/src/run.jl b/src/run.jl index 683f1ca..1458847 100644 --- a/src/run.jl +++ b/src/run.jl @@ -74,7 +74,7 @@ function run_sim( end bundles_dir = "$dir/bundles" - bundle::Bundle = JLD2.load_object("$bundles_dir/bundle_$n_bundles.jld2") + bundle::Bundle = JLD2.load_object("$bundles_dir/$n_bundles.jld2") particles = gen_particles(bundle, sim_consts.n_particles)