[ncl-talk] Unable to link to Fortran shared object created with WRAPIT
Michael Toy
toy at ucar.edu
Mon May 14 10:58:42 MDT 2018
Hi Dennis,
On second thought, I think I will have to use your suggestion of adding a second subroutine. I’ve tried doing this, but have not yet been successful. (Part of the trouble is that I’m not F77 proficient.)
My first question is about the 17 lines of code you wrote, i.e, C NCLFORTSTART ….. end. Would this be the contents of “toy_mult7790.f”? In your “WRAPIT” command execution, is toy_module.f90 my original F90 module? Where’s the “stub” file?
Thanks.
— 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 <mailto: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 <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>
>
> <toy_module.f90><test.toy_module.f90><toy_mult7790.f><toy_test.ncl>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180514/f73e3f5c/attachment.html>
More information about the ncl-talk
mailing list