From: John Stone (johns_at_ks.uiuc.edu)
Date: Wed Jun 30 2004 - 15:18:22 CDT

Axel,
  I suppose a simple Tcl proc could take a floating point number
of seconds and convert it to the integer part and fractional part
and do the required 'sleep' and 'after ms' calls to get the right delay,
this could be done in Tcl itself like this:

proc floatsleep { seconds } {
  if ([expr $seconds > 0.0]) {
    set secs [expr int($seconds)]
    set frac [expr fmod($seconds, 1)]
    set ms [expr int($frac * 1000)]
          sleep $secs
    after $ms
  }
}

It seems to be fairly usable for smallish delay values:
vmd> time {floatsleep 0.09}
91280 microseconds per iteration

It will not be as nice as a C-based implementation for small delay values,
but it ought to be an easy-to-use substitute for the time being.
Let me know if that is good enough for what you have in mind,
I just whipped it up just now so it may not be 100%
bulletproof yet. Give it a try and tell me what you think.

  John Stone
  vmd_at_ks.uiuc.edu

On Wed, Jun 30, 2004 at 09:45:31PM +0200, Axel Kohlmeyer wrote:
> On Wed, 30 Jun 2004, John Stone wrote:
>
>
> john,
>
> indeed this is very nice. yet, it would be
> even more convenient to have the sleep command
> accept a floating point number and convert
> that internally to milliseconds. that was my
> initial motivation behind posting the select
> based sleep (only i forgot to explain it in detail),
> and i think i was not the only one trying to
> wait a sub-second delay with the sleep command...
>
> axel.
>
> JS>
> JS> Axel,
> JS> Even better, as it turns out, there's already a Tcl command
> JS> to delay for a specified number of milliseconds.
> JS>
> JS> Compare this:
> JS> foreach {i} [info functions] {
> JS> puts $i;
> JS> }
> JS>
> JS> To this:
> JS> foreach {i} [info functions] {
> JS> # sleep for 250 milliseconds
> JS> after 250
> JS> puts $i;
> JS> }
> JS>
> JS> Enjoy,
> JS> John Stone
> JS> vmd_at_ks.uiuc.edu
> JS>
>
> [...]
>
> --
>
> =======================================================================
> Dr. Axel Kohlmeyer e-mail: axel.kohlmeyer_at_rub.de
> Lehrstuhl fuer Theoretische Chemie Phone: ++49 (0)234/32-26673
> Ruhr-Universitaet Bochum - NC 03/53 Fax: ++49 (0)234/32-14045
> D-44780 Bochum http://www.theochem.ruhr-uni-bochum.de/~axel.kohlmeyer/
> =======================================================================
>

-- 
NIH Resource for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
Email: johns_at_ks.uiuc.edu                 Phone: 217-244-3349              
  WWW: http://www.ks.uiuc.edu/~johns/      Fax: 217-244-6078