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

  • Context: Fortran 
  • Thread starter Thread starter jtibbitt
  • Start date Start date
  • Tags Tags
    File Fortran
Click For Summary
SUMMARY

To efficiently retrieve data from the middle or end of a large file in Fortran, utilize direct access file methods. The current code reads sequentially, which is inefficient for large datasets. By defining the open statement correctly for direct access, you can read specific records without processing the entire file. This approach significantly enhances performance when accessing large datasets.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with direct access file handling in Fortran
  • Knowledge of unformatted file I/O operations
  • Basic concepts of fixed-length records in file systems
NEXT STEPS
  • Research Fortran direct access file programming techniques
  • Explore the Fortran I/O library for advanced file handling
  • Learn about fixed-length records and their implementation in Fortran
  • Review performance optimization strategies for large file processing in Fortran
USEFUL FOR

Fortran developers, data scientists working with large datasets, and anyone looking to optimize file I/O operations in Fortran applications.

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:
Technology 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
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 19 ·
Replies
19
Views
7K
  • · Replies 5 ·
Replies
5
Views
3K