matrix - Use of IF statement with matrices in fortran -


i want go through matrix , check if block of same predefined unit. here code. 'sd5' 2 2 predefined unit.

allocate (flist((n-1)**2,3)) flist = 0 p = 1 = 1, n-1, 1   j = 1, n-1, 1     if (test(i:i+1, j:j+1) == sd5)       flist(p,1:3) = (i, j+1, 101) ! 101 should replaced submatrix number   end if   p = p+1   end end 

the problem seems in if statement 4 logical statements returned in test(i:i+1, j:j+1) == sd5. error:

error: if clause @ (1) requires scalar logical expression 

i error:

flist(p,1:3) = (i, j+1, 101) ! 101 should replaced sub matrix number      1 error: expected parameter symbol in complex constant @ (1) 

i not understand error, variables integer defined.

first, if statements require scalar clauses.

(test(i:i+1, j:j+1) == sd5) 

results in 2x2 matrix containing .true. or .false.. since want check all entries, statement should read

if ( all( test(i:i+1, j:j+1) == sd5) ) 

[ use any if 1 matching entry sufficient. ]

the second statement little tricky, since not state want achieve. is, not expect. guess trying store vector of length three, , assignment should read

flist(p,1:3) = (/ i, j+1, 101 /) 

or

flist(p,1:3) = [ i, j+1, 101 ] 

the syntax provided in fact used specify complex constants:

( real, imag ) 

in form, real , imag need constants or literals themselves, cf. fortran 2008 standard, r417.


Comments