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
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

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