function [fmeas, pmeas] = uv2fp(arg1, arg2, arg3);
% use velocity and heading to rotate into forward and port components
%
% real velocities in gives two real velocities out 
% [fmeas, pmeas] = uv2fp(umeas, vmeas, heading)    
%
% complex velocity in, one argument (complex) out
% [fmeas + i*pmeas] = uv2fp(umeas + i*vmeas, heading) %complex velocities

if (nargin == 3)
   cuv = arg1 + i*arg2;
   heading = arg3;
   output_real = 1;
else %velocity in is complex
   if isreal(arg1)
      error('two arguments implies the first argument is u+iv (complex)')
   end
   
   cuv = arg1;
   heading = arg2;
   output_real = 0;
end


[hrow, hcol] = size(heading);
[urow, ucol] = size(cuv);


if ((hrow == 1) | (hcol == 1))
   rads = (90-heading(:)')*pi/180;
   if ((urow == 1) | (ucol == 1))
      cuv = cuv(:).';       % !!! complex: want transpose, not compl. conj.
   else
      rads = repmat(rads, length(cuv(:,1)), 1);
   end
else
   if ((urow ~= hrow) | (ucol ~= hcol))
      error('heading not same size as u or v')
   end
   %keep the original size
   rads = (90-heading)*pi/180;   
end


fp = cuv.*exp(-i*rads);

if (output_real)
   fmeas = real(fp);
   pmeas = imag(fp);
else
   fmeas = fp;
   if (nargout == 2)
      fprintf('complex velocities in gives one complex answer out:\n')
      fprintf('fore+i*port\n')
      error('only one output expected for complex input')
   end
end

      
         
