clear; close all;

% ------------ path setup ---------------------
% path to base of all VERTCON3 items
basepth = 'Q:\shared\VERTCON3\';
% local path to FlaggedGrids/Final products
pth = [basepth 'FlaggedGrids\FinalV2\'];
addpath([basepth 'VERTCON3toolbox']);
figPth = [basepth 'plots\'];
 % used to be 'C:\Users\andria.bilich\Documents\projects\VERTCON\';


cmap = 'jet';

% ------------ Alaska ---------------------
[pid,pt] = plotHtDiff([basepth 'vmacdoht.ngvd29.navd88.alaska.003']);
region = 'alaska';
figure
[lat, lon] = borders(region);
    plot(lon+360, lat,'k'); hold on
grid on
scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
colormap(cmap)
c = colorbar('southoutside');
c.Label.String = 'meters';
tightFig(gca);
axis([172 232 50 73])
print('-dpng',[figPth 'alaska_vmacd_all.png']);
axis equal
axis([211 214 64 66])
print('-dpng',[figPth 'alaska_vmacd_fairbanks.png']);



% ------------ American Samoa ---------------------
[pid,pt] = plotHtDiff([basepth 'vmacdoht.lt.asvd02.as.003']);
region = 'as';
figure
drawBoundaries2(region);
scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
colormap(cmap)
c = colorbar('southoutside');
c.Label.String = 'meters';
%xlim([144.3 145.3])
tightFig(gca);
axis([189.10 189.50 -14.40 -14.20])
print('-dpng',[figPth 'cnmi_vmacd_tutuila.png']);



% ------------ CNMI ---------------------
[pid,pt] = plotHtDiff([basepth 'vmacdoht.lt.nmvd03.cnmi.000']);
region = 'cnmi';
figure
drawBoundaries2(region);
scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
colormap(cmap)
c = colorbar('southoutside');
c.Label.String = 'meters';
%xlim([144.3 145.3])
tightFig(gca);
print('-dpng',[figPth 'cnmi_vmacd_all.png']);
axis([145 146 14 15.5])
print('-dpng',[figPth 'cnmi_vmacd_zoom.png']);



% ------------ Guam ---------------------
[pid,pt] = plotHtDiff([basepth 'vmacdoht.guvd63.guvd04.guam.000']);
region = 'guam';
figure
drawBoundaries2(region);
scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
colormap(cmap)
c = colorbar('southoutside');
c.Label.String = 'meters';
xlim([144.3 145.3])
tightFig(gca);
print('-dpng',[figPth 'guam_vmacd_all.png']);



% ------------ Virgin Islands ---------------------
zone = {'entire' 'stcroix', 'stthomas'};
axx = [294.9000  296.0000   17.0000   19.00;
         295.05 295.466667 17.633 17.833; 
         294.866667 295.20 18.250 18.450];
     
[pid,pt] = plotHtDiff([basepth 'vmacdoht.lt.vivd09.vi.000']);
region = 'vi';
figure
drawBoundaries2(region);
scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
axis(axx(1,:));
colormap(cmap)
c = colorbar('southoutside');
c.Label.String = 'meters';
tightFig(gca);
print('-dpng',[figPth 'vi_vmacd_all.png']);

figure
[ha, pos] = tight_subplot(1,2,0.05,[.01 .01],[.1 .01]);
for i = 1:2
    axes(ha(i));
    drawBoundaries2(region);
    scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
    colormap(cmap)
    axis(axx(i+1,:));
    set(ha(i), 'XTickLabelMode', 'auto') 
    set(ha(i), 'YTickLabelMode', 'auto')
end
set(gcf,'PaperUnits','inches');
set(gcf,'PaperPosition',[0.25 0.25 6 2]);
print('-dpng',[figPth 'vi_vmacd_zoom.png']);


% ------------ Puerto Rico ---------------------
% ---->> data plots
[pid,pt] = plotHtDiff([basepth 'vmacdoht.lt.prvd02.pr.000']);
region = 'pr';
figure
drawBoundaries2(region);
scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
axis([291 294.9 17 19]);
colormap(cmap)
c = colorbar('southoutside');
c.Label.String = 'meters';
tightFig(gca);
print('-dpng',[figPth 'pr_vmacd_all.png']);

% zoom on the 3 subareas
figure
[ha, pos] = tight_subplot(1,3,0.05,[.01 .01],[.1 .01]);
axx = [292.74 292.95 18.2 18.3; ...
       293.25 293.55 17.95 18.1; ...
       293.6 294.2 18.3 18.6];
for i = 1:3
    axes(ha(i));
    drawBoundaries2(region);
    scatter(pt(:,2), pt(:,1),[],pt(:,4),'filled');
    colormap(cmap)
    axis(axx(i,:));
    set(ha(i), 'XTickLabelMode', 'auto') 
    set(ha(i), 'YTickLabelMode', 'auto')
end
set(gcf,'PaperUnits','inches');
set(gcf,'PaperPosition',[0.25 0.25 6 2]);
print('-dpng',[figPth 'pr_vmacd_zoom.png']);


% ------------ CONUS ---------------------
% residual plots
[pid,pt] = plotHtDiff([basepth 'vmarzoht.ngvd29.navd88.conus.003']);
datacursormode off
f1 = gcf;
axis([-84 -77 31 38]);
caxis([-0.5 0.75])
%tightFig(gca);
print('-dpng',[figPth 'conus_NC_all.png']);

q = find(abs(pt(:,4))>0.15);
[p,d] = replotHtDiff(pid(q), pt(q,:), 'conus');
datacursormode off
f2 = gcf;
axis([-84 -77 31 38]);
caxis([-0.5 0.75])
%tightFig(gca);
%size2x(f2);
%size1x(f2);
title('vmarzoht.ngvd29.navd88.conus.003, large values')
print('-dpng',[figPth 'conus_NC_notZero.png']);

figure(f1);
axis([-81 -79.6 33.2 34.5]);
print('-dpng',[figPth 'conus_NC_zoom.png']);

figure(f1);
%size1x(f1);
caxis auto;
axis([-95 -87 28 33]);
print('-dpng',[figPth 'conus_LA_AL.png']);
axis([-112.4 -111 32.4 33.6]);
print('-dpng',[figPth 'conus_AZ.png']);
axis([-122.5 -118 34 38]);
print('-dpng',[figPth 'conus_centralCA.png']);


% CONUS histograms
figure
hist(pt(:,4),100)
grid on
xlabel('VERTCON 2.0 residual (m)')
ylabel('number of points')
% fig = gcf;
% fig.PaperUnits = 'inches';
% fig.PaperPosition = [0 0 3 2];
%size2x(gcf);
print('-dpng',[figPth 'conus_rz_hist.png']);
ylim([0 1000])
print('-dpng',[figPth 'conus_rz_histZoom.png']);

function size2x(fig)
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 3 2];
end

function size1x(fig)
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 6 4];
end