#!/bin/bash
#
# PURPOSE: Create Matlab-readable file of the avu location and time-stamps from
#	   the Winfrog log file.
# AUTHOR:  Rob McEwen
# DATE:    00/6/8
#
# NOTES:1) See page B-7 of the Winfrog User's Guide for the format description.

 if [ $1 ]
 then
   echo "Converting USBL data ..."
 else
   echo "cvtwfq: Please furnish a file name."
   exit -1
 fi
#
# The Winfrog on the Healy 2001 generated a .DAT with the following 
# columns:
#
# 1 2                   3           4            5 6          7         8    
# 0,10-24-01 10:58:09.1,N81 00.8440,E016 08.3090,0,8994969.29,519850.82,0.00,
#
# 9    10   11    12    13   14   15   16    17   18   19   20   21   22
# 0.00,0.00,21.57,63.23,1.67,0.00,NONE,0.000,0.00,0.00,0.00,0.00,0.00,Support
# Ship,
#
# 23          24           25     26         27        28   29  30    31   
# N81 01.0441,E016 09.0412,-50.00,8995345.62,520056.19,0.00,0.00,0.00,53.94,
#
# 32    33    34   35   36    37   38   39   40   41   42 
# 53.94,10.34,0.00,NONE,0.000,0.00,0.00,0.00,0.00,0.00,AUV
#
#
 echo "usbl = [ ... " > dataUsbl.m
#                1 2 3  4  5  6  7  8  9  10 11 12 13
 cat $1 | cut -f 6,7,11,12,13,26,27,28,29,30,31,32,33 -d "," >> dataUsbl.m
 echo " ];" >> dataUsbl.m
#
# The following used to extract only the time portion.  I've changed it to
# put the entire mm-dd-yy in the string, so that datenum will reference 
# 1 Jan 0000. Then, we can synchronize this with the vehicle time, which is 
# seconds since 1 Jan 1970, 00:00:00 (midnight).
#
#cat $1 | cut -f 2 -d "," | cut -f 2 -d " " > temp.txt
 cat $1 | cut -f 2 -d "," > temp.txt
#
# This gnarly sed command inserts a ' at the start and end of each line.
#
 cat temp.txt | sed 's/^/'\''/' | sed 's/$/'\''/' > temp1.txt


 echo "usblTime = [ ... " > dataUsblTime.m
 cat temp1.txt >> dataUsblTime.m
 echo " ];" >> dataUsblTime.m

 rm temp.txt
 rm temp1.txt


