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.
 
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
2
Views
3K
Replies
4
Views
2K
Replies
1
Views
438
Replies
6
Views
1K
Replies
2
Views
2K
Replies
5
Views
13K
Replies
4
Views
11K
Replies
10
Views
25K
Back
Top