comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: bytarr type conversion/structures

Re: bytarr type conversion/structures
type: item
description: 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 …
creator: davidf
date: 1998-09-26T07:00:00-00:00

Re: bytarr type conversion/structures
type: item
description: Kevin Ivory wrote: > > Jacobus Koster wrote: > [...] > 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). > > Cheers, > Kevin > -- This is very nice, Kevin. Maybe I can contribute another 2 cents to this problem: As DF (in my definition about the only pro around) pointed out, there is a contradiction between "forget forever about the file" and retrieve the data later. Yet, I have recently written a few routines that achieve almost that. What I needed to do sounds somewhat similar: "parse" a huge file for its header structures *once* (there are several spread out over the file in our case), then store data pointers (for point_lun) and access the data as soon as it is needed. The whole thing is too complicated and long to "give away" on this newsgroup, but I will eventually place it on my web page (after some more testing), and I will give a few hints here: * I use the logical file unit as a relational link between the data files and some "datainfo" structures that describe the contents and dimensions of the data as well as "where to find it" (the file pointer). For this, you need to avoid get_lun, because you must make sure that you can re-open your files with the same unit numbers if they have been closed by some unaware user. I attach a little fun…
creator: Martin Schultz
date: 1998-09-28T07:00:00-00:00

Re: bytarr type conversion/structures
type: item
description: Kevin Ivory (Kevin.Ivory@linmpi.mpg.de) writes: > Looks like even "pro DF" is going to learn something today. Indeed. In fact, hardly a day goes by that I don't learn something from this newsgroup. That's why I like it so much. And I would have learned this tip too if I had taken 10 minutes to read that IDL Programming Techniques book by ol' whatshisname. :-( 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/
creator: davidf
date: 1998-09-28T07:00:00-00:00

Re: bytarr type conversion/structures
type: item
description: 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). Cheers, Kevin -- 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/
creator: Kevin Ivory
date: 1998-09-28T07:00:00-00:00