<?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 Accessing fortran module data from c in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776519#M25360</link>
    <description>Also, how do I access a 2d array such as:&lt;DIV&gt;&lt;PRE&gt;
  TYPE mytype
    INTEGER :: sz
    INTEGER, POINTER :: j(:)
    INTEGER, POINTER :: k(:)
    INTEGER, POINTER :: m(:,:)&lt;/PRE&gt;&lt;PRE&gt;  END TYPE mytype&lt;/PRE&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 30 Jul 2012 19:40:33 GMT</pubDate>
    <dc:creator>Lance_Larsen</dc:creator>
    <dc:date>2012-07-30T19:40:33Z</dc:date>
    <item>
      <title>Accessing fortran module data from c</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776518#M25359</link>
      <description>I have a program where I need to access data in a fortran module from c.As in example, in the following module, I need to access "mighty":&lt;BR /&gt;&lt;BR /&gt;

&lt;PRE&gt;MODULE testm
  TYPE mytype
    INTEGER :: sz
    INTEGER, POINTER :: j(:)
    INTEGER, POINTER :: k(:)
  END TYPE mytype
  
  TYPE(mytype), SAVE :: mighty
CONTAINS
  SUBROUTINE init()
    mighty%sz = 3
    ALLOCATE(mighty%j(mighty%sz))
    mighty%j = (/ 1,2,3 /)
    ALLOCATE(mighty%k(mighty%sz))
    mighty%k = (/ 4,5,6 /)    
  END SUBROUTINE INIT
END MODULE testm
&lt;/PRE&gt;&lt;BR /&gt;

I am using intel fortran and MSVC. The intel fortran documentation gave some indicationof how to access fortran module data from c, but seemed to leave some holes. I didn'tsee info on how to access pointers contained in types. I created a c header file with the following:&lt;BR /&gt;&lt;BR /&gt;

&lt;PRE&gt;extern struct {
  int sz;
  int* j;
  int* k;
} TESTM_mp_MIGHTY;
&lt;/PRE&gt;&lt;BR /&gt;

I can access the 'sz' value and the 'j' array correctly from TESTM_mp_MIGHTY, but it lookslike my 'k' pointer is no good. In essence, anything following the 'j' pointer seems to beincorrect. Can anyone tell me what I need to do to access pointers in structures correctly so that the values that follow are accessed correctly?</description>
      <pubDate>Mon, 30 Jul 2012 19:38:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776518#M25359</guid>
      <dc:creator>Lance_Larsen</dc:creator>
      <dc:date>2012-07-30T19:38:21Z</dc:date>
    </item>
    <item>
      <title>Accessing fortran module data from c</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776519#M25360</link>
      <description>Also, how do I access a 2d array such as:&lt;DIV&gt;&lt;PRE&gt;
  TYPE mytype
    INTEGER :: sz
    INTEGER, POINTER :: j(:)
    INTEGER, POINTER :: k(:)
    INTEGER, POINTER :: m(:,:)&lt;/PRE&gt;&lt;PRE&gt;  END TYPE mytype&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 Jul 2012 19:40:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776519#M25360</guid>
      <dc:creator>Lance_Larsen</dc:creator>
      <dc:date>2012-07-30T19:40:33Z</dc:date>
    </item>
    <item>
      <title>Accessing fortran module data from c</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776520#M25361</link>
      <description>You can't do this. Fortran pointers are not the same as C pointers.&lt;BR /&gt;&lt;BR /&gt;What you can do is have components in your derived type of TYPE(C_PTR) where the definition of C_PTR comes from module ISO_C_BINDING. You can then use C_LOC(array) to assign values to these components. A C_PTR is interoperable with a C pointer.&lt;BR /&gt;&lt;BR /&gt;For arrays, you need to be aware that C indexes starting at zero and is row-major. C doesn't have the equivalent of Fortran multidimensional arrays - in C, multidimensional arrays are "arrays of pointers to arrays".</description>
      <pubDate>Mon, 30 Jul 2012 20:40:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Accessing-fortran-module-data-from-c/m-p/776520#M25361</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-07-30T20:40:43Z</dc:date>
    </item>
  </channel>
</rss>

