Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Speculative file access

Intel_C_Intel
Employee
424 Views
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
0 Kudos
1 Reply
david_jones
Beginner
424 Views
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
0 Kudos
Reply