matlab function to search binary format in binary file

matlab function to search binary format in binary file

Post by gregthom9 » Tue, 15 Apr 2008 19:13:00


Hello all

say I have a file, I know somewhere in the binary file, there is some data stored as 4 byte big-endian, how can I search the binary file to find the first occurence of the formatted data?

Cheers

GT
 
 
 

matlab function to search binary format in binary file

Post by Davi » Wed, 16 Apr 2008 00:19:01


< XXXX@XXXXX.COM
.org>...
there is some data stored as 4 byte big-endian, how can I
search the binary file to find the first occurence of the
formatted data?

you search the specification for the file format to find
out the offset for the data you want in the file. there
is no pattern or marker you can search for in a generic
binary file format to find any particular type or piece of
data.

 
 
 

matlab function to search binary format in binary file

Post by roberso » Wed, 16 Apr 2008 01:43:18

In article < XXXX@XXXXX.COM >,



Do you know anything about the alignment of the target data in the
file? Could that 4 byte value occur at any offset, or can it only
occur at even bytes, or only at bytes that are multiples of 4?

Is the file small enough that it could reasonably be read entirely
into memory? If so, then read it all and then either use strmatch
or use regex . regex might be more efficient.
--
"I want to be remembered as the guy who gave his all whenever
he was on the field." -- Walter Payton
 
 
 

matlab function to search binary format in binary file

Post by gregthom9 » Sat, 19 Apr 2008 17:52:00

Greetings and thanks for all trying to help.
In my files, the first few lines are ascii text.
Here is a sample of the file. When opened with text editor I see something like this

============================================================
line 1: 0062101e
line 2: 0,2
line 3:
line 4: 0
line 5: 1e-005,1.000000

.
.
.

line 27: 0.000000000,0.000000000
line 28: %^%%^%&$%%%%%&%@@#@3 ...
.
.
.
=====================================================================================

We see that the binary data only starts after a certain number of lines which may or may not be variable. It this line is constant I don't have a big problem.
If the line is not at the same position for all files, I need to search the file somehow to know where the binary data starts.

I know for sure the binary data is written as 4 bytes big-endian.
I just need to somehow find all the first few lines which are ascii and start reading the binary data from that position onwards. My problem is how to determine where the ascii data stops.

Cheers
 
 
 

matlab function to search binary format in binary file

Post by gregthom9 » Thu, 24 Apr 2008 19:46:57

Anyone with any ideas based on what I have in the previous post ?

Cheers
 
 
 

matlab function to search binary format in binary file

Post by Davi » Fri, 25 Apr 2008 01:08:04


< XXXX@XXXXX.COM
.org>...
previous post ?

nope, still can't be done with any certainty. even if you
assume that the 'ascii' data is only printable characters
and newlines, that could still leave you reading past the
first of the 'binary' data if it happens to represent a
printable character. you need some way to know where the
binary data starts. Don't any of those text header lines
give you a start of data offset, a count of headers? or
could there be some flag for the end of text and start of
data?? in olden days there were special ascii characters
used to mark end of text and start of data, but you would
have to check with whatever writes those data files to
know for sure. we use a similar file format for a project
here and the first text line says how many text lines
there are to read, then the data starts right after the
cr/lf pair for the last line... and as a safety measure
the last line must always be the same, so it can be
checked to be sure the first line was right.