Menu

Time format without date, only hours, minutes and seconds with precision of a millisecond

Help
2021-11-10
2021-11-10
  • Louis Fournier

    Louis Fournier - 2021-11-10

    Hello everybody!

    I'm a bit confused to use timefmt function due to ouput warning "Bad time format in string"
    To bring some details, I would like to print out the output values from an ADC of a microcontroller. Values a logged with timestamp (without date like year-month-day). I made a script that fit data with timestamp to a csv file.

    My input file is a csv file with this kind of values:

    00:29:49.955;405
    00:29:49.960;-501
    00:29:49.965;-447
    00:29:49.970;445
    00:29:49.975;405
    00:29:49.980;-519
    00:29:49.985;-433
    00:29:49.990;459
    00:29:49.995;412
    00:29:50.000;-510
    00:29:50.005;-424
    00:29:50.010;461
    

    The GNUPlot script is the following:

    unset key
    set datafile separator ";"
    set key autotitle columnhead
    set style data linespoints
    set key top
    set key box opaque
    set terminal png size 1000,400 enhanced font 'Helvetica,10'
    set output "./RESULTS/IMAGES/Sinus.png"
    set size 1,1
    set origin 0,0
    set key on outside noopaque font "Courriel,8"
    set tics font "Courriel,8"
    set title "ADC Output Signal" font ",10"
    set ylabel 'Measured ADC Signal (mV)'
    set xlabel 'Time (sec)'
    set autoscale y
    set xdata time
    set timefmt "%H:%M:%.3S"
    set format x "%M:%.3S"
    plot "SinusWaveFile.csv" using 1:2 with lines title "Channel 1"
    

    I get warning from last line "warning: Bad time format in string"

    It is important to have a precision of a millisecond because ADC measurement is made every 5 milliseconds. It seems it takes only one value each second. I thought if I specify "%.3S" in time format it should take each value.

    I cannot get the correct graph, could you please help me to fix this issue?
    I assume something is missing but I cannot find what is it...

    Thank you in advance,
    Best regards,
    Louis

     

    Last edit: Louis Fournier 2021-11-10
  • Louis Fournier

    Louis Fournier - 2021-11-10

    Sorry for spamming, finally I fixed my issue!

    The correct use of timefmt is :

    set timefmt "%H:%M:%S"
    

    Even if seconds have a precision of a millisecond, this is for the axis format that you have to specify the precision that you want. In my case this is:

    set format x "%M:%.3S"
    

    Hope it could help someone!
    Louis

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.