data = readtable("binnedCUGN66_dfdf_944c_f7b3.csv");
data = sortrows(data,"profile");
time = data.time;
% Convert to datetime (UTC)
dt = datetime(time, 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss''Z''', 'TimeZone', 'UTC');

% Convert to datenum
data.sdn = datenum(dt);
%%
nprofs = data.profile(end-1)-data.profile(2);
timegrid = linspace(min(data.sdn),max(data.sdn),nprofs+1);
depthgrid = 10:10:500;
tempgrid = reshape(data.temperature(1:end-1),50,[]);
psalgrid = reshape(data.salinity(1:end-1),50,[]);
chlgrid = reshape(data.chlorophyll(1:end-1),50,[]);
doxgrid = reshape(data.doxy(1:end-1),50,[]);
latgrid = reshape(data.latitude(1:end-1),50,[]);
longrid = reshape(data.longitude(1:end-1),50,[]);

s = struct;
s.sdn = timegrid;
s.depth = depthgrid;
s.lat = latgrid(1,:);
s.lon = longrid(1,:);
s.tc = tempgrid;
s.psal = psalgrid;
s.chl = chlgrid;
s.doxy = doxgrid;

save("SprayData_12122024","s");
%%
fig = figure;
tl = tiledlayout(2,2);
title(tl,'Contour plots: December 12, 2024')
nexttile
contourf(s.sdn,s.depth,s.tc)
set(gca,'Ydir','reverse')
datetick('x',15,'keeplimits')
title('Temperature (C)')
ylim([0 300])
colorbar

nexttile
contourf(s.sdn,s.depth,s.psal)
set(gca,'Ydir','reverse')
datetick('x',15,'keeplimits')
title('Salinity (PSU)')
ylim([0 300])
colorbar

nexttile
contourf(s.sdn,s.depth,s.chl)
set(gca,'Ydir','reverse')
datetick('x',15,'keeplimits')
title('Chlorophyll-a (mg m^-3) ')
ylim([0 300])
colorbar

nexttile
contourf(s.sdn,s.depth,s.doxy)
set(gca,'Ydir','reverse')
datetick('x',15,'keeplimits')
title('Dissolved Oxygen (\mumol/kg)')
ylim([0 300])
colorbar

mapfig = figure;
geoscatter(s.lat,s.lon)