It looks like that bug was fixed in the version of the compiler that I’m using. If it is a bug in the compiler, and not my code, then perhaps they are related bugs.
On a related question, in that example the trim() function was used. I’ve been assuming that the return values for those two functions are already in their trimmed form. At least for the versions of gfortran that I’ve tried where this code works, that has been the case. trim() is easy enough to add, but is it necessary? Are there any known compilers that do not returned trimmed values for those two intrinsic functions?