<div dir="ltr"><div>NCL is written in C.<br></div><div><br></div><div>[1] Passing *one* string C/NCL<==>Fortran is not a problem.</div><div>[2] Passing an <b>array of strings/character  </b>C<==>Fortran can be an issue.</div><div>Fortran does not allow variable length strings.</div><div><br></div><div>In the following, I changed the subroutine name: <b>mpr_match ==> match_mpr</b></div><div>In the NCL code change the 1st string array element fro 5 to 4 characters. See what happens.</div><div><br></div><div><b></b></div><div><b><br></b></div><div>C NCLFORTSTART<br>      subroutine <b>match_mpr</b>(ncvs,cvsid,obsid,istd)<br>      implicit none<br>      integer ncvs, istd<br>      character*(*) cvsid(ncvs)<br>      character*(*) obsid<br>C NCLEND<br>      integer  j, ls<br><br>       print *,  "ncvs=",ncvs<br>       print *,  "obsid=",obsid<br>       print *,  "cvsid=",cvsid    ! should print 'ncvs' values<br>       print *,  "istd=",istd<br>       print *,  "================"<br><br>       do j = 1, ncvs<br>         if(obsid.eq.cvsid(j)) then<br>            istd = j<br>         endif<br>         ls = len_trim(cvsid(j))<br>         print *, j,":", obsid,":", cvsid(j),":", istd,":",ls<br>       enddo<br>      end</div><div><br></div><div>I am sure there may be ways to work around the issue. Perhaps, make all string lengths 10 with, say, a $ terminator</div><div><br></div><div>  "F1234$    "</div><div>Then in the fortran code extract the string-subset with the '$' terminator. That is a wild guess.<br></div><div><br></div><div>[3] The Fortran 2003 standard introduced the <em>language-binding-spec</em> attribute, using the keyword <b>BIND</b>.</div><div>See: <a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-bind"><b>https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-bind</b></a></div><div><br></div><div>subroutine <b>match_mpr</b>(ncvs,cvsid,obsid,istd) BIND(C)</div><div><pre class="gmail-lang-c gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pln"> <b><span style="font-family:arial,sans-serif">use iso_c_binding</span></b></span><span style="font-family:arial,sans-serif"><b><span class="gmail-pun">,</span><span class="gmail-pln"> only</span></b><span class="gmail-pun">:</span></span><span class="gmail-pln"> ...</span><span class="gmail-pln">
 <span style="font-family:arial,sans-serif">implicit none<br><br></span></span></code></pre><pre class="gmail-lang-c gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pln"><span style="font-family:arial,sans-serif">however, I am not sure how one would be able to implement this from 'WRAPIT'<br><br></span></span></code></pre><pre class="gmail-lang-c gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-pln"><span style="font-family:arial,sans-serif">Good luck<br></span></span></code></pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 27, 2019 at 9:53 AM Ming Chen <<a href="mailto:chenming@ucar.edu">chenming@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF">
    <p>Hi Dennis,</p>
    <p>Thanks for the answer, which solves my problem. However, I am
      still curious why the Fortran code doesn't work and how I can make
      it work. I ask this because I heavily rely on Fortran to process
      some in-situ observations, which includes both numbers and
      strings. I hope to understand more about the combination of
      Fortran with NCL.<br>
    </p>
    <p>Thanks again.</p>
    <p>Ming<br>
    </p>
    <div class="gmail-m_-5616948966753294050moz-cite-prefix">On 8/26/19 6:04 PM, Dennis Shea wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>No need for fortran code.</div>
        <div><br>
        </div>
        <div><a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/get1Dindex.shtml" target="_blank"><b>https://www.ncl.ucar.edu/Document/Functions/Contributed/get1Dindex.shtml</b></a></div>
        <div><br>
        </div>
        <div>========================</div>
        <div>            ;        0             1            <b>2</b>           
          3            4               <== <br>
        </div>
        <div>  cvsid = (/"76373", "76612", "<b>XRKF</b>", "PRUK",
          "DENB"/)<br>
            obsid = (/"<b>XRKF</b>", "76737", "BSRK"/)<br>
          <br>
            i = <b>get1Dindex</b>(cvsid, obsid)<br>
            print(i)<br>
            print("====")<br>
          <br>
            ni = num(.not.ismissing(i))<br>
            print("ni="+ni)<br>
            print("====")</div>
        <div>==================================<br>
        </div>
        <div>Variable: i<br>
          Type: integer<br>
          Total Size: 12 bytes<br>
                      3 values<br>
          Number of Dimensions: 1<br>
          Dimensions and sizes: [3]<br>
          Coordinates: <br>
          Number Of Attributes: 3<br>
            _FillValue : -2147483647<br>
            index_info : Out of nWant=3 : multiple index occurrences=0<br>
            nMultInd : 0</div>
        <div><br>
        </div>
        <div>(0) <b>2</b><br>
        </div>
        <div>(1) -2147483647   <=== No match for <b>76737</b></div>
        <div>(2) -2147483647   <=== No match for <b>BSRK</b><br>
          (0) ====<br>
          (0) ni=<b>1                 </b><=== only one match<br>
          (0) ====<br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Mon, Aug 26, 2019 at 5:30
          PM Ming Chen via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear
          All,<br>
          <br>
          I am trying to match two sets of in-situ observations. First
          of all, I <br>
          need to match stations between the two sets of data. However,
          my scrip <br>
          failed with the error message below:<br>
          <br>
          fatal:Argument type mismatch on argument (1) of (mpr_match)
          can not coerce<br>
          fatal:["Execute.c":8637]:Execute: Error occurred at or near
          line 19 in <br>
          file test4.ncl<br>
          <br>
          I attach the sample ncl script and fortran code. Any help will
          be highly <br>
          appreciated.<br>
          <br>
          Ming<br>
          <br>
          <br>
          _______________________________________________<br>
          ncl-talk mailing list<br>
          <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
          List instructions, subscriber options, unsubscribe:<br>
          <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote>
      </div>
    </blockquote>
  </div>

</blockquote></div>