All,
Is it possible to write variables to a file? for example, I have a numeric variable "X" which which changes through each loop of a simulation. I want to add the value of "X" to a file called "data" on each loop. I've tried the following command:
print -file data.out $X
but on each loop it just writes a new file which is named the value of "X" (i.e. a number).
Any help would be much appreciated.
Thanks,
Lorcan.
Write variables to a file
Moderators: silvia, selimgunay, Moderators
Re: Write variables to a file
You can use the "puts" command to write to a file. If you want to output a list onto separate lines, you'll have to add a loop.
set X 1000.
set fid [open data.out w]
puts $fid "$X"
close $fid
set X_List [list 1 2 3 4]
set fid [open data.out w]
foreach Xi X_List {
puts $fid "$Xi\n"
}
close $fid
set X 1000.
set fid [open data.out w]
puts $fid "$X"
close $fid
set X_List [list 1 2 3 4]
set fid [open data.out w]
foreach Xi X_List {
puts $fid "$Xi\n"
}
close $fid
Re: Write variables to a file
Nick,
Thanks a lot. Worked perfectly.
Lorcan.
Thanks a lot. Worked perfectly.
Lorcan.