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

Home » Public Forums » archive » Undefined variables in structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Undefined variables in structures [message #62506 is a reply to message #62437] Thu, 11 September 2008 08:28 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Sep 10, 5:16 am, Joost Aan de Brugh <joost...@gmail.com> wrote:
> Hello all,
>
> What is the most plausible way to undefine variables in a structure.
> Sometimes, you need undefined variables to put into optional arguments
> if the procedure checks with N_Elements(..) ne 0.
>
> For example:
> plot,....,color=fsc_color(colorname,filename=consts.COLOR_FI LENAME),...
> If I do not want to use an own color file, I need to undefine
> consts.COLOR_FILENAME. Note that "" as filename is an error.
>
> Several attempts
> 1
> if consts.COLOR_FILENAME eq "" then void =
> Temporary(consts.COLOR_FILENAME)
> ; does not work in a struct. consts.COLOR_FILENAME remains ""
>
> 2
> temp_color_filename = consts.COLOR_FILENAME
> if consts.COLOR_FILENAME eq "" then void =
> Temporary(temp_color_filename)
> plot,...,color=fsc_color(color,filename=temp_color_filename) ,...
> ; Not the way to go. Makes the code messy, especially when more
> variables have to be undefined this way
>
> 3
> if consts.COLOR_FILENAME eq "" then
> plot,...,color=fsc_color(color),... else
> plot,...,color=fsc_color(color,filename=consts.COLOR_FILENAM E)
> ; Not the way to go. Will create a huge if-then-else pyramid when
> using several optional arguments.
>
> 4
> plot,...,color=fsc_color(color,filename=consts.COLOR_FILENAM E eq ""?
> undefined:consts.COLOR_FILENAME),...
> ; No pyramid because of the ? : construction But this is very hacky,
> because I am using a nonsense name (undefined).
>
> 5 ; The way I now just thought of.
> Make it a pointer and during startup
> if *const.COLOR_FILENAME eq "" then void =
> Temporary(*consts.COLOR_FILENAME)
> and then simply
> plot,...,color=fsc_color(color,filename=*consts.COLOR_FILENA ME)
> ; This does work. I can dereference the pointer, because it is a valid
> pointer to an undefined heap variable. It is still a little bit
> tricky, but the least evil of these possibilities (in my opinion).
>
> Are there people with more experience with these kinds of
> constructions and know a better way to do this.
> (Actually, I was already formulation this question before I thought
> about the pointer)

For just one variable, option 5 is probably the way to go. If you'll
have lots of possible options that you give one function or procedure,
though, you might want to consider using AUGMENT_INHERITED_KEYWORD in
JBIU:
http://web.astroconst.org/jbiu/jbiu-doc/misc/augment_inherit ed_keyword.html

-Jeremy.
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Segmentation in ENVI
Next Topic: write_tiff integer format

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

Current Time: Sun Oct 12 02:38:33 PDT 2025

Total time taken to generate the page: 1.52000 seconds