<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Dennis,<div class=""><br class=""></div><div class="">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.)</div><div class=""><br class=""></div><div class="">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?</div><div class=""><br class=""></div><div class="">Thanks.</div><div class=""><br class=""></div><div class="">— Mike</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 13, 2018, at 8:27 AM, Dennis Shea <<a href="mailto:shea@ucar.edu" class="">shea@ucar.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Hello,<br class=""><br class=""></div>Once a function/subroutine is placed in a module, two 'things' must be done:<br class=""><br class=""></div>[1] A module must be compiled <b class="">prior</b> to its invocation by other program units<br class=""></div>[2] The program unit(s) invoking the function/subroutine contained within a module must apply the USE statement.<br class=""><br class=""></div>Attached are two fortran codes. Note the module is compiled 1st. <br class=""></div><div class="">Also, a side point, these could be in one file as long as the module is compiled prior to other units. <br class=""></div><div class=""><br class=""></div>%> gfortran toy_module.f90 test.toy_module.f90<br class=""></div>%> ./a.out<br class=""><br class=""> z=   6.8999996<br class=""><br class="">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br class=""><br class=""></div>Likely, you already know the above .<br class="">However, I thought it should be mentioned for others who might want to do something similar to what you are doing.<br class=""><br class="">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br class=""><br class=""></div>OK ... how to accommodate using a subroutine contained within a module from NCL.<br class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><br class="">[1] *THE* issue is that NCL's  WRAPIT  understands only f77 syntax. <br class="">[2] The  'USE' statement is f90. Further, it must/should appear even before an 'implicit none' statement.<br class=""></div><div class="">[3] WRAPIT would likely fail (untested if this is true) if the USE statement were encountered between the 'C NCLFORTSTART' and 'C NCLEND' delimiters.<br class=""></div><div class="">[4] My opinion is that you must add a 2nd subroutine ... a bit of a nuisance. <br class=""><br class="">---<br class="">In the following, the 77 and 90 suffixes are used to differentiate the program subroutines. They have no language meaning.<br class=""><br class="">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.<br class=""><br class=""></div><div class="">The 2nd subroutine is a valid program unit invokes the 'USE' statement. <br class=""><br class=""></div><div class="">Again, the USE statement could not be simply added to the 1st subroutine because WRAPIT would not know what to do with it!<br class=""></div><div class=""><br class="">C NCLFORTSTART<br class="">      subroutine<b class=""> mult77</b>(x,y,z)<br class=""></div><div class="">      implicit none<br class=""></div><div class="">      real x,y,z<br class="">C NCLEND<br class="">      call <b class="">mult90</b>(x,y,z)<br class="">      return<br class="">      end<br class="">C------------<br class="">      subroutine <b class="">mult90</b>(x,y,z)<br class="">      <b class="">use module_mult</b><br class="">      implicit none<br class="">      real, intent(in)  :: x,y<br class="">      real, intent(out) :: z<br class=""><br class="">      call <b class="">mult</b>(x,y,z)<br class="">      return<br class="">      end<br class=""><br class="">================<br class=""></div><div class="">Test the NCL call to invoke the module. Note the module is compiled 1st.<br class=""><br class="">%> <b class="">WRAPIT</b> toy_module.f90 toy_mult7790.f<br class=""></div><div class=""><br class=""></div><div class="">This will create '<b class="">toy_module.so</b>'<br class=""><br class=""></div><div class="">The following 'toy_test.ncl' contains:<br class=""><br class="">external TOY_MODULE "./toy_module.so"<br class=""><br class=""><br class="">   xNCL = 2.3<br class="">   yNCL = 3.0<br class="">   zNCL = 1e20<br class="">   <b class="">TOY_MODULE::mult77</b>(xNCL, yNCL, zNCL)  ; interface with f77 which calls f90<br class="">   print("zNCL="+zNCL)<br class=""></div><div class=""><br class="">=====<br class=""></div><div class="">%> ncl toy_test.ncl<br class=""><br class="">(0)    zNCL=6.9<br class=""><br class="">==================<br class=""></div><div class="">Hopefully, this is somewhat clear.<br class=""><br class=""></div><div class="">Good luck<br class=""></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, May 11, 2018 at 3:47 PM, Michael Toy <span dir="ltr" class=""><<a href="mailto:toy@ucar.edu" target="_blank" class="">toy@ucar.edu</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Hello,<div class=""><br class=""></div><div class="">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:</div><div class="">ncl 0> external MLT “./mult.so"</div><div class=""><br class=""></div><div class="">I get the error message:</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">warning:An error occurred loading the external file ./mult.so, file not loaded</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">./mult.so: undefined symbol: mult_</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">warning:error at line 0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div></div><div class=""><br class=""></div><div class="">I’m testing a simple subroutine which multiplies two numbers together.  My Fortran 90 code (mult.f90) is:</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">module module_mult</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">contains</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">subroutine mult(x,y,z)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">implicit none</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">real, intent(in) :: x,y</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">real, intent(out) :: z</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">z = x*y</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">end subroutine mult</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">end module module_mult</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255);min-height:15px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div></div><div class=""><br class=""></div><div class="">My “stub” file is:</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">C NCLFORTSTART</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">      subroutine mult(x,y,z)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">      real x,y,z</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">C NCLEND</span></div></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">When I run “WRAPIT mult.stub mult.f90” it seems to run successfully, and produces the file:</div><div class="">mult.so</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I am running NCL version 6.4.0 on the following system:</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Monaco;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Linux x86_64 x86_64 x86_64 GNU/Linux</span></div></div><div class=""><div class=""><br class="m_8796665186174588599webkit-block-placeholder"></div><div class="">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.</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Mike</div></div></div><br class="">______________________________<wbr class="">_________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/<wbr class="">mailman/listinfo/ncl-talk</a><br class="">
<br class=""></blockquote></div><br class=""></div>
<span id="cid:5446A18D-237B-40FB-BE1E-0528B48D85C6@fsl.noaa.gov"><toy_module.f90></span><span id="cid:360EB4D1-3BCC-4D70-8010-8D2B922246A8@fsl.noaa.gov"><test.toy_module.f90></span><span id="cid:6B965E3E-3A25-48A1-A6EF-B60BAD86A440@fsl.noaa.gov"><toy_mult7790.f></span><span id="cid:C2EC99C9-A44F-4439-AE93-39E48B1E5415@fsl.noaa.gov"><toy_test.ncl></span></div></blockquote></div><br class=""></div></body></html>