Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28477 Discussions

Backspacing through segmented files instead of rewind

Dan_U_
Beginner
260 Views

Hi,

I am having some trouble trying to adapt some fortran code to BACKSPACE through unformatted segmented files.

My code exists as a few separate programs, the first creates these very large, unformatted files, which are then read in by a second program.

My first modification was to store these files as segmented, as I was having issues with reading in the data correctly on the next step. I'm not too clued up with the technicalities but my understanding was that the data I was writing (which is not fixed length) might have been exceeding the record length, leading to some gibberish data being into the second program. Having these files segmented appeared to fix this issue.

My current issue though is something else. These files are very large and in my second program the records are read in, and the record data is then used for calculations. It is necessary for me to step back over records to reread them at certain points, and in these instances the desired record to be read is always 2 records away from the record where the "pointer" actually is.

Initially the code would REWIND the file and then perform multiple reads to get to the desired record, however this proved to be a bottleneck as my files grew larger, so I am instead trying to implement the BACKSPACE function to skip back to the record that I need instead of rewinding the whole thing.

This seems to speed things up, but now the data I read into my arrays from each record I BACKSPACE to are different to when I used the REWIND function.

The logic of my code seems to be fine - BACKSPACE is essentially the same as doing a REWIND from file N to file N-1. I just don't understand what would be causing the data to look so different. Is there something about the structure of segmented files I have to be careful about? Can BACKSPACE determine the start of a segmented record like it does other records?

I have some information which might give a clue: in one run of my code, I run through a file which has about 10 of these large records, saved as segmented. On the first instance of using the BACKSPACE statement the code correctly arrives at the correct record #1 and reads in the data in the same way as the previous REWIND version, however the following time BACKSPACE is executed it appears to read incorrect data from record #2. Perhaps this second record is actually segmented and the first one isn't because it hasn't reached the max record length limit? This is just a guess!

If I have completely misunderstood the concept of segmented files then please enlighten me! Or I can provide addition information if necessary. Thank you!

0 Kudos
1 Reply
Steven_L_Intel1
Employee
260 Views

It would help if you could provide a sample program that demonstrates the problem. However, I note that we have another report of BACKSPACE issues in https://software.intel.com/en-us/forums/topic/549033 that might be related, even though the symptom is different.

Segmented records should not cause BACKSPACE to execute incorrectly. Please try to come up with a test program that demonstrates the error and we'll be glad to investigate.

0 Kudos
Reply