Hi,
I have a derived type which should have an 2-dimensional array as a component. However, the use of allocatable is not allowed in a derived type. The solution is to use a pointer.
The basic problem is as follows: I have to read a entry from a database and keep all the data as a single variable in the program. Along with the 2-dimensional data there are some header information.
Below is some example code from what I am trying to do. I think that there must be some better way of assiging the 2D data than below.
And that better way is what I am looking for 😃 I would appreciate any help, since this a problem that I often have.
Regards Jacques
program pointers
implicit none
integer :: i,j,ii
type main_type
integer :: n
real,dimension(:,:),pointer :: x
end type
real,allocatable,dimension(:,:) :: old,var,new
type(main_type) :: main
allocate(new(1,10))
do i=1,10
allocate(old(i,10))
do j = 1,10
new(i,j) = j
enddo
old = new
if (i==10) then;exit;endif
deallocate(new)
! increase size
allocate(new(i+1),10)
new = 0.0
do ii=1,i
new(ii,1:10)=old(ii,1:10)
enddo
deallocate(old)
enddo
main%x => new
deallocate(old)
deallocate(new)
end program pointers