

const = {
    'c_from_sp_ca':  6.163816124171717e-010,
    'sp_from_c_ca':  1.297193463756230e-010,
    'r_from_sp_ca':  1.436317731418058e-011,
    'sp_from_r_ca':  2.681299626772216e-012,
    'sp_salinometer_ca':  1.297131291266851e-010,
    'sa_from_sp_ca':  1.300080043620255e-010,
    'sstar_from_sp_ca':  1.300008989346679e-010,
    'ct_from_t_ca':  6.261107188265669e-010,
    'deltasa_from_sp_ca':  6.963318810448982e-013,
    'sa_sa_sstar_from_sp_ca':  1.300008989346679e-010,
    'sstar_sa_sstar_from_sp_ca':  1.300008989346679e-010,
    'sr_from_sp_ca':  1.303233077010191e-010,
    'sp_from_sr_ca':  1.297122409482654e-010,
    'sp_from_sa_ca':  1.297113527698457e-010,
    'sstar_from_sa_ca':  1.300008989346679e-010,
    'sa_from_sstar_ca':  1.300222152167407e-010,
    'sp_from_sstar_ca':  1.297122409482654e-010,
    't_from_ct_ca':  6.000142604989378e-010,
    'pt_from_ct_ca':  6.054037271496782e-010,
    'ct_from_pt_ca':  6.261107188265669e-010,
    'pot_enthalpy_from_pt_ca':  2.499356924090534e-006,
    'pt0_from_t_ca':  6.054037271496782e-010,
    'pt_from_t_ca':  6.054037271496782e-010,
    'entropy_from_ct_ca':  9.028163105995191e-009,
    'ct_from_entropy_ca':  6.261107188265669e-010,
    'entropy_from_pt_ca':  9.028163105995191e-009,
    'pt_from_entropy_ca':  6.054072798633570e-010,
    't90_from_t68_ca':  5.998579410970706e-010,
    't90_from_t48_ca':  5.997407015456702e-010,
    'z_from_p_ca':  2.287223921371151e-008,
    'p_from_z_ca':  2.301931090187281e-008,
    'depth_from_z_ca':  2.287223921371151e-008,
    'z_from_depth_ca':  2.287223921371151e-008,
    'molality_from_sa_ca':  4.446665258228677e-012,
    'ionic_strength_from_sa_ca':  2.768674178810215e-012,
    'rho_ca':  2.945625965367071e-010,
    'alpha_ca':  8.264713918662917e-015,
    'beta_ca':  1.846179459308317e-015,
    'rho_rab_ca':  2.944489096989855e-010,
    'alpha_rab_ca':  8.264713918662917e-015,
    'beta_rab_ca':  1.846179459308317e-015,
    'specvol_ca':  2.821094052807283e-016,
    'specvol_anom_ca':  2.810252031082428e-016,
    'sigma0_ca':  2.933120413217694e-010,
    'sigma1_ca':  2.999058779096231e-010,
    'sigma2_ca':  3.060449671465904e-010,
    'sigma3_ca':  3.119566827081144e-010,
    'sigma4_ca':  3.180957719450817e-010,
    'sound_speed_ca':  2.596152626210824e-009,
    'internal_energy_ca':  2.499342372175306e-006,
    'enthalpy_ca':  2.499356924090534e-006,
    'enthalpy_diff_ca':  1.154347728515859e-010,
    'dynamic_enthalpy_ca':  2.288754734930485e-007,
    'sa_from_rho_ca':  1.308677610722953e-010,
    'ct_maxdensity_ca':  6.688338771709823e-011,
    'ct_from_rho_ca':  6.298552790440226e-010,
    'n2_ca':  1.578186366313350e-014,
    'p_mid_n2_ca':  2.300021151313558e-008,
    'tu_ca':  2.190718007000214e-008,
    'rsubrho_ca':  1.709803143512545e-008,
    'p_mid_tursr_ca':  2.300021151313558e-008,
    'ipvfn2_ca':  3.474816878679121e-009,
    'p_mid_ipvfn2_ca':  2.300021151313558e-008,
    'geo_strf_dyn_height_ca':  9.969444363377988e-007,
    'geo_strf_dyn_height_pc_ca':  4.210555459849275e-008,
    'geo_strf_dyn_height_pc_p_mid_ca':  1.000000000000000e-015,
    'geo_strf_isopycnal_ca':  4.297791695861974e-007,
    'geo_strf_isopycnal_pc_ca':  8.540336438045415e-009,
    'geo_strf_isopycnal_pc_p_mid_ca':  1.000000000000000e-015,
    'geo_strf_montgomery_ca':  9.915690188933013e-007,
    'geo_strf_cunningham_ca':  9.926097845891491e-007,
    'geo_strf_velocity_ca':  8.024344404222727e-009,
    'geo_strf_velocity_mid_lat_ca':  1.000000000000000e-015,
    'geo_strf_velocity_mid_long_ca':  1.000000000000000e-015,
    'cabbeling_ca':  1.744482989595071e-015,
    'thermobaric_ca':  2.527995218416681e-021,
    'isopycnal_slope_ratio_ca':  3.781384094736495e-010,
    'g_ct_ca':  2.854610769986721e-009,
    'p_mid_g_ct_ca':  2.300021151313558e-008,
    'ntpptct_ca':  5.024869409453459e-013,
    'ct_sa_ca':  1.006231122729906e-012,
    'ct_pt_ca':  2.964295475749168e-013,
    'ct_sa_sa_ca':  1.431146867680866e-014,
    'ct_sa_pt_ca':  1.457167719820518e-014,
    'ct_pt_pt_ca':  5.551115123125783e-014,
    'h_sa_ca':  2.371365326325758e-010,
    'h_ct_ca':  3.160494088660926e-010,
    'h_p_ca':  2.818925648462312e-016,
    'h_sa_sa_ca':  7.264189250122399e-013,
    'h_sa_ct_ca':  2.188554892867956e-012,
    'h_ct_ct_ca':  1.135647131889073e-011,
    'eta_sa_ca':  4.653527563291959e-012,
    'eta_ct_ca':  3.137579085432662e-011,
    'eta_sa_sa_ca':  6.995931611797346e-013,
    'eta_sa_ct_ca':  4.981922535098049e-014,
    'eta_ct_ct_ca':  2.381358998881922e-013,
    'pt_sa_ca':  9.670458878119348e-013,
    'pt_ct_ca':  2.733369086627135e-013,
    'pt_sa_sa_ca':  2.081668171172169e-014,
    'pt_sa_ct_ca':  1.199127602768968e-014,
    'pt_ct_ct_ca':  4.440892098500626e-014,
    'ct_freezing_ca':  2.257127817983928e-011,
    't_freezing_ca':  2.157829470661454e-011,
    'brinesa_ct_ca':  1.300080043620255e-010,
    'brinesa_t_ca':  1.300293206440983e-010,
    'latentheat_melting_ca':  6.286427378654480e-008,
    'latentheat_evap_ct_ca':  1.455657184123993e-006,
    'latentheat_evap_t_ca':  1.443084329366684e-006,
    'f_ca':  1.000000000000000e-015,
    'grav_ca':  5.329070518200751e-014,
    'distance_ca':  4.470348358154297e-008,
    'steric_height_ca':  1.017674460257467e-007,
    'abs_pressure_from_p_ca':  2.300031483173370e-004,
    'p_from_abs_pressure_ca':  2.300066626048647e-008,
    'rho_ct_exact_ca':  2.944489096989855e-010,
    'alpha_ct_exact_ca':  8.257102480598889e-015,
    'beta_ct_exact_ca':  1.847372081698051e-015,
    'rho_ct_exact_rab_ca':  2.944489096989855e-010,
    'alpha_ct_exact_rab_ca':  8.257102480598889e-015,
    'beta_ct_exact_rab_ca':  1.847372081698051e-015,
    'specvol_ct_exact_ca':  2.818925648462312e-016,
    'specvol_anom_ct_exact_ca':  2.805915222392486e-016,
    'sigma0_ct_exact_ca':  2.929709808086045e-010,
    'sigma1_ct_exact_ca':  2.994511305587366e-010,
    'sigma2_ct_exact_ca':  3.055902197957039e-010,
    'sigma3_ct_exact_ca':  3.117293090326712e-010,
    'sigma4_ct_exact_ca':  3.176410245941952e-010,
    'sound_speed_ct_exact_ca':  2.590240910649300e-009,
    'internal_energy_ct_exact_ca':  2.499335096217692e-006,
    'enthalpy_ct_exact_ca':  2.499349648132920e-006,
    'enthalpy_diff_ct_exact_ca':  7.275957614183426e-011,
    'dynamic_enthalpy_ct_exact_ca':  2.288797986693680e-007,
    'sa_from_rho_ct_exact_ca':  1.306119656874216e-010,
    'ct_maxdensity_exact_ca':  5.839062566792563e-011,
    'ct_from_rho_exact_ca':  6.280096442878858e-010,
    'rho_t_exact_ca':  2.944489096989855e-010,
    'pot_rho_t_exact_ca':  2.929709808086045e-010,
    'sigma0_pt0_exact_ca':  2.929709808086045e-010,
    'specvol_t_exact_ca':  2.818925648462312e-016,
    'specvol_anom_t_exact_ca':  2.805915222392486e-016,
    'alpha_wrt_ct_t_exact_ca':  8.257094010269417e-015,
    'alpha_wrt_pt_t_exact_ca':  8.599068316130290e-015,
    'alpha_wrt_t_exact_ca':  8.594856868316542e-015,
    'beta_const_ct_t_exact_ca':  1.847372081698051e-015,
    'beta_const_pt_t_exact_ca':  1.805738718274608e-015,
    'beta_const_t_exact_ca':  1.804871356536619e-015,
    'entropy_t_exact_ca':  9.028163105995191e-009,
    'internal_energy_t_exact_ca':  2.499335096217692e-006,
    'enthalpy_t_exact_ca':  2.499349648132920e-006,
    'dynamic_enthalpy_t_exact_ca':  2.288943505845964e-007,
    'cp_t_exact_ca':  2.813976607285440e-009,
    'isochoric_heat_cap_t_exact_ca':  1.614353095646948e-009,
    'chem_potential_t_exact_ca':  1.317864928296331e-009,
    'chem_potential_water_t_exact_ca':  4.811790859093890e-007,
    'chem_potential_salt_t_exact_ca':  4.805315256817266e-007,
    'helmholtz_energy_t_exact_ca':  2.440137905068696e-007,
    'sound_speed_t_exact_ca':  2.590240910649300e-009,
    'kappa_t_exact_ca':  1.712677458291044e-021,
    'kappa_const_t_exact_ca':  1.697064424229105e-021,
    'adiabatic_lapse_rate_t_exact_ca':  5.699738675609156e-019,
    'osmotic_coefficient_t_exact_ca':  3.583799923490005e-013,
    'osmotic_pressure_t_exact_ca':  1.023465756588848e-009,
    't_maxdensity_exact_ca':  6.274447628129565e-011,
    'sa_from_rho_t_exact_ca':  1.304769625676272e-010,
    't_from_rho_exact_ca':  6.032974120273593e-010,
    'fdelta_ca':  2.702939055302528e-014,
    'delta_sa_ref_ca':  6.945514042372425e-013,
}

class Constants(object):
    pass

C = Constants()
C.__dict__ = const


sp                  = 35.5e0
sa                  = 35.7e0
sstar               = 35.5e0
sr                  = 35.5e0
t                   = 15e0
ct                  = 20e0
pt                  = 15e0
p                   = 300e0
p_bs                = 50e0
p_ref               = 100e0
lon                 = 260e0
long_bs             = 20e0
lat                 = 16e0
lat_bs              = 60e0
saturation_fraction = 0.5e0

import unittest
import numpy as np

import pygsw as gsw
from pygsw import vectors as gswv

class PyGSWTest(unittest.TestCase):
    def test_vector_values(self):
        self.assertTrue( self.validate('gswv.alpha', C.alpha_ca,gswv.alpha(sa,ct,p),2.62460550806784356e-4))
        self.assertTrue( self.validate("gswv.sa_from_sp", C.sa_from_sp_ca, gswv.sa_from_sp(sp,p,lon,lat), 35.671358392019094e0))
        self.assertTrue( self.validate("gswv.sstar_from_sp", C.sstar_from_sp_ca, gswv.sstar_from_sp(sa,p,lon,lat), 35.866946753006239e0))
        self.assertTrue( self.validate("gswv.ct_from_t", C.ct_from_t_ca, gswv.ct_from_t(sa,t,p),  14.930280459895560e0))
        self.assertTrue( self.validate("gswv.deltasa_from_sp", C.deltasa_from_sp_ca, gswv.deltasa_from_sp(sp,p,lon,lat),  3.96067773336028495e-3))
        self.assertTrue( self.validate("gswv.sr_from_sp", C.sr_from_sp_ca, gswv.sr_from_sp(sp),  35.667397714285734e0))
        self.assertTrue( self.validate("gswv.sp_from_sr", C.sp_from_sr_ca, gswv.sp_from_sr(sr),  35.333387933015295e0))
        self.assertTrue( self.validate("gswv.sp_from_sa", C.sp_from_sa_ca, gswv.sp_from_sa(sa,p,lon,lat), 35.528504019167094e0))
        self.assertTrue( self.validate("gswv.sstar_from_sa", C.sstar_from_sa_ca, gswv.sstar_from_sa(sa,p,lon,lat), 35.694648791860907e0))
        self.assertTrue( self.validate("gswv.sp_from_sstar", C.sp_from_sstar_ca, gswv.sp_from_sstar(sstar,p,lon,lat), 35.334761242083573e0))
        self.assertTrue( self.validate("gswv.sa_from_sstar", C.sa_from_sstar_ca, gswv.sa_from_sstar(sstar,p,lon,lat), 35.505322027120805e0))
        self.assertTrue( self.validate("gswv.pt_from_ct", C.pt_from_ct_ca, gswv.pt_from_ct(sa,ct), 20.023899375975017e0))
        self.assertTrue( self.validate("gswv.t_from_ct", C.t_from_ct_ca, gswv.t_from_ct(sa,ct,p), 20.079820359223014e0))
        self.assertTrue( self.validate("gswv.ct_from_pt", C.ct_from_pt_ca, gswv.ct_from_pt(sa,pt), 14.976021403957613e0))
        self.assertTrue( self.validate("gswv.pt0_from_t", C.pt0_from_t_ca, gswv.pt0_from_t(sa,t,p),  14.954241363902305e0))
        self.assertTrue( self.validate("gswv.pt_from_t", C.pt_from_t_ca, gswv.pt_from_t(sa,t,p,p_ref), 14.969381237883740e0))
        self.assertTrue( self.validate("gswv.rho", C.rho_ca, gswv.rho(sa,ct,p), 1026.4562376198473e0))
        self.assertTrue( self.validate("gswv.alpha", C.alpha_ca, gswv.alpha(sa,ct,p), 2.62460550806784356e-4))
        self.assertTrue( self.validate("gswv.beta", C.beta_ca, gswv.beta(sa,ct,p), 7.29314455934463365e-4 ))
        self.assertTrue( self.validate("gswv.specvol", C.specvol_ca, gswv.specvol(sa,ct,p), 9.74225654586897711e-4 ))
        self.assertTrue( self.validate("gswv.specvol_anom", C.specvol_anom_ca, gswv.specvol_anom(sa,ct,p), 2.90948181201264571e-6 ))
        self.assertTrue( self.validate("gswv.sound_speed", C.sound_speed_ca, gswv.sound_speed(sa,ct,p), 1527.2011773569989e0 ))
        self.assertTrue( self.validate("gswv.internal_energy", C.internal_energy_ca, gswv.internal_energy(sa,ct,p), 79740.482561720783e0 ))
        self.assertTrue( self.validate("gswv.enthalpy", C.enthalpy_ca, gswv.enthalpy(sa,ct,p), 82761.872939932495e0 ))
        self.assertTrue( self.validate("gswv.dynamic_enthalpy", C.dynamic_enthalpy_ca, gswv.dynamic_enthalpy(sa,ct,p),  2924.5137975399025e0 ))
        self.assertTrue( self.validate("gswv.ct_freezing", C.ct_freezing_ca, gswv.ct_freezing(sa,p,saturation_fraction), -2.1801450326174852e0))
        self.assertTrue( self.validate("gswv.t_freezing", C.t_freezing_ca, gswv.t_freezing(sa,p,saturation_fraction), -2.1765521998023516e0))
        self.assertTrue( self.validate("gswv.latentheat_melting", C.latentheat_melting_ca, gswv.latentheat_melting(sa,p), 329330.54839618353e0))
        self.assertTrue( self.validate("gswv.latentheat_evap_ct", C.latentheat_evap_ct_ca, gswv.latentheat_evap_ct(sa,ct), 2450871.0228523901e0))
        self.assertTrue( self.validate("gswv.latentheat_evap_t", C.latentheat_evap_t_ca, gswv.latentheat_evap_t(sa,t), 2462848.2895522709e0))
        self.assertTrue( self.validate("gswv.rho_t_exact", C.rho_t_exact_ca, gswv.rho_t_exact(sa,t,p), 1027.7128170207150e0))
        self.assertTrue( self.validate("gswv.pot_rho_t_exact", C.pot_rho_t_exact_ca, gswv.pot_rho_t_exact(sa,t,p,p_ref), 1026.8362655887486e0))
        self.assertTrue( self.validate("gswv.alpha_wrt_t_exact", C.alpha_wrt_t_exact_ca, gswv.alpha_wrt_t_exact(sa,t,p), 2.19066952410728916e-4))
        self.assertTrue( self.validate("gswv.beta_const_t_exact", C.beta_const_t_exact_ca, gswv.beta_const_t_exact(sa,t,p),  7.44744841648729426e-4))
        self.assertTrue( self.validate("gswv.specvol_t_exact", C.specvol_t_exact_ca, gswv.specvol_t_exact(sa,t,p), 9.73034473676164815e-4))
        self.assertTrue( self.validate("gswv.sound_speed_t_exact", C.sound_speed_t_exact_ca, gswv.sound_speed_t_exact(sa,t,p), 1512.2053940303056e0))
        self.assertTrue( self.validate("gswv.kappa_t_exact", C.kappa_t_exact_ca, gswv.kappa_t_exact(sa,t,p), 4.25506953386609075e-010))
        self.assertTrue( self.validate("gswv.enthalpy_t_exact", C.enthalpy_t_exact_ca, gswv.enthalpy_t_exact(sa,t,p), 62520.680485510929e0))
        self.assertTrue( self.validate("gswv.entropy_t_exact", C.entropy_t_exact_ca, gswv.entropy_t_exact(sa,t,p), 212.30166821093002e0))
        self.assertTrue( self.validate("gswv.cp_t_exact", C.cp_t_exact_ca, gswv.cp_t_exact(sa,t,p), 3982.7832563441461e0))
        self.assertTrue( self.validate("gswv.delta_sa_ref", C.delta_sa_ref_ca, gswv.delta_sa_ref(p,lon,lat), 3.87660373016291727e-3))
        self.assertTrue( self.validate("gswv.fdelta", C.fdelta_ca, gswv.fdelta(p,lon,lat), 1.49916256924158942e-004))
        self.assertTrue( self.validate("gswv.sa_from_sp_baltic", C.sa_from_sp_ca, gswv.sa_from_sp_baltic(sp,long_bs,lat_bs) , 35.666154857142850e0))
        self.assertTrue( self.validate("gswv.sp_from_sa_baltic", C.sp_from_sa_ca, gswv.sp_from_sa_baltic(sa,long_bs,lat_bs), 35.533769845749660e0))
        

    def test_valid_values(self):
        self.assertTrue( self.validate('gsw.alpha', C.alpha_ca,gsw.alpha(sa,ct,p),2.62460550806784356e-4))
        self.assertTrue( self.validate("gsw.sa_from_sp", C.sa_from_sp_ca, gsw.sa_from_sp(sp,p,lon,lat), 35.671358392019094e0))
        self.assertTrue( self.validate("gsw.sstar_from_sp", C.sstar_from_sp_ca, gsw.sstar_from_sp(sa,p,lon,lat), 35.866946753006239e0))
        self.assertTrue( self.validate("gsw.ct_from_t", C.ct_from_t_ca, gsw.ct_from_t(sa,t,p),  14.930280459895560e0))
        self.assertTrue( self.validate("gsw.deltasa_from_sp", C.deltasa_from_sp_ca, gsw.deltasa_from_sp(sp,p,lon,lat),  3.96067773336028495e-3))
        self.assertTrue( self.validate("gsw.sr_from_sp", C.sr_from_sp_ca, gsw.sr_from_sp(sp),  35.667397714285734e0))
        self.assertTrue( self.validate("gsw.sp_from_sr", C.sp_from_sr_ca, gsw.sp_from_sr(sr),  35.333387933015295e0))
        self.assertTrue( self.validate("gsw.sp_from_sa", C.sp_from_sa_ca, gsw.sp_from_sa(sa,p,lon,lat), 35.528504019167094e0))
        self.assertTrue( self.validate("gsw.sstar_from_sa", C.sstar_from_sa_ca, gsw.sstar_from_sa(sa,p,lon,lat), 35.694648791860907e0))
        self.assertTrue( self.validate("gsw.sp_from_sstar", C.sp_from_sstar_ca, gsw.sp_from_sstar(sstar,p,lon,lat), 35.334761242083573e0))
        self.assertTrue( self.validate("gsw.sa_from_sstar", C.sa_from_sstar_ca, gsw.sa_from_sstar(sstar,p,lon,lat), 35.505322027120805e0))
        self.assertTrue( self.validate("gsw.pt_from_ct", C.pt_from_ct_ca, gsw.pt_from_ct(sa,ct), 20.023899375975017e0))
        self.assertTrue( self.validate("gsw.t_from_ct", C.t_from_ct_ca, gsw.t_from_ct(sa,ct,p), 20.079820359223014e0))
        self.assertTrue( self.validate("gsw.ct_from_pt", C.ct_from_pt_ca, gsw.ct_from_pt(sa,pt), 14.976021403957613e0))
        self.assertTrue( self.validate("gsw.pt0_from_t", C.pt0_from_t_ca, gsw.pt0_from_t(sa,t,p),  14.954241363902305e0))
        self.assertTrue( self.validate("gsw.pt_from_t", C.pt_from_t_ca, gsw.pt_from_t(sa,t,p,p_ref), 14.969381237883740e0))
        self.assertTrue( self.validate("gsw.rho", C.rho_ca, gsw.rho(sa,ct,p), 1026.4562376198473e0))
        self.assertTrue( self.validate("gsw.alpha", C.alpha_ca, gsw.alpha(sa,ct,p), 2.62460550806784356e-4))
        self.assertTrue( self.validate("gsw.beta", C.beta_ca, gsw.beta(sa,ct,p), 7.29314455934463365e-4 ))
        self.assertTrue( self.validate("gsw.specvol", C.specvol_ca, gsw.specvol(sa,ct,p), 9.74225654586897711e-4 ))
        self.assertTrue( self.validate("gsw.specvol_anom", C.specvol_anom_ca, gsw.specvol_anom(sa,ct,p), 2.90948181201264571e-6 ))
        self.assertTrue( self.validate("gsw.sound_speed", C.sound_speed_ca, gsw.sound_speed(sa,ct,p), 1527.2011773569989e0 ))
        self.assertTrue( self.validate("gsw.internal_energy", C.internal_energy_ca, gsw.internal_energy(sa,ct,p), 79740.482561720783e0 ))
        self.assertTrue( self.validate("gsw.enthalpy", C.enthalpy_ca, gsw.enthalpy(sa,ct,p), 82761.872939932495e0 ))
        self.assertTrue( self.validate("gsw.dynamic_enthalpy", C.dynamic_enthalpy_ca, gsw.dynamic_enthalpy(sa,ct,p),  2924.5137975399025e0 ))
        self.assertTrue( self.validate("gsw.ct_freezing", C.ct_freezing_ca, gsw.ct_freezing(sa,p,saturation_fraction), -2.1801450326174852e0))
        self.assertTrue( self.validate("gsw.t_freezing", C.t_freezing_ca, gsw.t_freezing(sa,p,saturation_fraction), -2.1765521998023516e0))
        self.assertTrue( self.validate("gsw.latentheat_melting", C.latentheat_melting_ca, gsw.latentheat_melting(sa,p), 329330.54839618353e0))
        self.assertTrue( self.validate("gsw.latentheat_evap_ct", C.latentheat_evap_ct_ca, gsw.latentheat_evap_ct(sa,ct), 2450871.0228523901e0))
        self.assertTrue( self.validate("gsw.latentheat_evap_t", C.latentheat_evap_t_ca, gsw.latentheat_evap_t(sa,t), 2462848.2895522709e0))
        self.assertTrue( self.validate("gsw.rho_t_exact", C.rho_t_exact_ca, gsw.rho_t_exact(sa,t,p), 1027.7128170207150e0))
        self.assertTrue( self.validate("gsw.pot_rho_t_exact", C.pot_rho_t_exact_ca, gsw.pot_rho_t_exact(sa,t,p,p_ref), 1026.8362655887486e0))
        self.assertTrue( self.validate("gsw.alpha_wrt_t_exact", C.alpha_wrt_t_exact_ca, gsw.alpha_wrt_t_exact(sa,t,p), 2.19066952410728916e-4))
        self.assertTrue( self.validate("gsw.beta_const_t_exact", C.beta_const_t_exact_ca, gsw.beta_const_t_exact(sa,t,p),  7.44744841648729426e-4))
        self.assertTrue( self.validate("gsw.specvol_t_exact", C.specvol_t_exact_ca, gsw.specvol_t_exact(sa,t,p), 9.73034473676164815e-4))
        self.assertTrue( self.validate("gsw.sound_speed_t_exact", C.sound_speed_t_exact_ca, gsw.sound_speed_t_exact(sa,t,p), 1512.2053940303056e0))
        self.assertTrue( self.validate("gsw.kappa_t_exact", C.kappa_t_exact_ca, gsw.kappa_t_exact(sa,t,p), 4.25506953386609075e-010))
        self.assertTrue( self.validate("gsw.enthalpy_t_exact", C.enthalpy_t_exact_ca, gsw.enthalpy_t_exact(sa,t,p), 62520.680485510929e0))
        self.assertTrue( self.validate("gsw.entropy_t_exact", C.entropy_t_exact_ca, gsw.entropy_t_exact(sa,t,p), 212.30166821093002e0))
        self.assertTrue( self.validate("gsw.cp_t_exact", C.cp_t_exact_ca, gsw.cp_t_exact(sa,t,p), 3982.7832563441461e0))
        self.assertTrue( self.validate("gsw.delta_sa_ref", C.delta_sa_ref_ca, gsw.delta_sa_ref(p,lon,lat), 3.87660373016291727e-3))
        self.assertTrue( self.validate("gsw.fdelta", C.fdelta_ca, gsw.fdelta(p,lon,lat), 1.49916256924158942e-004))
        self.assertTrue( self.validate("gsw.sa_from_sp_baltic", C.sa_from_sp_ca, gsw.sa_from_sp_baltic(sp,long_bs,lat_bs) , 35.666154857142850e0))
        self.assertTrue( self.validate("gsw.sp_from_sa_baltic", C.sp_from_sa_ca, gsw.sp_from_sa_baltic(sa,long_bs,lat_bs), 35.533769845749660e0))


    def validate(self, name, acceptable, actual, expected):
        diff = abs(actual - expected)
        if ( diff < acceptable):
            return True
        print name, ' failed.'
        return False

    def test_pracsal(self):

        C = np.array([34.5487, 34.7275, 34.8605, 34.6810, 34.5680, 34.5600])
        t = np.array([28.7856, 28.4329, 22.8103, 10.2600,  6.8863,  4.4036])
        p = np.array([10, 50, 125, 250, 600, 1000])

        output = gswv.sp_from_c(C,t,p)
        check_values = np.array((20.009869599086951,
                                 20.265511864874270,
                                 22.981513062527689,
                                 31.204503263727982,
                                 34.032315787432829,
                                 36.400308494388170))
        np.testing.assert_array_almost_equal(output, check_values)
        

    def test_ctd_density(self):
        """
        Test ctd_density function.
        """
        
        SP = np.array([33.5, 33.5, 37, 34.9, 35, 35])
        t = np.array([28., 28., 20., 6., 3., 2.])
        p = np.array([0., 10., 150., 800., 2500., 5000.])
        lat = 15.00
        lon = -55.00
        
        output = gswv.ctd_density(SP,t,p,lat,lon)

        check_values = np.array([1021.26851,
                                 1021.31148,
                                 1026.94422,
                                 1031.13498,
                                 1039.28768,
                                 1050.30616])
        np.testing.assert_array_almost_equal(output, check_values, 3)
        

    
