From: mabrowning on
So, I have an array valued function declared in a module.

I'd like to pass this function to a subroutine in a different module.

MODULE fun
CONTAINS
FUNCTION func(t)
REAL :: t
REAL, DIMENSION(2,2)::func
func(1,1)=1*t
func(1,2)=2*t
func(2,1)=3*t
func(2,2)=4*t
END FUNCTION func
END MODULE fun

MODULE sub
INTERFACE
SUBROUTINE subr(A)
REAL, EXTERNAL :: A
END SUBROUTINE
END INTERFACE
END MODULE sub

SUBROUTINE subr(A)
REAL, EXTERNAL :: A
WRITE(*,*)A(1.0)
END SUBROUTINE subr

PROGRAM main
USE sub
USE fun
subr(func)
END PROGRAM main

This doesn't seem to work. Do I need a different type of interface?

Thanks!
From: mabrowning on
EDIT: should be

CALL subr(func) on the 2nd to last line.

I think it is a scoping issue. How do I tell the interface to expect
an array value from the external variable? It works just fine on a
scalar function.
From: Gary Scott on
mabrowning wrote:

> EDIT: should be
>
> CALL subr(func) on the 2nd to last line.
>
> I think it is a scoping issue. How do I tell the interface to expect
> an array value from the external variable? It works just fine on a
> scalar function.
I was thinking that the subroutine wasn't actually in the module as
indicated, although an interface definition for it is. I guess that is
sufficient.

--

Gary Scott
mailto:garylscott(a)sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
From: glen herrmannsfeldt on
mabrowning wrote:
> So, I have an array valued function declared in a module.

> I'd like to pass this function to a subroutine in a different module.

(snip)

> PROGRAM main
> USE sub
> USE fun
> subr(func)
> END PROGRAM main

You have to CALL a subroutine:

call subr(func)

-- glen

From: James Van Buskirk on
"mabrowning" <mabrowningrr(a)gmail.com> wrote in message
news:b6f04072-4f9a-414c-96c8-ef13499ff068(a)m73g2000hsh.googlegroups.com...

> So, I have an array valued function declared in a module.

> I'd like to pass this function to a subroutine in a different module.

If a dummy argument to a procedure has one of the characteristics
that require an explicit interface, you have to provide one either
via an interface block or the PROCEDURE statement:

C:\gfortran\clf\extern_array>type extern_array.f90
MODULE fun
CONTAINS
FUNCTION func(t)
REAL :: t
REAL, DIMENSION(2,2)::func
func(1,1)=1*t
func(1,2)=2*t
func(2,1)=3*t
func(2,2)=4*t
END FUNCTION func
END MODULE fun

MODULE sub
INTERFACE
SUBROUTINE subr(A)
REAL, EXTERNAL :: A
END SUBROUTINE
END INTERFACE
END MODULE sub

SUBROUTINE subr(A)
INTERFACE
FUNCTION A(t)
REAL :: t
REAL, DIMENSION(2,2) :: A
END FUNCTION
END INTERFACE
WRITE(*,*)A(1.0)
END SUBROUTINE subr

PROGRAM main
USE sub
USE fun
CALL subr(func)
END PROGRAM main

C:\gfortran\clf\extern_array>c:\gcc_equation\bin\x86_64-pc-mingw32-gfortran
exte
rn_array.f90 -oextern_array

C:\gfortran\clf\extern_array>extern_array
1.00000000 3.0000000 2.0000000 4.0000000

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end