0

I am working on a complicated code and have made a few changes. The main purpose of the code is to open two files and perform calculations by taking data from each file a record at a time. These files are very large and are unformatted.

My first change was to save these files using the segmented filetype flag, and also to have the code read them in as segmented. This works fine.

My next change was to convert a REWIND into a BACKSPACE, this is what my code looks like:

if (kneed .le. kbeg) then
        kback=kbeg-kneed                                                
        if(kback.le.5)then
           do i=1,kback
               backspace ivec
           end do
        else
           rewind ivec
           do 10 i=1,kneed+6
              read(ivec)
           10 continue
        end if
end if

What's happening here: IVEC is the handle for the file. FILE1 is read through sequentially, as in, 1, 2, 3, 4,....N. Then, for each N in FILE1, FILE2 is read twice, and a calculation is performed between the record N in FILE1 and both records N-1 and N+1 for FILE2. i.e. calculation(FILE1_N, FILE2_N-1) and calculation(FILE1_N, FILE2_N+1).

In the code, kbeg is the current record of FILE2, kneed is the desired record.

This is where the REWIND was necessary, FILE2 needed to be rewound to get to the N-1 for the subsequent N+1 (FILE1) calculation. My issue was that this REWIND proved to be the biggest bottleneck, I am trying to speed it up by implementing this IF statement to do a BACKSPACE (before my modification only the statement in the ELSE section was present, the "+6" is there because my files have a 6 line header before the records begin).

THE PROBLEM: Now I have made this change, the BACKSPACE appears to be speeding up the process, but now when I read the FILE2 records the data are different from when I just used the REWIND function. The logic here seems fine, and it actually works for the first time I do this to FILE2, but after that the data appear to be wrong.

I'm wondering if there is something about segmented records that I need to be aware of for the BACKSPACE to work properly. Also, my kneed and kbeg are appearing correctly. The only issue is when I read my data into an array the data are different from when only the REWIND function is present.

Am I missing something?

Please advise me if I need to provide more info!

  • `segmented` is an extension of the Intel compiler. Are you sure that you need that? `access="sequential"` might suffice. If the records are fixed length, you could use direct access and read records in any order. – M. S. B. Apr 12 '15 at 16:44
  • I need the segmented flag because I can't contain my data on one single variable length record in most cases. There are examples of my data where not using segmented files works fine, and the BACKSPACE functionality I have implemented also works. There seems to be an issue with backspacing when I use segmented records, it looks like it is unable to find the beginning of the "main" record which contains the segments. I was wondering if there is any control I can use to get around this issue. – underthew00d Apr 13 '15 at 14:02
  • How long are your records? Maybe split them. Otherwise, maybe this is a support question for Intel. – M. S. B. Apr 13 '15 at 17:27

0 Answers0