Revisão | 541d5f73c5fe4a058d2daff1745e5829b8b66762 (tree) |
---|---|
Hora | 2007-11-20 01:37:45 |
Autor | iselllo |
Commiter | iselllo |
I modified read_1_particle_kind.tcl which is now able to read and save
(from the configuration blockfiles) all the particles coordinates at
different times in a format suitable for R and Python.
@@ -1,94 +1,161 @@ | ||
1 | - | |
2 | -#set f [open "config_1" "r"] | |
3 | -#while { [blockfile $f read auto] != "eof" } {} | |
4 | -#close $f | |
5 | - | |
6 | -#puts "ok reading the block file" | |
7 | 1 | |
8 | -#set rdf [analyze rdf 0 0 0.9 [expr $box_l/2] 100] | |
9 | -#puts "the box size is $box_l" | |
10 | -#puts "the radial density is $rdf" | |
11 | -#set rlist "" | |
12 | -#set rdflist "" | |
13 | -#foreach value [lindex $rdf 1] { | |
14 | -#lappend rlist [lindex $value 0] | |
15 | -#lappend rdflist [lindex $value 1] | |
16 | -#} | |
17 | 2 | |
3 | +# first a test on reading a single configuration | |
4 | + | |
5 | + | |
6 | + | |
7 | +set f [open "config_2" "r"] | |
8 | +while { [blockfile $f read auto] != "eof" } {} | |
9 | +close $f | |
10 | + | |
11 | +puts "ok reading the block file" | |
12 | + | |
13 | + | |
14 | + | |
15 | +puts "I read a specific configuration" | |
16 | + | |
17 | + analyze append | |
18 | + | |
19 | +#puts "u is, $u " | |
20 | + | |
21 | +set z [analyze config] | |
22 | + | |
23 | + | |
24 | +puts "z is, $z " | |
25 | + | |
26 | + | |
27 | +#Now I try saving the configuration to a specific file | |
28 | + | |
29 | + | |
30 | +set obs [open "my_saved_config.dat" "w"] | |
31 | + | |
32 | +#the following line saves the particle positions in a funny way | |
33 | +#i.e. exactly as a TCL list | |
34 | + | |
35 | +puts $obs "$z " | |
36 | + | |
37 | +close $obs | |
38 | + | |
39 | +#z is now a list of 3N particle positions (3 positions x,y,z per particle) | |
40 | +#however, the list should be read as a row, i.e. the 6th position of the list is given by | |
41 | +# [lindex $z 0 5] (arrays are numbered from zero, C-style) i.e. zero-th row and 5-th column (always | |
42 | +#counting from zero). | |
43 | + | |
44 | +set zt [lindex $z 0 5] | |
45 | + | |
46 | +puts "z(5) is, $zt" | |
18 | 47 | |
19 | 48 | |
20 | 49 | |
21 | 50 | |
22 | 51 | |
23 | -set f [open "config_6" "r"] | |
24 | -while { [blockfile $f read auto] != "eof" } {} | |
25 | -close $f | |
52 | +set zlist "" | |
26 | 53 | |
27 | -puts "ok reading the block file" | |
54 | +foreach value [lindex $z 0] { | |
55 | +#puts "value is, $value" | |
56 | +lappend zlist [lindex $value 0] | |
57 | +} | |
28 | 58 | |
29 | -for {set i 0} {$i < 100} {incr i} { lappend rdf_single 0} | |
30 | -puts "rdf_single is $rdf_single" | |
31 | -# the previous avg_single is used only to contain the results of the statistics on a single configuration | |
32 | -# in a convenient way. | |
59 | +puts "zlist is, $zlist" | |
60 | + | |
61 | +#this way I am saving zlist as an array | |
62 | + | |
63 | +#Now I save the array to a file I can read with R, Python, etc... | |
64 | + | |
65 | +set obs2 [open "example_configuration.dat" "w"] | |
66 | + | |
67 | +foreach r $zlist { puts $obs2 "$r" } | |
68 | +close $obs2 | |
33 | 69 | |
34 | 70 | |
35 | -set rdf [analyze rdf 0 0 0.9 [expr $box_l/2] 100] | |
36 | -puts "the box size is $box_l" | |
37 | -puts "the radial density is $rdf" | |
38 | -set rlist "" | |
39 | -set rdflist "" | |
40 | -foreach value [lindex $rdf 1] { | |
41 | -lappend rlist [lindex $value 0] | |
42 | -lappend rdflist [lindex $value 1] | |
43 | -} | |
44 | - | |
45 | - | |
46 | -set rdf_single [vecadd $rdf_single $rdflist] | |
47 | - | |
48 | -set plot [open "rdf_single.data" "w"] | |
49 | -puts $plot "\# r rdf(r)" | |
50 | -foreach r $rlist rdf $rdf_single { puts $plot "$r $rdf" } | |
51 | -close $plot | |
52 | 71 | |
53 | 72 | |
54 | 73 | |
55 | 74 | puts "OK reading single configuration" |
56 | 75 | |
57 | 76 | |
77 | + | |
78 | + | |
79 | + | |
80 | +#Now I read and count a set of configurations | |
81 | + | |
82 | +#first I remove the previously stored configuration | |
83 | + | |
84 | +analyze remove | |
85 | + | |
86 | + | |
87 | + | |
88 | +#The following 2 parameters are needed to read the saved configurations | |
89 | + | |
90 | +set my_increase 1 | |
91 | + | |
92 | +set tot_config 200 | |
93 | + | |
94 | +#for {set i 0} {$i < $tot_config} {incr i $my_increase} { lappend rdf_single 0} | |
95 | +#puts "rdf_single is $rdf_single" | |
96 | +# the previous avg_single is used only to contain the results of the statistics on a single configuration | |
97 | +# in a convenient way. | |
98 | + | |
99 | + | |
58 | 100 | set cnt 0 |
59 | -for {set i 0} {$i < 100} {incr i} { lappend avg_rdf 0} | |
101 | +#for {set i 0} {$i < 200000} {incr i 200} { lappend avg_rdf 0} | |
60 | 102 | #this initializes to zero the an array by "back-pushing" (appending) every time a zero element to a list. |
61 | 103 | |
62 | 104 | set j 0 |
63 | -while {$j<20} { | |
105 | +while {$j< $tot_config} { | |
64 | 106 | puts "j is $j" |
65 | 107 | set f [open "config_$j" "r"] |
66 | 108 | while { [blockfile $f read auto] != "eof" } {} |
67 | 109 | close $f |
68 | -set rdf [analyze rdf 0 0 0.9 [expr $box_l/2] 100] | |
69 | -set rlist "" | |
70 | -set rdflist "" | |
71 | -foreach value [lindex $rdf 1] { | |
72 | -lappend rlist [lindex $value 0] | |
73 | -lappend rdflist [lindex $value 1] } | |
74 | -set avg_rdf [vecadd $avg_rdf $rdflist] | |
110 | + | |
111 | +#Now I try retrieving the info about particle positions | |
112 | + | |
113 | + analyze append | |
114 | + | |
115 | +#puts "u is, $u " | |
116 | + | |
117 | +set w [analyze config] | |
118 | + | |
119 | + | |
120 | + | |
75 | 121 | incr cnt |
76 | -incr j | |
122 | +incr j $my_increase | |
77 | 123 | } |
78 | -set avg_rdf [vecscale [expr 1.0/$cnt] $avg_rdf] | |
124 | + | |
125 | +puts "the total number of read configurations is, $cnt" | |
79 | 126 | |
80 | 127 | puts "ok reading the configurations" |
81 | 128 | |
82 | -set plot [open "rdf.data" "w"] | |
83 | -puts $plot "\# r rdf(r)" | |
84 | -#the previous line adds a header to the file with the saved data | |
85 | -foreach r $rlist rdf $avg_rdf { puts $plot "$r $rdf" } | |
86 | -close $plot | |
129 | +puts "w is, $w" | |
130 | + | |
131 | +set wlist "" | |
132 | + | |
133 | +set flag 0 | |
87 | 134 | |
88 | 135 | |
89 | -#plotObs "rdf.data" { 1:2 } labels { "time" "radial density" } out "radial_density_new" | |
90 | -#exec gv radial_density_new.ps | |
91 | -exec ./simulations_script | |
92 | -# the simulation script is bash script which calls and R code for the visualization of the results | |
136 | +set i 0 | |
137 | +set j 0 | |
138 | +while {$j< $tot_config} { | |
139 | +puts "j is, $j" | |
140 | +foreach value [lindex $w $j] { | |
141 | + | |
142 | +#puts "value is, $value" | |
143 | + | |
144 | +set my_reading [lindex $w ] | |
145 | +#puts "I am reading, $my_reading" | |
146 | + | |
147 | +lappend wlist [lindex $value ] | |
148 | +incr i 1 | |
149 | +} | |
150 | +incr j $my_increase | |
151 | +} | |
152 | + | |
153 | + | |
154 | +#puts "wlist is, $wlist" | |
155 | + | |
156 | +set obs3 [open "total_configuration.dat" "w"] | |
157 | + | |
158 | +foreach r $wlist { puts $obs3 "$r" } | |
159 | +close $obs3 | |
93 | 160 | |
94 | 161 | puts "So far so good" |
\ No newline at end of file |