<?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 Yes, certainly. There isn't in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998731#M103125</link>
    <description>&lt;P&gt;Yes, certainly. There isn't anything special about this. You don't even need an explicit interface for a function returning a non-polymorphic derived type. For example:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;function dtype (arg) bind(C)
type, bind(C) :: dtype_t
  integer i
end type dtype_t
type(dtype_t) :: dtype
integer :: arg
dtype%i = arg
return
end

program test
type, bind(C) :: dtype_t
  integer i
end type dtype_t
interface
  function dtype (arg) bind(C)
  import
  type(dtype_t) :: dtype
  integer :: arg
  end function dtype
end interface

type(dtype_t) :: local

local = dtype(3)
print *, local%i
end&lt;/PRE&gt;

&lt;P&gt;Some comments about this example. First, I didn't need to use an explicit interface, I could have just said:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type(dtype_t) :: dtype&lt;/PRE&gt;

&lt;P&gt;but I consider that bad form. Second, normally I would have put the function and the type in a module, but you say you are calling Java so the actual function would not be Fortran. Third, I added BIND(C) to indicate C-compatible calling and function returns. I am not sure what your Java wants here.&lt;/P&gt;

&lt;P&gt;I will comment that you need to make sure Java is returning the derived type in the same manner Fortran expects it. Without BIND(C), Fortran will pass a hidden first argument where the function value should be returned. With BIND(C), it won't do that for "small" return values, typically 8 bytes or less.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Sep 2014 14:50:08 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2014-09-19T14:50:08Z</dc:date>
    <item>
      <title>Function that returns a derived type...</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998730#M103124</link>
      <description>&lt;P&gt;I was wondering if there is anyway that a fortran function can be used to return a derived type. &amp;nbsp;I am building a fortran function (compiled into a DLL) that will be called by a JAVA program. &amp;nbsp;This generally works well, and returning regular variables (integers, reals, etc) is really very simple. &amp;nbsp;However, it would be nice to be able to return a 'class' in the form of a derived type. &amp;nbsp;There is a way to map classes to derived types as passed arguments, but I have not been able to find a way to make it work with a return from a function call.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 14:35:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998730#M103124</guid>
      <dc:creator>mountain_ike</dc:creator>
      <dc:date>2014-09-19T14:35:26Z</dc:date>
    </item>
    <item>
      <title>Yes, certainly. There isn't</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998731#M103125</link>
      <description>&lt;P&gt;Yes, certainly. There isn't anything special about this. You don't even need an explicit interface for a function returning a non-polymorphic derived type. For example:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;function dtype (arg) bind(C)
type, bind(C) :: dtype_t
  integer i
end type dtype_t
type(dtype_t) :: dtype
integer :: arg
dtype%i = arg
return
end

program test
type, bind(C) :: dtype_t
  integer i
end type dtype_t
interface
  function dtype (arg) bind(C)
  import
  type(dtype_t) :: dtype
  integer :: arg
  end function dtype
end interface

type(dtype_t) :: local

local = dtype(3)
print *, local%i
end&lt;/PRE&gt;

&lt;P&gt;Some comments about this example. First, I didn't need to use an explicit interface, I could have just said:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type(dtype_t) :: dtype&lt;/PRE&gt;

&lt;P&gt;but I consider that bad form. Second, normally I would have put the function and the type in a module, but you say you are calling Java so the actual function would not be Fortran. Third, I added BIND(C) to indicate C-compatible calling and function returns. I am not sure what your Java wants here.&lt;/P&gt;

&lt;P&gt;I will comment that you need to make sure Java is returning the derived type in the same manner Fortran expects it. Without BIND(C), Fortran will pass a hidden first argument where the function value should be returned. With BIND(C), it won't do that for "small" return values, typically 8 bytes or less.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 14:50:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998731#M103125</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-09-19T14:50:08Z</dc:date>
    </item>
    <item>
      <title>Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998732#M103126</link>
      <description>&lt;P&gt;Steve,&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;You are always to go-to guy! &amp;nbsp;This worked great in Fortran (although I needed to put the type declaration into a module). &amp;nbsp;Now the challenge will be to get JAVA to like it...&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 15:50:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998732#M103126</guid>
      <dc:creator>mountain_ike</dc:creator>
      <dc:date>2014-09-19T15:50:44Z</dc:date>
    </item>
    <item>
      <title>Having a derived type as a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998733#M103127</link>
      <description>&lt;P&gt;Having a derived type as a passed argument works fine. &amp;nbsp;The values get passed from JAVA into fortran with no problem. &amp;nbsp;However, using this implementation for returning a derived type from a function call is not so clean. &amp;nbsp;The passed arguments get garbled when they reach the fortran function, and the function crashes when it tries to write to the derived type variables (even with the bind(C) command). &amp;nbsp;This may be a new thread, and possibly not one for the fortran board...&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 16:31:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998733#M103127</guid>
      <dc:creator>mountain_ike</dc:creator>
      <dc:date>2014-09-19T16:31:53Z</dc:date>
    </item>
    <item>
      <title>Maybe you need to write the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998734#M103128</link>
      <description>&lt;P&gt;Maybe you need to write the Java function as one where the result is explicitly passed as an argument (making it into a subroutine). It could be that Java can't handle structure function results in a way compatible with Fortran.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 18:12:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998734#M103128</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-09-19T18:12:03Z</dc:date>
    </item>
    <item>
      <title>I'll look into it.  My</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998735#M103129</link>
      <description>&lt;P&gt;I'll look into it. &amp;nbsp;My application will require that the returns all be from the method, but maybe I can encapsulate the results internally before sending them out. &amp;nbsp;I've done that in C#...I was just hoping for an easy short cut!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 19:16:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998735#M103129</guid>
      <dc:creator>mountain_ike</dc:creator>
      <dc:date>2014-09-19T19:16:35Z</dc:date>
    </item>
    <item>
      <title>Is it possible that Java is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998736#M103130</link>
      <description>&lt;P&gt;Is it possible that Java is assuming STDCALL when you call it? This would corrupt the stack on return if there is a mismatch.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2014 19:26:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Function-that-returns-a-derived-type/m-p/998736#M103130</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-09-19T19:26:00Z</dc:date>
    </item>
  </channel>
</rss>

