You are reading a single comment by @ottbot and its replies. Click here to read the full conversation.
  • The file is created with a bash file, that is clearly where I am wrong. I thought binary access was different again, at least that was the impression I got from the documentation I found. The documentation I've found about direct access has not been the best, it seems a lesser used feature.

    That gist.github.com looks like a good idea. I'll try and pick out the bit I'm using.

    I looked at this a bit more, formatted direct access isn't binary (unformatted is) - and in the case of formatted, RECL depends on size needed by your format length in characters..

    If you're writing out integers with a format of I5, the record len is 5 bytes because the record is read as 5 characters, including padding.

    So if I have an output file with the contents:
    [code] 1 2 3 4 5 6 7 8 9 10[/code]

    and I want to read record 6, I need:
    [code] INTEGER :: i

          OPEN(2, FILE='test.dat', ACCESS='DIRECT', RECL=5, FORM='FORMATTED') 
          READ( 2, '(I5)', REC= 6 ) i[/code]
    

    If you were dealing with unformatted direct access, the RECL would just be the size of the integer kind.

    If you want to post up a snippet of your output file, I can try to read it.. Basically, you just need to make sure each integer you write with bash has a fixed width padded by leading spaces - so you need to know the max integer you'll be outputting - you can always just make it huge.. Then set the length in the RECL and FMT values.

About

Avatar for ottbot @ottbot started