Re: bytarr type conversion/structures [message #13004 is a reply to message #12995] |
Sat, 26 September 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Jacobus Koster (jkdj@ix.netcom.com) writes:
> Here's one for the pro's (and DF :-), at least, I think, but I'm no
> (big) expert.
Being separated from the "pro's" only serves to accentuate
my decreasing stature as a programmer to be reckoned with.
I am simply going to have to *stop* writing those damn FOR
loops in example programs I publish on this newsgroup. :-(
> Suppose my image files have a standard format with a standard 2048 byte
> header.
> This header consists of 10 bytes of extraneous information followed by a
> descriptor part and a data part.
> The descriptor part consists of about 100 descriptor fields, each of
> which is a record/structure consisting of 3 short ints : key.type,
> key.length, and key.offset.
> [...]
> 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.
Does it strike you that forgetting "forever about the file" and
accessing "the actual data itself" might be mutually exclusive
goals in this case? :-)
> 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 ?
No. Given the constraints you are putting on the problem (I suspect
needlessly, but that is up to you to determine), I would say it is
impossible to do this without writing a FOR loop (Oh boy!). What
you want to do, it seems, is read a structure array from a byte
array. You can certainly read integers or long integer, or even
floats, from a byte array, but you can't read structures without
doing it in some kind of loop.
> All I know is : it should involve pointers (if only because the type of
> the actual data varies). In addition to this, I would like to avoid
> FOR-loops, and explicitly calculating integers as 256*byte1 + byte2
> strikes me as kinda crude.
I suspect, although I can't prove it, that your thinking about
this problem is not crystal clear yet. Tell me again *why* you
want to do this? And why you want to do it in this "throw it out"
sort of way?
Cheers,
David
----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|