SBE 16-03 Temperature MATLAB Implementation

function [temperature, status] = sbe1603do_temperature ( raw_sensor_temp, coefs )
% SBE1603DO_TEMPERATURE:  Compute temperature from frequency
%
% USAGE:  [temperature, status] = sbe1603do_temperature ( raw_sensor_temp, coefs );
%
% PARAMETERS:
% Input:
%    raw_sensor_temp:  
%       as reported by sbe 1603
%    coefs:
%       vector of 5 calibration coefficients [g h i j f0]
% 
% Output:
%    temperature:  degrees celsius
%    status:  -1 if failure
%
% ITS-90 can be computed with one set of coefficients, IPTS-68
% with another.  T68 can also be computed by 1.00024*T90
%
% See the SEACAT SBE 16-03 Conductivity and Temperature Recorder 
% Operating Manual.
%

temperature = [];
status = -1;

if nargin ~= 2
	help sbe1603do_temperature;
	return
end

%
% check the coefficients, must be length 5
if ( length(coefs) ~= 5 )
	fprintf ( 2, '%s:  must supply 5 coefficients.\n', mfilename );
	help sbe1603do_temperature;
	return
end


%
% unpack the coefficients
g = coefs(1);
h = coefs(2);
i = coefs(3);
j = coefs(4);
f0 = coefs(5);

f = raw_sensor_temp / 19 + 2100;

lnff0 = log ( f0 ./ f );
temperature = 1 ./ ( g + h*lnff0 + i*lnff0.^2 + j*lnff0.^3 ) - 273.15;


status = 1;
return