gnuplot:如何正确解释负数时间? [英] gnuplot: how to correctly interpret negative times?

查看:141
本文介绍了gnuplot:如何正确解释负数时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gnuplot中存在负时间问题.

I have some issue with negative times in gnuplot.

基本上,我想写一个负数时间,例如为-00:01:00,但是gnuplot不会将其解释为-60秒,而是解释为+60秒. 我能以某种方式理解原因:因为-00小时等于+00小时,然后01分钟被算为正.

Basically, I would like to write a negative time, e.g. as -00:01:00, but gnuplot is not interpreting it as -60 seconds, but as +60 seconds. I can somehow understand why: because -00 hours is equal to +00 hours and then 01 minutes are counted positive.

我忽略了什么吗?也许有一个简单的解决方法?

Did I overlook something? Is there maybe an easy workaround?

下面提供了更多示例.让我们以%H:%M:%S(实际上是%tH:%tM:%tS)格式进行一些转换. 除第6行外,我所有行都没问题. 第7行将被解释为%tH:%tM,而没有秒,这就是为什么它是-3660秒.

More examples are given below. Let's convert some times in the format %H:%M:%S (actually %tH:%tM:%tS). I'm fine with all lines, except line 6. Line 7 will be interpreted as %tH:%tM without seconds that's why it is -3660 seconds.

代码:

### negative times
reset session

$Data <<EOD
1   01:00:00
2   01:00:01
3  -01:00:00
4  -01:00:01
5   00:01:01
6  -00:01:01
7     -01:01
8   00:-01:-01
9   00:-01:01
EOD

myTimeFmt = "%tH:%tM:%tS"

set table $Test
    plot $Data u 1:(strcol(2)):(timecolumn(2,myTimeFmt)) w table
unset table
print $Test
### end of code

结果:

 1      01:00:00         3600
 2      01:00:01         3601
 3     -01:00:00        -3600
 4     -01:00:01        -3601
 5      00:01:01           61
 6     -00:01:01           61
 7        -01:01        -3660
 8      00:-01:-01        -61
 9      00:-01:01         -61

推荐答案

以下尝试包括输入以-00小时%tH:%tM:%tS(或分钟%tM:%tS)开头的否定时间的可能性.

The following is an attempt to include the possibility of entering negative times starting with -00 hours %tH:%tM:%tS (or minutes %tM:%tS).

与gnuplot当前处理情况不同,它对4和6的处理方式不同. 解决方法将以与gnuplot相同的方式处理小时数为-00小时且负数为 的分钟或秒为负(案例7-14和16-17).好吧,无论如何后者都是奇怪的格式.

It will handle cases 4 and 6 differently than gnuplot currently will do. The workaround will handle cases which have negative or -00 hours and additionally negative minutes or seconds (cases 7-14 and 16-17) the same way as gnuplot will do. Well, the latter are strange formats anyway.

代码:

### workaround for handling negative times
reset session

$Data <<EOD
1    01:00:00
2   -01:00:00
3    00:01:00
4   -00:01:00
5    00:00:01
6   -00:00:01
7    00:00:-01
8    00:-00:01
9    00:-00:-01
10   00:-01:01
11   00:-01:-01
12  -00:-01:-01
13  -00:-01:01
14  -00:-01:-01
15  -01:01:01
16  -01:-01:-01
17   01:-01:-01
EOD

myTimeFmt = "%tH:%tM:%tS"

myTimeSigned(fmt,s) = s[1:1] eq '-' && strptime("%tH",s)==0 && strptime(fmt,s)>0 ? \
                      -strptime(fmt,s[2:]) : strptime(fmt,s)
myTime(n,fmt) = myTimeSigned(fmt,strcol(n))

set table $Test
    plot $Data u 1:(strcol(2)):(timecolumn(2,myTimeFmt)):(myTime(2,myTimeFmt)) w table
unset table
print $Test
### end of code

结果:

         input       gnuplot  workaround

 1      01:00:00       3600    3600
 2     -01:00:00      -3600   -3600
 3      00:01:00         60      60
 4     -00:01:00         60     -60   # different
 5      00:00:01          1       1
 6     -00:00:01          1      -1   # different
 7      00:00:-01        -1      -1
 8      00:-00:01         1       1
 9      00:-00:-01       -1      -1
 10     00:-01:01       -61     -61
 11     00:-01:-01      -61     -61
 12    -00:-01:-01      -61     -61
 13    -00:-01:01       -61     -61
 14    -00:-01:-01      -61     -61
 15    -01:01:01      -3661   -3661
 16    -01:-01:-01    -3661   -3661
 17     01:-01:-01     3539    3539

这篇关于gnuplot:如何正确解释负数时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆