Extended Re-OPEN capabilities in Fortran Wiki
Proposal: Extend the number of attributes that may be modified when re-opening a connected unit. Rationale: It is often useful to change I/O attributes without disconnecting a unit that may be connected to an unnamed pipe (common with standard I/O units). This is currently supported when issuing an OPEN command with matching UNIT and FILE values, but only for a limited set of properties. For example, it can be useful to set standard-input to a non-default text ENCODING, or set ACCESS='STREAM'. It is reasonable to extend the set of modifiable I/O properties only for connected units that have not yet transferred any data. Often, standard I/O units are unnamed. For those units, re-OPEN should accept FILE='', or possibly no FILE specifier. ----- ## Comments [[Jason Blevins]], 20 July 2010: I think being able to re-open pre-connected units such as stdio to use stream I/O is very important. This would make writing Unix-style text filters much more natural. There was some discussion about this on [[comp.lang.fortran]] last year in the following threads: * [making a filter using stream I/O ](http://groups.google.com/groups?threadm=40ab9721-188e-4791-8d99-b0aab0a6b9e9@x5g2000yqk.googlegroups.com) * [STREAM I/O questions ](http://groups.google.com/groups?threadm=23a21e8f-5cd1-4efd-a7cb-bf0fe642c9a9@r25g2000vbn.googlegroups.com) ----- ## Compiler Behaviors The descriptions below are for the standard input unit. Similar behaviors occur for the standard output and error units. For many Fortran compilers, and INQUIRE on INPUT_UNIT returns the unit as unnamed. Many return the dummy filename "stdin", which is generally a bad convention because "stdin" is also a valid filename. In both cases, there is no proper way to issue a re-open on a standard I/O unit, unless the default filename for INPUT_UNIT does not follow the normal convention of "fort.5". ### Intel Fortran Intel Fortran seems to handle standard I/O units the best. It returns actual tty names where possible. However, when tty names are not available, it returns "stdin", which is really incorrect. The default unit is typically `"fort.`_number_`"` where _number_ is the logical UNIT number. Intel Fortran defines the default file for UNIT=INPUT_UNIT to always be stdin, rather than a named file. This is the best way to support re-opening standard I/O units without any Standards modifications. This does not completely solve the problem for extended re-open attributes, because some forms of I/O may be interrupted by explicitly closing the unit first. When an OPEN is issued with INPUT_UNIT and no FILE specifier, Intel Fortran will attempt to open or re-open stdin. This can be used to re-open stdin with modified attributes, including ACCESS='STREAM'. However, there is currently that causes STREAM I/O to fail for all pipe/tty devices (reported; hopefully fixed soon.) ### GFortran GFortran always returns "stdin" for standard input. (This may change, at least for tty devices.) You can re-open the connected stdin by not giving a FILE= specifier. It does not accept FILE=''. Once stdin has been closed, this behaves as FILE='fort.5', creating an empty fort.5 file if it does not yet exist. ### G77 INQUIRE returns stdin as unnamed. Reopening works as in GFortran, with UNIT=INPUT_UNIT and FILE= unspecified. ### Sunf90 Behaves generally the same as G77.
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル