[vtkusers] VTK/TCL logfile manipulation: howto update at a given frequency?

Goodwin Lawlor goodwin.lawlor at ucd.ie
Wed Mar 12 14:48:23 EDT 2008


Hi Graham,

This question would be more at home on comp.lang.tcl...

Graham E Voysey wrote:
> Hello List, 
> 
> I'm using VTK to display a human avatar and manipulate its position.
> The intended user is a test subject in a motion study who will use a
> joystick to position the avatar so that it reflects how the user feels
> that they are moving.
> 
> I've been asked to modify our script to include logging the camera
> orientation and position every 250ms.  I've hit two areas that confuse
> me.
> 
> 1. The script currently creates a log file with a hardcoded name.  I'd
> like to change this so that the name of the file is
> <dateAndTimeFirstOpened>.log, so that logs are not accidentally
> overwritten.
> 
> set logFile [open "GSV_log.log" w 0666]
> 
> would replacing the above with something like 
> 
> set logFile [open "[clock format [clock seconds]].log" w 0666]  
> 
> be anything close to proper syntax?

Be careful of [clock format] putting spaces in your file name, something 
like:

clock format [clock seconds] -format %T-%d:%m:%y

would work ok.

Also if you want to append values to the log file, open the file with 
append access. Something like:

set fid [open [clock format [clock seconds] -format %T-%d:%m:%y].log a]

> 
> 2.  I'm confused about how I would create a loop that would write a line
> to said logfile at a given time interval.  What's a good way to think
> about this, or do it?

Have a look at the [after] command - some examples here: 
http://wiki.tcl.tk/808

hth

Goodwin




More information about the vtkusers mailing list