Professor Diomar Cesar Lobao

Universidade Federal Fluminense-Volta Redonda, RJ, Brasil

Diomar Cesar


Dept. Ciências Exatas - Exact Science Dept.

Search

interface.f

c<html>
c<body>
c<pre>
      program interface
c
c      Simple demonstration of the INTERFACE structure
c      to permit the creation of FUNCTIONS returning
c      arrays rather than single values.
c
c      John Mahaffy   4/3/96
c
      implicit none
      integer i
      real, dimension(10) :: z,y,x=(/(i,i=1,10)/)
      data y /5*1,5*2/
c
c   interface block to permit a vector valued
c   function named saxpy
c
      interface saxpy
         function saxpy (a,x,y)
            real x(:),y(:),a
            real saxpy (size(x))
c
c    Declare x,y,a as input only to saxpy
c
c<a name="intent"><font color="FF0000">
            intent (in) x,y,a
c</font></a>
         end function saxpy
c
c<a name="end"><font color="FF0000">
      end interface
c</font></a>
c
c   Begin  Executable Statements
c
      z = saxpy(2.,x,y)
      write (*,2001)'a', 2.0
      write(*,2001) 'x', x
      write(*,2001) 'y', y
      write(*,*) ' For z = a x + y '
      write(*,2001) 'z',z
      stop
 2001 format (/, 1x,a1,' = ', 5f8.1,/, (5x,5f8.1))
      end
c
      function saxpy(a,x,y)
c
c   Multply all contents of an array "x" by the scalar "a"
c   then add the result to the array "y"
c
c   John Mahaffy    4/3/96
c
      implicit none
      real, dimension (:), intent(in):: x,y
      real saxpy (size(x))
      real a
      saxpy =  a*x + y
      return
      end
c</pre>
c</body>
c</html>
Skip to content