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

AI Thread 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
5
Views
8K
Replies
59
Views
11K
Replies
3
Views
2K
Replies
4
Views
4K
Replies
8
Views
3K
Replies
4
Views
2K
Replies
5
Views
13K
Back
Top