clear all
mission = '24403401';
filepath = ['\\atlas.shore.mbari.org\ProjectLibrary' ...
    '\901805_Coastal_Biogeochemical_Sensing\Spray_Data' ...
    '\',num2str(mission),'\sat_files\',num2str(mission),'_sat.mat'];
load(filepath,'eng')
load(filepath,'s')
%%
figure(1)

lat = s.lat(end-5:end);
lon = s.lon(end-5:end);
geobasemap satellite
geoscatter(lat,lon,100,'red','filled','diamond')
mosslat = 36.80594819607352;
mosslon = -121.786377002975;
ellipsoid = wgs84Ellipsoid('miles');
dist = abs(distance(mosslat, mosslon, lat, lon,ellipsoid));
if dist < 30
    n = 1;
    geolimits([lat(end)-n lat(end)+n],[lon(end)-n lon(end)+n])
else
    n = 2;
    geolimits([lat(end)-n lat(end)+n],[lon(end)-n lon(end)+n])
end
grid off
%% 
% basemapName = 'Ocean Basemap';
% webmap 'Ocean Basemap'
% Import the necessary package

% 
% basemapName = "WorldOceanBasemap";
% url = "https://services.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer";
% 
% 
basemapName = "myCustomMap";
url = "https://topex.ucsd.edu/pub/global_topo_1min/";
addCustomBasemap(basemapName, url);
webmap('myCustomMap');
%% 
webmap('World Street Map')
%%
pres = eng.pres(:,end); % estimations based on previous dive
secs = eng.secs(:,end);
estdivetimesecs = secs - min(secs(:));

figure(2)
% plot(estdivetimesecs,pres,'o',Color=[.7 .7 .7])
set(gca,"YDir",'reverse')
xlim([min(secs) max(secs)])
ylim([min(pres) max(pres)])
grid on
hold on
dt = datetime(datevec(s.sdn_(2,end))); % Spray surface / end of dive
dt.TimeZone = "UTC";
dt.TimeZone = "local";
while(1)
    ddt = datetime('now','TimeZone','local') - dt;
    ddt.Format = "s";
    [~,ii] = min(abs(estdivetimesecs - seconds(ddt)));
    plot(estdivetimesecs(1:ii),pres(1:ii),'-o',Color='b')
    title(datestr(datetime('now','TimeZone','local')))
    if seconds(ddt) > max(secs)
        clf;
        imshow('gliderwithjoe.jpg');
        text(190,200,'WAITING FOR DATA','Color','white','FontSize',20)
        break
    end
    pause(1)  
end