Fortran Fortran, subroutine with allocatable, intent(out) array

Click For Summary
A user is facing challenges with managing dynamic arrays in a Fortran 77/90 program. They need to pass local dynamic arrays from a subroutine back to the main program but encounter crashes when attempting to allocate these arrays within the subroutine. The user has explored using common blocks but found them ineffective. They are considering interface blocks but are unsure of their functionality. A sample code snippet illustrates the issue, where the user tries to define an allocatable array in the main program and pass it to the subroutine. Suggestions from others include using the INTENT(INOUT) attribute for the subroutine parameter, although the user has already attempted this without success. The discussion highlights the complexities of handling allocatable arrays in Fortran and the need for effective communication between main programs and subroutines.
alyflex
Messages
9
Reaction score
0
Hi,

I have a rather large program written in fortran 77/90. In one of the subroutines a lot of local dynamic arrays are declared.

In order to make this program able to calculate more stuff, I need to bring these dynamic arrays back into the main program.

I have tried to define the arrays allocatable in the main program and then passing them on to the subroutine which sets them as allocatable. But when I allocate them in the subroutine the program crashes.

I have tried to do it with common blocks, but as far as I can see that's a dead end.

I have considered trying interface blocks, but I am still a bit uncertain as to how they work and if it is possible to do it with those.

Does anyone know a way to do this, I have been stuck with this problem for 2 days now, so any help would be much appreciated.

A short example of what I am trying to do

Main.f90
Program main
double complex, allocatable :: Vlm(:)
...
Call init_potential(input,output,Vlm)
...
End main



init_potential.f90
subroutine init_potential(input,output,Vlm)
double complex, allocatable, intent(out) :: Vlm(:)
...
allocate(Vlm(sizeofVlm))
...
end init_potential
 
Technology news on Phys.org
If you're allocating in the main program, have you tried defining it as INTENT(INOUT) in the subroutine?
 
minger said:
If you're allocating in the main program, have you tried defining it as INTENT(INOUT) in the subroutine?

I'm not allocating it in the main program, but I have tried it anyways, with no succes.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
11K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
13K