function [vol,s2]=freshcalc(cdf,zback,tind);

%function (vol,s2)=freshcalc(cdf,depth);
% determine freshwater fraction by 
% calculating a "background" salinity s2
% below depth zback, then calculating
% the amount of freshwater above zback
% via v=v1(1-s1/s2) where v1 is the total
% volume above zback, and s1 is the mean
% salinity above zback and s2 is the mean
% salinity below zback

zback=abs(zback);
[d,x,y]=kslice(cdf,'depth');
dmax=abs(gmax(d(:)));
[nx,ny]=size(d);
[ctot2,s2]=ctotal3(cdf,'salt',tind,[1 nx 1 ny],-zback,-150);
[ctot1,s1]=ctotal3(cdf,'salt',tind,[1 nx 1 ny],0,-zback);
vol1=ctot1/s1;
vol=vol1*(1-s1/s2);

