How can I get the length of a data vector?

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

Moderators: silvia, selimgunay, Moderators

Post Reply
ljdeng
Posts: 9
Joined: Tue Mar 03, 2009 11:41 pm
Location: Davis, CA
Contact:

How can I get the length of a data vector?

Post by ljdeng »

I am a new user of opensees and tcl language.
I am wondering how I can automatically get the length of a data vector, for example, an earthquake time history; therefore I can know how many steps to "analyze". Similar commands like last(file) in Matlab and rows(file) in MathCAD?
Many thanks.
Lijun
silvia
Posts: 3909
Joined: Tue Jan 11, 2005 7:44 am
Location: Degenkolb Engineers
Contact:

Post by silvia »

you have to load up the file into a list and then use: llength command.
www.tcl.tk/man/tcl8.5/TclCmd/contents.htm
Silvia Mazzoni, PhD
Structural Consultant
Degenkolb Engineers
235 Montgomery Street, Suite 500
San Francisco, CA. 94104
ljdeng
Posts: 9
Joined: Tue Mar 03, 2009 11:41 pm
Location: Davis, CA
Contact:

Post by ljdeng »

Thanks Silvia. I made a proc to load the file into a list, and it works well.

proc EventLength filename {
set file [open $filename];
set iDstep [read $file];
set eventlist [list 0];
foreach Dstep $iDstep {
lappend eventlist $Dstep; };
set eventNo [llength $eventlist];
return [expr $eventNo-1];
}
Lijun
Post Reply