Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Reading binary (.ply) file of varying header size
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 :)
Re: Reading binary (.ply) file of varying header size
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