Bug fix reported by Hank Seidel

This commit foxes a bug reported by Hank Seidel. The problem was that
we tried to access a file that had already been closed. This new
version adds more generic filename and file opening methods.