Having tried to apply the first example, I think I found an error: Line 40 should close File Number 1, not 3, since 3 is the device number and 1 the file number.
You are correct! Thank you very much. --Jodigi (talk) 02:11, 31 May 2017 (CEST)