<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 &quot;selected_real_kind&quot; syntax in Fortran 90, but after reading about it, I don&#39;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 &quot;double precision&quot; 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&#39;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 &quot;selected_real_kind(15, 307)&quot; or &quot;real(kind(0.0d0))&quot;</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&#39;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 href="mailto:william.llovel@cerfacs.fr">william.llovel@cerfacs.fr</a> <span dir="ltr">&lt;<a href="mailto:llovel@cerfacs.fr" target="_blank">llovel@cerfacs.fr</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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 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 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 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>