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

Home » Public Forums » archive » Possible to create 'keyword_used' type function?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Possible to create 'keyword_used' type function? [message #88715] Mon, 09 June 2014 14:11 Go to previous message
Brian Devour is currently offline  Brian Devour
Messages: 5
Registered: September 2012
Junior Member
Hi all,

So, as noted here:

http://www.idlcoyote.com/tips/keyword_check.html

checking if keywords were used is kinda a pain in the butt, thanks to the difference between keywords passed by value or reference and the misleadingly-named functions used for these purposes.

At the bottom of the page, there's a nice example of a bit of code that will reliably check if a keyword was used, regardless of whether it was passed by value or reference:

pro testme, KEY=k
if n_elements(k) ne 0 OR arg_present(k) then $
print,'You used KEY!' else $
print,'You neglected KEY!'
end

The operative part, of course, is the test:

if n_elements(k) ne 0 OR arg_present(k) then...

I can and have used this in my programs to check keywords. However, just on an aesthetic level it somewhat annoys me to have a long compound test, as compared to how simple 'if keyword_set(k) then...' is. I would like to create a function named something like keyword_used that would duplicate the functionality of the compound test above, but in a more compact and quicker to type format, so that I could simply do:

if keyword_used(key) then...

in my program instead of doing:

if n_elements(key) ne 0 OR arg_present(key) then...

So, I tried to do this. The first and simplest way to try this that came to mind was this:

function keyword_used, key1
if n_elements(key1) ne 0 or arg_present(key1) then return, 1 else return, 0
end

This doesn't work; 'keyword_used(key)' in a program always returns 1 regardless of whether 'key' was actually used or not in the program call. I *think* this is because when 'key' doesn't exist in the program, IDL obligingly passes it into keyword_used by reference, hence causing 'arg_present(key1)' inside keyword_used to return true. (I'm not sure if I'm describing that correctly; these things still confuse me somewhat.)

I did some more experimentation with trying to use scope_varfetch and routine_info to try and figure out what variable names were used in various calls and to go up a level and examine the variables existing inside the routine that calls keyword_used, but I relatively quickly got lost in the complexities thereof. (I'm an astronomer, not a programmer, and it shows...) I did some searches on this general topic, but I didn't see anywhere anyone trying this particular task. Is it even possible to write a simple function to do this?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Ternary Plot in IDL?
Next Topic: How to display an image (tvscl, shade_surf, etc.) with values cut-off

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

Current Time: Wed Oct 08 13:56:28 PDT 2025

Total time taken to generate the page: 0.00459 seconds