% map_monterey.m
% Build figure maps for CPF
clear;
base_map_only=1;

% ***********************************************************************
% SET NAMES & PATHS
% ***********************************************************************



%range1 = [35.6 37.9 -123.25 -121]; % BIG
%range2 = [36.6 37.0 -122.25 -121.77]; % ZOOM
%range2 = [24.8 25.4 -81.14 -80.26];
lonmin = -122.25;
lonmax = -121.77;
latmin = 36.6;
latmax = 37.0;
maxP = -1100;

%Extract topograpy data
% mbay      = getbathy(range1, 5); % get topo data from etopo2
% mbay_zoom = getbathy(range2, 5); % get topo data from local netcdf
%  
% save mbay_mapdata

%pause

if exist('mbay','var') ~=1 % var loaded in the work space
   load mbay_mapdata.mat;
end
load mbay_colormaps
% ************************************************************************
% ************************************************************************
% BUILD THE FIGURES IN 2 PARTS. THIS IS ONE WAY TO PRESERVE DIFFERENT
% COLORMAPS FOR DIFFERNT AXES & PLOTS WITHIN A FIGURE WINDOW (TIP FROM JOHN RYAN).
% FIRST BUILD TOPO MAPS WITH ONE COLORMAP FOR PLOT BACKGROUNDS & SAVE AS
% JPEG. Then paste the JPEG image into the axes before plotting with
% differnt colormap

%T1 = mbay.topo >= 0; % Mask out the land
%mbay.topo(T1) = 100;

%T2 = mbay_zoom.topo >= 0; % Mask out the land
%mbay_zoom.topo(T2) = 1000;

%T3 = mbay_zoom.topo <= maxP; % Mask out the > maxP depths
%mbay_zoom.topo(T3) = maxP; 


% % MONTEREY JPEG
% figure(1) % MONTEREY  LOCATION MAP
% %clevs =-6500:500:0;
% contourf(mbay.lon,mbay.lat,mbay.topo,30,'linecolor','none');
% 
% mbay_ax = [xlim ylim]; % get axis bounds for later
% caxis([min(mbay.topo(:)) 0]);
% set(gcf,'Colormap',mbay_cmap);%,'Menubar','none','ToolBar','none')
% 
% 
% set(gca,'XLim',range1(3:4),'YLim',range1(1:2));%, ...
% %     'XTick',[-85 -80 -75 -70], ...
% %     'Ytick',[22 25 28 31]);

% ************************************************************************% FLORIDA ZOOM JPEG
figure; % MONTEREY  LOCATION MAP
%clevs = -500:25:0;
ax1=surf(mbay_zoom.lon,mbay_zoom.lat,mbay_zoom.topo,'FaceColor','interp','EdgeColor','none');%
alpha(0.5);
view(2);
hold on;
contour_depths = [maxP -1000 -500 -100 -50 0];
v = [-1000,-500,-100,-50]; %contour labels
[C,h]=contour(mbay_zoom.lon,mbay_zoom.lat,mbay_zoom.topo,contour_depths,'k');%,'TextList',[-1000 -500 -100 -50]);
clabel(C,h,v);
%mbay_zoom_ax = [xlim ylim]; % get axis bounds for later
set(gca,'xlim',([lonmin lonmax]),'ylim',([latmin latmax]));
%caxis([min(mbay_zoom.topo(:)) 0]);
caxis([maxP 0]);
set(gcf,'Colormap',mbay_cmap);%,'Menubar','none','ToolBar','none')
%, ...
%     'XTick',[-85 -80 -75 -70], ...
%     'Ytick',[22 25 28 31]);
cb = colorbar;
set(cb,'ytick',[-1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 -50 0]);


if(base_map_only==0)
    index = [13 size(lon,2)-1];

    hold on;
    plot(lon(index(1):index(2)),lat(index(1):index(2)),'rx');
    plot(lon(index(1):index(2)),lat(index(1):index(2)),'--');

    %set(gca,'Position',[0,0,1,1],'Box','off','Xtick',[],'Ytick',[])
    % print -djpeg FL.jpg
    %close(1)

    offset = .01;
    str = sprintf('prof %d',prof(index(1)));
    text(lon(index(1))+offset,lat(index(1))+offset,str,'Fontsize',8,'color','m','edgecolor','k','backgroundcolor','w');
    x = [lon(index(1)) lon(index(1))+offset];
    y = [lat(index(1)) lat(index(1))+offset];
    plot(x,y,'m');

    str = sprintf('prof %d',prof(index(2)));
    text(lon(index(2))+offset,lat(index(2))+offset,str,'Fontsize',8,'color','m','edgecolor','k','backgroundcolor','w');
    x = [lon(index(2)) lon(index(2))+offset];
    y = [lat(index(2)) lat(index(2))+offset];
    plot(x,y,'m');
    title(parsed);
    grid on;
end


T3 = mbay_zoom.topo <= 0; % Mask out the > maxP depths
mbay_zoom.topo(T3) = NaN; 

ax2=surf(mbay_zoom.lon,mbay_zoom.lat,mbay_zoom.topo,'FaceColor','interp','EdgeColor','none');


%waypoints
C1 = [36.797 -121.847];
M1 = [36.750 -122.022];
M2 = [36.691 -122.376];
plot(C1(2),C1(1),'go','MarkerEdgeColor','k','MarkerFaceColor','g');
plot(M1(2),M1(1),'go','MarkerEdgeColor','k','MarkerFaceColor','g');
plot(M2(2),M2(1),'go','MarkerEdgeColor','k','MarkerFaceColor','g');




%fig_h_background=gcf;
%axes_h_background = gca;
savefig('mbay_topo.fig');







