Goby v2
salinity.cpp
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 //
5 //
6 // This file is part of the Goby Underwater Autonomy Project Binaries
7 // ("The Goby Binaries").
8 //
9 // The Goby Binaries are free software: you can redistribute them and/or modify
10 // them under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The Goby Binaries are distributed in the hope that they will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
21 
22 #include "goby/util/seawater/salinity.h"
23 #include "goby/util/sci.h"
24 #include <cassert>
25 #include <iomanip>
26 #include <iostream>
27 
28 int main()
29 {
30  using goby::util::unbiased_round;
31 
32  // from UNESCO 1983 test cases
33  double test_conductivity_ratio = 1.888091;
34  const double CONDUCTIVITY_AT_STANDARD = 42.914; // S = 35, T = 15 deg C, P = 0 dbar
35  double test_conductivity_mSiemens_cm = test_conductivity_ratio * CONDUCTIVITY_AT_STANDARD;
36 
37  double test_temperature_deg_C = 40;
38  double test_pressure_dbar = 10000;
39 
40  double calculated_salinity = SalinityCalculator::salinity(
41  test_conductivity_mSiemens_cm, test_temperature_deg_C, test_pressure_dbar);
42 
43  std::cout << "calculated salinity: " << std::fixed << std::setprecision(5)
44  << calculated_salinity << " for T = " << test_temperature_deg_C << " deg C,"
45  << " P = " << test_pressure_dbar << " dbar,"
46  << " C = " << test_conductivity_mSiemens_cm << " mSiemens / cm" << std::endl;
47 
48  assert(goby::util::unbiased_round(calculated_salinity, 5) == 40.00000);
49 }