Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'importing *.SPE binary files on mac os x' topicStudent Support Forum > General > Archives > "importing *.SPE binary files on mac os x"

Next Comment >Help | Reply To Topic
Author Comment/Response
Rob Sewell
06/06/05 06:56am

The following code was written to import *.SPE files from Prinston Instruments' WinView program into mathematica for analysis. The code works well on a windows box running mathematica 5.1, but on a powerbook running mac os 10.3 the binary file is read incorrectly. Does anyone have any suggestions for importing binary files cross-platform?

(* Reading SPE Files *)

ReadSPE::usage="ReadSPE[file]
reads data from a Princeton Instruments SPE file into a Mathematica \
array. The function works with all data types supported by the SPE format. \
If the file contains a single frame, the data is returned as an array. If it \
contains multiple frames then the data is returned as a list of arrays.";

(* This function is used by ReadSPE[ ]. It uses to StreamPosition[ ] to access the header entries that we need, and the Experimental binary import function to improve performance. *)

ReadBinary[stream_,offset_,format_]:= Block[{},SetStreamPosition[stream,offset];BinaryRead[stream,\
format]]

(* This function reads in SPE files written by the Princeton Instruments camera. The location and data type of the header parameters we need to make sense of the file are taken from the file specification in the WinView manual. SPE files can contain one or more frames. The If[ ] at the end applies an extra partioning function in the case of multiple frames. *)

ReadSPE[fname_]:=Module[{strm,xsize,ysize,dtype,format,frames,data},
strm=OpenRead[fname,DOSTextFormatFalse,BinaryFormat -> True];
xsize=ReadBinary[strm,42,"UnsignedInteger16"];
ysize=ReadBinary[strm,656,"UnsignedInteger16"];
dtype=ReadBinary[strm,108,"Integer16"];
format=Switch[dtype,0,"Real32",1,"Integer32",2,"Integer16",3,"UnsignedInteger16"];
frames=ReadBinary[strm,1446,"Integer32"];
data=BinaryReadList[strm,format];
Close[strm];
If[frames==1,Partition[data,xsize],Partition[Partition[data,xsize],ysize]]
]

URL: ,

Subject (listing for 'importing *.SPE binary files on mac os x')
Author Date Posted
importing *.SPE binary files on mac os x Rob Sewell 06/06/05 06:56am
Re: importing *.SPE binary files on mac os x christoph he... 07/13/05 3:01pm
Re: importing *.SPE binary files on mac o... Forum Modera... 07/13/05 9:26pm
Next Comment >Help | Reply To Topic