reading newlines with FORMAT statement

Posted by peter.murray.rust on Stack Overflow See other posts from Stack Overflow or by peter.murray.rust
Published on 2010-12-12T09:59:03Z Indexed on 2011/01/07 21:54 UTC
Read the original article Hit count: 207

Filed under:

I'm writing a preprocessor and postprocessor for Fortran input and output using FORMAT-like statements (there are reasons not to use a FORTRAN library). I want to treat the new line ("/") character correctly. I don't have a Fortran compiler immediately to hand. Is there a simple algorithm for working out how many newlines are written or consumed (This post just gives reading examples)

[Please assume a FORTRAN77-like mentality in the FORTRAN code and correct any FORTRAN syntax on my part]

UPDATE: no comments yet so I am reduced to finding a compiler and running it myself. I'll post the answers if I'm not beaten to it. No-one commented I had the format syntax wrong. I've changed it but there may still be errors

Assume datafile 1

a
b
c
d

etc...

(a) does the READ command always consume a newline? does

READ(1, '(A)') A
READ(1, '(A)') B

give A='a' and B='b'

(b) what does

READ(1,'(A,/)') A
READ(1,'(A)') B

give for B? (I would assume 'c')

(c) what does

READ(1, '(/)')
READ(1, '(A)') A

give for A (is it 'b' or 'c')

(d) what does

READ(1,'(A,/,A)') A, B
READ(1,'(A)') C

give for A and B and C(can I assume 'a' and 'b' and 'c')

(e) what does

READ(1,'(A,/,/,A)') A, B
READ(1,'(A)') C

give for A and B and C(can I assume 'a' and 'c' and 'd')?

Are there any cases in which the '/' is redundant?

© Stack Overflow or respective owner

Related posts about fortran