00001 /* ***************************************************** */ 00002 /* Compute standard atmosphere pressure given altitude. */ 00003 /* alt_to_press.c */ 00004 /* ***************************************************** */ 00005 /* Author: Christian Page, CERFACS, Toulouse, France. */ 00006 /* ***************************************************** */ 00011 /* LICENSE BEGIN 00012 00013 Copyright Cerfacs (Christian Page) (2015) 00014 00015 christian.page@cerfacs.fr 00016 00017 This software is a computer program whose purpose is to downscale climate 00018 scenarios using a statistical methodology based on weather regimes. 00019 00020 This software is governed by the CeCILL license under French law and 00021 abiding by the rules of distribution of free software. You can use, 00022 modify and/ or redistribute the software under the terms of the CeCILL 00023 license as circulated by CEA, CNRS and INRIA at the following URL 00024 "http://www.cecill.info". 00025 00026 As a counterpart to the access to the source code and rights to copy, 00027 modify and redistribute granted by the license, users are provided only 00028 with a limited warranty and the software's author, the holder of the 00029 economic rights, and the successive licensors have only limited 00030 liability. 00031 00032 In this respect, the user's attention is drawn to the risks associated 00033 with loading, using, modifying and/or developing or reproducing the 00034 software by the user in light of its specific status of free software, 00035 that may mean that it is complicated to manipulate, and that also 00036 therefore means that it is reserved for developers and experienced 00037 professionals having in-depth computer knowledge. Users are therefore 00038 encouraged to load and test the software's suitability as regards their 00039 requirements in conditions enabling the security of their systems and/or 00040 data to be ensured and, more generally, to use and operate it in the 00041 same conditions as regards security. 00042 00043 The fact that you are presently reading this means that you have had 00044 knowledge of the CeCILL license and that you accept its terms. 00045 00046 LICENSE END */ 00047 00048 00049 00050 00051 00052 00053 00054 #include <utils.h> 00055 00057 void 00058 alt_to_press(double *pres, double *alt, int ni, int nj) { 00059 00067 /* 00068 ; Convert an array of (pressure-) altitudes (m) into an array of 00069 ; pressures (hPa) using the ICAO standard atmosphere definition 00070 ; 00071 ; See <A HREF="http://www.pdas.com/coesa.htm">exact definition 00072 ; here<\A> 00073 ; 00074 ; The 7 layers of the US standard atmosphere are: 00075 ; 00076 ; h1 h2 dT/dh h1,h2 geopotential alt in km 00077 ; 0 11 -6.5 dT/dh in K/km 00078 ; 11 20 0.0 00079 ; 20 32 1.0 00080 ; 32 47 2.8 00081 ; 47 51 0.0 00082 ; 51 71 -2.8 00083 ; 71 84.852 -2.0 00084 */ 00085 00086 #define NLAYERS 7 00088 int i; /* Loop counter */ 00089 int layr; /* Loop counter */ 00090 00091 double limits[NLAYERS+1]; 00092 double lapse_rate[NLAYERS]; 00093 int isoth[NLAYERS]; 00094 double presb[NLAYERS]; 00095 double tb[NLAYERS]; 00096 00097 int layer = 0; 00098 00099 /* Layer boundaries in m */ 00100 limits[0] = 0.0; 00101 limits[1] = 11.0 * 1000.0; 00102 limits[2] = 20.0 * 1000.0; 00103 limits[3] = 32.0 * 1000.0; 00104 limits[4] = 47.0 * 1000.0; 00105 limits[5] = 51.0 * 1000.0; 00106 limits[6] = 71.0 * 1000.0; 00107 limits[7] = 84.852 * 1000.0; 00108 00109 /* Lapse rates in each layer (9 means 0) */ 00110 lapse_rate[0] = -6.5 / 1000.0; 00111 lapse_rate[1] = 9.0; 00112 lapse_rate[2] = 1.0 / 1000.0; 00113 lapse_rate[3] = 2.8 / 1000.0; 00114 lapse_rate[4] = 9.0; 00115 lapse_rate[5] = -2.8 / 1000.0; 00116 lapse_rate[6] = -2.0 / 1000.0; 00117 00118 /* Flag for isothermal layers */ 00119 isoth[0] = 0; 00120 isoth[1] = 1; 00121 isoth[2] = 0; 00122 isoth[3] = 0; 00123 isoth[4] = 1; 00124 isoth[5] = 0; 00125 isoth[6] = 0; 00126 00127 presb[0] = 1013.25; 00128 tb[0] = 288.15; 00129 00130 /* Loop over layers and get pressures and temperatures at level tops */ 00131 for (i=0; i<(NLAYERS-1); i++) { 00132 tb[i+1] = tb[i] + (1-isoth[i]) * lapse_rate[i] * (limits[i+1] - limits[i]); 00133 presb[i+1] = (1-isoth[i]) * presb[i] * exp(log(tb[i]/tb[i+1]) * K_GMR / lapse_rate[i]) + 00134 isoth[i] * presb[i] * exp(-K_GMR * (limits[i+1]-limits[i]) / tb[i]); 00135 } 00136 00137 for (i=0; i<(ni*nj); i++) { 00138 /* Now calculate which layer each value belongs to */ 00139 for (layr=0; layr<NLAYERS; layr++) { 00140 if ( (limits[layr] - alt[i]) > 0.0 ) { 00141 layer = layr - 1; 00142 layr = NLAYERS + 1; 00143 } 00144 } 00145 if (layer < 0) layer = 0; 00146 if (layer > (NLAYERS-1)) layer = NLAYERS - 1; 00147 00148 /* Corresponding pressure */ 00149 pres[i] = isoth[layer] * presb[layer] * exp(-K_GMR * (alt[i] - limits[layer]) / tb[layer]) + 00150 (1-isoth[layer]) * presb[layer] * pow( ( tb[layer] / ( tb[layer] + lapse_rate[layer] * 00151 (alt[i] - limits[layer]) ) ), (K_GMR/lapse_rate[layer]) ); 00152 } 00153 00154 }