close all
clear all

MeanBuoy_lat = 36.77231;
MeanBuoy_lon = -121.86447;
[MeanBuoy_Easting, MeanBuoy_Northing,utmZone] = deg2utm(MeanBuoy_lat,MeanBuoy_lon);



Anchor_400lb_lat = 36.773940;
Anchor_400lb_lon = -121.867171;
[Anchor_400lb_Easting, Anchor_400lb_Northing,utmZone] = deg2utm(Anchor_400lb_lat,Anchor_400lb_lon);



Anchor_500lb_lat = 36.770950;
Anchor_500lb_lon = -121.862218;
[Anchor_500lb_Easting, Anchor_500lb_Northing,utmZone] = deg2utm(Anchor_500lb_lat,Anchor_500lb_lon);



hourly_data_file = '../HourlyResults/HourlyAverages.mat'

decoded_data_path = '../DecodedResults/';


load(hourly_data_file);

idx = 307:length(HourlyData.baseFileDateNum);
%find(HourlyData.baseFileDateNum > datenum(2025,5,1,12,0,0))

j = 0;
for i = idx
  j = j+1;
  data = load([decoded_data_path HourlyData.baseFilename{i} '_raw.mat']);
  Lat{j} = data.XB_Lat;
  Lon{j} = data.XB_Lon;
  DateNum{j} = data.XB_Time;
  [Easting{j},Northing{j}, utmZone] = deg2utm(Lat{j},Lon{j});

  disp(['Loaded ' num2str(j) ' of ' num2str(length(idx))]);
end
Final_Lat = Lat{end}(end);
Final_Lon = Lon{end}(end);

[Final_Easting,Final_Northing, utmZone] = deg2utm(Final_Lat,Final_Lon);


fh1 = figure
plot(Anchor_500lb_lon,Anchor_500lb_lat,'kx');
hold all
plot(Anchor_400lb_lon,Anchor_400lb_lat,'bx');

for j = 1:length(Lat)
  plot(Lon{j},Lat{j},'b.');
end
plot(Final_Lon,Final_Lat,'ro');

xlabel("Longitude");
ylabel("Latitude");
title([HourlyData.baseFilename{1} ' - ' HourlyData.baseFilename{end}]);
grid on





fh2 = figure
plot(Anchor_500lb_Easting-MeanBuoy_Easting,Anchor_500lb_Northing-MeanBuoy_Northing,'kx');
hold all
plot(Anchor_400lb_Easting-MeanBuoy_Easting,Anchor_400lb_Northing-MeanBuoy_Northing,'bx');

for j = 1:length(Easting)
  plot(Easting{j}-MeanBuoy_Easting,Northing{j}-MeanBuoy_Northing,'b.');
end
plot(Final_Easting-MeanBuoy_Easting,Final_Northing-MeanBuoy_Northing,'ro');

xlabel("Easting (m)");
ylabel("Northing");
title([HourlyData.baseFilename{1} ' - ' HourlyData.baseFilename{end}]);
grid on


figure
hold on;
for j = 1:length(DateNum)
Distance = ((Easting{j}-MeanBuoy_Easting).^2 + (Northing{j}-MeanBuoy_Northing).^2).^.5;
%plot(DateNum{j},Easting{j}-MeanBuoy_Easting,'b-');
plot(DateNum{j},Distance,'b-');

end
grid on;
datetick('x')
ylabel('m');


