% routine to regrid in lagrangian coordinates given:
%
%          input: time series of velocity: (tc,uc,vc)
%                 lat/lon shiptrack:       (ts,lat,lon)
%
%         output: the lagrangian coordinates (t,x,y)
%                 relative to initial observation


% call julio's "detide.m" to generate some current
[ut,vt,tc]=maktide;


% load in some lat/lon adcp ship track time series
load /data5/jmanning/adcp/tranhsj9507
ts=(th-(95-94)*365*24)/24;
lat=lath;
lon=lonh;


% calculate distances for each of above
[xc,yc,mag]=provecxy(ut*100,vt*100,3600);
[xs,ys]=distxy(lat,lon);

% now calculate lagrangian distance
% first have to match the yeardays
ik=0;
for is=1:length(ts);
  for ic=1:length(tc);
    if abs(ts(is)-tc(ic))<(1/24)
       ik=ik+1;
       x(ik)=xs(is)-xc(ic);
       y(ik)=ys(is)-yc(ic);
    end;
  end;
end;

% plot ship movement
subplot(3,1,1);
id=find(ts>min(tc)&ts<max(tc));
plot(xs(id),ys(id));
title('ship');
 axis('equal')

% plot water movement
subplot(3,1,2);
plot(xc,yc);
title('water');
 axis('equal')

% plot position of measurement relative to 1st parcel
subplot(3,1,3);
plot(x,y);
title('observation point relative to obs#1')
 axis('equal')