Fortran Increasing Size of FORTRAN Array without Reallocation

AI Thread Summary
In FORTRAN, once an array is allocated, its size cannot be increased without reallocation. The common method involves creating a temporary array to hold the existing values, deallocating the original array, and then reallocating a new array with the desired size. The example provided illustrates this process: first, a temporary array is allocated to store the original values, then the original array is deallocated, a new larger array is allocated, and finally, the values from the temporary array are copied back, with the new value added. Alternative methods for dynamic array resizing in FORTRAN are limited, and the discussed approach remains a standard practice.
Zahur
Messages
1
Reaction score
0
Is it possible to increase the size of an already allocated array in FORTRAN, without reallocation?
e.g. if in start A(3)=[4, 5, 6] and now I want something like A(4)=[4, 5, 6, 7].
Currently I am using a temporary array to do this

allocate(A(3))
A=(/4, 5, 6/)
allocate(temp(3))
temp=A
deallocate(A)
allocate(A(4))
A(1:3)=temp
A(4)=7


Or some other suggestion

Zahur
 
Technology news on Phys.org
I'm not a Fortran programmer, but some googling lead me to this. NB: I've not read the code, or tested it.
 
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
2
Views
3K
Replies
4
Views
2K
Replies
1
Views
492
Replies
6
Views
1K
Replies
2
Views
2K
Replies
5
Views
13K
Replies
4
Views
11K
Replies
10
Views
25K
Back
Top