[ncl-talk] Unable to link to Fortran shared object created with WRAPIT
Barry Lynn
barry.h.lynn at gmail.com
Mon May 14 11:31:12 MDT 2018
Hi:
Just remember that in NCL a variable that is V(x,y) in WRF output is V(y,x)
in NCL. However, in the WRAPIT program, you use V(X,Y).
On Mon, May 14, 2018 at 7:23 PM, Michael Toy <toy at ucar.edu> wrote:
> Hi Dennis,
>
> Thank you for your help. I understand now to keep things “Fortran 77” in
> terms of what WRAPIT processes. In this spirit, I changed my f90 program
> from a module to just a subroutine by eliminating the “module” statements,
> and just leaving “mult.f90” as:
>
> subroutine mult(x,y,z)
>
> implicit none
>
> real, intent(in) :: x,y
> real, intent(out) :: z
>
> z = x*y
>
> end subroutine mult
>
> Using the same mult.stub file as before, a mult.so file is created and is
> readable by the NCL — external MLT “./mult.so” — command, and executes just
> fine. Hopefully this will work for the actual Fortran code I’m hoping to
> execute from NCL, which is a WRF physics module (which I won’t call a
> module for the purposes of WRAPIT).
>
> Thanks again.
>
> Best regards,
> Mike
>
>
>
>
> On May 13, 2018, at 8:27 AM, Dennis Shea <shea at ucar.edu> wrote:
>
> Hello,
>
> Once a function/subroutine is placed in a module, two 'things' must be
> done:
>
> [1] A module must be compiled *prior* to its invocation by other program
> units
> [2] The program unit(s) invoking the function/subroutine contained within
> a module must apply the USE statement.
>
> Attached are two fortran codes. Note the module is compiled 1st.
> Also, a side point, these could be in one file as long as the module is
> compiled prior to other units.
>
> %> gfortran toy_module.f90 test.toy_module.f90
> %> ./a.out
>
> z= 6.8999996
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> Likely, you already know the above .
> However, I thought it should be mentioned for others who might want to do
> something similar to what you are doing.
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> OK ... how to accommodate using a subroutine contained within a module
> from NCL.
>
> [1] *THE* issue is that NCL's WRAPIT understands only f77 syntax.
> [2] The 'USE' statement is f90. Further, it must/should appear even
> before an 'implicit none' statement.
> [3] WRAPIT would likely fail (untested if this is true) if the USE
> statement were encountered between the 'C NCLFORTSTART' and 'C NCLEND'
> delimiters.
> [4] My opinion is that you must add a 2nd subroutine ... a bit of a
> nuisance.
>
> ---
> In the following, the 77 and 90 suffixes are used to differentiate the
> program subroutines. They have no language meaning.
>
> The 1st subroutine [mult77] contains the WRAPIT recognized delimiters:
> 'C NCLFORTSTART' and 'C NCLEND'. WRAPIT will create the necessary
> infrastructure for argument passing between arguments between NCL (written
> in C) and fortran.
>
> The 2nd subroutine is a valid program unit invokes the 'USE' statement.
>
> Again, the USE statement could not be simply added to the 1st subroutine
> because WRAPIT would not know what to do with it!
>
> C NCLFORTSTART
> subroutine* mult77*(x,y,z)
> implicit none
> real x,y,z
> C NCLEND
> call *mult90*(x,y,z)
> return
> end
> C------------
> subroutine *mult90*(x,y,z)
> *use module_mult*
> implicit none
> real, intent(in) :: x,y
> real, intent(out) :: z
>
> call *mult*(x,y,z)
> return
> end
>
> ================
> Test the NCL call to invoke the module. Note the module is compiled 1st.
>
> %> *WRAPIT* toy_module.f90 toy_mult7790.f
>
> This will create '*toy_module.so*'
>
> The following 'toy_test.ncl' contains:
>
> external TOY_MODULE "./toy_module.so"
>
>
> xNCL = 2.3
> yNCL = 3.0
> zNCL = 1e20
> *TOY_MODULE::mult77*(xNCL, yNCL, zNCL) ; interface with f77 which
> calls f90
> print("zNCL="+zNCL)
>
> =====
> %> ncl toy_test.ncl
>
> (0) zNCL=6.9
>
> ==================
> Hopefully, this is somewhat clear.
>
> Good luck
>
> On Fri, May 11, 2018 at 3:47 PM, Michael Toy <toy at ucar.edu> wrote:
>
>> Hello,
>>
>> I am trying to call a fortran subroutine from an NCL script, and have
>> followed the documentation for “WRAPIT”. This is my first time trying it.
>> When I enter the following in NCL:
>> ncl 0> external MLT “./mult.so"
>>
>> I get the error message:
>> warning:An error occurred loading the external file ./mult.so, file not
>> loaded
>> ./mult.so: undefined symbol: mult_
>> warning:error at line 0
>>
>>
>> I’m testing a simple subroutine which multiplies two numbers together.
>> My Fortran 90 code (mult.f90) is:
>>
>> module module_mult
>>
>> contains
>>
>> subroutine mult(x,y,z)
>>
>> implicit none
>>
>> real, intent(in) :: x,y
>> real, intent(out) :: z
>>
>> z = x*y
>>
>> end subroutine mult
>>
>> end module module_mult
>>
>>
>> My “stub” file is:
>> C NCLFORTSTART
>> subroutine mult(x,y,z)
>> real x,y,z
>> C NCLEND
>>
>>
>> When I run “WRAPIT mult.stub mult.f90” it seems to run successfully, and
>> produces the file:
>> mult.so
>>
>>
>> I am running NCL version 6.4.0 on the following system:
>> Linux x86_64 x86_64 x86_64 GNU/Linux
>>
>> I know this problem has come up in the NCL users’ forum before, but I’ve
>> not seen how the issue gets resolved. Your help would be appreciated.
>> Thanks.
>>
>> Best regards,
>> Mike
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
> <toy_module.f90><test.toy_module.f90><toy_mult7790.f><toy_test.ncl>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
--
Barry H. Lynn, Ph.D
Senior Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581
C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180514/215a9db0/attachment.html>
More information about the ncl-talk
mailing list