Re: WRAPIT issue: undefined symbol: kmns_

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 28 2011 - 11:26:45 MST

There are several issues here.
[1]
To my knowledge, you can only call fortran subroutines from NCL.
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
> LINKING
> 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
>
> Copyright (C) 1995-2009 - All Rights Reserved
> 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.
> warning:An error occurred loading the external file ./Lmoments1.so, file
> not loaded
> ./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
Received on Fri Jan 28 11:26:50 2011

This archive was generated by hypermail 2.1.8 : Mon Jan 31 2011 - 10:38:24 MST