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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

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