Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsw_cp0 #27

Closed
ThomasHaine opened this issue Dec 17, 2022 · 7 comments
Closed

gsw_cp0 #27

ThomasHaine opened this issue Dec 17, 2022 · 7 comments

Comments

@ThomasHaine
Copy link

How do I access the seawater specific heat capacity gsw_cp0 constant (and other constants, for that matter)? The MATLAB gsw package has a function that returns it.

Thanks for building this Julia gsw package!

@Alexander-Barth
Copy link
Member

Yes, that would be useful. I think that they have to be copied over manually from the C source:

https://github.com/TEOS-10/GSW-C/blob/master/gsw_internal_const.h#L33

Are you interested to make a pull request?

@ThomasHaine
Copy link
Author

Yes, I can try, although I'm a Julia newbie so will probably need some help.

@dankelley
Copy link

That could be a one-liner, as defined and tested below, but the harder thing would be finding where in the source to put this, so that it would sit alongside similar functions.

julia> gsw_cp0() = 3991.86795711963
gsw_cp0 (generic function with 1 method)

julia> gsw_cp0()
3991.86795711963

@Alexander-Barth
Copy link
Member

Alexander-Barth commented Dec 20, 2022

I guess that we can also declare it as an irrational as we did for Ωe (https://github.com/TEOS-10/GibbsSeaWater.jl/blob/master/src/utils.jl#L1 )

Base.@irrational gsw_cp0  3991.86795711963 big(3991.86795711963)
export gsw_cp0 

It can go maybe the same file src/utils.jl. The advantage of the irrational type is that when multiplied with a single precision float, the result will remain single precision (and not automatically promoted to double precision).

julia> Base.@irrational gsw_cp0  3991.86795711963 big(3991.86795711963)

julia> gsw_cp0
gsw_cp0 = 3991.8679571196...

julia> gsw_cp0 * 1.0
3991.86795711963

julia> gsw_cp0 * 1f0
3991.868f0

julia> typeof(gsw_cp0 * 1f0)
Float32

julia> typeof(gsw_cp0 * 1.0)
Float64

@kouketsu
Copy link
Collaborator

@Alexander-Barth, thanks for your support.
@ThomasHaine, please wait I can update.

@kouketsu
Copy link
Collaborator

@ThomasHaine, I've updated.

You can try after update the package, like
pkg> add GibbsSeaWater#master
and check it.

julia> using GibbsSeaWater
julia> Float32(GibbsSeaWater.gsw_cp0)
3991.868f0

Now, to check it without a warning, we may need to cast them to a type like Float32() or Float64() under julia version <= 1.8.3.

@ThomasHaine
Copy link
Author

Works! Thanks @kouketsu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants