gcc - Checking all elements of array for a logical condition in fortran -
i want check rows of array logical condition. used function all
described in gnu gcc guide https://gcc.gnu.org/onlinedocs/gfortran/all.html
here sample code:
program test3 implicit none real, allocatable, dimension (:,:) :: mat1 integer :: i,j,k,r logical :: lg r=3 allocate(mat1(r,r)) mat1=transpose( reshape( (/-1,-2,-3,-4,-5,-6,-7,-8,-9/), (/3,3/))) lg=all (abs(mat1)<10,1) write (*,*) lg end program
in program, want check whether absolute value of elements along rows less 10. getting error
lg=all (abs(mat1)<10,1) error: incompatible ranks 0 , 1 in assignment
any idea error or how check?
error: incompatible ranks 0 , 1 in assignment
means trying assign rank-1 array scalar variable.
in case lg
scalar left-hand side. want test condition against each row (as supported using [dim=]1
specifier) makes sense lg
array of rank-1 many elements there rows in mat1
.
that said, because fortran uses column-major storage using all(...,dim=1)
here giving test result along columns. in general, result of all(l, dim=n)
of shape [d_1, d_2, ..., d_{n-1}, d_{n+1}, ..., d_m]
shape of l
[d_1, ..., d_m]
.
[as noted in another answer result of all(l)
scalar. if want here, may have potential confusion language of formal description of all
.]
Comments
Post a Comment