Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
util/sci.h
00001 // copyright 2010 t. schneider tes@mit.edu
00002 // ocean engineering graudate student - mit / whoi joint program
00003 // massachusetts institute of technology (mit)
00004 // laboratory for autonomous marine sensing systems (lamss)    
00005 // 
00006 // this file is part of goby-util, a collection of utility libraries
00007 //
00008 //
00009 // This program is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // This software is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 #ifndef SCI20100713H
00023 #define SCI20100713H
00024 
00025 #include <cmath>
00026 
00027 namespace goby
00028 {
00029     namespace util
00030     {
00031 
00033 
00034     
00041         inline double unbiased_round(double r, double dec)
00042         {
00043             double ex = pow(10, dec);
00044             double final = floor(r * ex);
00045             double s = (r * ex) - final;
00046 
00047             // remainder less than 0.5 or even number next to it
00048             if (s < 0.5 || (s==0.5 && !(static_cast<unsigned long>(final)&1)))
00049                 return final / ex;
00050             else 
00051                 return (final+1) / ex;
00052         }
00053 
00060         inline double mackenzie_soundspeed(double T, double S, double D)
00061         {
00062             return
00063                 1448.96 + 4.591*T - 5.304e-2*T*T + 2.374e-4*T*T*T +
00064                 1.340*(S-35) + 1.630e-2*D+1.675e-7*D*D -
00065                 1.025e-2*T*(S-35)-7.139e-13*T*D*D*D;
00066         }
00067     }
00068 
00070 
00071 }
00072 
00073 
00074 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends