[Patch, FORTRAN] PR61933 Inquire on Internal Unit

Janne Blomqvist blomqvist.janne@gmail.com
Tue Sep 9 07:40:00 GMT 2014


On Mon, Sep 8, 2014 at 11:30 AM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> On Sun, Sep 7, 2014 at 9:34 PM, Jerry DeLisle <jvdelisle@charter.net> wrote:
>> With this preliminary (not tested yet) patch to the runtime:
>>
>> Index: inquire.c
>> ===================================================================
>> --- inquire.c   (revision 214973)
>> +++ inquire.c   (working copy)
>> @@ -43,16 +43,25 @@
>>
>>    if ((cf & IOPARM_INQUIRE_HAS_EXIST) != 0)
>>      {
>> -      *iqp->exist = (iqp->common.unit >= 0
>> -                    && iqp->common.unit <= GFC_INTEGER_4_HUGE);
>> -
>> -      if ((cf & IOPARM_INQUIRE_HAS_FILE) == 0)
>> +      if (iqp->common.unit >= 0
>> +         && iqp->common.unit <= GFC_INTEGER_4_HUGE)
>>         {
>> -         if (!(*iqp->exist))
>> -           *iqp->common.iostat = LIBERROR_BAD_UNIT;
>> -         *iqp->exist = *iqp->exist
>> -                       && (*iqp->common.iostat != LIBERROR_BAD_UNIT);
>> +         *iqp->exist = 1;
>> +         *iqp->common.iostat = 0;
>>         }
>> +      else
>> +       {
>> +         if (u == NULL)
>> +           {
>> +             *iqp->exist = 0;
>> +             *iqp->common.iostat = LIBERROR_BAD_UNIT;
>> +           }
>> +         else
>> +           {
>> +             *iqp->exist = 1;
>> +             *iqp->common.iostat = 0;
>> +           }
>> +       }
>>      }
>>
>>    if ((cf & IOPARM_INQUIRE_HAS_OPENED) != 0)
>
> I don't think we want to set iostat to anything but 0 here. See F2008
> 9.11. Setting iostat means that we hit some error; also, if iostat is
> not present error termination should occur. But if we're inquiring
> whether a unit exists, then certainly terminating the program if the
> unit does not exist is certainly not what one wants.
>
> Otherwise, wrt. negative units, I'll post to c.l.f. and ask for
> opinions. I think the standard is illogical here, and some subtle
> reading of it may be necessary.

My interpretation what the responses on clf imply for an implementation:

- file-unit-number can be a constant, variable, expression, or
whatever. Makes no difference. The rules are the same in all cases.

- Negative unit numbers are Ok, except for -1 (error condition) and
potentially another one reserved for internal UDDTIO, if that is ever
implemented. Of course, the implementation of OPEN in ligfortran must
check for negative unit numbers, and report an error if such a unit is
not connected or has the value -1 or the one reserved for internal
UDDTIO. E.g.

OPEN(newunit=u, ...)
...
OPEN(unit=u, ...) ! Reopen unit

is Ok, but trying to open a negative unit number which is not
connected must fail.

- Same for INQUIRE. RM offered a couple of interpretations of inquire
with negative unit numbers, but IMHO the one which makes sense from an
implementation and usability point of view is to handle them exactly
like positive unit numbers (except, again, the 2 reserved values).

-- 
Janne Blomqvist



More information about the Fortran mailing list