function mtm_plotgps

% Plot data within the last 12 hours
startTime = now - 0.5;
[year, month, day, hour, minute, second] = datevec(startTime);
startDate = sprintf('%04i%02i%02i.%02i%02i%02i', year, month, day, hour, minute, round(second));

% Call Java from Matlab to access a URL
url = java.net.URL(['http://predator.shore.mbari.org:8081/ssds/servlet/GetOriginalData?deviceID=1004&metadataID=1&recordTypeID=1&platformID=1009&isi=1&startDateTime=' startDate 'endDateTime=29991231.235959']);
is = openStream(url);
isr = java.io.InputStreamReader(is);
br = java.io.BufferedReader(isr);

% Loop through each line retrieved and try to parse it.
% If its an HTML tag the parsing will be caught in the try/catch block
i = 1;
while(1)
    s = char(readLine(br));
    if isempty(s)
        break;
    end
    try
        time(i) = datenum(stringtokenizer(s, 2, ','));
        latBuf = stringtokenizer(s, 7, ',');
        lonBuf = stringtokenizer(s, 9, ',');
        latitude(i) = str2num(latBuf(1:2)) + str2num(latBuf(3:end))/60;
        longitude(i) = -(str2num(lonBuf(1:3)) + str2num(lonBuf(4:end))/60);
        i = i + 1;
    catch

    end

end

% Double check that we're only plotting the last 12 hours
good = find(time > now - 0.5);

plot(longitude(good), latitude(good), 'k.');
hold on;
plot(longitude(end), latitude(end), 'ro');
th = text(longitude(end), latitude(end), [datestr(time(end)) ' GMT']);
set(th, 'Color', [1 0 0])
xlabel('Longitude (decimal degrees +E/-W)');
ylabel('Latitude (decimal degrees +N/-S)');
axis('equal')
grid('on')

set(gcf, 'PaperPosition', [0 0 5 4])
[latd, latm, lats] = dd2dms(latitude(end));
[lond, lonm, lons] = dd2dms(longitude(end));
lS = sprintf('Most recent position (%4i^o %02i'' %04.1f" N  %4i^o %02i'' %04.1f" E)', latd, latm, lats, lond, lonm, lons);
legend('Position (last 12 hours)', lS, 0);
title('MBARI MOOS Test Mooring position')
setfontsize(7)
% Hold on to the track limits
XLim = get(gca, 'XLim') + [-0.01 0.01];
YLim = get(gca, 'YLim') + [-0.01 0.01];
% Add the coastline.
load('CST');
plot(CST(:, 1), CST(:,2), '-', 'Color', [0.6 0.6 0.6])
set(gca, 'XLim', XLim, 'YLim', YLim);



