修订版 | 451a4306fe74c0b9641118379daaaeeb948dae62 (tree) |
---|---|
时间 | 2007-11-21 01:42:35 |
作者 | iselllo |
Commiter | iselllo |
I added the code read_test.tcl which specifically reads the output
(velocities and positions) of test.tcl.
@@ -0,0 +1,153 @@ | ||
1 | + | |
2 | +# first a test on reading a single configuration | |
3 | + | |
4 | + | |
5 | + | |
6 | +set f [open "config_vel_7" "r"] | |
7 | +while { [blockfile $f read auto] != "eof" } {} | |
8 | +close $f | |
9 | + | |
10 | +puts "ok reading the block file" | |
11 | + | |
12 | +set Mpos2 {} | |
13 | +set Mvel2 {} | |
14 | +for {set p 0} {$p <= [setmd max_part]} {incr p} { | |
15 | + set pos2 [part $p print pos] | |
16 | + set vel2 [part $p print v] | |
17 | + lappend Mpos2 $pos2 | |
18 | + lappend Mvel2 $vel2 | |
19 | +} | |
20 | + | |
21 | +puts "Mpos is, $Mpos2" | |
22 | +puts "M_vel is, $Mvel2" | |
23 | + | |
24 | + | |
25 | +puts "OK reading single configuration for velocity and position" | |
26 | + | |
27 | + | |
28 | + | |
29 | + | |
30 | + | |
31 | + | |
32 | +#The following 2 parameters are needed to read the saved configurations | |
33 | + | |
34 | +set my_increase 1 | |
35 | + | |
36 | +# number of snapshots of the system | |
37 | +set tot_config 10 | |
38 | + | |
39 | +# number of particles | |
40 | + | |
41 | +set n_part 10 | |
42 | + | |
43 | +set new_iter [expr $n_part*$tot_config] | |
44 | + | |
45 | +#counter | |
46 | +set cnt 0 | |
47 | + | |
48 | + | |
49 | +#lists containing the velocity and position data | |
50 | +set Mpos {} | |
51 | +set Mvel {} | |
52 | + | |
53 | + | |
54 | +set j 0 | |
55 | +while {$j< $tot_config} { | |
56 | +puts "j is $j" | |
57 | +set f [open "config_vel_$j" "r"] | |
58 | +while { [blockfile $f read auto] != "eof" } {} | |
59 | +close $f | |
60 | + | |
61 | + | |
62 | + | |
63 | + | |
64 | +for {set p 0} {$p <= [setmd max_part]} {incr p} { | |
65 | + set pos [part $p print pos] | |
66 | + set vel [part $p print v] | |
67 | + lappend Mpos $pos | |
68 | + lappend Mvel $vel | |
69 | +} | |
70 | + | |
71 | + | |
72 | + | |
73 | +incr cnt | |
74 | +incr j $my_increase | |
75 | +} | |
76 | + | |
77 | + | |
78 | +#puts "Mpos is, $Mpos" | |
79 | + | |
80 | +#puts "Mvel is, $Mvel" | |
81 | + | |
82 | + | |
83 | + | |
84 | + | |
85 | +########################################################################################################### | |
86 | +############################################################################################################# | |
87 | +#I tested I can read the positions and velocities correctly from the input files, but I also need to save them into | |
88 | +# two large files | |
89 | + | |
90 | + | |
91 | + | |
92 | +puts "the total number of read configurations is, $cnt" | |
93 | + | |
94 | +puts "ok reading the configurations" | |
95 | + | |
96 | + | |
97 | +#I define wlist which I'll be using to write the results to a file | |
98 | + | |
99 | +set wlist "" | |
100 | + | |
101 | + | |
102 | + | |
103 | + | |
104 | +set j 0 | |
105 | +while {$j< $new_iter} { | |
106 | + | |
107 | +foreach value [lindex $Mpos $j] { | |
108 | + | |
109 | +lappend wlist [lindex $value ] | |
110 | + | |
111 | +} | |
112 | +incr j $my_increase | |
113 | +} | |
114 | + | |
115 | + | |
116 | +set obs3 [open "total_configuration.dat" "w"] | |
117 | + | |
118 | +foreach r $wlist { puts $obs3 "$r" } | |
119 | +close $obs3 | |
120 | + | |
121 | + | |
122 | +#Now I save the particle velocities as a 1D array | |
123 | +#(same as above with the positions) | |
124 | + | |
125 | +set wlist2 "" | |
126 | + | |
127 | + | |
128 | +set j 0 | |
129 | +while {$j< $new_iter} { | |
130 | + | |
131 | +foreach value [lindex $Mvel $j] { | |
132 | + | |
133 | + | |
134 | + | |
135 | + | |
136 | +lappend wlist2 [lindex $value ] | |
137 | + | |
138 | +} | |
139 | +incr j $my_increase | |
140 | +} | |
141 | + | |
142 | + | |
143 | + | |
144 | + | |
145 | +set obs4 [open "total_configuration_vel.dat" "w"] | |
146 | + | |
147 | +foreach r $wlist2 { puts $obs4 "$r" } | |
148 | +close $obs4 | |
149 | + | |
150 | + | |
151 | + | |
152 | + | |
153 | +puts "So far so good" | |
\ No newline at end of file |