On 30 May 2003, Alvaro Fernandez wrote:
> Can an automatic array have the optional attribute? If so, does that mean it
> is only allocated inside an IF(PRESENT()) block?
>
> For example
>
> subroutine test(n,c)
> integer,intent(in) :: n
> real,intent(out),optional :: c(n)
>
> if (Present(c)) then
> ! c is allocated now?
> end if
>
>
> end subroutine test
>
>
>
> Alvaro Fernandez
Hi Alvaro,
I'm not sure what you're after, but if you want to allocate an automatic
array, it can't be a dummy argument.
Say you removed the OPTIONAL attribute and the PRESENT test. What would you
have? An assumed size array. So no allocation is going on. Adding OPTIONAL
and PRESENT doesn't change that.
If you want to allocate memory provisionally, use the ALLOCATABLE attribute
and do the ALLOCATE command explicitly inside an IF(PRESENT(...)) block. With
F95-compatible compilers, the deallocation will occur automatically when the
routine returns, IIRC. But it would be clearer to be explicit everywhere.
Ted
--
Ted Stern Applications Group
Cray Inc. office: 206-701-2182
411 First Avenue South, Suite 600 cell: 206-383-1049
Seattle, WA 98104-2860 FAX: 206-701-2500
Frango ut patefaciam -- I break that I may reveal
(The Paleontological Society motto, equally apropos for debugging)
|