1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) INRIA -
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2018 - Samuel GOUGEON
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
18 xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
19 xml:lang="en" xml:id="realtime">
20 <refnamediv xml:id="realtimeinit">
21 <refname>realtimeinit</refname>
22 <refpurpose>sets the time unit</refpurpose>
25 <refname>realtime</refname>
26 <refpurpose>sets the initial datetime and starts the chronometer, or waits until a given datetime</refpurpose>
31 realtimeinit(time_unit)
37 <title>Arguments</title>
40 <term>time_unit</term>
43 positive decimal number: time unit duration, in seconds.
51 decimal number: initial datetime, in <literal>time_unit</literal>.
52 This meaning holds when <literal>realtime(…)</literal> is called for the
53 first time after the last <literal>realtimeinit(…)</literal>.
54 This first call sets the datetime origin and restarts the real timer.
61 <para>decimal number: datetime up to which Scilab must wait before performing
62 the next instruction, expressed in time unit.
69 <title>Description</title>
71 While <literal>sleep(d)</literal> waits for a given fixed duration,
72 <literal>realtime(t)</literal> will wait the required (unknown) time to reach the
73 given datetime <varname>t</varname>.
76 <literal>realtimeinit(time_unit)</literal> defines the time unit in which the
77 datetime <varname>t</varname> specified by <literal>realtime</literal> is expressed.
80 After calling <literal>realtimeinit(time_unit)</literal>, the first call to
81 <literal>realtime(t0)</literal> sets the current datetime to <literal>t0</literal>,
82 without any wait. Each new call to <literal>realtime(t)</literal> then waits till
83 datetime <varname>t</varname> is reached. If <varname>t</varname> is already passed,
88 <title>Examples</title>
90 In the following example, in a loop, a job takes an arbitrary time, from
91 0 to 1.50 s. This is simulated with a sleep() of random duration. Although this period
92 is not regular, realtime() is used to compensate and print something every 2.00 seconds:
94 <programlisting role="example"><![CDATA[
100 if k==1, mprintf("\nSleep for Wake-up at Wait until date\n"), end
103 mprintf(' %4.2f s %5.2f s', d*1.5, toc());
105 mprintf(' %5.2f s\n', toc());
109 Sleep for Wake-up at Wait until date
114 1.28 s 9.36 s 10.08 s
115 0.02 s 10.10 s 12.08 s
116 0.28 s 12.36 s 14.08 s
117 0.74 s 14.82 s 16.08 s
118 1.12 s 17.20 s 18.08 s
119 1.41 s 19.49 s 20.08 s
122 <refsection role="see also">
123 <title>See also</title>
124 <simplelist type="inline">
126 <link linkend="sleep">sleep</link>
129 <link linkend="getdate">getdate</link>
132 <link linkend="waitbar">waitbar</link>
135 <link linkend="progressionbar">progressionbar</link>