Closed dankelley closed 8 years ago
I wrote some code to get the data from the netcdf file in the fortran 3.05 version. It is at
https://github.com/TEOS-10/GSW-R/blob/305/create_data/create_saar.R in case @richardsc wants to check my work. The numbers in the file are the same as they were for version 3.02, at least to the 1e-7 tests that are done by default with the testthat
package in R.
FYI, the netcdf file is also available on the github under datafile.
@fdelahoyde and @PaulMBarker ...
As an update, I've updated gsw-r for the new C code. Part of that work is to use the TEOS-10 supplied check values in build-time tests. By default, in R build-tests use a relative error of sqrt() machine precision, or 1.5e-8 on my computer. The functions all check OK at this threshold, with one exception: gsw_latentheat_melting()
, which has deviations about 20 times the threshold. (Details below, in funky R notation but I think it will be clear enough.)
Paul -- is there a chance the webpage http://www.teos-10.org/pubs/gsw/html/gsw_latentheat_melting.html might be wrong? (I don't have matlab so I can't check.)
Frank -- could you see if you get the same values from C as I do? (Possibly I made an editing error. I had to do a few changes in the code so that R can save the data file separately, because the R core team won't permit a C file that contains so much data.)
> library(gsw)
Loading required package: testthat
> SA <- c(34.7118, 34.8915, 35.0256, 34.8472, 34.7366, 34.7324)
> p <- c( 10, 50, 125, 250, 600, 1000)
> lh <- gsw_latentheat_melting(SA, p)
> lh_check <- 1e5*c(3.299495187300804, 3.298611954422526, 3.297124383647952,
+ 3.294972884747496, 3.288480015369891, 3.280715953443947)
> data.frame(lh=lh, difference=lh-lh_check)
lh difference
1 329949.7 0.149297041
2 329861.3 0.139797546
3 329712.6 0.123918659
4 329497.4 0.101058326
5 328848.0 0.043018985
6 328071.6 -0.009102756
> mean(abs((lh-lh_check)/lh))
[1] 2.862329e-07
Hey Dan,
You are correct the values listed on the webpage for latent heat are wrong. I must have missed updating the values when I updated the toolbox, sorry about that.
Here are the correct values:
SA = [34.7118; 34.8915; 35.0256; 34.8472; 34.7366; 34.7324;] p = [ 10; 50; 125; 250; 600; 1000;]
latentheat_melting = gsw_latentheat_melting(SA,p)
latentheat_melting =
1.0e+05 *
3.299496680271213 3.298613352397986 3.297125622834541 3.294973895330757 3.288480445559747 3.280715862416388
By the way when I changed the datafile to a netcdf file I included lots of test values and the computational accuracy that a calculation should achieve, these values will always be more upto date than the web page examples as they are automatically generated when I make the datafile, In the last couple of versions I have written more code to automate these things. Initially I was doing much of it by hand. Unfortunately the webpages are still done one at a time by hand.
It is a pain not getting recognition for your hard work translating GSW, I can assure you we appreciate it.
Thanks, Paul -- the values work with the default equality-check tolerances.
@PaulMBarker -- I wonder if the web check values for gsw_t_freezing()
may be in error. I get as follows (mean absolute error a bit under 1e-4 degC) when I hook R to gsw_t_freezing()
, but things are OK if I hook to gsw_t_freezing_exact()
.
> library(gsw)
> library(testthat)
> SA <- c(34.7118, 34.8915, 35.0256, 34.8472, 34.7366, 34.7324)
> p <- c( 10, 50, 125, 250, 600, 1000)
> saturation_fraction <- 1
> tf <- gsw_t_freezing(SA, p, saturation_fraction)
> expect_equal(tf, c(-1.902730710149803, -1.942908619287183, -2.006861069199743,
+ -2.090985086875259, -2.351293130342102, -2.660498762776720))
Error: tf not equal to c(-1.9027307101498, -1.94290861928718, -2.00686106919974, -2.09098508687526, -2.3512931303421, -2.66049876277672)
6/6 mismatches (average diff: 7.24e-05).
First 6:
pos x y diff
1 -1.90 -1.90 -2.63e-05
2 -1.94 -1.94 -1.07e-05
3 -2.01 -2.01 1.63e-05
4 -2.09 -2.09 5.63e-05
5 -2.35 -2.35 1.38e-04
6 -2.66 -2.66 1.86e-04
I need a bit more info to help on this one.
SA = [34.7118, 34.8915, 35.0256, 34.8472, 34.7366, 34.7324]; p = [ 10, 50, 125, 250, 600, 1000]; saturation_fraction = 1;
t_freezing = gsw_t_freezing(SA, p, saturation_fraction)'
t_freezing =
-1.902730710149803 -1.942908619287183 -2.006861069199743 -2.090985086875259 -2.351293130342102 -2.660498762776720
t_freezing_poly = gsw_t_freezing_poly(SA, p, saturation_fraction)'
t_freezing_poly =
-1.902704434299200 -1.942897945475226 -2.006877364578649 -2.091041391538033 -2.351431560178946 -2.660685237633709
I do not have a gsw_t_freezing_exact, what does your t_freezing_exact code do, does it call the chemical potential of water and the gibbs function or does it use a polynomial ?
Thanks, Paul. The R gets gsw_t_freezing_exact()
from line 10046 of gsw_oceanographic_toolbox.c, which is linked with:
https://github.com/TEOS-10/GSW-C/blob/master/gsw_oceanographic_toolbox.c#L10046
and I think is derived from the fortran source linked with:
https://github.com/TEOS-10/GSW-Fortran/blob/master/toolbox/gsw_t_freezing_exact.f90
In answer to the question, it seems to be using chemical potential.
I'm not sure why the fortran and C have a function that's not in the matlab.
I'll add an @fdelahoyde to this comment so that Frank gets an email. Possibly this issue is relevant to him, too.
PS. when replying over email, it's best not to include the material that was sent. Actually, the best is just to click the github link at the end, which shows all the discussion, possibly with images and so forth. I often chop out content from others' comments, if it contains phone numbers etc.
ok that helps, gsw_t_freezing_exact is gsw_t_freezing, I will email Glenn. Yesterday I calculated the values that I sent you not just copying them from the webpages, so they should be correct.
I am not sure what i included in my reply, I will check in future not to include the received email. This is the first time I have used the web interface, but I really need the spell checker option.
I realize this discussion concluded months ago, so I'm closing the issue.
Goal. The C and Fortran codes for GSW-3.05 are now available on the TEOS-10 website, so it makes sense to start migration of GSW-R to 3.05. I made a new branch named
305
for this. Below is a list of the functions in gsw (from a grep in the fileR/gsw.R
), with a checkmark indicating that the function and its documentation have been updated, and that the check values match the published ones (but see the notes on some functions).argfix
gsw_adiabatic_lapse_rate_from_CT
gsw_alpha
gsw_alpha_on_beta
gsw_alpha_wrt_t_exact
gsw_beta
gsw_beta_const_t_exact
gsw_cabbeling
gsw_C_from_SP
gsw_cp_t_exact
gsw_CT_freezing
gsw_CT_from_pt
gsw_CT_from_t
gsw_deltaSA_from_SP
gsw_dynamic_enthalpy
gsw_enthalpy
gsw_enthalpy_t_exact
gsw_entropy_from_t
gsw_grav
gsw_internal_energy
gsw_IPV_vs_fNsquared_ratio
gsw_kappa
gsw_kappa_t_exact
gsw_latentheat_evap_CT
gsw_latentheat_evap_t
gsw_latentheat_melting
gsw_Nsquared
gsw_p_from_z
gsw_pot_rho_t_exact
gsw_pt0_from_t
gsw_pt_from_CT
gsw_pt_from_t
gsw_rho
gsw_rho_first_derivatives
gsw_rho_t_exact
gsw_SA_from_rho
gsw_SA_from_SP
gsw_SA_from_Sstar
gsw_sigma0
gsw_sigma1
gsw_sigma2
gsw_sigma3
gsw_sigma4
gsw_sound_speed
gsw_sound_speed_t_exact
gsw_specvol
gsw_specvol_anom_standard
Note that previously we providedgsw_specvol_anom
, but things seem to be changed in the matlab/C. The matlab version ofgsw_specvol_anom
has two additional arguments. Nothing corresponding was found in the C library, so I deletedgsw_specvol_anom
and providedgsw_specvol_anom_standard
, which is in both matlab and C, and which has check values that work with the new R function of the same name.gsw_specvol_t_exact
gsw_SP_from_C
gsw_SP_from_SA
gsw_SP_from_SK
gsw_SP_from_SR
gsw_SP_from_Sstar
gsw_SR_from_SP
gsw_Sstar_from_SA
gsw_Sstar_from_SP
gsw_t_freezing
Note: This uses the C function namedgsw_t_freezing_exact
, because the C function namedgsw_t_freezing
does not produce check values that match the Matlab function calledgsw_t_freezing
.gsw_t_from_CT
gsw_thermobaric
gsw_Turner_Rsubrho
gsw_z_from_p