Fortran 77: Reading empty string 
Author Message
 Fortran 77: Reading empty string

I've written a simple finite automata simulator in fortran 77, which
works except that I cannot successfully read in and process the empty
string.  I've tried the following code, and in my READ statement I
supplied the END=13 which means "if the user just presses enter, goto
line 13".  That means just proceed as normal...passing the empty string
to the FA function should work, but I haven't gotten a chance to test
it because although the code compiles using g77, I get a runtime error
which follows my code.

       PROGRAM FASimulator

       CHARACTER*25 str

 10    WRITE(6,11)
 11    FORMAT(1x, 'String:  ', $)

       READ(*, END=13) str

 13    IF (FA(str).EQ.1) THEN
         PRINT *, 'accepted'
       ELSE
         PRINT *, 'rejected'
       END IF

       GOTO 10

       STOP
       END
-----------------------------
natica% !g
g77 program2.f -o program2
natica% !.
./program2
 String:  sue: unformatted io not allowed
apparent state: unit 5 (unnamed)
lately reading sequential unformatted external IO
Abort



Sun, 20 Jul 2008 03:12:10 GMT  
 Fortran 77: Reading empty string


Quote:

>       READ(*, END=13) str

Odd, but try using a formatted read for a character variable:

READ(*, fmt='(a)', END=13) str

Regards,

Mike Metcalf



Sun, 20 Jul 2008 03:27:05 GMT  
 Fortran 77: Reading empty string

Quote:

> in my READ statement I
> supplied the END=13 which means "if the user just presses enter, goto
> line 13".

First, no. It does not mean anything close to that. The end= detects an
end-of file. Pressing the enter key does not generate and end of file.
It just generates a record - an empty one, but still a record. You won't
"normally" see an end-of-file on an interactive terminal, because there
is always the possibility that the user will type more input. On a unix
system, control-D will typically generate an interactive end-of-file,
but that's not what I'd call "normal".

Quote:
> That means just proceed as normal...passing the empty string
> to the FA function should work,

I haven't seen the FA function (if it was in a previous post, I didn't
go back and check), but your terminilogy here makes me suspicious. There
is no such thing in f77 as an "empty" string. There can be an empty
record, but not an empty string. There can be a string full of blanks,
but that isn't the same thing as "empty". Quite the opposite, it is
"full"; what it is full of happens to be blanks, but those are perfectly
valid characters.

Quote:
>        READ(*, END=13) str

Two problems with this line. First is the one that the erro rmessage
{*filter*}ed about. You don't have a format here. A format specification is
*REQUIRED* for a formatted file. You might be intending the * to be the
format specification, but it isn't. The * here is the unit "number" (*
being a special case to denote the standard input unit). You might have
intended

   read(*,*,end=13) string

but that has another problem, namely that list-directed formatting (the
*) is a poor choice here. It will keep "searching" until it finds a line
with some input on it, which is not at all the behavior you want. You
probably want something more like

  read(*,'(a)') string

where I have also taken off the end=, which is pretty useless here
unless you really did want to detect control-D.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Sun, 20 Jul 2008 03:51:25 GMT  
 Fortran 77: Reading empty string
Wow, thanks for all the info!  Everything is working great now.
Quote:


> > in my READ statement I
> > supplied the END=13 which means "if the user just presses enter, goto
> > line 13".

> First, no. It does not mean anything close to that. The end= detects an
> end-of file. Pressing the enter key does not generate and end of file.
> It just generates a record - an empty one, but still a record. You won't
> "normally" see an end-of-file on an interactive terminal, because there
> is always the possibility that the user will type more input. On a unix
> system, control-D will typically generate an interactive end-of-file,
> but that's not what I'd call "normal".

> > That means just proceed as normal...passing the empty string
> > to the FA function should work,

> I haven't seen the FA function (if it was in a previous post, I didn't
> go back and check), but your terminilogy here makes me suspicious. There
> is no such thing in f77 as an "empty" string. There can be an empty
> record, but not an empty string. There can be a string full of blanks,
> but that isn't the same thing as "empty". Quite the opposite, it is
> "full"; what it is full of happens to be blanks, but those are perfectly
> valid characters.

> >        READ(*, END=13) str

> Two problems with this line. First is the one that the erro rmessage
> {*filter*}ed about. You don't have a format here. A format specification is
> *REQUIRED* for a formatted file. You might be intending the * to be the
> format specification, but it isn't. The * here is the unit "number" (*
> being a special case to denote the standard input unit). You might have
> intended

>    read(*,*,end=13) string

> but that has another problem, namely that list-directed formatting (the
> *) is a poor choice here. It will keep "searching" until it finds a line
> with some input on it, which is not at all the behavior you want. You
> probably want something more like

>   read(*,'(a)') string

> where I have also taken off the end=, which is pretty useless here
> unless you really did want to detect control-D.

> --
> Richard Maine                     | Good judgment comes from experience;
> email: my first.last at org.domain| experience comes from bad judgment.
> org: nasa, domain: gov            |       -- Mark Twain



Sun, 20 Jul 2008 04:08:40 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Concatenating strings in FORTRAN 77

2. Reading Undocumented fortran 77 source code.

3. Fomatted read from a csv file (FORTRAN 77)

4. READ statement in fortran 77

5. Using fortran 77 to read data file C

6. FORTRAN 77/90 Instructors--Read This!

7. HELP needed on Fortran 77 READ

8. HELP on Fortran 77 READ

9. Reading word files in Fortran 77?

10. READING ASCI FILE INTO FORTRAN 77

11. Fortran 77: read second number on a line in a comma delimited text file

12. Fortran 77 - File reading problem

 

 
Powered by phpBB® Forum Software