% plt_map_inj.m
% this one uses the stuff to plot the vectors

set(0,'defaultaxesfontsize',14')

figure(1)
clf
hold on

% load CODAS output data: contour
load contour_uv
load 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);
adcp_lon=xyt(1,:)-360;
adcp_lat=xyt(2,:);
adcp_time=xyt(3,:);

% injection map
Lat_min=30.25;
Lat_max=30.5;
Lon_min=-67.4;
Lon_max=-67.0014;
m_proj('mercator','lat',[Lat_min Lat_max],'lon',[Lon_min Lon_max])

%%%%%%% initial load for limits
% plot tracks of 2 injection streaks (cast 3 and 4)
load INJ_003_fl
load INJ_003_spd
% some bad points... make them nan
zz=find(lon > -60);
lon(zz)=nan;
aa=find(diff(lon) > 1e-4);
bb=find(diff(lon) < -1e-4);
lon(aa(1):bb(1))=nan;
lon(aa(2):bb(2))=nan;
lon(aa(3):bb(3))=nan;
lon(bb(4):end)=nan;

% when are pumps on and pumping sf6?
p1_spd = spd_1;
p2_spd = spd_2;
psf6_1 = pump_1 + p1_sf6;
psf6_2 = pump_2 + p2_sf6;
ind_p1 = find(psf6_1 == 2);
ind_p2 = find(psf6_2 == 2);

a3=find(adcp_time>= yearday(ind_p2(1)));
a3=a3(1);

load INJ_004_fl
psf6_1 = pump_1 + p1_sf6;
psf6_2 = pump_2 + p2_sf6;
ind_p1 = find(psf6_1 == 2);
ind_p2 = find(psf6_2 == 2);
% pump 1 not working - show only when pump 2 on and pumping SF6
%m_scatter(lon(ind_p2),lat(ind_p2),fl(ind_p2))

a4=find(adcp_time <= yearday(ind_p2(end)));
a4=a4(end);

% plot adcp stuff
ind = a3:a4;
h2=m_vecplot2(adcp_lon(ind),adcp_lat(ind),um(ind),vm(ind), ...
	      1.0,'cm/sec', -67.3,30.4, ...
	      [Lon_min Lon_max],[Lat_min,Lat_max]);


%%%%%%%%%% LOAD again to plot Chl
% plot tracks of 2 injection streaks (cast 3 and 4)
load INJ_003_fl
load INJ_003_spd
% some bad points... make them nan
zz=find(lon > -60);
lon(zz)=nan;
aa=find(diff(lon) > 1e-4);
bb=find(diff(lon) < -1e-4);
lon(aa(1):bb(1))=nan;
lon(aa(2):bb(2))=nan;
lon(aa(3):bb(3))=nan;
lon(bb(4):end)=nan;

% when are pumps on and pumping sf6?
p1_spd = spd_1;
p2_spd = spd_2;
psf6_1 = pump_1 + p1_sf6;
psf6_2 = pump_2 + p2_sf6;
ind_p1 = find(psf6_1 == 2);
ind_p2 = find(psf6_2 == 2);

% pump 1 not working - show only when pump 2 on and pumping SF6
% interpolate range of chl onto colormap

% map onto a range of Chlorophyll values:
flmin=.5;flmax=9;
aa=find(fl<flmin);
fl(aa)=flmin;
aa=find(fl>flmax);
fl(aa)=flmax;
chl_c=floor(interp1([flmin flmax],[1 64],fl(ind_p2)));

ccc=colormap;
for ii = 1:200:length(ind_p2)
  m_plot(lon(ind_p2(ii)),lat(ind_p2(ii)),'.', ...
	 'color',ccc(chl_c(ii),:), ...
	 'markersize',10)
end
%m_scatter(lon(ind_p2),lat(ind_p2),fl(ind_p2))

if 0
  % output subsampled data for plotting on big map
  fid=fopen('inj_dat.txt','w');
  for ii = 1:480:length(ind_p2)
    fprintf(fid,'%f %f\n',lon(ind_p2(ii)),lat(ind_p2(ii)));
  end
end

load INJ_004_fl
psf6_1 = pump_1 + p1_sf6;
psf6_2 = pump_2 + p2_sf6;
ind_p1 = find(psf6_1 == 2);
ind_p2 = find(psf6_2 == 2);
% pump 1 not working - show only when pump 2 on and pumping SF6
%m_scatter(lon(ind_p2),lat(ind_p2),fl(ind_p2))

aa=find(fl<flmin);
fl(aa)=flmin;
aa=find(fl>flmax);
fl(aa)=flmax;
chl_c=floor(interp1([flmin flmax],[1 64],fl(ind_p2)));
for ii = 1:200:length(ind_p2)
  m_plot(lon(ind_p2(ii)),lat(ind_p2(ii)),'.','color',ccc(chl_c(ii),:))
end

if 0
  % output subsampled data for plotting on big map
  for ii = 1:480:length(ind_p2)
    fprintf(fid,'%f %f\n',lon(ind_p2(ii)),lat(ind_p2(ii)));
  end
  fclose(fid)
end

m_grid('box','on','tickdir','in','fontweight','bold'); 
% this makes the color reappear
set(findobj('tag','m_grid_color'),'facecolor','none')

xlabel('Longitude')
ylabel('Latitude')
title('EDDIES - Injection - colored by Chlorophyll')

% add a colorbar - need to specify labels
hh=colorbar;
td=(flmax-flmin)/10; % 10 is nticks-1
ctick=flmin:.85:flmax;
clear ylab
for ii = 1:11
  ylab(ii)={sprintf('%4.2f',ctick(ii))};
end
set(hh,'yticklabel',ylab)


return
