# Re: WRAPIT issue: undefined symbol: kmns_

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon Jan 31 2011 - 19:11:58 MST

Actually, the cumulative exponential distribution function 'cdfexp'
is straight forward to develop in NCL. This works for
any dimensionality

undef ("cdfexp_lm") ; Lmoment:
function cdfexp_lm(x:numeric,para[2]:numeric)
local zero, one, y, expcdf
begin
if (typeof(x).eq."double") then
zero = 0.0d
one = 1.0d
else
zero = 0.0
one = 1.0
end if

if (para(1).le.zero) then
dimx = dimsizes(x)
expcdf = new( dimx, typeof(x), getVarFillValue(x))
expcdf = zero
else
y = (x-para(0))/para(1)
expcdf = one-exp(-y)
end if

copy_VarCoords(x, expcdf)
expcdf@long_name = "CDF: EXPONENTIAL DISTRIBUTION"
return( expcdf )
end

; ********** test driver ********

x = (/5,7,4,9,6,10,1,15,8,12,3,2/)
qsort(x)

para = (/0.1,5/)

cdfx = cdfexp_lm(x, para)
print(cdfx)

On 1/31/11 7:51 AM, Mary Haley wrote:
>
> On Jan 28, 2011, at 11:26 AM, Dennis Shea wrote:
>
>> There are several issues here.
>> [1]
>> To my knowledge, you can only call fortran subroutines from NCL.
>
> Hi Debasish,
>
> Actually, you can call Fortran functions as well. See example 1 at
>
> http://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Example_1
>
> One thing you have to be careful of is including your own code that
> may have the same name as one of our built-in functions. CDFGAM
> is a subroutine that already exists in our Fortran libraries, so if you
> need to wrap your own version of this routine, make sure to give
> it a different name.
>
> I think Dennis well-covered the issues with your wrapper, so hopefully
> you are now and up running.
>
> --Mary
>
>> These are functions. You must create a subroutine interface to any
>> function you are calling. I appended 'lm' to the name for L-Moment.
>> I created a file named "Lmoments1_interface.f". It contained the
>> following entry.
>>
>> C NCLFORTSTART
>> subroutine cdfexplm(x,para,z)
>> c subroutine interface to double precision function 'cdfexp'
>> implicit none
>> double precision x, para(2), z
>> C NCLEND
>> double precision cdfexp
>> z = cdfexp(x,para)
>> return
>> end
>>
>> [2]
>> There are many functions and subroutines in this package. However,
>> you need to create interface subroutines *only* for the functions
>> and subroutine you are going to call from NCL. You must populate
>> the "Lmoments1_interface.f" with other interfaces to functions
>> you are using.
>>
>> [3]
>> Note that the Lmoment1.f description states that there are other
>> subroutines that must be loaded: http://lib.stat.cmu.edu/apstat/136
>> Specifically a "SUBROUTINE KMNS". You did not include this.
>>
>> [4]
>> The fortran functions and codes do not work on arrays. Only on
>> scalars. You must read the documentation.
>>
>> [5]
>> WRAPIT -fPIC Lmoments1_interface.f Lmoments1.f KMNS.f
>>
>> [6]
>> external LMOM "./Lmoments1_interface.so"
>>
>> x = (/5,7,4,9,6,10,1,15,8,12,3,2/)*1d0
>> nx = dimsizes(x)
>>
>> PARA = (/0.1,5/)*1d0
>>
>> cdfx = new( nx, "double", "No_FillValue")
>>
>> do n=0,nx-1
>> LMOM::cdfexplm(x(n),PARA,cdfx(n))
>> end do
>>
>> print (cdfx)
>>
>>
>> Variable: cdfx
>> Type: double
>> Total Size: 96 bytes
>> 12 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [12]
>> Coordinates:
>> (0) 0.164729788339798
>> (1) 0.3161385905838375
>> (2) 0.4401016332677352
>> (3) 0.5415939885581609
>> (4) 0.6246889010367491
>> (5) 0.6927212613072926
>> (6) 0.7484214468652672
>> (7) 0.7940249017337312
>> (8) 0.8313618526811464
>> (9) 0.8619307626479593
>> (10) 0.9074494224620745
>> (11) 0.949207166119964
>>
>>
>> On 01/28/2011 08:25 AM, Debasish wrote:
>>> Hello,
>>>
>>> I am having a problem with WRAPIT. I have a FORTRAN program consist of
>>> multiple subroutines and multiple functions.
>>>
>>> First I create a ".stub" file for all subroutines and functions
>>> example:
>>>
>>> C NCLFORTSTART
>>> DOUBLE PRECISION FUNCTION CDFEXP(X,PARA)
>>> C NCLEND
>>> C NCLFORTSTART
>>> DOUBLE PRECISION FUNCTION CDFGAM(X,PARA)
>>> C NCLEND
>>> NCLFORTSTART
>>> DOUBLE PRECISION FUNCTION CDFGEV(X,PARA)
>>> C NCLEND
>>> ..
>>> ..
>>> ..
>>> During compilation fortran program is working fine and successfully
>>> creates ".so".
>>>
>>> %> WRAPIT -L \$NCARG_ROOT/lib -l nfpfort -L ./ Lmoments1.stub Lmoments1.f
>>>
>>> WRAPIT Version: 091416
>>> COMPILING Lmoments1.f
>>> END WRAPIT
>>>
>>> But when I try to run a NCL scripts using one of the subroutine, The NCL
>>> script is following
>>> ;-----------------------------------------------
>>> external LMOM "./Lmoments1.so"
>>>
>>> x= (/5,7,4,9,6,10,1,15,8,12,3,2/)
>>>
>>> PARA = (/0.1,5/)
>>> qsort(x)
>>>
>>> cdfx = LMOM::CDFEXP(x,PARA)
>>>
>>> print (cdfx)
>>> ;------------------------------------------------------
>>>
>>> it gives me following error message
>>>
>>> %> ncl tst_lmoment.ncl
>>>
>>> University Corporation for Atmospheric Research
>>> NCAR Command Language Version 5.1.1
>>> The use of this software is governed by a License Agreement.
>>> See http://www.ncl.ucar.edu/ for more details.
>>> ./Lmoments1.so: undefined symbol: kmns_
>>> warning:error at line 1 in file tst_lmoment.ncl
>>>
>>> fatal:syntax error: line 13 in file tst_lmoment.ncl before or near :
>>> cdfx = LMOM:
>>> -----------^
>>>
>>> fatal:Variable (cdfx) is undefined
>>> fatal:Execute: Error occurred at or near line 15 in file tst_lmoment.ncl
>>>
>>> Thanks for helping me in this regard
>>>
>>> Debasish
>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> --
>> ======================================================
>> Dennis J. Shea tel: 303-497-1361 |
>> P.O. Box 3000 fax: 303-497-1333 |
>> Climate Analysis Section |
>> Climate& Global Dynamics Div. |
>> National Center for Atmospheric Research |
>> Boulder, CO 80307 |
>> USA email: shea 'at' ucar.edu |
>> ======================================================
>> _______________________________________________
>> 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
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jan 31 19:12:04 2011

This archive was generated by hypermail 2.1.8 : Fri Feb 04 2011 - 09:26:53 MST