Fortran - How to retrieve read near middle or end of large file quickly.

  • Topic: Fortran 
  • Thread starter Thread starter jtibbitt
  • Start date Start date
  • Tags Tags
    File Fortran
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 6K views
jtibbitt
Messages
2
Reaction score
0
Hi. I need to be retrieve information far into a file without reading everything before it. Is there a way to do this? Current code is below.

Thanks,
Jeff Tibbitt

!ccccccccccccccccccccccccccccccccccccccc
program getcoord

integer i
real*4 xx(1000), yy(1000), zz(1000)
double precision x(1000,3)

! FILE
open(unit=56,file="tmp.dat",form='unformatted')

do i=1,50000
! GET 50000th SET OF COORDINATES
read(56) xx
read(56) yy
read(56) zz
enddo
close(56)

! CONVERT TO DOUBLE PRECISION
do i=1,1000
x(i,1)=xx(i)
x(i,2)=yy(i)
x(i,3)=zz(i)
enddo

end program
!cccccccccccccccccccccccccccccccccccccc
 
Last edited:
Physics news on Phys.org
I believe you can try reading it as a direct access file.
Direct access files can be formatted or unformatted, but each record has to have a fixed length, which I believe applies in your case.
If you define the open statement correctly, the record number would be the coordinate pair you are trying to read, as in the above example.
Try reading up (the later part of) the following article on direct access file and the examples:
http://www.amath.unc.edu/sysadmin/DOC4.0/fortran/prog_guide/2_io.doc.html
 
Yes, that seems to be exactly what I need. Thank-you.
Jeff