When I try to read this data using the following 'read' statement, it is not reading beyond 'dE'. It does not print anything beyond the 'dE' in the above file (i.e, starting from '/')....My 'read' statement and output is below:
dpb <n...@non.net> wrote: > jj_76 wrote: > ...snip example of attempting list-directed read on data file w/ "/" > character in record...
> ...
> "If a slash ( / ) is encountered during execution, the READ statement is > terminated, and any remaining input list items are unchanged."
> You need an explicit FORMAT statement.
Yes. Though that's a slight PITA for data like that shown, which appears to be blank delimitted instead of in fixed field widths.
My recommended approach for data like this (assuming that doing something like changing the input data format isn't an option - quotes would solve it easily for example) is:
1. Read the whole line into a character string using "A" format.
2. Separate the fields by searching for the blank delimitters. Make use of the INDEX, SCAN, and/or VERIFY intrinsics to do so. I've got my own subroutine that I use for such things, but it in turn uses other of my utility procedures. Probably about as easy to roll your own; it isn't very hard. Most people that do a lot of Fortran input parsing probably have one in their toolbox of handy routines.
3. Use an internal list-directed read to decode the data from each field (except for the character fields, which don't need any further decoding).
-- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain
>> jj_76 wrote: >> ...snip example of attempting list-directed read on data file w/ "/" >> character in record... ... > My recommended approach for data like this (assuming that doing > something like changing the input data format isn't an option - quotes > would solve it easily for example) is:
> 1. Read the whole line into a character string using "A" format.
> 2. Separate the fields by searching for the blank delimitters. Make > use of the INDEX, SCAN, and/or VERIFY intrinsics to do so. I've got > my own subroutine that I use for such things, but it in turn uses > other of my utility procedures. Probably about as easy to roll your > own; it isn't very hard. Most people that do a lot of Fortran input > parsing probably have one in their toolbox of handy routines.
> 3. Use an internal list-directed read to decode the data from each > field (except for the character fields, which don't need any further > decoding).
In this case, why not use your step 1, but then replace all the '/' characters with something else ('÷' say)? Then read the whole buffer with internal list-directed. To be sure, there also isn't a REPLACE intrinsic. But, as you say, it's fairly easy to roll your own. No sense reproducing the kind of parsing list-directed already does.
-- J. Giles
"I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." -- C. A. R. Hoare
"Simplicity is prerequisite for reliability" -- E. W. Dijkstra
James Giles <jamesgi...@worldnet.att.net> wrote: > In this case, why not use your step 1, but then replace all the '/' > characters with something else ('÷' say)? Then read the whole > buffer with internal list-directed.
That would also work.
-- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain
If that was all that was needed, the following would be somewhat easier ways (for the future)...
read(10,'(A)') test1 read(test1(36:46),*) frac
a) The simple "A" format will read the length of the variable w/o a precise count, and b( The substring selection eliminates the "/" problem character so you can use list-directed formatting again.
Or, since it was a fixed-column file, you could simply skip the required number of columns something like
read(10,'(35X,E11.5)') frac
Or, as Richard and James pointed out, a little alternative work in one of a couple of ways could leave you w/ being able to use the list-directed i/o, too.
In that particular situation, I would personally not try to find a suitable fortran format to read the data. That way of doing imply that each file requires its own parser, which is at the exact opposite of current software practices. Instead, I would turn the file into a standard data format, and directly use a component to read that format. For example, it would be easy to transform the previous data into a csv data file and use a csv fortran component, isn'it ?
> James Giles <jamesgi...@worldnet.att.net> wrote:
> > In this case, why not use your step 1, but then replace all the '/' > > characters with something else ('÷' say)? Then read the whole > > buffer with internal list-directed.
> That would also work.
Not if the line already has the character '÷' in it.
However, this difficulty can be overcome by keeping a record of which characters were replaced, and then later re-instating the altered ones.