% plt_map_sam.m - plot sampling runs and injection

clear h

cast = 13
figure(1)
clf

cast_str=int2str(cast);
if cast < 10
  cast_str=['00',cast_str];
elseif cast < 100
  cast_str=['0',cast_str];
end

if cast == 1
  Lat_min=29.7;
  Lat_max=29.9;
  Lon_min=-69.16;
  Lon_max=-68.98;
elseif cast == 2
  Lat_min=29.7;
  Lat_max=29.8;
  Lon_min=-69.5;
  Lon_max=-69.2;
elseif cast == 3
  Lat_min=29.72;
  Lat_max=29.82;
  Lon_min=-69.58;
  Lon_max=-69.25;
elseif cast == 4
  Lat_min=29.6;
  Lat_max=29.75;
  Lon_min=-69.6;
  Lon_max=-69.25;
elseif cast == 6
  Lat_min=29.9;
  Lat_max=30.2;
  Lon_min=-69.9;
  Lon_max=-69.5;
elseif cast == 7
  Lat_min=29.65;
  Lat_max=29.75;
  Lon_min=-69.75;
  Lon_max=-69.4;
elseif cast == 8
  Lat_min=29.8;
  Lat_max=30.05;
  Lon_min=-69.75;
  Lon_max=-69.5;
elseif cast == 9
  Lat_min=29.7;
  Lat_max=29.9;
  Lon_min=-69.6;
  Lon_max=-69.4;
elseif cast == 10
  Lat_min=29.65;
  Lat_max=29.8;
  Lon_min=-69.5;
  Lon_max=-69.2;
elseif cast == 11
  Lat_min=29.7;
  Lat_max=29.88;
  Lon_min=-69.45;
  Lon_max=-69.;
elseif cast == 13
  Lat_min=29.7;
  Lat_max=29.9;
  Lon_min=-69.9;
  Lon_max=-69.55;
else
  error('set lat/lon limits for this cast')
end

m_proj('mercator','lat',[Lat_min Lat_max],'lon',[Lon_min Lon_max])

%%%%%%%%%%%%%%% Sampling casts start here
eval(['load SAM_',cast_str,'_fl'])
aa=find(sampl == 1 & lon < -60);


h(1)=m_plot(lon(aa),lat(aa),'b');
hold on

% this show when the samplers stopped according to watches
%cc=find(min(abs( postime-(yearday(aa(1))+8/24+20/24/60) )) ...
%   == abs( postime-(yearday(aa(1))+8/24+20/24/60) ));
%h(10)=m_plot(-lon(cc),lat(cc),'*k','markersize',10);

% add medusa sampling
[st_time en_time]=get_med(cast);
for ii = 1:length(st_time)
  aa=find( min(abs(yearday-st_time(ii))) ==  ...
	   abs(yearday-st_time(ii)));
  if ~isempty(aa),
    cc(ii)=aa(1);
    %bb=find( min(abs(yearday-en_time(ii))) ==  ...
    %   abs(yearday-en_time(ii)));
    %if isempty(bb), bb=length(yearday);end
    if cast == 6 & lon(cc(ii)) > -10
      disp('fixing a longitude!')
      keyboard
      (lon(cc(ii)-1)+lon(cc(ii)+1))/2
      lon(cc(ii)) = (lon(cc(ii)-1)+lon(cc(ii)+1))/2;
    elseif cast == 10 & lon(cc(ii)) > -69.2
      disp('fixing a longitude!')
      keyboard
      (lon(cc(ii)-6)+lon(cc(ii)+5))/2
      lon(cc(ii)) = (lon(cc(ii)-6)+lon(cc(ii)+5))/2;
    end
    hh(ii)=m_plot(lon(cc(ii)),lat(cc(ii)),'xr');
    mlat(ii) = lat(cc(ii));
    mlon(ii) = lon(cc(ii));
    if floor(ii/5) == ii/5
      m_text(lon(cc(ii)),lat(cc(ii)),['  ',int2str(ii)],'fontsize',10)
    end
  end
  h(2)=hh(1);
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')

legend(h,['Sam ',int2str(cast)],'medusa')
% save the time and position dat
m_st=st_time;
m_en=en_time;
title(['EDDIES - Sampling ',int2str(cast), ...
       ' - medusa syringe filling locations'])

eval(['print -dpng sam',int2str(cast),'_map.png'])
eval(['save med',int2str(cast),'_pos mlat mlon m_st m_en'])
