diff --git a/src/CoordVisualize.jl b/src/CoordVisualize.jl index 73ecc03..e0a8927 100644 --- a/src/CoordVisualize.jl +++ b/src/CoordVisualize.jl @@ -4,5 +4,6 @@ using Dates include("typedef.jl") include("parser.jl") +include("edit.jl") -end # end module CoordVisualize +end # module CoordVisualize diff --git a/src/edit.jl b/src/edit.jl new file mode 100644 index 0000000..a9ac869 --- /dev/null +++ b/src/edit.jl @@ -0,0 +1,26 @@ +""" + split_log(log::CoordLog, at::Unsigned, notes_1::AbstractString, notes_2::AbstractString)::Vector{CoordLog} + +Split `log` at `at`, i.e. to `1:at` and `at:end` then assign `notes_1` and `notes_2` to notes for each other. +""" +function split_log(log::CoordLog, at::Unsigned, notes_1::AbstractString, notes_2::AbstractString)::Vector{CoordLog} + @assert at < size(log.coords)[1] "Split index must be less than original log length($(size(log.coords)[1]))" + [ + CoordLog(log.coords[1:at, :], log.logdate, notes_1), + CoordLog(log.coords[at:end, :], log.logdate, notes_2), + ] +end + +function split_log(log::CoordLog, at::Integer, notes_1::AbstractString, notes_2::AbstractString)::Vector{CoordLog} + split_log(log, UInt(at), notes_1, notes_2) +end + + +""" + assign_note!(log::CoordLog, new_note::AbstractString) + +Replace `note` in `log` with `new_note`. +""" +function assign_note!(log::CoordLog, new_note::AbstractString) + log.note = new_note +end diff --git a/src/typedef.jl b/src/typedef.jl index b8ea29f..7f722ba 100644 --- a/src/typedef.jl +++ b/src/typedef.jl @@ -1,7 +1,15 @@ using Dates -struct CoordLog{T <: AbstractFloat} +mutable struct CoordLog{T <: AbstractFloat} coords::Matrix{T} logdate::DateTime note::String end +""" + n_coords(log::CoordLog)::Integer + +Get number of coordinates in `log`. +""" +function n_coords(log::CoordLog)::Integer + size(log.coords)[1] +end