For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2004 > Question: lines of numbers separated with empty lines









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Question: lines of numbers separated with empty lines
peter_smith_yh@yahoo.com

2004-12-18, 3:56 pm

Hi there,

I have the following problem:

I have lines with numbers; every several lines, the numbers are
separated with 2 empty lines. How can I count the # of lines
with numbers between 2 separations?

For example

1 2
2 3 4 lines here
3 4
4 5


1 2 2 lines here
5 6


2 3
3 4 3 lines here
4 5

Thank you!

/PS

beliavsky@aol.com

2004-12-18, 3:56 pm

The following program counts the number of non-blank lines between
blank lines. You could modify it to check that non-blank lines contain
two integers. Google Groups seems to mess up the indentation.

program xread
implicit none
integer :: ierr,nnum
integer, parameter :: in_unit=20
character (len=100) :: text
character (len=*), parameter :: in_file="read_test.dat"
open (unit=in_unit,file=in_file,action="read",status="old")
nnum = 0
do
read (in_unit,"(a)",iostat=ierr) text
if (ierr /= 0) then
print*,nnum
exit
end if
if (text == "") then
if (nnum > 0) print*,nnum
nnum = 0
else
nnum = nnum + 1
end if
end do
end program xread

output:
4
2
3

peter_smith_yh@yahoo.com

2004-12-18, 8:56 pm

Thanks - it works fine!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com