Goby v2
pressure.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 // modified for C++ by s. petillo spetillo@mit.edu
24 // ocean engineering graduate student - mit / whoi joint program
25 // massachusetts institute of technology (mit)
26 // laboratory for autonomous marine sensing systems (lamss)
27 
28 #ifndef PRESSUREH
29 #define PRESSUREH
30 
31 #include <cmath>
32 
33 // Calculate water density anomaly at a given Salinity, Temperature, Pressure using the seawater Equation of State.
34 // Taken directly from MATLAB OceansToolbox pressure.m
35 
36 inline double depth2pressure(double DPTH, double XLAT)
37 {
38  // function P80=pressure(DPTH,XLAT);
39  /*
40  Computes pressure given the depth at some latitude
41  P = depth2pressure(DPTH,XLAT) gives the pressure P (dbars) at a depth DPTH (m) at some latitude XLAT (degrees).
42 
43  This probably works best in mid-latitude oceans, if anywhere!
44 
45  Ref: Saunders, "Practical Conversion of Pressure to Depth",
46  J. Phys. Oceanog., April 1981.
47 
48  I copied this from the Matlab OceansToolbox pressure.m, copied directly from the UNESCO algorithms.
49 
50 
51  CHECK VALUE: P80=7500.004 DBARS;FOR LAT=30 DEG., DEPTH=7321.45 METERS
52  ^P80 test value should be 7500.006 (from spetillo@mit.edu)
53  */
54 
55  using namespace std; // for math functions
56 
57  const double pi = 3.14159;
58 
59  double PLAT = abs(XLAT * pi / 180);
60  double D = sin(PLAT);
61  double C1 = (5.92E-3) + (D * D) * (5.25E-3);
62  double P80 = ((1 - C1) - sqrt(((1 - C1) * (1 - C1)) - ((8.84E-6) * DPTH))) / 4.42E-6;
63 
64  return P80;
65 }
66 
67 #endif
STL namespace.