function [xx,ny,f]=fl_unpack(fin, kx, ky, L, d )
%  given Fluent output array, fin, and the index, kx, of the x-coordinate,
%  and the index ky of the y-coordinate
%  return xx=x-locations, ny=number of points at x-location, f containing
%  the data f(1:ny(k),:,k) at station k.

fin(:,2) = fin(:,2) ./ L;  % x/L
fin(:,3) = fin(:,3) ./ d;  % r/d
fin(:,7) = 2.*fin(:,7).*fin(:,14)./fin(:,6);  % chi=2eps*var(f)/k
fin(:,6) = sqrt( fin(:,6) );  % sqrt(k)
fin(:,14) = sqrt( fin(:,14) );  % rms(f)

g   = sortrows( fin, kx);  %  sort for increasing x
x   = g(:,kx);
dx  = diff(x);
thresh = 1.e-3*max(dx);    %  threshold for difference

nx=1;
xx(1) = x(1);
for k=1:size(x,1)-1;
    if dx(k) > thresh;
        kl(nx) = k;  % last entry in nx
        nx = nx + 1;
        xx(nx) = x(k+1);
    end
end
kl(nx)=size(x,1);

kl = kl'; xx = xx';
kf = kl; kf(1)=1; kf(2:nx)=kl(1:nx-1)+1;
ny = kl-kf+1;

f = zeros(max(kl-kf),size(fin,2),nx);
for k=1:nx
    f(1:1+kl(k)-kf(k),:,k) = sortrows( g(kf(k):kl(k),:), ky);
end