Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!thumper!ulysses!mhuxo!mhuxt!mhuxi!mhuxh!mhuxu!att!rutgers!orstcs!mist!gil
From: gil@mist.cs.orst.edu (Gil Bachelor)
Newsgroups: comp.lang.fortran
Subject: Re: Any way to fseek() in MS-Fortran under DOS?
Keywords: free format internal read
Message-ID: <5462@orstcs.CS.ORST.EDU>
Date: 13 Jul 88 01:55:37 GMT
Sender: netnews@orstcs.CS.ORST.EDU
Reply-To: gil@mist.UUCP (Gil Bachelor)
Distribution: na
Organization: Oregon State University - CS - Corvallis, Oregon
Lines: 67

In article <490@calvin.EE.CORNELL.EDU> richard@calvin.ee.cornell.edu.UUCP 
   (Richard Brittain) writes:
>In article <11041@cgl.ucsf.EDU> seibel@hegel.mmwb.ucsf.edu.UUCP 
>   (George Seibel) writes:
>>In article <472@morgoth.UUCP> dmb@morgoth.UUCP (David M. Brown) writes:
>>>What I want to do is look at the first character in the line, and, if 
>>>it's a '#', just go on to the next line.  No problem there.  But, if it's
>>>not, then I want to read data from the rest of the line.
>>.........
>>The usual approach is to read a line into a buffer, then test the buffer
>>to see if it has the characters that signify a real record.  If it does,
>>read it using an internal read.  ...
>   ....... example deleted
>>... that's all.  this is standard fortran 77, so you shouldn't have to
>>mess around with fseek(), and it should work on any fortran 77 compiler.
>   .........
>>You'll have to do formatted reads however; if you want to do a "free 
>>format read" from the buffer, then you'll have to parse it yourself.
>>George Seibel, UCSF
>
>This is a very common situation in a lot of the programming which I am
>involved in, and I find the inability to perform a free format read from
>a character string a constant frustration.  I never use a formatted read
>when a free format read will do as this makes life so much easier.  Can
>anyone explain a good reason for this rule in the fortran standard?  It has
>always seemed somewhat arbitrary to me. 
>
>Richard Brittain,                   School of Elect. Eng.,  Upson Hall   
>                                    Cornell University, Ithaca, NY 14853

I don't know the reason for the rule.  However, some versions of Fortran
have been extended to allow free-format reads from internal files 
(character variables or arrays).  For those versions that don't allow it,
one can use a scratch file, as shown in this example:

      character line*80
      integer n
      real x

* Open unit 9 as a scratch file.
      open(9)

* Use A-format input to read an 80-character line into
*  variable "line".  
100   read (*,1000,end=200) line
1000  format(a)

* Test the first character of "line"; if it is a '#',
*  go somewhere else.
      if (line(1:1) .eq. '#') goto 150

* Use A-format to write the line on the scratch file and 
* read it back, using list-directed input.
      rewind(9)
      write(9,1000) line
      rewind(9)
      read (9,*) n, x
      ...

This may be considered a "kludge", but it works, and is a lot
easier than writing your own number-conversion routines.

------------------------------------------------------------------
Gilbert A. Bachelor      | Internet: gil@cs.orst.edu
Dept. of Computer Science|     UUCP: {hp-pcd,tektronix}!orstcs!gil
Oregon State University  |
Corvallis, OR  97331     | Phone:  (503) 754-3273