[ncl-talk] Unable to link to Fortran shared object created with WRAPIT
Michael Toy
toy at ucar.edu
Tue May 15 07:51:46 MDT 2018
Hello,
After my success with using WRAPIT on the simple example, I have been unable to create a Fortran shared object with the actual WRF F90 module I want to use.
I’ve attached the F77 subroutine (module_bl_gwdo_gsd.NCL.f) that calls the F90 WRF module (module_bl_gwdo_gsd.f90). When I enter:
%> WRAPIT module_bl_gwdo_gsd.f90 module_bl_gwdo_gsd.NCL.f
I get the message:
WRAPIT Version: 120209
A syntax error occurred while parsing: :
COMPILING module_bl_gwdo_gsd.f90
COMPILING module_bl_gwdo_gsd.NCL.f
LINKING
END WRAPIT
The f90 module compiles and the files module_bl_gwdo_gsd.mod and module_bl_gwdo_gsd.so are created. However when I try to link to the shared object in NCL, using:
0> external GWD “./module_bl_gwdo_gsd.so"
I get the message:
warning:Could not find Init() in external file ./module_bl_gwdo_gsd.so, file not loaded
warning:error at line 0
I’m wondering if there’s something wrong with my F77 syntax. The WRAPIT execution complains about a “:” somewhere?
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/20180515/4f48d375/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: module_bl_gwdo_gsd.f90
Type: application/octet-stream
Size: 53663 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180515/4f48d375/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180515/4f48d375/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: module_bl_gwdo_gsd.NCL.f
Type: application/octet-stream
Size: 9179 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180515/4f48d375/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180515/4f48d375/attachment-0002.html>
More information about the ncl-talk
mailing list