Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageThe 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
Post Follow-up to this messageThanks - it works fine!
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.