At 19:51 08-09-98 +0100, you wrote:
>The compiler HP-UX FORTRAN 90 gives me the following error:
>
> program TEST
> internal function HEVAL
>Error 294 : Function HEVAL has not been given a result value
>
>but in the definition of the function Heval I have the clause result
>with the corresponding definition in the header of the function.
>Can someone tell what I am doing wrong?
>
>Thanks in advance,
>
>David
>
>-----------------------------------
>
>program test
>
> type Smatrix
> integer :: ne
> integer ,pointer :: i(:),j(:)
> real(kind=8),pointer :: z(:)
> end type Smatrix
>
> integer,parameter :: n=10
> real(kind=8),allocatable :: x(:)
> type(Smatrix) :: H
>
> allocate(H%i(n),H%j(n),H%z(n),x(n))
> x=(/(real(i),i=1,n)/)
> H=Heval(x)
> deallocate(H%i,H%j,H%z,x)
> stop 'end'
>
>contains
>
> function Heval(x) result(H)
> type(Smatrix) :: H
> real(kind=8) :: x(:)
> integer :: i,n
>
> n =Size(x)
> H%i=(/(i,i=1,n)/)
> H%j=(/(i,i=1,n)/)
> H%z=x
>
> return
> end function Heval
>end program test
>
>--------------------------------------
David,
I think the error message comes from the fact, that
in the function you are assigning values to a pointer object
that is not allocated.
With your program two compilers did compile and link, but gave
runtime errors
1. Stack error
2. Access violation
I append modified program producing errors and a version with subroutine
that works OK.
In this program the object H is correctly allocated.
Y buena suerte !
program test
implicit none
integer :: i, st
integer, parameter :: dp = selected_real_kind(10)
type Smatrix
integer :: ne
integer , pointer :: i(:),j(:)
real(kind=dp), pointer :: z(:)
end type Smatrix
integer,parameter :: n = 10
real(kind=dp),allocatable :: x(:)
type(Smatrix) :: H
allocate(H%i(n),H%j(n),H%z(n), stat=st)
print*, "stat H: ", st
allocate( x(n), stat=st )
print*, "stat X: ", st
x = (/ (real(i),i=1,n) /)
H = Heval(x)
print*, "I: ", associated(H%I)
print*, "J: ", associated(H%J)
print*, "Z: ", associated(H%Z)
print*, "X: ", allocated( X )
deallocate( x, stat=st)
print*, "stat X: ", st
deallocate(H%i,H%j,H%z, stat=st)
print*, "stat H: ", st
stop 'end'
contains
function Heval(x) result(H)
type(Smatrix) :: H
real(kind=dp) :: x(:)
integer :: i, n
n = Size(x)
H%ne = n ! JvO 1998-09-09
H%i=(/(i,i=1,n)/)
H%j=(/(i,i=1,n)/)
H%z=x
return
end function Heval
end program test
program test
implicit none
integer :: i, st
integer, parameter :: dp = selected_real_kind(10)
type Smatrix
integer :: ne
integer , pointer :: i(:),j(:)
real(kind=dp), pointer :: z(:)
end type Smatrix
integer,parameter :: n = 10
real(kind=dp),allocatable :: x(:)
type(Smatrix) :: H
allocate(H%i(n),H%j(n),H%z(n), stat=st)
print*, "stat H: ", st
allocate( x(n), stat=st )
print*, "stat X: ", st
x = (/ (real(i),i=1,n) /)
call Heval(x)
print*, "I: ", associated(H%I)
print*, "J: ", associated(H%J)
print*, "Z: ", associated(H%Z)
print*, "X: ", allocated( X )
deallocate( x, stat=st)
print*, "stat X: ", st
deallocate(H%i,H%j,H%z, stat=st)
print*, "stat H: ", st
stop 'end'
contains
subroutine Heval(x) ! result(H)
! type(Smatrix) :: H
real(kind=dp) :: x(:)
integer :: i, n
n = Size(x)
H%ne = n ! JvO 1998-09-09
H%i=(/(i,i=1,n)/)
H%j=(/(i,i=1,n)/)
H%z=x
return
end subroutine Heval
end program test
---
Meilleures Salutations,
Best Greetings,
/---
Jan van Oosterwijk
Computing Centre
Delft University of Technology
Postbus 354
2600 AJ Delft
Netherlands / Pays Bas
Phone: +31 15 278 50 17
Fax: +31 15 278 37 87
|