I tried to print the diagonal of a matrix using pointer remapping in fortran. But i received an error. Any idea how to solve it? This is the program
program try
implicit none
integer , dimension (3,3), target :: a
a=reshape([1, 2, 3,4 ,5, 6, 7, 8, 9],[3,3])
real, pointer, dimension(:, :) :: matrix
real, pointer, dimension(:) :: diagonal, base
allocate (base(3*3))
matrix(1:3, 1:3) => base
diagonal => base(1:9:4)
print *, diagonal
end program try
I got this error:
unexpected data declaration statement. at line 9 and 10
(where i declare the pointers)
a = reshape....