Scilab 6.0.2
Change language to:
Français - 日本語 - Português - Русский

See the recommended documentation of this function

Scilab Help >> Time and Date > realtimeinit

# realtimeinit

sets the time unit

# realtime

sets the initial datetime and starts the chronometer, or waits until a given datetime

### Syntax

```realtimeinit(time_unit)
realtime(t0)
realtime(t)```

### Arguments

time_unit

positive decimal number: time unit duration, in seconds.

t0

decimal number: initial datetime, in `time_unit`. This meaning holds when `realtime(…)` is called for the first time after the last `realtimeinit(…)`. This first call sets the datetime origin and restarts the real timer.

t

decimal number: datetime up to which Scilab must wait before performing the next instruction, expressed in time unit.

### Description

While `sleep(d)` waits for a given fixed duration, `realtime(t)` will wait the required (unknown) time to reach the given datetime `t`.

`realtimeinit(time_unit)` defines the time unit in which the datetime `t` specified by `realtime` is expressed.

After calling `realtimeinit(time_unit)`, the first call to `realtime(t0)` sets the current datetime to `t0`, without any wait. Each new call to `realtime(t)` then waits till datetime `t` is reached. If `t` is already passed, no wait is added.

### Examples

In the following example, in a loop, a job takes an arbitrary time, from 0 to 1.50 s. This is simulated with a sleep() of random duration. Although this period is not regular, realtime() is used to compensate and print something every 2.00 seconds:

```clc
tic();
realtimeinit(2.00);
realtime(0);
for k = 1:10
if k==1, mprintf("\nSleep for  Wake-up at   Wait until date\n"), end
d = rand(1,1);
sleep(d*1500);
mprintf(' %4.2f s     %5.2f s', d*1.5, toc());
realtime(k);
mprintf('      %5.2f s\n', toc());
end```
```Sleep for  Wake-up at   Wait until date
0.28 s      0.57 s       2.08 s
0.03 s      2.11 s       4.08 s
1.27 s      5.34 s       6.08 s
0.11 s      6.19 s       8.08 s
1.28 s      9.36 s      10.08 s
0.02 s     10.10 s      12.08 s
0.28 s     12.36 s      14.08 s
0.74 s     14.82 s      16.08 s
1.12 s     17.20 s      18.08 s
1.41 s     19.49 s      20.08 s
```