function [mps, x, y] = ll2mps(dday,lon,lat);
% [mps, x, y] = ll2mps(dday,lon,lat);
% output sizes match input sizes by padding the first speed with 0 
%     and assuming the speed should be applied to the last time of 
%     the interval (consistent with shipboard adcp data)
% works on Nx1 or 1XN vectors only
% 

switchback = 0;
[rows, cols] = size(dday + lon + lat);
if (rows == 1)
   switchback = 1;
   dday = dday';
   lon = lon';
   lat = lat';
end


dy = lat_to_m(diff(lat),mid(lat));
dx = lon_to_m(diff(lon),mid(lat));
ds = sqrt(dx.^2 + dy.^2);
x = cumsum([0;dx]);
y = cumsum([0;dy]);
s = cumsum([0;ds]);
mps = ds./(diff(dday)*86400);
mps = [0; mps];

if (switchback)
   mps = mps';
   x = x';
   y = y';
end
