- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
Does anyone have any suggestions as to the best way to perform speculative file access?
I'll give an example: I have a file saved from FORTRAN. I want to add a version number as the first entry in the file. OK, so my standard unformatted WRITE can do that, but now I have some files with a version number, some without. What READ can I do to perform the following logic:
Read first entry - is it a version number?
If NO - use file reading routine A
If YES - use file reading routine B
Obviously, once read I'd save it out with a version number.
Thanks for you help,
Dan
Does anyone have any suggestions as to the best way to perform speculative file access?
I'll give an example: I have a file saved from FORTRAN. I want to add a version number as the first entry in the file. OK, so my standard unformatted WRITE can do that, but now I have some files with a version number, some without. What READ can I do to perform the following logic:
Read first entry - is it a version number?
If NO - use file reading routine A
If YES - use file reading routine B
Obviously, once read I'd save it out with a version number.
Thanks for you help,
Dan
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The "best" way to do this involves avoiding a rewind or backspace of the file if at all possible, in order to save time.
Read the first record into a character-string buffer, and test it:
If it is a version number, treat it as such, and skip to a new read statement for the next and subsequent records which will read directly into the usual target locations;
If it is not a version number, read from the character-string buffer into the usual locations for the first "real" record, take action regarding missing version number (set flag to indicate need to rewrite file, then write version number and first record), then skip to a read for the next and subsequent records, again directly into the target locations.
I have used this approach for formatted reads, but it should work for unformatted
Read the first record into a character-string buffer, and test it:
If it is a version number, treat it as such, and skip to a new read statement for the next and subsequent records which will read directly into the usual target locations;
If it is not a version number, read from the character-string buffer into the usual locations for the first "real" record, take action regarding missing version number (set flag to indicate need to rewrite file, then write version number and first record), then skip to a read for the next and subsequent records, again directly into the target locations.
I have used this approach for formatted reads, but it should work for unformatted

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