GPS extracts fix delta time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GPS extracts fix delta time
# 1  
Old 07-03-2014
GPS extracts fix delta time

Hello all,

I am currently trying to find the delta time from some GPS log.

I am using the following script with awk. But the script result shows some incorrect values (delta time some time = 0.2 but when I check it manually it is equal to 0.1)

My final goal is to get a script that print the line number where the GPS fix are not equal to 0.1

Could you please help to find my mistake ?

Thanks for your help;

Script used :
Code:
#!/bin/bash
echo check gps fix time stamp
awk '{print substr( $0, 8, 10)}' $1 > gps_time_stamp.txt

awk 'NR % 2 !=0 {a=$1} NR % 2 ==0 {b=$1-a;print b}' gps_time_stamp.txt > gps_fix_period.txt

Log Example
Code:
$GPRMC,124711.567,V,,,,,0.06,330.27,160514,,,N*4D
$GPRMC,124711.667,V,,,,,0.09,330.27,160514,,,N*41
$GPRMC,124711.767,V,,,,,0.08,330.27,160514,,,N*41
$GPRMC,124711.867,V,,,,,0.12,330.27,160514,,,N*45
$GPRMC,124711.967,V,,,,,0.04,330.27,160514,,,N*43
$GPRMC,124712.067,V,,,,,0.08,330.27,160514,,,N*45
$GPRMC,124712.167,V,,,,,0.10,330.27,160514,,,N*4D
$GPRMC,124712.267,V,,,,,0.07,330.27,160514,,,N*48
$GPRMC,124712.367,V,,,,,0.05,330.27,160514,,,N*4B
$GPRMC,124712.467,V,,,,,0.05,330.27,160514,,,N*4C
$GPRMC,124712.567,V,,,,,0.19,330.27,160514,,,N*40
$GPRMC,124712.667,V,,,,,0.05,330.27,160514,,,N*4E
$GPRMC,124712.767,V,,,,,0.18,330.27,160514,,,N*43
$GPRMC,124712.867,V,,,,,0.09,330.27,160514,,,N*4C
$GPRMC,124712.967,V,,,,,0.02,330.27,160514,,,N*46
$GPRMC,124713.067,V,,,,,0.11,330.27,160514,,,N*4C
$GPRMC,124713.167,V,,,,,0.02,330.27,160514,,,N*4F
$GPRMC,124713.267,V,,,,,0.06,330.27,160514,,,N*48
$GPRMC,124713.367,V,,,,,0.13,330.27,160514,,,N*4D
$GPRMC,124713.467,V,,,,,0.02,330.27,160514,,,N*4A
$GPRMC,124713.567,V,,,,,0.04,330.27,160514,,,N*4D
$GPRMC,124713.667,V,,,,,0.10,330.27,160514,,,N*4B
$GPRMC,124713.767,V,,,,,0.11,330.27,160514,,,N*4B


Last edited by Don Cragun; 07-03-2014 at 06:06 PM.. Reason: Add CODE tags.
# 2  
Old 07-03-2014
What output would you like from that input? You have not labelled your columns.
# 3  
Old 07-03-2014
Try this:

Code:
awk -F, 'NR>1 && $2-p != "0.1" {print} {p=$2}' infile

This User Gave Thanks to Chubler_XL For This Post:
# 4  
Old 07-04-2014
Hi Chubler,

I tried your post
Code:
awk -F, 'NR>1 && $2-p != "0.1" {print} {p=$2}' gps_time_stamp.txt > test4.txt

But the ouput is equal to gps_time_stamp.txt but without the first line

I will try to debug and understand why, since I am not really fluent in awk I need some more time to understand what it is doing .-)

test4.txt result
Code:
124651.264
124651.364
124651.464
124651.564
124651.664

gps_timestampt.txt
Code:
124651.164
124651.264
124651.364
124651.464
124651.564
124651.664
124651.764
124651.864

---------- Post updated at 10:58 AM ---------- Previous update was at 10:56 AM ----------

I was a little bit rude I forgot to say : Thanks you Smilie

Last edited by Franklin52; 07-04-2014 at 11:38 AM.. Reason: Please use code tags
# 5  
Old 07-06-2014
I finally understood your awk line. It is working perfectly. I tried to google about "p" variable. But I did not found anything yet. I assume it is meaning the "previous" line output that awk delimited by the character "," specified by the -F option.

I will need now to convert the hourminsec string into sec only to avoid incorrect substraction from 59sec to the next mintute.

Thanks for you help.
# 6  
Old 07-06-2014
What the code "means"
Code:
awk -F, 'NR>1 && $2-p != "0.1" {print} {p=$2}' gps_time_stamp.txt > test4.txt

The red bit executes for every line of code. So after line #1 p is equal to what is in field #2.

The green executes for any line greater than than 1 - in this case every subsequent line after the very first one. It prints all fields in the record, if the result of substraction is not equal to .1

awk lets you write very concise code, which can be confusing unless you have previous programming experience.

As an aside, awk uses floating point arithmetic, using what is called double precision. Some numbers cannot be precisely represented in a double floating point variable. That is why ChublerXL uses quotes to force a string comparison. awk is okay with this wacky kind of implicit polymorphism. Otherwise, in theory, you could get a lot of false positives.

Last edited by jim mcnamara; 07-06-2014 at 08:43 AM..
# 7  
Old 07-08-2014
Hi jim

thanks for the explanation. I was not aware that adding quotes generate string comparison. So I was doing incorrect modification since I change != by > whereas I keep the quotes.
Currently I tried to convert the hhmmss time stamp into second only but with not very much success. I was able to generate 3 files. one with the hour convert into sec. Another file with the min convert into sec. And the last one with second only. I need now to add for each line the 3 files PLUS the millisecond.
I am not sure it is the most optimal way, but currently I do not know how to extract the hour, the min and the second from my file. Since there is no delimiter. I used the following cut unix tool.

echo " Print GPS HOUR parameter in gps_hour_time_stamp.txt"
awk -F. '{print $1}' gps_time_stamp.txt | cut -c1-2 > gps_hour_time_stamp.txt
echo " Convert GPS HOUR parameter into Seconds in gps_hour2sec_timestamp.txt"
awk '{print $1*3600}' gps_hour_time_stamp.txt > gps_hour2sec_timestamp.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UTC to GPS

Gents, Kindly can u help with this. I would like to get GPS time from UTC Input 17/11/27 03:13:50:480000 17/11/27 03:12:54:380000 17/11/27 03:14:39:980000 output desired. 17/11/27 03:13:50:480000 1195787648480000 17/11/27 03:12:54:380000 1195787592380000 17/11/27... (6 Replies)
Discussion started by: jiam912
6 Replies

2. Shell Programming and Scripting

Delta from the first digit

Thanks of your suggestions i was able to calculate the delta between some numbers in a column file with . awk 'BEGIN{last=0}{delta=$1-last; last=$1; print $0" "delta}' the file was like 499849120.00 500201312.00 500352416.00 500402784.00 500150944.00 499849120.00 500150944.00... (3 Replies)
Discussion started by: Board27
3 Replies

3. Shell Programming and Scripting

Nested if statements with word/number extracts

Hi everyone! I'm having difficulties setting up a complex script with nested if statements while doing some word extracts, any help is appreciated. Scenario: 1- Check if the file.txt has the word BINGO 2- If so then get the available number (any number) in the line that contains the word... (8 Replies)
Discussion started by: demmel
8 Replies

4. Shell Programming and Scripting

File delta detection

Hello, I need to compare two flat files (ASCII format), say file OLD and file NEW. Both have similar structure. These files are | delimitted files and have around few million of records (lines) each. Each file has same set columns and same set of key columns (i.e. the 3rd and 5th column of the... (7 Replies)
Discussion started by: manubatham20
7 Replies

5. UNIX for Advanced & Expert Users

Extracts files names and write those to another file in different directory

Hi , Need to shell script to extracts files names and write those to another file in different directory. input file is inputfile.txt abc|1|bcd.dat 123 david123 123 rudy2345 124 tinku5634 abc|1|def.dat 123 jevid123 123 qwer2345 124 ghjlk5634 abc|1|pqr.txt 123 vbjnnjh435 123 jggdy876... (9 Replies)
Discussion started by: dssyadav
9 Replies

6. Shell Programming and Scripting

Creating DELTA file in UNIX

I have a fixed length file (854 characters file). Our project will start getting this file soon. On the first day this file will have 100000 records. From the next day the file will have all the records from previous day + some new records (there will be few additions + few changes in day1... (13 Replies)
Discussion started by: varunrbs
13 Replies

7. Shell Programming and Scripting

How to have a Script that extracts files?

Hi, I know there is a way to have a script that include files in a way that once we run the script, it would extract those files. Kinda similar to how zip files work. For example: - I have a script called test.sh - Once I run this script, it will extract file1, file2 and file3 and then... (2 Replies)
Discussion started by: pgarousi
2 Replies

8. Shell Programming and Scripting

Getting MAC from GPS unit

Never mind i got the answer thanks., (0 Replies)
Discussion started by: deaconf19
0 Replies

9. Solaris

Daylight Savings Time Fix

Hello, I've been looking at coming up with a time change on my Sun workstations since daylight savings time comes early this year. Someone at work told me that a sun patch is available if you have a maintenance contract. It was recommended to just set your systems to GMT time zone. How is this... (5 Replies)
Discussion started by: stocksj
5 Replies
Login or Register to Ask a Question