#pragma rtGlobals=1 // Use modern global access method. #include // edited by tony withers //BinaryReader helps you peek into binary files on disk to see what is inside of them. // Useful if, e.g., you are making your own file loader and need to read headers and find offsets and see what kind of data is in the file. //modified Jun 3 2005 Constant kSegmentSize = 10000 //how many bytes of the file we are going to show at one time menu "Data" Submenu "packages" "Binary File Reader" end end //***************************************************************************************************** //make the packages folder and the global variables and the control panel Function BinaryFileReader () if (!(datafolderexists ("root:packages:"))) newdatafolder root:packages endif if (!(datafolderexists ("root:packages:BinaryReader"))) newdatafolder root:packages:BinaryReader //make waves for the list box showing the first segment of data in the selected file make/o/t/n = (kSegmentSize,2) root:packages:BinaryReader:FileListWave make/o/n = (kSegmentSize,2) root:packages:BinaryReader:FileListSelWave //Make a text wave for the listbox that shows the data after being loaded according to the chosen specs make/t/o/n=(1,2) root:packages:BinaryReader:OutPutWave //make a temporary wave to read data into before displaying it in the listbox make/o/n = (kSegmentSize) root:packages:BinaryReader:TempWave //First row of waves will show byte offset SetDimLabel 1,0,BytePos,root:packages:BinaryReader:FileListWave SetDimLabel 1,0,BytePos root:packages:BinaryReader:OutPutWave //Second row will show the data as a character SetDimLabel 1,1,Char,root:packages:BinaryReader:FileListWave //a global string to contain a list of segments in the file for loading string/G root:packages:BinaryReader:SegmentsList = "" //global variable to hold reference nmber to the open file variable/G root:packages:BinaryReader:BRrefNum = nan //global string to display name of open file in a title box string/G root:packages:BinaryReader:fileNameStr = "" endif //try to bring panel to the front doWindow/F Binary_Reader if (V_Flag) return 1 endif //make the panel, as it was not already open NewPanel /K=1 /W=(70,100,535,455) as "Binary Reader" DoWindow/C Binary_Reader ListBox FileAsByteList,pos={215,25},size={100,315} ListBox FileAsByteList,help={"Shows the selected segment of data in the selected file as characters"} ListBox FileAsByteList,listWave=root:packages:BinaryReader:FileListWave ListBox FileAsByteList,selWave=root:packages:BinaryReader:FileListSelWave ListBox FileAsByteList,mode= 3,widths={20,13} Button OpenFileButton,pos={10,5},size={67,22},proc=BRopenFIleProc,title="Open File" TitleBox FileNameTitle,pos={79,3},size={383,20} TitleBox FileNameTitle,variable= root:packages:BinaryReader:fileNameStr PopupMenu SegmentsPopup,pos={10,40},size={99,20},proc=BRLoadSegmentProc,title="Load Segment" PopupMenu SegmentsPopup,mode=1,popvalue="0",value= #"root:packages:BinaryReader:SegmentsList" PopupMenu EndianPopUp,pos={10,120},size={178,20},title="Byte Order" PopupMenu EndianPopUp,mode=1,popvalue="Big-endian (Mac)",value= #"\"Big-endian (Mac);Little-endian (Win)\"" PopupMenu UnSignedPopup,pos={10,95},size={134,20},title="Integer Data is" PopupMenu UnSignedPopup,mode=1,popvalue="Signed",value= #"\"Signed;UnSigned\"" PopupMenu DataFormatPopUp,pos={10,70},size={140,20},title="Data Format" PopupMenu DataFormatPopUp,mode=1,popvalue="1 byte int",value= #"\"1 byte int;2 byte int (word);4 byte int;4 byte float;8 byte float (double)\"" Button ShowSelectionButton,pos={40,150},size={105,27},proc=BRShowSelection,title="Show Selection" ListBox OutPutList,pos={323,25},size={130,315} ListBox OutPutList,listWave=root:packages:BinaryReader:OutPutWave SetWindow kwTopWin,hook=BRCloseHook PopupMenu SegmentsPopup,userdata(ResizeControlsInfo)=A"!!,A.!!#>.!!#@@!!#