<?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 Jim, in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962481#M95007</link>
    <description>&lt;P&gt;Jim,&lt;/P&gt;
&lt;P&gt;I can not get lbound and ubound values to be transferred in an interface. See the following example:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer*4 aa(1000), n&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; interface&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer*2 function&amp;nbsp; bb (a)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer, intent(in) :: a(:) ! assumed shape&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end function bb&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; end interface&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n =&amp;nbsp; bb (aa)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; write (*,*) 'bb(aa)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =',n&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; n =&amp;nbsp; bb (aa(5:33))&amp;nbsp; ; write (*,*) 'bb(aa(5:33)) =',n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer*2 function&amp;nbsp; bb (a)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer, intent(in) :: a(:) ! assumed shape&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'lbound', lbound (a, DIM=1)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'ubound', ubound (a, DIM=1)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'size&amp;nbsp; ', size (a)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bb = size (a) * kind (a)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end[/fortran]&lt;/P&gt;
&lt;P&gt;John&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Oct 2013 23:12:29 GMT</pubDate>
    <dc:creator>John_Campbell</dc:creator>
    <dc:date>2013-10-22T23:12:29Z</dc:date>
    <item>
      <title>Determining the length of an input matrix</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962476#M95002</link>
      <description>&lt;P&gt;Rather than specifically stating the length of an input matrix, how would one&lt;/P&gt;
&lt;P&gt;aumtomatically determine that from the calling sequence. I tried using Ubound, but the&lt;/P&gt;
&lt;P&gt;compiler doesn't like that, it say it is not determinable. And LEN is supposed to be&lt;/P&gt;
&lt;P&gt;for character strings.&lt;/P&gt;
&lt;P&gt;Here is a simple example;&lt;/P&gt;
&lt;P&gt;--------------------------------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;integer*1 a(200)&lt;/P&gt;
&lt;P&gt;integer*2 asum, sum&lt;/P&gt;
&lt;P&gt;asum=sum(a(3:24))&lt;/P&gt;
&lt;P&gt;integer*2 function &amp;nbsp;sum(a)&lt;/P&gt;
&lt;P&gt;integer*4 na(1)&lt;/P&gt;
&lt;P&gt;na=UBOUND(a) ! apparently not the right one&lt;/P&gt;
&lt;P&gt;sum=0&lt;/P&gt;
&lt;P&gt;do ia=1,na(1)&lt;/P&gt;
&lt;P&gt;sum=sum+a(ia)&lt;/P&gt;
&lt;P&gt;enddo&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;P&gt;--------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;I realize the FORTRAN already has a sum function, this is just an example.&lt;/P&gt;
&lt;P&gt;In the above case, its supposed to give a value of 22 for length, since 22 elements are&lt;/P&gt;
&lt;P&gt;being passed. I looked at the FORTRAN&amp;nbsp;HELP, but could not find the proper function, if one exists&lt;/P&gt;
&lt;P&gt;for getting the length of the passed array.&lt;/P&gt;
&lt;P&gt;This would of course get more complicated for 2 or 3 dimensional arrays, since the length would be passed to an array&lt;/P&gt;
&lt;P&gt;rather than a scalar.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 19:45:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962476#M95002</guid>
      <dc:creator>WSinc</dc:creator>
      <dc:date>2013-10-22T19:45:58Z</dc:date>
    </item>
    <item>
      <title>Hmm - thought I had replied</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962477#M95003</link>
      <description>&lt;P&gt;Hmm - thought I had replied to this.&lt;/P&gt;
&lt;P&gt;Your sample source is somewhat confusing - you never declare the argument a in sum and na comes from - where?&lt;/P&gt;
&lt;P&gt;There are generally two ways to get the bounds of a dummy argument. The modern way is to declare the argument as an assumed-shape array, with dimension (:). This requires that an explicit interface be visible to the caller, so the subroutine either has to be in a module or in a CONTAINS section. The older way is to pass the bound as a separate argument and use that in the declaration. For example:&lt;/P&gt;
&lt;P&gt;subroutine sub(a,n)&lt;BR /&gt;integer n&lt;BR /&gt;real a(n)&lt;/P&gt;
&lt;P&gt;With either of these you can use UBOUND (and LBOUND), and SIZE. SIZE gives you the number of elements, UBOUND gives the upper bound (which might not be the number of elements if the lower bound is not 1. Note that UBOUND by default returns an array of bounds, if you want a specific one add the DIM= argument.&lt;/P&gt;
&lt;P&gt;Perhaps you should pick up one of any number of books teaching "modern Fortran".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 21:15:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962477#M95003</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-10-22T21:15:51Z</dc:date>
    </item>
    <item>
      <title>integer*2 function  sum(a)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962478#M95004</link>
      <description>&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;integer*2 function&amp;nbsp; sum(a)&lt;BR /&gt;&amp;nbsp; implicit none&lt;BR /&gt;&amp;nbsp; integer, intent(in) :: a(:) ! assumed shape&lt;BR /&gt;&amp;nbsp; integer :: ia, sum&lt;BR /&gt;&amp;nbsp; sum=0&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do ia=lbound(a, DIM=1),ubound(a, DIM=1)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum=sum+a(ia)&lt;BR /&gt;&amp;nbsp; enddo&lt;BR /&gt;end&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;Then place that into a CONTAINS section of a module that you USE in your program.&lt;BR /&gt;Alternatively, you can place an interface to the function, into a module, or into the variable declaration of a procedure.&lt;/P&gt;
&lt;P&gt;[fortran]&lt;BR /&gt;interface&lt;BR /&gt;&amp;nbsp; integer*2 function&amp;nbsp; sum(a)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; implicit none&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer, intent(in) :: a(:) ! assumed shape&lt;BR /&gt;&amp;nbsp; end function sum&lt;BR /&gt;end interface&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 21:20:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962478#M95004</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-10-22T21:20:57Z</dc:date>
    </item>
    <item>
      <title>I will try the SIZE function.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962479#M95005</link>
      <description>&lt;P&gt;I will try the SIZE function. I have two books about Fortran, but they are not very helpful re this question.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 21:58:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962479#M95005</guid>
      <dc:creator>WSinc</dc:creator>
      <dc:date>2013-10-22T21:58:04Z</dc:date>
    </item>
    <item>
      <title>Maybe I got the wrong books?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962480#M95006</link>
      <description>&lt;P&gt;Maybe I got the wrong books? But it would be nice if they gave more examples.&lt;/P&gt;
&lt;P&gt;The FORTRAN help on-line is pretty sparse as well.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 22:31:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962480#M95006</guid>
      <dc:creator>WSinc</dc:creator>
      <dc:date>2013-10-22T22:31:13Z</dc:date>
    </item>
    <item>
      <title>Jim,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962481#M95007</link>
      <description>&lt;P&gt;Jim,&lt;/P&gt;
&lt;P&gt;I can not get lbound and ubound values to be transferred in an interface. See the following example:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer*4 aa(1000), n&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; interface&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer*2 function&amp;nbsp; bb (a)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer, intent(in) :: a(:) ! assumed shape&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end function bb&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; end interface&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n =&amp;nbsp; bb (aa)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; write (*,*) 'bb(aa)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =',n&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; n =&amp;nbsp; bb (aa(5:33))&amp;nbsp; ; write (*,*) 'bb(aa(5:33)) =',n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer*2 function&amp;nbsp; bb (a)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer, intent(in) :: a(:) ! assumed shape&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'lbound', lbound (a, DIM=1)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'ubound', ubound (a, DIM=1)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'size&amp;nbsp; ', size (a)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bb = size (a) * kind (a)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end[/fortran]&lt;/P&gt;
&lt;P&gt;John&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 23:12:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962481#M95007</guid>
      <dc:creator>John_Campbell</dc:creator>
      <dc:date>2013-10-22T23:12:29Z</dc:date>
    </item>
    <item>
      <title>Our documentation is meant as</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962482#M95008</link>
      <description>&lt;P&gt;Our documentation is meant as a reference, not a tutorial. That said, the description of UBOUND, at least, is far from sparse and includes examples.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 23:13:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962482#M95008</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-10-22T23:13:26Z</dc:date>
    </item>
    <item>
      <title>John, are you expecting that</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962483#M95009</link>
      <description>&lt;P&gt;John, are you expecting that you'll see bounds of 5:33 when you pass aa(5:33)? That's not how the language works. The bounds in the caller are not used - the lower bound starts at 1 unless declared otherwise and the upper bound is the extent.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 23:19:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962483#M95009</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-10-22T23:19:20Z</dc:date>
    </item>
    <item>
      <title>Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962484#M95010</link>
      <description>&lt;P&gt;Steve,&lt;/P&gt;
&lt;P&gt;Your response implies I am expecting too much of the language.&lt;BR /&gt;I understand that this is how the language presently works, but would it have been unreasonable to expect it to provide the bounds via an INTERFACE, rather than just the SIZE ?&lt;BR /&gt;The purpose of the INTERFACE was to improve on the F77 explicit bounds definition and provide the dimension information of an array. It has clearly stoped short on providing the bounds definition. In the past I wanted to find out this information for an array section and was disappointed with the result.&lt;/P&gt;
&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 23:53:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962484#M95010</guid>
      <dc:creator>John_Campbell</dc:creator>
      <dc:date>2013-10-22T23:53:18Z</dc:date>
    </item>
    <item>
      <title>Consider the general case -</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962485#M95011</link>
      <description>&lt;P&gt;Consider the general case - what if your procedure bb was called with the expression `aa(11:20) + aa(25:34)` as an argument.&amp;nbsp; What would the bounds inside the procedure be then?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could probably come up with some guidelines as to how it could work in some alternative Fortran universe, but I think they would end up being rather complicated, and in places counter-intuitive.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2013 00:06:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962485#M95011</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2013-10-23T00:06:44Z</dc:date>
    </item>
    <item>
      <title>Ian has it exactly right -</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962486#M95012</link>
      <description>&lt;P&gt;Ian has it exactly right - not to mention something like aa(11:20:3). The standard chose a definition that works for all possible manner of arguments. It makes it easier to write a procedure that takes array arguments as you always know what the lower bound is. If you have a situation where you need to preserve the bounds exactly, pass a pointer to a pointer.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2013 00:26:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Determining-the-length-of-an-input-matrix/m-p/962486#M95012</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-10-23T00:26:31Z</dc:date>
    </item>
  </channel>
</rss>

