Listing des Javascript-Code der Seite Rechner: Umrechnen von Fluggeschwindigkeiten.
#INCLUDE ControlPanel.inc <jscript> var BaroConst = { hIx: 0, // air level data of standard atmosphere model hLimitTab: [ 11000, 20000, 32000, 47000, 51000, 71000, 84852, 0 ], hRefTab: [ 0, 11000, 20000, 32000, 47000, 51000, 71000, NaN ], alphaTab: [ -0.0065, 0, 0.001, 0.0028, 0, -0.0028, -0.002, NaN ], TRefTab: [ 288.15, 216.65, 216.65, 228.65, 270.65, 270.65, 214.65, NaN ], rhoRefTab: [ 1.225, 0.363918, 0.0880348, 0.013225, 0.00142753, 0.000861605, 0.000064211, NaN ], pRefTab: [ 101325, 22632.1, 5474.89, 868.019, 110.906, 66.9389, 3.95642, NaN ], // some general constants g: 9.80665, R: 8.31446, RS: 287.058, kappa: 1.4, M: 28.9644, T0: 288.15, p0: 101325, rho0: 1.225, a0: 340.294, // private function defIx: function(i) { return xDefNum( i, this.hIx ); }, // set altitude range for following functions SetAltRange: function( h ) { for (var i = 0; i < this.hLimitTab.length; i++) { if (h <= this.hLimitTab[i]) { this.hIx = i; return; } } this.hIx = this.hLimitTab.length - 1; }, // query level dependent constants // default for i is this.hIx, see SetAltRange(h) hRef: function(i) { return this.hRefTab[this.defIx(i)]; }, alpha: function(i) { return this.alphaTab[this.defIx(i)]; }, TRef: function(i) { return this.TRefTab[this.defIx(i)]; }, rhoRef: function(i) { return this.rhoRefTab[this.defIx(i)]; }, pRef: function(i) { return this.pRefTab[this.defIx(i)]; } }; var ConvertUnit = { ms_kt: function( v ) { return v * 1.944; }, kt_ms: function( v ) { return v / 1.944; }, ft_m: function( h ) { return h * 0.3048; }, m_ft: function( h ) { return h / 0.3048; }, K_C: function( t ) { return t - 273.15; }, C_K: function( t ) { return t + 273.15; }, K_F: function( t ) { return t * 1.8 - 459.67; }, F_K: function( t ) { return (t + 459.67) / 1.8; } } var SpeedModel = { h: 0, q: 0, qc: 0, tas: 0, eas: 0, cas: 0, mach: 0, tasField: 0, tasSlider: 0, tasSliderLast: 0, easField: 0, easSlider: 0, easSliderLast: 0, casField: 0, casSlider: 0, casSliderLast: 0, machField: 0, machSlider: 0, machSliderLast: 0, hMax: ConvertUnit.ft_m( 45000 ), T: 0, p: 0, rho: 0, a: 0, h_unitId: 3, // 0 -> km, 1 -> m, 2 -> ft, 3 -> FL h_unitNameList: [ 'km', 'm', 'ft', 'FL' ], h_unitName: 'FL', h_multList: [ 1000, 1, 0.3048, 30.48 ], h_mult: 30.48, h_digitsList: [ 3, 0, 0, 2 ], h_digits: 2, v_unitId: 2, // 0 -> m/s, 1 -> km/h, 2 -> kt v_unitNameList: [ 'm/s', 'km/h', 'kt' ], v_unitName: 'kt', v_multList: [ 1, 1/3.6, 1/1.944 ], v_mult: 1/1.944, v_digitsList: [ 2, 2, 2 ], v_digits: 2, T_unitId: 1, // 0 -> K, 1 -> C, 2 -> F T_unitNameList: [ 'K', '°C', '°F' ], T_unitName: '°C', T_multList: [ 1, [ ConvertUnit.C_K, ConvertUnit.K_C ], [ ConvertUnit.F_K, ConvertUnit.K_F ] ], T_mult: [ ConvertUnit.C_K, ConvertUnit.K_C ], T_digitsList: [ 2, 3, 3 ], T_digits: 3, p_unitId: 0, // 0 -> Pa, 1 -> hPa, 2 -> inHg p_unitNameList: [ 'Pa', 'hPa', 'inHg' ], p_unitName: 'Pa', p_multList: [ 1, 100, 3386.5 ], p_mult: 1, p_digitsList: [ 0, 2, 4 ], p_digits: 0, rho_unitId: 1, // 0 -> g/m^3, 1 -> kg/m^3 rho_unitNameList: [ 'g/m<sup>3</sup>', 'kg/m<sup>3</sup>' ], rho_unitName: 'kg/m<sup>3</sup>', rho_multList: [ 0.001, 1 ], rho_mult: 1, rho_digitsList: [ 2, 5 ], rho_digits: 5, TempOfH: function( h ) { return BaroConst.TRef() + BaroConst.alpha() * (h - BaroConst.hRef()); }, PressureOfH: function( h ) { var alpha = BaroConst.alpha(); if (alpha == 0) { // isoterm var hs = BaroConst.RS * BaroConst.TRef() / BaroConst.g; var p = BaroConst.pRef() * Math.exp( -(h - BaroConst.hRef()) / hs ); return p; } else { var beta = BaroConst.g / BaroConst.RS / alpha; var p = BaroConst.pRef() * Math.pow( 1 + alpha * (h - BaroConst.hRef()) / BaroConst.TRef(), -beta ); return p; } }, DensityOfH: function( h ) { var alpha = BaroConst.alpha(); if (alpha == 0) { // isoterm var hs = BaroConst.RS * BaroConst.TRef() / BaroConst.g; var r = BaroConst.rhoRef() * Math.exp( -(h - BaroConst.hRef()) / hs ); return r; } else { var beta = BaroConst.g / BaroConst.RS / alpha; var r = BaroConst.rhoRef() * Math.pow( 1 + alpha * (h - BaroConst.hRef()) / BaroConst.TRef(), -beta-1 ); return r; } }, AofH: function( h ) { // require TempOfH() is called return Math.sqrt( BaroConst.kappa * BaroConst.RS * this.T ); }, BasicOfH: function() { BaroConst.SetAltRange( this.h ); this.T = this.TempOfH( this.h ); this.p = this.PressureOfH( this.h ); this.rho = this.DensityOfH( this.h ); this.a = this.AofH( this.h ); }, AllOfTas: function() { this.mach = this.tas / this.a; this.eas = Math.sqrt( this.rho / BaroConst.rho0 ) * this.tas; var k1 = (BaroConst.kappa - 1) / 2; var k2 = BaroConst.kappa / (BaroConst.kappa - 1); var v = this.tas / this.a; this.qc = this.p * ( Math.pow( k1 * v * v + 1 , k2 ) - 1 ); this.cas = BaroConst.a0 * Math.sqrt( (1/k1) * ( Math.pow( this.qc / BaroConst.p0 + 1 , 1/k2 ) - 1 ) ); this.q = 0.5 * this.rho * this.tas * this.tas; }, AllOfEas: function() { this.tas = Math.sqrt( BaroConst.rho0 / this.rho ) * this.eas; this.AllOfTas(); }, AllOfCas: function() { var k1 = (BaroConst.kappa - 1) / 2; var k2 = BaroConst.kappa / (BaroConst.kappa - 1); var v = this.cas / BaroConst.a0; this.qc = BaroConst.p0 * ( Math.pow( k1 * v * v + 1, k2 ) - 1 ); this.tas = this.a * Math.sqrt( (1/k1) * ( Math.pow( this.qc / this.p + 1 , 1/k2 ) - 1 ) ); this.AllOfTas(); }, AllOfMach: function() { this.tas = this.a * this.mach; this.AllOfTas(); }, Init: function() { this.h = ConvertUnit.ft_m( 30000 ); this.tas = 0; this.tasField = ConvertUnit.kt_ms( 500 ); this.tasSlider = 0; this.Update(); }, Update: function() { this.h_mult = this.h_multList[this.h_unitId]; this.h_digits = this.h_digitsList[this.h_unitId]; this.h_unitName = this.h_unitNameList[this.h_unitId]; this.v_mult = this.v_multList[this.v_unitId]; this.v_digits = this.v_digitsList[this.v_unitId]; this.v_unitName = this.v_unitNameList[this.v_unitId]; this.T_mult = this.T_multList[this.T_unitId]; this.T_digits = this.T_digitsList[this.T_unitId]; this.T_unitName = this.T_unitNameList[this.T_unitId]; this.p_mult = this.p_multList[this.p_unitId]; this.p_digits = this.p_digitsList[this.p_unitId]; this.p_unitName = this.p_unitNameList[this.p_unitId]; this.rho_mult = this.rho_multList[this.rho_unitId]; this.rho_digits = this.rho_digitsList[this.rho_unitId]; this.rho_unitName = this.rho_unitNameList[this.rho_unitId]; if (this.h < 0) this.h = 0; if (this.h > this.hMax) this.h = this.hMax; this.BasicOfH(); if (this.tasField != this.tas || this.tasSlider != this.tasSliderLast) { if (this.tasField != this.tas) { this.tas = this.tasField; } else { this.tas = this.tasSlider * BaroConst.a0; } if (this.tas < 0) this.tas = 0; if (this.tas > BaroConst.a0) this.tas = BaroConst.a0; this.AllOfTas(); } else if (this.easField != this.eas || this.easSlider != this.easSliderLast) { if (this.easField != this.eas) { this.eas = this.easField; } else { this.eas = this.easSlider * BaroConst.a0; } if (this.eas < 0) this.eas = 0; if (this.eas > BaroConst.a0) this.eas = BaroConst.a0; this.AllOfEas(); } else if (this.casField != this.cas || this.casSlider != this.casSliderLast) { if (this.casField != this.cas) { this.cas = this.casField; } else { this.cas = this.casSlider * BaroConst.a0; } if (this.cas < 0) this.cas = 0; if (this.cas > BaroConst.a0) this.cas = BaroConst.a0; this.AllOfCas(); } else if (this.machField != this.mach || this.machSlider != this.machSliderLast) { if (this.machField != this.mach) { this.mach = this.machField; } else { this.mach = this.machSlider; } if (this.mach < 0) this.mach = 0; if (this.mach > 1) this.mach = 1; this.AllOfMach(); } else { // h changed this.AllOfTas(); } if (this.tas > this.a) { this.tas = this.a; this.AllOfTas(); } // set fields and sliders this.tasField = this.tas; this.tasSlider = this.tas / BaroConst.a0; this.tasSliderLast = this.tasSlider; this.easField = this.eas; this.easSlider = this.eas / BaroConst.a0; this.easSliderLast = this.easSlider; this.casField = this.cas; this.casSlider = this.cas / BaroConst.a0; this.casSliderLast = this.casSlider; this.machField = this.mach; this.machSlider = this.mach; this.machSliderLast = this.machSlider; } }; xOnLoad( function(){ SpeedModel.Init(); UpdateAll(); } ); function UpdateAll() { SpeedModel.Update(); ControlPanels.Update(); } ControlPanels.NewSliderPanel( { Name: 'SliderPanel', ModelRef: 'SpeedModel', NCols: 1, Format: 'fix0', ValuePos: 'left', OnModelChange: UpdateAll, PanelFormat: 'InputMediumWidth' } ).AddValueSliderField( { Name: 'h', Color: 'blue', Min: 0, Max: SpeedModel.hMax, DigitsRef: 'h_digits', MultRef: 'h_mult', UnitsRef: 'h_unitName' } ).AddValueSliderField( { Name: 'tasField', Label: 'TAS', ValueRef: 'tasField', SliderValueRef: 'tasSlider', Color: 'green', Min: 0, Max: 1, DigitsRef: 'v_digits', MultRef: 'v_mult', UnitsRef: 'v_unitName' } ).AddValueSliderField( { Name: 'easField', Label: 'EAS', ValueRef: 'easField', SliderValueRef: 'easSlider', Color: 'green', Min: 0, Max: 1, DigitsRef: 'v_digits', MultRef: 'v_mult', UnitsRef: 'v_unitName' } ).AddValueSliderField( { Name: 'casField', Label: 'CAS', ValueRef: 'casField', SliderValueRef: 'casSlider', Color: 'green', Min: 0, Max: 1, DigitsRef: 'v_digits', MultRef: 'v_mult', UnitsRef: 'v_unitName' } ).AddValueSliderField( { Name: 'machField', Label: 'Mach', ValueRef: 'machField', SliderValueRef: 'machSlider', Color: 'red', Min: 0, Max: 1, Digits: 5 } ).Render(); ControlPanels.NewPanel( { Name: 'OutputPanel', ModelRef: 'SpeedModel', NCols: 2, Format: 'fix0', ReadOnly: true, PanelFormat: 'InputNormalWidth' } ).AddTextField( { Name: 'a', Label: 'a(h)', DigitsRef: 'v_digits', MultRef: 'v_mult', UnitsRef: 'v_unitName' } ).AddTextField( { Name: 'T', Label: 'T(h)', DigitsRef: 'T_digits', MultRef: 'T_mult', UnitsRef: 'T_unitName' } ).AddTextField( { Name: 'p', Label: 'p<sub>s</sub>(h)', DigitsRef: 'p_digits', MultRef: 'p_mult', UnitsRef: 'p_unitName' } ).AddTextField( { Name: 'rho', Label: 'ρ(h)', DigitsRef: 'rho_digits', MultRef: 'rho_mult', UnitsRef: 'rho_unitName' } ).AddTextField( { Name: 'qc', Label: 'q<sub>c</sub>(h,TAS)', DigitsRef: 'p_digits', MultRef: 'p_mult', UnitsRef: 'p_unitName' } ).AddTextField( { Name: 'q', Label: 'q(h,TAS)', DigitsRef: 'p_digits', MultRef: 'p_mult', UnitsRef: 'p_unitName' } ).Render(); ControlPanels.NewPanel( { Name: 'UnitsPanel', ModelRef: 'SpeedModel', NCols: 2, OnModelChange: UpdateAll } ).AddRadiobuttonField( { Name: 'h_unitId', Label: '[h]', ValueType: 'int', Items: [ { Name: 'km', Value: 0 }, { Name: 'm', Value: 1 }, { Name: 'ft', Value: 2 }, { Name: 'FL', Value: 3 } ] } ).AddRadiobuttonField( { Name: 'T_unitId', Label: '[T]', ValueType: 'int', Items: [ { Name: 'K', Value: 0 }, { Name: '°C', Value: 1 }, { Name: '°F', Value: 2 } ] } ).AddRadiobuttonField( { Name: 'v_unitId', Label: '[v]', ValueType: 'int', Items: [ { Name: 'm/s', Value: 0 }, { Name: 'km/h', Value: 1 }, { Name: 'kt', Value: 2 } ] } ).AddRadiobuttonField( { Name: 'p_unitId', Label: '[p]', ValueType: 'int', Items: [ { Name: 'Pa', Value: 0 }, { Name: 'hPa', Value: 1 }, { Name: 'inHg', Value: 2 } ] } ).AddEmptyField( { } ).AddRadiobuttonField( { Name: 'rho_unitId', Label: '[ρ]', ValueType: 'int', Items: [ { Name: 'g/m<sup>3</sup>', Value: 0 }, { Name: 'kg/m<sup>3</sup>', Value: 1 } ] } ).Render(); </jscript>