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 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
5
Views
8K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
1
Views
541
Replies
6
Views
1K
Replies
2
Views
2K
Replies
5
Views
13K
Replies
4
Views
11K
Replies
10
Views
25K
Back
Top