by michaelmet » Thu, 12 Mar 2009 22:32:37
> real*8 >: t,f,o
> >d type TFO1
> gt;nd module ff
> nterface
> > FUNCTION f>(a,b)
> use>ff
> implicit none
> type(TFO1),>dimension(:), intent(in) :: a,b
> type(TFO1> ::fd!dimension(size>arr_dt)) :: fd
>>end module f>nc
>
> R>GRAM test
> se ff
> se func
> > type(tfo1), DIMENSION(:),a>locatable::a,b,r
> allocat>(a(3),b(3),r(3))
> a%> = (/ 1., 2., 3./)
> gt;b%f = (/ 2., 2.,>2. /)
> r%f = 2.>*fd(b,a)%f
> P>IN> *, r%f
> deall>cate(a,b,r)
>> end PROGRAM test
>
> FUNCT>ON fd(c, d)
> use ff
> ty>e(Tfo1), DIMENSION(:) :: c, d
> type(tfo1),dimension(size(c>)::fd
> fd%f > c%f*d%f (or some more useful functio of c an> d)
> END FUNCTION fd
> Th>s program was compiled using ifort intel fortran
> david@katru:~$ ifort >est.f90
> fortcom: Error: test.f90, line>26: The leftmost part-ref>in a data-ref
> can>not be a function reference. [FD]
> r%f = 2.0*fd(b,a)%f
> ----->----------^
> fo>tcom: Error: test.f90, li>e 26: The structure->ame is invalid or is
> missing. [FD]
> gt;> r%f = 2.0*fd(b,a)%f
> ----------------^
> compilation aborted for >est.f90 (code 1)
>
> What could be possible reaseon for this? r does someone know any
> other way of writing this program?
Well, the message is to be believed: you cannot reference a component
of a function result of derived type. A version of your code that
gives what you appear to want is:
module ff
type tfo1
real*8 :: t,f,o
end type TFO1
end module ff
module func
contains
FUNCTION fd(c, d)
use ff
type(Tfo1), DIMENSION(:) :: c, d
type(tfo1), dimension(size(c))::fd
fd%f = c%f*d%f ! (or some more useful functio of c and
d)
END FUNCTION fd
end module func
PROGRAM test
use ff
use func
type(tfo1), DIMENSION(:),allocatable::a,b,r
allocate(a(3),b(3),r(3))
a%f = (/ 1., 2., 3./)
b%f = (/ 2., 2., 2. /)
r = fd(b,a)
r%f = 2.0 * r%f
PRINT *, r%f
deallocate(a,b,r)
end PROGRAM test
where having fd in a module ensures that the interface is correct.
Note, however, that in this form you are passing around the components
t and o that are not defined.
HTH
Mike Metcalf