function B = siltprofiler_bin_salinity(z,s,spm,chlo,temp,i0,i1,lon,lat)


z    = z(i0:i1);
s    = s(i0:i1);
spm  = spm(i0:i1);
chlo = chlo(i0:i1);
temp = temp(i0:i1);


B.position = [lon,lat];
B.z        = -50:0.2:5;
B.salt     = [];
B.spm      = [];
B.chlo     = [];
B.temp     = [];

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



