Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random seeking in binary file

Status
Not open for further replies.

andrews2004

Programmer
Oct 27, 2004
3
GB
Hi there,

I am new to fortran and i am writing some code to read a stata (a statistical package) binary file. i am using the open command with form='binary' and i have successfully managed to read all the information from the header of the file which tells me all i need to know about the actual data.

i want to be able to change the position i am reading in the file so that i can just extract specific data. does anybody know how i can do this?

thanks!
 
You also need to open with ACCESS='DIRECT', RECL=x where x is your record length in bytes. The system works on fixed length records. What you can get away with depends on your system. GNU allows RECL=1.

Say you managed to OPEN channel 10 with RECL=1 and you want to read an integer N from position 5798,
Code:
      READ(10,REC=5798) N
Note that this assumes unformatted data so it is possibly 4 to 8 bytes for an integer, depending on your architecture.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top