[SciPy-User] dtype of LabView binary files

Chris Barker Chris.Barker at noaa.gov
Tue Nov 9 17:51:14 EST 2010


Xunchen Liu wrote:
> It seems there is only one web page here talking about the dtype of the 
> binary file saved from Labview:
> 
> http://www.shocksolution.com/2008/06/25/reading-labview-binary-files-with-python/
> 
> I followed Travis' suggestion on that page to convert one of my Labview 
> binary file using
> 
> data=numpy.fromfile('name',dtype='>d')
> 
> but this gives a array doubled the shape of my recorded data 

hmm -- "d" is already double (64 bit float) -- could the labview data be 
128bit? seems unlikely.

> and also 
> the value of the data are not right.
> 
> For example, the attached is the text file and binary file saved by Labview.
> 
> the text file reads:
> 
> array([-2332., -2420., -2460., ...,  1660.,  1788.,  1804.])
> 
> while the binary file reads (with dtype='>d')
> 
> array([-3.30078125,  0.        , -3.30297852, ...,  0. ,       
> -2.6953125 ,  0.        ])
> 
> Anyone knows what dtype I should use, or how should I build the correct 
> dtype for it?

I see from that web page:

"One final note about arrays: arrays are represented by a 32-bit 
dimension, followed by the data."

so you may need to skip (or read) 32 bits (4 bytes) before you read the 
data:

header = numpy.fromfile(infile, dtype='>i',count=1)
data = numpy.fromfile(infile, dtype='>d')

that's guessing that the header is big-endian 32bit integer.

You also might try both ">" and "<" -- maybe it's not big endian?

It's going to take some experimentation.

The good news that if you read binary data wrong, the result is usually 
obviously wrong.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the SciPy-User mailing list