Dew-Point and absolute humidity can be calculated from temperature in celsius and relative humidity.
The Barometer class expects both values as inputs and calculates absolute humidity af and dew-point td.
| import kotlin.math.log10 | |
| import kotlin.math.pow | |
| data class Barometer(val r: Double, val t: Double) { | |
| // Konstanten | |
| private val mw = 18.016 // Molekulargewicht des Wasserdampfes (kg/kmol) | |
| private val gk = 8214.3 // universelle Gaskonstante (J/(kmol*K)) | |
| private val t0 = 273.15 // Absolute Temperatur von 0 °C (Kelvin) | |
| private val a = if (t >= 0.0) 7.5 else 7.6 | |
| private val b = if (t >= 0.0) 237.3 else 240.7 | |
| // Temperatur in Kelvin | |
| private val tk = t + t0 | |
| // Sättigungsdampfdruck (hPa) | |
| private val sdd = 6.1078 * 10.0.pow((a * t) / (b + t)) | |
| // Dampfdruck (hPa) | |
| private val dd = sdd * (r / 100.0) | |
| // Absolute Feuchte (g/m3) | |
| val af = 10.0.pow(5) * mw / gk * dd / tk | |
| // Taupunkttemperatur (°C) | |
| val td = log10(dd / 6.1078).let { v -> (b * v) / (a - v) } | |
| override fun toString() = "[r = $r, t = $t, af = $af, td = $td]" | |
| } |