function del = TU2del(TU,T,S,He4,flag)

% USAGE: dHe3 % = TU2del(He3 in TU,T,S,He4,flag)
%  Function to convert TU to del He3 (%)
% He4 is the measured value. T, S are temp and salinity. All
% input arguments must be vectors of same length.
% TU is the TRITUGENIC He3 in TU.
% If a measured He4 value is not available (i.e. 
% He4 is NaN, there is the option to use the solubility equilibrium
% value by setting flag=1. If flag=0, and He4=NaN,
% a NaN is returned for that value of TU.
% WARNING: make sure T or S are not NaN.

% Samar Khatiwala (spk@ldeo.columbia.edu)

Ra = 1.384e-6; % atmospheric 3/4 ratio
He4eq = HEsol(T,S); % solubility equilibrium conc. Weiss, 1971.

i = find(isnan(He4)); % if a He4 measurement is not available
if ((flag==1) & (length(i)>0)) % and flag = 1
  He4(i) = He4eq(i); % use solubility equilibrium value.
end

del = (2.4869e-15*100/Ra)*(TU./He4).*(1 - (S/1000));
