% stratus 11 only - stratus 10 already gone home
% use red O +    blue [] * black V (triangles)
% Stratus 11  (L-1 red O  L-2 blue square 
% shipboard IMET - vos is black hourly triangles

% stmd:  07-Apr-2011 22:00:00
% enmd:  09-Apr-2011 11:00:00
% These remove data received when we arrived back and
% data from a short visit back to buoy next night
% 
% gps       2011/04/07 22:00 to 2011/04/09 10:29 at 1.00 min
% sys1      2011/04/07 22:30 to 2011/04/09 10:30 at 60.00 mins
% sys2      2011/04/07 22:30 to 2011/04/09 10:30
% vos       2011/04/07 22:01 to 2011/04/09 10:59 at 2.00 mins
% etl_flux  2011/04/07 22:00 to 2011/04/09 10:59 at 5.00 mins
% etl       2011/04/07 22:00 to 2011/04/09 10:59 at 1.00 mins

addpath([matlabroot '\toolbox\local\m_map']);
addpath([matlabroot '\toolbox\local\seawater']);

% overall params:
year=2011;
day1=datenum(year,1,0);

%  axis start, end
stmd = datenum(2011,4, 7,22,0,0); styd=stmd-day1; %97.8917
enmd = datenum(2011,4, 9,11,0,0); enyd=enmd-day1; %99.4833
minx = min(styd) - .025;
maxx = max(enyd) + .025;

% xticks=[344.25 344.5 344.75 345.0 345.25];
xticks=[ 98. 98.25 98.5 98.75 99.0 99.25 ];

% get 1 minute truncated data
% contains gps sys1 sys2 vos etl etl_flux dist_s11
 load s11comp.mat
 
%% make some hourly averages, all with 30 min time stamps
% vos
myrmflds={ 'hdg' 'vane'  'year' 'month' 'day' 'hour' 'minute' };
vos=rmfield(vos,myrmflds);
warning off all
% get hourly VOS
vos=get_str_avg(vos);
[vos.wnds, vos.wndd] = vect2md(vos.wndu,vos.wndv);
ij = find(vos.wndd > 360) ;
if ij
    vos.wndd(ij) = vos.wndd(ij) - 360;
end
% get rain rate from hourly vos level
vos.prate=[0; diff(vos.precip)];
ship=vos;
ship.yday=ship.mday-day1;

% etl
% this will get E,N from Spd,Dir, avg, recreate S,D
etlh =get_avg_wdirs(etl_flux,'wspd_true', 'wdir_true');
% however we;re getting a NaN at the start...
% we need to pad out 07-Apr-2011 23:30 - 23:55?? (yd 97.9418)
%etlh =get_avg_wdirs(etl_flux,'wspd_true', 'wdir_true');


% rotate wind  
etlh.wdir_true=etlh.wdir_true +180;  
bv=find( etlh.wdir_true > 360);
etlh.wdir_true(bv) = etlh.wdir_true(bv)-360;

% hourly distance
distH = get_str_avg(dist_s11);
distH.yday=distH.mday-day1;
dist_s11.yday=dist_s11.mday-day1;

%plot
% ic = ['o';'+';'s';'*'];
xlt='Yearday 2011';

%% fig 1 Air temperature (AT, upper) and relative humidity (RH, lower)
figure(1); clf;
subplot(2,1,1);
shl=line(ship.yday,ship.atmp,'Color','k','LineStyle','-', 'Marker','^');
ylabel('AT (deg C)');
hold on
legtxt=['VOS '; 'Lgr1'; 'Lgr2'; 'ESRL' ];
l_1=line(sys1.yday,sys1.atmp,'Color','r','LineStyle','-', 'Marker','o');
l_2=line(sys2.yday,sys2.atmp,'Color','r','LineStyle','-', 'Marker','+');
l_et=line(etlh.yday,etlh.atmp,'Color','b','LineStyle','-', 'Marker','*');
ax=axis;
axis([ minx maxx ax(3:4)]);
axis([ minx maxx 19.25 22.75 ]);
set(gca,'XTick',xticks);
% lh1=legend([shl l_1 l_2 l_et], legtxt,'Location','Best');
%set(lh1,'Box','off', 'FontSize',8);
% set(lh1, 'FontSize',8);

subplot(2,1,2);
shl=line(ship.yday, ship.hrh,'Color','k','LineStyle','-', 'Marker','^');
ylabel('RH (%)')
hold on
l_1=line(sys1.yday,sys1.hrh,'Color','r','LineStyle','-', 'Marker','o');
l_2=line(sys2.yday,sys2.hrh,'Color','r','LineStyle','-', 'Marker','+');
l_et=line(etlh.yday,etlh.hrh,'Color','b','LineStyle','-', 'Marker','s');
ax=axis; axis([minx maxx ax(3:4)])
% axis([ minx maxx 71.5 82 ])
set(gca,'XTick',xticks);
xlabel('Yearday 2011');
lh1=legend([shl l_1 l_2 l_et], legtxt,'Location','Best');
set(lh1, 'FontSize',8);
print -dpng s11_atrh.png
print -depsc s11_atrh.eps

%% fig 2 (4 in report) swr top,  lwr bot
figure(2); clf
subplot(2,1,1)
legtxt=['VOS '; 'Lgr1'; 'Lgr2'; 'ESRL' ];
shl=line(ship.yday, ship.swr,'Color','k','LineStyle','-', 'Marker','^');
ylabel('SWR (W/m^2)')
hold on
l_1=line(sys1.yday,sys1.swr,'Color','r','LineStyle','-', 'Marker','o');
l_2 = line(sys2.yday,sys2.swr,'Color','r','LineStyle','-', 'Marker','+');
l_et = line(etlh.yday,etlh.swr,'Color','b','LineStyle','-', 'Marker','s');
ax=axis; axis([minx maxx ax(3:4)]);
axis([minx maxx -10 800]);
set(gca,'XTick',xticks);
lh2=legend([shl l_1 l_2 l_et ], legtxt,'Location','Best');
% set(lh2,'Box','off', 'FontSize',8);
set(lh2, 'FontSize',8);

subplot(2,1,2)
line(ship.yday, ship.lwr,'Color','k','LineStyle','-', 'Marker','^');
ylabel('LWR (W/m^2)')
hold on
line(sys1.yday,sys1.lwr,'Color','r','LineStyle','-', 'Marker','o'); 
line(sys2.yday,sys2.lwr,'Color','r','LineStyle','-', 'Marker','+');
line(etlh.yday,etlh.lwr,'Color','b','LineStyle','-', 'Marker','s');

ax=axis; axis([minx maxx ax(3:4)]);
%   axis([minx maxx 380 432])
set(gca,'XTick',xticks);
xlabel(xlt);
print -dpng s11_swlw.png
%print -depsc n10swlw.eps

%% fig 3  (2 in report) bp (top) prlev(bot)
figure(3); clf;
subplot(2,1,1);
legtxt={'VOS'; 'Lgr1'; 'Lgr2'; 'ESRL'};
% shl=
line(ship.yday,ship.bpr,'Color','k','LineStyle','-', 'Marker','^');
ylabel('BP (mb)')
hold on
% l_1 = 
 line(sys1.yday,sys1.bpr,'Color','r','LineStyle','-', 'Marker','o');
% l_2 = 
line(sys2.yday,sys2.bpr,'Color','r','LineStyle','-', 'Marker','+');
% l_et = 
line(etlh.yday,etlh.bpr,'Color','b','LineStyle','-', 'Marker','s');
%l4 = line(sys4.yday,sys4.bpr,'Color','b','LineStyle','-', 'Marker','x');
ax=axis; axis([minx maxx ax(3:4)]);
axis([minx maxx 1010.5 1017.5]);  % axis([ax(1:3) 1016.5])
set(gca,'XTick',xticks);
% lh3=legend([shl l_1 l_2 l_et ], legtxt,'Location','Best');
% set(lh3,'Box','off', 'FontSize',8);
% set(lh3, 'FontSize',8);

subplot(2,1,2)
shl=line(ship.yday, ship.prate,...
    'Color','k','LineStyle','-', 'Marker','^');
ylabel('RAIN (mm/hr)')
hold on
l_1 = line(sys1.yday,sys1.rainr,'Color','r','LineStyle','-', 'Marker','o');
l_2 = line(sys2.yday,sys2.rainr,'Color','r','LineStyle','-', 'Marker','+');
l_et = line(etlh.yday,etlh.rainrate,'Color','b','LineStyle','-', 'Marker','s');
%line(sys4.yday,sys4.prc,'Color','b','LineStyle','-', 'Marker','x');
ax=axis; axis([minx maxx ax(3:4)]);
set(gca,'XTick',xticks);
xlabel(xlt);
lh3=legend([shl l_1 l_2 l_et ], legtxt,'Location','Best');
set(lh1, 'FontSize',8);
print -dpng s11_bprn.png
%print -depsc n10bprn.eps

%% fig 4 (3 in report) sst top sal  bot 
figure(4); clf
subplot(2,1,1);

legtxt2=['Lgr1'; 'Lgr2'; 'ESRL'];
% shl=line(ship.yday, ship.sst,'Color','k','LineStyle','-', 'Marker','^');
ylabel('SST (deg C)')
l_1 = line(sys1.yday,sys1.sst,'Color','r','LineStyle','-', 'Marker','o');
hold on
l_2 = line(sys2.yday,sys2.sst,'Color','r','LineStyle','-', 'Marker','+');
l_et = line(etlh.yday,etlh.sst,'Color','b','LineStyle','-', 'Marker','s');
ax=axis; axis([minx maxx ax(3:4)]);
%     axis([minx maxx 26.5 26.85]);
set(gca,'XTick',xticks);
lh4=legend([l_1 l_2 l_et], legtxt2,'Location','Best');
% set(lh4,'Box','off', 'FontSize',8)
set(lh4, 'FontSize',8);

subplot(2,1,2)
%shl=
%line(ship.yday, ship.sal,'Color','k','LineStyle','-', 'Marker','^');
ylabel('SSS (PSU)')

%l_1 = 
line(sys1.yday,sys1.sal,'Color','r','LineStyle','-', 'Marker','o');
hold on
%l_2 = 
line(sys2.yday,sys2.sal,'Color','r','LineStyle','-', 'Marker','+');
% line(etlh.yday,etlh.hrh,'Color','b','LineStyle','-', 'Marker','s');
% line(sys4.yday,sys4.hrh,'Color','b','LineStyle','-', 'Marker','x');
ax=axis; axis([minx maxx ax(3:4)]);
%axis([minx maxx 5.25 6.2]);
%     axis([minx maxx 36.2 36.6]);
set(gca,'XTick',xticks);
xlabel(xlt);
print -dpng s11_tsal.png
%print -depsc n10tsal.eps

%% fig 5 wspd top wdir bot
figure(5); clf
subplot(2,1,1);
legtxt3=['Lgr1'; 'Lgr1'; 'ESRL' ];
%shl=line(ship.yday, ship.wspd,'Color','k','LineStyle','-', 'Marker','^');
ylabel('WSPD (m/s)')
hold on
l_1 = line(sys1.yday,sys1.wnds,'Color','r','LineStyle','-', 'Marker','o');
l_2 = line(sys2.yday,sys2.wnds,'Color','r','LineStyle','-', 'Marker','+');
l_et = line(etlh.yday,etlh.wspd_true,'Color','b','LineStyle','-', 'Marker','s');
ax=axis; axis([minx maxx ax(3:4)]);
axis([minx maxx 0 9 ]);
set(gca,'XTick',xticks);
lh5=legend([l_1 l_2 l_et], legtxt3,'Location','Best');
% set(lh5,'Box','off', 'FontSize',8)
set(lh5, 'FontSize',8);

subplot(2,1,2)

hold on
l_1 = line(sys1.yday,sys1.wndd,'Color','r','LineStyle','-', 'Marker','o');
l_2 = line(sys2.yday,sys2.wndd,'Color','r','LineStyle','-', 'Marker','+');
l_et = line(etlh.yday,etlh.wdir_true,'Color','b','LineStyle','-', 'Marker','s');
ylabel('WDIR (deg)')
ax=axis; axis([minx maxx ax(3:4)]);
set(gca,'XTick',xticks);
%   axis([minx maxx 270 320]);
xlabel(xlt);
print -dpng s11_wnd.png
%print -depsc n10wnd.eps

%% fig 6 distance
figure(6); clf
subplot(2,1,1);
% shl=line(dist_s11.yday, dist_s11.dist_km,'Color','k','LineStyle','-', 'Marker','^');
% ylabel('Distance (km)')
% ldtxt='Ship to Stratus 11';
% ax=axis; axis([minx maxx 1 (ax(4) + .25)]);
% set(gca,'XTick',xticks);
% lh6=legend([shl ], ldtxt,'Location','Best');
% % lh6=legend([shl ], ldtxt,'Location','NorthWest');
% %set(lh6,'Box','off', 'FontSize',8)
% set(lh6, 'FontSize',8);
% 
% subplot(2,1,2);
shl=line(distH.yday, distH.dist_km,'Color','k','LineStyle','-', 'Marker','^');
ylabel('Distance (km)')
ldtxt='Ship to Stratus 11';
ax=axis; axis([minx maxx 2 (ax(4) + .25)]);
set(gca,'XTick',xticks);
lh6=legend([shl ], ldtxt,'Location','Best');
print -dpng s11_dist.png
%print -depsc n10dist.eps

