<?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 Describe the contents of test in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088682#M123613</link>
    <description>&lt;P&gt;Describe the contents of test.opt2&lt;/P&gt;

&lt;P&gt;What is the value of res following fseek?&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2016 17:10:18 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2016-06-08T17:10:18Z</dc:date>
    <item>
      <title>Calls to fseek and ftell not working from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088679#M123610</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I'm writing some fortran code to read Nastran op2 files. I am using fseek and ftell to store the position of certain data blocks. This code is compiled to a DLL and called either from C++ code or C# code. When I call the function from c++ fseek/ftell works correctly, but when called from C# using PInvoke both return always -1. Am I missing something?&lt;/P&gt;

&lt;P&gt;C# code:&lt;/P&gt;

&lt;PRE class="brush:csharp;"&gt;[DllImport("mydll.dll", EntryPoint = "abcd", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
static extern int abcd([param: MarshalAs(UnmanagedType.I4)] Int32 dummyInt);&lt;/PRE&gt;

&lt;P&gt;int d1=abcd(4);&lt;/P&gt;

&lt;P&gt;F&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;ortran DLL code:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;function abcd(input) result(istat)
!DEC$ ATTRIBUTES ALIAS:'abcd' :: abcd
!DEC$ ATTRIBUTES DLLEXPORT :: abcd
!DEC$ ATTRIBUTES VALUE :: input

    use ifport
    integer,intent(in) :: input

    integer(4) istat, offset, ipos, posactual, res
    integer :: f
    
    f=1
    OPEN (UNIT=f, IOSTAT=ios, ERR=100, FILE='C:/test.op2', form='unformatted', STATUS='OLD', ACTION='READ')
    
    READ (f, END=100) res
    res=fseek(f, 10, 0)
    istat=ftell(f)

100 end function abcd&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 07:59:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088679#M123610</guid>
      <dc:creator>Ruben_P_</dc:creator>
      <dc:date>2016-06-08T07:59:25Z</dc:date>
    </item>
    <item>
      <title>First thing to resolve is if </title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088680#M123611</link>
      <description>&lt;P&gt;First thing to resolve is if&amp;nbsp; which function failed or if the C# interface is wrong.&lt;/P&gt;

&lt;P&gt;At line 11 above insert istat=999111&lt;BR /&gt;
	At line 14 above insert istat=999222&lt;BR /&gt;
	At line 18 above, insert istat=123456&lt;/P&gt;

&lt;P&gt;Then see what the return is to C#.&lt;BR /&gt;
	&lt;BR /&gt;
	999111 indicates&amp;nbsp;open fail,&lt;BR /&gt;
	999222 indicates read fail,&lt;BR /&gt;
	123456 indicates success (though value you do not want)&lt;BR /&gt;
	-1 indicates something wrong with interface.&lt;/P&gt;

&lt;P&gt;By the way, you will need to set in your own error codes at lines 11 and 14. Currently you would return uninitialized data.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 12:44:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088680#M123611</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-06-08T12:44:50Z</dc:date>
    </item>
    <item>
      <title>Thanks jimdempseyatthecove</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088681#M123612</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;jimdempseyatthecove for your response. I get 123456 as return, but my problem is that I cannot place the file pointer where I want using fseek. I have tried&amp;nbsp;INQUIRE(UNIT=f, POS=ipos) &amp;nbsp;but the position does not change after seeking 10 positions.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 15:05:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088681#M123612</guid>
      <dc:creator>Ruben_P_</dc:creator>
      <dc:date>2016-06-08T15:05:39Z</dc:date>
    </item>
    <item>
      <title>Describe the contents of test</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088682#M123613</link>
      <description>&lt;P&gt;Describe the contents of test.opt2&lt;/P&gt;

&lt;P&gt;What is the value of res following fseek?&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 17:10:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088682#M123613</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-06-08T17:10:18Z</dc:date>
    </item>
    <item>
      <title>The c# declares the procedure</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088683#M123614</link>
      <description>&lt;P&gt;The c# declares the procedure to be stdcall, but there is no visible corresponding declaration in the Fortran source.&lt;/P&gt;

&lt;P&gt;Which compiler are you using?&amp;nbsp; What compile options are you using?&amp;nbsp; If you are using Intel Fortran without some sort of compile option to specify stdcall - then you have a calling convention mismatch.&lt;/P&gt;

&lt;P&gt;I strongly recommend using the C interoperability features for Fortran 2003 for interoperating with other languages that know the relevant C calling convention.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 22:03:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088683#M123614</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2016-06-08T22:03:05Z</dc:date>
    </item>
    <item>
      <title>The value of res after line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088684#M123615</link>
      <description>&lt;P&gt;The value of res after line 16 is -1.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I have tried changing calling convention to cdecl in the C# dllimport or adding&amp;nbsp;!DEC$ATTRIBUTES STDCALL :: abcd to the fortran function, but the result is the same.&lt;/P&gt;

&lt;P&gt;The compiler is Intel Fortran 16.0 for Windows with these options:&lt;/P&gt;

&lt;P&gt;/nologo /debug:full /Od /warn:interfaces /module:"x64\Debug\\" /object:"x64\Debug\\" /Fd"x64\Debug\vc120.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 12:48:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088684#M123615</guid>
      <dc:creator>Ruben_P_</dc:creator>
      <dc:date>2016-06-09T12:48:37Z</dc:date>
    </item>
    <item>
      <title>Hi Ruben,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088686#M123617</link>
      <description>&lt;P&gt;Hi Ruben,&lt;/P&gt;

&lt;P&gt;We've had good success calling Fortran subroutines from C# for FEA result post processing and returning scalar and array values, so it is possible.&amp;nbsp; While you are working on the calling conventions, perhaps a comparison to the syntax we're using&amp;nbsp;would help.&amp;nbsp; Some differences that I see in our syntax is that in the C# code I only specified the DLL name, am using&amp;nbsp;"static extern void" to call the subroutine, and am passing arrays by reference&amp;nbsp;to return values from Fortran to C#, for example:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DllImport("myfortran.dll")]&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static extern void mysub1(ref int arraySize, int[] myIntArray, double[,] myRealArray);&lt;/P&gt;

&lt;P&gt;I think arrays are passed by reference by default ("ref" not needed), and passing scalars would need to have the "ref" statement added.&amp;nbsp; Does it make calling Fortran&amp;nbsp;any easier to use&amp;nbsp; "void" instead of returning an integer?&amp;nbsp; Could the integer be returned as one of the parameters?&lt;/P&gt;

&lt;P&gt;The syntax in the Fortran look similar, except we're using the "REFERENCE" attribute:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!DEC$ATTRIBUTES REFERENCE :: arraySize, myIntArray, myRealArray
&lt;/PRE&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
	Greg&lt;/P&gt;

&lt;PRE class="brush:csharp;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2016 16:58:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088686#M123617</guid>
      <dc:creator>Greg_T_</dc:creator>
      <dc:date>2016-06-09T16:58:17Z</dc:date>
    </item>
    <item>
      <title>I have tried C# to Fortran --</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088685#M123616</link>
      <description>&lt;P&gt;I have tried C# to Fortran -- you may as well take a long holiday in Nepal -- it is very difficult and leads to enormous frustration.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 13:51:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calls-to-fseek-and-ftell-not-working-from-C/m-p/1088685#M123616</guid>
      <dc:creator>JohnNichols</dc:creator>
      <dc:date>2016-06-09T13:51:03Z</dc:date>
    </item>
  </channel>
</rss>

