From: e p chandler on
What is list directed formatting supposed to do when it encounters an empty
field?
[MinGW32 on Win XP]

C:\temp>type q.f90
implicit none
character*5 a,b,c
character q
q='|'

open(10,file='q.txt')

do
read(10,*,end=100) a,b,c
print *,q // a // q // b // q // c // q
end do

100 continue
end


C:\temp>g95 q.f90

C:\temp>type q.txt
,,,
a,b,c
,,,


C:\temp>a
|#####|#####|#####|
|a |b |c |
|a |b |c |

The '#' represent "garbage" characters.

-- Elliot





From: Alois Steindl on
"e p chandler" <epc8(a)juno.com> writes:

> What is list directed formatting supposed to do when it encounters an empty
> field?

It seems, that on reading it doesn't change the variable at all, so if
it contained some garbage before, that garbage remains in its place.
Alois
From: Richard Maine on
Alois Steindl <Alois.Steindl(a)tuwien.ac.at> wrote:

> "e p chandler" <epc8(a)juno.com> writes:
>
> > What is list directed formatting supposed to do when it encounters an empty
> > field?
>
> It seems, that on reading it doesn't change the variable at all, so if
> it contained some garbage before, that garbage remains in its place.

Correct. That's also what the standard specifies (in slightly more
formal terminology, but that's the message).

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: e p chandler on

"Alois Steindl" <Alois.Steindl(a)tuwien.ac.at> wrote in message
news:m3d3uiur90.fsf(a)mch2pc28.mechanik.tuwien.ac.at...
> "e p chandler" <epc8(a)juno.com> writes:
>
>> What is list directed formatting supposed to do when it encounters an
>> empty
>> field?
>
> It seems, that on reading it doesn't change the variable at all, so if
> it contained some garbage before, that garbage remains in its place.
> Alois

Ouch. This reminds me of BASIC on the Commodore 64. It left the previous
contents of a variable when given an empty input. This was a real pain when
I wanted to be able to have the user input an empty string, say to exit a
loop or go back to the previous menu. There I had to pre-initialize the
variable to empty before each input statement.



From: Richard Maine on
e p chandler <epc8(a)juno.com> wrote:

> "Alois Steindl" <Alois.Steindl(a)tuwien.ac.at> wrote in message
> news:m3d3uiur90.fsf(a)mch2pc28.mechanik.tuwien.ac.at...
> > "e p chandler" <epc8(a)juno.com> writes:
> >
> >> What is list directed formatting supposed to do when it encounters an
> >> empty field?
> >
> > It seems, that on reading it doesn't change the variable at all,

> Ouch. This reminds me of BASIC on the Commodore 64. It left the previous
> contents of a variable when given an empty input. This was a real pain
> when I wanted to be able to have the user input an empty string, say to
> exit a loop or go back to the previous menu. There I had to pre-initialize
> the variable to empty before each input statement.

Two things.

1. To input an empty string, quote it. That's generally the way to
handle most problems with special input strings.

2. List-directed input is handily simple, but correspondingly limitted
in flexibility. There is no way to customize it for different
applications; adding such a way would hurt the simplicity that is the
strong point of list-directed. There are applications where leaving the
value unchanged is what you want, and there are others where that's not.
If you want to do something else, generally step back from list-directed
input. If nothing else, read the whole line into a character string.
Then parse as needed (which isn't very hard, particularly after the
first time, as one ought to adopt a personal library to facilitate it).
You can use list-directed internal reads on parts of the line as
appropriate.

3. If you want the user to be able to just hit return to indicate
something special (a common enough requirement), then you have more
serious problems than the treatment of empty fields. I assume you must
not have actually tried this with list-directed input or you would have
hit the more basic problem that hitting a return doesn't give you an
empty field (so it isn't relevant what happens with an empty field).
Hitting a return causes list-directed input to see no field yet at all
and thus to look for the next line of input. You need to take the
approach of reading the line into a character variable, as mentioned in
item 2 above. In this case, there is no parsing needed. You just check
for the special case of the line being blank. If it isn't blank, you
then use a list-directed internal read.

P.S. This stuff is all from f77, when list-directed input was introduced
to the standard, so it isn't particularly new. Before f90, list-directed
internal I/O was nonstandard and did not work in all compilers, which
made some of the alternatives awkward. By around the time f90 came out,
it also worked in most f77 compilers.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain