Fortran 90’s list directed input is powerful, flexible, but tricky. My function to read a keyword, boolean value pair from a file was not working when I reshuffled the order of the input parameters (blame Python’s orderless dictionaries for this, not that I’m complaining). Originally I just read the string and logical straight in, then tested the string for a match to the key. However when reading list directed logicals it seems that fortran was biting off the next record as well. New improved read_bool follows:
! Searches the input file for the key and reads the value
! to the supplied variable when it finds it.
character (len=20) :: st
character (len=*) :: key
logical :: val
w = len(key)
do while (st(1:len(key)) .ne. key)
print *,'reading value'
! print *,key,st(1:len(key)),i
if(i .eq. -1) then
stop 'fatal error: parameter not found'
if (st(1:len(key)) .eq. key) then
! print *,'I found ',st
end subroutine read_bool
Respect to Nick Maclaren for his online powerpoint slides (which didn’t lead me to the answer, but were quite useful nonetheless.) Also see http://cimss.ssec.wisc.edu/~gumley/programmingtips.txt, and the QUB notes which I always seem to stumble back to.