Re: output of allocatable array of strings==> blank?
- From: "dpb" <dpbozarth@xxxxxxxx>
- Date: 26 Jul 2006 07:42:11 -0700
Mike wrote:
Hi....
I had a subroutine which outputs array of strings, e.g. subheader, and
no_of_strings . Inside the subroutine, I declare subheader as
allocatable. I've checked the results in subroutine. It's ok.
However, they turn out blank in the main program. In main program, I
declare the subheader as a BIG_NUMBER of strings array.
(1) Why?
(2) could I declare as allocatable array of strings with no_of_strings
elements in main program? I worry about they will be blank. Or I
should write a function returning no_of_strings at first, then allocate
the subheader array, and then call the subroutine. That'll be
cumbersome.
You don't provide an example of the calling interface to see precisely,
but it sounds like the answer to (1) is probably because the
ALLOCATABLE array is created in the subroutine and therefore is local
to that routine.
For (2), the last option is "cleanest" from the standpoint of
determining the precise size of the array needed, but is, as you note,
less convenient operationally.
If you know (as I gather you don't :) ) the number a priori, you can
ALLOCATE the array of the right size and pass it, otherwise you can
create a large array as you presently are and pass it to the
subroutine. The operational problem is, you can't "shrink" that array
in the subroutine to the determined size so you would then either just
have to live w/ the full array and only use the populated portion in
the rest of the code logic or you could, on return, ALLOCATE a new
array based on the determined size and copy the elements to it and then
DEALLOCATE the working array. Probably not worth the effort as unless
the length is really large the amount of memory saved is likely to be
miniscule.
.
- Follow-Ups:
- Re: output of allocatable array of strings==> blank?
- From: Mike
- Re: output of allocatable array of strings==> blank?
- From: Rich Townsend
- Re: output of allocatable array of strings==> blank?
- References:
- Prev by Date: Re: g77 & gcc problem
- Next by Date: Re: g77 & gcc problem
- Previous by thread: output of allocatable array of strings==> blank?
- Next by thread: Re: output of allocatable array of strings==> blank?
- Index(es):
Relevant Pages
|