<Example Program>

Program newunit_example
    Integer :: unit
    Open (
Newunit=unit,File='DAT',Status='old',Position='Rewind')
    n_lines = 0
    Do
        Read (
unit,'( )',End=10)
        n_lines = n_lines + 1
    End Do
10 Continue
    Print *,'There are',n_lines,'lines in the file.'
    Close(
unit)
End Program


Contents of file: DAT

This is line 1
This is line 2
This is line 3; it is longer than the other lines

Execution Results

  There are 3 lines in the file.