Skip to main content

3.10) Disconnecting A File From A Program


Once you are done with an input or output file then it is good practice to unlink it from the program since there is no need for your program to keep managing it when you are not going to use it anymore. To disconnect a file (either input or output file) from a program then type close(unit number), where unit number is the actual unit number (e.g. 22 or 24 in past examples). So let’s say you have connected the file to the program with:

open(unit=24, file=’outputdata.dat’)

you can then disconnect it by the statement:

close(24)

and the outputdata.dat file will be disconnected from the program and the unit number 24 can be used again for other open statements.

On the next page, see an example of this.