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

Home » Public Forums » archive » Re: Programatically create structure
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: Programatically create structure [message #40443] Wed, 04 August 2004 08:56
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
> You can use CREATE_STRUCT:
>
> mystruct = CREATE_STRUCT( variable_name, $
> variable_data )
>
> is what I use in my netCDF reader - where I have may have no idea
> beforehand what the variable name is or what the variable data type is.
> That information comes from the netCDF read... or your database query.
>
> You can append stuff to the structure also,
>
> mystruct = CREATE_STRUCT( mystruct, $
> next_variable_name, $
> nest_variable_data )
>
> but I don't know how efficient that is for large datasets, or if you can
> do it for named structures.

Thanks. That's exactly what I needed. I know I read a ton about
CREATE_STRUCT() last night, but apparently it didn't sink in. I blame
it on me actually attempting to do IDL programming at 2:00AM. Or maybe
I can blame it on the Mountain Dew wearing off an hour or so before that.

-mike
Re: Programatically create structure [message #40444 is a reply to message #40443] Wed, 04 August 2004 05:49 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Michael Wallace writes:

> I'm far from being a structure guru, but I hope someone out there is.
> Is there a clean way to create a structure programmatically? I will
> neither know the names of the structure tags nor know their types ahead
> of time (i.e. before runtime).

I think you are looking for CREATE_STRUCT.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Programatically create structure [message #40445 is a reply to message #40444] Wed, 04 August 2004 05:36 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Michael Wallace wrote:
> I'm far from being a structure guru, but I hope someone out there is. Is
> there a clean way to create a structure programmatically? I will
> neither know the names of the structure tags nor know their types ahead
> of time (i.e. before runtime).
>
> What I want to do is create a structure based on the results returned
> from a database query. In the general case, I won't know the columns
> returned nor the column types before I execute the query. Once I have
> queried the database I can inspect the result set metadata and pull out
> column names and column types. Before doing this query I can have a
> another query which will return the total number of rows that the second
> query will return.
>
> So, I can get the total number of rows, the column names and column
> types. What I'd like to do is create a structure appropriate for the
> column names and column types. Once the structure is created, I can
> replicate it to make an array the same size as number of rows returned.
> But how do I create the structure in the middle of my running code?

You can use CREATE_STRUCT:

mystruct = CREATE_STRUCT( variable_name, $
variable_data )

is what I use in my netCDF reader - where I have may have no idea beforehand what the
variable name is or what the variable data type is. That information comes from the netCDF
read... or your database query.

You can append stuff to the structure also,

mystruct = CREATE_STRUCT( mystruct, $
next_variable_name, $
nest_variable_data )

but I don't know how efficient that is for large datasets, or if you can do it for named
structures.

Another alternative is to construct the structure constructor statement in a string and
call the EXECUTE function. I used to do it like that but I prefer CREATE_STRUCT.

paulv


>
> Everything I've read in the IDL documentation about structures shows the
> tag names being set statically. I haven't found any way to set the tag
> names to some variable. If I could do that then I'd be past the hurdle
> of getting the tag names to match the column names returned. The second
> hurdle is to set the correct data type. I suppose I could use some
> default at first and then reset the type based on the column type later
> on, if necessary. If there were a way to create a structure by first
> saying how many fields are present and then march through each of the
> field and set the tag name and type, I'd be set. Maybe it exists
> somewhere, but it sure doesn't exist the IDL documentation.
>
> I do not have my heart set on using structures if this isn't the way to
> go, but I'd like some nice general way to do handle results from a
> general query. In certain cases I will know what my query is ahead of
> time and then it's no problem since I can create the structure
> definition ahead of time, but it break down in the general case. The
> general case is always a doozie (just as Einstein).
>
> TIA,
> Mike
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: working dir with virtual machine
Next Topic: Controlling number of decimal places

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

Current Time: Thu Oct 09 07:28:50 PDT 2025

Total time taken to generate the page: 0.63935 seconds