Path: utzoo!attcan!uunet!husc6!rutgers!ucsd!ucbvax!ucsfcgl!seibel
From: seibel@cgl.ucsf.edu (George Seibel)
Newsgroups: comp.lang.fortran
Subject: Re: Any way to fseek() in MS-Fortran under DOS?
Keywords: seek, MS-Fortran, MS-DOS
Message-ID: <11041@cgl.ucsf.EDU>
Date: 11 Jul 88 07:37:12 GMT
References: <472@morgoth.UUCP>
Sender: daemon@cgl.ucsf.edu
Reply-To: seibel@hegel.mmwb.ucsf.edu.UUCP (George Seibel)
Organization: UCSF Computer Graphics Lab
Lines: 42

In article <472@morgoth.UUCP> dmb@morgoth.UUCP (David M. Brown) writes:
>[IBM-AT...MS-Fortran...MS-DOS]

>I am writing an application which reads in data from a file.  I want
>to be able to comment out lines of data.  I did this on my old system
>(Ultrix on uVAX II) by using fseek().  It wasn't pretty but it worked.

>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 backslash edit descriptor doesn't seem to work on input.  The lines
>in the file are of various lengths, so direct access won't work. 

>Anyone have any ideas?

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.  In this example, I assume a max record
length of 80 chars, and read an integer and a real...

      parameter (LENREC=80)
      character*LENREC buffer
c
c     --- read a line into the buffer ---
c
      read(lunit,'(a)') buffer
c
c     --- read data from buffer if not comment ---
c
      if (buffer(1:1) .ne. '#') read(buffer,'(i5,f8.3)') idata, rdata
c
... 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.
All you're doing here is substituting the name of a character variable
that contains your data for the logical unit number in an otherwise standard
read statement.  This method is simple and suffices for most applications.
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
seibel@cgl.ucsf.edu