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

  • Fortran
  • Thread starter jtibbitt
  • Start date
  • Tags
    File Fortran
TibbittIn summary, the conversation discusses a method for retrieving information from a file without having to read everything before it. The suggested solution is to use direct access files, which have a fixed record length and allow for specific records to be read. The code provided shows how to implement this method. The person in the conversation expresses gratitude for the helpful information.
  • #1
jtibbitt
2
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
  • #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
 
  • #3
Yes, that seems to be exactly what I need. Thank-you.
Jeff
 

1. How do I retrieve data from the middle or end of a large file in Fortran?

The most efficient way to retrieve data from the middle or end of a large file in Fortran is to use the SEEK statement. This statement allows you to specify the exact location in the file where you want to start reading data.

2. Is it possible to retrieve data from a specific line in a large file using Fortran?

Yes, it is possible to retrieve data from a specific line in a large file using Fortran. You can use the READ statement with the UNIT and IOSTAT parameters to read data from a specific line in the file.

3. Can I retrieve data from a large file in Fortran without reading the entire file?

Yes, you can retrieve data from a large file in Fortran without reading the entire file. You can use the POSITION and ACCESS parameters in the OPEN statement to set the starting point for reading data.

4. How can I make the process of retrieving data from a large file in Fortran faster?

To make the process of retrieving data from a large file in Fortran faster, you can use the DIRECT access mode in the OPEN statement. This allows you to access data directly from a specific record in the file without having to read through all the previous records.

5. Are there any built-in functions or libraries in Fortran that can help with retrieving data from a large file?

Yes, Fortran has built-in functions and libraries that can assist with retrieving data from a large file. For example, the GETARG function can be used to retrieve command line arguments, which can then be used to specify the file to be read. The INQUIRE statement can also be used to retrieve information about the file, such as its size and record length.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
877
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
4
Views
615
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top