summaryrefslogtreecommitdiff
path: root/ao-tools/lib
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-07-13 20:40:40 -0700
committerKeith Packard <keithp@keithp.com>2014-07-13 20:40:40 -0700
commit6c9daa4f471ac90ffce3bfe8876c9008f79a5b7f (patch)
treec6c1701aea6743daa30556a1e69b33fd2459a1ab /ao-tools/lib
parente447e1e5c90d3fc1be9c5a1c966c7c688a87ba18 (diff)
ao-tools: Provide altitude to temperature conversion function
This takes altitude and computes the 'normal' temperature for that. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/lib')
-rw-r--r--ao-tools/lib/cc-convert.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/ao-tools/lib/cc-convert.c b/ao-tools/lib/cc-convert.c
index 8d6876a0..b82dd778 100644
--- a/ao-tools/lib/cc-convert.c
+++ b/ao-tools/lib/cc-convert.c
@@ -108,6 +108,29 @@ cc_altitude_to_pressure(double altitude)
return pressure;
}
+double
+cc_altitude_to_temperature(double altitude)
+{
+
+ double base_temperature = LAYER0_BASE_TEMPERATURE;
+ double temperature;
+
+ int layer_number; /* identifies layer in the atmosphere */
+ double delta_z; /* difference between two altitudes */
+
+ /* calculate the base temperature for the atmospheric layer
+ associated with the inputted altitude */
+ for(layer_number = 0; layer_number < NUMBER_OF_LAYERS - 1 && altitude > base_altitude[layer_number + 1]; layer_number++) {
+ delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number];
+ base_temperature += delta_z * lapse_rate[layer_number];
+ }
+
+ /* calculate the pressure at the inputted altitude */
+ delta_z = altitude - base_altitude[layer_number];
+ temperature = base_temperature + lapse_rate[layer_number] * delta_z;
+
+ return temperature - 273.15;
+}
/* outputs the altitude associated with the given pressure. the altitude
returned is measured with respect to the mean sea level */