Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jan 28, 2009 #1
    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: Jan 28, 2009
  2. jcsd
  3. Jan 28, 2009 #2
    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
     
  4. Jan 29, 2009 #3
    Yes, that seems to be exactly what I need. Thank-you.
    Jeff
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Fortran - How to retrieve read near middle or end of large file quickly.
  1. Read file in fortran (Replies: 2)

Loading...