function e = emfTtype(T)
% emfTtype  EMF of T type thermocouple as function of temperature
%
% Synopsis:  e = emfTtype(T)
%
% Input:  T = temperature, degrees C,  -270 <= T <= 400 C
%
% Output: e = thermocouple emf in Volts
e = zeros(size(T));    %  preallocate so e vector will be contiguous in memory
n = 1:length(T);       %  vector to monitor which T values have been converted
ihi = find(0<=T & T<=400);  %  vector of indices such that 0 <= T(i) <= 400
ilo = find(-270<=T & T<0);  %  vector of indices such that -270 <= T(i) <= 0
if ~isempty(ihi)
	c = [-2.7512901673e-17  4.5479135290e-14  -3.0815758772e-11   1.0996880928e-8 ...
       -2.1882256846e-6   2.0618243404e-4    3.3292227880e-2   38.748106364  0];
  e(ihi) = polyval(c,T(ihi));
  n(ihi) = 0;   %  these i values are done, set elements in monitor vector to zero
end
if ~isempty(ilo)
  c = [ 7.9795153927e-28  1.3945027062e-24  1.0795539270e-21  4.8768662286e-19 ...
        1.4251594779e-16  2.8213521925e-14  3.8493939883e-12  3.6071154205e-10 ...
        2.2651156593e-8   9.0138019559e-7   2.0032973554e-5   1.1844323105e-4 ...
        4.4194434347e-2  38.748106364  0];
  e(ilo) = polyval(c,T(ilo));
  n(ilo) = 0;   %  these i values are done, set elements in monitor vector to zero
end
e = e*1e-6;   %  convert microvolts to volts
% --- Check to see if all elements of T vector have been converted
if any(n)
  nn = n(find(n~=0));   %  select only the nonzero indices
  warning(sprintf('T = %g value outside of range -270 <= T <= 400 C\n',T(nn)));
end
