[comp.lang.fortran] internal list-directed i/o

djh@osc.edu (David Heisterberg) (05/29/90)

Can anyone give a justification as to why internal list-directed i/o
is not required of a FORTRAN 77 implementation?  I'm interested because
I have to fix several occurrences of this in a program I'm porting.
In this particular case it's a trivial task, but annoying nonetheless.
Thanks.
-- 
David J. Heisterberg		djh@osc.edu		And you all know
The Ohio Supercomputer Center	djh@ohstpy.bitnet	security Is mortals'
Columbus, Ohio			ohstpy::djh		chiefest enemy.

jlg@lambda.UUCP (Jim Giles) (05/30/90)

From article <581@illini.osc.edu>, by djh@osc.edu (David Heisterberg):
> Can anyone give a justification as to why internal list-directed i/o
> is not required of a FORTRAN 77 implementation?  I'm interested because
> I have to fix several occurrences of this in a program I'm porting.
> In this particular case it's a trivial task, but annoying nonetheless.
> Thanks.

This is not a justification, just an explanation.  The problem concerns
the way in which many fortran implementations pass array arguments to
procedures:

      CHARACTER*80 A(50)
      ...
      READ (A,*)I,J,K    
      ...

The read is generally implemented as one or more procedure calls to
the I/O support library.  The array A is often passed as a descriptor
of the first element (ie. a pointer to the first element and some
indication that the element length is 80 characters).  The length
of the array is not passed.

Since list directed I/O can access more than one record _automatically_
(that is: not under program control but simply as a result of the
form of the data being transferred), and since the length of an
internal file (ie. the number of records) cannot be determined by
the library, the I/O could easily run passed the end of the internal
file.  To prevent this the committee made list-directed I/O to
internal files illegal - you can only do it if your implementation
provides the capability as an extension.

I don't think this explanation amounts to a justification for the 
continued lack of this feature in Fortran 90.  Since Fortran 90
requires the whole array descriptor to be passed in procedure
calls, the library could easily determine the internal file length
in the new standard.  I think that both list-directed and namelist
I/O _should_ be allowed to internal files in the new standard.

J. Giles

hirchert@ux1.cso.uiuc.edu (Kurt Hirchert) (05/30/90)

In article <581@illini.osc.edu> djh@osc.edu (David Heisterberg) writes:
>Can anyone give a justification as to why internal list-directed i/o
>is not required of a FORTRAN 77 implementation?  I'm interested because
>I have to fix several occurrences of this in a program I'm porting.
>In this particular case it's a trivial task, but annoying nonetheless.
>Thanks.

List-directed output was excluded because of the difficulty in using it
portably.  (There is such latitude in the format actually produced by
a processor that there is no way to portably determine how big a buffer
would be needed to receive the results of list-directed internal output.)
List-directed input was excluded merely as a matter of symmetry.
[Fortran 90 took the reverse point of view -- list-directed internal input
was seen to be useful and was thus allowed and list-directed internal output
was then allowed as a matter of symmetry, in spite of its not being
particularly portable.]

>-- 
>David J. Heisterberg		djh@osc.edu		And you all know
>The Ohio Supercomputer Center	djh@ohstpy.bitnet	security Is mortals'
>Columbus, Ohio			ohstpy::djh		chiefest enemy.

-- 
Kurt W. Hirchert     hirchert@ncsa.uiuc.edu
National Center for Supercomputing Applications

lamson@sierra.crd.ge.com (scott h lamson) (05/30/90)

In article <1990May29.220407.12112@ux1.cso.uiuc.edu> hirchert@ux1.cso.uiuc.edu (Kurt Hirchert) writes:

   From: hirchert@ux1.cso.uiuc.edu (Kurt Hirchert)

>   In article <581@illini.osc.edu> djh@osc.edu (David Heisterberg) writes:
>   >Can anyone give a justification as to why internal list-directed i/o
>   >is not required of a FORTRAN 77 implementation?  

>   List-directed output was excluded because of the difficulty in using it
>   portably.
>   ... why this was chnged in F-90...

Given this experience, i wondered why namelist was excluded from
internal IO in F-90 just like list-directed IO was in F-77.  Too late
now, I know, but it did seem odd.

scott

--
        Scott|  ARPA:      lamson@crd.ge.com
       Lamson|  UUCP:      uunet!crd.ge.com!lamson
(518)387-5795|  UUCP:      uunet!sierra.crd.ge.com!lamson

hirchert@ux1.cso.uiuc.edu (Kurt Hirchert) (06/12/90)

In article <14382@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes:
>From article <581@illini.osc.edu>, by djh@osc.edu (David Heisterberg):
>> Can anyone give a justification as to why internal list-directed i/o
>> is not required of a FORTRAN 77 implementation?  I'm interested because
>> I have to fix several occurrences of this in a program I'm porting.
>> In this particular case it's a trivial task, but annoying nonetheless.
>> Thanks.
>
>This is not a justification, just an explanation.  The problem concerns
>the way in which many fortran implementations pass array arguments to
>procedures:
>
>      CHARACTER*80 A(50)
>      ...
>      READ (A,*)I,J,K    
>      ...
>
>The read is generally implemented as one or more procedure calls to
>the I/O support library.  The array A is often passed as a descriptor
>of the first element (ie. a pointer to the first element and some
>indication that the element length is 80 characters).  The length
>of the array is not passed.
>
>Since list directed I/O can access more than one record _automatically_
>(that is: not under program control but simply as a result of the
>form of the data being transferred), and since the length of an
>internal file (ie. the number of records) cannot be determined by
>the library, the I/O could easily run passed the end of the internal
>file.  To prevent this the committee made list-directed I/O to
>internal files illegal - you can only do it if your implementation
>provides the capability as an extension.
>
>I don't think this explanation amounts to a justification for the 
>continued lack of this feature in Fortran 90.  Since Fortran 90
>requires the whole array descriptor to be passed in procedure
>calls, the library could easily determine the internal file length
>in the new standard.  I think that both list-directed and namelist
>I/O _should_ be allowed to internal files in the new standard.
>
>J. Giles

1. This "explanation" is, at best, incomplete.  Ordinary formatted input
   also has cases where the number of record being read cannot be predicted
   in advance (because of /'s in format and implied-DO loops controlled by
   values read from the internal file).

2. As I said in an earlier response to Dave's posting, Fortran 90 _does_
   allow listed-directed I/O to internal files.  This was not done for
   namelist I/O at least in part because no one suggested any plausible
   cases where this would be useful.
-- 
Kurt W. Hirchert     hirchert@ncsa.uiuc.edu
National Center for Supercomputing Applications