% map_monterey.m
% Build figure maps for CPF
clear;

faucon = [36.900520 -122.342180];
fauc_deploy = [36.90028 -122.34198];
debris = [36.900002 -122.342307; %fairing
    36.900518 -122.342278; %xmitter
    36.900408 -122.342360; %cone
    36.900536 -122.342148]; %WG est


% ***********************************************************************
% SET NAMES & PATHS
% ***********************************************************************
lat = ncread('socal_1as.nc','lat');
lon = ncread('socal_1as.nc','lon');
z = ncread('socal_1as.nc','Band1');
load mbay_colormaps;

lonmin = -122.3426;
lonmax = -122.3418;
latmin = 36.8999;
latmax = 36.9007;
maxP = -1000;

%dat=load('socal_1as.xyz');

figure;hold on; 
h=contourf(lon,lat,z,200,'linecolor','none');
set(gca,'xlim',([lonmin lonmax]),'ylim',([latmin latmax]));
caxis([-750 -550]);
set(gcf,'Colormap',mbay_cmap);%,'Menubar','none','ToolBar','none')
cb = colorbar;
set(cb, 'ylim', [-675 -600])
%set(cb,'ytick',[-650 -625 -600]);


plot(faucon(1,2),faucon(1,1),'rx');
plot(fauc_deploy(1,2),fauc_deploy(1,1),'ro');
plot(debris(:,2),debris(:,1),'k+');


%switch to utm for measurements
[x,y]=deg2utm(lat,lon);
[lonmin,latmin]=deg2utm(latmin,lonmin);
[lonmax,latmax]=deg2utm(latmax,lonmax);

%reorient 0,0 to Faucon recovery for measurements
[utmfaucx,utmfaucy]= deg2utm(faucon(1,1),faucon(1,2));

x_offset = utmfaucx;
y_offset = utmfaucy;
x = x-x_offset;
y = y - y_offset;
lonmax = lonmax-x_offset;
lonmin = lonmin-x_offset;
latmax = latmax-y_offset;
latmin = latmin-y_offset;


figure;hold on; 
h=contourf(x,y,z,200,'linecolor','none');
set(gca,'xlim',([lonmin lonmax]),'ylim',([latmin latmax]));
caxis([-750 -550]);
set(gcf,'Colormap',mbay_cmap);%,'Menubar','none','ToolBar','none')
cb = colorbar;
set(cb, 'ylim', [-675 -640])
%set(cb,'ytick',[-650 -625 -600]);


%convert faucon deployment
[utmfdepx,utmfdepy]=deg2utm(fauc_deploy(1,1),fauc_deploy(1,2));
utmfdepx = utmfdepx-x_offset;
utmfdepy = utmfdepy-y_offset;
plot(utmfdepx,utmfdepy,'ro');

%convert debris and plot
[utmdebrisx,utmdebrisy]=deg2utm(debris(:,1),debris(:,2));
utmdebrisx = utmdebrisx-x_offset;
utmdebrisy = utmdebrisy-y_offset;
plot(utmdebrisx,utmdebrisy,'k+');

%draw line from deploy to recover
lx = [0 utmfdepx];ly = [0 utmfdepy];
plot(lx,ly,'r--');
len = (lx(2)^2 + ly(2)^2)^0.5; %meters
str = sprintf('%3.1f m',len);
text(10,-10,str,'Color','r');

%draw line from deploy to fairing
lx = [0 utmdebrisx(1)];ly = [0 utmdebrisy(1)];
plot(lx,ly,'k--');
len = (lx(2)^2 + ly(2)^2)^0.5; %meters
str = sprintf('%3.1f m',len);
text(-5,-40,str,'Color','k');

plot(0,0,'rx'); %faucon recovery
plot(0,0,'ro'); %faucon recovery

%label
str = '\leftarrow CPF Recover';
text(2,0,str,'FontWeight','bold','Color','r');
str = 'CPF Deploy';
text(19,-22,str,'FontWeight','bold','Color','r')
str='Fairing';
text(-21,-55,str,'Color','k')
str='Xmitter';
text(-17,2,str,'Color','k')
str='Cone';
text(-22,-10,str,'Color','k')
str='WG Est';
text(4,4,str,'Color','k')

xlabel('Meters')
ylabel('Meters')
title('CPF Debris Field');
