OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

Temperatures

public static class Temperatures

Converting, rounding and labelling a temperature for a person, the same way in every Optris application and every SDK language.

A temperature and a difference convert differently. A temperature is a point on the scale: F = C × 9/5 + 32. A difference is a distance on it: F = K × 9/5, with no offset. An alarm's hysteresis, the limits of a rule with a reference (which are offsets), a standard deviation and a colour-scale span are differences. Converting 2 K like a temperature shows 35.6 °F; the right answer is 3.6 °F. So there are two pairs of methods, and the name says which one a number needs.

Converting never rounds. A value typed in Fahrenheit survives the trip into Celsius and back: 70.1 °F is stored as 21.1666… °C and shown as 70.1 °F again. Rounding the Celsius value to a tenth first would store 21.2 °C, which reads back as 70.2 °F.

Rounding happens once, when the number becomes text. Temperatures.Format(…) and Temperatures.FormatDifference(…) convert first and then round once, in the unit shown, half away from zero: 21.25 becomes "21.3" and -21.25 becomes "-21.3" at one decimal. "Half" is judged on the decimal number the Double stands for, the shortest decimal that reads back as the same double, which is what ToString() shows for it: 2.675 rounds to "2.68" at two decimals although no double holds 2.675 exactly. A result that rounds to zero has no sign: "0.0", not "-0.0".

These take and give Celsius and kelvin whatever Sdk.TemperatureUnit says. They are for a program that keeps the SDK in Celsius and converts for display itself. With Fahrenheit chosen there, the SDK's values are already in Fahrenheit and need no conversion here.

Every method here runs the SDK's own code through the C ABI, so C#, C++, C, Python and Rust show the same last digit for the same reading. None of them touches a camera; all are safe from any thread.

Example

TemperatureUnit unit = TemperatureUnit.Fahrenheit;

// A reading: "70.3 °F".
string shown = Temperatures.Format(21.3, unit, 1)
    + " " + Temperatures.Symbol(unit);

// A hysteresis of 2 K: "3.6", not "35.6".
string band = Temperatures.FormatDifference(2.0, unit, 1);

// What the user typed, stored in Celsius without rounding.
double limitC = Temperatures.ToCelsius(70.1, unit);

Temperatures: methods

public static string Format(double celsius, TemperatureUnit unit, int decimals, IFormatProvider? provider = null)

A Celsius temperature as text in unit: converted, then rounded once, half away from zero, to decimals decimals, without the symbol.

  • celsius: The temperature, in degrees Celsius.
  • unit: The unit to show it in.
  • decimals: How many decimals, 0 to 15.
  • provider: Whose decimal separator and minus sign to use, for example CultureInfo.GetCultureInfo("de-DE") for "21,3". null means the current culture, as everywhere in.NET. There is never a group separator, and the digits are always 0 to 9.

Returns: The text, or an empty string for Double.NaN and the infinities, so the application decides how it shows a missing value.

  • Throws SdkConfigurationException: unit is not one of the two units, or decimals is outside 0 to 15.
public static string FormatDifference(double kelvin, TemperatureUnit unit, int decimals, IFormatProvider? provider = null)

A temperature difference in kelvin as text in degrees of unit: converted with no offset, then rounded exactly as Temperatures.Format(…) rounds. 2 K in Fahrenheit is "3.6", not "35.6".

  • kelvin: The difference, in kelvin.
  • unit: The unit to show it in.
  • decimals: How many decimals, 0 to 15.
  • provider: As for Temperatures.Format(…); null means the current culture.

Returns: The text, or an empty string for Double.NaN and the infinities.

  • Throws SdkConfigurationException: unit is not one of the two units, or decimals is outside 0 to 15.
public static double FromCelsius(double celsius, TemperatureUnit unit)

A temperature (a point on the scale) from degrees Celsius into unit. Does not round.

  • Throws SdkConfigurationException: unit is not one of the two units.
public static double FromKelvinDifference(double kelvin, TemperatureUnit unit)

A temperature difference (a distance on the scale) from kelvin into degrees of unit: K × 9/5 for Fahrenheit, with no offset. Does not round.

  • Throws SdkConfigurationException: unit is not one of the two units.
public static string Symbol(TemperatureUnit unit)

The unit's symbol: the degree sign (U+00B0) followed by C or F.

  • Throws SdkConfigurationException: unit is not one of the two units.
public static double ToCelsius(double value, TemperatureUnit unit)

A temperature in unit back into degrees Celsius, for storing what a person typed. Does not round.

  • Throws SdkConfigurationException: unit is not one of the two units.
public static double ToKelvinDifference(double value, TemperatureUnit unit)

A temperature difference in degrees of unit back into kelvin. Does not round.

  • Throws SdkConfigurationException: unit is not one of the two units.