clear
close all

wgs84=almanac('earth','wgs84');
wgs84(1) = wgs84(1) * 1000.0;

drifterLonLat = importdata('DrifterTrack.txt');
LonDeg = drifterLonLat(:,4);
LonMin = drifterLonLat(:,5);
drifterLon = LonDeg - LonMin/60.0;
LatDeg = drifterLonLat(:,2);
LatMin = drifterLonLat(:,3);
drifterLat = LatDeg + LatMin/60.0;
[drifterDistMatlab, drifterAz]=distance(drifterLat(end),drifterLon(end),drifterLat(1),drifterLon(1), wgs84);

p1 = [drifterLat(end), drifterLon(end)];
z1 = utmzone(p1);
utmstruct = defaultm('utm');
utmstruct.zone = z1;
utmstruct.geoid = wgs84;
utmstruct = defaultm(utmstruct);
[x1,y1] = mfwdtran(utmstruct,drifterLat(1),drifterLon(1));
[x2,y2] = mfwdtran(utmstruct,drifterLat(end),drifterLon(end));
deltaX = x2 - x1;
deltaY = y2 - y1;
drifterDistUTM = sqrt( deltaX^2 + deltaY^2 );

meloLonLat = importdata('SIDMeloFixesSep10.txt');
meloLon = meloLonLat(:,4);
meloLat = meloLonLat(:,3);
[meloDistMatlab, meloAz]=distance(meloLat(end),meloLon(end),meloLat(1),meloLon(1), wgs84);

sableLonLat = importdata('SIDSableFixesSep10.txt');
sableLon = sableLonLat(:,4);
sableLat = sableLonLat(:,3);
[sableDistMatlab, sableAz]=distance(sableLat(end),sableLon(end),sableLat(1),sableLon(1), wgs84);

SG148LonLat = importdata('SG148FixesSep11.txt');
SG148Lon = SG148LonLat(:,4);
SG148Lat = SG148LonLat(:,3);
[SG148DistMatlab, SG148Az]=distance(SG148Lat(end),SG148Lon(end),SG148Lat(1),SG148Lon(1), wgs84);
SG148EOTLat = 24.0 + 45.0/60.0;
SG148EOTLon = -156.0 - 30/60.0;

StationLonLat = importdata('KM1125stations.txt');
StationLon = StationLonLat(:,4);
StationLat = StationLonLat(:,3);

h = axesm(  'mapprojection', 'mercator', ...
            'maplatlim', [20 25.25], ...
            'maplonlim', [-160 -155], ...
            'grid', 'on', 'frame', 'on', ...
            'MLineLocation', 1, 'PLineLocation', 1, ...
            'meridianLabel', 'on', 'parallelLabel', 'on');
geoshow('landareas.shp', 'FaceColor',  [0.5 0.7 0.5])
hDrifter = geoshow(drifterLat, drifterLon, 'DisplayType', 'line', 'Color', 'red', 'LineWidth', 3);
% geoshow(meloLat, meloLon, 'DisplayType', 'line', 'Color', 'green', 'LineWidth', 10);
hSable = geoshow(sableLat, sableLon, 'DisplayType', 'line', 'Color', 'yellow', 'LineWidth', 3);
hSG148Line = geoshow(SG148Lat, SG148Lon, 'DisplayType', 'line', 'Color', 'blue', 'LineWidth', 3);
hSG148EOT = geoshow(SG148EOTLat, SG148EOTLon, 'DisplayType', 'point', 'MarkerEdgeColor', 'blue', ...
                                  'MarkerSize', 6, 'LineWidth', 1.5);
hStation = geoshow(StationLat, StationLon, 'DisplayType', 'point', 'MarkerEdgeColor', 'magenta', ...
                                  'MarkerSize', 6, 'LineWidth', 1.5);

load('FSLE_Sept8_2011.mat');
newlon1 = -1.0 * (360 - newlon0);
x11 = newlon1(1);
y11 = newlat0(1);
[r, c] = size(fsle_hr);
dx = (newlon1(end) - newlon1(1)) / c;
dy = (newlat0(end) - newlat0(1)) / r; 
R = makerefmat(x11, y11, dx, dy);
[C,hFSLE] = contourm(fsle_hr*24*3600, R, [0.0:0.1:0.5]);
                              
load('SSH_Sept8_2011.mat');
ssh_lonvec1 = -1.0 * (360 - ssh_lonvec);
x11 = ssh_lonvec1(1);
y11 = ssh_latvec(1);
[r, c] = size(ssh);
dx = (ssh_lonvec1(end) - ssh_lonvec1(1)) / c;
dy = (ssh_latvec(end) - ssh_latvec(1)) / r; 
R = makerefmat(x11, y11, dx, dy);
[C,hSSH] = contourm(ssh, R, 'ShowText', 'on');

hArray = [hDrifter hSable hSG148Line hSG148EOT hStation];
hLegend = legend(hArray,'ESP', 'SID', 'SG148', 'SG148EOT', 'KM Stations', ...
    'Location', [.4 .26 .005, .005]);
set(hLegend, 'FontSize', 4);
scaleruler('MajorTick', [0 50 100], 'MinorTick', [37.040], 'MinorTickLabel', '20nm', ...
           'XLoc', -0.03, 'Yloc', .377, 'FontSize', 6, 'RulerStyle', 'patches')
