% plot_os75.m
% =====================================================
% plot velocity vectors using OS75 adcp data
% =====================================================

clf
set(gcf,'color','w');

% load CODAS output data: contour
load /home/howitt/adcp/oc415/contour/contour_uv
load /home/howitt/adcp/oc415/contour/contour_xy

% averaging through the depth 250 m (22 x 10m + 30 m); 
% codas output is 10 m bins (8 m is setup of OS75)
nd=22;
u=uv(1:nd,1:2:end);
v=uv(1:nd,2:2:end);
% get averages         
um=nanmean(u);vm=nanmean(v);
lon=xyt(1,:)-360;
lat=xyt(2,:);
time=xyt(3,:);
% set up time limit: it's not necessary to display the whole
% record from the very beginning; so, let's start from some point n1 
% until n2
%n1=1;n2=length(um);
%% CHANGE PLOT START TIME BY CHANGING n1 - CJS
n1=900;n2=length(um);
while isnan(lat(n2))
  n2 = n2 - 1;
end

start=datestr(time(n1)+datenum(2005,1,1),0);
endt=datestr(time(n2)+datenum(2005,1,1),0);
% this line is to stretch a figure whether ship track is 
% meridional
plot([-67. -66.2],[30.8 30.8],'w-');
set(gca,'fontsize',16,'fontweight','bold')
hold on
h(1) = plot(lon(n1:n2),lat(n1:n2),'m-','linewidth',2);
ss=find(~isnan(lon)==1);
n2=ss(end)

%add adcp vectors
h2=vecplot2(lon(n1:n2),lat(n1:n2),um(n1:n2),vm(n1:n2),1.0,'cm/sec', -67.3,30.65)

% add position of last ADCP fix
h(2)=plot(lon(n2),lat(n2),'d','markersize',10,'markerfacecolor','c',...
     'markeredgecolor','r');
% add current ship position
mm = datestr(now,5);
dd  = datestr(now,7);
[lon,lat,year,month,day,hour,minit,sec]=get_gps(mm,dd);
h(3)=plot(lon(end),lat(end),'d','color','k','markersize',10,'markerfacecolor','m');
% this adds an 'icon' of the oceanus but had trouble with it. and
% legend needs fixing
%add_OC(lon(end),lat(end),8);

% add ship track between current position and last adcp fix
track_index = find(datenum(year,month,day,hour,minit,sec)> ...
		   datenum(time(n2)+datenum(2005,1,1)));
plot(lon(track_index),lat(track_index),'m','linewidth',2)

grid

% plot spar buoy position
load /mnt/oc415-2a/oc415_2/spar/eddies_pos.mat
sp_lati = lat;
clear lat
sp_longi = lon;
clear lon
h(4)=plot(sp_longi,sp_lati,'r*:','markersize',10);

% plot seahorse position
[sh_dtstr, sh_fixtime, sh_lati, sh_longi] = textread('/mnt/oc415-2a/oc415_2/adcp/positions/seahorse.dat','%s%d%f%f','headerlines',1);
h(5)=plot(sh_longi,sh_lati,'g^:','markersize',10,'markerfacecolor','g'); ...

% James EM-APEX 1633       
[EM1633_dtstr, EM1633_fixtime, EM1633_lati, EM1633_longi] = textread('/mnt/oc415-2a/oc415_2/adcp/positions/float_1633.dat','%s%d%f%f','headerlines',1);
% plot seahorse launch position
h(6)=plot(EM1633_longi,EM1633_lati,'kp:','markersize',15,'markerfacecolor','k'); ...
% plot center position       
[cen_dtstr, cen_fixtime, cen_lati, cen_longi] = textread('/mnt/oc415-2a/oc415_2/adcp/positions/trajectory.dat','%s%d%f%f','headerlines',1);
% plot seahorse launch position
h(8)=plot(cen_longi,cen_lati,'ko--','markersize',10,'markerfacecolor','y'); ...

% plot CTD stations
[ctd_dtstr, ctd_fixtime, ctd_lati, ctd_longi, std_num] = textread('/mnt/oc415-2a/oc415_2/adcp/positions/station.dat','%s%d%f%f%d','headerlines',1);
h(7)=plot(ctd_longi,ctd_lati,'ko','markersize',10,'markerfacecolor','k'); 
%plot(sh_longi,sh_lati+0.05,int2str(std_num)); 


title(['OS75: time (GMT): ',start,' -- ',endt]);

% add the legend
legend(h,'Ship Track','Last ADCP','Current Ship','Spar Buoy', ...
       'SeaHorse','EM-APEX 1633','CTD')

xlabel('Longitude')
ylabel('Latitude')

% change final axis limits here:
ax=axis;
axrat = 1/cos(mean(ax(3:4))*pi/180);
set(gca,'DataAspectRatio',[1 1/axrat 1]);
axis([-67.5 -66.7 30.1 30.7])


set(gcf,'position',[1 55 1280 897])
