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 » Fri Jun 28, 2013 7:01 am

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 » Fri Jun 28, 2013 8:51 am

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 » Fri Jun 28, 2013 9:40 pm

Thanks i fixed that :)

Post Reply