At 4:39pm on 14 Oct, Harold P. Hjalmarson wrote:
> Also, I have become very curious about parsing input data. A search of the
> Web was not very productive (I found lots of information on compiler
> parsing). I realize that the Namelist command is a reasonable choice given
> that it has been standardized. However, it works differently in Sun and
> IBM Fortran. This caused me some trouble.
I have a set of routines, written in Fortran, that I use for all my
program input. One routine reads a data line, concatenating further
lines if the line ends in a continuation flag, and then parses it into
items separated by blank space or terminated by comma. Quotes can be
used in the usual way around items containing blank space. Then other
routines read items from the line-buffer, treating them as character,
real or integer as required. It is possible to go back and re-read an
item if (for example) it doesn't match any of a set of keywords and is
consequently to be read as a number. If reading beyond the last item
in a line, it is possible to return zero or blank, or to read further
lines until an item is found.
This arrangement makes it very easy to organise input files in
keyword-value style, so that the input is almost self-documenting.
Comment lines are easily dealt with too.
--
Anthony Stone http://fandango.ch.cam.ac.uk/
University Chemical Laboratory, Email: [log in to unmask]
Lensfield Road, Phone: +44 1223 336375
Cambridge CB2 1EW Fax: +44 1223 336362
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|