clc;clear all;close all;
addpath('/data3/yiwen/cesm_final_exp/matlab_toolbox/colorbrewer')
addpath('/data3/yiwen/cesm_final_exp/matlab_toolbox/m_map')
addpath('/home/yiwen/matlab_test/toolbox/tight_subplot')

pathi1='/data3/yiwen/matlab_coawst/particle_tracking/Offline_output/1002_tracking/2AREA/'
pathi2='/data3/yiwen/matlab_coawst/particle_tracking/Offline_output/0926_tracking/'
load([pathi2,'spun_up_10days'])

u_avg1=nanmean(u6(:,:,1152),3);v_avg1=nanmean(v6(:,:,1152),3); 
u_avg2=nanmean(u6(:,:,1153:1212),3);v_avg2=nanmean(v6(:,:,1153:1212),3); 
u_avg3=nanmean(u6(:,:,1213:1272),3);v_avg3=nanmean(v6(:,:,1213:1272),3); 
u_avg4=nanmean(u6(:,:,1273:1332),3);v_avg4=nanmean(v6(:,:,1273:1332),3); 

V1=sqrt(u_avg1(:,2:end).^2+v_avg1(2:end,:).^2);
V2=sqrt(u_avg2(:,2:end).^2+v_avg2(2:end,:).^2);
V3=sqrt(u_avg3(:,2:end).^2+v_avg3(2:end,:).^2);
V4=sqrt(u_avg4(:,2:end).^2+v_avg4(2:end,:).^2);
u_avg=nanmean(u6(:,:,1440:1728),3);v_avg=nanmean(v6(:,:,1440:1728),3); 
V_day2=sqrt(u_avg(:,2:end).^2+v_avg(2:end,:).^2);V_day2(isnan(V_day2))=0.4; 

u_avg=nanmean(u6(:,:,1729:2008),3);v_avg=nanmean(v6(:,:,1729:2008),3); 
V_day3=sqrt(u_avg(:,2:end).^2+v_avg(2:end,:).^2);V_day3(isnan(V_day3))=0.4; 
% get the colorbar %%
% % m_map=colormap(jet(size(xx,2)));
% for i=1:100:size(xx,1);
% %   for k=1:10:size(xx,2);
%       scatter(xx2(i,1),yy2(i,1),'markerfacecolor',m_map(k,:),...
%           'markeredgecolor','none','sizedata',4);hold on;
% %   end 
% end 
% axis equal;
% 
% figure;
% AxesH = axes('CLim', [0, 1730]);
% cbh = colorbar('peer', AxesH, 'h', ...
%                'XTickLabel',{'4/9','4/10','4/11','4/12','4/13','4/14','4/15'}, ...
%                'XTick', 0:288:1730,'location','southoutside')
%            
% w = cbh.LineWidth;
% cbh.LineWidth = 1.5;           
% cbh.FontSize = 16;           
% colormap(m_map);caxis([0 1730]);      
%
% Msize=linspace(1,1.5,1730);

set(0,'defaultfigurecolor','w')
[ha, hfigure]= tight_subplot(1, 4, [0.005 0.005], [0.13 0.05], [0.05 0.01]);

load([pathi1,'case1_0hr'])
xx(xx(:,1)==xx(:,end))=nan;yy(yy(:,1)==yy(:,end))=nan;
xx2(xx2(:,1)==xx2(:,end))=nan;yy2(yy2(:,1)==yy2(:,end))=nan;

m_map=m_colmap('jet',size(xx,2));
axes(ha(1))
pcolor(lon(2:end,2:end),lat(2:end,2:end),V1);shading flat;hold on; 
for k=1:10:size(xx,2);
   % sperating area
   plot(xx(1:1:270,k), yy(1:1:270,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx(270:2:end,k), yy(270:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on    
   plot(xx2(1:3*2:300,k), yy2(1:3*2:300,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx2(300:2:end,k), yy2(300:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
end   
load slice_cmaps;colormap(cmap)
set(gca,'Fontsize',14);set(gca,'Linewidth',2)
title({'Velocity field' ;'at 4/9 00:00:00' ; 'throw particles'},'Fontsize',16)
caxis([0 1.])    
axis([121.9140 121.9165 25.1220 25.1270]);axis square

%
load([pathi1,'case1_6hr'])
xx(xx(:,1)==xx(:,end))=nan;yy(yy(:,1)==yy(:,end))=nan;
xx2(xx2(:,1)==xx2(:,end))=nan;yy2(yy2(:,1)==yy2(:,end))=nan;
axes(ha(2))
pcolor(lon(2:end,2:end),lat(2:end,2:end),V2);shading flat;hold on;
for k=1:10:size(xx,2);
   % sperating area
   plot(xx(1:1:270,k), yy(1:1:270,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx(270:2:end,k), yy(270:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on    
   plot(xx2(1:3*2:300,k), yy2(1:3*2:300,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx2(300:2:end,k), yy2(300:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
end     
set(gca,'yticklabel',[]);
load slice_cmaps;colormap(cmap)
set(gca,'Fontsize',14);set(gca,'Linewidth',2)
title({'Velocity field' ;'at 4/9 06:00:00' ; 'throw particles'},'Fontsize',16)
axis([121.9140 121.9165 25.1220 25.1270]);axis square
caxis([0 1.])

load([pathi1,'case1_12hr'])
xx(xx(:,1)==xx(:,end))=nan;yy(yy(:,1)==yy(:,end))=nan;
xx2(xx2(:,1)==xx2(:,end))=nan;yy2(yy2(:,1)==yy2(:,end))=nan;
axes(ha(3))
pcolor(lon(2:end,2:end),lat(2:end,2:end),V3);shading flat;hold on;
for k=1:10:size(xx,2);
   % sperating area
   plot(xx(1:1:270,k), yy(1:1:270,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx(270:2:end,k), yy(270:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on    
   plot(xx2(1:3*2:300,k), yy2(1:3*2:300,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx2(300:2:end,k), yy2(300:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
end     
set(gca,'yticklabel',[]);
load slice_cmaps;colormap(cmap)
set(gca,'Fontsize',14);set(gca,'Linewidth',2)
title({'Velocity field' ;'at 4/9 12:00:00' ; 'throw particles'},'Fontsize',16)
axis([121.9140 121.9165 25.1220 25.1270]);axis square
caxis([0 1.])


load([pathi1,'case1_18hr'])
xx(xx(:,1)==xx(:,end))=nan;yy(yy(:,1)==yy(:,end))=nan;
xx2(xx2(:,1)==xx2(:,end))=nan;yy2(yy2(:,1)==yy2(:,end))=nan;

axes(ha(4))
pcolor(lon(2:end,2:end),lat(2:end,2:end),V4);shading flat;hold on;
for k=1:10:size(xx,2);
   % sperating area
   plot(xx(1:1:270,k), yy(1:1:270,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx(270:2:end,k), yy(270:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on    
   plot(xx2(1:3*2:300,k), yy2(1:3*2:300,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
   plot(xx2(300:2:end,k), yy2(300:2:end,k), 'o','Color', m_map(k,:),'Markersize',Msize(k));hold on
end  
set(gca,'yticklabel',[]);
load slice_cmaps;colormap(cmap)
set(gca,'Fontsize',14);set(gca,'Linewidth',2)
title({'Velocity field' ;'at 4/9 18:00:00' ; 'throw particles'},'Fontsize',16)
axis([121.9140 121.9165 25.1220 25.1270]);axis square
caxis([0 1.])


c=colorbar('location','southoutside','Position', [0.23 0.1 0.6 0.02],...
 'colormap', colormap(cmap));
c.Title.String = "m/s"; 

return;
% ===== save to .jpg ======%
set(gcf, 'PaperPositionMode' , 'auto' ) 
print( 'case1_1020' , '-djpeg' , '-r500' )







