Subcategory: None · Core

Reshape

It’s often required to reshape arrays used in Fortran code. This can be achieved in several ways, the most naive of which is to use hand-coded do loops. This is not recommended as it is error-prone and verbose. A better approach is to use the intrinsic reshape function, which is concise and clear.

The most efficient way to reshape arrays is to use pointers. This is a more advanced approach and care must be taken to ensure that (a) the original array is not deallocated while the pointer is still in use and (b) you are aware that modifications to the “reshaped” array will modify the original array and vice versa because they share the same memory.

Read More