I make a Script to extract Mx from the result file?!

If you have a script you think might be useful to others post it
here. Hopefully we will be able to get the most useful of these incorporated in the manuals.

Moderators: silvia, selimgunay, Moderators

Post Reply
Posts: 7
Joined: Wed Mar 28, 2007 9:03 am

I make a Script to extract Mx from the result file?!

Post by jiaochiyu2000 » Thu May 01, 2008 3:50 am

I make a script to extract Mx from the result file of the recorder but it is inefficient!,
#get the moment around the z-axis from file " PierElement-Lf_$idaSa-E$earthquake.out" put them into PierElement-LMZ_$idaSa-E$earthquake.out"
set start [open PierElement-Lf_$idaSa-E$earthquake.out r]
set ctr 0;
foreach line [split [read -nonewline $start] \n] {

set ctr [expr $ctr+1];
set lineSize($ctr) [llength $line];
set lineData($ctr) $line;
set lineNumber $ctr;

for {set i 1} {$i <= $lineNumber } {incr i 1} {
for {set j 1} {$j <= $lineSize($i)} {incr j 1} {
# puts "lineSize($i) $lineSize($i)"
set matrixa($i,$j) [lindex $lineData($i) [expr $j-1]]
# puts "data($i,$j) $matrixa($i,$j)"

set MZ [open "PierElement-LMZ_$idaSa-E$earthquake.out" a]
for {set i 1} {$i <= $lineNumber } {incr i 1} {
puts -nonewline $MZ "$matrixa($i,1) "
for {set j 2} {$j <=[expr ($lineSize($i)-1)/12+1]} {incr j 1} {
puts -nonewline $MZ "$matrixa($i,[expr 12*($j-2)+7]) "
puts -nonewline $MZ "\n"
close $MZ

altough the result is right, but the efficience is so low, it needs 40 minutes to extract all the forces (69element, 12forces =689column)(time =4000*0.01=40sec)!
do you have any idea to solve this problem!

Posts: 3912
Joined: Tue Jan 11, 2005 7:44 am
Location: Degenkolb Engineers

Post by silvia » Tue May 13, 2008 9:56 am

you should do it all within one loop.
tcl is not very efficient in reading data files because it does not do the scanf, it uploads the entire file.
you might want to try it in matlab, instead.
Silvia Mazzoni, PhD
Structural Consultant
Degenkolb Engineers
235 Montgomery Street, Suite 500
San Francisco, CA. 94104

Posts: 17
Joined: Sun Jan 21, 2007 12:04 am
Location: Fugro

Post by jaugalde » Fri Aug 01, 2008 7:22 am

All of the following suggestions are straight from the tcler's wiki which I've found very useful when writing any useful tcl code.

-Increasing the channel buffer size using fconfigure helps for large files or tell read exactly the size to read
set size [file size "myFile"]
....[read $myFileID $size]

-Put all that stuff in a procedure. Inline Tcl code doesn't get all the optimizations that a procedure can get

Also, all the optimizations would be useless if you are reading files from a network drive. File reading and writing is way faster if these giant files are on your local machine.

Post Reply