Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple fortran problem

Status
Not open for further replies.

pierrr

MIS
Jun 27, 2012
2
GB
Hi!

I'm a novice in fortran and I have a very simple problem.
I have a very large input file (more than 1.000.000 rows) and I need to read ONLY one row every 8 (row 1, 9, 17, ... and so on, up to the end of file).

I try with a simple do-loop, but something doesn't work...

do i= 1, nmax, 8
read(1, *) var
enddo

Any suggestion????

Thanks in advance!

 
No, this would read all lines until nmax is reached. As you read on every 8th instance only, you will read one 8th of the lines. You would have to advance in your file. My proposal would be

Code:
real var                    ! or whatever it is
integer iCount              ! this will be your counter

...                         ! open your file and all this stuff
...

iCount = 0               
do 1 = 1, nmax
    iCount = iCount + 1
    if (iCount .eq. 8) then
        read (1,*) var      ! read your variable whenever the count reached 8
        iCount = 0
    else
        read (1,*)          ! just advance one record
    endif
enddo
...
...

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top