- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mixing I/O runtimes often causes problems. You are attempting to use fseek and FORM='binary', which are extensions to standard Fortran, with stream files.
Why not use rewind(idata) instead of fseek(idata,0,0) and write(idata) instead of write(idata,pos=1)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the Windows environment, you can abandon the (ancient) Fortran file routines and use the Win32 API routines directly, much more efficient and also much easier, simpler and more productive programming. Here is a handle-based example which solves your problem:
[fortran]
RECURSIVE SUBROUTINE Set_File_Pointer (ihandl, offset, truncate)
IMPLICIT NONE
INTEGER(HANDLE), INTENT(IN) :: ihandl
INTEGER, INTENT(IN) :: offset
LOGICAL, INTENT(IN), OPTIONAL :: truncate
INTEGER :: rslt
rslt = SetFilePointer (ihandl, MAX0(offset,0), NULL, FILE_BEGIN)
IF (PRESENT(truncate)) rslt = SetEndOfFile (ihandl)
END SUBROUTINE Set_File_Pointer
[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd be a little cautious about the workaround of calling directly into the Windows API for this situation - that's broadening the number of sub-systems that your program has to directly interact with, and the overlying libraries may not be expecting things like operating system file position to be changing underneath them. As mecej4 notes, "form='binary, access='stream'" is a bit of a curious monster too - a mix of an extension and a standard language feature that essentially do the same thing as far as I know (?) - did you mean form='unformatted', access='stream'?
Given use of stream access, why do you need to use fseek at all? Can't you just supply the appropriate pos specifier? If you want to reposition a stream file without actually transferring data then just use an data transfer statement with an empty io-list e.g. "write (idata,pos=x)". That will let you stick within the standard language, which leaves less room for vendor quibbling around whether something is supported or a bug and also makes your life easier when someone tells you that your program needs to run on linux tomorrow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can't reproduce a problem using a current compiler version. Which version are you using?
I'm a bit uncomfortable mixing FORM='BINARY' with ACCESS='STREAM' - the latter is a Fortran 2003 feature meant to be combine dwith FORM='UNFORMATTED' (in this case), but it seems to work ok here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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