Increasing Size of FORTRAN Array without Reallocation

In summary, there are a few different methods for increasing the size of a FORTRAN array without reallocating. These include using the ALLOCATABLE attribute, RESHAPE function, and TRANSFER function. It is also possible to increase the size of an array without losing data by using these methods. The maximum size limit for a FORTRAN array varies depending on the compiler, but can be increased by changing settings or using alternative methods. However, it is not possible to decrease the size of a FORTRAN array without reallocation, which can have potential drawbacks such as inefficient memory usage and slower performance. It is important to carefully consider the needs of the program when choosing a method for increasing array size.
  • #1
Zahur
1
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
  • #2
I'm not a Fortran programmer, but some googling lead me to this. NB: I've not read the code, or tested it.
 

1. How can I increase the size of a FORTRAN array without reallocating?

There are a few different ways to increase the size of a FORTRAN array without reallocating. One option is to use the ALLOCATABLE attribute when declaring the array, which allows for dynamic allocation of memory. Another option is to use the RESHAPE function to create a new array with a larger size. Additionally, you can use the TRANSFER function to move the data from the old array to a new, larger array.

2. Can I increase the size of a FORTRAN array without losing data?

Yes, it is possible to increase the size of a FORTRAN array without losing data. Using the ALLOCATABLE attribute, RESHAPE function, or TRANSFER function will preserve the data in the array while increasing its size.

3. What is the maximum size limit for a FORTRAN array?

The maximum size limit for a FORTRAN array depends on the specific compiler being used. However, most modern compilers have a default maximum size limit of several billion elements for a single array. This can be increased by changing compiler settings or using alternative methods for increasing array size.

4. Can I decrease the size of a FORTRAN array without reallocating?

No, it is not possible to decrease the size of a FORTRAN array without reallocating. Once an array has been allocated, its size cannot be changed without using reallocation methods such as DEALLOCATE and ALLOCATE.

5. What are the potential drawbacks of increasing the size of a FORTRAN array without reallocation?

One potential drawback is that it can lead to inefficient memory usage if the array is not being fully utilized. Additionally, using dynamic allocation methods such as ALLOCATABLE can result in slower performance compared to using static arrays. It is important to carefully consider the needs of your program and choose the appropriate method for increasing array size.

Similar threads

  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
6
Views
778
  • Programming and Computer Science
Replies
5
Views
7K
  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
13
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
7
Replies
235
Views
9K
Back
Top