Roland Schilling wrote:
>
> Dear Fortran wizards,
>
> Is the current Fortran standard sufficient?
Yes, it is sufficient for everything! ;-)
>
> Please consider the task of reading character strings of
> unknown length with a *portable* piece of Fortran code.
>
> Since we don't know in advance the length of the records
> to be read (and this, in addition, can vary from record
> to record), we need an endless do loop with a non-advancing
> READ statement, feeding the data read into a character
> variable of appropriate length (but not long enough for
> *any* possible record). But how to find out whether the
> end-of-file is reached? We, of course, will use the
> SIZE= and the IOSTAT= specifier. But the standard only
> requires 'iostat' to be negative for end-of-file *and*
> end-of-record, and this two values to be different.
> Because the code should be portable we cannot use this
> difference to make the distinction between end-of-file
> and end-of-record, since the standard leaves it to the
> compiler writer to select these values. Also 'size'
> doesn't help here, since we can have records of any
> length, including zero!
>
> How to solve this problem? Any help and comments would
> be very much appreciated.
>
Two solutions.
Dan Nagle has a portability project set of
stuff that finds the values for any particular machine.
Look at users.erols.com/dnagle for the portability project.
Alternatively, you can compute them in a portable way.
Open a file, write a short record to it, rewind it and
read it into a string that is longer than the record.
Capture the iostat value and use it for future comparisons.
Read the "next record" and capture the iostat value and use
that for the EOF comparisons.
Otherwise, you can use the END=, EOR= and ERR= branches to
distinguish. They have the added advantage that they
automatically go anywhere you want in the code and you don't
need any confusing IF or CASE constructs.
Hope this helps
Dick Hendrickson
> Thanks in advance,
> Roland
>
> +----------------------------------------------------------------------+
> | Roland Schilling Home-Office: +49(89)32929-670 |
> | Max-Planck-Institut fuer Quantenoptik Phone: +49(89)32905-265 |
> | Hans-Kopfermann-Str. 1 Fax: +49(89)32905-200 |
> | D-85748 Garching E-mail: [log in to unmask] |
> | Germany http://www.geo600.uni-hannover.de |
> +----------------------------------------------------------------------+
|