WaBis

walter.bislins.ch

Script Barometrische Höhenformel

Nachfolgend das Java-Script zum Rechenformular (Ziel-SeiteBarometrische Höhenformel):
#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,

  // 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 BaroModel = {

  h: 0,
  T: 0,
  p: 0,
  rho: 0,

  h_unitId: 0,  // 0 -> km, 1 -> m, 2 -> ft, 3 -> FL
  h_unitNameList: [ 'km', 'm', 'ft', 'FL' ],
  h_unitName: 'm',
  h_multList: [ 1000, 1, 0.3048, 30.48 ], 
  h_mult: 1, 
  h_digitsList: [ 5, 5, 5, 4 ],
  h_digits: 3,

  T_unitId: 0,  // 0 -> K, 1 -> C, 2 -> F
  T_unitNameList: [ 'K', '&deg;C', '&deg;F' ],
  T_unitName: 'K',
  T_multList: [ 1, [ ConvertUnit.C_K, ConvertUnit.K_C ], [ ConvertUnit.F_K, ConvertUnit.K_F ] ],
  T_mult: 1,
  T_digitsList: [ 5, 5, 5 ],
  T_digits: 5,
  
  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: [ 6, 6, 5 ],  
  p_digits: 6,  
   
  rho_unitId: 0,  // 0 -> g/m^3, 1 -> kg/m^3
  rho_unitNameList: [ 'g/m<sup>3</sup>', 'kg/m<sup>3</sup>' ],  
  rho_unitName: 'g/m<sup>3</sup>',  
  rho_multList: [ 0.001, 1 ],  
  rho_mult: 0.001,  
  rho_digitsList: [ 5, 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;
    }
  },

  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.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];

    BaroConst.SetAltRange( this.h );
    this.T = this.TempOfH( this.h );
    this.p = this.PressureOfH( this.h );
    this.rho = this.DensityOfH( this.h );
  }

};


var BaroForm = ControlPanels.NewPanel( { 
  Name: 'BaroForm',
  ModelRef: 'BaroModel',
  NCols: 2, 
  OnModelChange: UpdateBaroModel, 
  PanelFormat: 'InputNormalWidth'
} );

BaroForm.AddTextField( {
  Name: 'h',
  Format: 'std', 
  DigitsRef: 'h_digits',
  MultRef: 'h_mult',
  UnitsRef: 'h_unitName'
} );

BaroForm.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 }
  ]
} );

BaroForm.AddTextField( {
  Name: 'T',
  Label: 'T(h)',
  Format: 'std', 
  DigitsRef: 'T_digits',
  MultRef: 'T_mult',
  UnitsRef: 'T_unitName',
  ReadOnly: true
} );

BaroForm.AddRadiobuttonField( {
  Name: 'T_unitId',
  Label: '[T]',
  ValueType: 'int',
  Items: [
    { Name: 'K',      Value: 0 },
    { Name: '&deg;C', Value: 1 },
    { Name: '&deg;F', Value: 2 }
  ]
} );

BaroForm.AddTextField( {
  Name: 'p',
  Label: 'p(h)',
  Format: 'std', 
  DigitsRef: 'p_digits',
  MultRef: 'p_mult',
  UnitsRef: 'p_unitName',
  ReadOnly: true
} );

BaroForm.AddRadiobuttonField( {
  Name: 'p_unitId',
  Label: '[p]',
  ValueType: 'int',
  Items: [
    { Name: 'Pa',   Value: 0 },
    { Name: 'hPa',  Value: 1 },
    { Name: 'inHg', Value: 2 }
  ]
} );

BaroForm.AddTextField( {
  Name: 'rho',
  Label: '&rho;(h)',
  Format: 'std', 
  DigitsRef: 'rho_digits',
  MultRef: 'rho_mult',
  UnitsRef: 'rho_unitName',
  ReadOnly: true
} );

BaroForm.AddRadiobuttonField( {
  Name: 'rho_unitId',
  Label: '[&rho;]',
  ValueType: 'int',
  Items: [
    { Name: 'g/m<sup>3</sup>', Value: 0 },
    { Name: 'kg/m<sup>3</sup>',  Value: 1 }
  ]
} );


function UpdateBaroModel() {
  BaroModel.Update();
  BaroForm.Update();
}

xOnLoad( UpdateBaroModel );

BaroForm.Render();

</jscript>

More Page Infos / Sitemap
Created Donnerstag, 10. September 2015
Scroll to Top of Page
Changed Sonntag, 27. Oktober 2019