% ntas 8 only - ntas 7 stpped recording/transmitting
% use red O +    blue [] * black V (triangles)
% NTAS-8  (L-12 and L-16) are red O +
% VOS systems blue square *
% shipboard IMET (SCS) is black hourly triangles

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


% overall params:

xticks=[210.5 210.75 211.00 211.25 ];
year=2008;
day1=datenum(year,1,0);
styd=datenum(2008, 7, 28, 5, 0, 0) - day1;
%enyd=datenum(2008,7,29,6,30,0) - day1;
%29-Jul-2008 06:30:00
enyd=211.5;   % last
% buoy position - surveyed anchor pos
n8.lat=14 + 45.1344/60;
n8.lon=-1 * (50 + 57.175/60);
%  data plot start, end
minx=styd;
maxx=enyd;

% imet - AO file
load  ntasAO78.mat imet_1 imet_2
n8l12=AO_to_variables(imet_1,styd,enyd+1/24);
n8l16=AO_to_variables(imet_2,styd,enyd+1/24);

% vos
vos=load ('vos.mat');
vos.yday=vos.mday-day1;
myrmflds= { 'wndu' 'wndv' 'hdg' 'vane' };
myvos=rmfield(vos,myrmflds);
hvos=get_str_avg(myvos);

% ship met & position
ship=load ('shipmet.mat');
% rotate wind
ship.wdir=ship.wdir+180;  blah=find( ship.wdir > 360);
ship.wdir(blah) = ship.wdir(blah)-360;
%get east,north for averaging
% syntax: [vx,vy] = md2vect(mag,dir);
[ship.wndu ship.wndv] = md2vect(ship.wspd,ship.wdir);
% ship.sal=sw_salt(10*ship.cond/sw_c3515, sys.sst, 0.25);
myrmflds={'GPS_COG' 'GPS_SOG' ...
    'Gyro' 'relwdir' 'relwspd'  ...
    'WXT5_TS_cnt' 'WXT5_TS_mean' ...
    'WXT5_TS_median' 'WXT5_TS_rms' 'WXT5_TS_sdev' ...
    'WXT5_TS_vari' 'HdChkSum' };
ship=rmfield(ship,myrmflds);
ship.yday=ship.mday-day1;

% get distance from ship to buoys
dst=ones(length(ship.mday),1);
for iil=1:length(ship.mday),
    jla=[n8.lat ship.lat(iil)];
    jlo=[n8.lon ship.lon(iil)];
    dst(iil) = m_lldist(jlo,jla);
end
ship.dist=dst;
%hourly average
hship=get_str_avg(ship);
% re-generate spd, dir
[hship.wspd, hship.wdir] = vect2md(hship.wndu,hship.wndv);
%hship.yday=hship.mday-day1;
sx=find(hship.yday >= styd & hship.yday <= enyd);

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

% fig 1 Air temperature (AT, upper) and relative humidity (RH, lower)
figure(1); clf;

subplot(2,1,1);
shl=line(hship.yday(sx),hship.atmp(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('AT (deg C)');
hold on
legtxt=['Ship '; 'VOS  '; 'Lgr12'; 'Lgr16'; ];
lvos=line(hvos.yday,hvos.atmp,'Color','b','LineStyle','-', 'Marker','*');
l12=line(n8l12.yday,n8l12.atmp,'Color','r','LineStyle','-', 'Marker','o');
l16=line(n8l16.yday,n8l16.atmp,'Color','r','LineStyle','-', 'Marker','+');
ax=axis;
axis([ minx maxx ax(3:4)]);
set(gca,'XTick',[xticks])
%axis([ minx maxx 25.6 26.75 ]);
lh1=legend([shl lvos l12 l16], legtxt);
%set(lh1,'Box','off', 'FontSize',8);
set(lh1, 'FontSize',8);

subplot(2,1,2);
%shl=
line(hship.yday(sx), hship.hrh(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('RH %')
hold on
%lvos=
line(hvos.yday,hvos.hrh,'Color','b','LineStyle','-', 'Marker','*');
%l12=
line(n8l12.yday,n8l12.hrh,'Color','r','LineStyle','-', 'Marker','o');
%l16=
line(n8l16.yday,n8l16.hrh,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
set(gca,'XTick',[xticks]);
% axis([ minx maxx 71.5 82 ])
xlabel('Yearday 2008');

% fig 2 (4 in report) swr top  lwr bot
figure(2); clf
subplot(2,1,1)
shl=line(hship.yday(sx), hship.swr(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('SWR (W/m^2)')
hold on
lvos=line(hvos.yday,hvos.swr,'Color','b','LineStyle','-', 'Marker','*');
l12=line(n8l12.yday,n8l12.swr,'Color','r','LineStyle','-', 'Marker','o');
l16 = line(n8l16.yday,n8l16.swr,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
set(gca,'XTick',[xticks]);
%   axis([minx maxx -5 1020]);
lh2=legend([shl lvos l12 l16], legtxt);
% set(lh2,'Box','off', 'FontSize',8);
set(lh2, 'FontSize',8);


subplot(2,1,2)
% no ship lwr
%lvos=
line(hvos.yday,hvos.lwr,'Color','b','LineStyle','-', 'Marker','*');
ylabel('LWR (W/m^2)')
hold on
%l12= 
line(n8l12.yday,n8l12.lwr,'Color','r','LineStyle','-', 'Marker','o');
%l16 = 
line(n8l16.yday,n8l16.lwr,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
%   axis([minx maxx 380 432])
xlabel('Yearday 2008');

% fig 3  (2 in report) bp (top) prlev(bot)
figure(3); clf;
subplot(2,1,1)
shl=line(hship.yday(sx),hship.bpr(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('BP (mb)')
hold on
lvos=line(hvos.yday,hvos.bpr,'Color','b','LineStyle','-', 'Marker','*');
l12 = line(n8l12.yday,n8l12.bpr,'Color','r','LineStyle','-', 'Marker','o');
l16 = line(n8l16.yday,n8l16.bpr,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
%    axis([minx maxx 1010 1016.5]);  % axis([ax(1:3) 1016.5])
lh3=legend([shl lvos l12 l16], legtxt);
% set(lh3,'Box','off', 'FontSize',8);
set(lh3, 'FontSize',8);


subplot(2,1,2)
% load data/hrain.mat
%shl=
line(hship.yday(sx), hship.rainlevel(sx),...
    'Color','k','LineStyle','-', 'Marker','^');
ylabel('PRLEV (mm)')
hold on
%l12 = 
line(n8l12.yday,n8l12.prc,'Color','r','LineStyle','-', 'Marker','o');
%l16 = 
line(n8l16.yday,n8l16.prc,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
xlabel('Yearday 2008');

% fig 4 (3 in report) sst top sal  bot (not cond)
figure(4); clf
subplot(2,1,1);
% load data/htsg.mat
legtxt2=['Ship SBE'; 'Ship TSG'; 'Lgr12   '; 'Lgr16   '; ];

shl=line(hship.yday(sx), hship.sbetemp(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('SST (deg C)')
hold on
sh2l=line(hship.yday(sx), hship.tsgsst(sx),'Color','b','LineStyle','-', 'Marker','*');
l12 = line(n8l12.yday,n8l12.sst,'Color','r','LineStyle','-', 'Marker','o');
l16 = line(n8l16.yday,n8l16.sst,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
%     axis([minx maxx 26.5 26.85]);
lh4=legend([shl sh2l l12 l16], legtxt2);
% set(lh4,'Box','off', 'FontSize',8)
set(lh4, 'FontSize',8);

subplot(2,1,2)
%shl=
line(hship.yday(sx), hship.Salinity(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('SSS (PSU)')
hold on
%l12 = 
line(n8l12.yday,n8l12.sal,'Color','r','LineStyle','-', 'Marker','o');
%l16 = 
line(n8l16.yday,n8l16.sal,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
%axis([minx maxx 5.25 6.2]);
%     axis([minx maxx 36.2 36.6]);
xlabel('Yearday 2008');

% fig 5 wspd top wdir bot
figure(5); clf
subplot(2,1,1);
legtxt3=['Ship '; 'Lgr12'; 'Lgr16'; ];

shl=line(hship.yday(sx), hship.wspd(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('WSPD (m/s)')
hold on
l12 = line(n8l12.yday,n8l12.wnds,'Color','r','LineStyle','-', 'Marker','o');
l16 = line(n8l16.yday,n8l16.wnds,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
% axis([minx maxx 4 8.2 ]);
lh5=legend([shl l12 l16 ], legtxt3);
% set(lh5,'Box','off', 'FontSize',8)
set(lh5, 'FontSize',8);


subplot(2,1,2)
shl=line(hship.yday(sx), hship.wdir(sx),'Color','k','LineStyle','-', 'Marker','^');
ylabel('WDIR(deg)')
hold on
l12 = line(n8l12.yday,n8l12.wndd,'Color','r','LineStyle','-', 'Marker','o');
l16 = line(n8l16.yday,n8l16.wndd,'Color','r','LineStyle','-', 'Marker','+');
ax=axis; axis([minx maxx ax(3:4)]);
%   axis([minx maxx 270 320]);
xlabel('Yearday 2008');


