comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Reading binary (.ply) file of varying header size
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Reading binary (.ply) file of varying header size [message #89656 is a reply to message #89654] Thu, 06 November 2014 10:03 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Thursday, November 6, 2014 11:40:19 AM UTC-5, Cyndy wrote:
> Hi folks -
>
> Way out of practice IDL programmer, here. I need to be able to read binary files, with potentially variable length header files, in a function in IDL.
> I'm not usre what the most efficient way to do that is; it seems it's easy if one knows a priori the number of bytes in the header, but i can't make that assumption. The files are .ply files, by the way, the header will tell me how much data follows, and the header ends with a specific set of characters. So, if I can read the header line by line, I can scan for the proper 'text' indicating end of header, and I know how to read in the rest. It's the header part I don't know how to do.
>
> Anyone have a few hints? Or if you know where I can find a binary ply to idl data structure procedure and can point me there, I'm eternally grateful :)

You can just read the data one byte at a time with READU. That is brute force, but it works.

If you know the maximum possible size of the header, then you can just read a stream of bytes and look for your signature.

;; Signature is 4 bytes 'deadbeaf' in hex
signature = ['de'xb, 'ad'xb, 'be'xb, 'ef'xb]
bb = bytarr(10000) ;; Assume maximum possible header size of 10000
readu, unit, bb
wh = where(bb[0:*] EQ signature[0] AND bb[1:*] EQ signature[1] AND $
bb[2:*] EQ signature[2] AND bb[3:*] EQ signature[3], ct)

;; Error checking
if ct EQ 0 then message, 'ERROR: signature not found'

;; We found it. wh[0] points to the first byte of signature in the header
pt_data = wh[0] + 4 ;; First character of data past the header
header = bb(0:pt_data-1)

;; Read the rest of the data
;; rewind to the start of the data
point_lun, unit, pt_data
;; ... now read the rest of the file however you want


Craig
[Message index]
 
Read Message
Read Message
Previous Topic: Coord_transform in axes
Next Topic: Turn off "< Press Spacebar to continue, ? for help >"

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:41:38 PDT 2025

Total time taken to generate the page: 0.00451 seconds