简体   繁体   中英

Reading a SEG-Y file with EBCDIC and binary data contents in Fortran

I am reading a SEG-Y file (used in geophysics to store data) which has 2 header sections, the first is 3200 bytes containing information in EBCDIC format, while the second header is in binary format and is 400 bytes length. The data later follows where the size of the data is determined by a number defined in the binary header defined in given byte locations 3217-3218.

I managed to read the EBCDIC (bytes 1-3200) header using simple open command in Fortran 90 with no access or format definitions, but I can't go further to read the specific bytes in the binary header (3201-3204, 3205-3206, ... and so on) which contains important information needed to read the rest of the binary data afterwards.

How to properly define the access/formatting for the file to successfully read everything at once? Does Fortran support changing the file access/format/... within a code? If this is not possible, how then I can skip the first 3200 bytes and move to the binary section (bytes 3201-3600) to read the data I need?

If you open the data-file with access="stream" , you can read the file byte by byte from any position you want.

character :: byte   ! integer(int8) might be a better type

open(11, file="filename",access="stream",form="unformatted",action="read",status="old")

!be careful, the positions are numbered from 1, not from 0
read(11, pos=3200) byte

You can also read other datatypes if they are stored there in a compatible binary format

integer :: i
...
read(11, pos=...) i

On a little-endian machine you may have to convert their endianness.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM