ao-tools: Provide altitude to temperature conversion function
authorKeith Packard <keithp@keithp.com>
Mon, 14 Jul 2014 03:40:40 +0000 (20:40 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 14 Jul 2014 03:40:40 +0000 (20:40 -0700)
This takes altitude and computes the 'normal' temperature for
that.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/lib/cc-convert.c

index 8d6876a064422a202fd7d3de99ea6ecd3cc4174e..b82dd778bc3969140f2270b104fa07ae3a0663ce 100644 (file)
@@ -108,6 +108,29 @@ cc_altitude_to_pressure(double altitude)
    return pressure;
 }
 
    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 */
 
 /* outputs the altitude associated with the given pressure. the altitude
    returned is measured with respect to the mean sea level */