function bug2ind(b,ndrft,sampint)

% function bug2ind(b,ndrft,sampint)
%
% Assumes b is 4 column VPR data of the form:
%   lon (negative)
%   lat
%   depth (negative)
%   yearday (assumes year=1999)
%
% ndrift: number of drogues to release, evenly spaced from data positions.
% sampint: number of drogue timesteps between drogue updates

if nargin<2
  ndrft=100;
end

if nargin<3
  sampint=5;
end

[x,y]=ll2xy(b(:,2),b(:,1));
z=b(:,3);
t=b(:,1);

ind=ceil([1:ndrft]/(ndrft)*size(b,1));
xdr=x(ind);
ydr=y(ind);
zdr=z(ind);
tpts=b(ind,4);

wtime=clock;
fid=fopen('BUG_Drifter.ind','w');
fprintf(fid,'Comment:\n');
fprintf(fid,'vpr bug data; file written: %s\n', ...
	datestr(datenum(now)));
fprintf(fid,' # of model dt"s btwn particle position updates\n',[]);
fprintf(fid,'1\n',[]);
fprintf(fid,' # of drog updates btwn drogue outputs\n',[]);
fprintf(fid,'%i\n',sampint);
fprintf(fid,' grid scaling factors in x,y directions\n',[]);
fprintf(fid,'1.0  1.0  1.0\n',[]);
fprintf(fid,' drog coordinate scaling factors\n',[]);
fprintf(fid,'1.0  1.0  1.0\n');
fprintf(fid,' Number of starting drogues (ndr)\n',[]);
fprintf(fid,'%i\n',ndrft);
fprintf(fid,' Starting Positions of Drogues\n',[]);
fprintf(fid,...
	'%10.1f %10.1f %7.2f %5i %10.5f\n',...
	[xdr ydr zdr 1999*ones(ndrft,1) tpts]');
fclose(fid);

m=loadgrid('bank150');
clf
plotbnd(m);
lcontour(m,m.z,[60 100]);
hold on
plot(xdr,ydr,'x','markersize',3);
