% get_new_spar.m
% get new spar buoy data
%
% Step 1: read the email messages and save them (could just grab inbox???)
% Step 2: get junk out of file (by hand or using something smarter
%           like Perl)
% Step 3: run the DOS program: 104ARG47.exe (use 'processing.bat'
% to tell it the input file name. Use format: jul18.txt and jul18)
%
% Step 4: use the Excel way (cut and paste into excel spreadsheet)
%          OR
%         This program to:
%         get a Perl script to strip it to a flat file and load
%         into Matlab

% make the file a flat file
% before running the program copy the data file to local file newdata.in

% strip off top:
!tail +18 newdata.in | tr -d '"' > newdata.in2
!mk_flt_spar.pl newdata.in2  > newdata.flt

% get previous data
%load eddies_pos.txt
load eddies_pos
old_lat=lat;
old_lon=lon;

% load new data 
load newdata.flt
newlat = newdata(:,7)+newdata(:,8)/60;
newlon = -(newdata(:,9)+newdata(:,10)/60);

% append new data to old
lat=[old_lat' newlat']';
lon=[old_lon' newlon']';

% save data
save eddies_pos lat lon

% plot the data
plot(lon,lat,'.',lon(end),lat(end),'r*')
%set(gca,'xdir','reverse')
ax=axis;
axrat = 1/cos(mean(ax(3:4))*pi/180);
set(gca,'DataAspectRatio',[1 1/axrat 1]);

lat(end)
lon(end)

% make a latest time file
 !tail -9 newdata.in | head -1 > xxx
 !get_latest_time.pl xxx > last_spar_time.dat
 
