[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bytarr type conversion/structures

Jacobus Koster wrote:
> I would like to read these headers as byte arrays of 2048 bytes, and
> then forget forever about the file I got them from. From this byte
> array, I want to read the 100 descriptor structures into a 100-element
> structure array, with the structure elements described by :
> {type:0,length:0,offset:0}. And then, I would like to access the actual
> data itself, of course.
> Is it possible in IDL to do this kind of type conversion, WITHOUT first
> writing the byte array out again into a dummy file and using an - albeit
> very beautiful - ASSOC variable or something like that ?

Looks like even "pro DF" is going to learn something today.

It is almost always possible to do type conversions without writing
into a dummy file and reading it again. The equivalent of Fortran
internal files are IDL strings. So you will have to look into the READS
procedure. Start off with the following lines:

header_bytes = bytarr(2048, /nozero)
openr, lun, /get_lun, image_file
readu, lun, header_bytes
free_lun, lun ; "forget forever about the file"
header_string = string(header_bytes)
; read 100 descriptor structures from header_string
header_structures = ({type:0,length:0,offset:0})[100]
reads, header_string, header_structures
; now read the data with formatted reads

I don't know about the pointer part (deleted from original message).

  Kevin Ivory                           Tel: +49 5556 979 434
  Max-Planck-Institut fuer Aeronomie    Fax: +49 5556 979 240
  Max-Planck-Str. 2                     mailto:Kevin.Ivory@linmpi.mpg.de
D-37191 Katlenburg-Lindau, GERMANY      http://www.gwdg.de/~kivory2/