%cbl_plot.m
%plotting program for cbl_growth model
%x = fetch (km); h = cbl height; thetam= mixed layer potential temp.; 
%hs = heat flux

%-----------------------------------------------------------------------
% input data - at distance x=0. Ropex = 1, Chang&Braham = 2, Labsea = 3
% test case = 4, mizclm (Guest et al.) = 5, mefis (heinemann) = 6 
%-----------------------------------------------------------------------
 input_set = 4

% load U:/data/matlab/cbl_growth

if (input_set == 1) 

 load U:/data/matlab/ropex_radiosonde
 load U:/data/matlab/soc_validation
 xmin = 0; xmax = 40; 			%km
 hmin = 0; hmax = 600; 			%m
 thetamin = 258; thetamax = 268; 	%K
 hsmin = 0; hsmax = 200; %W/m2
 
 subplot(3,1,1), plot(x,h ,'g-.');
hold on; 
 for i=1:length(dist),
  subplot(3,1,1),plot([dist(i) dist(i)], [h_v1(i) h_v2(i)],'k','linewidth',1.5)
 end;
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('CIBL height (m)');
 axis([xmin xmax hmin hmax]);
 title(['CIBL growth model - validation using ROPEX data']) 

 subplot(3,1,2), plot(x,thetam,'g-.');
hold on;
 subplot(3,1,2), plot(dist,thetam_v,'k*'); %ropex
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('potential temperature (K)');
 axis([xmin xmax thetamin thetamax]);

 subplot(3,1,3), plot(x,hs,'g-.');
hold on;
%errorbars using (1) std of mpaws wind speed and (2) using 15%, Garratt (92)
% subplot(3,1,3), errorbar(dist,hs_v2,hs_v2e,hs_v2e,'k*'); 
 subplot(3,1,3), errorbar(dist,hs_v2,0.15*hs_v2,0.15*hs_v2,'k*');
%SOC ship based bulk fluxes
 subplot(3,1,3), errorbar(dist_vs,hs_vs,0.15*hs_vs,0.15*hs_vs,'ko');
%Lagrangain estimate of surface heat fluxes - not used 
% for i=2:4, 
%  subplot(3,1,3), plot([dist(i) dist(i+1)], [hst_max(i) hst_max(i)],'c',...
%	'linewidth', 1.3)
%  subplot(3,1,3), plot([dist(i) dist(i+1)], [hst_min(i) hst_min(i)],'c',...
%      	'linewidth', 1.3)
% end;
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('sensible heat flux (W m^{-2})');
 axis([xmin xmax hsmin hsmax]);

%legend
legend_plot = 1
if (legend_plot == 1)
 text_h = (hmax-hmin)/10;
 subplot(3,1,1), plot([27 31],[hmin+text_h hmin+text_h],'b-');
 tt = text(32, hmin+text_h, '13 UTC');
 set(tt, 'fontsize', 11)
 subplot(3,1,1), plot([27 31],[hmin+2*text_h hmin+2*text_h],'r--');
 tt = text(32, hmin+2*text_h, '12 UTC'); 
 set(tt, 'fontsize', 11)
 subplot(3,1,1), plot([27 31],[hmin+3*text_h hmin+3*text_h],'g-.');
 tt = text(32, hmin+3*text_h, '11 UTC'); 
 set(tt, 'fontsize', 11)
end; 
orient tall

%----------------------------------------------------------------------
elseif (input_set ==2)

 load U:/data/matlab/chang_braham
 xmin = 0; xmax = 140; %km
 hmin = 0; hmax = 1600; %m
 thetamin = 246; thetamax = 256; %K
 hsmin = 0; hsmax = 600; %W/m2

 subplot(3,1,1), plot(x,h ,'r--');
hold on; 
 for i=1:length(dist),
  subplot(3,1,1),plot([dist(i) dist(i)], [h_v1(i) h_v2(i)],'k','linewidth',1.5)
 end;
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('CIBL height (m)');
 axis([xmin xmax hmin hmax]);
 title(['CIBL growth model - validation using Lake Michigan data']) 

 subplot(3,1,2), plot(x,thetam,'r--');
hold on;
 subplot(3,1,2), plot(dist2,thetam_meas,'ko'); 	% measured thetam
 subplot(3,1,2), plot(dist2,thetam_v,'k*'); 	% tendency removed
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('potential temperature (K)');
 axis([xmin xmax thetamin thetamax]);

 subplot(3,1,3), plot(x,hs,'r--');
hold on;
 subplot(3,1,3),plot(dist2, hs_v,'ko'); 	%measured fluxes 
 subplot(3,1,3),errorbar(dist2,hs_vc,0.15*hs_vc, 0.15*hs_vc,'k*'); %bulk fluxes
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('sensible heat flux (W m^{-2})');
 axis([xmin xmax hsmin hsmax]);

%legend
 text_h = (hmax-hmin)/10;
 subplot(3,1,1), plot([100 112],[hmin+text_h hmin+text_h],'b-');
 tt = text(115, hmin+text_h, '\beta = 0.1');
 set(tt, 'fontsize', 11)
 subplot(3,1,1), plot([100 112],[hmin+2*text_h hmin+2*text_h],'r--');
 tt = text(115, hmin+2*text_h, '\beta = 0.2'); 
 set(tt, 'fontsize', 11)

 orient tall

%----------------------------------------------------------------------
elseif (input_set == 3)

 load U:/data/matlab/labsea_radiosonde.asc
 xmin = 0; xmax = 400; 			%km
 hmin = 0; hmax = 2500; 		%m
 thetamin = 250; thetamax = 268; 	%K
 hsmin = 0; hsmax = 500; %W/m2 

 subplot(3,1,1), plot(x,h ,'b-');
hold on; 
 for i=1:length(dist),
  subplot(3,1,1),plot([dist(i) dist(i)], [h_v1(i) h_v2(i)],'k','linewidth',1.5)
 end;
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('CIBL height (m)');
 axis([xmin xmax hmin hmax]);
 title(['CIBL growth model - validation using Labrador Sea data']) 

 subplot(3,1,2), plot(x,thetam,'b-');
hold on;
 subplot(3,1,2), plot(dist,thetam_v,'k*'); 
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('potential temperature (K)');
 axis([xmin xmax thetamin thetamax]);

 subplot(3,1,3), plot(x,hs,'b-');
hold on;
 subplot(3,1,3), errorbar(dist,hs_v2,hs_v2e,hs_v2e,'k*'); 
 for i=2:4, 
  subplot(3,1,3), plot([dist(i) dist(i+1)], [hst_max(i) hst_max(i)],'c')
  subplot(3,1,3), plot([dist(i) dist(i+1)], [hst_min(i) hst_min(i)],'c')
 end;
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('sensible heat flux (W m^{-2})');
 axis([xmin xmax hsmin hsmax]);
 orient tall

%----------------------------------------------------------------------
elseif (input_set == 4)

 xmin = 0; xmax = 50; 			%km
 hmin = 0; hmax = 1000; 			%m
 thetamin = 255; thetamax = 265; 	%K
 hsmin = 0; hsmax = 300; 		%W/m2 

 subplot(3,1,1), plot(x,h ,'b-');
hold on; 
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('CIBL height (m)');
 axis([xmin xmax hmin hmax]);

 subplot(3,1,2), plot(x,thetam,'b-');
hold on;
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('potential temperature (K)');
 axis([xmin xmax thetamin thetamax]);

 subplot(3,1,3), plot(x,hs,'b-');
hold on;
% subplot(3,1,3), plot(x,lhf,'b--');
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('heat fluxes (W m^{-2})');
 axis([xmin xmax hsmin hsmax]);
 orient tall

%legend
 text_h = (hmax-hmin)/10;
% subplot(3,1,1), plot([35 39],[hmin+text_h hmin+text_h],'b-');
% tt= text(40, hmin+text_h, '\gamma_{\theta} = 12.0 K km^{-1}')
% tt= text(40, hmin+text_h, 'h_0 = 50 metres')
% set(tt, 'fontsize', 11)
% subplot(3,1,1), plot([35 39],[hmin+2*text_h hmin+2*text_h],'r--');
% tt= text(40, hmin+2*text_h, '\gamma_{\theta} = 9.2 K km^{-1}')
% tt= text(40, hmin+2*text_h, 'h_0 = 100 metres')
% set(tt, 'fontsize', 11)
% subplot(3,1,1), plot([35 39],[hmin+3*text_h hmin+3*text_h],'g-.');
% tt= text(40, hmin+3*text_h, '\gamma_{\theta} = 6.4 K km^{-1}')
% tt= text(40, hmin+3*text_h, 'h_0 = 150 metres')
% set(tt, 'fontsize', 11)

%----------------------------------------------------------------------
elseif (input_set ==5)

 load U:/data/matlab/mizclm
 xmin = 0; xmax = 150; %km
 hmin = 0; hmax = 2500; %m
 thetamin = 257; thetamax = 270; %K
 hsmin = 0; hsmax = 250; %W/m2

 subplot(3,1,1), plot(x,h ,'b-');
hold on; 
 subplot(3,1,1),errorbar(dist, h_v, h_v1, h_v2, 'k*');
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('CIBL height (m)');
 axis([xmin xmax hmin hmax]);
 title(['CIBL growth model - validation using MIZCLM data']) 

 subplot(3,1,2), plot(x,thetam,'b-');
hold on;
 subplot(3,1,2), plot(dist,thetam_v,'k*');
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('potential temperature (K)');
 axis([xmin xmax thetamin thetamax]);

 subplot(3,1,3), plot(x,hs,'b-');
hold on;
 subplot(3,1,3),errorbar(dist,hs_vc,0.15*hs_vc, 0.15*hs_vc,'k*'); %bulk fluxes
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('sensible heat flux (W m^{-2})');
 axis([xmin xmax hsmin hsmax]);

%legend
legend_plot = 1
if (legend_plot == 1)
 text_h = (hmax-hmin)/10;
 subplot(3,1,1), plot([10 20],[hmin+7.5*text_h hmin+7.5*text_h],'b-');
 tt=text(25, hmin+7.5*text_h, '\gamma_{\theta} = 5 K km^{-1},   h_0 = 475 m'); 
 set(tt, 'fontsize', 11)
 subplot(3,1,1), plot([10 20],[hmin+8.5*text_h hmin+8.5*text_h],'r--');
 tt=text(25, hmin+8.5*text_h, '\gamma_{\theta} = 10 K km^{-1}, h_0 = 100 m'); 
 set(tt, 'fontsize', 11)
end; 
 orient tall

%----------------------------------------------------------------------
elseif (input_set ==6)

% load U:/data/matlab/
 xmin = 0; xmax = 25; %km
 hmin = 0; hmax = 400; %m
 thetamin = 260; thetamax = 270; %K
 hsmin = 0; hsmax = 200; %W/m2
%validation data from paper
 dist = 20; h_v1=250; h_v2=325; thetam_v = 262.5; hs_vc = 60; 

 subplot(3,1,1), plot(x,h ,'b-');
hold on; 
 subplot(3,1,1),plot([dist dist], [h_v1 h_v2],'k','linewidth',1.5)
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('CIBL height (m)');
 axis([xmin xmax hmin hmax]);
 title(['CIBL growth model - validation using MEFIS data']) 

 subplot(3,1,2), plot(x,thetam,'b-');
hold on;
 subplot(3,1,2), plot(dist,thetam_v,'k*');
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('potential temperature (K)');
 axis([xmin xmax thetamin thetamax]);

 subplot(3,1,3), plot(x,hs,'b-');
hold on;
 subplot(3,1,3),errorbar(dist,hs_vc,0.15*hs_vc, 0.15*hs_vc,'k*'); %bulk fluxes
 set(gca, 'fontsize', 12);
 xlabel('fetch (km)');
 ylabel('sensible heat flux (W m^{-2})');
 axis([xmin xmax hsmin hsmax]);

%legend
legend_plot = 1
if (legend_plot == 1)
 text_h = (hmax-hmin)/10;
 subplot(3,1,1), plot([17 19],[hmin+text_h hmin+text_h],'b-');
 tt = text(20, hmin+text_h, 'u_m = 2 m s^{-1}');
 set(tt, 'fontsize', 11)
 subplot(3,1,1), plot([17 19],[hmin+2*text_h hmin+2*text_h],'r--');
 tt = text(20, hmin+2*text_h, 'u_m = 4 m s^{-1}'); 
 set(tt, 'fontsize', 11)
end; 
 orient tall

end;




