All the smart people have probably gone home, so I'll
try to give you some help on this.
Something really messed up the example: the "_"
for example, and it looks like the function is being
called recursively ???
Anyway the real problem is that the bounds may use
a function only in a situation that establishes the
size of a "dynamic" array--a dummy argument or in an
ALLOCATE statement, or something like that. It has
nothing to do with the fact that T is a component in
a type definition. And the Absoft message is pretty
strange.
Attached is an example with two such uses. I won't
attemp to fix this example. The attached programs
are F conformant as well as Fortran 95.
Alvaro Fernandez wrote:
> Can I do this?
>
>
>
> MODULE A
>
>
>
> IMPLICIT NONE
>
>
>
> PRIVATE
>
> PUBLIC :: NOOPTVARS_
>
>
>
>
>
> CONTAINS
>
>
>
> PURE FUNCTION NOOPTVARS() RESULT(F)
>
> INTEGER :: F
>
>
>
> F = NOOPTVARS_
>
>
>
> END FUNCTION NOOPTVARS
>
>
>
> END MODULE
>
>
>
> MODULE B
>
>
>
> USE A
>
> PRIVATE
>
> PUBLIC :: TEST_T
>
>
>
>
>
> TYPE :: TEST_T
>
> PRIVATE
>
> INTEGER :: T(NOOPTVARS())
>
> END TYPE TEST_T
>
>
>
>
>
> END MODULE B
>
>
>
> Absoft complains about NOOPTVARS; it says that because the component of
> the type is not a pointer, the array argument must be a constant. I was
> under the impression that a specification expression in Fortran 95 could
> be a pure function, and that the pure function could access a module
> variable. Was I wrong?
>
>
>
> Alvaro Fernandez
--
Walt Brainerd +1-877-355-6640 (voice & fax)
The Fortran Company +1-520-760-1397 (outside USA)
6025 N. Wilmot Road [log in to unmask]
Tucson, AZ 85750 USA http://www.fortran.com
module m
public :: ll
contains
pure function ll (n) result (rl)
integer, intent(in) :: n
integer :: rl
rl = ceiling(log(real(n)))
end function ll
end module m
program p
use m
implicit none
integer, dimension (1000) :: a = 1
real, dimension(:), allocatable :: x
allocate (x(2*ll(8)))
print *, "Size(x) = ", size(x)
call ss (a)
contains
subroutine ss (d)
integer, dimension(:), intent(in) :: d
integer, dimension(ll(size(d))) :: td
td = d (1:size(td))
print *, size(d), size(td), exp(6.0), exp(7.0)
end subroutine ss
end program p
|