function [Tout] = mV_to_t_inC(mV, Tref)
    % by Eugeniy E. Mikhailov 2020/09/01
    % Converts T-type thermocouple voltage in mV to Temperature in degrees C
    % Tref corresponds to temperature of the reference,
    % i.e. the temperature at which the other end is kept. See
    % https://en.wikipedia.org/wiki/Thermocouple
    % Tref is optional argument, if it is not supplied it assumed that
    % Tref = 0
    %
    % We will piggyback on t_inC_to_mV function which uses
    % NIST data for conversion
    
    % let's prepare data for interpolation
    Np=1000;
    Ti = linspace(-270, 400, Np);
    if nargin == 1
        Tref = 0;
    end
    mVi = t_inC_to_mV(Ti, Tref);
    
    Tout = interp1(mVi, Ti, mV);
end
