Unit number handling at file open. More...
Data Types | |
| interface | fileopen |
Functions/Subroutines | |
| subroutine, public | fileopen (unit, file, mode, err) |
Unit number handling at file open.
Unit number is handled when a file is opened. Subroutine "FileOpen" receives filename and open mode firstly, and searches an available unit number internally, and opens the file according to the open mode internally, and returns the unit number finally. This module simplifies source codes for unit number management or readable/writable check.
| Procedure | Description |
|---|---|
| FileOpen | A file is opened and unit number is returned with a filename and mode |
Give filename and open mode to subroutine "FileOpen" provided by this module. Then the file is opened and unit number is returned to an argument unit. Using the unit number, read the contents of the file or write in the file. Use Fortran built-in READ, WRITE, and CLOSE statements for read/write and close.
| subroutine, public dc_iounit::fileopen | ( | integer, intent(out) | unit, |
| character(*), intent(in) | file, | ||
| character(*), intent(in), optional | mode, | ||
| logical, intent(out), optional | err ) |
Open a file and return unit number
Filename is given to file, and open mode is given to mode, then the file is opened and unit number is returned.
| Mode | Description |
|---|---|
| "r" | A file is opened with read-only mode |
| "w" | A file is opened with writable mode. If a file is exist already, the content of the file is emptied. |
| "a" | A file is opened with writable mode. Output is appended at the end of the file. |
| "rw" | A file is opened with read/write mode. If a file is exist already, the content of the file is emptied. |
| "ra" | A file is opened with read/write mode. If a file is exist already, a position of read/write is set at the end of the file. |
If the file can not be opened with the mode, the program aborts. If this err argument is given, .true. is substituted to err and -1 is substituted to unit and the program does not abort.
| [out] | unit | Unit number assigned to the opened file |
| [in] | file | Filename to open |
| [in] | mode | Open mode ("r", "w", "a", "rw", "ra"). Default is "r". |
| [out] | err | Exception handling flag |
Definition at line 186 of file dc_iounit.f90.