<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Mary,<br>
<br>
To avoid this problem, one needs to declare the function as double
precision in addition to the argument into the stub.<br>
<br>
C NCLFORTSTART<br>
double precision function gsw_sa_from_sp(sp,p,lon,lat)<br>
double precision sp, lon, lat, p<br>
C NCLEND<br>
<br>
C NCLFORTSTART<br>
double precision function gsw_saar(p,lon,lat)<br>
double precision p, lat, lon<br>
C NCLEND<br>
<br>
I can provide you some sample code. Where should I put it ?<br>
<br>
Thanks,<br>
<br>
William<br>
<br>
<br>
<br>
<br>
<br>
On 02/25/2015 04:54 PM, Mary Haley wrote:
<blockquote
cite="mid:CACNN_C+EKmYToK6Jf2oMZ0iTqrdHgrQAhLjLZR=p8g03sgoG9Q@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-size: small;">Hi William,</div>
<div class="gmail_default" style="font-size: small;"><br>
</div>
<div class="gmail_default" style="font-size: small;">I am not
familiar with the "selected_real_kind" syntax in Fortran 90,
but after reading about it, I don't think you can interface to
it directly using WRAPIT, because of its arbitrary precision
potential.</div>
<div class="gmail_default" style="font-size: small;"><br>
</div>
<div class="gmail_default" style="font-size: small;">When you
declare something as a "double precision" in your WRAPIT stub,
then NCL is going to assume an 8-byte floating point number.
If you then pass this 8-byte number to a routine that turns it
into something with a different number of bytes of precision,
then it doesn't surprise me that the return result is
incorrect.</div>
<div class="gmail_default" style="font-size: small;"><br>
</div>
<div class="gmail_default" style="font-size: small;">To get
something that matches a true double precision, I think you
need to use "selected_real_kind(15, 307)" or
"real(kind(0.0d0))"</div>
<div class="gmail_default" style="font-size: small;"><br>
</div>
<div class="gmail_default" style="font-size: small;">I would
love to have a look at this further, if you could provide me
with some sample code that uses the Fortran 90 version of this
function. Or, do you know if there's a version of this code
that uses the more traditional real and double precision
Fortran definitions?</div>
<div class="gmail_default" style="font-size: small;"><br>
</div>
<div class="gmail_default" style="font-size: small;">--Mary</div>
<div class="gmail_default" style="font-size: small;"><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Feb 24, 2015 at 9:00 AM, <a
moz-do-not-send="true"
href="mailto:william.llovel@cerfacs.fr">william.llovel@cerfacs.fr</a>
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:llovel@cerfacs.fr" target="_blank">llovel@cerfacs.fr</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">Dear all,<br>
<br>
I am an oceanographer and a new NCL user. I am interested in
the ocean<br>
heat content change and its contribution to sea level.<br>
Thus, I need to compute some parameters as density, heat
capacity<br>
etc.... For that, I need to use the equation of state of the
ocean.<br>
The recommendation is now to consider the TEOS-10 software
available at<br>
<a moz-do-not-send="true" href="http://www.teos-10.org/"
target="_blank">http://www.teos-10.org/</a> .<br>
This website provides a set of fortran90 functions and
subroutines.<br>
I have tried to call them using the WRAPIT command :<br>
<a moz-do-not-send="true"
href="https://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Step_1"
target="_blank">https://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Step_1</a><br>
first, by creating a stub file and then, runing the WRAPIT
command.<br>
Unfortunately, this does not work. the results are wrong and
totally<br>
unphysical.<br>
<br>
this is why I am contacting you and asking your help.<br>
<br>
Below is an example of the F90 function.<br>
<br>
!==========================================================================<br>
function gsw_sa_from_sp(sp,p,lon,lat)<br>
!==========================================================================<br>
<br>
! Calculates Absolute Salinity, SA, from Practical Salinity,
SP<br>
!<br>
! sp : Practical Salinity
[unitless]<br>
! p : sea pressure
[dbar]<br>
! lon : lonitude
[DEG E]<br>
! lat : latitude
[DEG N]<br>
!<br>
! gsw_sa_from_sp : Absolute Salinity
[g/kg]<br>
<br>
implicit none<br>
integer, parameter :: r14 = selected_real_kind(14,30)<br>
<br>
real (r14) :: sp, lon, lat, p, gsw_sa_from_sp, gsw_saar,
saar<br>
real (r14) :: gsw_sa_baltic, gsw_sa_from_sp_baltic<br>
<br>
saar = gsw_saar(p,lon,lat)<br>
<br>
gsw_sa_from_sp = (35.16504d0/35.d0)*sp*(1.d0 + saar)<br>
!==========================================================================<br>
<br>
And my stub file before invoking WRAPIT.<br>
<br>
!==========================================================================<br>
C NCLFORTSTART<br>
function gsw_sa_from_sp(sp,p,lon,lat)<br>
double precision sp, lon, lat, p<br>
C NCLEND<br>
!==========================================================================<br>
<br>
I am able to run the WRAPIT command and create the file.so,
but when I<br>
try to call a function or subroutine with NCL, the results
are totally<br>
wrong.<br>
<br>
I think this is because of this line : integer, parameter ::
r14 =<br>
selected_real_kind(14,30) in the F90 functions that defines
my variables.<br>
<br>
If you have any idea on how I could resolve this issue, I
will be more<br>
than happy to hear from you.<br>
<br>
This toolbox is very important for any oceanographer. So,
implementing<br>
this toolbox into NCL will motive more researchers to use
your software.<br>
<br>
Thanks for your help,<br>
<br>
Best regards,<br>
<br>
William<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a moz-do-not-send="true"
href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk"
target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote>
</div>
<br>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
<a class="moz-txt-link-freetext" href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a>
</pre>
</blockquote>
<br>
</body>
</html>