Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor II
47 Views

READ String

100 READ  (sr,('(A)')) LINE

Why does taking the '(a)' out and using a * not work with a string line that has spaces in it?

Line is character*72 - A72 does not work unless string is 72 - hard in a text file.

 

0 Kudos
1 Reply
Highlighted
Black Belt
47 Views

A run of one or more blanks is considered a value separator in list directed input/output, hence if your input record was `abc   def`, LINE would only end up with `abc`.  There are quite a few other surprises associated with list directed input.

The `A` data descriptor means "transfer the same number of characters as the length of the associated input/output item". If LINE is of length 72, then `A` is the same as `A72`

If the PAD mode for a connection is 'YES' (which is the default) then additional blanks will be magically supplied by the Fortran processor if the current record is not long enough for the combination of format descriptor and input item.  There is no need for the user to get the line length exactly right.  If they supply more than 72 characters the extra stuff gets ignored.

So I would just use `READ (sr, '(A)') LINE`.  If that doesn't work, then there are other things going on that you haven't told us about.

(I am also deleting in the above the superfluous pair of parentheses around the character literal for the format specification.)

0 Kudos