%  overplot_etl_flux_panels 
% these are the post-processed files, updated daily
%%%% get some (all?) user-supplied params
etitle = 'ETL: red ';
ecolor='red';
set_up
% atitle='sys1:blue sys2:green ';
atitle=[];
if ~exist('pmaxx','var')
     pmaxx=datenum(now) - day1 + .25;
     pminx = pmaxx-3;
     stitle =[];
end
%
%%%% get all the data first
% truncate as you load, for better auto-axis ranges
%
% %get minute etl data
load etl_flux1h.mat; 
% wspd_true, wdir_true, sst, atmp, swr, lwr, rainrate
flux.yday=flux.mday-day1;
iidx=find(flux.yday > (pmaxx - daystoplot));
flux=structtrunc(flux,iidx);

load etl1h.mat;
% rainrate, sst, atmp, hrh, bpr, swr, swrKz, lwr, lwrKz
etl.yday=etl.mday-day1;    
iidx=find(etl.yday > (pmaxx - daystoplot));
% fprintf('etl: %d cut to %d\n', length(etl.yday),...
%     length(iidx));
etl=structtrunc(etl,iidx);
% new etl data for which there's no flux (processed) data
usen=find(etl.yday > flux.yday(end));

%%%% Now plot 
%%% add editing clauses as needed
%
% 1.atmp hrh  2.bpr prc  3.sst sal  4 lwr swr  5. wind
%% 
figure(1);  
% atmp, hrh
subplot(2,1,1);    %atmp
line(flux.yday,flux.atmp,'Color',ecolor);
line(etl.yday(usen),etl.atmp(usen),'Color',ecolor,'LineStyle',':')
ylabel('atmp');
hold on
title([titlemain atitle stitle etitle]);
ax=axis;
ax(3)=min([ax(3); etl.atmp]); ax(3)=ax(3)-.25;
axis([ pminx pmaxx ax(3:4) ]);

subplot(2,1,2);  %hrh
line(flux.yday,flux.hrh,'Color',ecolor);
line(etl.yday(usen),etl.hrh(usen),'Color',ecolor,...
    'LineStyle',':')
ax=axis;
ax(3)=min([ax(3); etl.hrh]);

ax(4)=max([ax(4); etl.hrh]);
axis([ pminx pmaxx ax(3:4)]);



%% sst & sal
figure(2);  
subplot(2,1,1);   %sst
hold on
line(flux.yday,flux.sst,'Color',ecolor);
line(etl.yday(usen),etl.sst(usen),'Color',ecolor,'LineStyle',':');
 ax=axis;
 ax(3)=min([ ax(3); flux.sst; etl.sst(usen)]);
  ax(4)=max([ ax(4); flux.sst; etl.sst(usen)]);
 axis([ pminx pmaxx ax(3:4)]);
title([titlemain atitle stitle etitle]);
% subplot(2,1,2);  %sal
% hold on
% gsal=find(tsg.sal > 20);
% line(tsg.yday(gsal),tsg.sal(gsal),'Color',ecolor,'LineStyle',...
%     ':');
% 
% %      if exist('tsgH','var'),
% %         line(tsgH.yday,tsgH.sal,'r.'); end
% ax=axis;
% axis([ pminx pmaxx ax(3:4)]);

%% 
figure(3);  % bpr & prc
subplot(2,1,1); %bpr
hold on
line(flux.yday,flux.bpr,'Color',ecolor);
line(etl.yday(usen),etl.bpr(usen),'Color',ecolor,'LineStyle',':');
 ax=axis;
 ax(4)=max([ax(4); etl.bpr]);
 axis([ pminx pmaxx ax(3:4)]);
title([titlemain atitle stitle etitle]);

subplot(2,1,2);    % rain
hold on
line(flux.yday,flux.rainrate,'Color',ecolor);
line(etl.yday(usen),etl.rainrate(usen),'Color',ecolor,...
    'LineStyle',':');
ax=axis;
axis([ pminx pmaxx -1 ax(4)]);

%% swr, lwr
figure(4);
subplot(2,1,1);  % swr
hold on
% gv=find(etl.swr > -2);
% line(etl.yday(gv),etl.swr(gv),'Color',ecolor, 'LineStyle',...
%     ':');
line(flux.yday,flux.swr,'Color',ecolor);
line(etl.yday(usen),etl.swrKz(usen),'Color',ecolor, 'LineStyle', ':');
line(etl.yday(usen),etl.swr(usen),'Color',ecolor, 'LineStyle', ':');
ax=axis;
axis([ pminx pmaxx ax(3:4)]);
title([titlemain atitle stitle etitle]);

subplot(2,1,2);    % lwr
hold on
line(flux.yday,flux.lwr,'Color',ecolor);
line(etl.yday(usen),etl.lwrKz(usen),'Color',ecolor,'LineStyle',':');
% ,...     'Marker','.','MarkerSize',2);
ax=axis;
axis([ pminx pmaxx ax(3) ax(4)]);


%% wind  - wspd_true, wdir_true
figure(5);
subplot(2,1,1);   % wind speed wnds
line(flux.yday,flux.wspd_true,'Color',ecolor);
ax=axis;

ax(3)=min([ax(3); flux.wspd_true]);
ax(4)=max([ax(4); flux.wspd_true]);

axis([ pminx pmaxx ax(3:4)]);
title([titlemain atitle stitle etitle]);

subplot(2,1,2);  %wdir
flux.wdir_true =flux.wdir_true + 180;
bw=find(flux.wdir_true > 360);
flux.wdir_true(bw)=flux.wdir_true(bw) -360;
line(flux.yday,(flux.wdir_true),'Color',ecolor);
ax=axis;
ax(3)=floor(min([ax(3); flux.wdir_true]));
ax(4)=ceil(max([ax(4); flux.wdir_true]));
axis([ pminx pmaxx ax(3:4)]);
