- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I want to realize the following function:
Firstly, I write a 'binary' file (real*8 data type), then I wish I can locate to any position of the file and read the correspondent data without read from the begin of the file? How can I do? My code is as following. Can anyone modify the code for me?
Thanks,
Zhanghong Tang
Code:
implicit none real*8 a integer i open(1,file='test',form='binary') do i=1,10000 a=i write(1)a enddo call testreadfile(1) close(1) end subroutine testreadfile(fileid) integer i integer fileid do i=1,10000 a=readfile(fileid,i) enddo end subroutine real*8 function readfile(fileid,i)result(out) integer fileid, i ! How can I read the ith data from the file without read all its former data? ! Thanks end function
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Read about the FSEEK library function in the Intel Fortran Libraries Reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This excellent question illustrates the limitations of Fortran file i/o as compared to other languages. Perhaps someday Fortran will develop modern file i/o. In the meantime,Win32 API functions can completely replace the native F90 file i/o, with improved performance and total versatility (albeit a lack of portability). See the attached code, particularly SetFilePointer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank both of you very much!
Another question: Can the 32-bit system support the file size greater than 2G?
Thanks,
Zhanghong Tang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page