function B = siltprofiler_bin(A,L)

for ifile = 78:82
z = A(ifile).depth(L.down_start(ifile):L.down_end(ifile));
%z = z + rand(size(z)).*.1;
s = A(ifile).salinity(L.down_start(ifile):L.down_end(ifile));

figure,
plot(s,z,'b-')
hold on
B.position = [];
B.z        = -50:0.2:5;
B.salt     = [];

for bin=1:length(B.z)-1
   mask =  z > B.z(bin) & ...
           z < B.z(bin+1);
       %plot(mask,z)
       %pause
    B.salt(bin) = mean(s(mask));
end
stairs([nan B.salt],B.z,'r')
B.salt=B.salt(ifile);
clear s
clear z
end

B=B.salt;
