View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Luis[_5_] Luis[_5_] is offline
external usenet poster
 
Posts: 2
Default Help reading binary file

I would like to open the data contained in a binary file in to an
excel worksheet. I can open the binary file in python with the
following script

################################################## #######################
def rsvdat(filename):
header=array.array('c') # Skip header
memsize=array.array('L')
file=open(filename,'rb')
# Define header as 1032 bytes dont use it
header.fromfile(file,1032)
# Define buf size as 4 byte long int
memsize.fromfile(file,1)
# This will give the number of data points (4 bytes floats)
totpts=int(memsize[0]/4.0)
v=array.array('f')
v.fromfile(file,totpts)
file.close()
v=Numeric.array(v) #convert to Numeric type to use
slicing ops
vc=Numeric.zeros(totpts/2,'D')
vc.real=v[::2]
vc.imag=v[1::2]
return vc

Now I want to do it in VBA, so far I got
'================================================= =============
Sub rsvd()
'================================================= =============
Dim Rdata As String
Dim BinaryFile As String
Dim numPts As Long
Dim SVpoint As Single ' 4 bytes right ?
'================================================= =============


FileNum = FreeFile ' Supply next available number
BinaryFile = Application.GetOpenFilename
'Workbooks.Add
Set NewSheet = Sheets.Add(Type:=xlWorksheet)
'NewSheet.Name = BinaryFile 'THIS DOESN"T WORK
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NewSheet.Select

Open BinaryFile For Binary Access Read As #FileNum
Seek #FileNum, 1032 ' Skip header
'numPts = Input(4, #FileNum) DONT LIKE IT, WANTS STRING
Input #FileNum, numPts "WORKS" BUT IT DOESNT RETURN RIGHT VALUE
Range("A1").Value = "Now the data :"
'================================================= =============
' Loop to get total number of points
For k = 1 To numPts
Input #FileNum, SVpoint
Range(Cells(k, 2), Cells(k, 2)).Value = otro
Next k
'================================================= =============
Close #FileNum
End Sub
'================================================= =============

at this point I am stuck !
If I cannot retrieve the total number of points (after 1032 bytes) i
cannot loop, furthermore
if I get the next value (should be a float) always return 0.

Am I using the Input # function correclty, or is there an alternative
to get data form the binary
file

TIA

Luis