[patch, Fortran] PR61933 Inquire on internal unit
Jerry DeLisle
jvdelisle@charter.net
Wed Jan 14 02:11:00 GMT 2015
Ping
On 01/09/2015 07:10 PM, Jerry DeLisle wrote:
> Hello all,
>
> I had to do a bit of research on this. I hope I have this correct. For
> background information, an "internal file" is a character variable that is
> connected to an internal unit. Likewise, an internal unit refers to an internal
> file which is a character variable.
>
> The subject refers to an "internal unit". This is actually touching on the
> fringes of User Defined Derived Type I/O. In at least the draft version of F2008
> Standard I have at the moment, I find the following:
>
> 1) "The unit argument passed to a defined input/output procedure will be
> negative when the parent input/output statement specified an internal unit, or
> specified an external unit that is a NEWUNIT value. When an internal unit is
> used with the INQUIRE statement, an error condition will occur, and any variable
> specified in an IOSTAT= specifier will be assigned the value
> IOSTAT_INQUIRE_INTERNAL_UNIT from the intrinsic module ISO FORTRAN ENV"
>
> Also regarding IOSTAT= we have:
>
> 2) "Execution of an input/output statement containing the IOSTAT= specifier
> causes the scalar-int-variable in the IOSTAT= specifier to become defined with:
> the processor-dependent positive integer value of the constant
> IOSTAT_INQUIRE_INTERNAL_UNIT from the intrinsic module ISO_FORTRAN_ENV(13.8.2)
> if a unit number in an INQUIRE statement identifies an internal file"
>
> 3) The standard lists as one of the processor dependencies - "the negative value
> of the unit argument to a defined input/output procedure if the parent data
> transfer statement accesses an internal file"
>
> To summarize all this, a negative unit number is used to communicate to defined
> type input/output procedures that the object of their I/O actions is an internal
> file, aka a character variable rather than an external file. To avoid
> ambiguity, the negative value should not be one created by NEWUNIT. INQUIRE on
> an internal file is not allowed and a specific error code is defined in the
> standard to be IOSTAT_INQUIRE_INTERNAL_UNIT. I suspect the standards committee
> recognized the need to communicate to DTIO procedures and defined this error
> code to enable user code to check for this condition and pass it back up to the
> parent?
>
> When I first implemented NEWUNIT, I reserved the values -1 thru -9 for future
> use. Our earlier email discussions on this PR centered around the case of
> UNIT=-1. This patch generates an error for -1 only. We can always change this
> later if the need to use -2 thru -9 comes about.
>
> Assuming we will implement the UDDTIO, we will then use -1 for the unit number
> to convey when an internal unit has been specified in the parent input/output
> procedure. As far as I can tell, the value used is processor defined and it
> appears that the cray COMPILER uses -1. Nothing special about that choice.
>
> I have eliminated the previous hack* I did in trans-io.c to handle the
> -fdefault-integer-8 problem way back in PR33055, reject UNIT=-1 at compile time
> in io.c, and simplified the definition of unit existence to whether or not the
> unit is connected in inquire.c.
>
> Finally, IOSTAT_INQUIRE_INTERNAL_UNIT was already defined for us in the
> intrinsic module ISO_FORTRAN_ENV but was never added into translate_error in
> runtime/error.c, so I have now done so and modified the test case to check it.
>
> Regression tested on x86-64-linux. New test cases added.
>
> OK for trunk?
>
> Regards,
>
> Jerry
>
> * hey, what can I say, my work is cheap as in free beer.
>
> 2015-01-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
>
> PR libgfortran/61933
> * io/inquire.c (inquire_via_unit): Set existing to true if a
> gfc_unit stucture was found for the given unit number.
> * runtime/error.c (translate_error): Add case for
> LIBERROR_INQUIRE_INTERNAL_UNIT.
>
> 2015-01-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
>
> PR fortran/61933
> * io.c (gfc_match_inquire): Generate error if unit number in
> inquire statement is a constant -1. All other values allowed.
> * trans-io.c (gfc_trans_inquire): Delete dummy iostat variable.
More information about the Fortran
mailing list