I'm finding a rare limitation in gnuplot, so it seems it can't work with dates after the year 2037. This is the code I'm using:
myTimeFmt = '%d/%m/%Y'
DateStart = '01/01/2038'
DateEnd = '31/12/2038'
SecsPerDay = 86400
set print $Data
do for [t=strptime(myTimeFmt,DateStart):strptime(myTimeFmt,DateEnd):SecsPerDay] {
print strftime(myTimeFmt,t)
}
set print
print $Data
This works for the year 2037. Trying it with the year 2038 returns the following error:
no datablock named $Data
With the year 2039 and so on, the code returns the date 13/12/1901
.
Is there any solution for my code to make it work? Or will I have to create the $Data content with another tool? Which one? Could I do that with awk (supported in gnuplot)?
Some more information:
gnuplot 5.0 patchlevel 5
Debian 4.9.258-1
4.9.0-15-amd64
x86_64
I'm not a Gnuplot expert, but think it's to do with for
loops only working with integer values. You can work around by doing something like:
t = strptime(myTimeFmt,DateStart)
te = strptime(myTimeFmt,DateEnd)
while (t < te) {
print strftime(myTimeFmt,t)
t = t + SecsPerDay
}
That way I get the iteration happening as normal.
Otherwise, you could rewrite to something like:
ts = strptime(myTimeFmt, DateStart)
te = strptime(myTimeFmt, DateEnd)
do for [day = 0 : (te - ts) / SecsPerDay] {
t = ts + day * SecsPerDay
print strftime(myTimeFmt,t)
}
Which might result in less floating point rounding errors if you increment by different values (e.g. if you want to increment by 0.1 seconds you'd run into things like Is floating point math broken?).