Reputation: 1525
Is it possible to use 8-bit and 16-bit unit numbers when calling Open
, or during read/write. If possible, how would one specify the correct declaration?
Upvotes: 0
Views: 396
Reputation: 32366
It is allowed to use integers of any kind to reference an external unit. In Fortran 2008 (but similar is given back to Fortran 90) the rule for an external-file-unit (R902) is merely "scalar-int-expr".
There are things to note, however. First, the units that exist are processor dependent: the processor is entitled to say that a unit number must be representable by default integer. Second, it's the value of the expression that is important in the file connection and data transfer statements: an external unit referenced in an open
, close
, read
, write
or inquire
statement by 15_int16
is the same as that referenced by 15_int32
(and the same as 15
).
This latter point means that it isn't important how the unit numbers are expressed.
open(15_int16, ...)
write(15) ...
write(15_int8) ...
write(15_int32) ...
write(15_int64) ...
are all appropriate (for when those kind numbers are valid).
In Fortran 95 when doing inquire by file/unit the variable given by the number=
specifier had to be of default integer. That restriction is no longer in place.
Upvotes: 4