I have uncovered a bug with logical comparisons of character variables in arrays.
Fortran's logical comparison == (or .eq.) should work for arrays (and array sections) on an element by element basis. For character variables this should be done on the same basis as for scalars, i.e. the character variable with the smallest length should first be padded with trailing blanks so both character variables have the same length.
However, this doesn't seem to work for arrays of character variables where the elements have a trimmed length of 1 (i.e. only one non-blank character in the first position).
In the following code, test 1 passes, but test 2 fails in two different ways.
I get the following output. Strangely the last array printed only has one element (Maybe there's a second bug with print logical array, but I have not looked hard at this).
TEST 1
Should print T F (AND DOES!) T F
TEST 2
Should print T F (BUT DOESN'T!) F F Should print T F (BUT DOESN'T) F
Hopefully, the code below is small enough to allow this to be debugged.
program anon
implicit none
logical :: flags(2)
character(len=3) :: s
print '(1x/'TEST 1'/)'
! Set s to 'AB ', i.e. it has one trailing blank
s = 'AB'
! The character array elements 'AB' and 'BB' should be padded with one blank to
! length 3 before carrying out the comparisons.
print *,'Should print T F (AND DOES!)'
flags = (s == (/'AB','BB'/))
print *, flags
print '(1x/'TEST 2'/)'
! Set s to 'A ', i.e. it has two trailing blanks
s = 'A'
! The character array elements 'A' and 'B' should be padded with two blanks to
! length 3 before carrying out the comparisons.
print *,'Should print T F (BUT DOESN''T!)'
flags = (s == (/'A','B'/))
print *, flags
print *,'Should print T F (BUT DOESN''T)'
print *, (s == (/'A','B'/))
end program anon
Best Regards David.