Question about unpack

  • Thread starter Thread starter dorian
  • Start date Start date
D

dorian

Dear friends, I am trying to get information from a SEGY file. This
format is used to handle seismic data. The first 3200 bytes are in
EBCDIC format. The following 400 bytes of the format are the binary
header. Every variable in this header occupies 2 or 4 bytes. I
developed a program in perl that uses the instruction "unpack". But I
have no idea how to proceed in C#.
For example, there is data named sample interval, that is located in
the byte 3200+17 to 3200+18 (it means, from byte 3217 to 3218, 2
bytes). To know the value of this variable, I used the perl
instruction:
$sr=unpack("n",substr ($buf,3216,2));

How can I do this in C#?

I really appreciate any help.

Dorian Oria
 
dorian said:
Dear friends, I am trying to get information from a SEGY file. This
format is used to handle seismic data. The first 3200 bytes are in
EBCDIC format. The following 400 bytes of the format are the binary
header. Every variable in this header occupies 2 or 4 bytes. I
developed a program in perl that uses the instruction "unpack". But I
have no idea how to proceed in C#.
For example, there is data named sample interval, that is located in
the byte 3200+17 to 3200+18 (it means, from byte 3217 to 3218, 2
bytes). To know the value of this variable, I used the perl
instruction:
$sr=unpack("n",substr ($buf,3216,2));

How can I do this in C#?

The easiest way for those two bytes is to seek to the right point in
the stream (eg using the Position property) and then read the two
bytes. You can use BinaryReader to make life easier in terms of
converting the bytes to "larger" types, or the EndianBinaryReader I've
got if BinaryReader uses the wrong Endianness for you.
See http://pobox.com/~skeet/csharp/miscutil for more details.
 
Back
Top