-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSave_Output.jl
96 lines (62 loc) · 2.15 KB
/
Save_Output.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function Open_Dir(dir, Path)
cd(Path)
if dir in readdir()
cd(dir)
else
println("Created Directory /", dir, ".")
mkdir(dir)
cd(dir)
end
end
function FileName(dir)
my_time = Dates.format(Dates.now(), "_dd_u_yyyy_HHMMs")
string(dir, my_time, ".txt")
end
function Header(p, p_desc, q, q_desc)
header1 = string("# From: ",Dates.now(), ", Email: [email protected] \n")
header2 = string("# ModelParameter: ", p, "\n")
header3 = string("# ModelParameter: ", p_desc, "\n")
header6 = string("# SimulationParameter: ", q, "\n")
header7 = string("# SimulationParameter:", q_desc, "\n")
header8 = string("#Model: Optimized Model \n")
string(header1, header2, header3, header6, header7, header8)
end
Row_Names() = string("#id\tframe\tx\ty\n")
Row_Names_Vel() = string("#id\tframe\tx\ty\tv_x\tv_y\n")
Data_Row(id::Int, frame::Int, pos::NTuple{2, Float64}) = string(id, '\t', frame, '\t', pos[1], '\t', pos[2], '\n')
Data_Row(id::Int, frame::Int, pos::NTuple{2, Float64}, v::NTuple{2, Float64}) = string(id, '\t', frame, '\t', pos[1], '\t', pos[2],'\t', v[1], '\t', v[2], '\n')
function Write_Data!(f, positions::Matrix)
N_t, N = size(positions)
write(f, Row_Names())
for id in 1:N
for frame in 1:N_t
write(f, Data_Row(id, frame, positions[frame, id]))
end
end
end
function Write_Data!(f, positions::Vector{Tuple{Float64, Float64}})
N_t = length(positions)
write(f, Row_Names())
for frame in 1:N_t
write(f, Data_Row(1, frame, positions[frame]))
end
end
function Write_Data!(f, positions::Vector{Vector{Tuple{Float64, Float64}}})
N = length(positions)
write(f, Row_Names())
for id in 1:N
for frame in 1:length(positions[id])
write(f, Data_Row(id, frame, positions[id][frame]))
end
end
end
function Save_Data!(Path, dir, Header, positions)
file = FileName(dir)
Open_Dir(dir, Path)
touch(file)
f = open(file, "w")
#header = Header(p, p_desc, q, q_desc, op_model, tact_model, order, update, N, L)
write(f, header)
Write_Data!(f, positions)
close(f)
end