X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Flib%2Fcc-convert.c;h=0f7fa809ecd77864be20d5b866529f7c1c082308;hb=1085ec5d57e0ed5d132f2bbdac1a0b6a32c0ab4a;hp=8d6876a064422a202fd7d3de99ea6ecd3cc4174e;hpb=9856b7c4397afcecc8f541af9a83824e817b3612;p=fw%2Faltos diff --git a/ao-tools/lib/cc-convert.c b/ao-tools/lib/cc-convert.c index 8d6876a0..0f7fa809 100644 --- a/ao-tools/lib/cc-convert.c +++ b/ao-tools/lib/cc-convert.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -108,6 +109,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 */