reading a .txt file in a list format

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

Moderators: silvia, selimgunay, Moderators

Post Reply
nahid2011
Posts: 74
Joined: Thu Jun 02, 2011 5:50 am
Location: OPS structures company

reading a .txt file in a list format

Post by nahid2011 »

Dear Sir or Madam

I need to read an input file named S.txt which contains a column of data like below:
0.01
0.02
0.03
0.04
and then saved it in a list like dtlist

I wrote the below lines, but it just took the first row data (0.01)

please help me

My code is:

set dtlist " " ; # define the array

if [catch {open S.txt r} InFileID] {
puts "ERROR - cannot open S.txt" ; # open the S.txt file
}

lappend dtlist [gets $InFileID]

close $InFileID

puts "dtlist=$dtlist"
Panos
Posts: 23
Joined: Fri Jul 20, 2012 10:28 am
Location: National Technical University of Athens

Re: reading a .txt file in a list format

Post by Panos »

the gets command reads only a line of data every time http://www.tcl.tk/man/tcl8.5/TclCmd/gets.htm
try the read command, or use a loop to read every line
nahid2011
Posts: 74
Joined: Thu Jun 02, 2011 5:50 am
Location: OPS structures company

Re: reading a .txt file in a list format

Post by nahid2011 »

Thanks i fixed that :)
Post Reply