clear all; close all;
gdata = readtable("Diel_GPP_log_QC_Revised.csv");
mission = 7;
idiel = gdata.StartProf(mission):gdata.EndProf(mission); % before DIC starts decreasing
filename = char(gdata.Filename(mission));
load(filename, 's'); % .mat file
%% get lat/lon
s.dt_UTC = datetime(s.sdn,'ConvertFrom','datenum','TimeZone','UTC');
s.dt_PT = s.dt_UTC;
s.dt_PT.TimeZone = "America/Los_Angeles";
s.sdn = datenum(s.dt_PT); % convert from UTC to local for these calculations
%% Create variables for calculations
time7 = s.sdn(idiel);
datetime7 = s.dt_PT(idiel);
depth7 = abs(s.depth(:,idiel)); % make depth positive
lat7 = s.lat(idiel);
lon7 = s.lon(idiel);
%%
mission = 8;
idiel = gdata.StartProf(mission):gdata.EndProf(mission); % before DIC starts decreasing
filename = char(gdata.Filename(mission));
load(filename, 's'); % .mat file
%% Create variables for calculations
depth8 = abs(s.depth(:,idiel)); % make depth positive
lat8 = s.lat(idiel);
lon8 = s.lon(idiel);
%%
mission = 3;
idiel = gdata.StartProf(mission):gdata.EndProf(mission); % before DIC starts decreasing
filename = char(gdata.Filename(mission));
load(filename, 's'); % .mat file
%% Create variables for calculations
depth3 = abs(s.depth(:,idiel)); % make depth positive
lat3 = s.lat(idiel);
lon3 = s.lon(idiel);
%% Create nice figure
% Define your lat/lon and sampling radius (in km)
centerLat = mean(lat);
centerLon = mean(lon);
radius_km = 1;  % Example radius

% Compute circle coordinates using scircle1
[clat, clon] = scircle1(centerLat, centerLon, km2deg(radius_km));

% Plot the map
mapfig_mission7 = figure;
clf
geoscatter(lat, lon, 30, 'black', 'filled')
hold on
geoplot(clat, clon, 'r-', 'LineWidth', 2)  % red circle
geobasemap('topographic')
title('Sampling Points and Radius')
legend('Spray Location','1 km')
%%
% MBARI
mosslat = 36.80594819607352;
mosslon = -121.786377002975;
% CalCOFI Line 67
CalCOFI67 = ...
[50	36.7869600000000	-122.056330000000
55	36.6202900000000	-122.414820000000
60	36.4536300000000	-122.772540000000
65	36.2869600000000	-123.129480000000
70	36.1202900000000	-123.485650000000
75	35.9536300000000	-123.841060000000
80	35.7869600000000	-124.195710000000
85	35.6202900000000	-124.549620000000
90	35.4536300000000	-124.902780000000
95	35.2869600000000	-125.255200000000
100	35.1202900000000	-125.606890000000];
CalCOFI67Description = strsplit(num2str(CalCOFI67(:,1)')); 
% M1
M1Lat = 36.75901;
M1Lon = -122.02019;

% Create a geographic axes
ax = geoaxes('Basemap','WorldOceanBaseMap');
hold(ax, 'on');
% Plot MBARI
geoplot(ax, mosslat, mosslon, "^", 'Color', '#FF00FF', 'MarkerFaceColor', '#FF00FF', 'DisplayName', 'MBARI', 'MarkerSize', 10);
% ax.Title.String = Maptitle;
% ax.Title.Visible = "on";
% Plot CalCOFI Line 67
geoplot(ax, CalCOFI67(:,2), CalCOFI67(:,3), 's', 'MarkerFaceColor', '#FFFF00', 'MarkerEdgeColor', 'none', 'DisplayName', 'CalCOFI Line 67', 'MarkerSize', 10);
% Plot M1
geoplot(ax, M1Lat, M1Lon, 'p', 'Color', '#00FFFF', 'MarkerFaceColor', '#00FFFF', 'DisplayName', 'M1 Mooring', 'MarkerSize', 10);
% Plot Spray Location 3
geoscatter(lat3, lon3, 30, 'green', 'filled')
% Plot Spray Location 7
geoscatter(lat7, lon7, 30, 'black', 'filled')
% Plot Spray Location 8
geoscatter(lat8, lon8, 30, 'red', 'filled')

% Add descriptions for CalCOFI Line 67
offset = -0.01; % adjust this value to control the offset
for i = 1:length(CalCOFI67Description)
    text(CalCOFI67(i,2) + offset, CalCOFI67(i,3) + offset, CalCOFI67Description{i}, 'Color', '#FFFF00', 'FontSize', 10, 'HorizontalAlignment', 'right');
end
legend('MBARI','CalCOFI','M1','Mission3','Mission7','Mission8',Location='northwest')