Dear Friends
This code produces a runtime Access Violation Error when trying to construct an array which includes elements from an array-valued function
Moreover, If I define REAL kk(5), then kk=(/ 0.0, diag4(matrix) /) gives a compilation error 'Non-conformant array shapes infirst Rank of an array expression (5 and 2)' It seems that diag4(matrix) is interpreted as a real instead of as a 4 elements array.
Any sugestion?
Thank you in advance
Antonio
[color=green:96958e36ab]program bug
interface diag4 ! Extracts the diagonal from a 4x4 matrix (assumed to be square) function diag4(A) real,dimension(4,4),intent(in)::A real,dimension(4)::diag4 end function diag4 end interface
real matrix(4,4)
matrix=reshape((/1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16./),(/4,4/))
print*,diag4(matrix) ! this runs ok
print*,(/ 0.0, diag4(matrix) /) ! this leads to Access Violation Error
end program
function diag4(A) implicit none real,dimension(4,4),intent(in)::A real,dimension(4)::diag4 integer index do index=1,size(diag4) diag4(index)=A(index,index) enddo return end function [/color:96958e36ab]