Advertisement
Guest User

Untitled

a guest
Jan 14th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. <?php
  2.  
  3. function salinity($measuredConductivity, $measuredTemperature, $measuredDepth) {
  4.  
  5. // PHP version by Ben Ostrowsky
  6. // Based on Excel formulas by James Douglass
  7. //   http://jimbodouglass.blogspot.com/2010/11/conductivity-to-salinity-conversion-for.html
  8. // Based on Fofonoff, N.P. and Millard, R.C., Jr. (1983). Algorithms for computation
  9. //   of fundamental properties of seawater. http://hdl.handle.net/1912/2470
  10. // Added code to compensate for depth.
  11.  
  12.         $referenceConductivity = 42900.0; // microsiemens per cm^2
  13.  
  14.         $conductivityRatio = $measuredConductivity / $referenceConductivity;
  15.  
  16.         $waterDensity = 1.03 * 10^3; // kilograms per m^3 (pure water would be 1.00 * 10^3)
  17.         $gravity = 9.8; // meters per s^2
  18.         $airPressure = 10.0; // decibars
  19.  
  20.         $computedPressure =  ($waterDensity * $gravity * $measuredDepth / 10.0) + $airPressure;
  21.  
  22.         $littlert = (
  23.                     0.6766097
  24.                 +   0.0200564     * $measuredTemperature
  25.                 +   0.0001104259  * ($measuredTemperature^2)
  26.                 + (-6.9698*10^-7) * ($measuredTemperature^3)
  27.                 + ( 1.0031*10^-9) * ($measuredTemperature^4)
  28.         );
  29.  
  30.         $Rp =
  31.                 1 + (
  32.                         (
  33.                                 $computedPressure * (
  34.                                         2.070*10^-5   * ($computedPressure^0)
  35.                                         + (-6.370*10^-10) * ($computedPressure^1)
  36.                                         +   3.989*10^-15  * ($computedPressure^2)
  37.                                 )
  38.  
  39.                                 /
  40.  
  41.                                 (
  42.                                         1
  43.                                         + (3.426*10^-2) * ($measuredTemperature^1)
  44.                                         + (4.464*10^-4) * ($measuredTemperature^2)
  45.                                         + ( 4.215*10^-1 + (-3.107*10^-3) * $measuredTemperature ) * $conductivityRatio
  46.                                 )
  47.                         )
  48.                 );
  49.  
  50.         $bigRt =  $conductivityRatio / ($littlert * $Rp);
  51.  
  52.         $dS =
  53.                 (
  54.                         ( $measuredTemperature - 15.0) / (1 + 0.0162*( $measuredTemperature - 15.0 ) )
  55.                 )
  56.                 * (
  57.                             0.0005
  58.                         + (-0.0056) * ($bigRt^0.5)
  59.                         + (-0.0066) * ($bigRt^1)
  60.                         + (-0.0375) * ($bigRt^1.5)
  61.                         + ( 0.0636) * ($bigRt^2)
  62.                         + (-0.0144) * ($bigRt^2.5)
  63.                 );
  64.  
  65.         $computedSalinity =
  66.                     0.008
  67.                 + (-0.1692) * ($bigRt^0.5)
  68.                 +  25.3851  * ($bigRt^1)
  69.                 +  14.0941  * ($bigRt^1.5)
  70.                 + (-7.0261) * ($bigRt^2)
  71.                 +   2.7081  * ($bigRt^2.5)
  72.                 + $dS;
  73.  
  74.         return $computedSalinity;
  75.  
  76. }
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement