|
From: Juhász P. <pet...@gm...> - 2010-12-29 19:05:29
|
On Wed, 2010-12-29 at 10:37 -0800, Ethan Merritt wrote:
> On Wednesday, December 29, 2010, Juhász Péter wrote:
> > I've found it frustrating that there is
> > no way within gnuplot to get the current time, one has to resort to an
> > external application. There is already an extensive framework in place
> > for formatting date&time strings, there is even a way to put the current
> > time as a time stamp on the plot, but there is no way to get it as a
> > variable (for example). There ought to be a time() function that returns
> > the current gnuplot time (seconds since 2000), the existing formatting
> > functions are adequate to transform that into any other format.
>
> Sounds reasonable to me. The only concern I see is the question of
> whether it can be made totally portable, or whether it will need
> documentation as being system-dependent.
>
> As you noted before in a sample script, on unix-ish systems you can do
> time = system("date +%s")
> to get the number of seconds since the unix epoch. Maybe it would be
> sufficient to export a user variable containing the offset between
> system time and internal time?
> internal_time = system("date +%s") - GPVAL_EPOCH
> Nah. That would just confuse everyone.
Please see the attached patch.
I think it's as portable as we can make it even in this rough draft
state. From the user's standpoint, we define gnuplot time as the number
of seconds elapsed since 2000.0 and the new function returns this
number, and that's that. Internally this depends on the C library's
time() function, which returns the number of seconds since 1970, from
which number we get the result with a simple subtraction.
I think it's reasonable to expect that C's time() function will be
available on every platform where gnuplot can be compiled.
Two observations:
The time stamp generated by "set timestamp" uses localtime() internally
(buried deep in graphics.c), so it prints the local time. Other
time-management functions generally work with gmtime().
Is that true that functions in gnuplot need to have at least one
argument?
And one more:
We keep saying "the number of seconds elapsed since 2000.0".
Unfortunately, that's not as unambiguous as one would think.
There is that nasty business of leap seconds, that is, the adjustments
made to UTC to keep it synchronized to mean solar time. This is needed
because Earth's rotation is not constant, it's slowly decelerating.
This means that UTC is not in sync with a pure atomic time (such as used
by GPS), the discrepancy is 34 seconds now.
If we were to be really anal about timekeeping in gnuplot, we should
tell users exactly which time standard do we follow.
Péter Juhász
|