read files and write

Forum for OpenSees users to post questions, comments, etc. on the use of the OpenSees interpreter, OpenSees.exe

Moderators: silvia, selimgunay, Moderators

Post Reply
sisa
Posts: 27
Joined: Sun Mar 13, 2011 8:03 am
Location: Bologna

read files and write

Post by sisa »

I would know if it is possible to create a procedure that read some filea (they are files of output) and writes all of them in a single file...I've tried to do this but it doesen't work. In every file I would read there are 3 dates and they are called DefMAxpilastro# with # that goes from 50 to 69 and I want to write all in complessivo.txt

---procedure-----
for { set a 50 } { $a <= 69 } { incr a } {
set valori [open DefMAxpilastro$a.out "r"]
set nuovo [gets $valori]
set outfile [open complessivo.out w]
puts $outfile "$nuovo"
close DefMAxpilastro$a.out
}
close complessivo.txt

in this way it say CAN NOT FIND CHANNEL NAMED DefMAxpilastro50.out
but this is in the same directory so it would be find it...
instead if I try to write without for loop it read just the first value of the original file...

---test--------
set valori [open DefMAxpilastro53.out "r"]
set nuovo [gets $valori]
puts $nuovo

do you have any suggest?
thank you
Annalisa
vesna
Posts: 3033
Joined: Tue May 23, 2006 11:23 am
Location: UC Berkeley

Re: read files and write

Post by vesna »

Try this:

for { set a 50 } { $a <= 69 } { incr a } {
set fName [format "DefMAxpilastro%02i.out" $a]
set valori [open $fName "r"]
set nuovo [gets $valori]
set outfile [open complessivo.out a]
puts $outfile "$nuovo"
close $valori
close $outfile
}
sisa
Posts: 27
Joined: Sun Mar 13, 2011 8:03 am
Location: Bologna

Re: read files and write

Post by sisa »

thank you for your reply. In this way it works but it reads and writes only the first date of each files...instead in each files there are 3 dates. is it possible read each of them and write all?
thanks a lot
Annalisa
Post Reply