[ncl-talk] using TEOS10 software with NCL

william.llovel@cerfacs.fr llovel at cerfacs.fr
Wed Feb 25 10:01:24 MST 2015


Hi Mary,

To avoid this problem, one needs to declare the function as double 
precision in addition to the argument into the stub.

C NCLFORTSTART
       double precision function gsw_sa_from_sp(sp,p,lon,lat)
       double precision  sp, lon, lat, p
C NCLEND

C NCLFORTSTART
       double precision function gsw_saar(p,lon,lat)
       double precision p, lat, lon
C NCLEND

I can provide you some sample code. Where should I put  it ?

Thanks,

William





On 02/25/2015 04:54 PM, Mary Haley wrote:
> Hi William,
>
> 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.
>
> 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.
>
> 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))"
>
> 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?
>
> --Mary
>
>
> On Tue, Feb 24, 2015 at 9:00 AM, william.llovel at cerfacs.fr 
> <mailto:william.llovel at cerfacs.fr> <llovel at cerfacs.fr 
> <mailto:llovel at cerfacs.fr>> wrote:
>
>     Dear all,
>
>     I am an oceanographer and a new NCL user. I am interested in the ocean
>     heat content change and its contribution to sea level.
>     Thus, I need to compute some parameters as density, heat capacity
>     etc.... For that, I need to use the equation of state of the ocean.
>     The recommendation is now to consider the TEOS-10 software
>     available at
>     http://www.teos-10.org/ .
>     This website provides a set of fortran90 functions and subroutines.
>     I have tried to call them using the WRAPIT command :
>     https://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Step_1
>     first, by creating a stub file and then, runing the WRAPIT command.
>     Unfortunately, this does not work. the results are wrong and totally
>     unphysical.
>
>     this is why I am contacting you and asking your help.
>
>     Below is an example of the F90 function.
>
>     !==========================================================================
>     function gsw_sa_from_sp(sp,p,lon,lat)
>     !==========================================================================
>
>     ! Calculates Absolute Salinity, SA, from Practical Salinity, SP
>     !
>     ! sp     : Practical Salinity                              [unitless]
>     ! p      : sea pressure                                    [dbar]
>     ! lon   : lonitude                                       [DEG E]
>     ! lat    : latitude                                        [DEG N]
>     !
>     ! gsw_sa_from_sp   : Absolute Salinity                     [g/kg]
>
>     implicit none
>     integer, parameter :: r14 = selected_real_kind(14,30)
>
>     real (r14) :: sp, lon, lat, p, gsw_sa_from_sp, gsw_saar, saar
>     real (r14) :: gsw_sa_baltic, gsw_sa_from_sp_baltic
>
>     saar = gsw_saar(p,lon,lat)
>
>     gsw_sa_from_sp = (35.16504d0/35.d0)*sp*(1.d0 + saar)
>     !==========================================================================
>
>     And my stub file before invoking WRAPIT.
>
>     !==========================================================================
>     C NCLFORTSTART
>            function gsw_sa_from_sp(sp,p,lon,lat)
>            double precision sp, lon, lat, p
>     C NCLEND
>     !==========================================================================
>
>     I am able to run the WRAPIT command and create the file.so, but when I
>     try to call a function or subroutine with NCL, the results are totally
>     wrong.
>
>     I think this is because of this line : integer, parameter :: r14 =
>     selected_real_kind(14,30) in the F90 functions that defines my
>     variables.
>
>     If you have any idea on how I could resolve this issue, I will be more
>     than happy to hear from you.
>
>     This toolbox is very important for any oceanographer. So, implementing
>     this toolbox into NCL will motive more researchers to use your
>     software.
>
>     Thanks for your help,
>
>     Best regards,
>
>     William
>
>
>
>
>
>
>
>     _______________________________________________
>     ncl-talk mailing list
>     List instructions, subscriber options, unsubscribe:
>     http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150225/a7219e25/attachment.html 


More information about the ncl-talk mailing list