简体   繁体   English

在Fortran中读取带有EBCDIC和二进制数据内容的SEG-Y文件

[英]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. 我正在读取一个SEG-Y文件(在地球物理学中用于存储数据),它具有2个标头部分,第一个标头为3200字节,其中包含EBCDIC格式的信息,而第二个标头为二进制格式,长度为400字节。 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. 之后是数据,数据的大小由给定字节位置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. 我设法在Fortran 90中使用简单的打开命令读取了EBCDIC(字节1-3200)标头,没有访问权限或格式定义,但是我无法进一步读取二进制标头(3201-3204,3205-)中的特定字节。 3206等),其中包含随后需要读取其余二进制数据的重要信息。

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? Fortran是否支持在代码中更改文件访问/格式/ ...? 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? 如果这不可能,那么我如何跳过前3200个字节并移至二进制部分(字节3201-3600)以读取所需的数据?

If you open the data-file with access="stream" , you can read the file byte by byte from any position you want. 如果使用access="stream"打开数据文件,则可以从任意位置逐字节读取文件。

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. 在小字节序计算机上,您可能必须转换其字节序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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