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

  • Thread starter Thread starter jtibbitt
  • Start date Start date
  • Tags Tags
    File Fortran
AI Thread Summary
To retrieve information from a file without reading all preceding data, using direct access files is recommended. This method allows for reading specific records based on their fixed length, which is suitable for the given data structure. By correctly defining the open statement, you can access the desired coordinate pair directly. For further guidance, reviewing resources on direct access file handling in Fortran can provide additional examples and insights.
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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
8
Views
1K
Replies
12
Views
3K
Replies
4
Views
2K
Replies
5
Views
5K
Replies
5
Views
2K
Replies
1
Views
3K
Replies
19
Views
6K
Replies
8
Views
2K
Back
Top