473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question about unpack

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

Mar 27 '07 #1
1 2440
dorian <do*********@gmail.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Geoffrey | last post by:
Hope someone can help. I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; xbuffer:...
5
by: grant | last post by:
Hi All, I am pretty new to python and am having a problem intepreting binary data using struct.unpack. I am reading a file containing binary packed data using open with "rb". All the values are...
10
by: ma740988 | last post by:
I'm trying to unpack a 32 bit word into 3-10 bits samples. So now: Sample0 corresponds to bits 0-9 Sample1 corresponds to bits 10-19 Sample2 corresponds to bits 20-29 Bits 30 and 31 are don't...
3
by: Eric Jacoboni | last post by:
Hi, To experiment with unpacking, i've written a little C code which stores one record in a file. Then, i try to reread this file to unpack the record. Here's the struct of a record: ...
3
by: Andrew Robert | last post by:
Hey everyone, Maybe you can see something I don't. I need to convert a working piece of perl code to python. The perl code is: sub ParseTrig {
4
by: OhKyu Yoon | last post by:
Hi! I have a really long binary file that I want to read. The way I am doing it now is: for i in xrange(N): # N is about 10,000,000 time = struct.unpack('=HHHH', infile.read(8)) # do...
2
by: brnstrmrs | last post by:
If I run: testValue = '\x02\x00' junk = struct.unpack('h', testValue) Everything works but If I run testValue = raw_input("Enter Binary Code..:") inputting at the console '\x02\x00' junk...
0
by: Ping Zhao | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I am writing a small program to decode MS bitmap image. When I use statements as follow, it works fine: header = str(struct.unpack('2s',...
1
by: joe shoemaker | last post by:
If you have the following: data = unpack('>L', sock.recv(4)) Does this line of code means that incoming data is big endian and unpack it to endianess of local machine? If local machine is...
17
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.