Line | |
---|
1 | module count_lines_m |
---|
2 | |
---|
3 | implicit none |
---|
4 | |
---|
5 | contains |
---|
6 | |
---|
7 | subroutine count_lines(unit, n) |
---|
8 | |
---|
9 | ! This subroutine counts the number of lines in an external file, |
---|
10 | ! from the current position, not necessarily the first record of the |
---|
11 | ! file. |
---|
12 | ! On return, the position is at the end of the file. |
---|
13 | ! The file should be connected for sequential access. |
---|
14 | ! The records of the file shoud be formatted. |
---|
15 | |
---|
16 | integer, intent(in):: unit ! external file unit |
---|
17 | integer, intent(out):: n ! number of lines |
---|
18 | |
---|
19 | ! Variable local to the procedure: |
---|
20 | integer iostat |
---|
21 | |
---|
22 | !------------------------------- |
---|
23 | |
---|
24 | n = 0 |
---|
25 | do |
---|
26 | read(unit, fmt=*, iostat=iostat) |
---|
27 | if (iostat /= 0) exit |
---|
28 | n = n + 1 |
---|
29 | end do |
---|
30 | |
---|
31 | end subroutine count_lines |
---|
32 | |
---|
33 | end module count_lines_m |
---|
Note: See
TracBrowser
for help on using the repository browser.