I have created a derived type to access multi-dimensional arrays. With each array I associate a name in the array nm.
My problem consists how to fill the array values once I have allocated the memory.
An initial idea has been to use a multi-dimensional array as input. However I might run into memory problems if I store two copies as the arrays can be big. A better idea might be to pass a one-dimensional array with data along the first dimension and a specification on the position of the second and third dimensions where the data should reside.
I would value some suggestions on possibly better ways to fill arrays to derived types if there are people who have experience working with big data sets.
Type :: Multia
Character (Len=65) :: nm(3)
Real, Allocatable :: ma(:,:,:)
Real, Allocatable :: mb(:,:,:)
Real, Allocatable :: mc(:,:,:)
Contains
Procedure :: set
End Type Multia
Subroutine set (m, nm, u, i, j)
Class (Multia), Intent (InOut) :: m
Character (Len=65) :: nm
Real, Intent (In) :: u(:)
Integer, Intent (In) :: i, j
If (nm .e. (m% nm(1))) Then
m% ma(:,i,j) = u
Else If (nm .e. (m% nm(2))) Then
m% mb(:,i,j) = u
Else If (nm .e. (m% nm(3))) Then
m% mc(:,i,j) = u
End If
End Subroutine set
If your concern is about the duplication of arrays such as in
then Fortran 2003 offers the
move_alloc
intrinsic which moves the allocation (including the values) from one variable to another.called something like
From the notes (in Fortran 2008) of that intrinsic:
That is, the expectation is that there will be no copying of data or array temporaries.
This assumes, of course, that you can't just allocate the components of
m
and assign there directly.