Deviating time unit default in gmt math -Q mode (just a note)

It is just a note, as I figured out the solution consulting the documentation. When calculating the duration between two time stamps, I get

gmt math -Q 2021-02-05T19:22:51 2021-02-05T18:40:11 SUB =
    2560

So, the interval is given in seconds. If I want to do the same with two files containing the respective time stamps, I need an extra flag, -fot .

echo '2021-02-05T19:22:51' > 1.dat
echo '2021-02-05T18:40:11' > 2.dat
gmt math -fot 1.dat 2.dat SUB =
    2560

Without it I get the time difference in absolute time:
1970-01-01T00:42:40

So, the default in quick mode seems to be -fot whereas otherwise it is -foT.

THis is a tricky one and I can add a note in the docs. WHen you read from the two files, GMT detects there is absolute time coordinates and flags that columns as abs time. hence on output it will format according to that. WHen you use the -Q there is no files and we just process arguments on the command line. The timestamp will be processed but it does not change the data column to abstime. What the format should be is not possible to determine. In your case you want a difference but others may wish to add 24 hours to a date and get the new date. I think the best we can do here is to say (a) gmt math will do computations so it makes sense to implicitly set -f0T unless the user overrides that, and (b) it should do the same thing for both your exaples. WIll have a look.

Master has been updated to be consistent regarding output time column formatting, See https://github.com/GenericMappingTools/gmt/pull/4768 for details.

As a follow-up to this …

I’m trying to write a script with gmt batch and I need to define a list of time coordinates to start each jobs :

$ gmt math -o0 -T1980-01-01T/1980-03-03T/1o T =
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
$ gmt math -o0 -T1980-01-01T/1980-02-03T/1o T =
1980-01-01T00:00:00
1980-02-01T00:00:00

Same if I try to use y for a longer period (ie the actual command I’m trying to run):

gmt math -o0 -T1980-01-01T/2019-12-31T/3y T =
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000
00T00:00:00.000000000

This is a bug. Do you want to open a GitHub issue for it? https://github.com/GenericMappingTools/gmt/issues

1 Like

Here’s a work-around if you need for while we fix this:
gmt math -o0 -T1980-01-01T/2019-12-31T/3y T --FORMAT_CLOCK_OUT='' =

1 Like

Thanks, no rush :slight_smile: I create the file with Matlab

@PlanetGus, the bug was fixed in the GMT repository through this PR.

1 Like