<?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 Re: How to get the size of a vector in a subroutine. in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740099#M124</link>
    <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
After reading some Fortran 77 books, I found the interface solution for this problem.&lt;BR /&gt;&lt;BR /&gt;The code is attached.&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[plain]      program ex
        implicit none
        interface
          subroutine sub(a)
            implicit none
            real(kind=4),intent(in)::a(:)
          end subroutine sub
        end interface
        integer(kind=2),parameter::n=48
        real(kind=4)::ap(n)
        ap=1.2E0
        call sub(ap)
        stop
      end program ex

      subroutine sub(a)
        implicit none
        integer(kind=2)::n
        real(kind=4),intent(in)::a(:)
        intrinsic::size
        n=size(a)
        write(*,*) n
        return
      end subroutine sub
[/plain]&lt;/PRE&gt;
&lt;BR /&gt;Any comments on interface of Fortran 77 and module of Fortran 90 are highly appreciated!&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 21 Oct 2009 10:01:29 GMT</pubDate>
    <dc:creator>woshiwuxin</dc:creator>
    <dc:date>2009-10-21T10:01:29Z</dc:date>
    <item>
      <title>How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740097#M122</link>
      <description>Hi, everyone!&lt;BR /&gt;&lt;BR /&gt;I want to get the size of a vector in a subroutine, and the vector itself is as a subroutine argument.&lt;BR /&gt;&lt;BR /&gt;Below is a simple code:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[plain]      program ex
        implicit none
! The size of a vector, ap, is defined as 4 in the main program.
        integer(kind=2),parameter::n=4
        real(kind=4)::ap(n)
        ap=1.2E0
! Here I want to get the size of ap by calling sub(ap).
        call sub(ap)
        stop
      end program ex

! Sub should be able to find out the size of a, but it fails.
! Can anyone help me in this part?
      subroutine sub(a)
        implicit none
        real(kind=4),intent(in)::a(:)
        integer(kind=2)::n
        intrinsic::size
        n=size(a)
        write(*,*) n
        return
      end subroutine sub
[/plain]&lt;/PRE&gt;
In the above subroutine, sub(a), can not find out the size of a correctly. Can anyone help me on this?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance!&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Oct 2009 09:04:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740097#M122</guid>
      <dc:creator>woshiwuxin</dc:creator>
      <dc:date>2009-10-21T09:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740098#M123</link>
      <description>I have a solution for this problem by using module in Fortran 90. But for Fortran 77, an interface definition might be needed to solve the problem. I'm not very familiar with Fortran 77, so I could only provide the solution by using Fortran 90.&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[plain]      module tools
      contains
        subroutine sub(a)
          implicit none
          integer(kind=2)::dima
          real(kind=4),intent(in)::a(:)
          intrinsic::size
          dima=size(a)
          write(*,*) dima
          return
        end subroutine sub
      end module tools

      program ex
        use tools
        implicit none
        integer(kind=2),parameter::n=50
        real(kind=4)::ap(n)
        ap=1.2E0
        call sub(ap)
        stop
      end program ex
[/plain]&lt;/PRE&gt;
&lt;BR /&gt;I know some differences between Fortran 77 and 90, but I'm not very familiar with those details. Can the Fortran guru give me more infomation (references, books) on this topic?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Oct 2009 09:43:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740098#M123</guid>
      <dc:creator>woshiwuxin</dc:creator>
      <dc:date>2009-10-21T09:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740099#M124</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
After reading some Fortran 77 books, I found the interface solution for this problem.&lt;BR /&gt;&lt;BR /&gt;The code is attached.&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[plain]      program ex
        implicit none
        interface
          subroutine sub(a)
            implicit none
            real(kind=4),intent(in)::a(:)
          end subroutine sub
        end interface
        integer(kind=2),parameter::n=48
        real(kind=4)::ap(n)
        ap=1.2E0
        call sub(ap)
        stop
      end program ex

      subroutine sub(a)
        implicit none
        integer(kind=2)::n
        real(kind=4),intent(in)::a(:)
        intrinsic::size
        n=size(a)
        write(*,*) n
        return
      end subroutine sub
[/plain]&lt;/PRE&gt;
&lt;BR /&gt;Any comments on interface of Fortran 77 and module of Fortran 90 are highly appreciated!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Oct 2009 10:01:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740099#M124</guid>
      <dc:creator>woshiwuxin</dc:creator>
      <dc:date>2009-10-21T10:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740100#M125</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
My general rule is: if you think you have to write an INTERFACE block for a Fortran routine, you're doing it wrong. Instead, the routine you're calling should be in a MODULE or be an internal procedure. An example of the latter is as follows:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[plain]     program ex
        implicit none
        integer(kind=2),parameter::n=48
        real(kind=4)::ap(n)
        ap=1.2E0
        call sub(ap)
        stop

      contains

      subroutine sub(a)
        implicit none
        integer(kind=2)::n
        real(kind=4),intent(in)::a(:)
        intrinsic::size
        n=size(a)
        write(*,*) n
        return
      end subroutine sub

      end program ex

[/plain]&lt;/PRE&gt;
&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Oct 2009 13:48:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740100#M125</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-10-21T13:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740101#M126</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
Thank you, Steve!&lt;BR /&gt;&lt;BR /&gt;I was actually inspired by the approach that Intel employed in order to create the Fortran 95 interface for BLAS and LAPACK libraries. There're two *.f90 files, namely blas_interfaces.f90 and lapack_interfaces.f90, located in $MKLROOT/interfaces/blas95(or lapack95)/source. I observe the general structure for those two files is:&lt;BR /&gt;
&lt;PRE&gt;[plain]MODULE MODULE_NAME
INTERFACE INTERFACE_NAME
  PURE FUNCTION FUNCTION_NAME
  ...
  END FUNCTION FUNCTION_NAME
  ...
  PURE SUBROUTINE SUBROUTINE_NAME
  ...
  END SUBROUTINE SUBROUTINE_NAME
  ...
END INTERFACE INTERFACE_NAME
END MODULE MODULE_NAME[/plain]&lt;/PRE&gt;
It seems that using this approach one can establish an explicit interface between the MODULE, i.e. MODULE_NAME, and the associated external procedures, i.e. FUNCTION_NAME and SUBROUTINE_NAME, and let the compiler to check the consistency of the actual and dummy arguments. Is there a better way to make such explicit interfaces between a module and the relevant external procedures?&lt;BR /&gt;&lt;BR /&gt;One can, of course, put all those external procedures into the module just after "contains", which makes the external procedures like "internal procedures". However, this would increase the size of the module file and consume more compile time if one of the internal procedures is modified.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Oct 2009 16:48:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740101#M126</guid>
      <dc:creator>woshiwuxin</dc:creator>
      <dc:date>2009-10-21T16:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740102#M127</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;If you have an existing library of routines, and you want to provide explicit interfaces for them, then it is reasonable to do so as a separate module as is done in Intel MKL with the BLAS routines. You can do that too if you wish. It all depends on how you want your program to be organized. If you do have a separate interface block, you have to make sure that if you change the actual routine's declarations that you make the corresponding change in the interface - making the routines module or internal procedures eliminates this opportunity for error.&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Oct 2009 17:42:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740102#M127</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-10-21T17:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the size of a vector in a subroutine.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740103#M128</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/336209"&gt;Steve Lionel (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; &lt;BR /&gt;If you have an existing library of routines, and you want to provide explicit interfaces for them, then it is reasonable to do so as a separate module as is done in Intel MKL with the BLAS routines. You can do that too if you wish. It all depends on how you want your program to be organized. If you do have a separate interface block, you have to make sure that if you change the actual routine's declarations that you make the corresponding change in the interface - making the routines module or internal procedures eliminates this opportunity for error.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Thank you, Steve!&lt;BR /&gt;&lt;BR /&gt;Now I understand why people like module :-)&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Oct 2009 06:03:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-get-the-size-of-a-vector-in-a-subroutine/m-p/740103#M128</guid>
      <dc:creator>woshiwuxin</dc:creator>
      <dc:date>2009-10-22T06:03:55Z</dc:date>
    </item>
  </channel>
</rss>

