<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Learning to use ISO_C_BINDING in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847964#M64958</link>
    <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
There's no F95 way to do this. I can't think of a way to get what you want without going through the mess you wanted to avoid initially.&lt;BR /&gt;</description>
    <pubDate>Fri, 24 Jul 2009 20:26:40 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2009-07-24T20:26:40Z</dc:date>
    <item>
      <title>Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847957#M64951</link>
      <description>Can someone tell me why this code does not work? I'm trying to use C_PTR to allocation (and later to reallocate) arrays with rank &amp;gt; 1. &lt;BR /&gt;&lt;BR /&gt;Thanks, &lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;code starts here&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;!-------------------------------------------------------------&lt;BR /&gt;MODULE trans_settings&lt;BR /&gt;USE ISO_C_BINDING&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTEGER,PARAMETER::isize0=4&lt;BR /&gt;INTEGER,PARAMETER::rsize0=8&lt;BR /&gt;INTEGER,PARAMETER::isysize=4 !4 for 32bit, 8 for 64bit&lt;BR /&gt;END MODULE trans_settings&lt;BR /&gt;&lt;BR /&gt;!-------------------------------------------------------------&lt;BR /&gt;MODULE iso&lt;BR /&gt;USE trans_settings&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTERFACE &lt;BR /&gt;! cray pointer style&lt;BR /&gt;FUNCTION trans_malloc(size) RESULT(addr)&lt;BR /&gt;USE trans_settings&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTEGER(isize0),INTENT(IN)::size&lt;BR /&gt;INTEGER(isysize)::addr&lt;BR /&gt;END FUNCTION trans_malloc&lt;BR /&gt;! iso_c_binding style&lt;BR /&gt;FUNCTION tr_malloc(size) RESULT(addr)&lt;BR /&gt;USE trans_settings&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTEGER(isize0),INTENT(IN)::size&lt;BR /&gt;TYPE(C_PTR)::addr&lt;BR /&gt;END FUNCTION tr_malloc &lt;BR /&gt;END INTERFACE&lt;BR /&gt;END MODULE iso&lt;BR /&gt;&lt;BR /&gt;!-------------------------------------------------------------&lt;BR /&gt;PROGRAM main &lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;CALL testiso&lt;BR /&gt;END PROGRAM main&lt;BR /&gt;&lt;BR /&gt;!-------------------------------------------------------------&lt;BR /&gt;SUBROUTINE testiso&lt;BR /&gt;USE iso&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;&lt;BR /&gt;! iso_c_binding pointer style&lt;BR /&gt;REAL(rsize0),DIMENSION(:,:),POINTER::riso&lt;BR /&gt;TYPE(C_PTR)::cp &lt;BR /&gt;! Cray pointer style&lt;BR /&gt;REAL(rsize0),DIMENSION(1)::rv&lt;BR /&gt;POINTER(ptr_rv,rv) &lt;BR /&gt;&lt;BR /&gt;!locals&lt;BR /&gt;INTEGER(isize0)::i,j,irows=12,jcols=7&lt;BR /&gt;&lt;BR /&gt;! iso_c_binding pointer style&lt;BR /&gt;cp=tr_malloc(rsize0*irows*jcols)&lt;BR /&gt;CALL C_F_POINTER(cp,riso,[irows,jcols])&lt;BR /&gt;&lt;BR /&gt;! Cray pointer style&lt;BR /&gt;!ptr_rv=trans_malloc(rsize0*irows*jcols)&lt;BR /&gt;&lt;BR /&gt;DO j=1,jcols&lt;BR /&gt;DO i=1,irows&lt;BR /&gt;riso(i,j)=100*i+j&lt;BR /&gt;END DO&lt;BR /&gt;END DO&lt;BR /&gt;END SUBROUTINE testiso&lt;BR /&gt;&lt;BR /&gt;!-------------------------------------------------------------&lt;BR /&gt;! cray pointer style&lt;BR /&gt;FUNCTION trans_malloc(size) RESULT(addr)&lt;BR /&gt;!MALLOC wrapper&lt;BR /&gt;USE trans_settings&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTEGER(isize0),INTENT(IN)::size&lt;BR /&gt;INTEGER(isysize)::addr&lt;BR /&gt;addr=MALLOC(size)&lt;BR /&gt;END FUNCTION trans_malloc&lt;BR /&gt;&lt;BR /&gt;!-------------------------------------------------------------&lt;BR /&gt;! iso_c_binding pointer style&lt;BR /&gt;FUNCTION tr_malloc(size) RESULT(addr)&lt;BR /&gt;!MALLOC wrapper&lt;BR /&gt;USE trans_settings&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTEGER(isize0),INTENT(IN)::size&lt;BR /&gt;INTEGER(isysize)::iptr&lt;BR /&gt;TYPE(C_PTR)::addr&lt;BR /&gt;iptr=MALLOC(size)&lt;BR /&gt;!how do I achieve addr%ptr = iptr???&lt;BR /&gt;addr=C_LOC(iptr)&lt;BR /&gt;END FUNCTION tr_malloc&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2009 15:14:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847957#M64951</guid>
      <dc:creator>Daniel_P_4</dc:creator>
      <dc:date>2009-07-23T15:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847958#M64952</link>
      <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
This is wrong:&lt;BR /&gt;&lt;BR /&gt;addr=C_LOC(iptr)&lt;BR /&gt;&lt;BR /&gt;What you are getting here is the address of the routine local variable iptr, not its contents. The result is that the loop in the caller overwrites other storage.&lt;BR /&gt;&lt;BR /&gt;What you want instead is:&lt;BR /&gt;&lt;BR /&gt;addr = TRANSFER(iptr,addr)&lt;BR /&gt;&lt;BR /&gt;This effectively converts or casts iptr to the desired C_PTR type.&lt;BR /&gt;&lt;BR /&gt;I would also recommend using KIND constants from ISO_C_BINDING rather than hardcoding values.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2009 15:42:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847958#M64952</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-07-23T15:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847959#M64953</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/336209"&gt;Steve Lionel (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;This is wrong:&lt;BR /&gt;&lt;BR /&gt;addr=C_LOC(iptr)&lt;BR /&gt;&lt;BR /&gt;What you are getting here is the address of the routine local variable iptr, not its contents. The result is that the loop in the caller overwrites other storage.&lt;BR /&gt;&lt;BR /&gt;What you want instead is:&lt;BR /&gt;&lt;BR /&gt;addr = TRANSFER(iptr,addr)&lt;BR /&gt;&lt;BR /&gt;This effectively converts or casts iptr to the desired C_PTR type.&lt;BR /&gt;&lt;BR /&gt;I would also recommend using KIND constants from ISO_C_BINDING rather than hardcoding values.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
Steve, &lt;BR /&gt;&lt;BR /&gt;Thanks once again. &lt;BR /&gt;&lt;BR /&gt;That gets me across another hurdle. &lt;BR /&gt;&lt;BR /&gt;Are the operations inverses of each other?&lt;BR /&gt;&lt;BR /&gt;iptr = cptr%ptr&lt;BR /&gt;cptr = TRANSFER(iptr,cptr)&lt;BR /&gt;&lt;BR /&gt;Can you comment on the universality of ISO_C_BINDING across other, current Fortran compilers. My web searches seem to tell me this is F2003 standard. How universal can I expect it to be in F90 and F95? &lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2009 15:57:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847959#M64953</guid>
      <dc:creator>Daniel_P_4</dc:creator>
      <dc:date>2009-07-23T15:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847960#M64954</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
Note that C_PTR is a private type - you can't access its component. You can use TRANSFER both ways.&lt;BR /&gt;&lt;BR /&gt;As for "universality" - it is a F2003 feature, and implementors who have been serious about F2003 tend to already have at least this part of it implemented. Intel, IBM, Sun and Cray all support this, as do (I think) gfortran and g95. I have no idea what is happening on HP-UX. You'll have to research the other compilers you're interested in.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2009 16:11:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847960#M64954</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-07-23T16:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847961#M64955</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/336209"&gt;Steve Lionel (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;Note that C_PTR is a private type - you can't access its component. You can use TRANSFER both ways.&lt;BR /&gt;&lt;BR /&gt;As for "universality" - it is a F2003 feature, and implementors who have been serious about F2003 tend to already have at least this part of it implemented. Intel, IBM, Sun and Cray all support this, as do (I think) gfortran and g95. I have no idea what is happening on HP-UX. You'll have to research the other compilers you're interested in.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Steve,&lt;BR /&gt;&lt;BR /&gt;How silly is this idea? - to "homegrow" my own ISO_C_BINDING that might be universal across all the compilers? I guess making a C_PTR is really the easy part, eh? I think the C_F_POINTER() is the thing that is really crucial to me. &lt;BR /&gt;&lt;BR /&gt;Thanks for all the help, &lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Jul 2009 15:26:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847961#M64955</guid>
      <dc:creator>Daniel_P_4</dc:creator>
      <dc:date>2009-07-24T15:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847962#M64956</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
C_F_POINTER is one of the harder items - it requires knowledge of how the implementation represents pointers and also a way to get the compiler to relax restrictions on type, kind and rank matching. If you have that information, it is feasible, but not "universal" in that the implementation would vary by compiler.&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Jul 2009 15:42:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847962#M64956</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-07-24T15:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847963#M64957</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/336209"&gt;Steve Lionel (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;C_F_POINTER is one of the harder items - it requires knowledge of how the implementation represents pointers and also a way to get the compiler to relax restrictions on type, kind and rank matching. If you have that information, it is feasible, but not "universal" in that the implementation would vary by compiler.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
I looked at iso_c_binding.f90 and I sort of understand what I'm seeing. I was hoping to find something that didn't require F2003 statements, but I found IMPORT and BIND(C). &lt;BR /&gt;&lt;BR /&gt;I'd really like to use this C_PTR method if I can, since it clearly does what I want done, with some elegance. &lt;BR /&gt;&lt;BR /&gt;Is there another way without going through a subroutine interface? Basically, I have to (1) allocate space through a c-style pointer, and (2) be able to address this space in the form of rank1, rank2, or rank3 fortran arrays, and (3) resize the arrays if needed. &lt;BR /&gt;&lt;BR /&gt;Is there any F95 compliant way to make the c pointers talk to the f pointers? &lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Jul 2009 19:38:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847963#M64957</guid>
      <dc:creator>Daniel_P_4</dc:creator>
      <dc:date>2009-07-24T19:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Learning to use ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847964#M64958</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
There's no F95 way to do this. I can't think of a way to get what you want without going through the mess you wanted to avoid initially.&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Jul 2009 20:26:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Learning-to-use-ISO-C-BINDING/m-p/847964#M64958</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-07-24T20:26:40Z</dc:date>
    </item>
  </channel>
</rss>

