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

Home » Public Forums » archive » Re: Need prog to give size of a structure in bytes
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Need prog to give size of a structure in bytes [message #13578] Thu, 26 November 1998 00:00
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Joe Means wrote:

> I need prog to give size of a structure in bytes, and I don't find one in the
> IDL 5.1 distribution. Has anyone else written one?
> Joe Means
> --
>

Dear Jooe

I will describe the way to do it:

help, structure,/str ,output=o
print,o[0]
** Structure <1843940>, 123 tags, length=55400, refs=1:
print,(str_sep((str_sep(o[0],'<'))[1],'>'))[0]
1843940


The keyword output was added by version 5.1 I believe.

regards
R.Bauer







>
> From:
> Joseph E. Means, Assistant Professor Forest Science Department
> Internet: Means@fsl.orst.edu Oregon State University
> Phone 541-750-7351 Fax 541-750-7329 Corvallis, OR 97331 U.S.A.
> http://www.fsl.orst.edu/rogues/meansj/meansnew.htm
Re: Need prog to give size of a structure in bytes [message #13638 is a reply to message #13578] Fri, 20 November 1998 00:00 Go to previous message
Michael Hartman is currently offline  Michael Hartman
Messages: 2
Registered: November 1998
Junior Member
Is there a reason why the N_Tags routine with LENGTH keyword set would not give
you what you are looking for?

Joe Means wrote:

> I need prog to give size of a structure in bytes, and I don't find one in the
> IDL 5.1 distribution. Has anyone else written one?
> Joe Means
> --
>
> From:
> Joseph E. Means, Assistant Professor Forest Science Department
> Internet: Means@fsl.orst.edu Oregon State University
> Phone 541-750-7351 Fax 541-750-7329 Corvallis, OR 97331 U.S.A.
> http://www.fsl.orst.edu/rogues/meansj/meansnew.htm

--
Michael Hartman
Electrical Geodesics INC
www.egi.com
PH: 541-687-7962
FX: 541-687-7963
Re: Need prog to give size of a structure in bytes [message #13639 is a reply to message #13638] Fri, 20 November 1998 00:00 Go to previous message
Brian Jackel is currently offline  Brian Jackel
Messages: 34
Registered: January 1998
Member
Not an obvious place to look, but from the docs:

========================================================
The N_TAGS function returns the number of structure
tags contained in a structure expression. It optionally
returns the size, in bytes, of the structure.
...
Keywords

LENGTH
Set this keyword to return the length of the structure, in bytes.

Note: The length of a structure is machine dependent.
The length of a given structure will vary depending
upon the host machine. IDL pads and aligns structures
in a manner consistent with the host machine's C compiler.
============================================================

I'm not sure if this works recursively (ie. structures in
structures). If not, and you need that, then drop me a
line. I've got some old code that does the general case,
but it's got some hardwired assumptions about how big
certain variable type are. Probably safe....


Hope this helps.

Brian Jackel
Re: Need prog to give size of a structure in bytes [message #13640 is a reply to message #13638] Fri, 20 November 1998 00:00 Go to previous message
Joe Means is currently offline  Joe Means
Messages: 44
Registered: November 1996
Member
I like your idea, David, but the length= from help is not close to the size of the
file when it is written out in binary.
IDL> help, /struct, headout
** Structure SMALLFOOTHEADER, 7 tags, length=272:
VERSION STRING 'smallfootheader1 '
TOTSHOTCOUNT LONG 0
DATUM STRING '83'
DATATYPE STRING 'utm'
NUMFILES INT 1
SHOTCOUNTS LONG Array[20]
FILENAMES STRING Array[20]
While the size of the file when written and closed is 1496 bytes. The filename
strings are each 70 characters long. Any ideas on this?

--Joe

David Fanning wrote:

> Snip....
>
> Help, struct, /Structure, Output=structInfo
> stuffIWant = structInfo[0]
> lengthInBytes = ParseIt(stuffIWant)
>
> I'll leave the ParseIt routine as an exercise for the reader. ;-)
>
> Cheers,
>
> David
>
> P.S. RSI warns you that following the instructions above
> may lead to heartache. I echo their comments.
Re: Need prog to give size of a structure in bytes [message #13643 is a reply to message #13638] Fri, 20 November 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Joe Means (means@fsl.orst.edu) writes:

> I need prog to give size of a structure in bytes, and I don't find one in the
> IDL 5.1 distribution. Has anyone else written one?

I haven't written one, but here is how I might do it.
The "help" information contains the size of the structure
in bytes. I might capture this help information and parse the
information out of it. I'm not sure, however, if this is
the *actually* size of the structure (taking into account
byte boundaries, etc.) or just the number of bytes in the
fields of the structure. Anyway, to get the info, I would
do this:

Help, struct, /Structure, Output=structInfo
stuffIWant = structInfo[0]
lengthInBytes = ParseIt(stuffIWant)

I'll leave the ParseIt routine as an exercise for the reader. ;-)

Cheers,

David

P.S. RSI warns you that following the instructions above
may lead to heartache. I echo their comments.

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Progamming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 5.2 available for FTP
Next Topic: Re: INSIGHT 3D Visualization ?

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

Current Time: Wed Oct 08 18:13:43 PDT 2025

Total time taken to generate the page: 0.00629 seconds