<?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 It's the Fortran language in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140325#M136936</link>
    <description>&lt;P&gt;It's the Fortran language that does not allow you to do those things, not the compiler. A function reference isn't a data object that can be itself qualified with subobjects.&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2019 17:41:23 GMT</pubDate>
    <dc:creator>Steve_Lionel</dc:creator>
    <dc:date>2019-05-06T17:41:23Z</dc:date>
    <item>
      <title>Questions about fortran constructions</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140324#M136935</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;Please answer some questions about fortran construction&lt;/P&gt;&lt;P&gt;1. I have a function:&lt;/P&gt;
&lt;PRE class="brush:fortran; wrap-lines:false;"&gt;function GetArgumentName() result(Res)
&amp;nbsp; &amp;nbsp; character(250) Res 
&amp;nbsp; &amp;nbsp; ...
end function

&lt;/PRE&gt;

&lt;P&gt;How can i use substring of first character without declaring additional variables like this:&lt;/P&gt;
&lt;P&gt;GetArgumentName()(1:1)&lt;/P&gt;
&lt;P&gt;Compiler don't let me so&lt;/P&gt;
&lt;P&gt;2. I have a function:&lt;/P&gt;

&lt;PRE class="brush:; class-name:dark;"&gt;function GetArray()  result(Res)
  integer(1:100) Res

end function&lt;/PRE&gt;

&lt;P&gt;Why compiler do not let me use the following expression:&lt;/P&gt;
&lt;P&gt;n = 5 +&amp;nbsp;GetArray()(1)&lt;/P&gt;
&lt;P&gt;where i want to add to 5 the first element of the array?&lt;/P&gt;
&lt;P&gt;3. I have a type and a function:&lt;/P&gt;

&lt;PRE class="brush:fortran; wrap-lines:false;"&gt;type T_Point
 real X, Y
end type

function GetPoint() result(Res)
  type(T_Point) Res

end function&lt;/PRE&gt;

&lt;P&gt;Why compiler do not let me use the following expression:&lt;/P&gt;
&lt;P&gt;r = 5.0 +&amp;nbsp;GetPoint() % X&lt;/P&gt;
&lt;P&gt;Is it really necessary to declare auxiliary variables every time to execute these expressions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 17:27:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140324#M136935</guid>
      <dc:creator>Averkov__Igor</dc:creator>
      <dc:date>2019-05-06T17:27:54Z</dc:date>
    </item>
    <item>
      <title>It's the Fortran language</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140325#M136936</link>
      <description>&lt;P&gt;It's the Fortran language that does not allow you to do those things, not the compiler. A function reference isn't a data object that can be itself qualified with subobjects.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 17:41:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140325#M136936</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-05-06T17:41:23Z</dc:date>
    </item>
    <item>
      <title>Thank you very much Steve</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140326#M136937</link>
      <description>&lt;P&gt;Thank you very much Steve&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 19:21:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140326#M136937</guid>
      <dc:creator>Averkov__Igor</dc:creator>
      <dc:date>2019-05-06T19:21:07Z</dc:date>
    </item>
    <item>
      <title>Quote:Averkov, Igor wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140327#M136938</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Averkov, Igor wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;Please answer some questions about fortran construction ..&lt;/P&gt;&lt;P&gt;How can i use substring of first character without declaring additional variables like this:&lt;/P&gt;&lt;P&gt;GetArgumentName()(1:1)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;.. use the following expression:&lt;/P&gt;&lt;P&gt;n = 5 +&amp;nbsp;GetArray()(1)&lt;/P&gt;&lt;P&gt;r = 5.0 +&amp;nbsp;GetPoint() % X.&lt;/P&gt;&lt;P&gt;Is it really necessary to declare auxiliary variables every time to execute these expressions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As stated upthread, the Fortran standard does not allow your to use function references the way you want.&lt;/P&gt;&lt;P&gt;However look into ASSOCIATE construct:&amp;nbsp;https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-associate&lt;/P&gt;&lt;P&gt;ASSOCIATE can prove very valuable in situations where you need to associate objects and their subobjects or function results, see below.&amp;nbsp; While you're at it. you may want to look at BLOCK construct in Fortran&amp;nbsp;also:&amp;nbsp;https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-block&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;   type :: T_Point
      real :: x = 0.0
      real :: y = 0.0
   end type

   blk2: block
      integer :: n
      asc2: associate ( Array =&amp;gt; GetArray() )
         n = 5 + Array(1)
         print *, "Associate 2: n = ", n, "; expected is 47"
      end associate asc2
   end block blk2

   blk3: block
      real :: n
      asc3: associate ( Pt =&amp;gt; GetPoint() )
         n = 5.0 + Pt%X
         print *, "Associate 3: n = ", n, "; expected is 6.0"
      end associate asc3
   end block blk3

   asc1: associate ( ArgName =&amp;gt; GetArgumentName() )
      print *, "Associate 1: ArgName(1:1) = ", ArgName(1:1)
   end associate asc1

contains

   function GetArgumentName() result(ret)
      ! Function result
      character(len=250) :: ret
      ret = "Hello World!"
   end function

   function GetArray() result(Res)
      ! Function result
      integer :: Res(1:100)
      Res = 42
   end function

   function GetPoint() result(Res)
      ! Function result
      type(T_Point) :: Res
      Res%X = 1.0 ; Res%Y = 2.0
   end function

end
&lt;/PRE&gt;

&lt;P&gt;Upon execution, the first two work ok.&amp;nbsp; Intel Fortran compiler gives a compile time warning and then crashes at run-time&amp;nbsp;with the CHARACTER object result from a function, both a bug me thinks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:plain; class-name:dark;"&gt;C:\Temp&amp;gt;ifort /standard-semantics /warn:all /check:all /stand:f18 /warn:stderrors /traceback p.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64,
Version 19.1.0.056 Pre-Release Beta Build 20190321
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

ifort: NOTE: The Beta evaluation period for this product ends on 9-oct-2019 UTC.
p.f90(23): warning #5481: Variable ARGNAME has substring ending point 1 which is
greater than the variable length of 0
      print *, "Associate 1: ArgName(1:1) = ", ArgName(1:1)
-----------------------------------------------^
Microsoft (R) Incremental Linker Version 14.16.27027.1
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:p.exe
-subsystem:console
-incremental:no
p.obj

C:\Temp&amp;gt;p.exe
 Associate 2: n =  47 ; expected is 47
 Associate 3: n =  6.000000 ; expected is 6.0
forrtl: severe (408): fort: (12): Variable ARGNAME has substring ending point 1 which is
greater than the variable length of 0

Image              PC                Routine            Line        Source
p.exe              00007FF606D0C611  Unknown               Unknown  Unknown
p.exe              00007FF606D014C3  MAIN__                     23  p.f90
p.exe              00007FF606D50DE2  Unknown               Unknown  Unknown
p.exe              00007FF606D517B4  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFD429B37E4  Unknown               Unknown  Unknown
ntdll.dll          00007FFD42DECB81  Unknown               Unknown  Unknown

C:\Temp&amp;gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 23:21:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140327#M136938</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-05-06T23:21:00Z</dc:date>
    </item>
    <item>
      <title>@FortranFan Thanks for your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140328#M136939</link>
      <description>&lt;P&gt;@FortranFan Thanks for your comment. That feature is very elegant. However, here is another question: when one associates a function with a name, and the name is used in the association block, is the function going to be called every time, or is it called only once upon entry to the associate construct?&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 15:10:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140328#M136939</guid>
      <dc:creator>DataScientist</dc:creator>
      <dc:date>2019-05-07T15:10:00Z</dc:date>
    </item>
    <item>
      <title>Quote:A. King wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140329#M136940</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;A. King wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@FortranFan Thanks for your comment. That feature is very elegant. However, here is another question: when one associates a function with a name, and the name is used in the association block, is the function going to be called every time, or is it called only once upon entry to the associate construct?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In principle, the evaluation of the expression based on the function reference should only take place once during the association of the entity (e.g., Pt above) with the selector.&amp;nbsp; Note where the selector (e.g., GetPoint() above) is not a variable, as in say a function reference, or is otherwise not allowed to be in a variable definition context, the associating entity and any of its subobjects, if applicable, cannot be present in a variable definition context either, like on the left-hand side of an assignment.&amp;nbsp; Such requirements on the coder allow a compiler not to invoke&amp;nbsp;a function any further during the execution of the block i.e., the instructions between "associate(..)" and "end associate".&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 16:21:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140329#M136940</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-05-07T16:21:54Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;In principle, the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140330#M136941</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;In principle, the evaluation of the expression based on the function reference should only take place once during the association of the entity (e.g., Pt above) with the selector.&lt;/P&gt;&lt;P&gt;You also have available the now depreciated statement function.&lt;/P&gt;&lt;P&gt;Or you can write a Get function:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;type T_Point
 real X, Y
end type

function GetPoint() result(Res)
  type(T_Point) Res

end function

function GetX(p) result(Res)
  type(T_Point) :: p
  real :: Res
  Res = p%x
end function GetX

...

something = GetX(GetPoint())

&lt;/PRE&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 17:11:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Questions-about-fortran-constructions/m-p/1140330#M136941</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2019-05-10T17:11:54Z</dc:date>
    </item>
  </channel>
</rss>

