Passing an allocatable array to a subroutine
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Passing an allocatable array to a subroutine         


Author: deadpickle
Date: Sep 15, 2008 13:31

I have been trying to pass an allocatable array around to a few
subroutines. I am getting a bounds error which means that the array is
not allocated. It might be better to create a little program:

!The main program

Program main
Implicit none

real, dimension(:,:), allocatable :: array

call sub1 (array)
call sub2 (array)

end program main

subroutine sub1 (array)

real, allocatable, dimension(:,:), intent(out) :: array
integer :: j

j = 1

allocate(array(j,3)

array(1,3) = 1.1

end subroutine sub1

subroutine sub2 (array)

real, allocatable, dimension(:,:), intent(inout) :: array
Show full article (0.91Kb)
2 Comments
Re: Passing an allocatable array to a subroutine         


Author: fj
Date: Sep 15, 2008 13:54

On 15 sep, 22:31, deadpickle gmail.com> wrote:
> I have been trying to pass an allocatable array around to a few
> subroutines. I am getting a bounds error which means that the array is
> not allocated. It might be better to create a little program:
>
> !The main program
>
> Program main
> Implicit none
>
> real, dimension(:,:), allocatable :: array
>
> call sub1 (array)
> call sub2 (array)
>
> end program main
>
> subroutine sub1 (array)
>
> real, allocatable, dimension(:,:), intent(out) :: array ...
Show full article (1.89Kb)
no comments
Re: Passing an allocatable array to a subroutine         


Author: nospam
Date: Sep 15, 2008 13:58

deadpickle gmail.com> wrote:
> I have been trying to pass an allocatable array around to a few
> subroutines.....

This is one of a class of frequently asked questions that all have the
same answer, namely that what you are doing requires an explicit
interface. There are many things that require an explicit interface -
pretty much anything that was added in f90 or later and has anything to
do with procedure arguments.

I consider it strongly recommended practice to just routinely provide an
explicit interface for all procedures. That way you don't have to
memorize the list of things that require it. Besides, there are other
side benefits of having explicit interfaces (such as better argument
agreement checking).

In your particular case, the feature in question is the allocatable
dummy argument (which isn't actually standard until f95+TR or f2003,
though most current compilers do now support the TR). Allocatable actual
arguments don't trigger the requirement, but allocatable dummy arguments
do.
Show full article (1.60Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
how to join array into arraycomp.lang.perl.misc ·
Re: Does passing an array make a copy of the array in memory?comp.lang.labview ·