Re: output of allocatable array of strings==> blank?




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.

.



Relevant Pages

  • output of allocatable array of strings==> blank?
    ... Inside the subroutine, I declare subheader as ... declare the subheader as a BIG_NUMBER of strings array. ... should write a function returning no_of_strings at first, then allocate ...
    (comp.lang.fortran)
  • Re: output of allocatable array of strings==> blank?
    ... Inside the subroutine, I declare subheader as ... declare the subheader as a BIG_NUMBER of strings array. ... ALLOCATE the array of the right size and pass it, ...
    (comp.lang.fortran)
  • Re: Compiler bug or illegal?
    ... an allocatable array. ... subroutine, you are not allowed to do anything inside the subroutine ... Even if it were in the same place, NEWSIZE remains undefined. ... ALLOCATE ) ...
    (comp.lang.fortran)
  • Re: Efficient arrays for artificial neural networks?
    ... This method is obviously unwieldy as the array will be very sparse. ... elemental function num_rowsresult ... subroutine set_row ... allocate %ii) ...
    (comp.lang.fortran)
  • User defined type with allocatable arrays
    ... and I allocate them like this in the main program ... Here nx*ny is the length of the array that I want to allocate...(it's ... %derxinto a subroutine and modify them.. ... I am supposed to have an explicit interface irrespective of ...
    (comp.lang.fortran)