1
votes

I have two data with different time format:
file1 (%Y %j %H %M %S vel):

2011 170 0 0 0 0.017042
2011 170 0 30 0 0.002124
2011 170 1 0 0 0.061001
2011 170 1 30 0 0.096256
2011 170 2 0 0 0.073920
2011 170 2 30 0 0.048899
2011 170 3 0 0 0.039534
2011 170 3 30 0 0.044790
2011 170 4 0 0 0.052662
2011 170 4 30 0 0.063144
etc ...

file2 (%Y %m %d %H %M tide):

2011 06 19 00 00 2.1950
2011 06 19 00 05 2.2650
2011 06 19 00 10 2.3290
2011 06 19 00 15 2.4030
2011 06 19 00 20 2.4730
2011 06 19 00 25 2.5480
2011 06 19 00 30 2.6220
2011 06 19 00 35 2.6890
2011 06 19 00 40 2.7690
2011 06 19 00 45 2.8460
2011 06 19 00 50 2.8970
2011 06 19 00 55 2.9690
2011 06 19 01 00 3.0610
2011 06 19 01 05 3.1370
2011 06 19 01 10 3.2030
2011 06 19 01 15 3.2670
etc ...

Is it possible to plot those data within the same graph? If so, how to do it?

What I did is:

set xdata time
set timefmt "%Y %j %H %M %S"
set xtics "2011 170 0 0 0",43200, "2011 172 0 0 0"
set xrange ["2011 170 0 0 0":"2011 172 0 0 0"]
set xtics format "%j"
plot "./file1" u 1:6 w lines ls 3 lc rgb "dark-red" notitle, \
"./file2" u 1:6 w lines ls 3 lc rgb "black" notitle axes x1y2

The result doesn't seem right.
Any helps will be greatly appreciated.
Thank you

1

1 Answers

1
votes

You must parse time of the second file manually. In gnuplot 5.0 this is very comfortable, because you can simply give timecolumn a time format as second option. Then it uses this format instead of the one given with set timefmt:

set xdata time
set timefmt "%Y %j %H %M %S"
set xtics "2011 170 0 0 0",43200, "2011 172 0 0 0"
set xrange ["2011 170 0 0 0":"2011 172 0 0 0"]
set xtics format "%j"
set y2tics
set ytics nomirror
plot "./file1.txt" u 1:6 w lines ls 3 lc rgb "dark-red" notitle, \
"./file2.txt" u (timecolumn(1, "%Y %m %d %H %M")):6 w lines ls 3 lc rgb "black" notitle axes x1y2

In earlier gnuplot versions you must first construct a string which contains all the time information and parse this string with strptime:

set xdata time
set timefmt "%Y %j %H %M %S"
set xtics "2011 170 0 0 0",43200, "2011 172 0 0 0"
set xrange ["2011 170 0 0 0":"2011 172 0 0 0"]
set xtics format "%j"
set y2tics
set ytics nomirror
mytimecolumn(c, fmt) = strptime(fmt, sprintf('%s %s %s %s %s', strcol(c), strcol(c+1), strcol(c+2), strcol(c+3), strcol(c+4)))
plot "./file1.txt" u 1:6 w lines ls 3 lc rgb "dark-red" notitle, \
"./file2.txt" u (mytimecolumn(1, "%Y %m %d %H %M")):6 w lines ls 3 lc rgb "black" notitle axes x1y2