开发者

How to skip bytes in file read using stream

开发者 https://www.devze.com 2023-02-16 16:50 出处:网络
I\'m trying to read some noncontiguous fields from a fixed length data using Fortran. I would like to read (stream) from a binary file an array of 4 byte integers each separated by 6 bytes (i.e. read

I'm trying to read some noncontiguous fields from a fixed length data using Fortran. I would like to read (stream) from a binary file an array of 4 byte integers each separated by 6 bytes (i.e. read 4bytes, skip 6bytes, read 4bytes, skip 6bytes,...). I could use a dummy variable of size 6bytes; however, I was wondering if there was an option in the read statement 开发者_高级运维to skip bytes after reading each element of the array. Thanks in advance for you help.

Eric


I think what you are looking for is direct access files: Direct-access files. Here you specify the number of bytes per record in the the OPEN statement, then specify which record to read in your READ statement. In your case the record length would be 10 bytes and you would only use the first 4 bytes of each record.

Personally I would just use a dummy variable and a format statement. I think it would make the final code more clear and I don't think there would be any performance penalty.

0

精彩评论

暂无评论...
验证码 换一张
取 消